Description
(Disclaimer: Rust noob here. Don't kill me if I've misinterpreted a correct behaviour.)
Problem
Building a crate with -Zbuild-std=...
and --target <target>
where <target>
is a custom target linked in Rustup like this (rustup link mytarget /...path.../
) is broken since approx the time when the changes for "cargo vendor" landed.
Steps
- Build a custom rust toolchain. For example, this one.
- Register the just-built toolchain as a custom target in rustup as described in the above repo.
- Try to build a crate (for example, this one) by using
cargo build -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort
- Problem 1: Building the crate will fail with complaint
error: could not read vendor path
. Apparently, because of this code on line 55. - Problem 2: If you make an empty "vendor" dir and re-run the build, it will fail again now with the dreaded:
error[E0463]: can't find crate for `std`
|
= note: the `xtensa-esp32-none-elf` target may not be installed
... which is due to the fact that cargo does not pick up the std lib from the sysroot of the custom target at all. An indication of that is the fact that it downloads and compiles the rustc-std-workspace-*
crates from GitHub rather than picking up their patches from the sysroot of the custom target. I.e. when run with --verbose
:
rustc --crate-name rustc_std_workspace_alloc --edition=2018 /Users/...path.../.cargo/registry/src/6github.com-1ecc6299db9ec823/rustc-std-workspace-alloc-1.0.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C metadata=c8dee4e2d9f82246 -C extra-filename=-c8dee4e2d9f82246 --out-dir /Users/<censored>/rust-esp32-std-hello/rust/target/xtensa-esp32-none-elf/release/deps --target xtensa-esp32-none-elf -Z force-unstable-if-unmarked -L dependency=/Users/...path.../rust-esp32-std-hello/rust/target/xtensa-esp32-none-elf/release/deps -L dependency=/Users/...path.../rust-esp32-std-hello/rust/target/release/deps --cap-lints allow (exit code: 1)
Apparently, the above is caused by the logic here (line 67 and onward), but I've not analyzed (yet) what needs to be fixed in detail.
Possible Solution(s)
The following workaround seems to fix the issue:
cd rust
mkdir vendor
cd vendor
ln -s ../library/rustc-std-workspace-alloc rustc-std-workspace-alloc
ln -s ../library/rustc-std-workspace-core rustc-std-workspace-core
ln -s ../library/rustc-std-workspace-std rustc-std-workspace-std
Yet, this just does not feel right.
I just want to use my custom target with -Zbuild-std
and that's it. Ideally, I should not be even aware of the vendor
machinery, let alone symlinking the rustc-std-workspace-* patch crates in there.
Or is this how it all is supposed to work with custom targets, now that cargo vendor
has landed?