Skip to Content
Octapus

Ship as a Swift package

Build an Octane app into prebuilt XCFrameworks that an existing iOS or macOS app adds as a Swift package.

oct build --xcframework turns an Octane app into a Swift package of prebuilt binaries. A brownfield app adds the package, imports one module, and shows the screen with one line of Swift. It needs no other frameworks, no build settings, and no Swift/C++ interop.

1. Build the package

oct build --target ios --bake --xcframework            # or: --target ios,mac
dist/ios-spm/
  Package.swift                 product ExampleApp = the two binaries below (local paths)
  ExampleApp.xcframework        the app: app.hbc, app.ofrm, app.css, manifest.json as resources
                                + a generated Swift entry point
  Octapus.xcframework           the runtime (OctapusKit on iOS, OctapusAppKit on macOS), Hermes inside
  *.xcframework.zip             the same binaries zipped for hosting
  Package.remote.swift          Package.swift with url: + checksum: for the zips

The product name comes from package.json (@octapus/example-app becomes ExampleApp) or from --name. In the monorepo, the runtime is built on first use and cached until a native source changes (pnpm xcframework, below). Elsewhere, pass a prebuilt one with --runtime <Octapus.xcframework>.

2. Add the package to the app

In Xcode, use File → Add Package Dependencies… → Add Local… and pick dist/ios-spm, or declare it in another package:

.package(path: "../my-feature/dist/ios-spm")

To host the binaries, upload the two zips and use Package.remote.swift as the package manifest (--remote-url sets the base URL). oct prints each target with its checksum:

.binaryTarget(name: "ExampleApp", url: "https://cdn.example.com/ExampleApp/1.0.0/ExampleApp.xcframework.zip",
              checksum: "9fba9363…"),
.binaryTarget(name: "Octapus", url: "https://cdn.example.com/ExampleApp/1.0.0/Octapus.xcframework.zip",
              checksum: "1da21deb…"),

3. One line of Swift

import ExampleApp

ExampleAppView()

The generated module re-exports the runtime (@_exported import OctapusKit / OctapusAppKit), so ExampleApp.bundle (an OctapusBundle) works with the lower-level API too, for example OctapusSurface(bundle: ExampleApp.bundle, onEvent: …).

How the runtime is built

pnpm xcframework (tools/build-xcframework/build.mjs) writes dist/xcframework/Octapus.xcframework, with one framework per slice:

SliceFrameworkSize
ios-arm64OctapusKit.framework6.0 MB
ios-arm64-simulatorOctapusKit.framework6.1 MB
macos-arm64OctapusAppKit.framework (versioned bundle)6.7 MB
  • One Swift module per framework. OctapusCore, OctapusCSS, OctapusLayout, OctapusSVG and the platform renderer are compiled together. The build copies the sources to a staging folder, drops the cross-module imports there, and leaves the repository sources unchanged. The frameworks are built with library evolution and ship only a .swiftinterface, so the interface is all a client sees.
  • C and C++ stay private. HermesBridge (C++) and the OctapusHermes C ABI are compiled into the binary with hidden visibility. Swift imports the C ABI through a private module map (internal import), so neither appears in the interface. Every C++ symbol is unexported.
  • Hermes is linked statically. pnpm hermes also builds native/hermes/artifacts/static/<platform>/libhermes.a (Hermes' hermesvm_a + jsi + boost_context, the same build trees as hermesvm.framework). It is linked with -hidden-l, so the frameworks link only system libraries and export only Swift symbols. The build checks this every time (otool -L, nm -gU, and a grep of the interfaces).

Two binaries or one (--embed-runtime)

By default a package contains two binaries: the app framework and the shared runtime. Several features can share one copy of the runtime this way, and the runtime zip has the same checksum in every package built from the same runtime.

--embed-runtime compiles the runtime into <Product>.xcframework, so the package has one binary. The trade-off: every feature built this way carries its own copy of the runtime and Hermes (about 6 MB each). The runtime types belong to each feature's module, so FeatureA.OctapusBundle and FeatureB.OctapusBundle are different types. The copies don't clash, because all C++ symbols are hidden and Swift names are module-qualified. Use --embed-runtime when an app has a single feature.

Limits

  • arm64 only. The iOS simulator slice runs on Apple silicon Macs, so build the host app for the active architecture (Xcode's default for Debug).
  • The interfaces are written by the Swift 6.4 compiler (they use Module::Type selectors), so the app needs the same Xcode or a newer one.
  • App targets in Xcode (iOS and macOS) embed the frameworks and need no settings. A SwiftPM command-line executable on macOS runs as is with swift build --build-system native. SwiftPM's default build system does not add @executable_path to an executable's rpaths, so with it the executable needs linkerSettings: [.unsafeFlags(["-Xlinker", "-rpath", "-Xlinker", "@executable_path"])].

On this page