in target-spec/src/simple_eval.rs [134:217]
fn test_target_feature() {
// target features are unknown by default.
assert_eq!(
eval("cfg(target_feature = \"sse\")", "x86_64-unknown-linux-gnu"),
Ok(None),
);
assert_eq!(
eval(
"cfg(target_feature = \"atomics\")",
"x86_64-unknown-linux-gnu",
),
Ok(None),
);
assert_eq!(
eval(
"cfg(not(target_feature = \"fxsr\"))",
"x86_64-unknown-linux-gnu",
),
Ok(None),
);
fn eval_unknown(spec: &str, platform: &str) -> Option<bool> {
let platform = Platform::new(
platform.to_owned(),
TargetFeatures::features(["sse", "sse2"].iter().copied()),
)
.expect("platform should be found");
let spec: TargetSpec = spec.parse().unwrap();
spec.eval(&platform)
}
assert_eq!(
eval_unknown("cfg(target_feature = \"sse\")", "x86_64-unknown-linux-gnu"),
Some(true),
);
assert_eq!(
eval_unknown(
"cfg(not(target_feature = \"sse\"))",
"x86_64-unknown-linux-gnu",
),
Some(false),
);
assert_eq!(
eval_unknown("cfg(target_feature = \"fxsr\")", "x86_64-unknown-linux-gnu"),
Some(false),
);
assert_eq!(
eval_unknown(
"cfg(not(target_feature = \"fxsr\"))",
"x86_64-unknown-linux-gnu",
),
Some(true),
);
fn eval_all(spec: &str, platform: &str) -> Option<bool> {
let platform = Platform::new(platform.to_owned(), TargetFeatures::All)
.expect("platform should be found");
let spec: TargetSpec = spec.parse().unwrap();
spec.eval(&platform)
}
assert_eq!(
eval_all("cfg(target_feature = \"sse\")", "x86_64-unknown-linux-gnu"),
Some(true),
);
assert_eq!(
eval_all(
"cfg(not(target_feature = \"sse\"))",
"x86_64-unknown-linux-gnu",
),
Some(false),
);
assert_eq!(
eval_all("cfg(target_feature = \"fxsr\")", "x86_64-unknown-linux-gnu"),
Some(true),
);
assert_eq!(
eval_all(
"cfg(not(target_feature = \"fxsr\"))",
"x86_64-unknown-linux-gnu",
),
Some(false),
);
}