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

Automatically pass /guard:cf to MSVC compiler when Control Flow Guard is enabled in rustc flags #557

Open
roblabla opened this issue Nov 2, 2020 · 1 comment

Comments

@roblabla
Copy link
Contributor

roblabla commented Nov 2, 2020

This is a bit of a longshot, and I'm not sure if it makes sense. When compiling with -C control-flow-guard=yes, it'd be really cool if C code build with cc-rs was automatically built with the equivalent flag (e.g. /guard:cf). This would allow projects to get an almost complete protection just by setting a variable in their .cargo/config file, instead of having to manually set the appropriate environment variable (which requires some kind of build orchestration tool on top of cargo to automatically set the variable, as I don't think cargo has any way to set environment variables on its own for the whole build?).

I'm not sure if this can be achieved in a practical way though. For one, I'm not entirely sure if build scripts have a reliable way of getting the target RUSTFLAGS, or otherwise knowing whether control-flow-guard is enabled.

@alexcrichton
Copy link
Member

Sounds reasonable to me! I'd be happy to take a PR for this.

Perhaps the easiest way for us to detect this is if rustc set a #[cfg] when CFG is enabled, that way we could look for CARGO_CFG_* and see if it's enabled or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants