Skip to content

Commit

Permalink
[eclipse-iceoryx#433] support ICEORYX2_CLANG_ARG for build.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuschen committed Oct 7, 2024
1 parent 6f05b7b commit 194105d
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions iceoryx2-pal/posix/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ use bindgen::*;
use std::env;
use std::path::PathBuf;

// ICEORYX2_CLANG_ARG is used to specify the clang_arg for bindgen.
const ICEORYX2_CLANG_ARG: &str = "ICEORYX2_CLANG_ARG";

fn main() {
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
println!("cargo:rustc-link-lib=pthread");
Expand All @@ -25,8 +28,18 @@ fn main() {
println!("cargo:rustc-link-lib=acl");
println!("cargo:rerun-if-changed=src/c/posix.h");


if !cc::Build::new().get_compiler().is_like_clang() {
println!("cargo:warning=Clang is not available, you may set up environment {} to avoid missing some headers.", ICEORYX2_CLANG_ARG);
}

let mut builder = bindgen::Builder::default();
if let Ok(value) = env::var(ICEORYX2_CLANG_ARG) {
builder = builder.clang_arg(format!("-I{}", value));
}

let bindings = if std::env::var("DOCS_RS").is_ok() {
bindgen::Builder::default()
builder
.header("src/c/posix.h")
.blocklist_type("max_align_t")
.parse_callbacks(Box::new(CargoCallbacks::new()))
Expand All @@ -37,7 +50,7 @@ fn main() {
} else {
#[cfg(not(feature = "acl"))]
{
bindgen::Builder::default()
builder
.header("src/c/posix.h")
.blocklist_type("max_align_t")
.parse_callbacks(Box::new(CargoCallbacks::new()))
Expand Down

0 comments on commit 194105d

Please sign in to comment.