Skip to content

Commit

Permalink
Merge pull request #371 from irajtaghlidi/bazel-compatible
Browse files Browse the repository at this point in the history
Explicitly indicate *static* linking to mbedtls C libraries (for Bazel compatibility)
  • Loading branch information
Pagten authored Nov 11, 2024
2 parents 5da749c + f43ba5d commit 0e5891d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
2 changes: 1 addition & 1 deletion mbedtls-sys/build/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl super::BuildConfig {
if cc.get_compiler().is_like_msvc() {
cc.flag("--driver-mode=cl");
}
cc.include(&self.mbedtls_include).define(
cc.include(&self.out_dir.join("include")).define(
"MBEDTLS_CONFIG_FILE",
Some(format!(r#""{}""#, self.config_h.to_str().expect("config.h UTF-8 error")).as_str()),
);
Expand Down
3 changes: 0 additions & 3 deletions mbedtls-sys/build/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use std::path::{Path, PathBuf};
struct BuildConfig {
out_dir: PathBuf,
mbedtls_src: PathBuf,
mbedtls_include: PathBuf,
config_h: PathBuf,
cflags: Vec<String>,
}
Expand Down Expand Up @@ -83,7 +82,6 @@ impl BuildConfig {
let out_dir = PathBuf::from(env::var_os("OUT_DIR").expect("OUT_DIR environment not set?"));
let config_h = out_dir.join("config.h");
let mbedtls_src = PathBuf::from(env::var("RUST_MBEDTLS_SYS_SOURCE").unwrap_or("vendor".to_owned()));
let mbedtls_include = mbedtls_src.join("include");

let mut cflags = vec![];
if FEATURES.have_platform_component("c_compiler", "freestanding") {
Expand All @@ -97,7 +95,6 @@ impl BuildConfig {
config_h,
out_dir,
mbedtls_src,
mbedtls_include,
cflags,
}
}
Expand Down
17 changes: 6 additions & 11 deletions mbedtls-sys/build/cmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,20 @@ impl super::BuildConfig {
cmk.define("CMAKE_TRY_COMPILE_TARGET_TYPE", "STATIC_LIBRARY");
}

let mut dst = cmk.build();
let dst = cmk.build();

dst.push("lib");
println!(
"cargo:rustc-link-search=native={}",
dst.to_str().expect("link-search UTF-8 error")
dst.join("lib").to_str().expect("link-search UTF-8 error")
);

println!("cargo:rustc-link-lib=mbedtls");
println!("cargo:rustc-link-lib=mbedx509");
println!("cargo:rustc-link-lib=mbedcrypto");
println!("cargo:rustc-link-lib=static=mbedtls");
println!("cargo:rustc-link-lib=static=mbedx509");
println!("cargo:rustc-link-lib=static=mbedcrypto");

println!(
"cargo:include={}",
::std::env::current_dir()
.unwrap()
.join(&self.mbedtls_include)
.to_str()
.expect("include/ UTF-8 error")
dst.join("include").to_str().expect("include/ UTF-8 error")
);
println!("cargo:config_h={}", self.config_h.to_str().expect("config.h UTF-8 error"));
}
Expand Down

0 comments on commit 0e5891d

Please sign in to comment.