mirror of
https://github.com/jmcorgan/fips.git
synced 2026-08-09 08:14:42 +00:00
Rationalize cargo feature and platform-gate surface (#79)
Drop the `tui`, `ble`, and `gateway` cargo features and replace them with platform cfg gates. Plain `cargo build` now produces every subsystem appropriate for the target platform with no feature flags required. Motivation: - `default = ["tui", "ble"]` broke `cargo build` on macOS and Windows because `ble` pulled in `bluer` (BlueZ, Linux-only). Every non-Linux packager needed `--no-default-features`. - The feature flags on `ble` and `gateway` were redundant with their platform-gated deps (`bluer`, `rustables`). The parallel gating was inconsistent and error-prone. - `tui` feature protected against a ratatui binary-size concern that no longer applies in 2026. Cargo.toml: - Remove `tui`, `ble`, `gateway` features; `default = []`. - Promote `ratatui` to a non-optional top-level dependency. - Move `rustables` from top-level optional into the Linux target block, non-optional. - Split `bluer` into its own target block with `cfg(all(target_os = "linux", not(target_env = "musl")))` — BlueZ isn't available on musl router targets and `libdbus-sys` doesn't cross-compile to musl without pkg-config sysroot setup. - Drop `required-features` from the `fipstop` and `fips-gateway` `[[bin]]` entries. build.rs: - Emit a `bluer_available` custom cfg when `target_os == "linux"` and `target_env != "musl"`, for use in place of the verbose full predicate in source cfg gates. Source: - Replace every `#[cfg(feature = "gateway")]` with `#[cfg(target_os = "linux")]`. Gateway code works on both glibc and musl Linux (rustables is fine on musl). - Replace every `#[cfg(feature = "ble")]` with `#[cfg(bluer_available)]`. BLE-specific code (BluerIo module, bluer type conversions, BLE transport instance creation, resolve_ble_addr) is excluded on musl and non-Linux. Generic `BleAddr`, `BleIo` trait, `MockBleIo`, and `BleTransport<I>` still compile on all targets. - `src/bin/fips-gateway.rs`: always compiled, but `main()` is gated to Linux. Non-Linux stub exits 1 with a diagnostic. Existing non-Linux packaging scripts don't ship it, so the stub binary sits unused. Packaging and CI: - Drop `--features` and `--no-default-features` flags from every packaging script and workflow. Defaults now match each platform's capabilities. - AUR `fips-git` automatically aligns with stable `PKGBUILD` (both build with defaults). Verified: `cargo build --release` with no flags produces all four binaries on glibc Linux; all unit and integration tests pass across Linux/macOS/Windows/OpenWrt (musl) in CI.
This commit is contained in:
@@ -3,21 +3,33 @@
|
||||
//! Allows unmodified LAN hosts to reach FIPS mesh destinations via
|
||||
//! DNS-allocated virtual IPs and kernel nftables NAT.
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
use clap::Parser;
|
||||
#[cfg(target_os = "linux")]
|
||||
use fips::Config;
|
||||
#[cfg(target_os = "linux")]
|
||||
use fips::gateway::{control, dns, nat, net, pool};
|
||||
#[cfg(target_os = "linux")]
|
||||
use fips::version;
|
||||
#[cfg(target_os = "linux")]
|
||||
use std::path::PathBuf;
|
||||
#[cfg(target_os = "linux")]
|
||||
use std::sync::Arc;
|
||||
#[cfg(target_os = "linux")]
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
#[cfg(target_os = "linux")]
|
||||
use std::time::Instant;
|
||||
#[cfg(target_os = "linux")]
|
||||
use tokio::signal::unix::{SignalKind, signal};
|
||||
#[cfg(target_os = "linux")]
|
||||
use tokio::sync::{Mutex, mpsc, watch};
|
||||
#[cfg(target_os = "linux")]
|
||||
use tracing::{error, info, warn};
|
||||
#[cfg(target_os = "linux")]
|
||||
use tracing_subscriber::{EnvFilter, fmt};
|
||||
|
||||
/// FIPS outbound LAN gateway
|
||||
#[cfg(target_os = "linux")]
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(
|
||||
name = "fips-gateway",
|
||||
@@ -35,6 +47,13 @@ struct Args {
|
||||
log_level: String,
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
fn main() {
|
||||
eprintln!("fips-gateway requires Linux (nftables unavailable on this platform)");
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn main() {
|
||||
let args = Args::parse();
|
||||
|
||||
+4
-4
@@ -18,7 +18,7 @@
|
||||
//! nsec: "nsec1..."
|
||||
//! ```
|
||||
|
||||
#[cfg(feature = "gateway")]
|
||||
#[cfg(target_os = "linux")]
|
||||
mod gateway;
|
||||
mod node;
|
||||
mod peer;
|
||||
@@ -30,7 +30,7 @@ use serde::{Deserialize, Serialize};
|
||||
use std::path::{Path, PathBuf};
|
||||
use thiserror::Error;
|
||||
|
||||
#[cfg(feature = "gateway")]
|
||||
#[cfg(target_os = "linux")]
|
||||
pub use gateway::{ConntrackConfig, GatewayConfig, GatewayDnsConfig, PortForward, Proto};
|
||||
pub use node::{
|
||||
BloomConfig, BuffersConfig, CacheConfig, ControlConfig, DiscoveryConfig, LimitsConfig,
|
||||
@@ -378,7 +378,7 @@ pub struct Config {
|
||||
pub peers: Vec<PeerConfig>,
|
||||
|
||||
/// Gateway configuration (`gateway`).
|
||||
#[cfg(feature = "gateway")]
|
||||
#[cfg(target_os = "linux")]
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub gateway: Option<GatewayConfig>,
|
||||
}
|
||||
@@ -500,7 +500,7 @@ impl Config {
|
||||
self.peers = other.peers;
|
||||
}
|
||||
// Merge gateway section — higher-priority config replaces entirely
|
||||
#[cfg(feature = "gateway")]
|
||||
#[cfg(target_os = "linux")]
|
||||
if other.gateway.is_some() {
|
||||
self.gateway = other.gateway;
|
||||
}
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ pub mod bloom;
|
||||
pub mod cache;
|
||||
pub mod config;
|
||||
pub mod control;
|
||||
#[cfg(feature = "gateway")]
|
||||
#[cfg(target_os = "linux")]
|
||||
pub mod gateway;
|
||||
pub mod identity;
|
||||
pub mod mmp;
|
||||
|
||||
@@ -125,7 +125,7 @@ impl Node {
|
||||
}
|
||||
}
|
||||
} else if addr.transport == "ble" {
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(bluer_available)]
|
||||
{
|
||||
match self.resolve_ble_addr(&addr.addr) {
|
||||
Ok(result) => result,
|
||||
@@ -140,11 +140,11 @@ impl Node {
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
#[cfg(not(bluer_available))]
|
||||
{
|
||||
debug!(
|
||||
transport = %addr.transport,
|
||||
"BLE transport not available on this platform"
|
||||
"BLE transport not available on this build"
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
+5
-7
@@ -800,7 +800,7 @@ impl Node {
|
||||
}
|
||||
|
||||
// Create BLE transport instances
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(bluer_available)]
|
||||
{
|
||||
let ble_instances: Vec<_> = self
|
||||
.config
|
||||
@@ -810,7 +810,7 @@ impl Node {
|
||||
.map(|(name, config)| (name.map(|s| s.to_string()), config.clone()))
|
||||
.collect();
|
||||
|
||||
#[cfg(all(feature = "ble", not(test)))]
|
||||
#[cfg(all(bluer_available, not(test)))]
|
||||
for (name, ble_config) in ble_instances {
|
||||
let transport_id = self.allocate_transport_id();
|
||||
let adapter = ble_config.adapter().to_string();
|
||||
@@ -833,12 +833,10 @@ impl Node {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(not(feature = "ble"), test))]
|
||||
#[cfg(any(not(bluer_available), test))]
|
||||
if !ble_instances.is_empty() {
|
||||
#[cfg(not(test))]
|
||||
tracing::warn!(
|
||||
"BLE transport configured but 'ble' feature not enabled at compile time"
|
||||
);
|
||||
tracing::warn!("BLE transport configured but this build lacks BlueZ support");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -908,7 +906,7 @@ impl Node {
|
||||
/// Resolve a BLE address string (`"adapter/AA:BB:CC:DD:EE:FF"`) to a
|
||||
/// (TransportId, TransportAddr) pair by finding the BLE transport
|
||||
/// instance matching the adapter name.
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(bluer_available)]
|
||||
fn resolve_ble_addr(&self, addr_str: &str) -> Result<(TransportId, TransportAddr), NodeError> {
|
||||
let ta = TransportAddr::from_string(addr_str);
|
||||
let adapter = crate::transport::ble::addr::adapter_from_addr(&ta).ok_or_else(|| {
|
||||
|
||||
@@ -55,10 +55,10 @@ impl BleAddr {
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// bluer type conversions (behind ble feature)
|
||||
// bluer type conversions (glibc-linux only; see build.rs bluer_available)
|
||||
// ============================================================================
|
||||
|
||||
#[cfg(feature = "ble")]
|
||||
#[cfg(bluer_available)]
|
||||
impl BleAddr {
|
||||
/// Construct from a bluer `Address` and adapter name.
|
||||
pub fn from_bluer(addr: bluer::Address, adapter: &str) -> Self {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! BLE I/O abstraction layer.
|
||||
//!
|
||||
//! Defines the `BleIo` trait that separates transport logic from the
|
||||
//! BlueZ/bluer stack. `BluerIo` (behind `cfg(feature = "ble")`) provides
|
||||
//! BlueZ/bluer stack. `BluerIo` (behind `cfg(bluer_available)`) provides
|
||||
//! the real implementation; `MockBleIo` provides an in-memory test double.
|
||||
|
||||
use crate::transport::TransportError;
|
||||
@@ -109,7 +109,7 @@ pub trait BleIo: Send + Sync + 'static {
|
||||
// BluerIo — Production BLE I/O via BlueZ D-Bus
|
||||
// ============================================================================
|
||||
|
||||
#[cfg(feature = "ble")]
|
||||
#[cfg(bluer_available)]
|
||||
mod bluer_impl {
|
||||
use super::*;
|
||||
use crate::transport::TransportError;
|
||||
@@ -486,7 +486,7 @@ mod bluer_impl {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "ble")]
|
||||
#[cfg(bluer_available)]
|
||||
pub use bluer_impl::{BluerAcceptor, BluerIo, BluerScanner, BluerStream, FIPS_SERVICE_UUID};
|
||||
|
||||
// ============================================================================
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
//!
|
||||
//! Transport logic (pool, discovery, lifecycle) is separated from the
|
||||
//! BlueZ/bluer stack via the `BleIo` trait. `BluerIo` provides the real
|
||||
//! implementation (behind `cfg(feature = "ble")`); `MockBleIo` provides
|
||||
//! implementation (behind `cfg(bluer_available)`); `MockBleIo` provides
|
||||
//! an in-memory test double for CI without hardware.
|
||||
//!
|
||||
//! ## Connection Pool
|
||||
@@ -50,12 +50,12 @@ pub const DEFAULT_PSM: u16 = 0x0085;
|
||||
|
||||
/// Concrete BLE transport type for use in TransportHandle.
|
||||
///
|
||||
/// Production builds with the `ble` feature use `BluerIo` (real BlueZ stack).
|
||||
/// Test builds and builds without `ble` use `MockBleIo`.
|
||||
#[cfg(all(feature = "ble", not(test)))]
|
||||
/// Production builds on glibc-linux use `BluerIo` (real BlueZ stack).
|
||||
/// Test builds, musl-linux, and non-Linux platforms use `MockBleIo`.
|
||||
#[cfg(all(bluer_available, not(test)))]
|
||||
pub type DefaultBleTransport = BleTransport<io::BluerIo>;
|
||||
|
||||
#[cfg(any(not(feature = "ble"), test))]
|
||||
#[cfg(any(not(bluer_available), test))]
|
||||
pub type DefaultBleTransport = BleTransport<io::MockBleIo>;
|
||||
|
||||
// ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user