Paths emitted by build script are not corrected when cross-compiling #6177
Description
Posted on behalf of @Phaiax: (originally rust-lang/rust#55072)
I am trying some embedded rust programming and figured out that the cargo/rustc cache does not survive a move of the project folder. (This is the cortex-m-quickstart project but I think that does not really matter.)
There are no absolute paths neither in .cargo/config nor in Cargo.toml. After a cargo clean I can do a build again.
PS C:\Users\danie_000\Code\RE\ABC> rustc --version rustc 1.30.0-beta.15 (590121930 2018-10-12) PS C:\Users\danie_000\Code\RE\ABC> cargo --version cargo 1.30.0-beta (05e9b01fc 2018-09-21)
The rust version is set by rustup default beta and not overwritten for any of these folders.
After the rename of the Project folder, cargo summons rustc with some references to the ABC path that does not exist anymore.
PS C:\Users\danie_000\Code\RE> cd .\ABC\ PS C:\Users\danie_000\Code\RE\ABC> cargo clean PS C:\Users\danie_000\Code\RE\ABC> cargo build Compiling proc-macro2 v0.4.20 Compiling unicode-xid v0.1.0 Compiling rand_core v0.3.0 Compiling cortex-m-rt v0.6.4 Compiling cortex-m-semihosting v0.3.1 Compiling cortex-m v0.5.7 Compiling vcell v0.1.0 Compiling myapp v0.1.0 (C:\Users\danie_000\Code\RE\ABC) Compiling bare-metal v0.2.3 Compiling r0 v0.2.2 Compiling aligned v0.2.0 Compiling panic-halt v0.2.0 Compiling rand_core v0.2.2 Compiling volatile-register v0.2.0 Compiling rand v0.5.5 Compiling quote v0.6.8 Compiling syn v0.15.11 Compiling cortex-m-rt-macros v0.1.2 Finished dev [unoptimized + debuginfo] target(s) in 28.77s PS C:\Users\danie_000\Code\RE\ABC> cd .. PS C:\Users\danie_000\Code\RE> mv ABC XYZ PS C:\Users\danie_000\Code\RE> cd .\XYZ\ PS C:\Users\danie_000\Code\RE\XYZ> cargo -v build Fresh unicode-xid v0.1.0 Fresh rand_core v0.3.0 Fresh vcell v0.1.0 Fresh r0 v0.2.2 Fresh aligned v0.2.0 Fresh bare-metal v0.2.3 Compiling myapp v0.1.0 (C:\Users\danie_000\Code\RE\XYZ) Fresh panic-halt v0.2.0 Running `rustc --edition=2018 --crate-name build_script_build build.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=3a754d4070599644 -C extra-filename=-3a754d4070599644 --out-dir C:\Users\danie_000\Code\RE\XYZ\target\debug\build\myapp-3a754d4070599644 -C incremental=C:\Users\danie_000\Code\RE\XYZ\target\debug\incremental -L dependency=C:\Users\danie_000\Code\RE\XYZ\target\debug\deps` Fresh rand_core v0.2.2 Fresh volatile-register v0.2.0 Fresh proc-macro2 v0.4.20 Fresh rand v0.5.5 Fresh cortex-m-semihosting v0.3.1 Fresh cortex-m v0.5.7 Fresh quote v0.6.8 Fresh syn v0.15.11 Fresh cortex-m-rt-macros v0.1.2 Fresh cortex-m-rt v0.6.4 Running `C:\Users\danie_000\Code\RE\XYZ\target\debug\build\myapp-3a754d4070599644\build-script-build` Running `rustc --edition=2018 --crate-name myapp src\main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=7f9cdf275b22bd50 -C extra-filename=-7f9cdf275b22bd50 --out-dir C:\Users\danie_000\Code\RE\XYZ\target\thumbv7m-none-eabi\debug\deps --target thumbv7m-none-eabi -C incremental=C:\Users\danie_000\Code\RE\XYZ\target\thumbv7m-none-eabi\debug\incremental -L dependency=C:\Users\danie_000\Code\RE\XYZ\target\thumbv7m-none-eabi\debug\deps -L dependency=C:\Users\danie_000\Code\RE\XYZ\target\debug\deps --extern cortex_m=C:\Users\danie_000\Code\RE\XYZ\target\thumbv7m-none-eabi\debug\deps\libcortex_m-6d95ef6e4550c4c8.rlib --extern cortex_m_rt=C:\Users\danie_000\Code\RE\XYZ\target\thumbv7m-none-eabi\debug\deps\libcortex_m_rt-03e440f58d1c0555.rlib --extern cortex_m_semihosting=C:\Users\danie_000\Code\RE\XYZ\target\thumbv7m-none-eabi\debug\deps\libcortex_m_semihosting-26e2b9dfbd5c7e3b.rlib --extern panic_halt=C:\Users\danie_000\Code\RE\XYZ\target\thumbv7m-none-eabi\debug\deps\libpanic_halt-8d085ea03dce307c.rlib -C link-arg=-Tlink.x -L C:\Users\danie_000\Code\RE\XYZ\target\thumbv7m-none-eabi\debug\build\myapp-b0e16e01c22428a8\out -L C:\Users\danie_000\Code\RE\ABC\target\thumbv7m-none-eabi\debug\build\cortex-m-765dfe6812e223ce\out -L C:\Users\danie_000\Code\RE\ABC\target\thumbv7m-none-eabi\debug\build\cortex-m-rt-1387b5ad4b26cfa2\out -L C:\Users\danie_000\Code\RE\ABC\target\thumbv7m-none-eabi\debug\build\cortex-m-semihosting-cb2469f22b42a1d7\out` error: linking with `rust-lld` failed: exit code: 1 | = note: "rust-lld" "-flavor" "gnu" "-L" "C:\\Users\\danie_000\\.rustup\\toolchains\\beta-x86_64-pc-windows-msvc\\lib\\rustlib\\thumbv7m-none-eabi\\lib" "C:\\Users\\danie_000\\Code\\RE\\XYZ\\target\\thumbv7m-none-eabi\\debug\\deps\\myapp-7f9cdf275b22bd50.57siomzwzet2ykzc.rcgu.o" "-o" "C:\\Users\\danie_000\\Code\\RE\\XYZ\\target\\thumbv7m-none-eabi\\debug\\deps\\myapp-7f9cdf275b22bd50" "--gc-sections" "-L" "C:\\Users\\danie_000\\Code\\RE\\XYZ\\target\\thumbv7m-none-eabi\\debug\\deps" "-L" "C:\\Users\\danie_000\\Code\\RE\\XYZ\\target\\debug\\deps" "-L" "C:\\Users\\danie_000\\Code\\RE\\XYZ\\target\\thumbv7m-none-eabi\\debug\\build\\myapp-b0e16e01c22428a8\\out" "-L" "C:\\Users\\danie_000\\Code\\RE\\ABC\\target\\thumbv7m-none-eabi\\debug\\build\\cortex-m-765dfe6812e223ce\\out" "-L" "C:\\Users\\danie_000\\Code\\RE\\ABC\\target\\thumbv7m-none-eabi\\debug\\build\\cortex-m-rt-1387b5ad4b26cfa2\\out" "-L" "C:\\Users\\danie_000\\Code\\RE\\ABC\\target\\thumbv7m-none-eabi\\debug\\build\\cortex-m-semihosting-cb2469f22b42a1d7\\out" "-L" "C:\\Users\\danie_000\\.rustup\\toolchains\\beta-x86_64-pc-windows-msvc\\lib\\rustlib\\thumbv7m-none-eabi\\lib" "-Bstatic" "C:\\Users\\danie_000\\Code\\RE\\XYZ\\target\\thumbv7m-none-eabi\\debug\\deps\\libcortex_m_rt-03e440f58d1c0555.rlib" "C:\\Users\\danie_000\\Code\\RE\\XYZ\\target\\thumbv7m-none-eabi\\debug\\deps\\libr0-e3b5285d82ebc9ad.rlib" "--start-group" "C:\\Users\\danie_000\\Code\\RE\\XYZ\\target\\thumbv7m-none-eabi\\debug\\deps\\libpanic_halt-8d085ea03dce307c.rlib" "C:\\Users\\danie_000\\.rustup\\toolchains\\beta-x86_64-pc-windows-msvc\\lib\\rustlib\\thumbv7m-none-eabi\\lib\\libcore-47bba88e05b648a7.rlib" "--end-group" "C:\\Users\\danie_000\\.rustup\\toolchains\\beta-x86_64-pc-windows-msvc\\lib\\rustlib\\thumbv7m-none-eabi\\lib\\libcompiler_builtins-1eaa5842cd3f5019.rlib" "-Tlink.x" "-Bdynamic" = note: rust-lld: error: cannot find linker script link.x error: aborting due to previous error error: Could not compile `myapp`. Caused by: process didn't exit successfully: `rustc --edition=2018 --crate-name myapp src\main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=7f9cdf275b22bd50 -C extra-filename=-7f9cdf275b22bd50 --out-dir C:\Users\danie_000\Code\RE\XYZ\target\thumbv7m-none-eabi\debug\deps --target thumbv7m-none-eabi -C incremental=C:\Users\danie_000\Code\RE\XYZ\target\thumbv7m-none-eabi\debug\incremental -L dependency=C:\Users\danie_000\Code\RE\XYZ\target\thumbv7m-none-eabi\debug\deps -L dependency=C:\Users\danie_000\Code\RE\XYZ\target\debug\deps --extern cortex_m=C:\Users\danie_000\Code\RE\XYZ\target\thumbv7m-none-eabi\debug\deps\libcortex_m-6d95ef6e4550c4c8.rlib --extern cortex_m_rt=C:\Users\danie_000\Code\RE\XYZ\target\thumbv7m-none-eabi\debug\deps\libcortex_m_rt-03e440f58d1c0555.rlib --extern cortex_m_semihosting=C:\Users\danie_000\Code\RE\XYZ\target\thumbv7m-none-eabi\debug\deps\libcortex_m_semihosting-26e2b9dfbd5c7e3b.rlib --extern panic_halt=C:\Users\danie_000\Code\RE\XYZ\target\thumbv7m-none-eabi\debug\deps\libpanic_halt-8d085ea03dce307c.rlib -C link-arg=-Tlink.x -L C:\Users\danie_000\Code\RE\XYZ\target\thumbv7m-none-eabi\debug\build\myapp-b0e16e01c22428a8\out -L C:\Users\danie_000\Code\RE\ABC\target\thumbv7m-none-eabi\debug\build\cortex-m-765dfe6812e223ce\out -L C:\Users\danie_000\Code\RE\ABC\target\thumbv7m-none-eabi\debug\build\cortex-m-rt-1387b5ad4b26cfa2\out -L C:\Users\danie_000\Code\RE\ABC\target\thumbv7m-none-eabi\debug\build\cortex-m-semihosting-cb2469f22b42a1d7\out` (exit code: 1) PS C:\Users\danie_000\Code\RE\XYZ>
I (@ExpHP) tried it myself and can easily reproduce it on linux, so it is not just a Windows thing. The build scripts involved are also innocuous, making correct use of std::env::var("OUT_DIR")
and emitting basic cargo linker flags.
To reproduce:
rustup target add thumbv7m-none-eabi
- generate a project from the
cortex-m-quickstart
template (or clone it and fix up the Cargo.toml) - ^^ do what the OP did in the above quote ^^
Thoughts:
To my best understanding, cargo
normally has no problem with the absolute paths that appear in build script cargo:
directives because it stores the current path at the time of build to target/build/(unique-name)/root-output
; future builds use this to correct the paths that are in the cached stdout from the script.
Looking at the build artefacts for clues, I notice that the build scripts' output is saved at
/home/lampam/asd/clone/original-name/target/thumbv7m-none-eabi/debug/build
but the root-output
files for the build scripts contain
/home/lampam/asd/clone/original-name/target/debug
which is not a prefix of that path.
Activity