Description
Problem
This is the exact same bug as #10744 except with regards to linker
and links
instead of rustflags
and rustdocflags
. When building with target-applies-to-host=false
and not passing a --target
flag linker
and links
are ignored because the host-values of those are set to the default and then the artifact units end up picking up the host values (see "How it is implemented" in #13900 for an explanation of how that happens).
Steps
Running on x86_64-unknown-linux-gnu (if you have a different host substitute in the correct architecture)
cargo new demo
cd demo
cargo build -Z target-applies-to-host --config target-applies-to-host=false --config target.x86_64-unknown-linux-gnu.linker="\"nope\""
Expected behavior: error: linker `nope` not found
Actual behavior: It builds without error
cargo new demo
cd demo
echo "int myfunc() {}" | gcc -xc -shared -o libmylib.so -
sed -i '/\[package\]/a links="mylib"' Cargo.toml
echo 'fn main() { panic!("build.rs run") }' > build.rs
cargo build \
--config 'target.x86_64-unknown-linux-gnu.mylib.rustc-link-lib=["mylib"]' \
--config 'target.x86_64-unknown-linux-gnu.mylib.rustc-link-search=["native=."]' \
-Z target-applies-to-host \
--config target-applies-to-host=false
Expected behavior: It builds without error
Expected bug: It fails to find mylib
Actual behavior:
Creating binary (application) `demo` package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
thread 'main' panicked at src/cargo/core/compiler/custom_build.rs:256:10:
running a script not depending on an actual script
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
I.e. cargo crashes as a whole instead of just failing to apply the flags. This only happens in the case where target-applies-to-host=false and no --target flag is passed so it's likely a side effect of failing to apply the flags, but that should be confirmed. I am confident it does fail to apply the flags as well from having been working on the code.
Possible Solution(s)
Extend the fix in #13900 to linker
and link overrides. That should fix the expected bugs, but the actual behavior of link overrides causing cargo to panic is a surprise to me and might need something further.