// swift-tools-version: 6.0 import PackageDescription // ProcessInfo — read the LYREBIRD_DISABLE_ALSA opt-out below. import Foundation let package = Package( name: "Lyrebird", platforms: [.macOS(.v15), .iOS(.v18)], products: [ // Consumer-facing product. Automatic linkage → SwiftPM/Xcode link the // `LyrebirdSynth` module statically into the downstream target. No // dynamic framework is produced, so the Xcode 26 regression where the // `PackageFrameworks/Lyrebird.framework` binary is never built (and the // app fails to link / launch) cannot affect external consumers. // Product name ≠ target name (`Lyrebird` vends `LyrebirdSynth`) so there // is also no static-vs-dynamic same-name collision. Consumers add the // `Lyrebird` product and write `import LyrebirdSynth`. .library(name: "Lyrebird", targets: ["LyrebirdSynth"]), // Internal-only DYNAMIC product — consumed solely by the nested // `LiveCompile/` dev sub-package. LiveCompile needs a single shared // `libLyrebirdDynamic.dylib` on disk so the host and each live-compiled // snippet dylib resolve to ONE copy of every Lyrebird class (the ObjC // double-registration crash fixed in Phase 167). External consumers // never reference this product — they use `Lyrebird` (static) above. .library(name: "LyrebirdDynamic", type: .dynamic, targets: ["LyrebirdSynth"]), // LyrebirdUI (SwiftUI/AppKit) product + targets are appended after this // literal under `#if os(macOS)` — they are Apple-only and must be absent // from the manifest on a native Linux/Windows host. See the block below // the `Package(...)` initializer. .library(name: "LyrebirdGraphDSL", targets: ["LyrebirdGraphDSL"]), .executable(name: "LyrebirdCLI", targets: ["LyrebirdCLI"]), ], dependencies: [ // LineNoise 0.0.3 — readline-style line editing, history, and tab completion. // // Package.resolved note: Nimble (Quick/Nimble) appears as a pinned dependency // because LineNoise 0.0.3's own test target depends on it. SPM resolves all // transitive test dependencies into Package.resolved regardless of whether they // are reachable from this package's targets. Nimble is NOT built, NOT linked, // and NOT importable in any Lyrebird target — the `LineNoise` library target // itself has zero dependencies. This is a known SPM artifact that cannot be // removed without forking linenoise-swift. .package( url: "https://github.com/andybest/linenoise-swift", .upToNextMajor(from: "0.0.3") ), // swift-docc-plugin — command plugin that drives DocC documentation builds. // Registers two commands available to all targets in this package: // • In Xcode: Product ▸ Build Documentation (or scheme-level build action) // • From CLI: swift package generate-documentation --target LyrebirdSynth // swift package preview-documentation --target LyrebirdSynth // No target-level plugins: entry is needed — command plugins apply package-wide. .package( url: "https://github.com/apple/swift-docc-plugin", from: "1.3.0" ), ], targets: [ // Thin C shim that exposes fesetenv(FE_DFL_DISABLE_DENORMS_ENV) to Swift. // FE_DFL_DISABLE_DENORMS_ENV is a C-only macro sentinel ((fenv_t *)-2) that cannot // be referenced from Swift directly; the C wrapper lets Lyrebird call it safely. .target( name: "LyrebirdC", path: "Sources/LyrebirdC" ), // Vector-math seam. On Apple this target re-exports Accelerate // (`@_exported import Accelerate`); on non-Apple platforms it supplies // API-compatible scalar replacements for the vDSP/vForce primitives the // synthesis core uses. Every core file writes `import LyrebirdDSP` in // place of `import Accelerate`. See Sources/LyrebirdDSP/AccelerateShim.swift. .target( name: "LyrebirdDSP", path: "Sources/LyrebirdDSP", linkerSettings: [ .linkedFramework("Accelerate", .when(platforms: [.macOS, .iOS])), ] ), .target( // Module/target renamed `Lyrebird` → `LyrebirdSynth` (the `Lyrebird` // product above still vends it). Folder path kept as `Sources/Lyrebird` // so the source tree and `Lyrebird.docc` catalog don't move. name: "LyrebirdSynth", // `CALSA` (libasound, for the Linux `ALSAAudioDriver`) is appended // to these dependencies on a Linux host — see the block below the // `Package(...)` initializer. dependencies: ["LyrebirdC", "LyrebirdDSP"], path: "Sources/Lyrebird", linkerSettings: [ // Apple-only frameworks. Guarded with `.when(platforms:)` so a // non-Apple target (Linux/Windows feasibility) does not fail at // link-configuration time before source-level errors surface. // macOS/iOS builds are unaffected. .linkedFramework("CoreAudio", .when(platforms: [.macOS, .iOS])), .linkedFramework("AudioToolbox", .when(platforms: [.macOS, .iOS])), .linkedFramework("Accelerate", .when(platforms: [.macOS, .iOS])), .linkedFramework("CoreMIDI", .when(platforms: [.macOS, .iOS])), .linkedFramework("AVFoundation", .when(platforms: [.macOS, .iOS])), ] ), .executableTarget( name: "LyrebirdCLI", dependencies: [ .product(name: "LineNoise", package: "linenoise-swift"), ], path: "Sources/LyrebirdCLI", resources: [ // Xcode .xctemplate bundles installed by `lyrebird install-templates`. // .copy preserves the directory structure exactly (Xcode discovers // templates by .xctemplate bundle name + TemplateInfo.plist). .copy("Resources/XcodeTemplates"), ] // Swift 6 language mode (Phase 202): inherits the swift-tools 6.0 default. ), // NOTE: LyrebirdUI, LyrebirdUITests, and LyrebirdTests are appended after // the `Package(...)` initializer under `#if os(macOS)` — they need Apple // frameworks and must be absent from a native Linux/Windows manifest. // Phase 167 — `LyrebirdLiveCompile` (and its SwiftUI host // `LyrebirdLiveCompileUI`) moved to the `LiveCompile/` nested SwiftPM // package. It depends on the internal `.product(name: "LyrebirdDynamic", // package: "Lyrebird")` (the dynamic product above) so SwiftPM // dynamic-links the live-compile dylib against `libLyrebirdDynamic.dylib` // instead of statically embedding the core module's classes — the root // cause of an ObjC class double-registration crash during `swift test` // in the single-package layout. The consumer-facing `Lyrebird` product // stays static (see products list). See `LiveCompile/Package.swift`. // LyrebirdBenchmark micro-benchmarks Accelerate/vDSP primitives directly // (`import Accelerate`), so it is Apple-only and appended under // `#if os(macOS)` below the initializer — otherwise `swift test` on Linux // would try to build it and fail on the missing Accelerate module. // Interpreted graph-DSL. Pure Swift over core `LyrebirdSynth` types — // no swiftc, no AppKit — so it is cross-platform (iOS included). The // `DSLBuiltin` registry it consumes is emitted by the separate // `DSLRegistryGen` code-gen tool (the only thing that depends on // swift-syntax); this shipped target does not. .target( name: "LyrebirdGraphDSL", dependencies: ["LyrebirdSynth"], path: "Sources/LyrebirdGraphDSL" ), .testTarget( name: "LyrebirdDSPTests", dependencies: ["LyrebirdDSP"], path: "Tests/LyrebirdDSPTests", linkerSettings: [ .linkedFramework("Accelerate", .when(platforms: [.macOS, .iOS])), ] ), .testTarget( name: "LyrebirdGraphDSLTests", dependencies: [ "LyrebirdGraphDSL", "LyrebirdSynth", ], path: "Tests/LyrebirdGraphDSLTests", linkerSettings: [ .linkedFramework("AudioToolbox", .when(platforms: [.macOS, .iOS])), .linkedFramework("Accelerate", .when(platforms: [.macOS, .iOS])), ] ), .testTarget( name: "LyrebirdCLITests", dependencies: ["LyrebirdCLI"], path: "Tests/LyrebirdCLITests" ), // Platform-neutral core tests. Unlike `LyrebirdTests` (Apple-only — // some files import AudioToolbox/Accelerate directly), this target // compiles and runs on every supported platform, so the golden-value // DSP tests it holds actually execute on Linux in CI. That is the only // place the portable FFT/biquad/vector fallbacks in `LyrebirdDSP` are // verified through the real generators; `LyrebirdDSPTests` compares to // real vDSP and is therefore Apple-only by construction. .testTarget( name: "LyrebirdPortableTests", dependencies: ["LyrebirdSynth"], path: "Tests/LyrebirdPortableTests", linkerSettings: [ .linkedFramework("AudioToolbox", .when(platforms: [.macOS, .iOS])), .linkedFramework("Accelerate", .when(platforms: [.macOS, .iOS])), ] ), ] ) // LyrebirdUI — the cross-platform UI module. Public control/view names are the // same on every platform; each file switches its body by backend // (`#if canImport(SwiftUI)` → real SwiftUI on Apple / `#else` → SwiftOpenUI on // Linux). Base dependency is `LyrebirdSynth` (the shared `@UIParam` model); // the Linux block below adds the SwiftOpenUI + BackendGTK4 backend deps. On // Apple, SwiftUI/AppKit are system frameworks so no package dep is needed. package.products.append( .library(name: "LyrebirdUI", targets: ["LyrebirdUI"]) ) package.targets.append( .target( name: "LyrebirdUI", dependencies: ["LyrebirdSynth"], path: "Sources/LyrebirdUI" ) ) // Apple-only pieces, added only when the manifest host is macOS. // // `#if` cannot appear as an element inside an array literal in a package // manifest, so these are appended to the already-built `package` instead of // being conditionalized in place. On a native Linux/Windows host (in-container // `swift build`/`swift test`, CI) they are simply absent, so nothing tries to // compile SwiftUI/AppKit or the AudioToolbox-importing test files. // // • LyrebirdUITests — exercises LyrebirdUI (the module itself is now // cross-platform and appended above the initializer). // • LyrebirdBenchmark — micro-benchmarks Accelerate/vDSP primitives directly. // • LyrebirdTests — the main suite; still imports Apple frameworks // directly in some files (e.g. AUv3 driver tests). // Porting its platform-neutral majority to run on // Linux, plus Linux-runnable golden DSP tests, is a // separate work item. // // Cross-compiling from a Mac keeps the host as macOS, so Apple-SDK builds are // unaffected — they still see every target. #if os(macOS) package.targets.append(contentsOf: [ .executableTarget( name: "LyrebirdBenchmark", dependencies: ["LyrebirdSynth"], path: "Sources/LyrebirdBenchmark", swiftSettings: [.unsafeFlags(["-O"])] ), .testTarget( name: "LyrebirdTests", dependencies: ["LyrebirdSynth"], path: "Tests/LyrebirdTests", linkerSettings: [ .linkedFramework("AudioToolbox", .when(platforms: [.macOS, .iOS])), .linkedFramework("Accelerate", .when(platforms: [.macOS, .iOS])), ] ), .testTarget( name: "LyrebirdUITests", dependencies: [ "LyrebirdUI", "LyrebirdSynth", ], path: "Tests/LyrebirdUITests" ), ]) #endif // Linux live audio. `ALSAAudioDriver` needs libasound's headers, which are not // installed by default on a build box (`apt-get install libasound2-dev`), so // the target is added only when the manifest is being evaluated ON Linux — // where those headers can actually exist. A macOS host never sees it, whether // building for Apple platforms or cross-compiling to Linux; a cross-compiled // Linux binary therefore has no live-audio driver, only offline NRT rendering. // Build natively on Linux to get audio out. // // Escape hatch: set `LYREBIRD_DISABLE_ALSA=1` to build the rest of Lyrebird on // a Linux box that has no ALSA development package. Everything except the // driver still works — `ALSAAudioDriver` is `#if canImport(CALSA)`-guarded and // simply will not exist, and `makeDefaultAudioDriver()` returns an // `OfflineDriver` instead. Note that SwiftPM caches evaluated manifests, so // flipping this variable on an existing checkout may need the cache cleared // (`rm -rf .build`, or a fresh `--scratch-path`) before it takes effect. #if os(Linux) if ProcessInfo.processInfo.environment["LYREBIRD_DISABLE_ALSA"] == nil { package.targets.append( .systemLibrary( name: "CALSA", path: "Sources/CALSA", pkgConfig: "alsa", providers: [ .apt(["libasound2-dev"]), ] ) ) if let synthIndex: Int = package.targets.firstIndex(where: { $0.name == "LyrebirdSynth" }) { package.targets[synthIndex].dependencies.append(.target(name: "CALSA")) } // The portable test target needs it too: its ALSA tests are guarded on // `canImport(CALSA)`, which is only true where the module is a dependency. // Without this the guard is always false and the driver's tests silently // never run. if let testIndex: Int = package.targets.firstIndex(where: { $0.name == "LyrebirdPortableTests" }) { package.targets[testIndex].dependencies.append(.target(name: "CALSA")) } } #endif // Linux backend for the cross-platform `LyrebirdUI`: SwiftOpenUI (GTK4). This is // now a DEFAULT Linux dependency — building `LyrebirdUI` on Linux pulls // SwiftOpenUI and needs `libgtk-4-dev`. (The default *core* Linux CI lane builds // only LyrebirdSynth / LyrebirdGraphDSL / LyrebirdCLI, so it does not build the // UI or need GTK; a plain `swift build` on Linux does.) // // Pinned to a personal fork commit carrying the GTK4 drag fix ("GTK4: continuous // drag for Canvas value controls": @Observable narrow path + live subtree redraw // + global interaction deferral with linked-control redraw). Move the pin to // `codelynx/SwiftOpenUI` + a version once the fix lands upstream and a release is // tagged. See spikes/SwiftOpenUIKnob/FORK_PATCH_PLAN.md. // // `LyrebirdUI`'s controls bind core `@UIParam` / `UIParamNode` (in // `LyrebirdSynth`), the same model the SwiftUI controls use, so one synthesizer's // parameters drive both platforms. #if os(Linux) // Set LYREBIRD_SWIFTOPENUI_LOCAL=/path/to/SwiftOpenUI to build against a local // fork checkout instead of the pinned release — used to iterate the GTK4 fork // without a push/pin round-trip (this Mac can't build the GTK4 backend; a Linux // container or the VM does). Unset (the default), it resolves the pinned tag. package.dependencies.append( ProcessInfo.processInfo.environment["LYREBIRD_SWIFTOPENUI_LOCAL"].map { .package(name: "SwiftOpenUI", path: $0) } ?? // Pinned to the fork's tagged release 0.5.0 (== commit a392026): 0.1.0 // (Patches A–F narrow-path + GTK4Backend.openStandaloneWindow → LyrebirdWindow // / presentInWindow + GTK4PointerTracking → Linux MouseTracker), plus the // GtkSourceView-backed `CodeEditor` view (Swift highlighting + gutter) used by // the Linux live-compile scratch editor — which adds a system dependency on // libgtksourceview-5-dev. A tag rather than a bare commit gives a stable, // human-readable release reference; bump it when the fork cuts a new release. // (Upstreaming to codelynx/SwiftOpenUI remains the open follow-on — see // docs/ui/linux-parity-plan.md.) .package( url: "https://github.com/joshpar/SwiftOpenUI", exact: "0.7.0" ) ) // Give the cross-platform LyrebirdUI target its Linux (GTK4) backend deps. if let uiIndex: Int = package.targets.firstIndex(where: { $0.name == "LyrebirdUI" }) { package.targets[uiIndex].dependencies.append(contentsOf: [ .product(name: "SwiftOpenUI", package: "SwiftOpenUI"), .product(name: "BackendGTK4", package: "SwiftOpenUI"), ]) } // Runnable GTK4 GUI demo: `swift run LyrebirdUILinuxDemo`. package.targets.append( .executableTarget( name: "LyrebirdUILinuxDemo", dependencies: ["LyrebirdSynth", "LyrebirdUI"], path: "Sources/LyrebirdUILinuxDemo" ) ) #endif