Skip to content
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

How can I pass some compiler flags to certain crates? #10014

Closed
fCorleone opened this issue Oct 27, 2021 · 2 comments
Closed

How can I pass some compiler flags to certain crates? #10014

fCorleone opened this issue Oct 27, 2021 · 2 comments
Labels
A-rustflags Area: rustflags C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@fCorleone
Copy link

Problem

I want to compile a project with cargo build. This project has one binary and several libraries. I would like to pass some compiler flags such as llvm-args=-sanitizer-coverage-level=2 to certain crates. If I change the environment variable: RUSTFLAGS, all the dependencies will also be passed with the flags. Is there a way?

Proposed Solution

No response

Notes

No response

@fCorleone fCorleone added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Oct 27, 2021
@alexcrichton
Copy link
Member

Currently there is no method of doing this, RUSTFLAGS applies to all crates. There is not a method to select flags for only some crates (except for the very last one through cargo rustc -- --custom-flag

@weihanglo
Copy link
Member

weihanglo commented Feb 19, 2023

The unstable profile rustflags feature can help this. For example

[profile.dev.package.foo]
opt-level = 3
rustflags = [ "-C", "..." ]

Let's track its progress over there #10271. Closing and thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustflags Area: rustflags C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

No branches or pull requests

4 participants