// 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" ), ] )