diff options
author | Pietro Albini <pietro.albini@ferrous-systems.com> | 2022-12-14 13:36:09 +0100 |
---|---|---|
committer | Pietro Albini <pietro.albini@ferrous-systems.com> | 2023-03-06 09:39:26 +0100 |
commit | 88b7f0d991eacae483b23c6ab9ba1ed0a4a6bd43 (patch) | |
tree | 176ed2d50bc373174b9b6ffe3ef198dd781f7937 /build.rs | |
parent | da4f8f82e367c556f889992c66ec89e84c1cbf52 (diff) | |
download | rust-libc-88b7f0d991eacae483b23c6ab9ba1ed0a4a6bd43.tar.gz |
refactor build script to use a function to set cfgs
Diffstat (limited to 'build.rs')
-rw-r--r-- | build.rs | 52 |
1 files changed, 27 insertions, 25 deletions
@@ -25,94 +25,92 @@ fn main() { // On CI, we detect the actual FreeBSD version and match its ABI exactly, // running tests to ensure that the ABI is correct. match which_freebsd() { - Some(10) if libc_ci || rustc_dep_of_std => { - println!("cargo:rustc-cfg=freebsd10") - } - Some(11) if libc_ci => println!("cargo:rustc-cfg=freebsd11"), - Some(12) if libc_ci => println!("cargo:rustc-cfg=freebsd12"), - Some(13) if libc_ci => println!("cargo:rustc-cfg=freebsd13"), - Some(14) if libc_ci => println!("cargo:rustc-cfg=freebsd14"), - Some(_) | None => println!("cargo:rustc-cfg=freebsd11"), + Some(10) if libc_ci || rustc_dep_of_std => set_cfg("freebsd10"), + Some(11) if libc_ci => set_cfg("freebsd11"), + Some(12) if libc_ci => set_cfg("freebsd12"), + Some(13) if libc_ci => set_cfg("freebsd13"), + Some(14) if libc_ci => set_cfg("freebsd14"), + Some(_) | None => set_cfg("freebsd11"), } // On CI: deny all warnings if libc_ci { - println!("cargo:rustc-cfg=libc_deny_warnings"); + set_cfg("libc_deny_warnings"); } // Rust >= 1.15 supports private module use: if rustc_minor_ver >= 15 || rustc_dep_of_std { - println!("cargo:rustc-cfg=libc_priv_mod_use"); + set_cfg("libc_priv_mod_use"); } // Rust >= 1.19 supports unions: if rustc_minor_ver >= 19 || rustc_dep_of_std { - println!("cargo:rustc-cfg=libc_union"); + set_cfg("libc_union"); } // Rust >= 1.24 supports const mem::size_of: if rustc_minor_ver >= 24 || rustc_dep_of_std { - println!("cargo:rustc-cfg=libc_const_size_of"); + set_cfg("libc_const_size_of"); } // Rust >= 1.25 supports repr(align): if rustc_minor_ver >= 25 || rustc_dep_of_std || align_cargo_feature { - println!("cargo:rustc-cfg=libc_align"); + set_cfg("libc_align"); } // Rust >= 1.26 supports i128 and u128: if rustc_minor_ver >= 26 || rustc_dep_of_std { - println!("cargo:rustc-cfg=libc_int128"); + set_cfg("libc_int128"); } // Rust >= 1.30 supports `core::ffi::c_void`, so libc can just re-export it. // Otherwise, it defines an incompatible type to retaining // backwards-compatibility. if rustc_minor_ver >= 30 || rustc_dep_of_std { - println!("cargo:rustc-cfg=libc_core_cvoid"); + set_cfg("libc_core_cvoid"); } // Rust >= 1.33 supports repr(packed(N)) and cfg(target_vendor). if rustc_minor_ver >= 33 || rustc_dep_of_std { - println!("cargo:rustc-cfg=libc_packedN"); - println!("cargo:rustc-cfg=libc_cfg_target_vendor"); + set_cfg("libc_packedN"); + set_cfg("libc_cfg_target_vendor"); } // Rust >= 1.40 supports #[non_exhaustive]. if rustc_minor_ver >= 40 || rustc_dep_of_std { - println!("cargo:rustc-cfg=libc_non_exhaustive"); + set_cfg("libc_non_exhaustive"); } // Rust >= 1.47 supports long array: if rustc_minor_ver >= 47 || rustc_dep_of_std { - println!("cargo:rustc-cfg=libc_long_array"); + set_cfg("libc_long_array"); } if rustc_minor_ver >= 51 || rustc_dep_of_std { - println!("cargo:rustc-cfg=libc_ptr_addr_of"); + set_cfg("libc_ptr_addr_of"); } // Rust >= 1.37.0 allows underscores as anonymous constant names. if rustc_minor_ver >= 37 || rustc_dep_of_std { - println!("cargo:rustc-cfg=libc_underscore_const_names"); + set_cfg("libc_underscore_const_names"); } // #[thread_local] is currently unstable if rustc_dep_of_std { - println!("cargo:rustc-cfg=libc_thread_local"); + set_cfg("libc_thread_local"); } // Rust >= 1.62.0 allows to use `const_extern_fn` for "Rust" and "C". if rustc_minor_ver >= 62 { - println!("cargo:rustc-cfg=libc_const_extern_fn"); + set_cfg("libc_const_extern_fn"); } else { // Rust < 1.62.0 requires a crate feature and feature gate. if const_extern_fn_cargo_feature { if !is_nightly || rustc_minor_ver < 40 { panic!("const-extern-fn requires a nightly compiler >= 1.40"); } - println!("cargo:rustc-cfg=libc_const_extern_fn_unstable"); - println!("cargo:rustc-cfg=libc_const_extern_fn"); + set_cfg("libc_const_extern_fn_unstable"); + set_cfg("libc_const_extern_fn"); } } } @@ -181,3 +179,7 @@ fn which_freebsd() -> Option<i32> { _ => None, } } + +fn set_cfg(cfg: &str) { + println!("cargo:rustc-cfg={}", cfg); +} |