Skip to content

Commit b05aadb

Browse files
committed
Error early when using conflicting architectures
1 parent f7ef72e commit b05aadb

File tree

5 files changed

+50
-0
lines changed

5 files changed

+50
-0
lines changed

.changeset/witty-cats-admire.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cmake-rn": patch
3+
---
4+
5+
Error early when using conflicting architectures for across triplets

packages/cmake-rn/src/cli.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ program = program.action(
250250
platformHasTriplet(platform, triplet),
251251
);
252252
if (relevantTriplets.length > 0) {
253+
platform.assertValidTriplets(
254+
relevantTriplets.map(({ triplet }) => triplet),
255+
);
253256
await platform.configure(
254257
relevantTriplets,
255258
baseOptions,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export const platform: Platform<Triplet[], AndroidOpts> = {
122122
.addOption(ndkVersionOption)
123123
.addOption(androidSdkVersionOption);
124124
},
125+
assertValidTriplets() {},
125126
async configure(
126127
triplets,
127128
{

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import fs from "node:fs";
44
import cp from "node:child_process";
55

66
import {
7+
assertFixable,
78
Option,
89
oraPromise,
910
prettyPath,
@@ -193,6 +194,12 @@ async function readCmakeSharedLibraryTarget(
193194
return sharedLibrary;
194195
}
195196

197+
const SIMULATOR_TRIPLET_SUFFIXES = [
198+
"apple-ios-sim",
199+
"apple-tvos-sim",
200+
"apple-visionos-sim",
201+
] as const;
202+
196203
export const platform: Platform<Triplet[], AppleOpts> = {
197204
id: "apple",
198205
name: "Apple",
@@ -243,6 +250,35 @@ export const platform: Platform<Triplet[], AppleOpts> = {
243250
.addOption(xcframeworkExtensionOption)
244251
.addOption(appleBundleIdentifierOption);
245252
},
253+
assertValidTriplets(triplets) {
254+
for (const suffix of SIMULATOR_TRIPLET_SUFFIXES) {
255+
const suggestion = `use the universal 'arm64;x86_64-${suffix}' triplet instead`;
256+
assertFixable(
257+
!triplets.includes(`x86_64-${suffix}`) ||
258+
!triplets.includes(`arm64-${suffix}`),
259+
`Conflicting triplet variants for ${suffix}`,
260+
{
261+
instructions: `Remove either the arm64 or x86_64 variant of the ${suffix} triplet or ${suggestion}`,
262+
},
263+
);
264+
assertFixable(
265+
!triplets.includes(`x86_64-${suffix}`) ||
266+
!triplets.includes(`arm64;x86_64-${suffix}`),
267+
`Conflicting triplet variants for ${suffix}`,
268+
{
269+
instructions: `Remove the x86_64 variant of the ${suffix} triplet and ${suggestion}`,
270+
},
271+
);
272+
assertFixable(
273+
!triplets.includes(`arm64-${suffix}`) ||
274+
!triplets.includes(`arm64;x86_64-${suffix}`),
275+
`Conflicting triplet variants for ${suffix}`,
276+
{
277+
instructions: `Remove the arm64 variant of the ${suffix} triplet and ${suggestion}`,
278+
},
279+
);
280+
}
281+
},
246282
async configure(
247283
triplets,
248284
{ source, build, define, weakNodeApiLinkage, cmakeJs },

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ export type Platform<
5353
defaultTriplets(
5454
mode: "current-development" | "all",
5555
): Triplet[] | Promise<Triplet[]>;
56+
/**
57+
* Assert the combination of triplets is supported by the platform.
58+
* @throws {Error} If the combination of triplets is not supported.
59+
*/
60+
assertValidTriplets(triplets: Triplet[]): void;
5661
/**
5762
* Implement this to add any platform specific options to the command.
5863
*/

0 commit comments

Comments
 (0)