Skip to content

Commit

Permalink
feat: Add macOS to build matrix (#102)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: William Candillon <wcandillon@gmail.com>
  • Loading branch information
Saadnajmi and wcandillon authored Sep 6, 2024
1 parent 7c4f3d1 commit 13bdf17
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 32 deletions.
2 changes: 1 addition & 1 deletion apps/paper/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/webgpu/react-native-wgpu.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
59 changes: 35 additions & 24 deletions packages/webgpu/scripts/build/dawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const PLATFORM_MAP: Record<string, string> = {
arm64_xros: "VISIONOS",
arm64_xrsimulator: "SIMULATOR_VISIONOS",
x86_64_xrsimulator: "SIMULATOR64_VISIONOS",
universal_macosx: "MAC_UNIVERSAL",
};

const android = {
Expand All @@ -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");
Expand All @@ -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 `,
);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/webgpu/scripts/build/static_build.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions packages/webgpu/scripts/build/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
Expand Down Expand Up @@ -83,6 +84,7 @@ export const build = async (
args: Record<string, string>,
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)}`;
Expand All @@ -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}`);
Expand All @@ -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");
Expand Down

0 comments on commit 13bdf17

Please sign in to comment.