react-native-webgpu 0.5.17 → 0.5.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,6 +8,20 @@ WebGPU for React Native, powered by Dawn.
8
8
 
9
9
  [Installation instructions](https://wcandillon.github.io/react-native-webgpu/docs/getting-started/installation)
10
10
 
11
+ ## Expo config plugin
12
+
13
+ The package ships with an Expo config plugin that disables Metal API validation in the iOS Xcode scheme, which is required to run WebGPU on the iOS Simulator (Metal API validation reports false positives for Dawn that do not occur on device). Because the plugin is part of the package, plugin and package versions are always aligned.
14
+
15
+ ```json
16
+ {
17
+ "expo": {
18
+ "plugins": ["react-native-webgpu"]
19
+ }
20
+ }
21
+ ```
22
+
23
+ See the [Expo guide](https://wcandillon.github.io/react-native-webgpu/docs/getting-started/expo#config-plugin) for details.
24
+
11
25
  ## Contributing
12
26
 
13
27
  For detailed information on library development, building, testing, and contributing guidelines, please see [CONTRIBUTING.md](packages/webgpu/CONTRIBUTING.md).
package/app.plugin.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require("./plugin/build").default;
@@ -0,0 +1,3 @@
1
+ declare const _exports: any;
2
+ export = _exports;
3
+ //# sourceMappingURL=app.plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.plugin.d.ts","sourceRoot":"","sources":["../../app.plugin.js"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-webgpu",
3
- "version": "0.5.17",
3
+ "version": "0.5.18",
4
4
  "description": "React Native WebGPU",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -18,15 +18,19 @@
18
18
  "cpp/**/*.{h,cpp}",
19
19
  "apple/**",
20
20
  "libs/**",
21
- "*.podspec"
21
+ "*.podspec",
22
+ "app.plugin.js",
23
+ "plugin/build/**"
22
24
  ],
23
25
  "dawn": "chromium/7849",
24
26
  "scripts": {
25
27
  "test": "NODE_OPTIONS='--experimental-require-module' jest -i",
26
28
  "test:ref": "REFERENCE=true NODE_OPTIONS='--experimental-require-module' jest -i",
29
+ "test:plugin": "jest -c plugin/jest.config.js",
27
30
  "lint": "eslint . --ext .ts,.tsx --max-warnings 0 --cache --fix",
28
31
  "tsc": "tsc --noEmit",
29
- "build": "bob build",
32
+ "build": "bob build && yarn build:plugin",
33
+ "build:plugin": "tsc -p plugin/tsconfig.build.json",
30
34
  "release": "semantic-release",
31
35
  "build-dawn": "tsx scripts/build/dawn.ts",
32
36
  "clean-dawn": "rimraf ./libs && rimraf ../../externals/dawn/out",
@@ -41,7 +45,9 @@
41
45
  "keywords": [
42
46
  "react-native",
43
47
  "ios",
44
- "android"
48
+ "android",
49
+ "expo",
50
+ "expo-config-plugin"
45
51
  ],
46
52
  "repository": {
47
53
  "type": "git",
@@ -59,6 +65,7 @@
59
65
  "provenance": true
60
66
  },
61
67
  "devDependencies": {
68
+ "@expo/config-plugins": "^57.0.3",
62
69
  "@semantic-release/commit-analyzer": "^13.0.0",
63
70
  "@semantic-release/exec": "^7.0.3",
64
71
  "@semantic-release/github": "^10.3.3",
@@ -0,0 +1,3 @@
1
+ import type { ConfigPlugin } from "@expo/config-plugins";
2
+ declare const _default: ConfigPlugin<void>;
3
+ export default _default;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const config_plugins_1 = require("@expo/config-plugins");
4
+ const withMetalApiValidation_1 = require("./withMetalApiValidation");
5
+ const pkg = require("../../package.json");
6
+ const withWebGPU = (config) => (0, withMetalApiValidation_1.withMetalApiValidationDisabled)(config);
7
+ // Expo resolves config plugins through their default export (re-exported by
8
+ // app.plugin.js at the package root).
9
+ // eslint-disable-next-line import/no-default-export
10
+ exports.default = (0, config_plugins_1.createRunOncePlugin)(withWebGPU, pkg.name, pkg.version);
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Rewrites an Xcode scheme (.xcscheme XML) so that Metal API validation is
3
+ * disabled for the Run action — the same effect as unchecking
4
+ * Product → Scheme → Edit Scheme → Run → Diagnostics → Metal API Validation.
5
+ *
6
+ * Xcode encodes the setting as the `enableGPUValidationMode` attribute on the
7
+ * <LaunchAction> element: the attribute is absent when validation is enabled
8
+ * (the default) and set to "1" when disabled. This mirrors how Flutter
9
+ * disables Metal API validation in its templates
10
+ * (https://github.com/flutter/flutter/pull/159228).
11
+ */
12
+ export declare const setMetalApiValidationDisabled: (xcscheme: string) => string;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setMetalApiValidationDisabled = void 0;
4
+ /**
5
+ * Rewrites an Xcode scheme (.xcscheme XML) so that Metal API validation is
6
+ * disabled for the Run action — the same effect as unchecking
7
+ * Product → Scheme → Edit Scheme → Run → Diagnostics → Metal API Validation.
8
+ *
9
+ * Xcode encodes the setting as the `enableGPUValidationMode` attribute on the
10
+ * <LaunchAction> element: the attribute is absent when validation is enabled
11
+ * (the default) and set to "1" when disabled. This mirrors how Flutter
12
+ * disables Metal API validation in its templates
13
+ * (https://github.com/flutter/flutter/pull/159228).
14
+ */
15
+ const setMetalApiValidationDisabled = (xcscheme) => xcscheme.replace(/<LaunchAction([^>]*)>/, (launchAction, attributes) => {
16
+ if (attributes.includes("enableGPUValidationMode")) {
17
+ return launchAction.replace(/enableGPUValidationMode\s*=\s*"[^"]*"/, 'enableGPUValidationMode = "1"');
18
+ }
19
+ return `<LaunchAction${attributes}\n enableGPUValidationMode = "1">`;
20
+ });
21
+ exports.setMetalApiValidationDisabled = setMetalApiValidationDisabled;
@@ -0,0 +1,9 @@
1
+ import type { ConfigPlugin } from "@expo/config-plugins";
2
+ /**
3
+ * Disables Metal API validation in every shared Xcode scheme of the iOS
4
+ * project. Dawn (the WebGPU implementation) triggers false-positive
5
+ * validation errors on the iOS Simulator that do not occur on device.
6
+ * Manually unchecking the setting in Xcode does not survive
7
+ * `npx expo prebuild --clean`, which is why this is a config plugin.
8
+ */
9
+ export declare const withMetalApiValidationDisabled: ConfigPlugin;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.withMetalApiValidationDisabled = void 0;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ const config_plugins_1 = require("@expo/config-plugins");
40
+ const setMetalApiValidation_1 = require("./setMetalApiValidation");
41
+ const getSharedSchemes = (platformProjectRoot) => {
42
+ if (!fs.existsSync(platformProjectRoot)) {
43
+ return [];
44
+ }
45
+ return fs
46
+ .readdirSync(platformProjectRoot)
47
+ .filter((entry) => entry.endsWith(".xcodeproj"))
48
+ .map((entry) => path.join(platformProjectRoot, entry, "xcshareddata", "xcschemes"))
49
+ .filter((schemesDir) => fs.existsSync(schemesDir))
50
+ .flatMap((schemesDir) => fs
51
+ .readdirSync(schemesDir)
52
+ .filter((file) => file.endsWith(".xcscheme"))
53
+ .map((file) => path.join(schemesDir, file)));
54
+ };
55
+ /**
56
+ * Disables Metal API validation in every shared Xcode scheme of the iOS
57
+ * project. Dawn (the WebGPU implementation) triggers false-positive
58
+ * validation errors on the iOS Simulator that do not occur on device.
59
+ * Manually unchecking the setting in Xcode does not survive
60
+ * `npx expo prebuild --clean`, which is why this is a config plugin.
61
+ */
62
+ const withMetalApiValidationDisabled = (config) => (0, config_plugins_1.withDangerousMod)(config, [
63
+ "ios",
64
+ async (cfg) => {
65
+ const schemes = getSharedSchemes(cfg.modRequest.platformProjectRoot);
66
+ for (const scheme of schemes) {
67
+ const contents = fs.readFileSync(scheme, "utf8");
68
+ fs.writeFileSync(scheme, (0, setMetalApiValidation_1.setMetalApiValidationDisabled)(contents));
69
+ }
70
+ return cfg;
71
+ },
72
+ ]);
73
+ exports.withMetalApiValidationDisabled = withMetalApiValidationDisabled;