Skip to content

Commit b7ae6fe

Browse files
committed
introduce yargs-parser to be compatible with xcodebuild -create-xcframework
1 parent 5422566 commit b7ae6fe

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
@@ -146,46 +146,33 @@ cmake_build macos-cli
146146

147147
fi
148148

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

168155
if $BUILD_SIMULATOR; then
169-
FRAMEWORK="$DIST/intermediates/ios-sim/$CONFIG_BUILD-iphonesimulator/NativeScript.framework"
170-
XCFRAMEWORKS+=( "$FRAMEWORK_FLAG" "$FRAMEWORK" "$DSYM_FLAG" "$FRAMEWORK.dSYM" )
156+
XCFRAMEWORKS+=( -framework "$DIST/intermediates/ios-sim/$CONFIG_BUILD-iphonesimulator/NativeScript.framework"
157+
-debug-symbols "$DIST/intermediates/ios-sim/$CONFIG_BUILD-iphonesimulator/NativeScript.framework.dSYM" )
171158
fi
172159

173160
if $BUILD_IPHONE; then
174-
FRAMEWORK="$DIST/intermediates/ios/$CONFIG_BUILD-iphoneos/NativeScript.framework"
175-
XCFRAMEWORKS+=( "$FRAMEWORK_FLAG" "$FRAMEWORK" "$DSYM_FLAG" "$FRAMEWORK.dSYM" )
161+
XCFRAMEWORKS+=( -framework "$DIST/intermediates/ios/$CONFIG_BUILD-iphoneos/NativeScript.framework"
162+
-debug-symbols "$DIST/intermediates/ios/$CONFIG_BUILD-iphoneos/NativeScript.framework.dSYM" )
176163
fi
177164

178165
if $BUILD_MACOS; then
179-
FRAMEWORK="$DIST/intermediates/macos/$CONFIG_BUILD/NativeScript.framework"
180-
XCFRAMEWORKS+=( "$FRAMEWORK_FLAG" "$FRAMEWORK" "$DSYM_FLAG" "$FRAMEWORK.dSYM" )
166+
XCFRAMEWORKS+=( -framework "$DIST/intermediates/macos/$CONFIG_BUILD/NativeScript.framework"
167+
-debug-symbols "$DIST/intermediates/macos/$CONFIG_BUILD/NativeScript.framework.dSYM" )
181168
fi
182169

183170
if $BUILD_VISION; then
184-
FRAMEWORK="$DIST/intermediates/visionos/$CONFIG_BUILD-xros/NativeScript.framework"
185-
XCFRAMEWORKS+=( "$FRAMEWORK_FLAG" "$FRAMEWORK" "$DSYM_FLAG" "$FRAMEWORK.dSYM" )
171+
XCFRAMEWORKS+=( -framework "$DIST/intermediates/visionos/$CONFIG_BUILD-xros/NativeScript.framework"
172+
-debug-symbols "$DIST/intermediates/visionos/$CONFIG_BUILD-xros/NativeScript.framework.dSYM" )
186173

187-
FRAMEWORK="$DIST/intermediates/visionos-sim/$CONFIG_BUILD-xros/NativeScript.framework"
188-
XCFRAMEWORKS+=( "$FRAMEWORK_FLAG" "$FRAMEWORK" "$DSYM_FLAG" "$FRAMEWORK.dSYM" )
174+
XCFRAMEWORKS+=( -framework "$DIST/intermediates/visionos-sim/$CONFIG_BUILD-xros/NativeScript.framework"
175+
-debug-symbols "$DIST/intermediates/visionos-sim/$CONFIG_BUILD-xros/NativeScript.framework.dSYM" )
189176
fi
190177

191178
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)