Skip to content

Commit 9c3dfb4

Browse files
authored
Error early when using conflicting architectures (#350)
1 parent 7349c34 commit 9c3dfb4

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
@@ -273,6 +273,9 @@ program = program.action(
273273
platformHasTriplet(platform, triplet),
274274
);
275275
if (relevantTriplets.length > 0) {
276+
platform.assertValidTriplets(
277+
relevantTriplets.map(({ triplet }) => triplet),
278+
);
276279
await platform.configure(
277280
relevantTriplets,
278281
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
async function getCompilerPath(
197204
name: "clang" | "clang++",
198205
{ buildBinPath, ccachePath }: { buildBinPath: string; ccachePath: string },
@@ -254,6 +261,35 @@ export const platform: Platform<Triplet[], AppleOpts> = {
254261
.addOption(xcframeworkExtensionOption)
255262
.addOption(appleBundleIdentifierOption);
256263
},
264+
assertValidTriplets(triplets) {
265+
for (const suffix of SIMULATOR_TRIPLET_SUFFIXES) {
266+
const suggestion = `use the universal 'arm64;x86_64-${suffix}' triplet instead`;
267+
assertFixable(
268+
!triplets.includes(`x86_64-${suffix}`) ||
269+
!triplets.includes(`arm64-${suffix}`),
270+
`Conflicting triplet variants for ${suffix}`,
271+
{
272+
instructions: `Remove either the arm64 or x86_64 variant of the ${suffix} triplet or ${suggestion}`,
273+
},
274+
);
275+
assertFixable(
276+
!triplets.includes(`x86_64-${suffix}`) ||
277+
!triplets.includes(`arm64;x86_64-${suffix}`),
278+
`Conflicting triplet variants for ${suffix}`,
279+
{
280+
instructions: `Remove the x86_64 variant of the ${suffix} triplet and ${suggestion}`,
281+
},
282+
);
283+
assertFixable(
284+
!triplets.includes(`arm64-${suffix}`) ||
285+
!triplets.includes(`arm64;x86_64-${suffix}`),
286+
`Conflicting triplet variants for ${suffix}`,
287+
{
288+
instructions: `Remove the arm64 variant of the ${suffix} triplet and ${suggestion}`,
289+
},
290+
);
291+
}
292+
},
257293
async configure(
258294
triplets,
259295
{ source, build, define, weakNodeApiLinkage, cmakeJs, ccachePath },

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)