Skip to content

Commit 7c7a820

Browse files
committed
introduce yargs-parser to be compatible with xcodebuild -create-xcframework
1 parent 6623068 commit 7c7a820

File tree

3 files changed

+54
-54
lines changed

3 files changed

+54
-54
lines changed

build_nativescript.sh

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -148,46 +148,33 @@ cmake_build macos-cli
148148

149149
fi
150150

151-
# Due to inconvenient design choices on both sides, we have to choose between
152-
# either long flags or short flags based on whether we're calling
153-
# `xcodebuild -create-xcframework` or `scripts/build_xcframework.mts`.
154-
if [[ "$TARGET_ENGINE" == "none" ]]; then
155-
# Node.js parseArgs() supports short flags, but only if they're single-letter.
156-
FRAMEWORK_FLAG="--framework"
157-
DSYM_FLAG="--debug-symbols"
158-
else
159-
# xcodebuild doesn't implement any single-letter short flags like -f and -d.
160-
FRAMEWORK_FLAG="-framework"
161-
DSYM_FLAG="-debug-symbols"
162-
fi
163-
164151
XCFRAMEWORKS=()
165152
if $BUILD_CATALYST; then
166-
FRAMEWORK="$DIST/intermediates/catalyst/$CONFIG_BUILD-maccatalyst/NativeScript.framework"
167-
XCFRAMEWORKS+=( "$FRAMEWORK_FLAG" "$FRAMEWORK" "$DSYM_FLAG" "$FRAMEWORK.dSYM" )
153+
XCFRAMEWORKS+=( -framework "$DIST/intermediates/catalyst/$CONFIG_BUILD-maccatalyst/NativeScript.framework"
154+
-debug-symbols "$DIST/intermediates/catalyst/$CONFIG_BUILD-maccatalyst/NativeScript.framework.dSYM" )
168155
fi
169156

170157
if $BUILD_SIMULATOR; then
171-
FRAMEWORK="$DIST/intermediates/ios-sim/$CONFIG_BUILD-iphonesimulator/NativeScript.framework"
172-
XCFRAMEWORKS+=( "$FRAMEWORK_FLAG" "$FRAMEWORK" "$DSYM_FLAG" "$FRAMEWORK.dSYM" )
158+
XCFRAMEWORKS+=( -framework "$DIST/intermediates/ios-sim/$CONFIG_BUILD-iphonesimulator/NativeScript.framework"
159+
-debug-symbols "$DIST/intermediates/ios-sim/$CONFIG_BUILD-iphonesimulator/NativeScript.framework.dSYM" )
173160
fi
174161

175162
if $BUILD_IPHONE; then
176-
FRAMEWORK="$DIST/intermediates/ios/$CONFIG_BUILD-iphoneos/NativeScript.framework"
177-
XCFRAMEWORKS+=( "$FRAMEWORK_FLAG" "$FRAMEWORK" "$DSYM_FLAG" "$FRAMEWORK.dSYM" )
163+
XCFRAMEWORKS+=( -framework "$DIST/intermediates/ios/$CONFIG_BUILD-iphoneos/NativeScript.framework"
164+
-debug-symbols "$DIST/intermediates/ios/$CONFIG_BUILD-iphoneos/NativeScript.framework.dSYM" )
178165
fi
179166

180167
if $BUILD_MACOS; then
181-
FRAMEWORK="$DIST/intermediates/macos/$CONFIG_BUILD/NativeScript.framework"
182-
XCFRAMEWORKS+=( "$FRAMEWORK_FLAG" "$FRAMEWORK" "$DSYM_FLAG" "$FRAMEWORK.dSYM" )
168+
XCFRAMEWORKS+=( -framework "$DIST/intermediates/macos/$CONFIG_BUILD/NativeScript.framework"
169+
-debug-symbols "$DIST/intermediates/macos/$CONFIG_BUILD/NativeScript.framework.dSYM" )
183170
fi
184171

185172
if $BUILD_VISION; then
186-
FRAMEWORK="$DIST/intermediates/visionos/$CONFIG_BUILD-xros/NativeScript.framework"
187-
XCFRAMEWORKS+=( "$FRAMEWORK_FLAG" "$FRAMEWORK" "$DSYM_FLAG" "$FRAMEWORK.dSYM" )
173+
XCFRAMEWORKS+=( -framework "$DIST/intermediates/visionos/$CONFIG_BUILD-xros/NativeScript.framework"
174+
-debug-symbols "$DIST/intermediates/visionos/$CONFIG_BUILD-xros/NativeScript.framework.dSYM" )
188175

189-
FRAMEWORK="$DIST/intermediates/visionos-sim/$CONFIG_BUILD-xros/NativeScript.framework"
190-
XCFRAMEWORKS+=( "$FRAMEWORK_FLAG" "$FRAMEWORK" "$DSYM_FLAG" "$FRAMEWORK.dSYM" )
176+
XCFRAMEWORKS+=( -framework "$DIST/intermediates/visionos-sim/$CONFIG_BUILD-xros/NativeScript.framework"
177+
-debug-symbols "$DIST/intermediates/visionos-sim/$CONFIG_BUILD-xros/NativeScript.framework.dSYM" )
191178
fi
192179

193180
if [[ -n "${XCFRAMEWORKS[@]}" ]]; then

scripts/build_xcframework.mts

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from "node:path";
22
import process from "node:process";
3-
import { parseArgs } from "node:util";
3+
import yargsParser from "yargs-parser";
44
import { createXCframework } from "react-native-node-api";
55

66
main();
@@ -13,41 +13,32 @@ async function main() {
1313

1414
const monorepoRoot = path.resolve(__dirname, "..");
1515

16-
const args = parseArgs({
17-
args: process.argv.slice(2),
18-
options: {
19-
output: {
20-
type: "string",
21-
},
22-
framework: {
23-
multiple: true,
24-
type: "string",
25-
},
26-
"debug-symbols": {
27-
multiple: true,
28-
type: "string",
29-
},
30-
help: {
31-
short: "h",
32-
type: "boolean",
33-
default: false,
34-
},
16+
const args = yargsParser(process.argv.slice(2), {
17+
configuration: {
18+
"short-option-groups": false,
19+
},
20+
string: ["output", "framework", "debug-symbols"],
21+
array: ["framework", "debug-symbols"],
22+
boolean: ["help"],
23+
alias: {
24+
h: "help",
25+
},
26+
default: {
27+
help: false,
3528
},
3629
});
3730

3831
const {
39-
values: {
40-
output,
41-
framework: frameworks,
42-
"debug-symbols": debugSymbols,
43-
help,
44-
},
32+
output,
33+
framework: frameworks = new Array<string>(),
34+
"debug-symbols": debugSymbols = new Array<string>(),
35+
help,
4536
} = args;
4637

4738
const helpText = `
4839
Typical usage:
4940
50-
$ deno run -A ./scripts/build_xcframework.ts --output packages/ios/build/Release/NativeScript.apple.node --framework dist/intermediates/ios/RelWithDebInfo-iphoneos/NativeScript.framework
41+
$ 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
5142
`.trim();
5243

5344
if (help) {
@@ -62,9 +53,16 @@ $ deno run -A ./scripts/build_xcframework.ts --output packages/ios/build/Release
6253
process.exit(1);
6354
}
6455

56+
if (!isStringArray(frameworks) || !isStringArray(debugSymbols)) {
57+
console.log(
58+
`Expected -framework and -debug-symbols to be parsed as arrays.\n\n${helpText}`
59+
);
60+
process.exit(1);
61+
}
62+
6563
if (!frameworks?.length) {
6664
console.log(
67-
`Please specify at least one framework to bundle into the xcframework by passing the \`--framework\` arg one or more times.\n\n${helpText}`
65+
`Please specify at least one framework to bundle into the xcframework by passing the \`-framework\` arg one or more times.\n\n${helpText}`
6866
);
6967
process.exit(1);
7068
}
@@ -97,3 +95,17 @@ $ deno run -A ./scripts/build_xcframework.ts --output packages/ios/build/Release
9795
)}\x1b[22m`
9896
);
9997
}
98+
99+
function isStringArray(value: unknown): value is Array<string> {
100+
if (!Array.isArray(value)) {
101+
return false;
102+
}
103+
104+
for (const element of value) {
105+
if (typeof element !== "string") {
106+
return false;
107+
}
108+
}
109+
110+
return true;
111+
}

scripts/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"type": "commonjs",
1212
"description": "",
1313
"dependencies": {
14-
"@nativescript/core": "^8.8.6"
14+
"@nativescript/core": "^8.8.6",
15+
"yargs-parser": "^22.0.0"
1516
},
1617
"devDependencies": {
1718
"react-native-node-api": "^0.3.2"

0 commit comments

Comments
 (0)