Skip to content

Add C ABI - #63

Open
colemancda wants to merge 30 commits into
masterfrom
feature/c-abi
Open

Add C ABI#63
colemancda wants to merge 30 commits into
masterfrom
feature/c-abi

Conversation

@colemancda

@colemancda colemancda commented Aug 1, 2026

Copy link
Copy Markdown
Member

Summary

Scaffolding for a drop-in, Swift-implemented replacement for BlueZ's shared libbluetooth.so.3. The deliverable is a library that loads, resolves all 218 symbols the reference exports, and fails loudly (by symbol name) on any call not implemented yet — so the rest of the port can proceed incrementally, one symbol family at a time.

Nothing in the bluez package actually links this shared library — bluetoothd, bluetoothctl, btmon, hciconfig and sdptool all statically link libbluetooth-internal.a — so replacing it can't break the Bluetooth stack itself; it exists solely for third-party consumers.

  • Sources/CBluetoothLinuxABI vendors the eleven public BlueZ headers verbatim (GPL-2.0-or-later, isolated in its own directory with its own LICENSE and README) and generates a stub for every symbol not yet implemented, via scripts/gen_stubs.py. Each stub's signature is read out of the vendored headers, so it's checked against the real declaration rather than hand-typed.
  • scripts/symbols.txt records the reference export surface (218, split 17/101/100 across bluetooth.c/hci.c/sdp.c); scripts/implemented.txt records the 27 currently implemented (the bluetooth.c + bt_uuid_* families, implemented in PureSwift/Bluetooth). scripts/gen_symbols.py derives the linker version script and the flat export list from these; scripts/check-exports.sh asserts the built library against it.
  • scripts/ownership.md records the return/who-frees/lifetime contract for each symbol, ahead of implementation — the conventions aren't uniform (some allocate on the heap, some write into a caller buffer, some return static pointers) and guessing produces leaks or double frees no type checker would catch.
  • CMakeLists.txt builds libbluetooth.so.3.19.15 by linking a PureSwift/Bluetooth checkout's static archives (-DBLUETOOTH_PACKAGE_PATH) together with the generated stubs, with the soname, version, and a pinned export list that Package.swift can't express.
  • Conformance/README.md records where the differential conformance harness for the implemented symbols lives (in PureSwift/Bluetooth, alongside the symbols it covers) and what's needed for the rest.

Verified

  • The built library exports exactly the 228 expected symbols (check-exports target).
  • Its output over the differential conformance driver for the implemented symbols is identical to the system libbluetooth.so.3, aside from three already-documented bt_compidtostr naming deltas.
  • Calling an unimplemented symbol (e.g. hci_open_dev) aborts with libbluetooth (PureSwift): hci_open_dev is not implemented yet. rather than crashing unhelpfully or corrupting state.

Test plan

  • swift build — default configuration, unaffected
  • SWIFTPM_BLUETOOTH_CABI=1 swift build — C ABI target builds
  • cmake -B build -G Ninja -DBLUETOOTH_PACKAGE_PATH=<Bluetooth checkout> && cmake --build buildlibbluetooth.so.3.19.15 builds
  • cmake --build build --target check-exports — 228/228 symbols match
  • Smoke test: reference and built library produce identical output over the implemented symbols' conformance driver
  • Smoke test: an unimplemented symbol aborts loudly by name instead of misbehaving

@colemancda colemancda changed the title Add libbluetooth.so.3 scaffolding (phase 0) Add C ABI Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant