Skip to content

Commit 1cc6ff5

Browse files
authored
Merge pull request #13 from xoviat/build
fix lib selection and bump version
2 parents bef2beb + 3e2bd0d commit 1cc6ff5

File tree

3 files changed

+55
-19
lines changed

3 files changed

+55
-19
lines changed

stm32-bindings-gen/res/Cargo.toml

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "stm32-bindings"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
edition = "2024"
55
license = "MIT OR Apache-2.0"
66
repository = "https://github.com/embassy-rs/stm32-data"
@@ -73,4 +73,36 @@ defmt = ["dep:defmt"]
7373

7474
rt = ["cortex-m-rt/device"]
7575

76-
# Chip-selection features
76+
# Library selection features
77+
78+
lib_wba5_linklayer_ble_basic_20_links_lib = []
79+
lib_wba5_linklayer_ble_basic_lib = []
80+
lib_wba5_linklayer_ble_basic_plus_20_links_lib = []
81+
lib_wba5_linklayer_ble_basic_plus_lib = []
82+
lib_wba5_linklayer_ble_full_lib = []
83+
lib_wba5_linklayer_ble_mac_lib = []
84+
lib_wba5_linklayer_ble_peripheral_only_lib = []
85+
lib_wba5_linklayer_ble_thread_lib = []
86+
lib_wba5_linklayer_rawmac_lib = []
87+
lib_wba5_linklayer_thread_lib = []
88+
lib_wba5_linklayer15_4 = []
89+
lib_wba6_linklayer_ble_basic_20_links_lib = []
90+
lib_wba6_linklayer_ble_basic_lib = []
91+
lib_wba6_linklayer_ble_basic_plus_20_links_lib = []
92+
lib_wba6_linklayer_ble_basic_plus_lib = []
93+
lib_wba6_linklayer_ble_full_lib = []
94+
lib_wba6_linklayer_ble_mac_lib = []
95+
lib_wba6_linklayer_ble_peripheral_only_lib = []
96+
lib_wba6_linklayer_ble_thread_lib = []
97+
lib_wba6_linklayer_rawmac_lib = []
98+
lib_wba6_linklayer_thread_lib = []
99+
lib_wba6_linklayer15_4 = []
100+
lib_wba_mac_lib = []
101+
lib_stm32wba_ble_stack_po = []
102+
lib_stm32wba_ble_stack_llo = []
103+
lib_stm32wba_ble_stack_full = []
104+
lib_stm32wba_ble_stack_basic = []
105+
lib_stm32wba_ble_stack_basic_plus = []
106+
lib_lc3 = []
107+
lib_codec_mngr = []
108+
lib_ble_audio = []

stm32-bindings-gen/res/build.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ fn main() {
2020

2121
add_dir(&lib_dir).unwrap();
2222

23-
// TODO: link libraries based on features
24-
25-
println!("cargo:rustc-link-lib=wba_mac_lib");
26-
println!("cargo:rustc-link-lib=WBA5_LinkLayer15_4");
23+
env::vars()
24+
.filter_map(|(a, _)| a.strip_prefix("CARGO_FEATURE_LIB_").map(|a| a.to_string()))
25+
.map(|a| a.to_ascii_lowercase())
26+
.for_each(|a| println!("cargo:rustc-link-lib=static={}", a));
2727
}

stm32-bindings-gen/src/lib.rs

Lines changed: 17 additions & 13 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, true)
316+
self.copy_lib(&src, &dst)
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, true)
319+
self.copy_lib_dir(&src, &dst)
320320
.unwrap_or_else(|err| panic!("Failed to copy dir {}: {err}", src.display()));
321321
} else {
322322
panic!(
@@ -357,24 +357,28 @@ impl Gen {
357357
}
358358
}
359359

360-
fn copy_file(&self, src: &Path, dst: &Path, is_library: bool) -> io::Result<()> {
360+
fn copy_lib(&self, src: &Path, dst: &Path) -> io::Result<()> {
361361
if let Some(parent) = dst.parent() {
362362
fs::create_dir_all(parent)?;
363363
}
364364

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-
};
365+
let file_name = "lib".to_string()
366+
+ dst
367+
.file_name()
368+
.ok_or(io::Error::new(io::ErrorKind::InvalidFilename, ""))?
369+
.to_str()
370+
.ok_or(io::Error::new(io::ErrorKind::InvalidFilename, ""))?;
371+
372+
let dst = dst
373+
.parent()
374+
.unwrap_or(&Path::new(""))
375+
.join(file_name.to_ascii_lowercase());
372376

373377
fs::copy(src, dst)?;
374378
Ok(())
375379
}
376380

377-
fn copy_dir(&self, src: &Path, dst: &Path, is_library: bool) -> io::Result<()> {
381+
fn copy_lib_dir(&self, src: &Path, dst: &Path) -> io::Result<()> {
378382
if !dst.exists() {
379383
fs::create_dir_all(dst)?;
380384
}
@@ -383,9 +387,9 @@ impl Gen {
383387
let path = entry.path();
384388
let target = dst.join(entry.file_name());
385389
if path.is_dir() {
386-
self.copy_dir(&path, &target, is_library)?;
390+
self.copy_lib_dir(&path, &target)?;
387391
} else {
388-
self.copy_file(&path, &target, is_library)?;
392+
self.copy_lib(&path, &target)?;
389393
}
390394
}
391395
Ok(())

0 commit comments

Comments
 (0)