Skip to content

Commit 2170c0c

Browse files
committed
Split generated bindings into 3 sections:
- ble: BLE bindings - linklayer: lower-level - mac: MAC bindings Also added ll_sys_if, linklayer_plat bindings Added mac_sys_if.rs and fixed workflow file to conform to new crate generation CI: generate bindings before packaging also exclude wba-linklayer from workspace Add explicit version for linklayer bindings in generated crates Squashed generated bindings to single package Minimized changes between main
1 parent 4f3b962 commit 2170c0c

File tree

22 files changed

+1891
-224
lines changed

22 files changed

+1891
-224
lines changed

.github/workflows/rust.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,24 @@ jobs:
3333
run: ./d download-all
3434
- name: Run build
3535
run: cargo run --release --bin stm32-bindings-gen
36+
- name: Check wba-linklayer
37+
run: cargo check --manifest-path wba-linklayer/Cargo.toml
3638
- name: Run package build
3739
run: |
38-
cd build/stm32-bindings
3940
export CARGO_BUILD_TARGET=thumbv8m.main-none-eabihf
40-
cargo fix --lib -p stm32-bindings --allow-no-vcs
41-
cargo build
42-
cargo package
43-
ls target/package
41+
for crate_dir in linklayer-bindings; do
42+
echo "::group::Packaging ${crate_dir}"
43+
(
44+
cd build/${crate_dir}
45+
cargo fix --lib --allow-no-vcs --target ${CARGO_BUILD_TARGET}
46+
cargo build --target ${CARGO_BUILD_TARGET}
47+
cargo package
48+
ls target/package
49+
)
50+
echo "::endgroup::"
51+
done
4452
- name: Upload package build
4553
uses: actions/upload-artifact@v4
4654
with:
4755
name: crate
48-
path: build/stm32-bindings/target/package/*.crate
56+
path: build/*-bindings/target/package/*.crate

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ members = [
44
"stm32-bindings-gen",
55
]
66
exclude = [
7-
"build"
7+
"build",
8+
"wba-linklayer",
89
]
910

1011
# Optimize for dev experience: shortest "build+run" time after making a small change.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[package]
2+
name = "ble-bindings"
3+
version = "0.1.0"
4+
edition = "2024"
5+
license = "MIT OR Apache-2.0"
6+
description = "Raw STM32 WBA BLE stack bindings generated from the ST middleware."
7+
build = "build.rs"
8+
9+
[lib]
10+
path = "src/lib.rs"
11+
12+
[dependencies]
13+
linklayer-bindings = { path = "../linklayer-bindings" }
14+
15+
[features]
16+
default = []
17+
lib_stm32wba_ble_stack_po = []
18+
lib_stm32wba_ble_stack_llo = []
19+
lib_stm32wba_ble_stack_full = []
20+
lib_stm32wba_ble_stack_basic = []
21+
lib_stm32wba_ble_stack_basic_plus = []
22+
lib_lc3 = []
23+
lib_codec_mngr = []
24+
lib_ble_audio = []
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# ble-bindings
2+
3+
Raw bindings for the STM32 WBA Bluetooth Low Energy stack. This crate is generated automatically by `stm32-bindings-gen` and is meant to be consumed by higher-level wrappers that expose safe BLE abstractions.
4+
5+
## Overview
6+
7+
The generator ingests the ST middleware headers and prebuilt static libraries, then uses `bindgen` to emit Rust FFI items. Everything in this crate mirrors the original C API one-to-one; you should treat every item as `unsafe` and build ergonomic wrappers in a separate crate.
8+
9+
## Layout
10+
11+
- `src/bindings/`: Modules produced by `bindgen`, containing raw FFI definitions.
12+
- `src/lib/`: Static libraries copied from the STM32CubeWBA distribution. Selecting the proper feature toggles which archives get linked.
13+
- `build.rs`: Registers the static libraries with Cargo based on the enabled features.
14+
15+
## Usage
16+
17+
1. Run `cargo run -p stm32-bindings-gen` so this crate is regenerated under `build/ble-bindings`.
18+
2. Add a path dependency in your Cargo manifest pointing to that directory.
19+
3. Enable the feature corresponding to the static library variant required by your project (e.g. `lib_stm32wba_ble_stack_full`).
20+
4. Wrap the raw FFI functions in a higher-level API before exposing them to the rest of your system.
21+
22+
## Feature Flags
23+
24+
Each `lib_*` feature matches a static archive provided by ST. Enable exactly the variants you need and the build script will emit the proper `cargo:rustc-link-lib` entries.
25+
26+
## Regeneration
27+
28+
If the underlying middleware or binding configuration changes, rerun `cargo run -p stm32-bindings-gen`. The generator will overwrite this crate with the latest bindings, libraries, and metadata.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use std::path::{Path, PathBuf};
2+
use std::{env, fs, io};
3+
4+
fn add_dir(dir: &Path) -> io::Result<()> {
5+
if !dir.exists() {
6+
return Ok(());
7+
}
8+
9+
println!("cargo:rustc-link-search=native={}", dir.display());
10+
11+
for entry in fs::read_dir(dir)? {
12+
let entry = entry?;
13+
let path = entry.path();
14+
if path.is_dir() {
15+
add_dir(&path)?;
16+
}
17+
}
18+
19+
Ok(())
20+
}
21+
22+
fn main() {
23+
let crate_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
24+
let lib_dir = crate_dir.join("src").join("lib");
25+
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
26+
let target_family = env::var("CARGO_CFG_TARGET_FAMILY").unwrap_or_default();
27+
let is_embedded = target_os == "none" || target_family == "embedded";
28+
29+
if !is_embedded {
30+
return;
31+
}
32+
33+
add_dir(&lib_dir).expect("failed to add link search paths");
34+
35+
env::vars()
36+
.filter_map(|(key, _)| {
37+
key.strip_prefix("CARGO_FEATURE_LIB_")
38+
.map(|suffix| suffix.to_ascii_lowercase())
39+
})
40+
.for_each(|lib| println!("cargo:rustc-link-lib=static={lib}"));
41+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![no_std]
2+
#![allow(non_snake_case)]
3+
#![allow(non_camel_case_types)]
4+
#![allow(non_upper_case_globals)]
5+
#![doc(html_no_source)]
6+
7+
/// Raw bindings generated by `stm32-bindings-gen`.
8+
///
9+
/// The `bindings` module is produced by `bindgen` and exposes a one-to-one FFI
10+
/// surface to the STM32 WBA BLE middleware. All items should be treated as
11+
/// `unsafe` and wrapped by higher-level crates before use.
12+
pub mod bindings;
13+
14+
pub use bindings::*;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[package]
2+
name = "linklayer-bindings"
3+
version = "0.1.0"
4+
edition = "2024"
5+
license = "MIT OR Apache-2.0"
6+
description = "Raw STM32 WBA link-layer bindings generated from the ST middleware."
7+
build = "build.rs"
8+
9+
[lib]
10+
path = "src/lib.rs"
11+
12+
[dependencies]
13+
14+
[features]
15+
default = []
16+
lib_wba5_linklayer_ble_basic_20_links_lib = []
17+
lib_wba5_linklayer_ble_basic_lib = []
18+
lib_wba5_linklayer_ble_basic_plus_20_links_lib = []
19+
lib_wba5_linklayer_ble_basic_plus_lib = []
20+
lib_wba5_linklayer_ble_full_lib = []
21+
lib_wba5_linklayer_ble_mac_lib = []
22+
lib_wba5_linklayer_ble_peripheral_only_lib = []
23+
lib_wba5_linklayer_ble_thread_lib = []
24+
lib_wba5_linklayer_rawmac_lib = []
25+
lib_wba5_linklayer_thread_lib = []
26+
lib_wba5_linklayer15_4 = []
27+
lib_wba6_linklayer_ble_basic_20_links_lib = []
28+
lib_wba6_linklayer_ble_basic_lib = []
29+
lib_wba6_linklayer_ble_basic_plus_20_links_lib = []
30+
lib_wba6_linklayer_ble_basic_plus_lib = []
31+
lib_wba6_linklayer_ble_full_lib = []
32+
lib_wba6_linklayer_ble_mac_lib = []
33+
lib_wba6_linklayer_ble_peripheral_only_lib = []
34+
lib_wba6_linklayer_ble_thread_lib = []
35+
lib_wba6_linklayer_rawmac_lib = []
36+
lib_wba6_linklayer_thread_lib = []
37+
lib_wba6_linklayer15_4 = []
38+
lib_wba_mac_lib = []
39+
lib_stm32wba_ble_stack_basic = []
40+
lib_stm32wba_ble_stack_basic_plus = []
41+
lib_stm32wba_ble_stack_full = []
42+
lib_stm32wba_ble_stack_llo = []
43+
lib_stm32wba_ble_stack_po = []
44+
lib_lc3 = []
45+
lib_codec_mngr = []
46+
lib_ble_audio = []
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# linklayer-bindings
2+
3+
Raw bindings for the STM32 WBA link-layer middleware. This crate is generated automatically by `stm32-bindings-gen` and is intended to be consumed by higher-level wrappers that provide safe abstractions for BLE or IEEE 802.15.4 stacks.
4+
5+
## Overview
6+
7+
The generator pulls in STM-provided headers and static libraries, then runs `bindgen` to emit Rust FFI shims. No additional logic lives here—consumers should treat every item as `unsafe` and wrap it before use.
8+
9+
## Layout
10+
11+
- `src/bindings/`: Raw Rust modules produced by `bindgen`.
12+
- `src/lib/`: Static libraries copied from the STM32CubeWBA middleware tree, gated behind Cargo features.
13+
- `build.rs`: Emits the appropriate `cargo:rustc-link-*` directives based on the selected features.
14+
15+
## Usage
16+
17+
1. Ensure `stm32-bindings-gen` has been run so this crate exists in `build/linklayer-bindings`.
18+
2. Add a path dependency in your Cargo manifest pointing at that directory.
19+
3. Opt into the desired static library variant by enabling the matching `lib_*` feature exposed by this crate.
20+
4. Call the generated functions through `unsafe` code and wrap them in a higher-level API before exposing them to the rest of your application.
21+
22+
## Feature Flags
23+
24+
Each feature named `lib_<variant>` selects one of the prebuilt static archives shipped by ST. Enable exactly the libraries required by your firmware configuration; the build script will link them automatically.
25+
26+
## Regeneration
27+
28+
If the upstream ST middleware or the bindings configuration changes, rerun `cargo run -p stm32-bindings-gen`. The generator will overwrite this crate with the latest bindings, static libraries, and metadata.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use std::path::{Path, PathBuf};
2+
use std::{env, fs, io};
3+
4+
fn add_dir(dir: &Path) -> io::Result<()> {
5+
if !dir.exists() {
6+
return Ok(());
7+
}
8+
9+
println!("cargo:rustc-link-search=native={}", dir.display());
10+
11+
for entry in fs::read_dir(dir)? {
12+
let entry = entry?;
13+
let path = entry.path();
14+
if path.is_dir() {
15+
add_dir(&path)?;
16+
}
17+
}
18+
Ok(())
19+
}
20+
21+
fn main() {
22+
let crate_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
23+
let lib_dir = crate_dir.join("src").join("lib");
24+
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
25+
let target_family = env::var("CARGO_CFG_TARGET_FAMILY").unwrap_or_default();
26+
let is_embedded = target_os == "none" || target_family == "embedded";
27+
28+
if !is_embedded {
29+
return;
30+
}
31+
32+
add_dir(&lib_dir).expect("failed to add link search paths");
33+
34+
env::vars()
35+
.filter_map(|(key, _)| {
36+
key.strip_prefix("CARGO_FEATURE_LIB_")
37+
.map(|s| s.to_ascii_lowercase())
38+
})
39+
.for_each(|lib| println!("cargo:rustc-link-lib=static={lib}"));
40+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![no_std]
2+
#![allow(non_snake_case)]
3+
#![allow(non_camel_case_types)]
4+
#![allow(non_upper_case_globals)]
5+
#![doc(html_no_source)]
6+
7+
/// Raw bindings generated by `stm32-bindings-gen`.
8+
///
9+
/// The `bindings` module is produced by `bindgen` and exposes a one-to-one FFI
10+
/// surface to the STM32 WBA link-layer middleware. All items should be treated
11+
/// as `unsafe` and wrapped by higher-level crates before use.
12+
pub mod bindings;
13+
14+
pub use bindings::*;

0 commit comments

Comments
 (0)