Skip to content

Commit ab86696

Browse files
authored
fix(🍏): fix duplicate headers for iOS (#283)
1 parent 7be0ab7 commit ab86696

File tree

11 files changed

+80
-112
lines changed

11 files changed

+80
-112
lines changed

apps/example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,7 +1865,7 @@ PODS:
18651865
- ReactCommon/turbomodule/core
18661866
- SocketRocket
18671867
- Yoga
1868-
- react-native-wgpu (0.3.0):
1868+
- react-native-wgpu (0.3.2):
18691869
- boost
18701870
- DoubleConversion
18711871
- fast_float
@@ -2903,7 +2903,7 @@ SPEC CHECKSUMS:
29032903
React-microtasksnativemodule: 75b6604b667d297292345302cc5bfb6b6aeccc1b
29042904
react-native-safe-area-context: c6e2edd1c1da07bdce287fa9d9e60c5f7b514616
29052905
react-native-skia: 5bf2b2107cd7f2d806fd364f5e16b1c7554ed3cd
2906-
react-native-wgpu: 6704c6ad8ef91fdbbad58543089ac50c0e6f3fa7
2906+
react-native-wgpu: 15ebc049194b0d06082ab00fb2e5d21ec871c2f4
29072907
React-NativeModulesApple: 879fbdc5dcff7136abceb7880fe8a2022a1bd7c3
29082908
React-oscompat: 93b5535ea7f7dff46aaee4f78309a70979bdde9d
29092909
React-perflogger: 5536d2df3d18fe0920263466f7b46a56351c0510

apps/example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"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\"",
1515
"build:macos": "react-native build-macos --scheme Example --mode Debug",
1616
"mkdist": "node -e \"require('node:fs').mkdirSync('dist', { recursive: true, mode: 0o755 })\"",
17-
"postinstall": "yarn pod:install:ios"
17+
"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' });\""
1818
},
1919
"dependencies": {
2020
"@callstack/react-native-visionos": "^0.74.0",

packages/webgpu/apple/MetalView.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#import "MetalView.h"
2-
#import "webgpu_cpp.h"
2+
#import "webgpu/webgpu_cpp.h"
33

44
@implementation MetalView {
55
BOOL _isConfigured;

packages/webgpu/cpp/rnwgpu/api/GPU.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "rnwgpu/async/AsyncRunner.h"
1313
#include "rnwgpu/async/AsyncTaskHandle.h"
1414

15-
#include "dawn/native/DawnNative.h"
1615
#include "webgpu/webgpu_cpp.h"
1716

1817
#include "GPUAdapter.h"

packages/webgpu/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-wgpu",
3-
"version": "0.3.1",
3+
"version": "0.3.2",
44
"description": "React Native WebGPU",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",

packages/webgpu/scripts/build/dawn-configuration.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { checkDuplicateHeaders } from "../codegen/util";
2-
31
import { $, checkFileExists, runAsync } from "./util";
42

53
export const libs = ["libwebgpu_dawn"] as const;
@@ -18,29 +16,6 @@ export const platforms = [
1816
export type OS = "apple" | "android";
1917
export type Platform = (typeof platforms)[number];
2018

21-
export const copyHeaders = () => {
22-
console.log("📗 Copy headers");
23-
[
24-
`rm -rf ${projectRoot}/cpp/webgpu`,
25-
`rm -rf ${projectRoot}/cpp/dawn`,
26-
`cp -a externals/dawn/out/android_arm64-v8a/gen/include/webgpu ${projectRoot}/cpp`,
27-
`cp -a externals/dawn/out/android_arm64-v8a/gen/include/dawn ${projectRoot}/cpp`,
28-
`cp -a externals/dawn/include/webgpu/. ${projectRoot}/cpp/webgpu`,
29-
`cp -a externals/dawn/include/dawn/. ${projectRoot}/cpp/dawn`,
30-
`sed -i '' 's/#include "dawn\\/webgpu.h"/#include "webgpu\\/webgpu.h"/' ${projectRoot}/cpp/dawn/dawn_proc_table.h`,
31-
`cp ${projectRoot}/cpp/dawn/webgpu.h ${projectRoot}/cpp/webgpu/webgpu.h`,
32-
`cp ${projectRoot}/cpp/dawn/webgpu_cpp.h ${projectRoot}/cpp/webgpu/webgpu_cpp.h`,
33-
`rm -rf ${projectRoot}/cpp/dawn/webgpu.h`,
34-
`rm -rf ${projectRoot}/cpp/dawn/webgpu_cpp.h`,
35-
`rm -rf ${projectRoot}/cpp/dawn/wire`,
36-
`rm -rf ${projectRoot}/cpp/webgpu/webgpu_cpp_print.h`,
37-
`cp externals/dawn/src/dawn/dawn.json ${projectRoot}/libs`,
38-
].map((cmd) => $(cmd));
39-
40-
// Check for duplicate header names and issue warnings
41-
checkDuplicateHeaders(`${projectRoot}/cpp`);
42-
};
43-
4419
const serializeCMakeArgs = (args: Record<string, string>) => {
4520
return Object.keys(args)
4621
.map((key) => `-D${key}=${args[key]}`)

packages/webgpu/scripts/build/dawn.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
import { chdir } from "process";
44

55
import type { Platform } from "./dawn-configuration";
6-
import { $, mapKeys } from "./util";
6+
import { $, checkDuplicateHeaders, mapKeys } from "./util";
77
import {
88
build,
99
checkBuildArtifacts,
10-
copyHeaders,
1110
copyLib,
1211
libs,
1312
projectRoot,
@@ -64,6 +63,32 @@ const apple = {
6463
},
6564
};
6665

66+
// TODO: should be:
67+
// cmake --install ${{ output_dir }} --prefix dawn-headers
68+
// and the associated postProcess from install-dawn
69+
export const copyHeaders = () => {
70+
console.log("📗 Copy headers");
71+
[
72+
`rm -rf ${projectRoot}/cpp/webgpu`,
73+
`rm -rf ${projectRoot}/cpp/dawn`,
74+
`cp -a externals/dawn/out/android_arm64-v8a/gen/include/webgpu ${projectRoot}/cpp`,
75+
`cp -a externals/dawn/out/android_arm64-v8a/gen/include/dawn ${projectRoot}/cpp`,
76+
`cp -a externals/dawn/include/webgpu/. ${projectRoot}/cpp/webgpu`,
77+
`cp -a externals/dawn/include/dawn/. ${projectRoot}/cpp/dawn`,
78+
`sed -i '' 's/#include "dawn\\/webgpu.h"/#include "webgpu\\/webgpu.h"/' ${projectRoot}/cpp/dawn/dawn_proc_table.h`,
79+
`cp ${projectRoot}/cpp/dawn/webgpu.h ${projectRoot}/cpp/webgpu/webgpu.h`,
80+
`cp ${projectRoot}/cpp/dawn/webgpu_cpp.h ${projectRoot}/cpp/webgpu/webgpu_cpp.h`,
81+
`rm -rf ${projectRoot}/cpp/dawn/webgpu.h`,
82+
`rm -rf ${projectRoot}/cpp/dawn/webgpu_cpp.h`,
83+
`rm -rf ${projectRoot}/cpp/dawn/wire`,
84+
`rm -rf ${projectRoot}/cpp/webgpu/webgpu_cpp_print.h`,
85+
`cp externals/dawn/src/dawn/dawn.json ${projectRoot}/libs`,
86+
].map((cmd) => $(cmd));
87+
88+
// Check for duplicate header names and issue warnings
89+
checkDuplicateHeaders(`${projectRoot}/cpp`);
90+
};
91+
6792
(async () => {
6893
process.chdir("../..");
6994

packages/webgpu/scripts/build/download-artifacts.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

packages/webgpu/scripts/build/util.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,38 @@ export const $ = (command: string) => {
5555
exit(1);
5656
}
5757
};
58+
59+
export const checkDuplicateHeaders = (cppPath: string) => {
60+
// Check for duplicate header names and issue warnings
61+
const duplicateHeaders = $(
62+
`find ${cppPath} -name '*.h' -type f | sed 's/.*\\///' | sort | uniq -d`,
63+
).toString();
64+
if (duplicateHeaders.trim()) {
65+
console.warn("⚠️ WARNING: Found duplicate header names:");
66+
let hasConflicts = false;
67+
68+
duplicateHeaders
69+
.split("\n")
70+
.filter(Boolean)
71+
.forEach((filename: string) => {
72+
const fullPaths = $(
73+
`find ${cppPath} -name "${filename}" -type f`,
74+
).toString();
75+
const paths = fullPaths.split("\n").filter(Boolean);
76+
77+
console.warn(` ${filename}:`);
78+
paths.forEach((filePath: string) => {
79+
console.warn(` ${filePath}`);
80+
});
81+
82+
hasConflicts = true;
83+
});
84+
85+
if (hasConflicts) {
86+
console.error(
87+
"❌ ERROR: Duplicate headers found that will cause iOS build conflicts!",
88+
);
89+
exit(1);
90+
}
91+
}
92+
};

packages/webgpu/scripts/codegen/util.ts

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,38 +39,3 @@ export const writeFile = (
3939
`${labels[label]} ${file.substring(file.indexOf("/package/") + "/package/".length)}`,
4040
);
4141
};
42-
43-
export const checkDuplicateHeaders = (cppPath: string) => {
44-
// Check for duplicate header names and issue warnings
45-
const duplicateHeaders = $(
46-
`find ${cppPath} -name '*.h' -type f | sed 's/.*\\///' | sort | uniq -d`,
47-
).toString();
48-
if (duplicateHeaders.trim()) {
49-
console.warn("⚠️ WARNING: Found duplicate header names:");
50-
let hasConflicts = false;
51-
52-
duplicateHeaders
53-
.split("\n")
54-
.filter(Boolean)
55-
.forEach((filename: string) => {
56-
const fullPaths = $(
57-
`find ${cppPath} -name "${filename}" -type f`,
58-
).toString();
59-
const paths = fullPaths.split("\n").filter(Boolean);
60-
61-
console.warn(` ${filename}:`);
62-
paths.forEach((filePath: string) => {
63-
console.warn(` ${filePath}`);
64-
});
65-
66-
hasConflicts = true;
67-
});
68-
69-
if (hasConflicts) {
70-
console.error(
71-
"❌ ERROR: Duplicate headers found that will cause iOS build conflicts!",
72-
);
73-
exit(1);
74-
}
75-
}
76-
};

0 commit comments

Comments
 (0)