Files
fips/build.rs
T
ArjenandJohnathan Corgan e0a639fd64 build: gate BLE on backend availability, and let an embedder install the radio
Two changes that are not themselves BLE code: the build gate that decides
where the transport exists, and the node-level seam an application uses to
hand it a radio. They are kept out of the BLE commits so that those stay
purely about the transport.

The BLE transport was compiled only on target_os = "linux", which conflates
the transport with one of its backends. Nothing above the BleIo seam has a
platform dependency, and the part that does is already selected separately. So
the module gate becomes ble_available, defined as bluer_available or Android:
the set of platforms with a concrete backend, deliberately not the set that
could plausibly have Bluetooth.

That distinction is the whole point. The mock arm was previously written as
"anything that is not BlueZ", so widening the module gate alone would have
handed a platform a transport that compiles, starts, reports itself Up and
never peers, with no error anywhere to find it. The backend cascade is now
explicitly three-way -- BlueZ, an embedder-supplied radio, and the in-memory
double under cfg(test) only -- with a compile_error! for the remaining case. A
compile_error! cannot fire in a test build, which is the build everybody runs,
so a unit test asserts the same condition from the other side by reading cfg!
values for the target rather than for the profile.

Nothing about which backend runs changes on any platform that builds today.
glibc-linux still gets BlueZ. macOS and Windows still have no BLE. Android is
the only new platform and it gets a real backend rather than the mock. musl
now has no BLE deliberately, where before the module compiled there and
resolved to the mock; a musl node with BLE configured logs a warning and starts
without the transport rather than running one that could never peer.

The node side gains an optional BLE radio slot. It is built whether or not a
radio has been installed, because the backend resolves the slot per operation,
so an embedder that starts Bluetooth after the node is running is adopted in
place. Arming twice returns the same slot rather than replacing it, since a
slot may already hold a live radio a second call must not orphan, and the slot
is per-node rather than a process global because a global collapses as soon as
two nodes share a process.
2026-08-26 07:58:58 +01:00

65 lines
2.4 KiB
Rust

use std::process::Command;
fn main() {
// Git commit hash (short)
let git_hash = Command::new("git")
.args(["rev-parse", "--short=10", "HEAD"])
.output()
.ok()
.filter(|o| o.status.success())
.map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string())
.unwrap_or_default();
println!("cargo:rustc-env=FIPS_GIT_HASH={git_hash}");
// Dirty working tree
let dirty = Command::new("git")
.args(["status", "--porcelain"])
.output()
.ok()
.filter(|o| o.status.success())
.map(|o| !o.stdout.is_empty())
.unwrap_or(false);
if dirty {
println!("cargo:rustc-env=FIPS_GIT_DIRTY=-dirty");
} else {
println!("cargo:rustc-env=FIPS_GIT_DIRTY=");
}
// Build target triple
if let Ok(target) = std::env::var("TARGET") {
println!("cargo:rustc-env=FIPS_TARGET={target}");
}
// Rebuild when commits change
println!("cargo:rerun-if-changed=.git/HEAD");
println!("cargo:rerun-if-changed=.git/refs/");
// Support reproducible builds (Debian packaging)
println!("cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH");
// bluer/BlueZ is glibc-linux only: musl cross-compiles (OpenWrt) can't
// satisfy libdbus-sys's pkg-config cross-compile requirement, and musl
// router targets don't run BlueZ by default anyway.
println!("cargo:rustc-check-cfg=cfg(bluer_available)");
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
let target_env = std::env::var("CARGO_CFG_TARGET_ENV").unwrap_or_default();
let bluer_available = target_os == "linux" && target_env != "musl";
if bluer_available {
println!("cargo:rustc-cfg=bluer_available");
}
// Whether the BLE transport is compiled at all.
//
// This is the set of platforms that have a concrete `BleIo` backend, not
// the set that could plausibly have one. A platform listed here with no
// backend behind it does not get "BLE, degraded" — it gets an in-memory
// transport that starts, reports itself up and never peers, with no error
// anywhere. Add a platform here only in the same change that adds its
// backend; `transport::ble` carries a compile-time tripwire that refuses
// a build where the two disagree.
println!("cargo:rustc-check-cfg=cfg(ble_available)");
if bluer_available || target_os == "android" {
println!("cargo:rustc-cfg=ble_available");
}
}