Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions stm32-bindings-gen/res/build.rs
Original file line number Diff line number Diff line change
@@ -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");
}
21 changes: 15 additions & 6 deletions stm32-bindings-gen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down Expand Up @@ -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)?;
}
Expand All @@ -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(())
Expand Down