From 653b5c84594855cab42697a85e66a672566e67ed Mon Sep 17 00:00:00 2001 From: William Candillon Date: Sun, 2 Nov 2025 07:56:53 +0100 Subject: [PATCH 1/4] :green_heart: --- apps/example/ios/Podfile.lock | 4 +-- packages/webgpu/apple/MetalView.mm | 2 +- packages/webgpu/cpp/rnwgpu/api/GPU.h | 1 - packages/webgpu/package.json | 2 +- .../scripts/build/dawn-configuration.ts | 25 ------------------- packages/webgpu/scripts/install-dawn.ts | 13 ++++++++++ 6 files changed, 17 insertions(+), 30 deletions(-) diff --git a/apps/example/ios/Podfile.lock b/apps/example/ios/Podfile.lock index bb33cc217..fa69eaf26 100644 --- a/apps/example/ios/Podfile.lock +++ b/apps/example/ios/Podfile.lock @@ -1865,7 +1865,7 @@ PODS: - ReactCommon/turbomodule/core - SocketRocket - Yoga - - react-native-wgpu (0.3.0): + - react-native-wgpu (0.3.2): - boost - DoubleConversion - fast_float @@ -2903,7 +2903,7 @@ SPEC CHECKSUMS: React-microtasksnativemodule: 75b6604b667d297292345302cc5bfb6b6aeccc1b react-native-safe-area-context: c6e2edd1c1da07bdce287fa9d9e60c5f7b514616 react-native-skia: 5bf2b2107cd7f2d806fd364f5e16b1c7554ed3cd - react-native-wgpu: 6704c6ad8ef91fdbbad58543089ac50c0e6f3fa7 + react-native-wgpu: 15ebc049194b0d06082ab00fb2e5d21ec871c2f4 React-NativeModulesApple: 879fbdc5dcff7136abceb7880fe8a2022a1bd7c3 React-oscompat: 93b5535ea7f7dff46aaee4f78309a70979bdde9d React-perflogger: 5536d2df3d18fe0920263466f7b46a56351c0510 diff --git a/packages/webgpu/apple/MetalView.mm b/packages/webgpu/apple/MetalView.mm index 1431e8177..ccff1245c 100644 --- a/packages/webgpu/apple/MetalView.mm +++ b/packages/webgpu/apple/MetalView.mm @@ -1,5 +1,5 @@ #import "MetalView.h" -#import "webgpu_cpp.h" +#import "webgpu/webgpu_cpp.h" @implementation MetalView { BOOL _isConfigured; diff --git a/packages/webgpu/cpp/rnwgpu/api/GPU.h b/packages/webgpu/cpp/rnwgpu/api/GPU.h index a94e66c68..08f50c750 100644 --- a/packages/webgpu/cpp/rnwgpu/api/GPU.h +++ b/packages/webgpu/cpp/rnwgpu/api/GPU.h @@ -12,7 +12,6 @@ #include "rnwgpu/async/AsyncRunner.h" #include "rnwgpu/async/AsyncTaskHandle.h" -#include "dawn/native/DawnNative.h" #include "webgpu/webgpu_cpp.h" #include "GPUAdapter.h" diff --git a/packages/webgpu/package.json b/packages/webgpu/package.json index f302b6df0..3a688afe2 100644 --- a/packages/webgpu/package.json +++ b/packages/webgpu/package.json @@ -1,6 +1,6 @@ { "name": "react-native-wgpu", - "version": "0.3.1", + "version": "0.3.2", "description": "React Native WebGPU", "main": "lib/commonjs/index", "module": "lib/module/index", diff --git a/packages/webgpu/scripts/build/dawn-configuration.ts b/packages/webgpu/scripts/build/dawn-configuration.ts index 1cc73f44f..beef14e06 100644 --- a/packages/webgpu/scripts/build/dawn-configuration.ts +++ b/packages/webgpu/scripts/build/dawn-configuration.ts @@ -1,5 +1,3 @@ -import { checkDuplicateHeaders } from "../codegen/util"; - import { $, checkFileExists, runAsync } from "./util"; export const libs = ["libwebgpu_dawn"] as const; @@ -18,29 +16,6 @@ export const platforms = [ export type OS = "apple" | "android"; export type Platform = (typeof platforms)[number]; -export const copyHeaders = () => { - console.log("📗 Copy headers"); - [ - `rm -rf ${projectRoot}/cpp/webgpu`, - `rm -rf ${projectRoot}/cpp/dawn`, - `cp -a externals/dawn/out/android_arm64-v8a/gen/include/webgpu ${projectRoot}/cpp`, - `cp -a externals/dawn/out/android_arm64-v8a/gen/include/dawn ${projectRoot}/cpp`, - `cp -a externals/dawn/include/webgpu/. ${projectRoot}/cpp/webgpu`, - `cp -a externals/dawn/include/dawn/. ${projectRoot}/cpp/dawn`, - `sed -i '' 's/#include "dawn\\/webgpu.h"/#include "webgpu\\/webgpu.h"/' ${projectRoot}/cpp/dawn/dawn_proc_table.h`, - `cp ${projectRoot}/cpp/dawn/webgpu.h ${projectRoot}/cpp/webgpu/webgpu.h`, - `cp ${projectRoot}/cpp/dawn/webgpu_cpp.h ${projectRoot}/cpp/webgpu/webgpu_cpp.h`, - `rm -rf ${projectRoot}/cpp/dawn/webgpu.h`, - `rm -rf ${projectRoot}/cpp/dawn/webgpu_cpp.h`, - `rm -rf ${projectRoot}/cpp/dawn/wire`, - `rm -rf ${projectRoot}/cpp/webgpu/webgpu_cpp_print.h`, - `cp externals/dawn/src/dawn/dawn.json ${projectRoot}/libs`, - ].map((cmd) => $(cmd)); - - // Check for duplicate header names and issue warnings - checkDuplicateHeaders(`${projectRoot}/cpp`); -}; - const serializeCMakeArgs = (args: Record) => { return Object.keys(args) .map((key) => `-D${key}=${args[key]}`) diff --git a/packages/webgpu/scripts/install-dawn.ts b/packages/webgpu/scripts/install-dawn.ts index 6fa8f3cc4..7feb89bef 100644 --- a/packages/webgpu/scripts/install-dawn.ts +++ b/packages/webgpu/scripts/install-dawn.ts @@ -5,6 +5,7 @@ import { existsSync, mkdirSync, readFileSync, rmSync } from "fs"; import { join } from "path"; import { checkBuildArtifacts } from "./build/dawn-configuration"; +import { checkDuplicateHeaders } from "./codegen/util"; // ANSI color codes const colors = { @@ -133,6 +134,9 @@ const assets = [ name: `dawn-headers-${releaseTag}.tar.gz`, extractTo: libsDir, postProcess: () => { + // clean folders + rmSync("cpp/dawn", { recursive: true, force: true }); + rmSync("cpp/webgpu", { recursive: true, force: true }); // Move headers directly to cpp directory const headersIncludePath = join(libsDir, "dawn-headers", "include"); if (existsSync(join(headersIncludePath, "webgpu"))) { @@ -143,6 +147,15 @@ const assets = [ } // Remove the dawn-headers directory after copying rmSync(join(libsDir, "dawn-headers"), { recursive: true, force: true }); + rmSync("cpp/dawn/wire", { recursive: true, force: true }); + // Copy headers from cpp/dawn/ to cpp/webgpu/ and then delete source files + execSync( + `cp "cpp/dawn/webgpu_cpp_print.h" "cpp/webgpu/webgpu_cpp_print.h"`, + ); + execSync(`cp "cpp/dawn/webgpu_cpp.h" "cpp/webgpu/webgpu_cpp.h"`); + execSync(`cp "cpp/dawn/webgpu.h" "cpp/webgpu/webgpu.h"`); + rmSync("cpp/dawn", { recursive: true, force: true }); + checkDuplicateHeaders(`cpp`); }, }, ]; From ac8c465cdc513e1c2c6c4b17811575a5aabac776 Mon Sep 17 00:00:00 2001 From: William Candillon Date: Sun, 2 Nov 2025 07:58:03 +0100 Subject: [PATCH 2/4] :wrench: --- packages/webgpu/scripts/build/util.ts | 35 +++++++++++++++++++++++++ packages/webgpu/scripts/codegen/util.ts | 35 ------------------------- packages/webgpu/scripts/install-dawn.ts | 2 +- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/packages/webgpu/scripts/build/util.ts b/packages/webgpu/scripts/build/util.ts index acaa7a242..a14a29c61 100644 --- a/packages/webgpu/scripts/build/util.ts +++ b/packages/webgpu/scripts/build/util.ts @@ -55,3 +55,38 @@ export const $ = (command: string) => { exit(1); } }; + +export const checkDuplicateHeaders = (cppPath: string) => { + // Check for duplicate header names and issue warnings + const duplicateHeaders = $( + `find ${cppPath} -name '*.h' -type f | sed 's/.*\\///' | sort | uniq -d`, + ).toString(); + if (duplicateHeaders.trim()) { + console.warn("⚠️ WARNING: Found duplicate header names:"); + let hasConflicts = false; + + duplicateHeaders + .split("\n") + .filter(Boolean) + .forEach((filename: string) => { + const fullPaths = $( + `find ${cppPath} -name "${filename}" -type f`, + ).toString(); + const paths = fullPaths.split("\n").filter(Boolean); + + console.warn(` ${filename}:`); + paths.forEach((filePath: string) => { + console.warn(` ${filePath}`); + }); + + hasConflicts = true; + }); + + if (hasConflicts) { + console.error( + "❌ ERROR: Duplicate headers found that will cause iOS build conflicts!", + ); + exit(1); + } + } +}; diff --git a/packages/webgpu/scripts/codegen/util.ts b/packages/webgpu/scripts/codegen/util.ts index 3815bfbde..be8221742 100644 --- a/packages/webgpu/scripts/codegen/util.ts +++ b/packages/webgpu/scripts/codegen/util.ts @@ -39,38 +39,3 @@ export const writeFile = ( `${labels[label]} ${file.substring(file.indexOf("/package/") + "/package/".length)}`, ); }; - -export const checkDuplicateHeaders = (cppPath: string) => { - // Check for duplicate header names and issue warnings - const duplicateHeaders = $( - `find ${cppPath} -name '*.h' -type f | sed 's/.*\\///' | sort | uniq -d`, - ).toString(); - if (duplicateHeaders.trim()) { - console.warn("⚠️ WARNING: Found duplicate header names:"); - let hasConflicts = false; - - duplicateHeaders - .split("\n") - .filter(Boolean) - .forEach((filename: string) => { - const fullPaths = $( - `find ${cppPath} -name "${filename}" -type f`, - ).toString(); - const paths = fullPaths.split("\n").filter(Boolean); - - console.warn(` ${filename}:`); - paths.forEach((filePath: string) => { - console.warn(` ${filePath}`); - }); - - hasConflicts = true; - }); - - if (hasConflicts) { - console.error( - "❌ ERROR: Duplicate headers found that will cause iOS build conflicts!", - ); - exit(1); - } - } -}; diff --git a/packages/webgpu/scripts/install-dawn.ts b/packages/webgpu/scripts/install-dawn.ts index 7feb89bef..001876692 100644 --- a/packages/webgpu/scripts/install-dawn.ts +++ b/packages/webgpu/scripts/install-dawn.ts @@ -5,7 +5,7 @@ import { existsSync, mkdirSync, readFileSync, rmSync } from "fs"; import { join } from "path"; import { checkBuildArtifacts } from "./build/dawn-configuration"; -import { checkDuplicateHeaders } from "./codegen/util"; +import { checkDuplicateHeaders } from "./build/util"; // ANSI color codes const colors = { From 1bd1cce4baffda0edfdac6b6d1f2ab3c0a8613ab Mon Sep 17 00:00:00 2001 From: William Candillon Date: Sun, 2 Nov 2025 08:03:06 +0100 Subject: [PATCH 3/4] :wrench: --- packages/webgpu/scripts/build/dawn.ts | 29 +++++++++++- .../scripts/build/download-artifacts.ts | 44 ------------------- 2 files changed, 27 insertions(+), 46 deletions(-) delete mode 100644 packages/webgpu/scripts/build/download-artifacts.ts diff --git a/packages/webgpu/scripts/build/dawn.ts b/packages/webgpu/scripts/build/dawn.ts index f12869285..722e0f8ab 100644 --- a/packages/webgpu/scripts/build/dawn.ts +++ b/packages/webgpu/scripts/build/dawn.ts @@ -3,11 +3,10 @@ import { chdir } from "process"; import type { Platform } from "./dawn-configuration"; -import { $, mapKeys } from "./util"; +import { $, checkDuplicateHeaders, mapKeys } from "./util"; import { build, checkBuildArtifacts, - copyHeaders, copyLib, libs, projectRoot, @@ -64,6 +63,32 @@ const apple = { }, }; +// TODO: should be: +// cmake --install ${{ output_dir }} --prefix dawn-headers +// and the associated postProcess from install-dawn +export const copyHeaders = () => { + console.log("📗 Copy headers"); + [ + `rm -rf ${projectRoot}/cpp/webgpu`, + `rm -rf ${projectRoot}/cpp/dawn`, + `cp -a externals/dawn/out/android_arm64-v8a/gen/include/webgpu ${projectRoot}/cpp`, + `cp -a externals/dawn/out/android_arm64-v8a/gen/include/dawn ${projectRoot}/cpp`, + `cp -a externals/dawn/include/webgpu/. ${projectRoot}/cpp/webgpu`, + `cp -a externals/dawn/include/dawn/. ${projectRoot}/cpp/dawn`, + `sed -i '' 's/#include "dawn\\/webgpu.h"/#include "webgpu\\/webgpu.h"/' ${projectRoot}/cpp/dawn/dawn_proc_table.h`, + `cp ${projectRoot}/cpp/dawn/webgpu.h ${projectRoot}/cpp/webgpu/webgpu.h`, + `cp ${projectRoot}/cpp/dawn/webgpu_cpp.h ${projectRoot}/cpp/webgpu/webgpu_cpp.h`, + `rm -rf ${projectRoot}/cpp/dawn/webgpu.h`, + `rm -rf ${projectRoot}/cpp/dawn/webgpu_cpp.h`, + `rm -rf ${projectRoot}/cpp/dawn/wire`, + `rm -rf ${projectRoot}/cpp/webgpu/webgpu_cpp_print.h`, + `cp externals/dawn/src/dawn/dawn.json ${projectRoot}/libs`, + ].map((cmd) => $(cmd)); + + // Check for duplicate header names and issue warnings + checkDuplicateHeaders(`${projectRoot}/cpp`); +}; + (async () => { process.chdir("../.."); diff --git a/packages/webgpu/scripts/build/download-artifacts.ts b/packages/webgpu/scripts/build/download-artifacts.ts deleted file mode 100644 index a27261bee..000000000 --- a/packages/webgpu/scripts/build/download-artifacts.ts +++ /dev/null @@ -1,44 +0,0 @@ -import fs from "fs"; -import path from "path"; - -import { $ } from "./util"; - -const repo = "wcandillon/react-native-webgpu"; -const workflow = "build-dawn.yml"; -const artifactName = "dawn-libs"; -//const branch = "main"; - -const artifactsDir = path.resolve(__dirname, "../../../../artifacts"); - -// Function to clear directory contents -const clearDirectory = (directory: string) => { - if (fs.existsSync(directory)) { - fs.readdirSync(directory).forEach((file) => { - const curPath = path.join(directory, file); - if (fs.lstatSync(curPath).isDirectory()) { - clearDirectory(curPath); - fs.rmdirSync(curPath); - } else { - fs.unlinkSync(curPath); - } - }); - console.log(`❌ ${directory}`); - } else { - console.log(`Directory ${directory} does not exist, creating it...`); - fs.mkdirSync(directory, { recursive: true }); - } -}; - -const result = $( - `gh run list --repo "${repo}" --workflow "${workflow}" --status success --limit 1 --json databaseId --jq '.[0].databaseId'`, -); -const id = result.toString("utf8").trim(); - -console.log("Clearing existing artifacts..."); -clearDirectory(artifactsDir); - -console.log(`Downloading artifacts to ${artifactsDir}`); -$( - `gh run download "${id}" --repo "${repo}" --name "${artifactName}" --dir ${artifactsDir}`, -); -console.log("Done"); From f1736a68616f974074236aa02789c2474f3d8835 Mon Sep 17 00:00:00 2001 From: William Candillon Date: Sun, 2 Nov 2025 08:09:24 +0100 Subject: [PATCH 4/4] :wrench: --- apps/example/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/example/package.json b/apps/example/package.json index ae9083043..1b8223271 100644 --- a/apps/example/package.json +++ b/apps/example/package.json @@ -14,7 +14,7 @@ "build:ios": "react-native build-ios --scheme Example --mode Debug --extra-params \"-sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO\"", "build:macos": "react-native build-macos --scheme Example --mode Debug", "mkdist": "node -e \"require('node:fs').mkdirSync('dist', { recursive: true, mode: 0o755 })\"", - "postinstall": "yarn pod:install:ios" + "postinstall": "node -e \"if (process.platform !== 'darwin') { console.log('Skipping iOS pod install on non-macOS environment.'); process.exit(0); } const { execSync } = require('child_process'); execSync('yarn pod:install:ios', { stdio: 'inherit' });\"" }, "dependencies": { "@callstack/react-native-visionos": "^0.74.0",