Skip to content

Commit

Permalink
fix: properly build xcframework
Browse files Browse the repository at this point in the history
  • Loading branch information
okwasniewski committed Sep 20, 2024
1 parent 8d6eea8 commit ac72962
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 62 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build-dawn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
12 changes: 1 addition & 11 deletions packages/webgpu/react-native-wgpu.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
43 changes: 22 additions & 21 deletions packages/webgpu/scripts/build/apple.toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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"
#
Expand Down Expand Up @@ -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)
Expand All @@ -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}")
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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")
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
34 changes: 7 additions & 27 deletions packages/webgpu/scripts/build/dawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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 `,
);
});

Expand Down

0 comments on commit ac72962

Please sign in to comment.