-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild_xcframework.mts
More file actions
124 lines (106 loc) · 3.65 KB
/
build_xcframework.mts
File metadata and controls
124 lines (106 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import path from "node:path";
import process from "node:process";
import yargsParser from "yargs-parser";
import { createXCframework } from "react-native-node-api";
main();
/**
* Builds an XCFramework in the style that `react-native-node-api` expects,
* following the [prebuilds standard](https://github.com/callstackincubator/react-native-node-api/blob/9b231c14459b62d7df33360f930a00343d8c46e6/docs/PREBUILDS.md).
*
* This is really just an XCFramework renamed with a `.node` extension,
* containing an extra file named `react-native-api-module`. Once `cmake-rn`
* supports it, we may be able to replace this whole script with a simple
* `cmake-rn` call.
*/
async function main() {
const __dirname = import.meta.dirname;
if (!__dirname) {
throw new Error("Expected import.meta.dirname to be truthy.");
}
const monorepoRoot = path.resolve(__dirname, "..");
// Args are designed to match the names of the args from cmake we're
// interested in.
const args = yargsParser(process.argv.slice(2), {
configuration: {
"short-option-groups": false,
},
string: ["output", "framework", "debug-symbols"],
array: ["framework", "debug-symbols"],
boolean: ["help"],
alias: {
h: "help",
},
default: {
help: false,
},
});
const {
output,
framework: frameworks = new Array<string>(),
"debug-symbols": debugSymbols = new Array<string>(),
help,
} = args;
const helpText = `
Typical usage:
$ deno run -A ./scripts/build_xcframework.mts --output packages/ios/build/Release/NativeScript.apple.node -framework dist/intermediates/ios/RelWithDebInfo-iphoneos/NativeScript.framework -debug-symbols dist/intermediates/ios/RelWithDebInfo-iphoneos/NativeScript.framework.dSYM
$ deno run -A ./scripts/build_xcframework.mts --output packages/macos/build/Release/NativeScript.apple.node -framework dist/intermediates/macos/RelWithDebInfo/NativeScript.framework -debug-symbols dist/intermediates/macos/RelWithDebInfo/NativeScript.framework.dSYM
`.trim();
if (help) {
console.log(helpText);
process.exit(0);
}
if (!output) {
console.log(
`Please specify the output directory by passing the \`--output\` arg.\n\n${helpText}`
);
process.exit(1);
}
if (!isStringArray(frameworks) || !isStringArray(debugSymbols)) {
console.log(
`Expected -framework and -debug-symbols to be parsed as arrays.\n\n${helpText}`
);
process.exit(1);
}
if (!frameworks?.length) {
console.log(
`Please specify at least one framework to bundle into the xcframework by passing the \`-framework\` arg one or more times.\n\n${helpText}`
);
process.exit(1);
}
const outputPath = path.resolve(monorepoRoot, output);
const frameworkPaths = frameworks.map((framework) =>
path.resolve(monorepoRoot, framework)
);
// TODO: Pass this to the createXCFramework() options, once supported.
const _dsymPaths =
debugSymbols?.map((dsym) => path.resolve(monorepoRoot, dsym)) ?? [];
try {
await createXCframework({
outputPath,
frameworkPaths,
// dsymPaths,
autoLink: true,
});
} catch (error) {
const errorMessage = error instanceof Error ? error.message : "<unknown>";
console.error(`Failed to assemble XCFramework: ${errorMessage}`, error);
process.exit(1);
}
console.log(
`\x1b[32m✔\x1b[0m XCFramework assembled into \x1b[2m${path.relative(
monorepoRoot,
outputPath
)}\x1b[22m`
);
}
function isStringArray(value: unknown): value is Array<string> {
if (!Array.isArray(value)) {
return false;
}
for (const element of value) {
if (typeof element !== "string") {
return false;
}
}
return true;
}