-
Notifications
You must be signed in to change notification settings - Fork 2.6k
cdylib extra link args apply to unit tests #12663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm pretty sure this is not the intended behavior for |
@weihanglo Is this cargo behaviour intended or is it a bug for |
It sounds absolutely like what ehuss said, and I have no doubt in their memory of Cargo's history. |
<!-- Thanks for submitting a pull request 🎉! Here are some tips for you: * If this is your first contribution, read "Cargo Contribution Guide" first: https://doc.crates.io/contrib/ * Run `cargo fmt --all` to format your code changes. * Small commits and pull requests are always preferable and easy to review. * If your idea is large and needs feedback from the community, read how: https://doc.crates.io/contrib/process/#working-on-large-features * Cargo takes care of compatibility. Read our design principles: https://doc.crates.io/contrib/design.html * When changing help text of cargo commands, follow the steps to generate docs: https://github.com/rust-lang/cargo/tree/master/src/doc#building-the-man-pages * If your PR is not finished, set it as "draft" PR or add "WIP" in its title. * It's ok to use the CI resources to test your PR, but please don't abuse them. ### What does this PR try to resolve? Explain the motivation behind this change. A clear overview along with an in-depth explanation are helpful. You can use `Fixes #<issue number>` to associate this PR to an existing issue. ### How should we test and review this PR? Demonstrate how you test this change and guide reviewers through your PR. With a smooth review process, a pull request usually gets reviewed quicker. If you don't know how to write and run your tests, please read the guide: https://doc.crates.io/contrib/tests ### Additional information Other information you want to mention in this PR, such as prior arts, future extensions, an unresolved problem, or a TODO list. --> fixes #12663
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: