From 3478c90b1b8184e2c0c97e0646f9aeba62782459 Mon Sep 17 00:00:00 2001 From: Wesley Rosenblum <55108558+WesleyRosenblum@users.noreply.github.com> Date: Thu, 21 Dec 2023 14:19:54 -0800 Subject: [PATCH] bindings: ensure CFLAGS includes come after libcrypto includes (#4338) * bindings: ensure CFLAGS includes come after libcrypto includes * Prepend cflags --- bindings/rust/s2n-tls-sys/build.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/bindings/rust/s2n-tls-sys/build.rs b/bindings/rust/s2n-tls-sys/build.rs index 8710c97b942..b7ae351986d 100644 --- a/bindings/rust/s2n-tls-sys/build.rs +++ b/bindings/rust/s2n-tls-sys/build.rs @@ -187,8 +187,18 @@ fn build_vendored() { fn builder(libcrypto: &Libcrypto) -> cc::Build { let mut build = cc::Build::new(); + if let Ok(cflags) = std::env::var("CFLAGS") { + // cc will read the CFLAGS env variable and prepend the compiler + // command with all flags and includes from it, which may conflict + // with the libcrypto includes we specify. To ensure the libcrypto + // includes show up first in the compiler command, we prepend our + // includes to CFLAGS. + std::env::set_var("CFLAGS", format!("-I {} {}", libcrypto.include, cflags)); + } else { + build.include(&libcrypto.include); + }; + build - .include(&libcrypto.include) .include("lib") .include("lib/api") .flag("-std=c11")