Skip to content

Commit

Permalink
Support build for tvOS
Browse files Browse the repository at this point in the history
  • Loading branch information
jhen0409 committed Nov 7, 2023
1 parent a55310a commit 6079eca
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"scripts": {
"build-skia-ios-framework": "ts-node ./scripts/build-skia-ios-framework.ts",
"build-skia-ios": "ts-node ./scripts/build-skia-ios.ts && yarn build-skia-ios-framework",
"build-skia-ios": "ts-node ./scripts/build-skia-ios.ts && ts-node ./scripts/build-skia-tvos.ts && yarn build-skia-ios-framework",
"build-skia-android": "ts-node ./scripts/build-skia-android.ts",
"build-skia": "yarn build-skia-ios && yarn build-skia-android",
"clean-skia": "yarn rimraf ./package/libs && yarn rimraf ./externals/skia/out",
Expand Down
10 changes: 9 additions & 1 deletion package/react-native-skia.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Pod::Spec.new do |s|
# optional - use expanded license entry instead:
# s.license = { :type => "MIT", :file => "LICENSE" }
s.authors = { "Your Name" => "[email protected]" }
s.platforms = { :ios => "12.0" }
s.platforms = { :ios => "12.0", :tvos => "12.0" }
s.source = { :git => "https://github.com/shopify/react-native-skia/react-native-skia.git", :tag => "#{s.version}" }

s.requires_arc = true
Expand All @@ -38,6 +38,14 @@ Pod::Spec.new do |s|
'libs/ios/libskunicode.xcframework',
]

s.tvos.vendored_frameworks = [
'libs/ios/libskia.xcframework',
'libs/ios/libsvg.xcframework',
'libs/ios/libskshaper.xcframework',
'libs/ios/libskparagraph.xcframework',
'libs/ios/libskunicode.xcframework',
]

# All iOS cpp/h files
s.source_files = [
"ios/**/*.{h,c,cc,cpp,m,mm,swift}",
Expand Down
13 changes: 12 additions & 1 deletion scripts/build-skia-ios-framework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { executeCmdSync, checkFileExists } from "./utils";
* This build script is run after the Skia Binaries are built.
*/

console.log("Building iOS Fat Libraries from Skia Binaries");
console.log("Building iOS / tvOS Fat Libraries from Skia Binaries");
console.log("");

console.log("Checking prerequisites...");
Expand All @@ -27,6 +27,15 @@ Object.keys(configurations.ios.targets).forEach((targetKey) => {
);
});
});
Object.keys(configurations.tvos.targets).forEach((targetKey) => {
configurations.tvos.outputNames.forEach((out) => {
checkFileExists(
`package/libs/ios/${targetKey}/${out}`,
`package/libs/ios/${targetKey}/${out}`,
`package/libs/ios/${targetKey}/${out} not found`
);
});
});

console.log("");
console.log("Prerequisites met. Starting build.");
Expand All @@ -53,6 +62,8 @@ configurations.ios.outputNames.forEach((out) => {
"xcodebuild -create-xcframework " +
`-library ./package/libs/ios/${libName}.a ` +
`-library ./package/libs/ios/arm64-iphoneos/${libName}.a ` +
`-library ./package/libs/ios/arm64-tvsimulator/${libName}.a ` +
`-library ./package/libs/ios/arm64-tvos/${libName}.a ` +
` -output ./package/libs/ios/${libName}.xcframework `
);
});
Expand Down
17 changes: 17 additions & 0 deletions scripts/build-skia-tvos.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { configurations } from "./skia-configuration";
import { executeCmd } from "./utils";

const configuration = configurations.tvos;

console.log("Building skia for tvOS...");
let command = "";

Object.keys(configuration.targets).forEach((targetKey) => {
command +=
(command !== "" ? " && " : "") +
`yarn ts-node ./scripts/build-skia.ts tvos ${targetKey}`;
});

executeCmd(command, "tvOS", () => {
console.log(`Done building skia for tvOS.`);
});
37 changes: 36 additions & 1 deletion scripts/skia-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const commonArgs = [
["is_component_build", false],
];

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

type Arg = (string | boolean | number)[];
export type Target = {
Expand Down Expand Up @@ -157,4 +157,39 @@ export const configurations: Configuration = {
...ParagraphOutputs,
],
},
tvos: {
targets: {
"arm64-tvos": {
cpu: "arm64",
args: [
["extra_cflags", '["-target", "arm64-apple-tvos", "-mappletvos-version-min=13.0"]'],
["extra_asmflags", '["-target", "arm64-apple-tvos", "-mappletvos-version-min=13.0"]'],
["extra_ldflags", '["-target", "arm64-apple-tvos", "-mappletvos-version-min=13.0"]'],
],
},
"arm64-tvsimulator": {
cpu: "arm64",
args: [
["extra_cflags", '["-target", "arm64-apple-tvos-simulator", "-mappletvos-version-min=13.0"]'],
["extra_asmflags", '["-target", "arm64-apple-tvos-simulator", "-mappletvos-version-min=13.0"]'],
["extra_ldflags", '["-target", "arm64-apple-tvos-simulator", "-mappletvos-version-min=13.0"]'],
],
},
},
args: [
["skia_use_metal", true],
["cc", '"clang"'],
["cxx", '"clang++"'],
...ParagraphArgsIOS
],
outputRoot: "package/libs/ios",
outputNames: [
"libskia.a",
"libskshaper.a",
"libsvg.a",
"libskottie.a",
"libsksg.a",
...ParagraphOutputs,
],
},
};

0 comments on commit 6079eca

Please sign in to comment.