From ac7296249ce6d7c6157b4b8c1c8d17d66e6074ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Kwas=CC=81niewski?= Date: Fri, 20 Sep 2024 14:28:37 +0200 Subject: [PATCH] fix: properly build xcframework --- .github/workflows/build-dawn.yml | 3 +- .github/workflows/ci.yml | 4 +- packages/webgpu/react-native-wgpu.podspec | 12 +----- .../scripts/build/apple.toolchain.cmake | 43 ++++++++++--------- packages/webgpu/scripts/build/dawn.ts | 34 +++------------ 5 files changed, 34 insertions(+), 62 deletions(-) diff --git a/.github/workflows/build-dawn.yml b/.github/workflows/build-dawn.yml index ffa94b381..44c5b1138 100644 --- a/.github/workflows/build-dawn.yml +++ b/.github/workflows/build-dawn.yml @@ -41,6 +41,7 @@ jobs: with: name: dawn-libs path: | - packages/webgpu/libs + packages/webgpu/libs/android + packages/webgpu/libs/ios/*.xcframework packages/webgpu/cpp/dawn packages/webgpu/cpp/webgpu diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index df1f2e31c..c0c8d4af6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,7 +55,7 @@ jobs: run: yarn build build-android: - runs-on: macos-latest-large + runs-on: macos-latest env: TURBO_CACHE_DIR: .turbo/android steps: @@ -126,7 +126,7 @@ jobs: yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}" build-ios: - runs-on: macos-latest-large + runs-on: macos-latest env: TURBO_CACHE_DIR: .turbo/ios steps: diff --git a/packages/webgpu/react-native-wgpu.podspec b/packages/webgpu/react-native-wgpu.podspec index f306158cf..36709c901 100644 --- a/packages/webgpu/react-native-wgpu.podspec +++ b/packages/webgpu/react-native-wgpu.podspec @@ -19,17 +19,7 @@ Pod::Spec.new do |s| "cpp/**/*.{h,cpp}" ] - s.ios.vendored_frameworks = [ - 'libs/apple/libwebgpu_dawn.xcframework', - ] - - s.visionos.vendored_frameworks = [ - 'libs/apple/libwebgpu_dawn_visionos.xcframework', - ] - - s.pod_target_xcconfig = { - 'HEADER_SEARCH_PATHS' => '$(PODS_TARGET_SRCROOT)/cpp', - } + s.vendored_frameworks = 'libs/apple/libwebgpu_dawn.xcframework' # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0. # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79. diff --git a/packages/webgpu/scripts/build/apple.toolchain.cmake b/packages/webgpu/scripts/build/apple.toolchain.cmake index 382d870fe..d4997d266 100644 --- a/packages/webgpu/scripts/build/apple.toolchain.cmake +++ b/packages/webgpu/scripts/build/apple.toolchain.cmake @@ -67,10 +67,9 @@ # TVOSCOMBINED = Build for arm64 x86_64 tvOS + tvOS Simulator. Combined into FAT STATIC lib (only supported on 3.14+ of CMake with "-G Xcode" argument in combination with the "cmake --install" CMake build step) # SIMULATOR_TVOS = Build for x86_64 tvOS Simulator. # SIMULATORARM64_TVOS = Build for arm64 tvOS Simulator. -# VISIONOSCOMBINED = Build for arm64 x86_64 visionOS Simulator and arm64 visionOS. Combined into FAT STATIC lib (only supported on 3.14+ of CMake with "-G Xcode" argument in combination with the "cmake --install" CMake build step) +# VISIONOSCOMBINED = Build for arm64 visionOS + visionOS Simulator. Combined into FAT STATIC lib (only supported on 3.14+ of CMake with "-G Xcode" argument in combination with the "cmake --install" CMake build step) # VISIONOS = Build for arm64 visionOS. # SIMULATOR_VISIONOS = Build for arm64 visionOS Simulator. -# SIMULATOR64_VISIONOS = Build for x86_64 visionOS Simulator. # WATCHOS = Build for armv7k arm64_32 for watchOS. # WATCHOSCOMBINED = Build for armv7k arm64_32 x86_64 watchOS + watchOS Simulator. Combined into FAT STATIC lib (only supported on 3.14+ of CMake with "-G Xcode" argument in combination with the "cmake --install" CMake build step) # SIMULATOR_WATCHOS = Build for x86_64 for watchOS Simulator. @@ -82,6 +81,7 @@ # Note: The build argument "MACOSX_DEPLOYMENT_TARGET" can be used to control min-version of macOS # MAC_CATALYST_ARM64 = Build for Apple Silicon macOS with Catalyst support (iOS toolchain on macOS). # Note: The build argument "MACOSX_DEPLOYMENT_TARGET" can be used to control min-version of macOS +# MAC_CATALYST_UNIVERSAL = Combined build for x86_64 and Apple Silicon on Catalyst. # # CMAKE_OSX_SYSROOT: Path to the SDK to use. By default this is # automatically determined from PLATFORM and xcodebuild, but @@ -124,6 +124,7 @@ # MAC_UNIVERSAL = x86_64 arm64 # MAC_CATALYST = x86_64 # MAC_CATALYST_ARM64 = arm64 +# MAC_CATALYST_UNIVERSAL = x86_64 arm64 # # NOTE: When manually specifying ARCHS, put a semi-colon between the entries. E.g., -DARCHS="armv7;arm64" # @@ -155,7 +156,8 @@ cmake_minimum_required(VERSION 3.8.0) # CMake invokes the toolchain file twice during the first build, but only once during subsequent rebuilds. -if(DEFINED ENV{_IOS_TOOLCHAIN_HAS_RUN}) +# NOTE: To improve single-library build-times, provide the flag "OS_SINGLE_BUILD" as a build argument. +if(DEFINED OS_SINGLE_BUILD AND DEFINED ENV{_IOS_TOOLCHAIN_HAS_RUN}) return() endif() set(ENV{_IOS_TOOLCHAIN_HAS_RUN} true) @@ -166,8 +168,8 @@ list(APPEND _supported_platforms "TVOS" "TVOSCOMBINED" "SIMULATOR_TVOS" "SIMULATORARM64_TVOS" "WATCHOS" "WATCHOSCOMBINED" "SIMULATOR_WATCHOS" "SIMULATORARM64_WATCHOS" "MAC" "MAC_ARM64" "MAC_UNIVERSAL" - "VISIONOS" "SIMULATOR_VISIONOS" "VISIONOSCOMBINED" "SIMULATOR64_VISIONOS" - "MAC_CATALYST" "MAC_CATALYST_ARM64") + "VISIONOS" "SIMULATOR_VISIONOS" "VISIONOSCOMBINED" + "MAC_CATALYST" "MAC_CATALYST_ARM64" "MAC_CATALYST_UNIVERSAL") # Cache what generator is used set(USED_CMAKE_GENERATOR "${CMAKE_GENERATOR}") @@ -231,7 +233,7 @@ if("${contains_PLATFORM}" EQUAL "-1") endif() # Check if Apple Silicon is supported -if(PLATFORM MATCHES "^(MAC_ARM64)$|^(MAC_CATALYST_ARM64)$|^(MAC_UNIVERSAL)$" AND ${CMAKE_VERSION} VERSION_LESS "3.19.5") +if(PLATFORM MATCHES "^(MAC_ARM64)$|^(MAC_CATALYST_ARM64)$|^(MAC_UNIVERSAL)$|^(MAC_CATALYST_UNIVERSAL)$" AND ${CMAKE_VERSION} VERSION_LESS "3.19.5") message(FATAL_ERROR "Apple Silicon builds requires a minimum of CMake 3.19.5") endif() @@ -267,7 +269,7 @@ if(NOT DEFINED DEPLOYMENT_TARGET) elseif(PLATFORM STREQUAL "MAC") # Unless specified, SDK version 10.13 (High Sierra) is used by default as the minimum target version (macos). set(DEPLOYMENT_TARGET "11.0") - elseif(PLATFORM STREQUAL "VISIONOS") + elseif(PLATFORM STREQUAL "VISIONOS" OR PLATFORM STREQUAL "SIMULATOR_VISIONOS" OR PLATFORM STREQUAL "VISIONOSCOMBINED") # Unless specified, SDK version 1.0 is used by default as minimum target version (visionOS). set(DEPLOYMENT_TARGET "1.0") elseif(PLATFORM STREQUAL "MAC_ARM64") @@ -276,7 +278,7 @@ if(NOT DEFINED DEPLOYMENT_TARGET) elseif(PLATFORM STREQUAL "MAC_UNIVERSAL") # Unless specified, SDK version 11.0 (Big Sur) is used by default as minimum target version for universal builds. set(DEPLOYMENT_TARGET "11.0") - elseif(PLATFORM STREQUAL "MAC_CATALYST" OR PLATFORM STREQUAL "MAC_CATALYST_ARM64") + elseif(PLATFORM STREQUAL "MAC_CATALYST" OR PLATFORM STREQUAL "MAC_CATALYST_ARM64" OR PLATFORM STREQUAL "MAC_CATALYST_UNIVERSAL") # Unless specified, SDK version 13.0 is used by default as the minimum target version (mac catalyst minimum requirement). set(DEPLOYMENT_TARGET "13.1") else() @@ -503,14 +505,6 @@ elseif(PLATFORM_INT STREQUAL "SIMULATOR_VISIONOS") else() set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-xros${DEPLOYMENT_TARGET}-simulator) endif() -elseif(PLATFORM_INT STREQUAL "SIMULATOR64_VISIONOS") - set(SDK_NAME xrsimulator) - if(NOT ARCHS) - set(ARCHS x86_64) - set(APPLE_TARGET_TRIPLE_INT x86_64-apple-xros${DEPLOYMENT_TARGET}-simulator) - else() - set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-xros${DEPLOYMENT_TARGET}-simulator) - endif() elseif(PLATFORM_INT STREQUAL "VISIONOS") set(SDK_NAME xros) if(NOT ARCHS) @@ -526,7 +520,7 @@ elseif(PLATFORM_INT STREQUAL "VISIONOSCOMBINED") set(ARCHS arm64) set(APPLE_TARGET_TRIPLE_INT arm64-apple-xros${DEPLOYMENT_TARGET}) set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=xros*] "arm64") - set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=xrsimulator*] "x86_64 arm64") + set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=xrsimulator*] "arm64") else() set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-xros${DEPLOYMENT_TARGET}) endif() @@ -562,6 +556,13 @@ elseif(PLATFORM_INT STREQUAL "MAC_UNIVERSAL") endif() string(REPLACE ";" "-" ARCHS_SPLIT "${ARCHS}") set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-macosx${DEPLOYMENT_TARGET}) +elseif(PLATFORM_INT STREQUAL "MAC_CATALYST_UNIVERSAL") + set(SDK_NAME macosx) + if(NOT ARCHS) + set(ARCHS "x86_64;arm64") + endif() + string(REPLACE ";" "-" ARCHS_SPLIT "${ARCHS}") + set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-ios${DEPLOYMENT_TARGET}-macabi) else() message(FATAL_ERROR "Invalid PLATFORM: ${PLATFORM_INT}") endif() @@ -770,10 +771,10 @@ set(APPLE ON CACHE BOOL "") if(PLATFORM STREQUAL "MAC" OR PLATFORM STREQUAL "MAC_ARM64" OR PLATFORM STREQUAL "MAC_UNIVERSAL") set(IOS OFF CACHE BOOL "") set(MACOS ON CACHE BOOL "") -elseif(PLATFORM STREQUAL "MAC_CATALYST" OR PLATFORM STREQUAL "MAC_CATALYST_ARM64") +elseif(PLATFORM STREQUAL "MAC_CATALYST" OR PLATFORM STREQUAL "MAC_CATALYST_ARM64" OR PLATFORM STREQUAL "MAC_CATALYST_UNIVERSAL") set(IOS ON CACHE BOOL "") set(MACOS ON CACHE BOOL "") -elseif(PLATFORM STREQUAL "VISIONOS" OR PLATFORM STREQUAL "SIMULATOR_VISIONOS" OR PLATFORM STREQUAL "VISIONOSCOMBINED" OR PLATFORM STREQUAL "SIMULATOR64_VISIONOS") +elseif(PLATFORM STREQUAL "VISIONOS" OR PLATFORM STREQUAL "SIMULATOR_VISIONOS" OR PLATFORM STREQUAL "VISIONOSCOMBINED") set(IOS OFF CACHE BOOL "") set(VISIONOS ON CACHE BOOL "") else() @@ -1048,7 +1049,7 @@ set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES ) if(NAMED_LANGUAGE_SUPPORT_INT) - list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES + list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES CMAKE_OBJC_FLAGS CMAKE_OBJC_DEBUG CMAKE_OBJC_MINSIZEREL @@ -1086,7 +1087,7 @@ IF(NOT DEFINED CMAKE_FIND_FRAMEWORK) ENDIF(NOT DEFINED CMAKE_FIND_FRAMEWORK) # Set up the default search directories for frameworks. -if(PLATFORM_INT MATCHES "^MAC_CATALYST") +if(PLATFORM_INT MATCHES "^MAC_CATALYST") set(CMAKE_FRAMEWORK_PATH ${CMAKE_DEVELOPER_ROOT}/Library/PrivateFrameworks ${CMAKE_OSX_SYSROOT_INT}/System/Library/Frameworks diff --git a/packages/webgpu/scripts/build/dawn.ts b/packages/webgpu/scripts/build/dawn.ts index 132d04b7a..30fcd1b5a 100644 --- a/packages/webgpu/scripts/build/dawn.ts +++ b/packages/webgpu/scripts/build/dawn.ts @@ -84,7 +84,7 @@ const android = { const apple = { matrix: { arm64: platforms(["iphoneos", "iphonesimulator", "xros", "xrsimulator"]), - x86_64: platforms(["iphonesimulator", "xrsimulator"]), + x86_64: platforms(["iphonesimulator"]), universal: platforms(["macosx"]), }, args: { @@ -130,46 +130,26 @@ const apple = { } } + $(`mkdir -p ${projectRoot}/libs/apple/iphonesimulator`); libs.forEach((lib) => { console.log(`📱 Building fat binary for iphone simulator: ${lib}`); $( - `lipo -create ${projectRoot}/libs/apple/x86_64_iphonesimulator/${lib}.a ${projectRoot}/libs/apple/arm64_iphonesimulator/${lib}.a -output ${projectRoot}/libs/apple/${lib}.a`, + `lipo -create ${projectRoot}/libs/apple/x86_64_iphonesimulator/${lib}.a ${projectRoot}/libs/apple/arm64_iphonesimulator/${lib}.a -output ${projectRoot}/libs/apple/iphonesimulator/${lib}.a`, ); }); libs.forEach((lib) => { - console.log(`👓 Building fat binary for visionos simulator: ${lib}`); - $( - `lipo -create ${projectRoot}/libs/apple/x86_64_xrsimulator/${lib}.a ${projectRoot}/libs/apple/arm64_xrsimulator/${lib}.a -output ${projectRoot}/libs/apple/${lib}_visionos.a`, - ); - }); + console.log(`📱 Building ${lib} (XCFramework) for iOS, visionOS and macOS`); - libs.forEach((lib) => { - console.log(`📱 Building ${lib} for iOS`); - // iOS $(`rm -rf ${projectRoot}/libs/apple/${lib}.xcframework`); $( "xcodebuild -create-xcframework " + - `-library ${projectRoot}/libs/apple/${lib}.a ` + + `-library ${projectRoot}/libs/apple/iphonesimulator/${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/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 - $(`rm -rf ${projectRoot}/libs/apple/${lib}_macosx.xcframework`); - $( - "xcodebuild -create-xcframework " + + `-library ${projectRoot}/libs/apple/arm64_xrsimulator/${lib}.a ` + `-library ${projectRoot}/libs/apple/universal_macosx/${lib}.a ` + - ` -output ${projectRoot}/libs/apple/${lib}_macosx.xcframework `, + ` -output ${projectRoot}/libs/apple/${lib}.xcframework `, ); });