From e5a93d7b16ec637dc322cebff1a9a80e7a197abe Mon Sep 17 00:00:00 2001 From: ckrenslehner Date: Sat, 28 Dec 2024 16:41:25 +0100 Subject: [PATCH] build: generate bindings via bindgen cli --- justfile | 2 ++ stm32cubeprogrammer-sys/build.rs | 25 ------------------------- stm32cubeprogrammer-sys/justfile | 11 +++++++++++ 3 files changed, 13 insertions(+), 25 deletions(-) delete mode 100644 stm32cubeprogrammer-sys/build.rs create mode 100644 stm32cubeprogrammer-sys/justfile diff --git a/justfile b/justfile index 9fbe898..3102b7d 100644 --- a/justfile +++ b/justfile @@ -7,6 +7,8 @@ shebang := if os() == 'windows' { '/usr/bin/env nu' } +import 'stm32cubeprogrammer-sys/justfile' + # List all the recipes default: just -l diff --git a/stm32cubeprogrammer-sys/build.rs b/stm32cubeprogrammer-sys/build.rs deleted file mode 100644 index c0bca44..0000000 --- a/stm32cubeprogrammer-sys/build.rs +++ /dev/null @@ -1,25 +0,0 @@ -use std::path::PathBuf; - -const STM32_CUBE_PROGRAMMER_API_PATH: &str = "include/CubeProgrammer_API.h"; - -#[cfg(windows)] -const BINDINGS_FILE_NAME: &str = "bindings_windows.rs"; -#[cfg(unix)] -const BINDINGS_FILE_NAME: &str = "bindings_unix.rs"; - -fn main() { - let bindings = bindgen::Builder::default() - .header(STM32_CUBE_PROGRAMMER_API_PATH) - .clang_arg("-x") - .clang_arg("c++") - // Configure bindgen to generate libloading bindings - .dynamic_library_name("CubeProgrammer_API") - .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) - .generate() - .expect("Unable to generate bindings"); - - let out_path = PathBuf::from("src").join(BINDINGS_FILE_NAME); - bindings - .write_to_file(out_path) - .expect("Couldn't write bindings!"); -} diff --git a/stm32cubeprogrammer-sys/justfile b/stm32cubeprogrammer-sys/justfile new file mode 100644 index 0000000..ebb1b14 --- /dev/null +++ b/stm32cubeprogrammer-sys/justfile @@ -0,0 +1,11 @@ +bindgen_header := "include/CubeProgrammer_API.h" + +bindgen_output := if os() == 'windows' { + "src/bindings_windows.rs" +} else { + "src/bindings_unix.rs" +} + +# Generate bindings for the CubeProgrammer API dynamic library +generate-bindings: + bindgen {{source_directory()}}/{{bindgen_header}} --dynamic-loading CubeProgrammer_API --output {{source_directory()}}/{{bindgen_output}} -- -x c++ \ No newline at end of file