Skip to content

Commit

Permalink
Emit directives for cargo-check-cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed May 6, 2024
1 parent 2001e76 commit 1a5c2fb
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{collections::BTreeMap, env, sync::atomic::Ordering};

fn main() {
println!("cargo:rerun-if-changed=build.rs");
configure_check_cfg();

let target = env::var("TARGET").unwrap();
let cwd = env::current_dir().unwrap();
Expand Down Expand Up @@ -145,6 +146,46 @@ fn generate_aarch64_outlined_atomics() {
std::fs::write(dst, buf).unwrap();
}

/// Emit directives for features we expect to support that aren't in `Cargo.toml`
fn configure_check_cfg() {
// Functions where we can set the "optimized-c" flag
const HAS_OPTIMIZED_C: &[&str] = &[
"__ashldi3",
"__ashlsi3",
"__ashrdi3",
"__ashrsi3",
"__clzsi2",
"__divdi3",
"__divmoddi4",
"__divmodsi4",
"__divmodsi4",
"__divmodti4",
"__lshrdi3",
"__lshrsi3",
"__moddi3",
"__modsi3",
"__muldi3",
"__udivdi3",
"__udivmoddi4",
"__udivmodsi4",
"__udivsi3",
"__umoddi3",
"__umodsi3",
];

for fn_name in HAS_OPTIMIZED_C {
println!(
"cargo::rustc-check-cfg=cfg({}, values(\"optimized-c\"))",
fn_name
);
}

println!("cargo::rustc-check-cfg=cfg(feature, values(\"mem-unaligned\")");
println!("cargo::rustc-check-cfg=cfg(feature, values(\"unstable\")");
println!("cargo::rustc-check-cfg=cfg(assert_no_panic)");
println!("cargo::rustc-check-cfg=cfg(kernel_user_helpers)");
}

#[cfg(feature = "c")]
mod c {
extern crate cc;
Expand Down

0 comments on commit 1a5c2fb

Please sign in to comment.