Skip to content

Commit bef2beb

Browse files
authored
Merge pull request #12 from xoviat/build
fix library naming
2 parents 1efd921 + a58297c commit bef2beb

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

stm32-bindings-gen/res/build.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
1-
use std::env;
2-
use std::path::PathBuf;
1+
use std::path::{Path, PathBuf};
2+
use std::{env, fs, io};
3+
4+
fn add_dir(src: &Path) -> io::Result<()> {
5+
println!("cargo:rustc-link-search=native={}", src.to_str().unwrap());
6+
7+
for entry in fs::read_dir(src)? {
8+
let entry = entry?;
9+
let path = entry.path();
10+
if path.is_dir() {
11+
add_dir(&path)?;
12+
}
13+
}
14+
Ok(())
15+
}
316

417
fn main() {
518
let crate_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
19+
let lib_dir = crate_dir.join("src").join("lib");
20+
21+
add_dir(&lib_dir).unwrap();
22+
23+
// TODO: link libraries based on features
624

7-
println!(
8-
"cargo:rustc-link-search=native={}",
9-
crate_dir.join("src").join("lib").to_str().unwrap()
10-
);
1125
println!("cargo:rustc-link-lib=wba_mac_lib");
26+
println!("cargo:rustc-link-lib=WBA5_LinkLayer15_4");
1227
}

stm32-bindings-gen/src/lib.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,10 @@ impl Gen {
313313
let dst = self.opts.out_dir.join(artifact.destination);
314314

315315
if src.is_file() {
316-
self.copy_file(&src, &dst)
316+
self.copy_file(&src, &dst, true)
317317
.unwrap_or_else(|err| panic!("Failed to copy file {}: {err}", src.display()));
318318
} else if src.is_dir() {
319-
self.copy_dir(&src, &dst)
319+
self.copy_dir(&src, &dst, true)
320320
.unwrap_or_else(|err| panic!("Failed to copy dir {}: {err}", src.display()));
321321
} else {
322322
panic!(
@@ -357,15 +357,24 @@ impl Gen {
357357
}
358358
}
359359

360-
fn copy_file(&self, src: &Path, dst: &Path) -> io::Result<()> {
360+
fn copy_file(&self, src: &Path, dst: &Path, is_library: bool) -> io::Result<()> {
361361
if let Some(parent) = dst.parent() {
362362
fs::create_dir_all(parent)?;
363363
}
364+
365+
let dst = if is_library {
366+
dst.parent()
367+
.unwrap()
368+
.join("lib".to_owned() + dst.file_name().unwrap().to_str().unwrap())
369+
} else {
370+
dst.to_path_buf()
371+
};
372+
364373
fs::copy(src, dst)?;
365374
Ok(())
366375
}
367376

368-
fn copy_dir(&self, src: &Path, dst: &Path) -> io::Result<()> {
377+
fn copy_dir(&self, src: &Path, dst: &Path, is_library: bool) -> io::Result<()> {
369378
if !dst.exists() {
370379
fs::create_dir_all(dst)?;
371380
}
@@ -374,9 +383,9 @@ impl Gen {
374383
let path = entry.path();
375384
let target = dst.join(entry.file_name());
376385
if path.is_dir() {
377-
self.copy_dir(&path, &target)?;
386+
self.copy_dir(&path, &target, is_library)?;
378387
} else {
379-
self.copy_file(&path, &target)?;
388+
self.copy_file(&path, &target, is_library)?;
380389
}
381390
}
382391
Ok(())

0 commit comments

Comments
 (0)