Static consumer product + internal dynamic for LiveCompile
The Lyrebird product was forced type: .dynamic, forcing an SPM dynamic framework on consumers and hitting the Xcode 26 regression (PackageFrameworks/Lyrebird.framework binary missing). Split into two products vending the same LyrebirdSynth target: • Lyrebird (automatic → static): consumer-facing, no framework, no workarounds. • LyrebirdDynamic (.dynamic): internal-only, consumed by LiveCompile. LiveCompile repointed to LyrebirdDynamic with linker refs updated (libLyrebirdDynamic.dylib). README + GettingStarted updated: consumers link static and need no disable-library-validation entitlement or driver override. Verified: core + LiveCompile (34/34) build/test clean; external consumer links the static product with no dynamic dylib. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
||||
.build/
|
||||
.claude/settings.local.json
|
||||
.claude/worktrees/
|
||||
*.o
|
||||
*.d
|
||||
*.swp
|
||||
.DS_Store
|
||||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
|
||||
xcuserdata/
|
||||
*.xcuserstate
|
||||
@@ -37,7 +37,7 @@ let package = Package(
|
||||
.target(
|
||||
name: "LyrebirdLiveCompile",
|
||||
dependencies: [
|
||||
.product(name: "Lyrebird", package: "Lyrebird"),
|
||||
.product(name: "LyrebirdDynamic", package: "Lyrebird"),
|
||||
],
|
||||
path: "Sources/LyrebirdLiveCompile"
|
||||
),
|
||||
@@ -45,7 +45,7 @@ let package = Package(
|
||||
name: "LyrebirdLiveCompileUI",
|
||||
dependencies: [
|
||||
"LyrebirdLiveCompile",
|
||||
.product(name: "Lyrebird", package: "Lyrebird"),
|
||||
.product(name: "LyrebirdDynamic", package: "Lyrebird"),
|
||||
],
|
||||
path: "Sources/LyrebirdLiveCompileUI",
|
||||
swiftSettings: [.swiftLanguageMode(.v5)]
|
||||
@@ -54,7 +54,7 @@ let package = Package(
|
||||
name: "LyrebirdLiveCompileTests",
|
||||
dependencies: [
|
||||
"LyrebirdLiveCompile",
|
||||
.product(name: "Lyrebird", package: "Lyrebird"),
|
||||
.product(name: "LyrebirdDynamic", package: "Lyrebird"),
|
||||
],
|
||||
path: "Tests/LyrebirdLiveCompileTests"
|
||||
),
|
||||
@@ -63,7 +63,7 @@ let package = Package(
|
||||
dependencies: [
|
||||
"LyrebirdLiveCompile",
|
||||
"LyrebirdLiveCompileUI",
|
||||
.product(name: "Lyrebird", package: "Lyrebird"),
|
||||
.product(name: "LyrebirdDynamic", package: "Lyrebird"),
|
||||
],
|
||||
path: "Tests/LyrebirdLiveCompileUITests",
|
||||
swiftSettings: [.swiftLanguageMode(.v5)]
|
||||
|
||||
@@ -36,7 +36,7 @@ public final class LiveSession {
|
||||
public let libraries: [String]
|
||||
|
||||
/// `-Xlinker -rpath -Xlinker <path>` entries baked into the snippet dylib
|
||||
/// so `dlopen` resolves dependent dylibs (`libLyrebird.dylib` etc.) at
|
||||
/// so `dlopen` resolves dependent dylibs (`libLyrebirdDynamic.dylib` etc.) at
|
||||
/// runtime without `DYLD_LIBRARY_PATH` ceremony.
|
||||
public let rpaths: [URL]
|
||||
|
||||
@@ -57,7 +57,7 @@ public final class LiveSession {
|
||||
engine: SynthesisEngine,
|
||||
importPaths: [URL] = LiveSession.defaultImportPaths(),
|
||||
librarySearchPaths: [URL] = LiveSession.defaultLibrarySearchPaths(),
|
||||
libraries: [String] = ["Lyrebird", "LyrebirdLiveCompile"],
|
||||
libraries: [String] = ["LyrebirdDynamic", "LyrebirdLiveCompile"],
|
||||
rpaths: [URL] = LiveSession.defaultRpaths()
|
||||
) {
|
||||
self.engine = engine
|
||||
@@ -257,7 +257,7 @@ public final class LiveSession {
|
||||
// MARK: - Build-dir discovery
|
||||
|
||||
/// Best-effort discovery of the SPM `.build/<triple>/<config>` directory
|
||||
/// that contains `libLyrebird.dylib` and the swiftmodule directories. Used
|
||||
/// that contains `libLyrebirdDynamic.dylib` and the swiftmodule directories. Used
|
||||
/// as the default for `importPaths`/`librarySearchPaths`/`rpaths`. Hosts can
|
||||
/// override by passing explicit URLs.
|
||||
///
|
||||
@@ -277,9 +277,11 @@ public final class LiveSession {
|
||||
// LyrebirdSynth.swiftmodule (Xcode SPM static-linked into the host app).
|
||||
// The swiftmodule alone is enough for `-I` module resolution; linking
|
||||
// falls back to `-undefined dynamic_lookup` when no dylib is found.
|
||||
// Note: the product/dylib is named `Lyrebird` (libLyrebird.dylib); the
|
||||
// module/target is named `LyrebirdSynth` (LyrebirdSynth.swiftmodule).
|
||||
let markers: [String] = ["libLyrebird.dylib", "LyrebirdSynth.swiftmodule"]
|
||||
// Note: LiveCompile depends on the internal `LyrebirdDynamic` product
|
||||
// (→ libLyrebirdDynamic.dylib); the module/target is `LyrebirdSynth`
|
||||
// (LyrebirdSynth.swiftmodule). The consumer-facing `Lyrebird` product
|
||||
// is static and produces no dylib, so it is not a marker here.
|
||||
let markers: [String] = ["libLyrebirdDynamic.dylib", "LyrebirdSynth.swiftmodule"]
|
||||
for start: URL in candidates {
|
||||
var cur: URL = start
|
||||
for _ in 0..<maxWalk {
|
||||
@@ -297,13 +299,13 @@ public final class LiveSession {
|
||||
return nil
|
||||
}
|
||||
|
||||
/// `true` when a `libLyrebird.dylib` actually exists in `buildDir`. Used to
|
||||
/// decide whether to link against the dylib at compile time or fall back to
|
||||
/// `-undefined dynamic_lookup` so the snippet binds to symbols already
|
||||
/// resolved in the running process.
|
||||
/// `true` when a `libLyrebirdDynamic.dylib` actually exists in `buildDir`.
|
||||
/// Used to decide whether to link against the dylib at compile time or fall
|
||||
/// back to `-undefined dynamic_lookup` so the snippet binds to symbols
|
||||
/// already resolved in the running process.
|
||||
public static func hasLyrebirdDylib(in buildDir: URL) -> Bool {
|
||||
FileManager.default.fileExists(
|
||||
atPath: buildDir.appendingPathComponent("libLyrebird.dylib").path
|
||||
atPath: buildDir.appendingPathComponent("libLyrebirdDynamic.dylib").path
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ struct LiveSessionTests {
|
||||
@Test
|
||||
func buildDirDiscoveryFindsLyrebirdDylib() throws {
|
||||
let buildDir: URL = try #require(LiveSession.currentBuildDir())
|
||||
let dylib: URL = buildDir.appendingPathComponent("libLyrebird.dylib")
|
||||
let dylib: URL = buildDir.appendingPathComponent("libLyrebirdDynamic.dylib")
|
||||
#expect(FileManager.default.fileExists(atPath: dylib.path))
|
||||
}
|
||||
|
||||
|
||||
+23
-14
@@ -5,14 +5,22 @@ let package = Package(
|
||||
name: "Lyrebird",
|
||||
platforms: [.macOS(.v15), .iOS(.v18)],
|
||||
products: [
|
||||
// Product name stays `Lyrebird` (external API), but it vends the
|
||||
// renamed `LyrebirdSynth` target/module. Product name ≠ target name is
|
||||
// required: a forced-`.dynamic` product cannot share a name with its
|
||||
// target when a downstream project's graph also static-links that
|
||||
// target ("linked as a static library … but cannot be built
|
||||
// dynamically because there is a package product with the same name").
|
||||
// Consumers add the `Lyrebird` product and write `import LyrebirdSynth`.
|
||||
.library(name: "Lyrebird", type: .dynamic, targets: ["LyrebirdSynth"]),
|
||||
// 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"]),
|
||||
.library(name: "LyrebirdUI", targets: ["LyrebirdUI"]),
|
||||
.executable(name: "LyrebirdCLI", targets: ["LyrebirdCLI"]),
|
||||
],
|
||||
@@ -94,12 +102,13 @@ let package = Package(
|
||||
),
|
||||
// Phase 167 — `LyrebirdLiveCompile` (and its SwiftUI host
|
||||
// `LyrebirdLiveCompileUI`) moved to the `LiveCompile/` nested SwiftPM
|
||||
// package. The cross-package `.product(name: "Lyrebird", package: "Lyrebird")`
|
||||
// dependency there forces SwiftPM to dynamic-link the live-compile dylib
|
||||
// against `libLyrebird.dylib` instead of statically embedding the core
|
||||
// module's classes, which was the root cause of an ObjC class
|
||||
// double-registration crash during `swift test` in the single-package
|
||||
// layout. See `LiveCompile/Package.swift`.
|
||||
// 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`.
|
||||
.executableTarget(
|
||||
name: "LyrebirdBenchmark",
|
||||
dependencies: ["LyrebirdSynth"],
|
||||
|
||||
@@ -141,18 +141,9 @@ Add the package:
|
||||
https://realizedsound.mooo.com/josh/Lyrebird.git
|
||||
```
|
||||
|
||||
**File ▸ Add Package Dependencies…** → that URL → **Up to Next Major** from `1.0.0` → add the `Lyrebird` product (and `LyrebirdUI` for the SwiftUI controls).
|
||||
**File ▸ Add Package Dependencies…** → that URL → **Up to Next Major** from `1.0.0` → add the `Lyrebird` product (and `LyrebirdUI` for the SwiftUI controls). Write `import LyrebirdSynth` in your code (the product is `Lyrebird`; the module it vends is `LyrebirdSynth`).
|
||||
|
||||
Then three settings a hand-made project needs (the `lyrebird new` scaffolds set all three for you):
|
||||
|
||||
1. **Embed the framework.** App targets: confirm Lyrebird shows under *General ▸ Frameworks, Libraries, and Embedded Content* as **Embed & Sign** (Xcode sets this automatically). CLI/SwiftPM executables need no embed.
|
||||
2. **Disable library validation** — required for any target with **Hardened Runtime** (signed apps + all AUv3). `Lyrebird` ships as a `.dynamic` library; its SPM-built `libLyrebird.dylib` is ad-hoc-signed, so dyld otherwise fails with `dyld: Library not loaded`. Add to the target's `.entitlements`, then clean build (⇧⌘K):
|
||||
```xml
|
||||
<key>com.apple.security.cs.disable-library-validation</key>
|
||||
<true/>
|
||||
```
|
||||
Plain debug apps without Hardened Runtime can skip this.
|
||||
3. **Xcode 26 Swift-driver workaround** (only if the build throws Swift driver errors): set `SWIFT_USE_INTEGRATED_DRIVER = NO` and `parallelizeBuildables = NO` in Build Settings.
|
||||
That's it — the `Lyrebird` product links **statically**, so there's no dynamic framework, no embed step, and **no special build settings**: you do *not* need a `disable-library-validation` entitlement or a `SWIFT_USE_INTEGRATED_DRIVER` override. It just links, even under Hardened Runtime / sandbox / AUv3.
|
||||
|
||||
Full walk-through (SPM manifest form, local-path dev dependency, per-template details): [`INSTALLATION_AND_USAGE.md`](INSTALLATION_AND_USAGE.md). DocC version: **Getting Started ▸ Adding Lyrebird to your own Xcode project**.
|
||||
|
||||
@@ -193,8 +184,8 @@ Use `Lyrebird-Package` for day-to-day development of the engine and tests.
|
||||
| `Synchronization.Atomic` not indexed | Requires Xcode 16+ — false errors in older versions, still builds |
|
||||
| LineNoise concurrency warnings | Expected — `LyrebirdCLI` uses `.swiftLanguageMode(.v5)` intentionally |
|
||||
| Nimble in Package dependencies | Cosmetic — LineNoise transitive dep, never built in Lyrebird targets |
|
||||
| Build fails with Swift driver errors | Xcode 26 bug — workspace already sets `SWIFT_USE_INTEGRATED_DRIVER = NO`, `parallelizeBuildables = NO`, `type: .dynamic`. In your own project see [Adding Lyrebird to your own project](#adding-lyrebird-to-your-own-project) |
|
||||
| `dyld: Library not loaded` | Hardened Runtime rejects the ad-hoc-signed SPM framework — add `com.apple.security.cs.disable-library-validation = true` to entitlements, then clean build (⇧⌘K). Full steps: [Adding Lyrebird to your own project](#adding-lyrebird-to-your-own-project) |
|
||||
| Build fails with Swift driver errors | Xcode 26 bug affecting the **demo workspace** (which dynamic-links for live-coding) — it already sets `SWIFT_USE_INTEGRATED_DRIVER = NO` + `parallelizeBuildables = NO`. Your own project links Lyrebird statically and is unaffected. |
|
||||
| `dyld: Library not loaded` | Only the bundled demos/AUv3 use the dynamic `LyrebirdDynamic` product; their entitlements already set `disable-library-validation`. External consumers link the static `Lyrebird` product and never hit this. |
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -165,12 +165,8 @@ Writes a starter ``SynthesizerBase`` subclass into your project.
|
||||
|
||||
## Adding Lyrebird to your own Xcode project
|
||||
|
||||
If you're not using the scaffolder — adding Lyrebird as a dependency of an
|
||||
existing or hand-made Xcode project — there are three settings to know. The
|
||||
generated templates set these for you; a hand-made project needs them applied
|
||||
manually.
|
||||
|
||||
### 1. Add the package and product
|
||||
Adding Lyrebird as a dependency of an existing or hand-made Xcode project is a
|
||||
single step — no special build settings required.
|
||||
|
||||
**File ▸ Add Package Dependencies…**, enter the repository URL:
|
||||
|
||||
@@ -179,47 +175,25 @@ https://realizedsound.mooo.com/josh/Lyrebird.git
|
||||
```
|
||||
|
||||
Choose **Up to Next Major Version** from `1.0.0`, then add the `Lyrebird`
|
||||
product (and `LyrebirdUI` if you use the SwiftUI controls) to your target.
|
||||
product (and `LyrebirdUI` if you use the SwiftUI controls) to your target. In
|
||||
your source write `import LyrebirdSynth` — the *product* is named `Lyrebird`,
|
||||
the *module* it vends is `LyrebirdSynth`.
|
||||
|
||||
For an **app** target, confirm Lyrebird appears under **General ▸ Frameworks,
|
||||
Libraries, and Embedded Content** with **Embed & Sign** selected — Xcode sets
|
||||
this automatically for apps. A plain command-line / SwiftPM executable target
|
||||
needs no embed step.
|
||||
The `Lyrebird` product uses **automatic linkage**, so SwiftPM/Xcode link it
|
||||
**statically** into your target. There is no dynamic framework to embed and no
|
||||
ad-hoc-signed dylib to load, which means:
|
||||
|
||||
### 2. Hardened Runtime → disable library validation
|
||||
- **No** `com.apple.security.cs.disable-library-validation` entitlement.
|
||||
- **No** `SWIFT_USE_INTEGRATED_DRIVER` / `parallelizeBuildables` override.
|
||||
- Works as-is under Hardened Runtime, App Sandbox, and AUv3.
|
||||
|
||||
`Lyrebird` is built as a **dynamic** library (`type: .dynamic` in its
|
||||
`Package.swift` — a deliberate workaround for an Xcode 26 SwiftPM regression,
|
||||
reverting to `.static` once fixed). The SwiftPM-built `libLyrebird.dylib` is
|
||||
ad-hoc-signed, not signed by your team. Any target with **Hardened Runtime**
|
||||
enabled — every signed/notarized app, and **all** AUv3 extensions — will
|
||||
otherwise fail at launch with:
|
||||
|
||||
```
|
||||
dyld: Library not loaded: @rpath/libLyrebird.dylib
|
||||
```
|
||||
|
||||
Fix: add this key to the target's `.entitlements`, then clean build (⇧⌘K):
|
||||
|
||||
```xml
|
||||
<key>com.apple.security.cs.disable-library-validation</key>
|
||||
<true/>
|
||||
```
|
||||
|
||||
A plain debug app **without** Hardened Runtime doesn't need this — skip it.
|
||||
|
||||
### 3. Xcode 26 Swift-driver workaround
|
||||
|
||||
If the build fails with Swift driver errors, set in **Build Settings**:
|
||||
|
||||
- `SWIFT_USE_INTEGRATED_DRIVER = NO`
|
||||
- `parallelizeBuildables = NO`
|
||||
|
||||
Both are temporary, tied to the same Xcode 26 regression as the dynamic-library
|
||||
choice.
|
||||
|
||||
> The `lyrebird new --template macos-ui-xcode | ios-ui | auv3` scaffolds apply
|
||||
> all three automatically. Reach for them if you'd rather not wire this by hand.
|
||||
> The package also vends an internal `LyrebirdDynamic` (`type: .dynamic`)
|
||||
> product used **only** by the bundled `LiveCompile/` live-coding sub-package
|
||||
> (it needs a shared dylib so live-compiled snippets and the host resolve to one
|
||||
> copy of every class). External consumers never reference `LyrebirdDynamic`.
|
||||
> The demo workspace and AUv3 sample link that dynamic product, which is why
|
||||
> *those* projects carry the `disable-library-validation` entitlement and the
|
||||
> Xcode-26 driver settings — your own project does not.
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user