-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtargets.ts
More file actions
102 lines (92 loc) · 3.07 KB
/
targets.ts
File metadata and controls
102 lines (92 loc) · 3.07 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
import { chalk, UsageError } from "@react-native-node-api/cli-utils";
import { getInstalledTargets } from "./rustup.js";
export const ANDROID_TARGETS = [
"aarch64-linux-android",
"armv7-linux-androideabi",
"i686-linux-android",
"x86_64-linux-android",
// "arm-linux-androideabi",
// "thumbv7neon-linux-androideabi",
] as const;
export type AndroidTargetName = (typeof ANDROID_TARGETS)[number];
// TODO: Consider calling out to rustup to generate this list or just use @napi-rs/triples
export const APPLE_TARGETS = [
"aarch64-apple-darwin",
"x86_64-apple-darwin",
"aarch64-apple-ios",
"aarch64-apple-ios-sim",
// "aarch64-apple-ios-macabi", // Catalyst
// "x86_64-apple-ios",
// "x86_64-apple-ios-macabi", // Catalyst
// TODO: Re-enabled these when we know how to install them 🙈
/*
"aarch64-apple-tvos",
"aarch64-apple-tvos-sim",
*/
"aarch64-apple-visionos",
"aarch64-apple-visionos-sim",
// "aarch64-apple-watchos",
// "aarch64-apple-watchos-sim",
// "arm64_32-apple-watchos",
// "arm64e-apple-darwin",
// "arm64e-apple-ios",
// "arm64e-apple-tvos",
// "armv7k-apple-watchos",
// "armv7s-apple-ios",
// "i386-apple-ios",
// "i686-apple-darwin",
// "x86_64-apple-tvos",
// "x86_64-apple-watchos-sim",
// "x86_64h-apple-darwin",
] as const;
export type AppleTargetName = (typeof APPLE_TARGETS)[number];
export const ALL_TARGETS = [...ANDROID_TARGETS, ...APPLE_TARGETS] as const;
export type TargetName = (typeof ALL_TARGETS)[number];
/**
* Ensure the targets are installed into the Rust toolchain
* We do this up-front because the error message and fix is very unclear from the failure when missing.
*/
export function ensureInstalledTargets(expectedTargets: Set<TargetName>) {
const installedTargets = getInstalledTargets();
const missingTargets = new Set([
...[...expectedTargets].filter((target) => !installedTargets.has(target)),
]);
if (missingTargets.size > 0) {
// TODO: Ask the user if they want to run this
throw new UsageError(
`You're missing ${
missingTargets.size
} targets - to fix this, run:\n\n${chalk.italic(
`rustup target add ${[...missingTargets].join(" ")}`,
)}`,
);
}
}
export function isAndroidTarget(
target: TargetName,
): target is AndroidTargetName {
return ANDROID_TARGETS.includes(target as (typeof ANDROID_TARGETS)[number]);
}
export function isAppleTarget(target: TargetName): target is AppleTargetName {
return APPLE_TARGETS.includes(target as (typeof APPLE_TARGETS)[number]);
}
export function filterTargetsByPlatform(
targets: Set<TargetName>,
platform: "android",
): AndroidTargetName[];
export function filterTargetsByPlatform(
targets: Set<TargetName>,
platform: "apple",
): AppleTargetName[];
export function filterTargetsByPlatform(
targets: Set<TargetName>,
platform: "apple" | "android",
) {
if (platform === "android") {
return [...targets].filter(isAndroidTarget);
} else if (platform === "apple") {
return [...targets].filter(isAppleTarget);
} else {
throw new Error(`Unexpected platform ${platform as string}`);
}
}