-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect retpolines in build.rs as cfg is never set for them. Fixes #46
- Loading branch information
1 parent
2862c14
commit db10ec5
Showing
2 changed files
with
26 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
fn main() { | ||
// retpolines are not yet recognized by rust as a regular target feature. | ||
// We can't detect them with `cfg(target_feature = "retpoline")`, but we can detect them in | ||
// rustflags, since they shouldn't be the default for any target. | ||
let rustflags = std::env::var("CARGO_ENCODED_RUSTFLAGS").unwrap(); | ||
let retpolines_enabled = rustflags.split('\x1f').any(|flag| { | ||
let features = flag | ||
.strip_prefix("target-feature=") | ||
.or(flag.strip_prefix("-Ctarget-feature=")); | ||
if let Some(features) = features { | ||
features | ||
.split(',') | ||
.any(|feature| feature.starts_with("+retpoline")) | ||
} else { | ||
false | ||
} | ||
}); | ||
|
||
if retpolines_enabled { | ||
println!("cargo::rustc-cfg=retpoline") | ||
} | ||
println!("cargo::rustc-check-cfg=cfg(retpoline)"); | ||
println!("cargo::rerun-if-changed=build.rs"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters