Skip to content

Commit

Permalink
chore(🍏): add macOS to build matrix (Shopify#2835)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: William Candillon <[email protected]>
  • Loading branch information
Saadnajmi and wcandillon authored Dec 29, 2024
1 parent 1aeb7e2 commit 4b821d3
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-skia.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@ jobs:
with:
name: skia-ios-xcframeworks
path: |
./packages/skia/libs/ios/*.xcframework
./packages/skia/libs/apple/*.xcframework
2 changes: 1 addition & 1 deletion apps/paper/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1957,7 +1957,7 @@ SPEC CHECKSUMS:
React-Mapbuffer: 1c08607305558666fd16678b85ef135e455d5c96
React-microtasksnativemodule: 87b8de96f937faefece8afd2cb3a518321b2ef99
react-native-safe-area-context: ab8f4a3d8180913bd78ae75dd599c94cce3d5e9a
react-native-skia: 1549ee5068efc5a004b84b2e0ba109c6234e2fde
react-native-skia: b9a7bb46f52a1b9a06b89d477ba6a8c1fe96a69d
react-native-slider: 97ce0bd921f40de79cead9754546d5e4e7ba44f8
react-native-wgpu: 8d0437a304318e0e3d6ccbfed2a39880f8eae4dd
React-nativeconfig: 57781b79e11d5af7573e6f77cbf1143b71802a6d
Expand Down
2 changes: 1 addition & 1 deletion packages/skia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"jestEnv.mjs",
"cpp/**/*.{h,cpp}",
"ios/**",
"libs/ios/*.xcframework/**",
"libs/apple/*.xcframework/**",
"react-native-skia.podspec",
"scripts/setup-canvaskit.js",
"dist/**"
Expand Down
18 changes: 9 additions & 9 deletions packages/skia/react-native-skia.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ preprocessor_defs = use_graphite ?
'$(inherited) SK_METAL=1 SK_GANESH=1 SK_IMAGE_READ_PIXELS_DISABLE_LEGACY_API=1'

# Define base frameworks
base_frameworks = ['libs/ios/libskia.xcframework',
'libs/ios/libsvg.xcframework',
'libs/ios/libskshaper.xcframework',
'libs/ios/libskparagraph.xcframework',
'libs/ios/libskunicode_core.xcframework',
'libs/ios/libskunicode_libgrapheme.xcframework',]
base_frameworks = ['libs/apple/libskia.xcframework',
'libs/apple/libsvg.xcframework',
'libs/apple/libskshaper.xcframework',
'libs/apple/libskparagraph.xcframework',
'libs/apple/libskunicode_core.xcframework',
'libs/apple/libskunicode_libgrapheme.xcframework',]

# Add Graphite frameworks if enabled
graphite_frameworks = [
'libs/ios/libdawn_native_static.xcframework',
'libs/ios/libdawn_platform_static.xcframework',
'libs/ios/libdawn_proc_static.xcframework'
'libs/apple/libdawn_native_static.xcframework',
'libs/apple/libdawn_platform_static.xcframework',
'libs/apple/libdawn_proc_static.xcframework'
]

Pod::Spec.new do |s|
Expand Down
15 changes: 11 additions & 4 deletions packages/skia/scripts/build-skia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const configurePlatform = async (
"";

// eslint-disable-next-line max-len
const command = `${commandline} ${options} ${targetOptions} --script-executable=python3 --args='target_os="${platformName}" target_cpu="${target.cpu}" ${common}${args}${targetArgs}'`;
const command = `${commandline} ${options} ${targetOptions} --script-executable=python3 --args='target_os="${target.platform}" target_cpu="${target.cpu}" ${common}${args}${targetArgs}'`;
await runAsync(command, "⚙️");
return true;
} else {
Expand Down Expand Up @@ -117,8 +117,8 @@ export const copyLib = (
};

const buildXCFrameworks = () => {
const os: PlatformName = "ios";
const { outputNames } = configurations.ios;
const os: PlatformName = "apple";
const { outputNames } = configurations.apple;
process.chdir(SkiaSrc);
outputNames.forEach((name) => {
console.log("Building XCFramework for " + name);
Expand All @@ -127,14 +127,21 @@ const buildXCFrameworks = () => {
$(`rm -rf ${OutFolder}/${os}/iphonesimulator/${name}`);
$(
// eslint-disable-next-line max-len
`lipo -create ${OutFolder}/${os}/x64/${name} ${OutFolder}/${os}/arm64-iphonesimulator/${name} -output ${OutFolder}/${os}/iphonesimulator/${name}`
`lipo -create ${OutFolder}/${os}/x64-iphonesimulator/${name} ${OutFolder}/${os}/arm64-iphonesimulator/${name} -output ${OutFolder}/${os}/iphonesimulator/${name}`
);
$(`mkdir -p ${OutFolder}/${os}/macosx`);
$(`rm -rf ${OutFolder}/${os}/macosx/${name}`);
$(
// eslint-disable-next-line max-len
`lipo -create ${OutFolder}/${os}/x64-macosx/${name} ${OutFolder}/${os}/arm64-macosx/${name} -output ${OutFolder}/${os}/macosx/${name}`
);
const [lib] = name.split(".");
const dstPath = `${PackageRoot}/libs/${os}/${lib}.xcframework`;
$(
"xcodebuild -create-xcframework " +
`-library ${prefix}/arm64-iphoneos/${name} ` +
`-library ${prefix}/iphonesimulator/${name} ` +
`-library ${prefix}/macosx/${name} ` +
` -output ${dstPath}`
);
});
Expand Down
42 changes: 30 additions & 12 deletions packages/skia/scripts/skia-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const NoParagraphArgs = [

// To build the paragraph API:
// On Android: we use system ICU
// On iOS: we use libgrapheme
// On Apple: we use libgrapheme
const CommonParagraphArgs = [
["skia_enable_skparagraph", true],
["skia_use_system_icu", false],
Expand All @@ -36,7 +36,7 @@ const ParagraphArgsAndroid = BUILD_WITH_PARAGRAPH
]
: NoParagraphArgs;

const ParagraphArgsIOS = BUILD_WITH_PARAGRAPH
const ParagraphArgsApple = BUILD_WITH_PARAGRAPH
? [
...CommonParagraphArgs,
["skia_use_icu", false],
Expand All @@ -45,7 +45,7 @@ const ParagraphArgsIOS = BUILD_WITH_PARAGRAPH
]
: NoParagraphArgs;

const ParagraphIOS = BUILD_WITH_PARAGRAPH
const ParagraphApple = BUILD_WITH_PARAGRAPH
? ["libskparagraph.a", "libskunicode_core.a", "libskunicode_libgrapheme.a"]
: [];

Expand Down Expand Up @@ -81,12 +81,13 @@ export const commonArgs = [
["skia_use_dawn", GRAPHITE],
];

export type PlatformName = "ios" | "android";
export type PlatformName = "apple" | "android";

type Arg = (string | boolean | number)[];
export type Target = {
args?: Arg[];
cpu: string;
platform?: string;
output?: string;
options?: Arg[];
};
Expand All @@ -105,18 +106,22 @@ export const configurations = {
android: {
targets: {
arm: {
platform: "android",
cpu: "arm",
output: "armeabi-v7a",
},
arm64: {
platform: "android",
cpu: "arm64",
output: "arm64-v8a",
},
x86: {
platform: "android",
cpu: "x86",
output: "x86",
},
x64: {
platform: "android",
cpu: "x64",
output: "x86_64",
},
Expand Down Expand Up @@ -145,10 +150,11 @@ export const configurations = {
...DawnOutput,
],
},
ios: {
apple: {
targets: {
"arm64-iphoneos": {
cpu: "arm64",
platform: "ios",
args: [
["ios_min_target", iosMinTarget],
["extra_cflags", '["-target", "arm64-apple-ios"]'],
Expand All @@ -158,6 +164,7 @@ export const configurations = {
},
"arm64-iphonesimulator": {
cpu: "arm64",
platform: "ios",
args: [
["ios_min_target", iosMinTarget],
["extra_cflags", '["-target", "arm64-apple-ios-simulator"]'],
Expand All @@ -166,30 +173,41 @@ export const configurations = {
["ios_use_simulator", true],
],
},
x64: {
"x64-iphonesimulator": {
cpu: "x64",
platform: "ios",
args: [
["ios_min_target", iosMinTarget],
["extra_cflags", '["-target", "arm64-apple-ios-simulator"]'],
["extra_asmflags", '["-target", "arm64-apple-ios-simulator"]'],
["extra_ldflags", '["-target", "arm64-apple-ios-simulator"]'],
["extra_cflags", '["-target", "x64-apple-ios-simulator"]'],
["extra_asmflags", '["-target", "x64-apple-ios-simulator"]'],
["extra_ldflags", '["-target", "x64-apple-ios-simulator"]'],
],
},
"arm64-macosx": {
platformGroup: "macosx",
cpu: "arm64",
platform: "mac",
},
"x64-macosx": {
platformGroup: "macosx",
cpu: "x64",
platform: "mac",
},
},
args: [
["skia_use_metal", true],
["cc", '"clang"'],
["cxx", '"clang++"'],
...ParagraphArgsIOS,
...ParagraphArgsApple,
],
outputRoot: "libs/ios",
outputRoot: "libs/apple",
outputNames: [
"libskia.a",
"libskshaper.a",
"libsvg.a",
"libskottie.a",
"libsksg.a",
...ParagraphIOS,
...ParagraphApple,
...DawnOutput,
],
},
Expand Down

0 comments on commit 4b821d3

Please sign in to comment.