From a58297c61013ca7feca1bf0f886d57e3b22bcbc5 Mon Sep 17 00:00:00 2001 From: xoviat Date: Thu, 4 Dec 2025 21:01:03 -0600 Subject: [PATCH] fix library naming --- stm32-bindings-gen/res/build.rs | 27 +++++++++++++++++++++------ stm32-bindings-gen/src/lib.rs | 21 +++++++++++++++------ 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/stm32-bindings-gen/res/build.rs b/stm32-bindings-gen/res/build.rs index 7f8db90..545ca82 100644 --- a/stm32-bindings-gen/res/build.rs +++ b/stm32-bindings-gen/res/build.rs @@ -1,12 +1,27 @@ -use std::env; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; +use std::{env, fs, io}; + +fn add_dir(src: &Path) -> io::Result<()> { + println!("cargo:rustc-link-search=native={}", src.to_str().unwrap()); + + for entry in fs::read_dir(src)? { + let entry = entry?; + let path = entry.path(); + if path.is_dir() { + add_dir(&path)?; + } + } + Ok(()) +} fn main() { let crate_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap()); + let lib_dir = crate_dir.join("src").join("lib"); + + add_dir(&lib_dir).unwrap(); + + // TODO: link libraries based on features - println!( - "cargo:rustc-link-search=native={}", - crate_dir.join("src").join("lib").to_str().unwrap() - ); println!("cargo:rustc-link-lib=wba_mac_lib"); + println!("cargo:rustc-link-lib=WBA5_LinkLayer15_4"); } diff --git a/stm32-bindings-gen/src/lib.rs b/stm32-bindings-gen/src/lib.rs index 3ff68c0..43b4e13 100644 --- a/stm32-bindings-gen/src/lib.rs +++ b/stm32-bindings-gen/src/lib.rs @@ -313,10 +313,10 @@ impl Gen { let dst = self.opts.out_dir.join(artifact.destination); if src.is_file() { - self.copy_file(&src, &dst) + self.copy_file(&src, &dst, true) .unwrap_or_else(|err| panic!("Failed to copy file {}: {err}", src.display())); } else if src.is_dir() { - self.copy_dir(&src, &dst) + self.copy_dir(&src, &dst, true) .unwrap_or_else(|err| panic!("Failed to copy dir {}: {err}", src.display())); } else { panic!( @@ -357,15 +357,24 @@ impl Gen { } } - fn copy_file(&self, src: &Path, dst: &Path) -> io::Result<()> { + fn copy_file(&self, src: &Path, dst: &Path, is_library: bool) -> io::Result<()> { if let Some(parent) = dst.parent() { fs::create_dir_all(parent)?; } + + let dst = if is_library { + dst.parent() + .unwrap() + .join("lib".to_owned() + dst.file_name().unwrap().to_str().unwrap()) + } else { + dst.to_path_buf() + }; + fs::copy(src, dst)?; Ok(()) } - fn copy_dir(&self, src: &Path, dst: &Path) -> io::Result<()> { + fn copy_dir(&self, src: &Path, dst: &Path, is_library: bool) -> io::Result<()> { if !dst.exists() { fs::create_dir_all(dst)?; } @@ -374,9 +383,9 @@ impl Gen { let path = entry.path(); let target = dst.join(entry.file_name()); if path.is_dir() { - self.copy_dir(&path, &target)?; + self.copy_dir(&path, &target, is_library)?; } else { - self.copy_file(&path, &target)?; + self.copy_file(&path, &target, is_library)?; } } Ok(())