Files
Lyrebird/LiveCompile/Package.swift
T
josh b6fdee8bfc Lyrebird 2.0.0 — Linux support
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>
2026-09-10 21:09:11 -07:00

142 lines
6.2 KiB
Swift

// Package.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
// swift-tools-version: 6.0
import PackageDescription
// `LyrebirdLiveCompile` and `LyrebirdLiveCompileUI` live in this
// sub-package so that cross-package `.product(name:, package:)` dependency
// resolution forces SwiftPM to dynamic-link `libLyrebirdLiveCompile.dylib`
// against `libLyrebird.dylib` instead of statically embedding `Lyrebird`'s
// classes (which caused ObjC class double-registration during `swift test`
// in the single-package layout).
//
// macOS-only — the host swiftc-shell-out + dlopen surface cannot run on iOS.
let package = Package(
name: "LyrebirdLiveCompile",
platforms: [.macOS(.v15)],
products: [
// Product name ≠ target name (mirrors the main package's
// `Lyrebird`/`LyrebirdDynamic` pairing). A `.dynamic` product whose name
// EQUALS its target name collides in Xcode when that target is also
// referenced as a static link elsewhere in the same build graph:
// "Swift package target 'X' is linked as a static library by … but
// cannot be built dynamically because there is a package product with
// the same name." Naming the dynamic products `…Dynamic` removes the
// collision so each target builds as a single shared dylib that every
// consumer links dynamically. Target/module names are unchanged, so
// `import LyrebirdLiveCompile` / `import LyrebirdLiveCompileUI` and the
// test targets (which reference targets by name) are unaffected.
.library(
name: "LyrebirdLiveCompileDynamic",
type: .dynamic,
targets: ["LyrebirdLiveCompile"]
),
.library(
name: "LyrebirdLiveCompileUIDynamic",
type: .dynamic,
targets: ["LyrebirdLiveCompileUI"]
),
],
dependencies: [
.package(name: "Lyrebird", path: "..")
],
targets: [
// The interpreted graph-DSL, compiled from the main package's shared
// sources (a symlink at `Sources/LyrebirdGraphDSLEmbedded`) as a LOCAL
// target here rather than consumed as a main-package product.
//
// Why not the main-package product: any `LyrebirdGraphDSL` product —
// static OR dynamic — bakes a SECOND copy of `LyrebirdSynth` into its
// dylib (a same-package target dependency is always static-embedded), so
// both `libLyrebirdDynamic` and that product's dylib register Lyrebird's
// ObjC classes → double registration → spurious cast failures + SIGSEGV
// under `swift test`. Compiling the DSL as a local target here lets its
// `import LyrebirdSynth` resolve cross-package to the ONE shared
// `libLyrebirdDynamic`. Safe because the DSL is pure value types (no
// classes), so recompiling it in a second module registers nothing with
// the ObjC runtime. Distinct module name (`…Embedded`) avoids any clash
// with the main package's `LyrebirdGraphDSL` in a shared Xcode graph.
.target(
name: "LyrebirdGraphDSLEmbedded",
dependencies: [
.product(name: "LyrebirdDynamic", package: "Lyrebird"),
],
path: "Sources/LyrebirdGraphDSLEmbedded"
),
.target(
name: "LyrebirdLiveCompile",
dependencies: [
.product(name: "LyrebirdDynamic", package: "Lyrebird"),
// Instant, no-swiftc graph evaluation for the editor's DSL mode.
"LyrebirdGraphDSLEmbedded",
],
path: "Sources/LyrebirdLiveCompile"
),
.target(
name: "LyrebirdLiveCompileUI",
dependencies: [
"LyrebirdLiveCompile",
.product(name: "LyrebirdDynamic", package: "Lyrebird"),
],
path: "Sources/LyrebirdLiveCompileUI"
// Swift 6 language mode: inherits the swift-tools 6.0 default.
),
.testTarget(
name: "LyrebirdLiveCompileTests",
dependencies: [
"LyrebirdLiveCompile",
.product(name: "LyrebirdDynamic", package: "Lyrebird"),
"LyrebirdGraphDSLEmbedded",
],
path: "Tests/LyrebirdLiveCompileTests"
),
.testTarget(
name: "LyrebirdLiveCompileUITests",
dependencies: [
"LyrebirdLiveCompile",
"LyrebirdLiveCompileUI",
.product(name: "LyrebirdDynamic", package: "Lyrebird"),
],
path: "Tests/LyrebirdLiveCompileUITests"
),
]
)
#if os(Linux)
// On Linux the editor UI is SwiftOpenUI/GTK4 (the macOS AppKit surface is
// #if os(macOS)-gated out). Wire the cross-platform LyrebirdUI product — which
// @_exported re-exports SwiftOpenUI + BackendGTK4 and provides LyrebirdWindow /
// LyrebirdScopeView — into the UI target, plus a runnable minimal scratch demo:
// LYREBIRD_ENABLE_LINUX_UI is not needed; `swift run LyrebirdScratchLinuxDemo`.
if let uiIndex: Int = package.targets.firstIndex(where: { $0.name == "LyrebirdLiveCompileUI" }) {
package.targets[uiIndex].dependencies.append(
.product(name: "LyrebirdUI", package: "Lyrebird")
)
}
package.targets.append(
.executableTarget(
name: "LyrebirdScratchLinuxDemo",
dependencies: [
"LyrebirdLiveCompile",
"LyrebirdLiveCompileUI",
.product(name: "LyrebirdDynamic", package: "Lyrebird"),
.product(name: "LyrebirdUI", package: "Lyrebird"),
],
path: "Sources/LyrebirdScratchLinuxDemo"
// NOTE: a live-compiled snippet links `-lLyrebirdDynamic
// -lLyrebirdLiveCompileDynamic`, so those shared libraries must exist in
// the build dir before you Run. A same-package target can't depend on a
// same-package product to force them, so build the whole package first —
// `swift build` (builds all products, incl. the …Dynamic .so's) — then
// `swift run LyrebirdScratchLinuxDemo`. `swift run` alone only builds the
// executable's own graph and would leave the snippet link unable to find
// libLyrebirdLiveCompileDynamic.so.
)
)
#endif