Skip to content

Commit

Permalink
feat: visionOS build (#90)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: William Candillon <[email protected]>
  • Loading branch information
okwasniewski and wcandillon authored Aug 30, 2024
1 parent 4b73727 commit 96c1720
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
1 change: 0 additions & 1 deletion packages/webgpu/ios/SurfaceUtils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ + (void)configureSurface:(CALayer *)layer
size:(CGSize)size
contextId:(int)contextId {
std::shared_ptr<rnwgpu::RNWebGPUManager> manager = [WebGPUModule getManager];
CGFloat scaleFactor = [UIScreen mainScreen].scale;
void *nativeSurface = (__bridge void *)layer;
manager->surfacesRegistry.addSurface(contextId, nativeSurface, size.width,
size.height);
Expand Down
2 changes: 1 addition & 1 deletion packages/webgpu/react-native-wgpu.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Pod::Spec.new do |s|
s.license = package["license"]
s.authors = package["author"]

s.platforms = { :ios => min_ios_version_supported }
s.platforms = { :ios => min_ios_version_supported, :visionos => "1.0" }
s.source = { :git => "https://github.com/wcandillon/react-native-webgpu.git", :tag => "#{s.version}" }

s.source_files = [
Expand Down
16 changes: 14 additions & 2 deletions packages/webgpu/scripts/build/dawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ const PLATFORM_MAP: Record<string, string> = {
arm64_iphoneos: "OS64",
arm64_iphonesimulator: "SIMULATORARM64",
x86_64_iphonesimulator: "SIMULATOR64",
arm64_xros: "VISIONOS",
arm64_xrsimulator: "SIMULATOR_VISIONOS",
x86_64_xrsimulator: "SIMULATOR64_VISIONOS",
};

const android = {
Expand All @@ -45,8 +48,8 @@ const android = {

const ios = {
matrix: {
arm64: ["iphoneos", "iphonesimulator"],
x86_64: ["iphonesimulator"],
arm64: ["iphoneos", "iphonesimulator", "xros", "xrsimulator"],
x86_64: ["iphonesimulator", "xrsimulator"],
},
args: {
CMAKE_TOOLCHAIN_FILE: `${__dirname}/ios.toolchain.cmake`,
Expand Down Expand Up @@ -103,13 +106,22 @@ const ios = {
);
});

libs.forEach((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`,
);
});

libs.forEach((lib) => {
console.log(`Building ${lib}`);
$(`rm -rf ${projectRoot}/libs/ios/${lib}.xcframework`);
$(
"xcodebuild -create-xcframework " +
`-library ${projectRoot}/libs/ios/${lib}.a ` +
`-library ${projectRoot}/libs/ios/arm64_iphoneos/${lib}.a ` +
`-library ${projectRoot}/libs/ios/${lib}_visionos.a ` +
`-library ${projectRoot}/libs/ios/arm64_xros/${lib}.a ` +
` -output ${projectRoot}/libs/ios/${lib}.xcframework `,
);
});
Expand Down
21 changes: 15 additions & 6 deletions packages/webgpu/scripts/build/ios.toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@
# 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 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)
# 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)
# 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 Down Expand Up @@ -165,7 +166,7 @@ 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"
"VISIONOS" "SIMULATOR_VISIONOS" "VISIONOSCOMBINED", "SIMULATOR64_VISIONOS"
"MAC_CATALYST" "MAC_CATALYST_ARM64")

# Cache what generator is used
Expand Down Expand Up @@ -266,7 +267,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" OR PLATFORM STREQUAL "SIMULATOR_VISIONOS" OR PLATFORM STREQUAL "VISIONOSCOMBINED")
elseif(PLATFORM STREQUAL "VISIONOS")
# 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 Down Expand Up @@ -313,7 +314,7 @@ if(PLATFORM_INT STREQUAL "OS")
set(ARCHS armv7 armv7s arm64)
set(APPLE_TARGET_TRIPLE_INT arm-apple-ios${DEPLOYMENT_TARGET})
else()
set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-ios${DEPLOYMENT_TARGET})
set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-ios${DEPLOYMENT_TARGET})
endif()
elseif(PLATFORM_INT STREQUAL "OS64")
set(SDK_NAME iphoneos)
Expand Down Expand Up @@ -502,6 +503,14 @@ 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 @@ -517,7 +526,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*] "arm64")
set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=xrsimulator*] "x86_64 arm64")
else()
set(APPLE_TARGET_TRIPLE_INT ${ARCHS_SPLIT}-apple-xros${DEPLOYMENT_TARGET})
endif()
Expand Down Expand Up @@ -764,7 +773,7 @@ if(PLATFORM STREQUAL "MAC" OR PLATFORM STREQUAL "MAC_ARM64" OR PLATFORM STREQUAL
elseif(PLATFORM STREQUAL "MAC_CATALYST" OR PLATFORM STREQUAL "MAC_CATALYST_ARM64")
set(IOS ON CACHE BOOL "")
set(MACOS ON CACHE BOOL "")
elseif(PLATFORM STREQUAL "VISIONOS" OR PLATFORM STREQUAL "SIMULATOR_VISIONOS" OR PLATFORM STREQUAL "VISIONOSCOMBINED")
elseif(PLATFORM STREQUAL "VISIONOS" OR PLATFORM STREQUAL "SIMULATOR_VISIONOS" OR PLATFORM STREQUAL "VISIONOSCOMBINED" OR PLATFORM STREQUAL "SIMULATOR64_VISIONOS")
set(IOS OFF CACHE BOOL "")
set(VISIONOS ON CACHE BOOL "")
else()
Expand Down

0 comments on commit 96c1720

Please sign in to comment.