Repository navigation
Expand file tree
/
Copy pathbuild_runtime.ts
More file actions
84 lines (68 loc) · 2.28 KB
/
Copy pathbuild_runtime.ts
File metadata and controls
84 lines (68 loc) · 2.28 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
import { $ } from "./deps.ts";
$.setPrintCommand(true);
// CWD is scripts/
Deno.chdir(new URL("./", import.meta.url));
// Process arguments and environment variables
const VALID_PLATFORMS = [
"macos",
"ios",
"ios-sim",
"ios-universal",
];
const targetPlatform = Deno.args[0] ?? "macos";
if (!VALID_PLATFORMS.includes(targetPlatform)) {
throw new Error(
`Invalid platform: ${targetPlatform}. Valid platforms are: ${
VALID_PLATFORMS.join(
", ",
)
}`,
);
}
const buildConfig = Deno.args.includes("debug") ? "Debug" : "Release";
// Ensure we have a build directory
await Deno.mkdir(`../runtime/build`).catch(() => {});
async function ensureTargetDir(targetPlatform: string) {
// Clean any previous target specific build
// await Deno.remove(`../packages/${platformDir}/build/${targetPlatform}`, { recursive: true }).catch(
// () => {},
// );
// Create a new target specific build directory
await Deno.mkdir(`../runtime/build/${targetPlatform}`).catch(() => {});
}
async function build(targetPlatform: string) {
await ensureTargetDir(targetPlatform);
// Generate the build files
await $`cmake -S=../runtime -B=../runtime/build/${targetPlatform} -GXcode -DTARGET_PLATFORM=${targetPlatform} -DCMAKE_EXPORT_COMPILE_COMMANDS=ON`;
// Build the project
await $`cmake --build ../runtime/build/${targetPlatform} --config ${buildConfig}`;
}
const TARGET_RELEASE_FOLDERS: Record<string, string> = {
"ios": `${buildConfig}-iphoneos`,
"ios-sim": `${buildConfig}-iphonesimulator`,
};
if (import.meta.main) {
if (targetPlatform === "ios-universal") {
await ensureTargetDir(targetPlatform);
const targets = ["ios", "ios-sim"];
for (const target of targets) {
await build(target);
}
await Deno.remove(
`../runtime/build/${targetPlatform}/NativeScriptRuntime.xcframework`,
{ recursive: true },
).catch(() => {});
await $`xcodebuild -create-xcframework ${
targets.map((
targetPlatform,
) => [
`-framework`,
`../runtime/build/${targetPlatform}/${
TARGET_RELEASE_FOLDERS[targetPlatform]
}/NativeScriptRuntime.framework`,
]).flat()
} -output ../runtime/build/${targetPlatform}/NativeScriptRuntime.xcframework`;
} else {
await build(targetPlatform);
}
}