cdylib extra link args apply to unit tests #12663
Labels
A-build-scripts
Area: build.rs scripts
A-linkage
Area: linker issues, dylib, cdylib, shared libraries, so
C-bug
Category: bug
S-needs-team-input
Status: Needs input from team on whether/how to proceed.
Problem
According to The Cargo Book, the
build.rs
file can emit thecargo:rustc-link-arg-cdylib=FLAG
setting to have it passed to rustc as a-C link-arg=FLAG
but only when building a "cdylib library target". From the documentation, its not clear that building and running the test binaries for unittests in a cdylib crate will also apply-C link-arg=FLAG
.In my specific case, I am passing (among other linker arguments)
rustc-link-arg-cdylib=/INTEGRITYCHECK
to a cdylib crate viabuild.rs
. Doing so also passes it to the unit tests, so it makes it impossible to execute my unit tests.This is sort of the opposite problem of #10937. In that issue, they want
cargo:rustc-link-arg-tests=FLAG
to apply to unittests. In this issue, I want all the otherrustc-link-arg
variants to not apply to unit tests (or at least have some option that lets me do this).Steps
Cargo.toml
:build.rs
src/lib.rs
:empty file
cargo test
fails to run because/INTEGRITYCHECK
was passed to the unittest "targets" (Aside: are these unit test binaries considered a separate target in the world of cargo?)note:
/INTEGRITYCHECK
is an msvc-specific linker argumentPossible Solution(s)
I think a way to control whether extra link args are passed or not passed to unit tests would be a good thing. The cargo documentation could also be improved as it pretty loose with the word "tests", and the way it is worded could confuse people (like me) as to what directives apply to tests(including unittests) and what applies only to integration tests(ie. test targets?).
Note: I would be very happy if anyone knows any workaround to this issue that allows me to pass linker arguments only to the cdylib and not to the cdylib's tests.
Notes
No response
Version
The text was updated successfully, but these errors were encountered: