b6fdee8bfc
Consolidated release: the cross-platform Linux port (engine, generators, CLI, REPL, NRT, portable DSP), live ALSA audio + ALSA MIDI + POSIX OSC + portable WAV codec, the GTK4 GUI (LyrebirdUI on the SwiftOpenUI backend), and the Linux live-coding scratchpad (LiveCompile). Apple platforms unchanged; all additive. See RELEASES.md and LINUX_README.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
325 lines
16 KiB
Markdown
325 lines
16 KiB
Markdown
# Cross-Platform Feasibility — Linux / Windows
|
||
|
||
> Status: **investigation** (branch `feasibility/cross-platform-linux-windows`).
|
||
> Not a commitment to ship. This document records the measured non-portable
|
||
> surface of the codebase and the paths that could carry Lyrebird off Apple
|
||
> platforms, ranked by effort.
|
||
|
||
## Summary
|
||
|
||
Lyrebird is currently welded to Apple platforms in `Package.swift`
|
||
(`.macOS(.v15), .iOS(.v18)`) and links five Apple-only frameworks
|
||
(`CoreAudio`, `AudioToolbox`, `Accelerate`, `CoreMIDI`, `AVFoundation`).
|
||
|
||
Two independent porting jobs stand between today and a Linux/Windows build:
|
||
|
||
1. **DSP kernel** — 73 files call `vDSP_*` (Accelerate) directly. This is the
|
||
dominant cost. No portable fallback exists.
|
||
2. **Audio + MIDI I/O** — live drivers (CoreAudio/RemoteIO), audio file codec
|
||
(ExtAudioFile), and MIDI (CoreMIDI) all need per-platform implementations.
|
||
|
||
Everything except vDSP is already folder-isolated behind a small number of
|
||
files, so the porting surface outside the DSP kernel is small.
|
||
|
||
`Synchronization.Atomic` (52 files) is **not** a blocker — it is a stdlib
|
||
module and works on Linux/Windows with Swift 6.x. The CLAUDE.md note
|
||
"requires macOS 15" refers to Apple-availability, not portability.
|
||
|
||
## Measured non-portable surface (core `LyrebirdSynth` module)
|
||
|
||
| Blocker | Files | Nature | Isolated |
|
||
|---|---|---|---|
|
||
| Accelerate / vDSP | 73 | Pervasive across 62 generators + Spectral/Buffers/Engine | No |
|
||
| Audio file I/O (ExtAudioFile) | ~6 (`Buffers/AudioFileFormat`, `Buffers/LyrebirdBufferFileIO`, `Generators/BufferIO/DiskIn`,`DiskOut`+errors) | WAV/AIFF read+write | Yes |
|
||
| CoreMIDI | 3 (`MIDI/`) | MIDI in/out | Yes |
|
||
| Live audio drivers | 4 (`AudioDrivers/`) | CoreAudio/RemoteIO/AUv3/NRT | Yes (protocol seam exists) |
|
||
| AUv3 | 7 (`AUv3/`) | Apple plugin format — **exclude** off-Apple | Yes |
|
||
|
||
Not blockers for core: `AVFoundation` (8 files, all AUv3/iOS/CLI-scaffolder),
|
||
`Foundation` (293 files, mostly portable via swift-corelibs-foundation).
|
||
|
||
## The abstraction seams that already exist
|
||
|
||
- `AudioDrivers/AudioDriver.swift` — protocol (`setup`/`start`/`stop` +
|
||
`suggestedControlBlockSize`) with `OfflineDriver` no-op already present. A
|
||
`LinuxAudioDriver` / `WindowsAudioDriver` slots in here without engine
|
||
changes.
|
||
- `MIDI/` — three files, self-contained CoreMIDI usage.
|
||
- `LyrebirdGraphDSL` target — documented pure-Swift, no swiftc/AppKit →
|
||
portable once core compiles.
|
||
|
||
Missing seam: **there is no vDSP abstraction layer.** Generators call
|
||
`vDSP_vmulD`, `vDSP_vsmaD`, `vDSP_biquadD`, `vDSP_fft_zrip`, etc. directly.
|
||
|
||
## Proposed architecture (the one lever that unblocks everything)
|
||
|
||
Introduce `LyrebirdDSP` — a thin vector-math shim behind
|
||
`#if canImport(Accelerate)`:
|
||
|
||
```swift
|
||
// Apple: forwards to vDSP (zero cost).
|
||
// Elsewhere: scalar/SIMD fallback, or link OpenBLAS + pffft/FFTW.
|
||
@inline(__always) func lb_vmul(_ a: UnsafePointer<Double>, _ b: ..., ...) { ... }
|
||
```
|
||
|
||
Do this first. It is the single change that unblocks offline render, headless
|
||
live audio, and both target OSes at once, and costs nothing on macOS (pure
|
||
forwarding). The 73 call sites migrate to the shim mechanically.
|
||
|
||
FFT is the sharpest sub-problem: `vDSP_fft_zrip` has no drop-in portable twin
|
||
— candidates are pffft, FFTW (GPL — licensing), or a pure-Swift radix-2.
|
||
|
||
## Toolchains
|
||
|
||
### Linux
|
||
- Manager: `swiftly` (official). Latest stable Swift **6.3.3**.
|
||
- Distro builds: Ubuntu/Debian/Fedora/RHEL/Amazon Linux + static-Linux (musl) SDK.
|
||
- CI: official `swift:6.3.3` Docker image.
|
||
- Live audio: new `LinuxAudioDriver` — PipeWire (preferred) or ALSA via C-interop.
|
||
- MIDI: ALSA seq or RtMidi.
|
||
|
||
### Windows
|
||
- Install: `winget install --id Swift.Toolchain`. **`swiftly` not yet on Windows.**
|
||
- Prereqs: Visual Studio 2022 / Build Tools (MSVC + Windows SDK).
|
||
- Tier-2 after Linux: larger Foundation gaps, rougher SPM ergonomics.
|
||
- Live audio: WASAPI (built-in) or ASIO (low-latency, Steinberg-licensed SDK).
|
||
- MIDI: WinMM or RtMidi.
|
||
|
||
### IDE (base library, off Xcode)
|
||
- **VS Code + Swift extension** (official) — recommended. LSP + LLDB + tests.
|
||
- Cursor/Windsurf (same extension), Zed, Neovim + sourcekit-lsp, JetBrains CLion.
|
||
- Xcode-exclusive loss that matters: SwiftUI previews — `LyrebirdUI` only.
|
||
|
||
## SwiftUI off-Apple
|
||
|
||
SwiftUI does **not** exist on Linux or Windows and no port is planned.
|
||
`LyrebirdUI` (31 SwiftUI/AppKit/UIKit files) stays Apple-exclusive.
|
||
|
||
| Path | Target | Note |
|
||
|---|---|---|
|
||
| Skip | Android | wrong target for desktop |
|
||
| swift-cross-ui | Linux/Win desktop | SwiftUI-*like*, not SwiftUI; rewrite; immature |
|
||
| TokamakUI | Web (WASM) | largely stalled |
|
||
| GTK/Qt Swift bindings | native | most work, no SwiftUI idiom |
|
||
| External UI (Flutter/Tauri) over headless engine | any | pragmatic; IPC boundary |
|
||
|
||
**Recommendation:** keep Lyrebird headless off-Apple (CLI + GraphDSL + OSC/MIDI),
|
||
let external UIs drive it — mirrors the SuperCollider server/client split.
|
||
|
||
## Paths ranked by effort
|
||
|
||
| # | Path | Effort | Blockers to clear |
|
||
|---|---|---|---|
|
||
| 1 | Linux offline/NRT render + CLI + GraphDSL | Low–Med | vDSP shim, portable file codec, drop platform pin, exclude AUv3 |
|
||
| 2 | Linux live audio (headless engine) | +Med | `LinuxAudioDriver` (PipeWire/ALSA) + MIDI port |
|
||
| 3 | Windows headless engine | +Med | reuse vDSP shim; WASAPI/ASIO driver; MSVC/Foundation friction |
|
||
| 4 | Cross-platform GUI | High | swift-cross-ui rewrite OR external UI over IPC — not real SwiftUI |
|
||
|
||
## First cross-compile attempt (this branch)
|
||
|
||
Static Linux SDK `swift-6.3.3-RELEASE_static-linux-0.1.0` installed
|
||
(checksum-verified). `Package.swift` linker settings made Apple-only via
|
||
`.when(platforms: [.macOS, .iOS])` — macOS build unaffected (verified, 2.6s).
|
||
|
||
Cross-compile `swift build --swift-sdk aarch64-swift-linux-musl --target
|
||
LyrebirdSynth`:
|
||
|
||
- Reached **625/625** compile tasks.
|
||
- **1244 of 1245 errors are a single cause:** `Foundation` — "compiled module
|
||
was created by an older version of the compiler; rebuild 'Foundation'".
|
||
- **Zero** `no such module 'Accelerate' / 'CoreAudio'` errors — those imports
|
||
are never reached, because the compiler bails at `import Foundation` first.
|
||
|
||
**Diagnosis: toolchain↔SDK mismatch, not a Lyrebird code result.** The active
|
||
toolchain is Xcode's (`swiftlang-6.3.3.1.3`); the Static Linux SDK's prebuilt
|
||
`Foundation.swiftmodule` was built by swift.org's 6.3.3 toolchain. `.swiftmodule`
|
||
format is not stable across compiler *builds* at the same version. No swift.org
|
||
toolchain is installed (`/Library/Developer/Toolchains/` empty).
|
||
|
||
The real (masked) break set — Accelerate + audio frameworks — cannot be read
|
||
until the toolchains match.
|
||
|
||
## Second cross-compile — under matching swift.org toolchain
|
||
|
||
Installed swift.org toolchain `swift-6.3.3-RELEASE` (Apple-notarized,
|
||
Developer ID "Swift Open Source", user-home install, no sudo) and re-ran:
|
||
|
||
```
|
||
~/Library/Developer/Toolchains/swift-6.3.3-RELEASE.xctoolchain/usr/bin/swift \
|
||
build --swift-sdk aarch64-swift-linux-musl --target LyrebirdSynth --scratch-path .build-linux
|
||
```
|
||
|
||
Result — **the Foundation mismatch is gone.** Foundation (the 293-file base)
|
||
compiles for Linux. The remaining error is `no such module 'AudioToolbox'`
|
||
(first reached in `AUv3/`). Behind it sit Accelerate / CoreAudio / CoreMIDI —
|
||
the compiler aborts module-emit at the first missing framework, so it reveals
|
||
them one layer at a time, but there are **no surprise errors**: the blocker set
|
||
is exactly the five Apple frameworks from the static inventory. No Foundation
|
||
API gaps, no stdlib breakage.
|
||
|
||
### Headline feasibility number
|
||
|
||
Of **621** files in `Sources/Lyrebird`:
|
||
|
||
- **529 (85%) are framework-free** — Foundation/stdlib only, and Foundation is
|
||
now confirmed to compile for Linux.
|
||
- **92 (15%) touch an Apple framework** — the entire porting surface:
|
||
|
||
| Folder | Files | Job |
|
||
|---|---|---|
|
||
| Generators | 66 | vDSP → `LyrebirdDSP` shim (the wall) |
|
||
| AUv3 | 7 | exclude off-Apple |
|
||
| Buffers | 5 | portable WAV/AIFF codec |
|
||
| AudioDrivers | 4 | per-OS live drivers |
|
||
| Spectral | 3 | portable FFT |
|
||
| MIDI | 3 | CoreMIDI → RtMidi/ALSA |
|
||
| Engine / Buses / NodeTree / GeneratorCore | 4 | small Accelerate helpers |
|
||
|
||
**Conclusion: feasible.** 85% of the tree is portable as-is; the work is
|
||
concentrated in a 92-file surface dominated by ~69 Accelerate/vDSP files that a
|
||
single `LyrebirdDSP` shim addresses centrally. No architectural blocker found —
|
||
this is mechanical porting, not a redesign.
|
||
|
||
## `LyrebirdDSP` shim — built and proven
|
||
|
||
New target `Sources/LyrebirdDSP` (wired in `Package.swift`, a dependency of
|
||
`LyrebirdSynth`):
|
||
|
||
- `AccelerateShim.swift` — `#if canImport(Accelerate)` → `@_exported import
|
||
Accelerate`; `#else` → vDSP/vForce API-compatible shims + `vDSP_Length` /
|
||
`vDSP_Stride` typealiases, delegating to the scalar cores. Non-Apple math
|
||
(`sin`/`cos`/…) imported from `Glibc`/`Musl`/`ucrt`.
|
||
- `ScalarDSP.swift` — portable scalar cores, generic over `BinaryFloatingPoint`,
|
||
compiled on **all** platforms so they are testable against real vDSP.
|
||
- All 71 core `import Accelerate` lines migrated to `import LyrebirdDSP` (pure
|
||
rename; on Apple the re-export makes the code byte-identical).
|
||
|
||
Verified:
|
||
|
||
- macOS full `swift build` green (unchanged behaviour — real vDSP via re-export).
|
||
- `LyrebirdDSP` **cross-compiles clean to `aarch64-swift-linux-musl`** in
|
||
isolation (0.84s).
|
||
- `Tests/LyrebirdDSPTests/ScalarDSPParityTests` — 8 tests compare each scalar
|
||
core to the real vDSP on Apple (incl. the operand-order-sensitive
|
||
`vsub`/`vdiv`); all pass. This is the guarantee the Linux fallback matches
|
||
Accelerate.
|
||
- Full-core cross-compile: the **Accelerate wall is gone** — the next
|
||
`no such module` is `AudioToolbox` (the compiler aborts at the first
|
||
unguarded framework, so blockers surface one layer at a time).
|
||
|
||
Deliberately deferred in the shim (compile to a precise "cannot find …" off
|
||
Apple, which is the burn-down list): FFT family (`vDSP_fft_zrip`, `ctoz`, …),
|
||
biquad-setup family (`vDSP_biquad*`), `vDSP_mmulD`, `vDSP_vrampmul`,
|
||
`vDSP_vdpsp`. These need real portable replacements, not one-line loops.
|
||
|
||
## AudioToolbox layer — module walls cleared
|
||
|
||
Portable WAV codec + platform guards landed. **Every `no such module` wall is
|
||
now gone** — the Linux cross-compile no longer aborts on a missing Apple
|
||
framework; what remains is symbol-level (the deferred DSP), not module-level.
|
||
|
||
Done this stage:
|
||
|
||
- **Portable WAV codec** (`Buffers/WavEncoding.swift`, `WavFileWriter.swift`,
|
||
`WavFileReader.swift`, `WavFileError.swift`) — streaming RIFF/WAVE PCM
|
||
read+write (float32 / int16 / int24), pure Foundation, no AudioToolbox.
|
||
4 round-trip tests (float32 exact; int16/int24 within quantization; non-WAVE
|
||
rejected). This is the ExtAudioFile replacement for offline render / disk I/O.
|
||
- **Guarded the Apple-only framework files** with `#if canImport(...)`:
|
||
AudioToolbox (17: AUv3 + drivers + file I/O), CoreMIDI (3, `MIDI/`),
|
||
Network (2, `OSC/`).
|
||
- **Conditional C-library import** (`#if canImport(Darwin) … #elseif Glibc /
|
||
Musl`) across 16 files (`RTThreadIdentity` pthread TLS + 15 math users).
|
||
|
||
Verified: macOS full build green; 12 new tests pass; the Linux cross-compile
|
||
now reaches the symbol-level remainder below (no module aborts).
|
||
|
||
## Milestone: the LyrebirdSynth core cross-compiles to Linux
|
||
|
||
`swift build --swift-sdk aarch64-swift-linux-musl --target LyrebirdSynth`
|
||
**completes with 0 errors.** The full synthesis core builds on Linux; macOS
|
||
build is unchanged and its 19 DSP/WAV parity tests pass. Getting here took, in
|
||
order: matching toolchain → `LyrebirdDSP` vDSP/vForce shim → portable WAV codec
|
||
+ framework guards → deferred DSP (FFT/biquad/mmul) → mach-time + FoundationXML
|
||
→ AudioFileFormat split + OSStatus → NRTDriver/DiskOut WAV backend.
|
||
|
||
What works on Linux today: the entire generator/synthesizer graph, offline
|
||
(NRT) render **to WAV**, WAV disk streaming (`DiskOut`) and reading, the graph
|
||
DSL, MIDI/OSC/AUv3/CoreAudio-drivers excluded (guarded). Apple builds keep every
|
||
format and driver.
|
||
|
||
Still to do for a *runnable* Linux binary (beyond compiling the library):
|
||
a live `LinuxAudioDriver` (PipeWire/ALSA), building the `LyrebirdCLI`/other
|
||
targets for Linux, and a Linux CI lane. FFT/biquad are compile-parity-tested but
|
||
not yet golden-value-tested through the actual spectral generators on Linux.
|
||
|
||
## Deferred DSP — complete
|
||
|
||
`LyrebirdDSP` now provides an Apple-forward + portable implementation of **every**
|
||
vDSP/vForce symbol the core uses. Portable pieces (compiled off Apple; on Apple
|
||
the real Accelerate is re-exported):
|
||
|
||
- Vector ops + vForce (`ScalarDSP.swift`) — earlier stage.
|
||
- `vDSP_vdpsp` (double→float), `vDSP_mmulD` (row-major matmul), biquad family
|
||
(`PortableBiquad.swift`, DF-II, opaque setup), `vDSP_vrampmul`,
|
||
`vDSP_hann_window` (periodic Hann), `vvatan2f`.
|
||
- Real FFT — radix-2 complex core (`ComplexFFTCore.swift`) + real forward/inverse
|
||
matching vDSP's `zrip` packing (DC→`realp[0]`, Nyquist→`imagp[0]`) and scaling
|
||
(forward ×2/bin, forward→inverse ×2N); `PortableFFT.swift` shims
|
||
`create/destroy_fftsetup`, `fft_zrip`, `ctoz`, `ztoc`, `zvmags`, `zvma`;
|
||
`DSPComplex`/`DSPSplitComplex` mirror types.
|
||
|
||
**All parity-tested against real vDSP on Apple** (`LyrebirdDSPTests`, 15 tests):
|
||
FFT forward + round-trip, biquad, matmul, vdpsp, vrampmul, Hann, and the vector
|
||
ops — the guarantee the Linux fallback matches Accelerate. Linux cross-compile:
|
||
**zero unresolved DSP symbols.**
|
||
|
||
## Remaining (non-DSP; the last mile to a compiling Linux core)
|
||
|
||
Errors down to ~1497, now exclusively:
|
||
|
||
1. **Mach time** — `mach_absolute_time`, `mach_timebase_info(_data_t)`,
|
||
`clock_gettime_nsec_np`, `CLOCK_UPTIME_RAW` (monotonic clock). Port to
|
||
`clock_gettime(CLOCK_MONOTONIC)` on Linux — small, localized.
|
||
2. **`FoundationXML`** — `XMLParser`/`XMLParserDelegate` moved out of `Foundation`
|
||
on Linux; `#if canImport(FoundationXML) import FoundationXML` in the 3
|
||
`Score/MusicXML/` files.
|
||
3. **File-I/O cross-references** — `AudioFileFormat`, `DiskOut`, `NRTDriver`,
|
||
`OSStatus` referenced from portable code (SynthesisEngine, EngineHost, NRTJob,
|
||
LyrebirdEventList/Process, RF64Writer, DiskOutFormat). These are the
|
||
entanglement from guarding the AudioToolbox file-I/O out; resolve by wiring
|
||
the (already-built, tested) portable WAV codec into NRTDriver / DiskIn/DiskOut
|
||
and guarding the residual `OSStatus`/AU references.
|
||
|
||
## Remaining (symbol-level, no longer module walls)
|
||
|
||
1. **Deferred DSP** — the shim intentionally omits these off-Apple; they need
|
||
real portable implementations, and they are what the Linux compile now
|
||
reports as `cannot find …`:
|
||
- FFT family — `vDSP_fft_zrip`, `vDSP_create_fftsetup`, `vDSP_ctoz`/`ztoc`,
|
||
`DSPSplitComplex`, `DSPComplex`, `FFTDirection`/`FFTRadix` (Spectral,
|
||
ConvolutionReverb). Needs a portable FFT (pffft / pure-Swift radix-2).
|
||
- Biquad-setup family — `vDSP_biquad*` (Butterworth, Klank, ResonatorBank,
|
||
Moog/MuTron/SVF helpers). Needs a portable biquad.
|
||
- `vDSP_mmulD` (AmbiDecoder1, Pan2/PanN), `vDSP_vdpsp` (double→float in
|
||
SynthesisEngine/ScratchBuses/RF64Writer). Small portable replacements.
|
||
2. **C-lib qualified refs** — a handful of `Darwin.foo` / `memcpy` / bare
|
||
`cos`/`sin` call sites in the above files need the platform C-lib in scope
|
||
(mechanical, folds into stage 1 as those files are touched).
|
||
3. **Live drivers / AUv3 / MIDI / OSC** — currently guarded *out* off-Apple.
|
||
Restoring capability needs `LinuxAudioDriver` (PipeWire/ALSA), a WAV-backed
|
||
NRT driver (codec now exists — wiring pending), RtMidi, POSIX-socket OSC.
|
||
|
||
Before any merge: run full `swift test` on macOS + `/lyrebird_review`. The
|
||
import migrations are semantic no-ops via re-export/guards on Apple, but CI must
|
||
confirm.
|
||
|
||
### Reproduce the cross-compile
|
||
|
||
```
|
||
swift sdk install <static-linux-sdk-url> --checksum <sha>
|
||
# matching swift.org toolchain required (Xcode's will not pair with the SDK):
|
||
~/Library/Developer/Toolchains/swift-6.3.3-RELEASE.xctoolchain/usr/bin/swift \
|
||
build --swift-sdk aarch64-swift-linux-musl --target LyrebirdSynth --scratch-path .build-linux
|
||
```
|