Skip to content

Commit 6b8302e

Browse files
halby24claude
andcommitted
feat: add Expo Config Plugin for Dawn debug toggles
Expo managed/bare workflow ユーザーが app.json の plugins フィールドから enableToggles / disableToggles を設定できる Config Plugin を追加。 plugin/src/app.plugin.ts → app.plugin.js にコンパイルして配布。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 83ec66f commit 6b8302e

5 files changed

Lines changed: 369 additions & 6 deletions

File tree

packages/webgpu/app.plugin.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
const config_plugins_1 = require("@expo/config-plugins");
4+
const withWebGPUAndroid = (config, { enableToggles = [], disableToggles = [] } = {}) => {
5+
return (0, config_plugins_1.withAndroidManifest)(config, (config) => {
6+
const app = config_plugins_1.AndroidConfig.Manifest.getMainApplicationOrThrow(config.modResults);
7+
if (!app['meta-data'])
8+
app['meta-data'] = [];
9+
if (enableToggles.length > 0) {
10+
app['meta-data'].push({
11+
$: {
12+
'android:name': 'com.webgpu.enable_toggles',
13+
'android:value': enableToggles.join(','),
14+
},
15+
});
16+
}
17+
if (disableToggles.length > 0) {
18+
app['meta-data'].push({
19+
$: {
20+
'android:name': 'com.webgpu.disable_toggles',
21+
'android:value': disableToggles.join(','),
22+
},
23+
});
24+
}
25+
return config;
26+
});
27+
};
28+
const withWebGPUIos = (config, { enableToggles = [], disableToggles = [] } = {}) => {
29+
return (0, config_plugins_1.withInfoPlist)(config, (config) => {
30+
if (enableToggles.length > 0) {
31+
config.modResults['RNWebGPUEnableToggles'] = enableToggles;
32+
}
33+
if (disableToggles.length > 0) {
34+
config.modResults['RNWebGPUDisableToggles'] = disableToggles;
35+
}
36+
return config;
37+
});
38+
};
39+
const withWebGPU = (config, options = {}) => {
40+
config = withWebGPUAndroid(config, options);
41+
config = withWebGPUIos(config, options);
42+
return config;
43+
};
44+
exports.default = withWebGPU;

packages/webgpu/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77
"types": "lib/typescript/src/index.d.ts",
88
"react-native": "src/index",
99
"source": "src/index",
10+
"expo": {
11+
"plugin": "./app.plugin"
12+
},
1013
"files": [
1114
"src/**",
1215
"lib/**",
16+
"app.plugin.js",
17+
"plugin/src/**",
1318
"!**/__tests__/**",
1419
"android/build.gradle",
1520
"android/CMakeLists.txt",
@@ -26,6 +31,7 @@
2631
"test:ref": "REFERENCE=true NODE_OPTIONS='--experimental-require-module' jest -i",
2732
"lint": "eslint . --ext .ts,.tsx --max-warnings 0 --cache --fix",
2833
"tsc": "tsc --noEmit",
34+
"build:plugin": "tsc -p plugin/tsconfig.json",
2935
"build": "bob build",
3036
"build-dawn": "tsx scripts/build/dawn.ts",
3137
"clean-dawn": "rimraf ./libs && rimraf ../../externals/dawn/out",
@@ -56,6 +62,7 @@
5662
"registry": "https://registry.npmjs.org/"
5763
},
5864
"devDependencies": {
65+
"@expo/config-plugins": "^9.0.0",
5966
"@types/jest": "^29.5.12",
6067
"@types/lodash": "^4.17.5",
6168
"@types/node": "^20.14.7",
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import {
2+
ConfigPlugin,
3+
withAndroidManifest,
4+
withInfoPlist,
5+
AndroidConfig,
6+
} from '@expo/config-plugins';
7+
8+
type WebGPUPluginOptions = {
9+
enableToggles?: string[];
10+
disableToggles?: string[];
11+
};
12+
13+
const withWebGPUAndroid: ConfigPlugin<WebGPUPluginOptions> = (
14+
config,
15+
{ enableToggles = [], disableToggles = [] } = {}
16+
) => {
17+
return withAndroidManifest(config, (config) => {
18+
const app = AndroidConfig.Manifest.getMainApplicationOrThrow(
19+
config.modResults
20+
);
21+
if (!app['meta-data']) app['meta-data'] = [];
22+
23+
if (enableToggles.length > 0) {
24+
app['meta-data'].push({
25+
$: {
26+
'android:name': 'com.webgpu.enable_toggles',
27+
'android:value': enableToggles.join(','),
28+
},
29+
});
30+
}
31+
if (disableToggles.length > 0) {
32+
app['meta-data'].push({
33+
$: {
34+
'android:name': 'com.webgpu.disable_toggles',
35+
'android:value': disableToggles.join(','),
36+
},
37+
});
38+
}
39+
return config;
40+
});
41+
};
42+
43+
const withWebGPUIos: ConfigPlugin<WebGPUPluginOptions> = (
44+
config,
45+
{ enableToggles = [], disableToggles = [] } = {}
46+
) => {
47+
return withInfoPlist(config, (config) => {
48+
if (enableToggles.length > 0) {
49+
config.modResults['RNWebGPUEnableToggles'] = enableToggles;
50+
}
51+
if (disableToggles.length > 0) {
52+
config.modResults['RNWebGPUDisableToggles'] = disableToggles;
53+
}
54+
return config;
55+
});
56+
};
57+
58+
const withWebGPU: ConfigPlugin<WebGPUPluginOptions> = (
59+
config,
60+
options = {}
61+
) => {
62+
config = withWebGPUAndroid(config, options);
63+
config = withWebGPUIos(config, options);
64+
return config;
65+
};
66+
67+
export default withWebGPU;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2019",
4+
"module": "commonjs",
5+
"lib": ["ES2019"],
6+
"strict": true,
7+
"outDir": "../",
8+
"rootDir": "./src",
9+
"declaration": false,
10+
"skipLibCheck": true
11+
},
12+
"include": ["./src"],
13+
"exclude": ["../node_modules"]
14+
}

0 commit comments

Comments
 (0)