diff --git a/.changeset/loud-dodos-kneel.md b/.changeset/loud-dodos-kneel.md new file mode 100644 index 00000000..898c29bb --- /dev/null +++ b/.changeset/loud-dodos-kneel.md @@ -0,0 +1,5 @@ +--- +"cmake-rn": minor +--- + +Derive default targets from the CMAKE_RN_TARGETS environment variable diff --git a/.changeset/loud-paths-eat.md b/.changeset/loud-paths-eat.md new file mode 100644 index 00000000..500a4f55 --- /dev/null +++ b/.changeset/loud-paths-eat.md @@ -0,0 +1,5 @@ +--- +"ferric-cli": minor +--- + +Derive default targets from the FERRIC_TARGETS environment variable diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 7601c91e..1abfe758 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -75,6 +75,9 @@ jobs: - run: rustup target add x86_64-linux-android aarch64-linux-android armv7-linux-androideabi i686-linux-android aarch64-apple-ios-sim - run: npm ci - run: npm run bootstrap + env: + CMAKE_RN_TARGETS: arm64-apple-ios-sim + FERRIC_TARGETS: aarch64-apple-ios-sim - run: npm run pod-install working-directory: apps/test-app - name: Run tests (iOS) @@ -103,6 +106,9 @@ jobs: - run: rustup target add x86_64-linux-android aarch64-linux-android armv7-linux-androideabi i686-linux-android aarch64-apple-ios-sim - run: npm ci - run: npm run bootstrap + env: + CMAKE_RN_TARGETS: i686-linux-android + FERRIC_TARGETS: i686-linux-android - name: Clone patched Hermes version shell: bash run: | diff --git a/packages/cmake-rn/src/cli.ts b/packages/cmake-rn/src/cli.ts index 39ffadc3..56c8dac9 100644 --- a/packages/cmake-rn/src/cli.ts +++ b/packages/cmake-rn/src/cli.ts @@ -41,10 +41,23 @@ const configurationOption = new Option("--configuration ") // TODO: Derive default targets // This is especially important when driving the build from within a React Native app package. -const targetOption = new Option( - "--target ", - "Targets to build for" -).choices(allTargets); +const { CMAKE_RN_TARGETS } = process.env; + +const defaultTargets = CMAKE_RN_TARGETS ? CMAKE_RN_TARGETS.split(",") : []; + +for (const target of defaultTargets) { + assert( + (allTargets as string[]).includes(target), + `Unexpected target in CMAKE_RN_TARGETS: ${target}` + ); +} + +const targetOption = new Option("--target ", "Targets to build for") + .choices(allTargets) + .default( + defaultTargets, + "CMAKE_RN_TARGETS environment variable split by ','" + ); const buildPathOption = new Option( "--build ", @@ -148,6 +161,9 @@ program = program.action( }); // Configure every triplet project + const targetsSummary = chalk.dim( + `(${getTargetsSummary(targetContexts)})` + ); await oraPromise( Promise.all( targetContexts.map(({ platform, ...context }) => @@ -155,9 +171,9 @@ program = program.action( ) ), { - text: "Configuring projects", + text: `Configuring projects ${targetsSummary}`, isSilent: baseOptions.verbose, - successText: "Configured projects", + successText: `Configured projects ${targetsSummary}`, failText: ({ message }) => `Failed to configure projects: ${message}`, } ); @@ -208,6 +224,23 @@ program = program.action( } ); +function getTargetsSummary( + targetContexts: { target: string; platform: Platform }[] +) { + const targetsPerPlatform: Record = {}; + for (const { target, platform } of targetContexts) { + if (!targetsPerPlatform[platform.id]) { + targetsPerPlatform[platform.id] = []; + } + targetsPerPlatform[platform.id].push(target); + } + return Object.entries(targetsPerPlatform) + .map(([platformId, targets]) => { + return `${platformId}: ${targets.join(", ")}`; + }) + .join(" / "); +} + function getBuildPath({ build, source }: BaseOpts) { // TODO: Add configuration (debug vs release) return path.resolve(process.cwd(), build || path.join(source, "build")); diff --git a/packages/ferric/src/build.ts b/packages/ferric/src/build.ts index 51063eff..48c10d8b 100644 --- a/packages/ferric/src/build.ts +++ b/packages/ferric/src/build.ts @@ -18,7 +18,7 @@ import { prettyPath, } from "react-native-node-api"; -import { UsageError } from "./errors.js"; +import { UsageError, assertFixable } from "./errors.js"; import { ensureCargo, build } from "./cargo.js"; import { ALL_TARGETS, @@ -62,9 +62,26 @@ const ANDROID_TRIPLET_PER_TARGET: Record = { const DEFAULT_NDK_VERSION = "27.1.12297006"; const ANDROID_API_LEVEL = 24; +const { FERRIC_TARGETS } = process.env; + +function getDefaultTargets() { + const result = FERRIC_TARGETS ? FERRIC_TARGETS.split(",") : []; + for (const target of result) { + assertFixable( + (ALL_TARGETS as readonly string[]).includes(target), + `Unexpected target in FERRIC_TARGETS: ${target}`, + { + instructions: + "Pass only valid targets via FERRIC_TARGETS (or remove them)", + } + ); + } + return result as (typeof ALL_TARGETS)[number][]; +} + const targetOption = new Option("--target ", "Target triple") .choices(ALL_TARGETS) - .default([]); + .default(getDefaultTargets()); const appleTarget = new Option("--apple", "Use all Apple targets"); const androidTarget = new Option("--android", "Use all Android targets"); const ndkVersionOption = new Option(