Skip to content

Commit

Permalink
Use build-target for nstd.os.unix.alloc.
Browse files Browse the repository at this point in the history
  • Loading branch information
RustEnthusiast committed Mar 16, 2023
1 parent baf43bb commit 607784f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 }
56 changes: 29 additions & 27 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand All @@ -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()
};
Expand Down

0 comments on commit 607784f

Please sign in to comment.