Skip to content

Commit 407f4e1

Browse files
committed
chore: isolate macOS example on React Native macOS 0.83
1 parent 3c54979 commit 407f4e1

29 files changed

Lines changed: 2098 additions & 1066 deletions

‎.github/workflows/ci.yml‎

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -197,19 +197,21 @@ jobs:
197197
xcrun simctl shutdown "$IOS_SIMULATOR_UDID" || true
198198
fi
199199
200-
# Decides whether build-spm-ios runs. That job only proves that
200+
# Decides whether the SwiftPM and native macOS builds run. SwiftPM proves that
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
204204
# compiles, the scripts behind the Dawn check, the dependencies that pin
205205
# react-native-webgpu-dawn, the example that links it, or CI itself. Pushes
206-
# to main, the merge queue and manual runs build unconditionally, so a
207-
# change this list misses still shows up on main.
208-
spm-changes:
206+
# to main, the merge queue and manual runs always build SwiftPM. macOS builds
207+
# on main, manual runs and relevant PRs; shared JavaScript is checked by
208+
# bundle-macos on every PR.
209+
changes:
209210
runs-on: ubuntu-latest
210211
timeout-minutes: 5
211212
outputs:
212-
run: ${{ steps.diff.outputs.run }}
213+
spm: ${{ steps.diff.outputs.spm }}
214+
macos: ${{ steps.diff.outputs.macos }}
213215
steps:
214216
- name: Checkout
215217
if: github.event_name == 'pull_request'
@@ -225,24 +227,68 @@ jobs:
225227
BASE: ${{ github.event.pull_request.base.sha }}
226228
run: |
227229
if [ "$EVENT" != "pull_request" ]; then
228-
echo "run=true" >> "$GITHUB_OUTPUT"
230+
echo "spm=true" >> "$GITHUB_OUTPUT"
231+
echo "macos=true" >> "$GITHUB_OUTPUT"
229232
exit 0
230233
fi
231234
git fetch --depth=1 origin "$BASE"
232235
changed=$(git diff --name-only "$BASE" HEAD)
233-
run=false
236+
spm=false
237+
macos=false
234238
while IFS= read -r file; do
235239
case "$file" in
236240
packages/webgpu/Package.swift|packages/webgpu/package.json|packages/webgpu/react-native.config.js|\
237241
packages/webgpu/apple/*|packages/webgpu/cpp/*|packages/webgpu/scripts/*|\
238242
spm-example/*|package.json|yarn.lock|\
239243
.github/workflows/ci.yml|.github/actions/setup/*)
240244
echo "$file"
241-
run=true
245+
spm=true
246+
;;
247+
esac
248+
case "$file" in
249+
apps/example-macos/*|packages/webgpu/*.podspec|packages/webgpu/package.json|\
250+
packages/webgpu/react-native.config.js|packages/webgpu/apple/*|packages/webgpu/cpp/*|\
251+
packages/webgpu/scripts/*|package.json|yarn.lock|.yarn/patches/*|turbo.json|\
252+
.github/workflows/ci.yml|.github/actions/setup/*)
253+
echo "macos: $file"
254+
macos=true
242255
;;
243256
esac
244257
done <<< "$changed"
245-
echo "run=$run" >> "$GITHUB_OUTPUT"
258+
echo "spm=$spm" >> "$GITHUB_OUTPUT"
259+
echo "macos=$macos" >> "$GITHUB_OUTPUT"
260+
261+
# Bundle shared sources on every PR without reserving a Mac. Native builds
262+
# alone do not exercise Metro or the desktop Worklets/Babel configuration.
263+
bundle-macos:
264+
runs-on: ubuntu-latest
265+
timeout-minutes: 15
266+
steps:
267+
- name: Checkout
268+
uses: actions/checkout@v4
269+
- name: Setup
270+
uses: ./.github/actions/setup
271+
with:
272+
github_token: ${{ secrets.GITHUB_TOKEN }}
273+
- name: Bundle macOS example
274+
run: yarn workspace example-macos bundle:macos
275+
276+
# Match Skia's macOS check: shared JS is bundled above; relevant native,
277+
# dependency or runner changes also build the CocoaPods app on a hosted Mac.
278+
build-test-macos:
279+
needs: changes
280+
if: needs.changes.outputs.macos == 'true' && (github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref == 'refs/heads/main'))
281+
runs-on: macos-latest
282+
timeout-minutes: 60
283+
steps:
284+
- name: Checkout
285+
uses: actions/checkout@v4
286+
- name: Setup
287+
uses: ./.github/actions/setup
288+
with:
289+
github_token: ${{ secrets.GITHUB_TOKEN }}
290+
- name: Build macOS example
291+
run: yarn turbo run build:macos --concurrency 1
246292

247293
# The SwiftPM example gets its own job on a GitHub-hosted Mac. It needs no
248294
# Metro, simulator or CocoaPods, so nothing ties it to the self-hosted
@@ -251,8 +297,8 @@ jobs:
251297
# It used to be a step of `build`: a hung xcodebuild there blocked the iOS
252298
# e2e result and held the self-hosted runner, which has no slack for that.
253299
build-spm-ios:
254-
needs: spm-changes
255-
if: needs.spm-changes.outputs.run == 'true'
300+
needs: changes
301+
if: needs.changes.outputs.spm == 'true'
256302
runs-on: macos-latest
257303
# Cold run: yarn install, Dawn download, RN artifacts, then one xcodebuild.
258304
timeout-minutes: 25

‎.yarn/patches/@react-navigation-stack-npm-6.4.1-52dad4e278.patch‎

Lines changed: 0 additions & 75 deletions
This file was deleted.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
diff --git a/scripts/codegen/generate-artifacts-executor/index.js b/scripts/codegen/generate-artifacts-executor/index.js
2+
index ec7ad6028727f0932c50b9b3be05317398d9fc2d..ba5777efd2acb3f23597a916857b1dc6937dfdf0 100644
3+
--- a/scripts/codegen/generate-artifacts-executor/index.js
4+
+++ b/scripts/codegen/generate-artifacts-executor/index.js
5+
@@ -27,7 +27,10 @@ const {
6+
generateRCTThirdPartyComponents,
7+
} = require('./generateRCTThirdPartyComponents');
8+
const {generateReactCodegenPodspec} = require('./generateReactCodegenPodspec');
9+
-const {generateSchemaInfos} = require('./generateSchemaInfos');
10+
+const {
11+
+ extractSupportedApplePlatforms,
12+
+ generateSchemaInfos,
13+
+} = require('./generateSchemaInfos');
14+
const {
15+
generateUnstableModulesRequiringMainQueueSetupProvider,
16+
} = require('./generateUnstableModulesRequiringMainQueueSetupProvider');
17+
@@ -119,9 +122,26 @@ function execute(
18+
reactNativeConfig,
19+
platform,
20+
);
21+
- const libraries = codegenEnabledLibraries.filter(
22+
- ({name}) => !disabledLibraries.includes(name),
23+
- );
24+
+ const libraries = codegenEnabledLibraries.filter(({name, libraryPath}) => {
25+
+ if (disabledLibraries.includes(name)) {
26+
+ return false;
27+
+ }
28+
+ if (platform !== 'ios') {
29+
+ return true;
30+
+ }
31+
+ // Only macOS apps use react-native-macos here: skip the libraries
32+
+ // whose podspec declares Apple platforms but not macOS. Their pods
33+
+ // aren't installed, and their specs may need a newer codegen.
34+
+ const applePlatforms = extractSupportedApplePlatforms(
35+
+ name,
36+
+ libraryPath,
37+
+ );
38+
+ return (
39+
+ applePlatforms == null ||
40+
+ applePlatforms.macos ||
41+
+ !Object.values(applePlatforms).some(Boolean)
42+
+ );
43+
+ });
44+
45+
const outputPath = computeOutputPath(
46+
projectRoot,
47+
diff --git a/scripts/codegen/generate-artifacts-executor/utils.js b/scripts/codegen/generate-artifacts-executor/utils.js
48+
index 7aefca2f12f8358a22c2ed5f64a585dec778c431..973e3f40b20578a30ce374cc83e9fd94906f2772 100644
49+
--- a/scripts/codegen/generate-artifacts-executor/utils.js
50+
+++ b/scripts/codegen/generate-artifacts-executor/utils.js
51+
@@ -241,6 +241,12 @@ function findExternalLibraries(
52+
);
53+
// Handle third-party libraries
54+
return Object.keys(dependencies).flatMap(dependency => {
55+
+ // Core specs come from react-native-macos. Skip the react-native peer
56+
+ // dependency so fresh discovery does not collect FBReactNativeSpec twice
57+
+ // or merge mobile-only core metadata into the macOS providers.
58+
+ if (dependency === 'react-native' && REACT_NATIVE !== 'react-native') {
59+
+ return [];
60+
+ }
61+
let configFilePath = '';
62+
try {
63+
configFilePath = require.resolve(path.join(dependency, 'package.json'), {
64+
diff --git a/Libraries/Network/RCTFileRequestHandler.mm b/Libraries/Network/RCTFileRequestHandler.mm
65+
--- a/Libraries/Network/RCTFileRequestHandler.mm
66+
+++ b/Libraries/Network/RCTFileRequestHandler.mm
67+
@@ -41,7 +41,9 @@ RCT_EXPORT_MODULE()
68+
69+
- (BOOL)canHandleRequest:(NSURLRequest *)request
70+
{
71+
- return [request.URL.scheme caseInsensitiveCompare:@"file"] == NSOrderedSame && !RCTIsBundleAssetURL(request.URL);
72+
+ // Bridgeless networking does not register RCTImageLoader as a request handler.
73+
+ // Read bundled PNG/JPEG files as bytes too, so fetch(asset.uri) can resolve.
74+
+ return [request.URL.scheme caseInsensitiveCompare:@"file"] == NSOrderedSame;
75+
}
76+
77+
- (NSOperation *)sendRequest:(NSURLRequest *)request withDelegate:(id<RCTURLRequestDelegate>)delegate

‎apps/example-macos/.gitignore‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Generated project, pods and bundles.
2+
*.xcworkspace/
3+
.xcode.env
4+
Pods/
5+
ReactTestApp-Resources.podspec.json
6+
build/
7+
node_modules/
8+
!dist/
9+
dist/*
10+
!dist/.gitignore

‎apps/example-macos/README.md‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# macOS example
2+
3+
The runner reuses `../example/src/App.tsx` and the shared gallery. Its RN macOS
4+
0.83 dependencies stay separate from the mobile RN 0.88 app. React 19.2,
5+
Reanimated 4.6 and Worklets 0.12 match the desktop renderer; Metro and Babel
6+
resolve shared imports to that same dependency graph.
7+
8+
## Build and run
9+
10+
From the repository root:
11+
12+
```sh
13+
yarn install
14+
yarn workspace example-macos bundle:macos
15+
yarn workspace example-macos pod:install:macos
16+
yarn workspace example-macos build:macos
17+
```
18+
19+
The app targets macOS 14. Dawn comes from `react-native-webgpu-dawn`; nothing
20+
is built from Dawn sources. For development, run these in separate terminals:
21+
22+
```sh
23+
yarn workspace example-macos start
24+
yarn workspace example-macos macos
25+
```
26+
27+
The shared gallery already uses a JavaScript navigation stack. Screens stays on
28+
4.19 for its desktop View fallback. The camera integration remains mobile-only;
29+
its native Nitro dependencies are not installed in this workspace. Gallery rows
30+
use React Native's `TouchableOpacity`, matching Skia's example. Gesture Handler
31+
buttons stopped accepting mouse clicks after returning from a demo on macOS;
32+
white rows also set black text so dark appearance cannot hide their labels.
33+
34+
The RN macOS patch keeps Codegen on the desktop native modules and lets its
35+
file request handler read bundled images. Without the latter, bridgeless
36+
`fetch(asset.uri)` has no handler for PNG/JPEG assets, leaving the gallery
37+
waiting for its textures.
38+
39+
## CI
40+
41+
Every PR bundles the macOS gallery on Linux. Changes to the desktop runner,
42+
native sources or dependency configuration also build the macOS app on a hosted
43+
Mac, matching Skia's platform-specific CI checks.

‎apps/example-macos/app.json‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "Example",
3+
"displayName": "WebGPU macOS Example",
4+
"singleApp": "example-app",
5+
"components": [
6+
{
7+
"appKey": "Example",
8+
"displayName": "Example",
9+
"slug": "example-app"
10+
}
11+
],
12+
"resources": {
13+
"macos": ["dist/assets", "dist/main.macos.jsbundle"]
14+
},
15+
"macos": {
16+
"metalAPIValidation": false
17+
}
18+
}

‎apps/example-macos/babel.config.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Shared files must use the Worklets plugin matching the desktop native build.
2+
module.exports = {
3+
presets: [require.resolve("@react-native/babel-preset")],
4+
plugins: [
5+
require.resolve("@babel/plugin-transform-class-static-block"),
6+
require.resolve("babel-plugin-transform-inline-environment-variables"),
7+
require.resolve("unplugin-typegpu/babel"),
8+
require.resolve("react-native-worklets/plugin"),
9+
],
10+
};

‎apps/example-macos/dist/.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

‎apps/example-macos/index.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/** Share the gallery while using this runner's desktop dependencies. */
2+
import { AppRegistry } from "react-native";
3+
4+
import App from "../example/src/App";
5+
6+
import { name as appName } from "./app.json";
7+
8+
AppRegistry.registerComponent(appName, () => App);

‎apps/example-macos/macos/Podfile‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
ws_dir = Pathname.new(__dir__)
2+
ws_dir = ws_dir.parent until
3+
File.exist?("#{ws_dir}/node_modules/react-native-test-app/macos/test_app.rb") ||
4+
ws_dir.expand_path.to_s == '/'
5+
require "#{ws_dir}/node_modules/react-native-test-app/macos/test_app.rb"
6+
7+
workspace 'Example.xcworkspace'
8+
9+
platform :osx, '14.0'
10+
11+
# Dependencies with older podspec floors still compile for the app's minimum.
12+
raise_pod_deployment_targets = ->(installer) do
13+
installer.pods_project.targets.each do |target|
14+
target.build_configurations.each do |config|
15+
current = config.build_settings['MACOSX_DEPLOYMENT_TARGET']
16+
next if current.nil? || Gem::Version.new(current) >= Gem::Version.new('14.0')
17+
18+
config.build_settings['MACOSX_DEPLOYMENT_TARGET'] = '14.0'
19+
end
20+
end
21+
end
22+
23+
use_test_app!(:hermes_enabled => true,
24+
:new_arch_enabled => true,
25+
:post_install => raise_pod_deployment_targets)

0 commit comments

Comments
 (0)