Skip to content

Commit 8557768

Browse files
authored
Determine default targets from CMAKE_RN_TARGETS and FERRIC_TARGETS environment variable (#191)
* Use CMAKE_RN_TARGETS as default targets * Pass CMAKE_RN_TARGETS when bootstrapping on CI * Add changeset * Use FERRIC_TARGETS as default targets for Ferric * Pass FERRIC_TARGETS when bootstrapping on CI
1 parent aa539c2 commit 8557768

File tree

5 files changed

+74
-8
lines changed

5 files changed

+74
-8
lines changed

.changeset/loud-dodos-kneel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cmake-rn": minor
3+
---
4+
5+
Derive default targets from the CMAKE_RN_TARGETS environment variable

.changeset/loud-paths-eat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"ferric-cli": minor
3+
---
4+
5+
Derive default targets from the FERRIC_TARGETS environment variable

.github/workflows/check.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ jobs:
7575
- run: rustup target add x86_64-linux-android aarch64-linux-android armv7-linux-androideabi i686-linux-android aarch64-apple-ios-sim
7676
- run: npm ci
7777
- run: npm run bootstrap
78+
env:
79+
CMAKE_RN_TARGETS: arm64-apple-ios-sim
80+
FERRIC_TARGETS: aarch64-apple-ios-sim
7881
- run: npm run pod-install
7982
working-directory: apps/test-app
8083
- name: Run tests (iOS)
@@ -103,6 +106,9 @@ jobs:
103106
- run: rustup target add x86_64-linux-android aarch64-linux-android armv7-linux-androideabi i686-linux-android aarch64-apple-ios-sim
104107
- run: npm ci
105108
- run: npm run bootstrap
109+
env:
110+
CMAKE_RN_TARGETS: i686-linux-android
111+
FERRIC_TARGETS: i686-linux-android
106112
- name: Clone patched Hermes version
107113
shell: bash
108114
run: |

packages/cmake-rn/src/cli.ts

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,23 @@ const configurationOption = new Option("--configuration <configuration>")
4141
// TODO: Derive default targets
4242
// This is especially important when driving the build from within a React Native app package.
4343

44-
const targetOption = new Option(
45-
"--target <target...>",
46-
"Targets to build for"
47-
).choices(allTargets);
44+
const { CMAKE_RN_TARGETS } = process.env;
45+
46+
const defaultTargets = CMAKE_RN_TARGETS ? CMAKE_RN_TARGETS.split(",") : [];
47+
48+
for (const target of defaultTargets) {
49+
assert(
50+
(allTargets as string[]).includes(target),
51+
`Unexpected target in CMAKE_RN_TARGETS: ${target}`
52+
);
53+
}
54+
55+
const targetOption = new Option("--target <target...>", "Targets to build for")
56+
.choices(allTargets)
57+
.default(
58+
defaultTargets,
59+
"CMAKE_RN_TARGETS environment variable split by ','"
60+
);
4861

4962
const buildPathOption = new Option(
5063
"--build <path>",
@@ -148,16 +161,19 @@ program = program.action(
148161
});
149162

150163
// Configure every triplet project
164+
const targetsSummary = chalk.dim(
165+
`(${getTargetsSummary(targetContexts)})`
166+
);
151167
await oraPromise(
152168
Promise.all(
153169
targetContexts.map(({ platform, ...context }) =>
154170
configureProject(platform, context, baseOptions)
155171
)
156172
),
157173
{
158-
text: "Configuring projects",
174+
text: `Configuring projects ${targetsSummary}`,
159175
isSilent: baseOptions.verbose,
160-
successText: "Configured projects",
176+
successText: `Configured projects ${targetsSummary}`,
161177
failText: ({ message }) => `Failed to configure projects: ${message}`,
162178
}
163179
);
@@ -208,6 +224,23 @@ program = program.action(
208224
}
209225
);
210226

227+
function getTargetsSummary(
228+
targetContexts: { target: string; platform: Platform }[]
229+
) {
230+
const targetsPerPlatform: Record<string, string[]> = {};
231+
for (const { target, platform } of targetContexts) {
232+
if (!targetsPerPlatform[platform.id]) {
233+
targetsPerPlatform[platform.id] = [];
234+
}
235+
targetsPerPlatform[platform.id].push(target);
236+
}
237+
return Object.entries(targetsPerPlatform)
238+
.map(([platformId, targets]) => {
239+
return `${platformId}: ${targets.join(", ")}`;
240+
})
241+
.join(" / ");
242+
}
243+
211244
function getBuildPath({ build, source }: BaseOpts) {
212245
// TODO: Add configuration (debug vs release)
213246
return path.resolve(process.cwd(), build || path.join(source, "build"));

packages/ferric/src/build.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
prettyPath,
1919
} from "react-native-node-api";
2020

21-
import { UsageError } from "./errors.js";
21+
import { UsageError, assertFixable } from "./errors.js";
2222
import { ensureCargo, build } from "./cargo.js";
2323
import {
2424
ALL_TARGETS,
@@ -62,9 +62,26 @@ const ANDROID_TRIPLET_PER_TARGET: Record<AndroidTargetName, AndroidTriplet> = {
6262
const DEFAULT_NDK_VERSION = "27.1.12297006";
6363
const ANDROID_API_LEVEL = 24;
6464

65+
const { FERRIC_TARGETS } = process.env;
66+
67+
function getDefaultTargets() {
68+
const result = FERRIC_TARGETS ? FERRIC_TARGETS.split(",") : [];
69+
for (const target of result) {
70+
assertFixable(
71+
(ALL_TARGETS as readonly string[]).includes(target),
72+
`Unexpected target in FERRIC_TARGETS: ${target}`,
73+
{
74+
instructions:
75+
"Pass only valid targets via FERRIC_TARGETS (or remove them)",
76+
}
77+
);
78+
}
79+
return result as (typeof ALL_TARGETS)[number][];
80+
}
81+
6582
const targetOption = new Option("--target <target...>", "Target triple")
6683
.choices(ALL_TARGETS)
67-
.default([]);
84+
.default(getDefaultTargets());
6885
const appleTarget = new Option("--apple", "Use all Apple targets");
6986
const androidTarget = new Option("--android", "Use all Android targets");
7087
const ndkVersionOption = new Option(

0 commit comments

Comments
 (0)