From 607784fc298398068fc56a1262af206f75acd59a Mon Sep 17 00:00:00 2001 From: Rust Enthusiast Date: Thu, 16 Mar 2023 14:42:28 -0500 Subject: [PATCH] Use `build-target` for `nstd.os.unix.alloc`. --- Cargo.toml | 3 ++- build.rs | 56 ++++++++++++++++++++++++++++-------------------------- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8796ec0..c64d1a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,7 +41,7 @@ nstd_io = ["nstd_alloc", "nstd_core", "nstd_os_unix_io", "nstd_string", "nstd_ve nstd_math = ["std"] nstd_mutex = ["nstd_core", "nstd_heap_ptr", "std"] nstd_os = ["windows-sys"] -nstd_os_unix_alloc = ["cc", "nstd_core", "nstd_os"] +nstd_os_unix_alloc = ["build-target", "cc", "nstd_core", "nstd_os"] nstd_os_unix_io = ["errno", "libc", "nstd_alloc", "nstd_core", "nstd_os", "nstd_string", "nstd_vec"] nstd_os_unix_mutex = [ "libc", "nstd_core", "nstd_heap_ptr", "nstd_os", "nstd_os_unix_time", "nstd_thread" @@ -75,4 +75,5 @@ errno = { version = "0.3", optional = true, default-features = false } windows-sys = { version = "0.45", optional = true, features = ["Win32_Foundation"] } [build-dependencies] +build-target = { version = "0.4", optional = true } cc = { version = "1.0", optional = true } diff --git a/build.rs b/build.rs index aa91473..70ed40a 100644 --- a/build.rs +++ b/build.rs @@ -16,27 +16,26 @@ struct CModule { } impl CModule { /// Compiles and links the C/C++ module. + #[cfg(feature = "cc")] fn build(self) { - #[cfg(feature = "cc")] - { - use cc::Build; - if std::env::var("DOCS_RS").is_err() { - // Create the compiler. - let mut cc = Build::new(); - // Add compiler flags. - for flag in self.flags { - cc.flag_if_supported(flag); - } - // Compile. - cc.flag_if_supported("-pedantic-errors") - .flag_if_supported("/permissive-") - .include("include") - .warnings(true) - .extra_warnings(true) - .cpp(self.cpp) - .files(self.src) - .compile(self.name); + use cc::Build; + if std::env::var("DOCS_RS").is_err() { + // Create the compiler. + let mut cc = Build::new(); + // Add compiler flags. + for flag in self.flags { + cc.flag_if_supported(flag); } + // Disable compiler extensions. + cc.flag_if_supported("-pedantic-errors") + .flag_if_supported("/permissive-"); + // Compile. + cc.include("include") + .warnings(true) + .extra_warnings(true) + .cpp(self.cpp) + .files(self.src) + .compile(self.name); } } } @@ -47,20 +46,23 @@ fn main() { println!("cargo:rerun-if-changed=include/*"); #[cfg(feature = "nstd_os_unix_alloc")] { - let nstd_os_unix_alloc = CModule { - name: "nstd_os_unix_alloc", - src: &["src/os/unix/alloc.c"], - flags: &["-std=c99", "/std:c99"], - ..Default::default() - }; - nstd_os_unix_alloc.build(); + use build_target::Family; + if build_target::target_family() == Ok(Family::Unix) { + let nstd_os_unix_alloc = CModule { + name: "nstd_os_unix_alloc", + src: &["src/os/unix/alloc.c"], + flags: &["-std=c99", "/std:c11"], + ..Default::default() + }; + nstd_os_unix_alloc.build(); + } } #[cfg(feature = "nstd_timed_mutex")] { let nstd_timed_mutex = CModule { name: "nstd_timed_mutex", src: &["src/timed_mutex.cpp"], - flags: &["-std=c++11", "/std:c++11"], + flags: &["-std=c++11", "/std:c++14"], cpp: true, ..Default::default() };