Include bindgen generated file via a build time env var, this plays nicer with other build systems like Soong and Gn.
Change-Id: I42e40da22dd243796cd735e09a9821cc2d114200
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/58785
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
diff --git a/rust/bssl-sys/CMakeLists.txt b/rust/bssl-sys/CMakeLists.txt
index 9b5c841..05f03f4 100644
--- a/rust/bssl-sys/CMakeLists.txt
+++ b/rust/bssl-sys/CMakeLists.txt
@@ -20,8 +20,6 @@
# https://doc.rust-lang.org/nightly/rustc/platform-support.html
--target=${RUST_BINDINGS})
-set(INCLUDES "include!(\"wrapper_${RUST_BINDINGS}.rs\");\n")
-
add_custom_target(
bindgen_rust_${RUST_BINDINGS}
ALL
diff --git a/rust/bssl-sys/build.rs b/rust/bssl-sys/build.rs
index 955eae3..c2b7358 100644
--- a/rust/bssl-sys/build.rs
+++ b/rust/bssl-sys/build.rs
@@ -20,6 +20,16 @@
let dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let crate_path = Path::new(&dir);
+ // Find the bindgen generated target platform bindings file and set BINDGEN_RS_FILE
+ let bindgen_file = crate_path
+ .join("src")
+ .read_dir()
+ .unwrap()
+ .map(|file| file.unwrap().file_name().into_string().unwrap())
+ .find(|file| file.starts_with("wrapper_"))
+ .unwrap();
+ println!("cargo:rustc-env=BINDGEN_RS_FILE={}", bindgen_file);
+
// building bssl-sys with: `mkdir build && cd build && cmake -G Ninja .. -DRUST_BINDINGS="$(gcc -dumpmachine)" && ninja`
// outputs this crate to /build/rust/bssl-sys/ so need to go up 3 levels to the root of the repo
let repo_root = crate_path.parent().unwrap().parent().unwrap();
diff --git a/rust/bssl-sys/src/lib.rs b/rust/bssl-sys/src/lib.rs
index d8c2c00..51ba2cf 100644
--- a/rust/bssl-sys/src/lib.rs
+++ b/rust/bssl-sys/src/lib.rs
@@ -2,8 +2,8 @@
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
-// populated by cmake
-${INCLUDES}
+// Set in build.rs
+include!(env!("BINDGEN_RS_FILE"));
pub fn ERR_GET_LIB(packed_error: u32) -> i32 {
unsafe { ERR_GET_LIB_RUST(packed_error) }
@@ -18,5 +18,7 @@
}
pub fn init() {
- unsafe { CRYPTO_library_init(); }
+ unsafe {
+ CRYPTO_library_init();
+ }
}