diff --git a/apps/paper/ios/Podfile.lock b/apps/paper/ios/Podfile.lock index 71d41944e..1a48b0e92 100644 --- a/apps/paper/ios/Podfile.lock +++ b/apps/paper/ios/Podfile.lock @@ -1545,7 +1545,7 @@ SPEC CHECKSUMS: React-Mapbuffer: bf56147c9775491e53122a94c423ac201417e326 react-native-safe-area-context: ab8f4a3d8180913bd78ae75dd599c94cce3d5e9a react-native-skia: 8da84ea9410504bf27f0db229539a43f6caabb6a - react-native-wgpu: a7cafd1960f61fa2fca1ddd478553f0950052f0a + react-native-wgpu: 7b017059e1841bee7a7347fc154353115c9bb2da React-nativeconfig: 9f223cd321823afdecf59ed00861ab2d69ee0fc1 React-NativeModulesApple: ff7efaff7098639db5631236cfd91d60abff04c0 React-perflogger: 32ed45d9cee02cf6639acae34251590dccd30994 diff --git a/packages/webgpu/react-native-wgpu.podspec b/packages/webgpu/react-native-wgpu.podspec index b86b6ed62..f306158cf 100644 --- a/packages/webgpu/react-native-wgpu.podspec +++ b/packages/webgpu/react-native-wgpu.podspec @@ -20,11 +20,11 @@ Pod::Spec.new do |s| ] s.ios.vendored_frameworks = [ - 'libs/ios/libwebgpu_dawn.xcframework', + 'libs/apple/libwebgpu_dawn.xcframework', ] s.visionos.vendored_frameworks = [ - 'libs/ios/libwebgpu_dawn_visionos.xcframework', + 'libs/apple/libwebgpu_dawn_visionos.xcframework', ] s.pod_target_xcconfig = { diff --git a/packages/webgpu/scripts/build/ios.toolchain.cmake b/packages/webgpu/scripts/build/apple.toolchain.cmake similarity index 100% rename from packages/webgpu/scripts/build/ios.toolchain.cmake rename to packages/webgpu/scripts/build/apple.toolchain.cmake diff --git a/packages/webgpu/scripts/build/dawn.ts b/packages/webgpu/scripts/build/dawn.ts index 096fa3773..f803b8de7 100644 --- a/packages/webgpu/scripts/build/dawn.ts +++ b/packages/webgpu/scripts/build/dawn.ts @@ -35,6 +35,7 @@ const PLATFORM_MAP: Record = { arm64_xros: "VISIONOS", arm64_xrsimulator: "SIMULATOR_VISIONOS", x86_64_xrsimulator: "SIMULATOR64_VISIONOS", + universal_macosx: "MAC_UNIVERSAL", }; const android = { @@ -46,18 +47,20 @@ const android = { }, }; -const ios = { +const apple = { matrix: { - arm64: ["iphoneos", "iphonesimulator", "xros", "xrsimulator"], - x86_64: ["iphonesimulator", "xrsimulator"], + arm64: ["iphoneos", "iphonesimulator", "xros", "xrsimulator"] as const, + x86_64: ["iphonesimulator", "xrsimulator"] as const, + universal: ["macosx"] as const, }, args: { - CMAKE_TOOLCHAIN_FILE: `${__dirname}/ios.toolchain.cmake`, + CMAKE_TOOLCHAIN_FILE: `${__dirname}/apple.toolchain.cmake`, ...commonArgs, }, }; (async () => { + checkBuildArtifacts(); process.chdir("../.."); process.chdir("externals/dawn"); $("git reset --hard HEAD"); @@ -78,53 +81,61 @@ const ios = { copyLib("android", platform); } - // Build iOS - for (const platform of mapKeys(ios.matrix)) { - console.log(`Build iOS: ${platform}`); - for (const sdk of ios.matrix[platform]) { + // Build Apple + for (const platform of mapKeys(apple.matrix)) { + console.log(`Build Apple: ${platform}`); + for (const sdk of apple.matrix[platform]) { await build( - `ios_${platform}_${sdk}`, + `apple_${platform}_${sdk}`, { PLATFORM: PLATFORM_MAP[`${platform}_${sdk}`], - ...ios.args, + ...apple.args, }, `🍏 ${platform} ${sdk}`, ); - copyLib("ios", platform, sdk); + copyLib("apple", platform, sdk); } } libs.forEach((lib) => { - console.log(`Building fat binary for iphone simulator: ${lib}`); + console.log(`📱 Building fat binary for iphone simulator: ${lib}`); $( - `lipo -create ${projectRoot}/libs/ios/x86_64_iphonesimulator/${lib}.a ${projectRoot}/libs/ios/arm64_iphonesimulator/${lib}.a -output ${projectRoot}/libs/ios/${lib}.a`, + `lipo -create ${projectRoot}/libs/apple/x86_64_iphonesimulator/${lib}.a ${projectRoot}/libs/apple/arm64_iphonesimulator/${lib}.a -output ${projectRoot}/libs/apple/${lib}.a`, ); }); libs.forEach((lib) => { - console.log(`Building fat binary for visionos simulator: ${lib}`); + console.log(`👓 Building fat binary for visionos simulator: ${lib}`); $( - `lipo -create ${projectRoot}/libs/ios/x86_64_xrsimulator/${lib}.a ${projectRoot}/libs/ios/arm64_xrsimulator/${lib}.a -output ${projectRoot}/libs/ios/${lib}_visionos.a`, + `lipo -create ${projectRoot}/libs/apple/x86_64_xrsimulator/${lib}.a ${projectRoot}/libs/apple/arm64_xrsimulator/${lib}.a -output ${projectRoot}/libs/apple/${lib}_visionos.a`, ); }); libs.forEach((lib) => { - console.log(`Building ${lib}`); + console.log(`📱 Building ${lib} for iOS`); // iOS - $(`rm -rf ${projectRoot}/libs/ios/${lib}.xcframework`); + $(`rm -rf ${projectRoot}/libs/apple/${lib}.xcframework`); $( "xcodebuild -create-xcframework " + - `-library ${projectRoot}/libs/ios/${lib}.a ` + - `-library ${projectRoot}/libs/ios/arm64_iphoneos/${lib}.a ` + - ` -output ${projectRoot}/libs/ios/${lib}.xcframework `, + `-library ${projectRoot}/libs/apple/${lib}.a ` + + `-library ${projectRoot}/libs/apple/arm64_iphoneos/${lib}.a ` + + ` -output ${projectRoot}/libs/apple/${lib}.xcframework `, ); + console.log(`👓 Building ${lib} for VisionOS`); // VisionOS - $(`rm -rf ${projectRoot}/libs/ios/${lib}_visionos.xcframework`); + $(`rm -rf ${projectRoot}/libs/apple/${lib}_visionos.xcframework`); + $( + "xcodebuild -create-xcframework " + + `-library ${projectRoot}/libs/apple/${lib}_visionos.a ` + + `-library ${projectRoot}/libs/apple/arm64_xros/${lib}.a ` + + ` -output ${projectRoot}/libs/apple/${lib}_visionos.xcframework `, + ); + console.log(`🖥️ Building ${lib} for macOS`); + // macOS $( "xcodebuild -create-xcframework " + - `-library ${projectRoot}/libs/ios/${lib}_visionos.a ` + - `-library ${projectRoot}/libs/ios/arm64_xros/${lib}.a ` + - ` -output ${projectRoot}/libs/ios/${lib}_visionos.xcframework `, + `-library ${projectRoot}/libs/apple/universal_macosx/${lib}.a ` + + ` -output ${projectRoot}/libs/apple/${lib}_macosx.xcframework `, ); }); diff --git a/packages/webgpu/scripts/build/static_build.patch b/packages/webgpu/scripts/build/static_build.patch index 06d521d99..122165b62 100644 --- a/packages/webgpu/scripts/build/static_build.patch +++ b/packages/webgpu/scripts/build/static_build.patch @@ -8,7 +8,7 @@ index 046a6af10d..5a63ac3d6d 100644 - add_library(${output_target} SHARED ${all_objects}) - -+ if(${CMAKE_SYSTEM_NAME} STREQUAL "iOS" OR ${CMAKE_SYSTEM_NAME} STREQUAL "visionOS") ++ if(${CMAKE_SYSTEM_NAME} STREQUAL "iOS" OR ${CMAKE_SYSTEM_NAME} STREQUAL "visionOS" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") + add_library(${output_target} STATIC ${all_objects}) + else() + add_library(${output_target} SHARED ${all_objects}) # Default to STATIC for other platforms diff --git a/packages/webgpu/scripts/build/util.ts b/packages/webgpu/scripts/build/util.ts index 0abe0ad8f..a52a63d95 100644 --- a/packages/webgpu/scripts/build/util.ts +++ b/packages/webgpu/scripts/build/util.ts @@ -13,9 +13,10 @@ export const platforms = [ "x86", "armeabi-v7a", "arm64-v8a", + "universal", ] as const; -export type OS = "ios" | "android"; +export type OS = "apple" | "android"; export type Platform = (typeof platforms)[number]; export const runAsync = (command: string, label: string): Promise => { @@ -83,6 +84,7 @@ export const build = async ( args: Record, debugLabel: string, ) => { + console.log(`🔨 Building ${label}`); $(`mkdir -p externals/dawn/out/${label}`); process.chdir(`externals/dawn/out/${label}`); const cmd = `cmake ../.. -G Ninja ${serializeCMakeArgs(args)}`; @@ -103,7 +105,7 @@ export const copyLib = (os: OS, platform: Platform, sdk?: string) => { ); } [ - `externals/dawn/out/${out}/src/dawn/native/libwebgpu_dawn.${os === "ios" ? "a" : "so"}`, + `externals/dawn/out/${out}/src/dawn/native/libwebgpu_dawn.${os === "apple" ? "a" : "so"}`, ].forEach((lib) => { const libPath = lib; console.log(`Copying ${libPath} to ${dstPath}`); @@ -114,14 +116,14 @@ export const copyLib = (os: OS, platform: Platform, sdk?: string) => { export const checkBuildArtifacts = () => { console.log("Check build artifacts..."); platforms - .filter((arch) => arch !== "arm64") + .filter((arch) => arch !== "arm64" && arch !== "universal") .forEach((platform) => { libs.forEach((lib) => { checkFileExists(`libs/android/${platform}/${lib}.so`); }); }); libs.forEach((lib) => { - checkFileExists(`libs/ios/${lib}.xcframework`); + checkFileExists(`libs/apple/${lib}.xcframework`); }); checkFileExists("cpp/dawn/webgpu_cpp.h"); checkFileExists("libs/dawn.json");