Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Packaging

weaveffi generate emits binding source. Shipping it takes two more steps: weaveffi build cross-compiles the Rust producer once per platform, and weaveffi package turns those builds into the artifacts each ecosystem installs: wheels, npm tarballs, gems, a SwiftPM package with its XCFramework, a NuGet package, and so on. Consumers install them with pip, npm, gem, SwiftPM, or dotnet and need no compiler.

weaveffi build --platforms darwin-arm64,ios-arm64,ios-sim-arm64
weaveffi package --target python,node,swift

Both read [project], [package], and [build] from weaveffi.toml (or take an explicit input), and every artifact loads the library named by the identity’s library field.

Build

weaveffi build finds the producer crate with cargo metadata (the project’s crate, [build] manifest, or --manifest-path) and runs cargo rustc --lib once per platform with the artifact kinds that platform needs, so the crate’s own crate-type doesn’t matter. It builds with the release profile unless --profile (or [build] profile) names another, and with the project’s Cargo features (-F/--features, --all-features, --no-default-features, or the [build] keys). A Rust producer’s API is then read from the first library it built (see Library Mode), so nothing is compiled twice. build produces only the producer’s library: no target needs compiled glue of its own.

PlatformWhat build produces
macOSthe cdylib, with install name @rpath/lib{library}.dylib, plus the staticlib an XCFramework slice is made from
iOSthe staticlib
Linux, Androidthe cdylib, with soname lib{library}.so (Android also 16 KB page-aligned)
Windowsthe DLL and its import library
wasm32the .wasm module, linked with --export-table --growable-table

It sets MACOSX_DEPLOYMENT_TARGET and IPHONEOS_DEPLOYMENT_TARGET from [build], and for Android it finds the NDK (ANDROID_NDK_HOME, ANDROID_NDK_ROOT, or the newest ndk/<version> of the Android SDK) and points Cargo’s linker and the cc crate at the NDK’s clang for the configured API level. Everything lands in the Cargo target directory:

target/weaveffi/
  darwin-arm64/  libkvstore.dylib  libkvstore.a
  ios-arm64/     libkvstore.a
  android-arm64/ libkvstore.so
  wasm32/        kvstore.wasm

Every platform is checked before anything compiles; a platform this machine can’t build (a missing rustup target, a missing NDK, or a host that can’t build it: Apple platforms need macOS, Windows needs Windows) is skipped with a warning naming the fix, and the run fails only when no requested platform can be built.

build and package follow one policy for a missing external tool (a C compiler, the NDK, Xcode, the .NET SDK): they warn, skip the artifact that needs it, finish everything else, and list every skipped artifact at the end. The run still exits 0; pass --strict to exit 1 when anything was skipped (as CI should).

Package

weaveffi package runs build for the requested platforms, then writes each target’s artifacts to the dist directory (-o, else [package] dist, else dist). With --binaries <dir>, it skips the build and reads a directory laid out like target/weaveffi/ instead; that’s how CI hands libraries built on separate runners to one packaging job, and how a producer that isn’t a Rust crate is packaged. A Rust producer’s API is read from the first library in the directory.

TargetArtifactsPublish with
pythonone platform wheel per desktop platform, the library inside the import packagetwine upload
nodeone npm tarball per desktop platform ({package}-{os}-{cpu}) carrying only the library, plus the main package, which lists them as optional dependencies and depends on koffinpm publish for each, platform packages first
wasman npm tarball with the .wasm modulenpm publish
rubyone platform gem per desktop platformgem push
swiftC{Module}.xcframework.zip (static libraries for every Apple platform built), its .sha256, and the SwiftPM package whose binary target points at the archive’s URL and checksumupload the archive, then commit and tag the package
dotneta project with runtimes/<rid>/native/ libraries, and the .nupkg that dotnet pack builds from itdotnet nuget push
kotlina Gradle project with the Android libraries under src/main/jniLibs/<abi>/ and the desktop ones under JNA’s src/main/resources/<os>-<arch>/Gradle
darta pub package with the desktop libraries under native/<platform>/dart pub publish
goa module with the libraries and cgo flags that link the right onepush the module to its repository
c, cpparchives of the headers, the libraries per platform, and a CMakeLists.txtattach to a release

Each target’s page under Generators documents its artifacts’ names and layout. Each archive is deterministic (fixed timestamps and order), so the same builds always produce the same bytes and checksums. A target skips platforms its ecosystem has no slot for (a wheel has no Android tag, NuGet no wasm32 runtime), and a target with nothing to ship is named in a note.

Platforms

--platforms takes a comma-separated list of platform ids; without it, build and package use [build] platforms, else the host. With --binaries, the default is every platform directory present.

Platform idRust targetShipped by
darwin-arm64aarch64-apple-darwinevery desktop target, and swift
darwin-x64x86_64-apple-darwinevery desktop target, and swift
linux-x64x86_64-unknown-linux-gnuevery desktop target
linux-arm64aarch64-unknown-linux-gnuevery desktop target
windows-x64x86_64-pc-windows-msvcevery desktop target
ios-arm64aarch64-apple-iosswift
ios-sim-arm64aarch64-apple-ios-simswift
ios-sim-x64x86_64-apple-iosswift
android-arm64aarch64-linux-androidkotlin (and c)
android-x64x86_64-linux-androidkotlin (and c)
wasm32wasm32-unknown-unknownwasm (and c)

Swift and the XCFramework

package fuses the Apple static libraries into C{Module}.xcframework (iOS device, iOS simulator, and macOS slices, with a group’s architectures fused by lipo), zips it, and writes its SHA-256 checksum. The packaged Package.swift declares the C module as a .binaryTarget(url:checksum:), so apps link the library with no flags. The URL comes from the Swift target’s configuration (see Swift); to publish, upload the archive to that URL and commit the package to the repository consumers depend on. This step runs xcodebuild, so it needs macOS with Xcode; elsewhere the Swift package is skipped.

What still needs the ecosystem’s tools

  • Publishing. There’s no weaveffi publish; run each ecosystem’s own upload command on the artifacts.
  • NuGet. package runs dotnet pack, so the .NET SDK must be installed; without it the .nupkg is skipped (and --strict fails the run) after everything else is written.
  • Kotlin. The output is a Gradle project, not an .aar or .jar, so build one with Gradle.
  • Cross-architecture Linux. Building linux-arm64 on an x64 host needs a cross linker (CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER); an arm64 runner is simpler.

CI recipe

Build each platform on a runner that can, upload target/weaveffi/, then package once:

jobs:
  build:
    strategy:
      matrix:
        include:
          - runner: macos-latest
            platforms: darwin-arm64,darwin-x64,ios-arm64,ios-sim-arm64
            targets: aarch64-apple-darwin,x86_64-apple-darwin,aarch64-apple-ios,aarch64-apple-ios-sim
          - runner: ubuntu-latest
            platforms: linux-x64,android-arm64,android-x64,wasm32
            targets: aarch64-linux-android,x86_64-linux-android,wasm32-unknown-unknown
          - { runner: ubuntu-24.04-arm, platforms: linux-arm64, targets: "" }
          - { runner: windows-latest, platforms: windows-x64, targets: "" }
    runs-on: ${{ matrix.runner }}
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.targets }}
      - run: cargo install weaveffi-cli
      - run: weaveffi build --platforms ${{ matrix.platforms }} --strict
      - uses: actions/upload-artifact@v4
        with:
          name: weaveffi-${{ matrix.runner }}
          path: target/weaveffi/

  package:
    needs: build
    runs-on: macos-latest   # the XCFramework needs xcodebuild
    steps:
      - uses: actions/checkout@v4
      - uses: actions/download-artifact@v4
        with:
          pattern: weaveffi-*
          path: prebuilt
          merge-multiple: true
      - run: cargo install weaveffi-cli
      - run: weaveffi package --binaries prebuilt --strict

The Linux runner finds the NDK through ANDROID_NDK_HOME (or the SDK preinstalled on GitHub’s images). A platform you can’t build can be dropped from the matrix; every target packages whatever subset is present.