Skip to content

Commit 46bae15

Browse files
theeketwcandillon
andauthored
feat(🍏): download the Apple binaries from GitHub releases (CocoaPods/SPM) (#640)
* feat(🍏): download the Apple binaries from GitHub releases (CocoaPods/SPM) * chore(⬆️): use the binaries-158.1.0 release Pins the first release with SDK-grouped Apple archives. Same Dawn commit as 158.0.0. * fix(🍏): address review findings on Apple binary preparation - Ignore the dormant Skia demos in the example's ESLint config, matching tsconfig.json (fixes the failing lint step in CI). - Restore the RNWGPU_USE_SPM stub mode of the podspec so apps that link through SwiftPM but still run CocoaPods don't get the module twice. - Keep Dawn's headers out of the pod's public headers instead of setting header_mappings_dir, preserving the flat public header layout. - Serialize stale lock recovery so a waiter never removes a lock another build has just taken over. - Treat minimumDeploymentTarget as optional in SDK metadata. --------- Co-authored-by: William Candillon <wcandillon@gmail.com>
1 parent 4199a0a commit 46bae15

41 files changed

Lines changed: 1332 additions & 651 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/actions/setup/action.yml‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,25 @@ runs:
2626
fi
2727
shell: bash
2828

29-
# Dawn comes with the react-native-webgpu-dawn dependency; this only checks
30-
# it against the C++ workarounds pinned to a Dawn commit.
29+
# Cache only the pinned header ZIP. Apple SDK archives stay in the runner's
30+
# shared local cache; this avoids uploading them in every setup job.
31+
# Header copying verifies the cached ZIP, including when Yarn install is skipped.
32+
- name: Cache Dawn header archive
33+
uses: actions/cache@v4
34+
with:
35+
path: |
36+
~/Library/Caches/react-native-skia/*/*/dawn-headers.zip
37+
~/.cache/react-native-skia/*/*/dawn-headers.zip
38+
~/AppData/Local/react-native-skia/*/*/dawn-headers.zip
39+
key: ${{ runner.os }}-${{ runner.arch }}-dawn-headers-${{ hashFiles('packages/webgpu/binaries.json') }}
40+
41+
# Populate cpp/dawn/include before checks, compilation, and npm publishing.
42+
# Checkout omits these source/generated headers; no native build runs here.
43+
- name: Copy Dawn headers
44+
working-directory: packages/webgpu
45+
shell: bash
46+
run: yarn copy-dawn-headers
47+
3148
- name: Check Dawn
3249
working-directory: packages/webgpu
3350
shell: bash

‎.github/workflows/apple-sdks.yml‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,23 @@ on:
88
- "packages/webgpu/apple/**"
99
- "packages/webgpu/cpp/**"
1010
- "packages/webgpu/package.json"
11+
- "packages/webgpu/binaries.json"
1112
- "packages/webgpu/scripts/check-apple-sdks.sh"
13+
- "packages/webgpu/scripts/prepare-dawn-headers.mjs"
1214
- ".github/workflows/apple-sdks.yml"
1315
jobs:
1416
apple-sdks:
1517
# Syntax-check only: no yarn install, no pods, no simulator. Only the Dawn
16-
# headers are downloaded (about 1 MB out of the package's tarball).
18+
# headers archive is downloaded from the pinned Skia binaries release.
1719
runs-on: macos-latest
1820
timeout-minutes: 10
1921
steps:
2022
- uses: actions/checkout@v4
21-
- name: Download Dawn headers
22-
run: |
23-
VERSION=$(node -p 'require("./packages/webgpu/package.json").dependencies["react-native-webgpu-dawn"]')
24-
mkdir -p "$RUNNER_TEMP/dawn"
25-
curl -sfL "https://registry.npmjs.org/react-native-webgpu-dawn/-/react-native-webgpu-dawn-$VERSION.tgz" \
26-
| tar xz -C "$RUNNER_TEMP/dawn" package/include
23+
- name: Setup Node.js
24+
uses: actions/setup-node@v3
25+
with:
26+
node-version-file: .nvmrc
27+
- name: Prepare Dawn headers
28+
run: node packages/webgpu/scripts/prepare-dawn-headers.mjs
2729
- name: Check Apple sources against every SDK
28-
run: packages/webgpu/scripts/check-apple-sdks.sh "$RUNNER_TEMP/dawn/package/include"
30+
run: packages/webgpu/scripts/check-apple-sdks.sh

‎.github/workflows/ci.yml‎

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ jobs:
201201
# packages/webgpu/Package.swift resolves and compiles, so a pull request
202202
# pays for it only when its diff touches what can change the outcome: the
203203
# manifest and the autolinking config, the Apple and C++ sources it
204-
# compiles, the scripts behind the Dawn check, the dependencies that pin
205-
# react-native-webgpu-dawn, the example that links it, or CI itself. Pushes
204+
# compiles, preparation/check scripts, the Dawn release pin,
205+
# the example that links it, or CI itself. Pushes
206206
# to main, the merge queue and manual runs always build SwiftPM. macOS builds
207207
# on main, manual runs and relevant PRs; shared JavaScript is checked by
208208
# bundle-macos on every PR.
@@ -237,7 +237,7 @@ jobs:
237237
macos=false
238238
while IFS= read -r file; do
239239
case "$file" in
240-
packages/webgpu/Package.swift|packages/webgpu/package.json|packages/webgpu/react-native.config.js|\
240+
packages/webgpu/Package.swift|packages/webgpu/*.podspec|packages/webgpu/package.json|packages/webgpu/binaries.json|packages/webgpu/react-native.config.js|\
241241
packages/webgpu/apple/*|packages/webgpu/cpp/*|packages/webgpu/scripts/*|\
242242
spm-example/*|package.json|yarn.lock|\
243243
.github/workflows/ci.yml|.github/actions/setup/*)
@@ -246,7 +246,7 @@ jobs:
246246
;;
247247
esac
248248
case "$file" in
249-
apps/example-macos/*|packages/webgpu/*.podspec|packages/webgpu/package.json|\
249+
apps/example-macos/*|packages/webgpu/*.podspec|packages/webgpu/package.json|packages/webgpu/binaries.json|\
250250
packages/webgpu/react-native.config.js|packages/webgpu/apple/*|packages/webgpu/cpp/*|\
251251
packages/webgpu/scripts/*|package.json|yarn.lock|.yarn/patches/*|turbo.json|\
252252
.github/workflows/ci.yml|.github/actions/setup/*)
@@ -292,15 +292,15 @@ jobs:
292292

293293
# The SwiftPM example gets its own job on a GitHub-hosted Mac. It needs no
294294
# Metro, simulator or CocoaPods, so nothing ties it to the self-hosted
295-
# machine, and a fresh runner is the strictest check that the WebGPUDawn
296-
# binaryTarget resolves from the release zip + checksum with nothing cached.
295+
# machine. The Xcode phase selects the simulator SDK archive and verifies
296+
# its checksum, independently of SwiftPM package resolution.
297297
# It used to be a step of `build`: a hung xcodebuild there blocked the iOS
298298
# e2e result and held the self-hosted runner, which has no slack for that.
299299
build-spm-ios:
300300
needs: changes
301301
if: needs.changes.outputs.spm == 'true'
302302
runs-on: macos-latest
303-
# Cold run: yarn install, Dawn download, RN artifacts, then one xcodebuild.
303+
# Install JS/headers, resolve RN artifacts, then prepare Dawn during Xcode.
304304
timeout-minutes: 25
305305
steps:
306306
- name: Checkout
@@ -320,7 +320,7 @@ jobs:
320320

321321
# spm-example sits outside the yarn workspace so its React Native can
322322
# differ from the one apps/example pins: SwiftPM autolinking needs
323-
# React Native 0.87+. It ships no lockfile; react and react-native are
323+
# React Native 0.87.1+. It ships no lockfile; react and react-native are
324324
# pinned exactly in its package.json.
325325
- name: Install spm-example dependencies
326326
working-directory: spm-example
@@ -333,11 +333,8 @@ jobs:
333333
working-directory: spm-example/ios
334334
run: npx react-native spm update
335335

336-
# No CocoaPods and no -disableAutomaticPackageResolution here (unlike
337-
# the example app build above): react-native-webgpu is linked through
338-
# its own Package.swift, and its WebGPUDawn binaryTarget resolves to a
339-
# remote release zip + checksum with nothing cached ahead of time: this
340-
# build's whole point is exercising that download-and-verify step.
336+
# No CocoaPods: the package compiles from bundled headers, and its Xcode
337+
# phase prepares only the selected SDK's Dawn before the app links.
341338
- name: Build spm-example for iOS
342339
working-directory: spm-example/ios
343340
run: |

‎.gitignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,7 @@ apps/vendor/
7171
Package.resolved
7272

7373
.turbo
74+
75+
# Prepared release inputs and local Apple SDK overrides
76+
packages/webgpu/cpp/dawn/include/
77+
packages/webgpu/libs/

‎apps/docs/content/docs/getting-started/installation.mdx‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ npm i react-native-webgpu
2424

2525
An Android app with a lower `minSdkVersion` fails to build; on Expo, the [config plugin](/docs/getting-started/expo#config-plugin) raises it for you.
2626

27+
## Prebuilt binaries
28+
29+
Both platforms use the [React Native Skia binaries release](https://github.com/wcandillon/react-native-skia/releases) pinned by this package's `binaries.json`:
30+
31+
- **Android:** Gradle downloads only the ABIs being built and caches them as Gradle dependencies.
32+
- **Apple:**
33+
- **CocoaPods:** `pod install` registers an Xcode phase; it downloads only the selected SDK's Dawn archive during compilation.
34+
- **SwiftPM (optional):** The autolinking plugin registers the same phase. Package resolution uses bundled headers and a local link-settings package, without downloading Dawn.
35+
36+
Apple archives share Skia's `~/Library/Caches/react-native-skia` cache; set `RNSKIA_CACHE_DIR` to override it.
37+
2738
## Setup
2839

2940
Once installed, the global `navigator.gpu` API is available, the same entry point as in Chrome or Safari:
@@ -63,16 +74,16 @@ This replaces the package with a JS-only stand-in: `<Canvas>` renders as a plain
6374

6475
By default, `react-native-webgpu` links on iOS/macOS through CocoaPods autolinking, with no extra setup. The long-term plan is to move the Apple platforms to Swift Package Manager. It is available today as an alternative: the package also ships a `Package.swift` for React Native's SwiftPM autolinking, which needs no CocoaPods at all:
6576

66-
1. Use **React Native 0.87 or newer**. Earlier releases have no SwiftPM autolinking, so keep CocoaPods there.
77+
1. Use **React Native 0.87.1 or newer**, with the autolinking plugin's `scriptPhases` hook. Keep CocoaPods on earlier releases.
6778
2. From your app's `ios` directory, run `npx react-native spm add --deintegrate` once. It removes CocoaPods from the project and adds the Swift packages to the `.xcodeproj`. Then build the project (not a workspace) as usual.
6879
3. Do not run `pod install` in that app: it would re-integrate CocoaPods and break the Swift packages.
6980

70-
Dawn comes as a prebuilt binary that Xcode downloads the first time it resolves packages.
81+
Set **User Script Sandboxing** to **NO** on the app target. The Xcode phase needs access to the shared cache and build products. After upgrading the package, run `npx react-native spm update` again.
7182

72-
With React Native Skia v3 installed alongside, package resolution checks that both packages link the same Dawn release, and fails if they are not at [compatible versions](/docs/integrations/react-native-skia#compatibility). After changing either version, reset the package caches in Xcode (File > Packages > Reset Package Caches) if the error persists.
83+
With a compatible React Native Skia integration installed, WebGPU supplies the single Dawn copy. Both packages must pin the same release version and Dawn commit; mismatches fail before linking. See [compatible versions](/docs/integrations/react-native-skia#compatibility).
7384

7485
<Callout type="warn" title="Platform coverage">
75-
The Swift package targets iOS only: tvOS, macOS and Android still require the CocoaPods/Gradle autolinked path. See `spm-example` at the root of the [React Native WebGPU repo](https://github.com/wcandillon/react-native-webgpu) for a working reference project, and its README for the gotchas (stale `Package.resolved`, the stub `Podfile`).
86+
The Swift package targets iOS only: tvOS, macOS and Android still require the CocoaPods/Gradle autolinked path. See `spm-example` at the root of the [React Native WebGPU repo](https://github.com/wcandillon/react-native-webgpu) for a working reference project, and its README for setup notes and the stub `Podfile`.
7687
</Callout>
7788

7889
## Troubleshooting
@@ -101,8 +112,8 @@ The simulator's Metal stack is not identical to real hardware, and validation ca
101112
Learn more in [Apple's documentation on validating Metal API usage](https://developer.apple.com/documentation/xcode/validating-your-apps-metal-api-usage/).
102113
</Callout>
103114

104-
<Callout type="info" title="Android builds without network access">
105-
Gradle downloads the prebuilt Dawn from the [GitHub releases of React Native Skia](https://github.com/wcandillon/react-native-skia/releases), which builds it, the first time it builds, only for the architectures being built, and caches it like any other Gradle dependency. To download it from a mirror or a local directory instead, set the `reactNativeSkiaBinariesUrl` Gradle property (or the `REACT_NATIVE_SKIA_BINARIES_URL` environment variable) to a URL or a `file:///` directory that holds the release assets under `binaries-<version>/`.
115+
<Callout type="info" title="Builds without network access">
116+
To use a mirror or local release directory on either platform, set `REACT_NATIVE_SKIA_BINARIES_URL` to a URL or `file:///` path holding `binaries-<version>/<asset>`. Android also accepts the `reactNativeSkiaBinariesUrl` Gradle property.
106117
</Callout>
107118

108119
## Next steps

‎apps/docs/content/docs/integrations/react-native-skia.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Because the two packages share Dawn, React Native Skia v3 and React Native WebGP
2626
| 0.12.1 | 3.0.6 to 3.0.8, or 3.1.0 and later |
2727
| 0.10.0 to 0.11.2 | 3.0.0 to 3.0.5 |
2828

29-
If the versions don't match, the native build fails with a `Dawn version mismatch` error rather than misbehaving at runtime. Both packages get Dawn from the `react-native-webgpu-dawn` npm package: make sure a single version of it is installed (`npm ls react-native-webgpu-dawn`, or `yarn why react-native-webgpu-dawn`).
29+
For SDK-archive integration, both packages must pin the same release version and `dawn.commit` in `binaries.json`. WebGPU supplies Dawn; Skia must use its compatible external-Dawn integration so the app links one copy. A mismatch fails with `Dawn version mismatch`. The older binary-npm integrations follow their release-specific installation instructions.
3030

3131
The Graphite previews of v2 (`@shopify/react-native-skia@next`) follow the same rule. Regular v2 releases don't use Dawn, so they work alongside any version of React Native WebGPU.
3232

‎apps/docs/package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
"eslint": "9.35.0",
4141
"fumadocs-twoslash": "^3.2.0",
4242
"fumadocs-typescript": "^4.0.4",
43-
"react-native-skia": "3.10.0",
4443
"react-native-vision-camera": "5.0.10",
4544
"tailwindcss": "^4.1.8",
4645
"twoslash": "^0.3.9",

‎apps/example-macos/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ yarn workspace example-macos pod:install:macos
1616
yarn workspace example-macos build:macos
1717
```
1818

19-
The app targets macOS 14.0. Dawn comes from `react-native-webgpu-dawn`; nothing
20-
is built from Dawn sources. For development, run these in separate terminals:
19+
The app targets macOS 14.0. Dawn is prepared from the pinned SDK archive during Xcode compilation;
20+
nothing is built from Dawn sources. For development, run these in separate terminals:
2121

2222
```sh
2323
yarn workspace example-macos start

‎apps/example-macos/macos/Podfile.lock‎

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,36 +2021,6 @@ PODS:
20212021
- ReactCommon/turbomodule/core
20222022
- SocketRocket
20232023
- Yoga
2024-
- react-native-skia (3.10.0):
2025-
- boost
2026-
- DoubleConversion
2027-
- fast_float
2028-
- fmt
2029-
- glog
2030-
- hermes-engine
2031-
- RCT-Folly
2032-
- RCT-Folly/Fabric
2033-
- RCTRequired
2034-
- RCTTypeSafety
2035-
- React
2036-
- React-callinvoker
2037-
- React-Core
2038-
- React-debug
2039-
- React-Fabric
2040-
- React-featureflags
2041-
- React-graphics
2042-
- React-ImageManager
2043-
- React-jsi
2044-
- React-NativeModulesApple
2045-
- React-RCTFabric
2046-
- React-renderercss
2047-
- React-rendererdebug
2048-
- React-utils
2049-
- ReactCodegen
2050-
- ReactCommon/turbomodule/bridging
2051-
- ReactCommon/turbomodule/core
2052-
- SocketRocket
2053-
- Yoga
20542024
- react-native-webgpu (0.0.0):
20552025
- boost
20562026
- DoubleConversion
@@ -2965,7 +2935,6 @@ DEPENDENCIES:
29652935
- React-microtasksnativemodule (from `../node_modules/react-native-macos/ReactCommon/react/nativemodule/microtasks`)
29662936
- React-mutationobservernativemodule (from `../node_modules/react-native-macos/ReactCommon/react/nativemodule/mutationobserver`)
29672937
- react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)
2968-
- react-native-skia (from `../node_modules/react-native-skia`)
29692938
- react-native-webgpu (from `../node_modules/react-native-webgpu`)
29702939
- React-NativeModulesApple (from `../node_modules/react-native-macos/ReactCommon/react/nativemodule/core/platform/ios`)
29712940
- React-networking (from `../node_modules/react-native-macos/ReactCommon/react/networking`)
@@ -3106,8 +3075,6 @@ EXTERNAL SOURCES:
31063075
:path: "../node_modules/react-native-macos/ReactCommon/react/nativemodule/mutationobserver"
31073076
react-native-safe-area-context:
31083077
:path: "../node_modules/react-native-safe-area-context"
3109-
react-native-skia:
3110-
:path: "../node_modules/react-native-skia"
31113078
react-native-webgpu:
31123079
:path: "../node_modules/react-native-webgpu"
31133080
React-NativeModulesApple:
@@ -3239,8 +3206,7 @@ SPEC CHECKSUMS:
32393206
React-microtasksnativemodule: 19a679c33c2a30339ded09015f3b150d17741dd9
32403207
React-mutationobservernativemodule: fd162222cbf7aa9f00ceaddcfcf3af472dd84db0
32413208
react-native-safe-area-context: 6cf08f4151132f9cf2adb948dc6c4ac387f8d30f
3242-
react-native-skia: 2a2e368f129a7c029b5dd22e06395eac4fe94c3f
3243-
react-native-webgpu: a038711df350957d325a322211216bb73dac7a10
3209+
react-native-webgpu: 7f9b1b83788339356f7567add013bef85f1cf117
32443210
React-NativeModulesApple: 5ead5f7c62cdc951f5090c3f736f4da36c1807b5
32453211
React-networking: d61cd2aed6bd3ef10baef7b327219f7c12a6969b
32463212
React-oscompat: 7551cbe14bc1ff01314e9cf119a985abe3e70344

‎apps/example-macos/package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"react-native-reanimated": "4.6.0",
2727
"react-native-safe-area-context": "^5.4.0",
2828
"react-native-screens": "4.19.0",
29-
"react-native-skia": "3.10.0",
3029
"react-native-webgpu": "workspace:*",
3130
"react-native-worklets": "0.12.2",
3231
"teapot": "^1.0.0",

0 commit comments

Comments
 (0)