Skip to content

Commit f745e7d

Browse files
committed
Conditionally add _DARWIN_C_SOURCE define
1 parent e8b6dd0 commit f745e7d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

aws-lc-sys/builder/cc_builder.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ impl CcBuilder {
222222
}
223223
}
224224

225+
if target_os() == "macos" {
226+
// Certain MacOS system headers are guarded by _POSIX_C_SOURCE and _DARWIN_C_SOURCE
227+
build_options.push(BuildOption::define("_DARWIN_C_SOURCE", "1"));
228+
}
229+
225230
let opt_level = cargo_env("OPT_LEVEL");
226231
match opt_level.as_str() {
227232
"0" | "1" | "2" => {
@@ -391,8 +396,6 @@ impl CcBuilder {
391396
let mut new_cflags = original_cflags.clone();
392397
// The `_FORTIFY_SOURCE` macro often requires optimizations to also be enabled, so unset it.
393398
new_cflags.push_str(" -O0 -Wp,-U_FORTIFY_SOURCE");
394-
// Certain MacOS system headers are guarded by _POSIX_C_SOURCE and _DARWIN_C_SOURCE
395-
new_cflags.push_str(" -D_DARWIN_C_SOURCE");
396399
set_env_for_target("CFLAGS", &new_cflags);
397400
// cc-rs currently prioritizes flags provided by CFLAGS over the flags provided by the build script.
398401
// The environment variables used by the compiler are set when `get_compiler` is called.
@@ -404,6 +407,10 @@ impl CcBuilder {
404407
};
405408

406409
je_builder.define("AWSLC", "1");
410+
if target_os() == "macos" {
411+
// Certain MacOS system headers are guarded by _POSIX_C_SOURCE and _DARWIN_C_SOURCE
412+
je_builder.define("_DARWIN_C_SOURCE", "1");
413+
}
407414
je_builder.pic(true);
408415
if target_os() == "windows" && compiler.is_like_msvc() {
409416
je_builder.flag("/Od").flag("/W4").flag("/DYNAMICBASE");

0 commit comments

Comments
 (0)