Skip to content

Commit 07ea9dc

Browse files
authored
Add x86_64 and universal simulator slices (#288)
* Delete unused APPLE_ARCHITECTURES from host package * Add x86_64 and universal simulator triplets to host * Provide per-triplet constants * Drive-by delete unused createPlistContent * Declare support for relevant triplets * Support multiple purposes when picking default triplets * Add changeset * Incorporate review * Update Ferric to link against the universal iOS simulator framework * Update CI to build universal ios sim framework * Renamed purpose to mode and values to be more semantic * Assert triplet platform is supported by host
1 parent 7536c6c commit 07ea9dc

File tree

9 files changed

+124
-57
lines changed

9 files changed

+124
-57
lines changed

.changeset/bright-parts-roll.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"cmake-rn": patch
3+
"react-native-node-api": patch
4+
---
5+
6+
Add x86_64 and universal simulator triplets

.github/workflows/check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ jobs:
9898
- run: npm ci
9999
- run: npm run bootstrap
100100
env:
101-
CMAKE_RN_TRIPLETS: arm64-apple-ios-sim
101+
CMAKE_RN_TRIPLETS: arm64;x86_64-apple-ios-sim
102102
FERRIC_TARGETS: aarch64-apple-ios-sim
103103
- run: npm run pod-install
104104
working-directory: apps/test-app

packages/cmake-rn/src/cli.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ program = program.action(
187187
for (const platform of Object.values(platforms)) {
188188
// Forcing the types a bit here, since the platform id option is dynamically added
189189
if ((baseOptions as Record<string, unknown>)[platform.id]) {
190-
for (const triplet of platform.triplets) {
190+
for (const triplet of await platform.defaultTriplets("all")) {
191191
triplets.add(triplet);
192192
}
193193
}
@@ -196,7 +196,9 @@ program = program.action(
196196
if (triplets.size === 0) {
197197
for (const platform of Object.values(platforms)) {
198198
if (platform.isSupportedByHost()) {
199-
for (const triplet of await platform.defaultTriplets()) {
199+
for (const triplet of await platform.defaultTriplets(
200+
"current-development",
201+
)) {
200202
triplets.add(triplet);
201203
}
202204
}
@@ -217,6 +219,11 @@ program = program.action(
217219
const tripletContexts = [...triplets].map((triplet) => {
218220
const platform = findPlatformForTriplet(triplet);
219221

222+
assert(
223+
platform.isSupportedByHost(),
224+
`Triplet '${triplet}' cannot be built, as the '${platform.name}' platform is not supported on a '${process.platform}' host.`,
225+
);
226+
220227
return {
221228
triplet,
222229
platform,

packages/cmake-rn/src/platforms/android.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,21 @@ export const platform: Platform<Triplet[], AndroidOpts> = {
100100
"i686-linux-android",
101101
"x86_64-linux-android",
102102
],
103-
defaultTriplets() {
104-
if (process.arch === "arm64") {
105-
return ["aarch64-linux-android"];
106-
} else if (process.arch === "x64") {
107-
return ["x86_64-linux-android"];
103+
defaultTriplets(mode) {
104+
if (mode === "all") {
105+
return [...this.triplets];
106+
} else if (mode === "current-development") {
107+
// We're applying a heuristic to determine the current simulators
108+
// TODO: Run a command to probe the currently running emulators instead
109+
if (process.arch === "arm64") {
110+
return ["aarch64-linux-android"];
111+
} else if (process.arch === "x64") {
112+
return ["x86_64-linux-android"];
113+
} else {
114+
return [];
115+
}
108116
} else {
109-
return [];
117+
throw new Error(`Unexpected mode: ${mode as string}`);
110118
}
111119
},
112120
amendCommand(command) {

packages/cmake-rn/src/platforms/apple.ts

Lines changed: 74 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,22 @@ const XCODE_SDK_NAMES = {
6262
"x86_64-apple-darwin": "macosx",
6363
"arm64-apple-darwin": "macosx",
6464
"arm64;x86_64-apple-darwin": "macosx",
65+
6566
"arm64-apple-ios": "iphoneos",
6667
"arm64-apple-ios-sim": "iphonesimulator",
67-
"arm64-apple-tvos": "appletvos",
68+
"x86_64-apple-ios-sim": "iphonesimulator",
69+
"arm64;x86_64-apple-ios-sim": "iphonesimulator",
70+
6871
// "x86_64-apple-tvos": "appletvos",
72+
"arm64-apple-tvos": "appletvos",
73+
"x86_64-apple-tvos-sim": "appletvsimulator",
6974
"arm64-apple-tvos-sim": "appletvsimulator",
75+
"arm64;x86_64-apple-tvos-sim": "appletvsimulator",
76+
7077
"arm64-apple-visionos": "xros",
7178
"arm64-apple-visionos-sim": "xrsimulator",
79+
"x86_64-apple-visionos-sim": "xrsimulator",
80+
"arm64;x86_64-apple-visionos-sim": "xrsimulator",
7281
} satisfies Record<Triplet, XcodeSDKName>;
7382

7483
type CMakeSystemName = "Darwin" | "iOS" | "tvOS" | "watchOS" | "visionOS";
@@ -77,27 +86,44 @@ const CMAKE_SYSTEM_NAMES = {
7786
"x86_64-apple-darwin": "Darwin",
7887
"arm64-apple-darwin": "Darwin",
7988
"arm64;x86_64-apple-darwin": "Darwin",
89+
8090
"arm64-apple-ios": "iOS",
8191
"arm64-apple-ios-sim": "iOS",
82-
"arm64-apple-tvos": "tvOS",
92+
"x86_64-apple-ios-sim": "iOS",
93+
"arm64;x86_64-apple-ios-sim": "iOS",
94+
8395
// "x86_64-apple-tvos": "appletvos",
96+
"arm64-apple-tvos": "tvOS",
8497
"arm64-apple-tvos-sim": "tvOS",
98+
"x86_64-apple-tvos-sim": "tvOS",
99+
"arm64;x86_64-apple-tvos-sim": "tvOS",
100+
85101
"arm64-apple-visionos": "visionOS",
102+
"x86_64-apple-visionos-sim": "visionOS",
86103
"arm64-apple-visionos-sim": "visionOS",
104+
"arm64;x86_64-apple-visionos-sim": "visionOS",
87105
} satisfies Record<Triplet, CMakeSystemName>;
88106

89107
const DESTINATION_BY_TRIPLET = {
108+
"x86_64-apple-darwin": "generic/platform=macOS",
109+
"arm64-apple-darwin": "generic/platform=macOS",
110+
"arm64;x86_64-apple-darwin": "generic/platform=macOS",
111+
90112
"arm64-apple-ios": "generic/platform=iOS",
91113
"arm64-apple-ios-sim": "generic/platform=iOS Simulator",
114+
"x86_64-apple-ios-sim": "generic/platform=iOS Simulator",
115+
"arm64;x86_64-apple-ios-sim": "generic/platform=iOS Simulator",
116+
92117
"arm64-apple-tvos": "generic/platform=tvOS",
93118
// "x86_64-apple-tvos": "generic/platform=tvOS",
119+
"x86_64-apple-tvos-sim": "generic/platform=tvOS Simulator",
94120
"arm64-apple-tvos-sim": "generic/platform=tvOS Simulator",
121+
"arm64;x86_64-apple-tvos-sim": "generic/platform=tvOS Simulator",
122+
95123
"arm64-apple-visionos": "generic/platform=visionOS",
96124
"arm64-apple-visionos-sim": "generic/platform=visionOS Simulator",
97-
// TODO: Verify that the three following destinations are correct and actually work
98-
"x86_64-apple-darwin": "generic/platform=macOS,arch=x86_64",
99-
"arm64-apple-darwin": "generic/platform=macOS,arch=arm64",
100-
"arm64;x86_64-apple-darwin": "generic/platform=macOS",
125+
"x86_64-apple-visionos-sim": "generic/platform=visionOS Simulator",
126+
"arm64;x86_64-apple-visionos-sim": "generic/platform=visionOS Simulator",
101127
} satisfies Record<Triplet, string>;
102128

103129
type AppleArchitecture = "arm64" | "x86_64" | "arm64;x86_64";
@@ -106,30 +132,24 @@ export const APPLE_ARCHITECTURES = {
106132
"x86_64-apple-darwin": "x86_64",
107133
"arm64-apple-darwin": "arm64",
108134
"arm64;x86_64-apple-darwin": "arm64;x86_64",
135+
109136
"arm64-apple-ios": "arm64",
110137
"arm64-apple-ios-sim": "arm64",
111-
"arm64-apple-tvos": "arm64",
138+
"x86_64-apple-ios-sim": "x86_64",
139+
"arm64;x86_64-apple-ios-sim": "arm64;x86_64",
140+
112141
// "x86_64-apple-tvos": "x86_64",
142+
"arm64-apple-tvos": "arm64",
113143
"arm64-apple-tvos-sim": "arm64",
144+
"x86_64-apple-tvos-sim": "x86_64",
145+
"arm64;x86_64-apple-tvos-sim": "arm64;x86_64",
146+
114147
"arm64-apple-visionos": "arm64",
148+
"x86_64-apple-visionos-sim": "x86_64",
115149
"arm64-apple-visionos-sim": "arm64",
150+
"arm64;x86_64-apple-visionos-sim": "arm64;x86_64",
116151
} satisfies Record<Triplet, AppleArchitecture>;
117152

118-
export function createPlistContent(values: Record<string, string>) {
119-
return [
120-
'<?xml version="1.0" encoding="UTF-8"?>',
121-
'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
122-
'<plist version="1.0">',
123-
"<dict>",
124-
...Object.entries(values).flatMap(([key, value]) => [
125-
`<key>${key}</key>`,
126-
`<string>${value}</string>`,
127-
]),
128-
"</dict>",
129-
"</plist>",
130-
].join("\n");
131-
}
132-
133153
const xcframeworkExtensionOption = new Option(
134154
"--xcframework-extension",
135155
"Don't rename the xcframework to .apple.node",
@@ -171,16 +191,46 @@ export const platform: Platform<Triplet[], AppleOpts> = {
171191
id: "apple",
172192
name: "Apple",
173193
triplets: [
194+
"arm64-apple-darwin",
195+
"x86_64-apple-darwin",
174196
"arm64;x86_64-apple-darwin",
197+
175198
"arm64-apple-ios",
176199
"arm64-apple-ios-sim",
200+
"x86_64-apple-ios-sim",
201+
"arm64;x86_64-apple-ios-sim",
202+
177203
"arm64-apple-tvos",
204+
"x86_64-apple-tvos-sim",
178205
"arm64-apple-tvos-sim",
206+
"arm64;x86_64-apple-tvos-sim",
207+
179208
"arm64-apple-visionos",
209+
"x86_64-apple-visionos-sim",
180210
"arm64-apple-visionos-sim",
211+
"arm64;x86_64-apple-visionos-sim",
181212
],
182-
defaultTriplets() {
183-
return process.arch === "arm64" ? ["arm64-apple-ios-sim"] : [];
213+
defaultTriplets(mode) {
214+
if (mode === "all") {
215+
return [
216+
"arm64;x86_64-apple-darwin",
217+
218+
"arm64-apple-ios",
219+
"arm64;x86_64-apple-ios-sim",
220+
221+
"arm64-apple-tvos",
222+
"arm64;x86_64-apple-tvos-sim",
223+
224+
"arm64-apple-visionos",
225+
"arm64;x86_64-apple-visionos-sim",
226+
];
227+
} else if (mode === "current-development") {
228+
// We're applying a heuristic to determine the current simulators
229+
// TODO: Run a command to probe the currently running simulators instead
230+
return ["arm64;x86_64-apple-ios-sim"];
231+
} else {
232+
throw new Error(`Unexpected mode: ${mode as string}`);
233+
}
184234
},
185235
amendCommand(command) {
186236
return command.addOption(xcframeworkExtensionOption);

packages/cmake-rn/src/platforms/types.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export type Platform<
3333
Triplets extends string[] = string[],
3434
Opts extends cli.OptionValues = Record<string, unknown>,
3535
Command = ExtendedCommand<Opts>,
36+
Triplet extends string = Triplets[number],
3637
> = {
3738
/**
3839
* Used to identify the platform in the CLI.
@@ -47,9 +48,11 @@ export type Platform<
4748
*/
4849
triplets: Readonly<Triplets>;
4950
/**
50-
* Get the limited subset of triplets that should be built by default for this platform, to support a development workflow.
51+
* Get the limited subset of triplets that should be built by default for this platform.
5152
*/
52-
defaultTriplets(): Triplets[number][] | Promise<Triplets[number][]>;
53+
defaultTriplets(
54+
mode: "current-development" | "all",
55+
): Triplet[] | Promise<Triplet[]>;
5356
/**
5457
* Implement this to add any platform specific options to the command.
5558
*/
@@ -62,15 +65,15 @@ export type Platform<
6265
* Configure all projects for this platform.
6366
*/
6467
configure(
65-
triplets: TripletContext<Triplets[number]>[],
68+
triplets: TripletContext<Triplet>[],
6669
options: BaseOpts & Opts,
6770
spawn: Spawn,
6871
): Promise<void>;
6972
/**
7073
* Platform specific command to build a triplet project.
7174
*/
7275
build(
73-
context: TripletContext<Triplets[number]>,
76+
context: TripletContext<Triplet>,
7477
options: BaseOpts & Opts,
7578
): Promise<void>;
7679
/**
@@ -81,7 +84,7 @@ export type Platform<
8184
* Location of the final prebuilt artefact.
8285
*/
8386
outputPath: string,
84-
triplets: TripletContext<Triplets[number]>[],
87+
triplets: TripletContext<Triplet>[],
8588
options: BaseOpts & Opts,
8689
): Promise<void>;
8790
};

packages/ferric/src/cargo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const APPLE_XCFRAMEWORK_CHILDS_PER_TARGET: Record<AppleTargetName, string> = {
2222
"aarch64-apple-darwin": "macos-arm64_x86_64", // Universal
2323
"x86_64-apple-darwin": "macos-arm64_x86_64", // Universal
2424
"aarch64-apple-ios": "ios-arm64",
25-
"aarch64-apple-ios-sim": "ios-arm64-simulator",
25+
"aarch64-apple-ios-sim": "ios-arm64_x86_64-simulator", // Universal
2626
// "aarch64-apple-ios-macabi": "", // Catalyst
2727
// "x86_64-apple-ios": "ios-x86_64",
2828
// "x86_64-apple-ios-macabi": "ios-x86_64-simulator",

packages/host/src/node/prebuilds/apple.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,8 @@ import os from "node:os";
66
import plist from "@expo/plist";
77
import { spawn } from "@react-native-node-api/cli-utils";
88

9-
import { AppleTriplet } from "./triplets.js";
109
import { determineLibraryBasename } from "../path-utils.js";
1110

12-
type AppleArchitecture = "arm64" | "x86_64" | "arm64;x86_64";
13-
14-
export const APPLE_ARCHITECTURES = {
15-
"x86_64-apple-darwin": "x86_64",
16-
"arm64-apple-darwin": "arm64",
17-
"arm64;x86_64-apple-darwin": "arm64;x86_64",
18-
"arm64-apple-ios": "arm64",
19-
"arm64-apple-ios-sim": "arm64",
20-
"arm64-apple-tvos": "arm64",
21-
// "x86_64-apple-tvos": "x86_64",
22-
"arm64-apple-tvos-sim": "arm64",
23-
"arm64-apple-visionos": "arm64",
24-
"arm64-apple-visionos-sim": "arm64",
25-
} satisfies Record<AppleTriplet, AppleArchitecture>;
26-
2711
type XCframeworkOptions = {
2812
frameworkPaths: string[];
2913
outputPath: string;

packages/host/src/node/prebuilds/triplets.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,25 @@ export const ANDROID_TRIPLETS = [
1111
export type AndroidTriplet = (typeof ANDROID_TRIPLETS)[number];
1212

1313
export const APPLE_TRIPLETS = [
14-
"arm64;x86_64-apple-darwin",
1514
"x86_64-apple-darwin",
1615
"arm64-apple-darwin",
16+
"arm64;x86_64-apple-darwin",
17+
1718
"arm64-apple-ios",
19+
"x86_64-apple-ios-sim",
1820
"arm64-apple-ios-sim",
21+
"arm64;x86_64-apple-ios-sim",
22+
1923
"arm64-apple-tvos",
20-
"arm64-apple-tvos-sim",
2124
// "x86_64-apple-tvos",
25+
"x86_64-apple-tvos-sim",
26+
"arm64-apple-tvos-sim",
27+
"arm64;x86_64-apple-tvos-sim",
28+
2229
"arm64-apple-visionos",
30+
"x86_64-apple-visionos-sim",
2331
"arm64-apple-visionos-sim",
32+
"arm64;x86_64-apple-visionos-sim",
2433
] as const;
2534

2635
export type AppleTriplet = (typeof APPLE_TRIPLETS)[number];

0 commit comments

Comments
 (0)