[package]
name = "peat-btle"
version = "0.3.1"
edition = "2021"
authors = ["Kit Plummer <kitplummer@defenseunicorns.com>"]
license = "Apache-2.0"
description = "Bluetooth Low Energy mesh transport for Peat Protocol"
repository = "https://github.com/defenseunicorns/peat-btle"
keywords = ["bluetooth", "ble", "mesh", "peat", "tactical"]
categories = ["network-programming", "embedded"]

[lib]
# Build as both a Rust library and a C dynamic library (for UniFFI bindings)
crate-type = ["rlib", "cdylib"]

[features]
default = ["std"]

# Standard library support (disable for embedded)
std = ["thiserror/std", "uuid/std"]

# Pure BLE transport, no app-layer CRDTs
transport-only = ["std"]

# ADR-059 cross-transport bridging: ships BleTranslator + the Translator
# trait impl wiring that lets a peat-mesh-using consumer plug peat-btle
# into `peat_mesh::transport::TransportManager`. Default-off so
# standalone BLE consumers (Bitchat-style, embedded sensors, etc.)
# compile without peat-mesh in their dep graph. Pulls the
# JSON/serde/postcard/tracing stack the codec needs — costs only get
# added when the feature is on.
mesh-translator = [
    "std",
    "dep:peat-mesh",
    "dep:serde",
    "dep:serde_json",
    "dep:anyhow",
    "dep:postcard",
    "dep:tracing",
]

# Legacy chat support (deprecated, will be removed in 0.2.0)
legacy-chat = []

# UniFFI bindings (generates Kotlin + Swift)
uniffi = ["dep:uniffi"]

# Platform-specific features
linux = ["dep:bluer", "dep:tokio", "dep:tokio-stream"]
android = ["uniffi", "dep:tokio", "dep:android_logger"]
macos = ["dep:objc2", "dep:block2", "dep:tokio", "dep:objc2-foundation", "dep:objc2-core-bluetooth"]
ios = ["dep:objc2", "dep:block2", "dep:tokio", "dep:objc2-foundation", "dep:objc2-core-bluetooth"]
windows = ["dep:windows", "dep:tokio"]

# Embedded/no_std support
embedded = []

# ESP32 support (requires esp-idf toolchain)
# Build with: cargo build --target xtensa-esp32-espidf --features esp32
esp32 = ["embedded", "std", "dep:esp-idf-svc", "dep:esp-idf-hal"]

# BLE 5.0 features
coded-phy = []
extended-adv = []

[dependencies]
# Core dependencies (always included)
async-trait = "0.1"
uuid = { version = "1.11", default-features = false }
bitflags = "2.6"
log = "0.4"

# Error handling
thiserror = { version = "2.0", default-features = false }

# Spin locks for no_std
spin = { version = "0.9", default-features = false, features = ["rwlock"] }

# Encryption (mesh-wide and per-peer E2EE)
chacha20poly1305 = "0.10"
hkdf = "0.12"
sha2 = "0.10"
rand_core = { version = "0.6", features = ["getrandom"] }
x25519-dalek = { version = "2.0", features = ["static_secrets"] }

# Identity and signing (DeviceIdentity, MeshGenesis)
ed25519-dalek = { version = "2.1", features = ["rand_core"] }
blake3 = "1.5"

# no_std HashMap for IdentityRegistry
hashbrown = "0.15"

# UniFFI for cross-language bindings (optional)
uniffi = { version = "0.31", optional = true }

# Async runtime (optional, for std platforms)
tokio = { version = "1.42", features = ["sync", "time", "macros", "rt-multi-thread"], optional = true }

# Linux/BlueZ (optional)
bluer = { version = "0.17", features = ["bluetoothd"], optional = true }
tokio-stream = { version = "0.1", optional = true }

# Android logging (optional)
android_logger = { version = "0.14", optional = true }

# Apple CoreBluetooth (optional)
objc2 = { version = "0.5", optional = true }
block2 = { version = "0.5", optional = true }
objc2-foundation = { version = "0.2", features = ["NSRunLoop", "NSDate", "NSString", "NSObjCRuntime"], optional = true }
objc2-core-bluetooth = { version = "0.2", features = ["all"], optional = true }

# Windows WinRT (optional)
windows = { version = "0.58", features = [
    "Devices_Bluetooth",
    "Devices_Bluetooth_Advertisement",
    "Devices_Bluetooth_GenericAttributeProfile",
    "Foundation",
    "Foundation_Collections",
    "Storage_Streams",
    "implement",
], optional = true }

# ESP32/ESP-IDF (optional)
esp-idf-svc = { version = "0.50", optional = true }
esp-idf-hal = { version = "0.45", optional = true }

# ADR-059 mesh-translator (optional, gated by the `mesh-translator` feature)
# These are *only* pulled in when a peat-mesh consumer enables the codec;
# standalone BLE consumers see none of them in their dep tree.
#
# **peat-mesh exact-pin coordination.** The `=0.9.0-rc.4` pin matches the
# peat workspace pin (peat/Cargo.toml). It MUST move in lockstep with the
# next peat-mesh release: when peat-mesh ships a new rc / stable, both
# this pin and peat's pin bump together, otherwise downstream consumers
# enabling `mesh-translator` alongside peat hit a resolver conflict.
# Bump path: peat-mesh release → peat workspace pin → this pin → peat-btle
# release. Logged in CHANGELOG under the `mesh-translator` feature entry.
peat-mesh = { version = "=0.9.0-rc.4", default-features = false, optional = true }
serde = { version = "1", features = ["derive"], optional = true }
serde_json = { version = "1", optional = true }
anyhow = { version = "1", optional = true }
postcard = { version = "1", features = ["alloc"], optional = true }
tracing = { version = "0.1", optional = true }

[dev-dependencies]
tokio-test = "0.4"
env_logger = "0.11"
tokio = { version = "1.42", features = ["rt-multi-thread", "macros", "signal"] }
base64 = "0.22"
peat-lite = "0.2.0"

[build-dependencies]
uniffi = { version = "0.31", features = ["build"] }

# Examples with platform-specific features
[[example]]
name = "range_test_node_macos"
required-features = ["macos"]

[package.metadata.docs.rs]
features = ["linux"]
