Skip to content

Commit

Permalink
Add way to specify target triple to run bindgen with (#8)
Browse files Browse the repository at this point in the history
Expand interface to pass in the target triple for bindgen via the environment variable  `RUST_MBEDTLS_BINDGEN_TARGET`
  • Loading branch information
nick-mobilecoin authored Apr 28, 2022
1 parent 49a293a commit 25a3c7e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions mbedtls-sys/build/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use bindgen;
use std::fmt::Write as _;
use std::fs::{self, File};
use std::io::Write;
use std::env;

use crate::headers;

Expand Down Expand Up @@ -88,6 +89,7 @@ impl super::BuildConfig {
}

let mut cc = cc::Build::new();

cc.include(&self.mbedtls_include)
.flag(&format!(
"-DMBEDTLS_CONFIG_FILE=\"{}\"",
Expand Down Expand Up @@ -116,6 +118,15 @@ impl super::BuildConfig {
};
}

// Bindgen utilizes libclang and the current `TARGET` to parse the C files.
// When the `TARGET` is custom, we need to override it so that bindgen
// finds the right stdlib headers.
// See https://docs.rust-embedded.org/embedonomicon/custom-target.html
// for more details.
if let Some(target) = env::var_os("RUST_MBEDTLS_BINDGEN_TARGET") {
env::set_var("TARGET", target);
}

let bindings = bindgen::builder()
.clang_args(cc.get_compiler().args().iter().map(|arg| arg.to_str().unwrap()))
.header_contents("bindgen-input.h", &input)
Expand Down
2 changes: 1 addition & 1 deletion mbedtls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extern crate bitflags;
#[macro_use]
extern crate serde_derive;
// required explicitly to force inclusion at link time
#[cfg(target_env = "sgx")]
#[cfg(all(target_vendor = "fortanix", target_env = "sgx"))]
extern crate rs_libc;

#[macro_use]
Expand Down

0 comments on commit 25a3c7e

Please sign in to comment.