Skip to content

feat(🍏): download the Apple binaries from GitHub releases (CocoaPods/SPM) - #4498

Merged
wcandillon merged 3 commits into
wcandillon:dev2from
theeket:feat/apple-sdk-binary-preparation
Nov 24, 2026
Merged

wcandillon merged 3 commits into
wcandillon:dev2from
theeket:feat/apple-sdk-binary-preparation

Conversation

@theeket

@theeket theeket commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

ℹ️ This PR requires prebuilt binaries from #4494, and its updated binaries.json

Summary

Move Apple binary consumption from large npm dependencies to SDK-specific GitHub release assets from #4494.

  • Headers remain bundled in react-native-skia.
  • Download binaries for the SDK being built. (only one at a build time; not at set-up stage)
  • Follow ExpoModulesJSI’s Xcode build-phase integration pattern. Skia and Dawn remain prebuilt.
  • Use a shared macOS cache, same as RN/Hermes. (multiple projects with same version download once)
  • Android’s Gradle binary resolution stays unchanged.

Workflow

See full workflow in the comments.

  1. Register the Xcode build phase with pod install or react-native spm update.

    CocoaPods or the RN 0.87.1+ SwiftPM plugin (spm-plugin.js) adds the phase automatically.
    The phase runs prepare-apple-binaries.sh, which sources apple-binaries-utils.sh.
    No binaries are downloaded during setup.

  2. Build in Xcode. The phase reads the SDK, platform variant, and architecture settings. For example, an iOS device build fetches iphoneos archives without fetching simulator, Catalyst, or macOS binaries.
  3. Resolve binaries. Use local builds when present; otherwise reuse or download the pinned SDK archives. Verify downloaded ZIPs against the package’s SHA-256 checksums.
  4. Prepare SDK slices. Assemble XCFramework containers from archive metadata under $OBJROOT/ReactNativeSkiaBinaries. Append or replace the current SDK slice while retaining other prepared slices for the same manifest.
  5. Link. Stage the selected SDK’s libraries as librnskia_*.a in build products. CocoaPods library settings or SwiftPM .linkedLibrary settings link them statically into the app/framework. No Skia/Dawn framework needs embedding or signing separately.

Unchanged inputs reuse existing containers and staged libraries. Release/checksum changes select new cache entries; manifest changes select a new assembly root.

Integration

  • CocoaPods remains automatic through pod install.
  • Optional SwiftPM integration requires RN 0.87.1+. It generates a small local link-settings package, avoiding remote binary targets that download whole XCFramework archives during resolution.
  • Preparation uses Bash and macOS system tools (like expo); the Xcode phase does not require Node.
  • When WebGPU supplies Dawn, require matching binaries.json release version and Dawn commit, then omit Skia’s own Dawn preparation.

Validation

  • CocoaPods Debug builds passed on iPhone/Simulator and macOS (example app), rendering as expected.
  • SwiftPM builds passed on iPhone/Simulator (the spm-example previously not using scene lifecycle, now updated to be able to test)
  • Tested with and without shared Dawn. (with react-native-webgpu#640 and 0.22)
  • Cold builds fetched only the selected SDK’s archives (tested with file:///).
  • Incremental builds performed zero re-downloads and preserved prepared outputs. 🚀
  • Tested removing / rebuilding slice and build again, the script works as expected.
  • Checksums, XCFramework metadata, staged library bytes, static linking, and signatures verified.

Voila! You just reduce total download size of > 900MB into 20-40MB a time 🚀

Multiple different projects with the same binaries version ? still download only once.

@theeket

theeket commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

What's going on there:

flowchart TD
  %% Installation configures linking; binary downloads wait for Xcode.
  subgraph SETUP["Installation — no binary downloads"]
    NPM["npm / yarn install<br/>JS, headers, binaries.json"]
    CP["CocoaPods: pod install<br/>Configure library links and pod-target phase"]
    SPM["Optional SwiftPM: spm update<br/>RN 0.87.1+ plugin generates<br/>link-settings package and app-target phase"]

    NPM --> CP
    NPM --> SPM
    PIN["Installed binaries.json<br/>Release tag, asset SHA-256, Dawn commit"]
    NPM -.-> PIN
  end

  CP --> PHASE
  SPM --> PHASE

  %% The same shell implementation handles both integrations.
  PHASE["Every Xcode build<br/>prepare-apple-binaries.sh<br/>Bash and system tools; no Node"]
  PHASE --> SDK["Select SDK and variant from Xcode<br/>Apply ARCHS, EXCLUDED_ARCHS, ONLY_ACTIVE_ARCH<br/>Catalyst selects maccatalyst, not native macOS"]
  SDK --> DAWN{"WebGPU supplies Dawn?"}
  DAWN -->|Yes| MATCH{"WebGPU binaries.json matches<br/>release version and Dawn commit?"}
  MATCH -->|No| FAIL
  MATCH -->|Yes: skip own Dawn| MODULE
  DAWN -->|No: prepare own Dawn| MODULE

  %% Skia and Dawn resolve independently.
  MODULE["For each owned module<br/>Skia; Dawn unless supplied by WebGPU"]
  MODULE --> LOCAL{"Local module directory exists?<br/>libs/apple or libs/dawn/apple"}

  LOCAL -->|Yes| OVERRIDE["Use local SDK folder read-only<br/>Never overwrite or download replacements"]
  OVERRIDE --> VALID

  LOCAL -->|No| ASSET["Locate selected SDK asset in pin<br/>Shared cache keyed by release tag and ZIP SHA-256"]
  PIN -.-> ASSET
  ASSET -->|Asset missing| FAIL
  ASSET --> CACHE{"Cached ZIP exists<br/>and SHA-256 matches?"}

  %% Downloads are bounded, verified, and synchronized across builds.
  CACHE -->|No| DOWNLOAD["Download selected SDK ZIP only<br/>GitHub, mirror, or file:///<br/>Bounded retries; verify SHA-256"]
  DOWNLOAD -->|Download or checksum failure| FAIL
  DOWNLOAD -->|Verified| MARKER
  CACHE -->|Yes: no download| MARKER{"Extraction marker matches SHA-256?"}

  MARKER -->|Yes: reuse extracted files| VALID
  MARKER -->|No| EXTRACT["Check archive paths<br/>Extract temporarily; atomically replace cache"]
  EXTRACT --> VALID

  VALID{"SDK metadata valid?<br/>Platform, variant, required architectures,<br/>libraries, and deployment minimum"}
  VALID -->|No| FAIL
  VALID -->|Yes| ROOT["Assembly root under OBJROOT<br/>Version + manifest hash<br/>Source signature: ZIP hash or local metadata/file stats"]

  %% A changed pin selects new storage; old binaries cannot silently win.
  PIN -. "Changed tag or SHA selects new cache entry" .-> ASSET
  PIN -. "Changed manifest selects new assembly root" .-> ROOT

  subgraph INCREMENTAL["Incremental preparation — synchronized per build root"]
    ROOT --> SAME{"Source signature unchanged<br/>and SDK slice files exist?"}
    SAME -->|Yes: reuse containers| STAGED
    SAME -->|No| COMPOSE["Atomically append or replace current SDK slice<br/>Preserve other SDK slices for this manifest<br/>Update Info.plist from metadata<br/>No compilation or lipo"]
    COMPOSE --> STAGED

    STAGED{"Staged signature matches<br/>and linker archives exist?"}
    STAGED -->|Yes: skip copies| NEXT
    STAGED -->|No| COPY["Stage selected SDK as librnskia_*.a<br/>APFS clone or ordinary copy"]
    COPY --> NEXT
  end

  NEXT{"More owned modules?"}
  NEXT -->|Yes| MODULE
  NEXT -->|No| LINK["Compile wrapper using bundled headers<br/>Statically link prepared libraries into app/framework<br/>No Skia/Dawn XCFramework embedding"]

  FAIL["Stop build with actionable Xcode error<br/>Clean temporary files and release owned locks"]

  %% Highlight SDK selection, downloads, preparation, and final linking.
  classDef selection fill:#dbeafe,stroke:#2563eb,color:#111827,stroke-width:2px;
  classDef download fill:#ffedd5,stroke:#ea580c,color:#111827,stroke-width:2px;
  classDef preparation fill:#ccfbf1,stroke:#0f766e,color:#111827,stroke-width:2px;
  classDef linking fill:#ede9fe,stroke:#7c3aed,color:#111827,stroke-width:2px;
  classDef failure fill:#fee2e2,stroke:#b91c1c,color:#111827;

  class SDK selection;
  class DOWNLOAD download;
  class PHASE,COMPOSE preparation;
  class LINK linking;
  class FAIL failure;
Loading

@wcandillon
wcandillon self-requested a review November 20, 2026 13:16
@wcandillon

Copy link
Copy Markdown
Owner

@theeket I like it (haven’t reviewed it yet), but just a heads-up: when we downloaded from GitHub releases in CocoaPods in the past, we got a lot of pushback from users (slow downloads, hash issues). Let’s revisit it, though.

There are two things I like about your approach:

  1. It might already fix some of the issues we had last time.
  2. "Back then" we had no alternative, but now we have a strong one if people run into problems with GitHub downloads in CocoaPods: SPM.

This feels very compelling.

CC’ing @chrfalch to show that this would likely incentivizing users toward SPM :)

@theeket

theeket commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

I'm not sure about the CocoaPods download back then, which approach is it.

But currently, it uses direct bash script in Xcode (not at Pods / SPM install time); and only download one required slice. So, it should as fast as Gradle downloads 🚀

Also, it is not SPM binaryTarget, so the #4494 works with this. SPM alone still downloads other unused slices before compilation time. So, this Xcode build phase solved that. Both Pods and SPM! 🚀

@theeket

theeket commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Other minor changes in this PR to be able to test (test passed):

  • Update spm-example to support scene lifecycle. Otherwise it will crash in Xcode 27.
  • Update react-native-webgpu in the example to 0.22.0, so it has binaries.json. Otherwise, it will not support the shared Dawn.

@theeket
theeket force-pushed the feat/apple-sdk-binary-preparation branch 2 times, most recently from 6c4c399 to 2160407 Compare November 22, 2026 11:39
@theeket
theeket marked this pull request as ready for review November 22, 2026 11:45
@theeket
theeket force-pushed the feat/apple-sdk-binary-preparation branch from 2160407 to 37d8f7c Compare November 22, 2026 12:06

@wcandillon wcandillon left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fantastic stuff. A big Thank You 💚 Here's how I'll do this.
0. There is a TN Skia release I want to do first for safety

  1. Merge this PR in an integration branch
  2. Run the 158.1.0 release
  3. Merge integration branch
  4. Release and on the RN WebGPU side too

@wcandillon
wcandillon changed the base branch from main to dev2 November 24, 2026 10:02
@wcandillon
wcandillon merged commit b7fce8e into wcandillon:dev2 Nov 24, 2026
8 of 11 checks passed
@theeket

theeket commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Great! Thanks 🚀

@theeket
theeket deleted the feat/apple-sdk-binary-preparation branch November 24, 2026 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants