diff --git a/.changeset/witty-cats-admire.md b/.changeset/witty-cats-admire.md new file mode 100644 index 00000000..cc563367 --- /dev/null +++ b/.changeset/witty-cats-admire.md @@ -0,0 +1,5 @@ +--- +"cmake-rn": patch +--- + +Error early when using conflicting architectures for across triplets diff --git a/packages/cmake-rn/src/cli.ts b/packages/cmake-rn/src/cli.ts index 2f97a161..b94e2fa2 100644 --- a/packages/cmake-rn/src/cli.ts +++ b/packages/cmake-rn/src/cli.ts @@ -273,6 +273,9 @@ program = program.action( platformHasTriplet(platform, triplet), ); if (relevantTriplets.length > 0) { + platform.assertValidTriplets( + relevantTriplets.map(({ triplet }) => triplet), + ); await platform.configure( relevantTriplets, baseOptions, diff --git a/packages/cmake-rn/src/platforms/android.ts b/packages/cmake-rn/src/platforms/android.ts index 9c20d916..da5f19c2 100644 --- a/packages/cmake-rn/src/platforms/android.ts +++ b/packages/cmake-rn/src/platforms/android.ts @@ -122,6 +122,7 @@ export const platform: Platform = { .addOption(ndkVersionOption) .addOption(androidSdkVersionOption); }, + assertValidTriplets() {}, async configure( triplets, { diff --git a/packages/cmake-rn/src/platforms/apple.ts b/packages/cmake-rn/src/platforms/apple.ts index e210ae83..36c595b9 100644 --- a/packages/cmake-rn/src/platforms/apple.ts +++ b/packages/cmake-rn/src/platforms/apple.ts @@ -4,6 +4,7 @@ import fs from "node:fs"; import cp from "node:child_process"; import { + assertFixable, Option, oraPromise, prettyPath, @@ -193,6 +194,12 @@ async function readCmakeSharedLibraryTarget( return sharedLibrary; } +const SIMULATOR_TRIPLET_SUFFIXES = [ + "apple-ios-sim", + "apple-tvos-sim", + "apple-visionos-sim", +] as const; + async function getCompilerPath( name: "clang" | "clang++", { buildBinPath, ccachePath }: { buildBinPath: string; ccachePath: string }, @@ -254,6 +261,35 @@ export const platform: Platform = { .addOption(xcframeworkExtensionOption) .addOption(appleBundleIdentifierOption); }, + assertValidTriplets(triplets) { + for (const suffix of SIMULATOR_TRIPLET_SUFFIXES) { + const suggestion = `use the universal 'arm64;x86_64-${suffix}' triplet instead`; + assertFixable( + !triplets.includes(`x86_64-${suffix}`) || + !triplets.includes(`arm64-${suffix}`), + `Conflicting triplet variants for ${suffix}`, + { + instructions: `Remove either the arm64 or x86_64 variant of the ${suffix} triplet or ${suggestion}`, + }, + ); + assertFixable( + !triplets.includes(`x86_64-${suffix}`) || + !triplets.includes(`arm64;x86_64-${suffix}`), + `Conflicting triplet variants for ${suffix}`, + { + instructions: `Remove the x86_64 variant of the ${suffix} triplet and ${suggestion}`, + }, + ); + assertFixable( + !triplets.includes(`arm64-${suffix}`) || + !triplets.includes(`arm64;x86_64-${suffix}`), + `Conflicting triplet variants for ${suffix}`, + { + instructions: `Remove the arm64 variant of the ${suffix} triplet and ${suggestion}`, + }, + ); + } + }, async configure( triplets, { source, build, define, weakNodeApiLinkage, cmakeJs, ccachePath }, diff --git a/packages/cmake-rn/src/platforms/types.ts b/packages/cmake-rn/src/platforms/types.ts index 6944d4bf..d6cd3963 100644 --- a/packages/cmake-rn/src/platforms/types.ts +++ b/packages/cmake-rn/src/platforms/types.ts @@ -53,6 +53,11 @@ export type Platform< defaultTriplets( mode: "current-development" | "all", ): Triplet[] | Promise; + /** + * Assert the combination of triplets is supported by the platform. + * @throws {Error} If the combination of triplets is not supported. + */ + assertValidTriplets(triplets: Triplet[]): void; /** * Implement this to add any platform specific options to the command. */