Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion apps/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/webgpu/apple/MetalView.mm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import "MetalView.h"
#import "webgpu_cpp.h"
#import "webgpu/webgpu_cpp.h"

@implementation MetalView {
BOOL _isConfigured;
Expand Down
1 change: 0 additions & 1 deletion packages/webgpu/cpp/rnwgpu/api/GPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion packages/webgpu/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
25 changes: 0 additions & 25 deletions packages/webgpu/scripts/build/dawn-configuration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { checkDuplicateHeaders } from "../codegen/util";

import { $, checkFileExists, runAsync } from "./util";

export const libs = ["libwebgpu_dawn"] as const;
Expand All @@ -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<string, string>) => {
return Object.keys(args)
.map((key) => `-D${key}=${args[key]}`)
Expand Down
29 changes: 27 additions & 2 deletions packages/webgpu/scripts/build/dawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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("../..");

Expand Down
44 changes: 0 additions & 44 deletions packages/webgpu/scripts/build/download-artifacts.ts

This file was deleted.

35 changes: 35 additions & 0 deletions packages/webgpu/scripts/build/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
};
35 changes: 0 additions & 35 deletions packages/webgpu/scripts/codegen/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
};
13 changes: 13 additions & 0 deletions packages/webgpu/scripts/install-dawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { existsSync, mkdirSync, readFileSync, rmSync } from "fs";
import { join } from "path";

import { checkBuildArtifacts } from "./build/dawn-configuration";
import { checkDuplicateHeaders } from "./build/util";

// ANSI color codes
const colors = {
Expand Down Expand Up @@ -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"))) {
Expand All @@ -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`);
},
},
];
Expand Down