Skip to content

Commit a1338fd

Browse files
authored
Merge branch 'main' into kh/cmake-rn-error-early-on-arch-conflicts
2 parents b05aadb + 7349c34 commit a1338fd

File tree

20 files changed

+449
-97
lines changed

20 files changed

+449
-97
lines changed

.changeset/nice-crews-wonder.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"gyp-to-cmake": patch
3+
"cmake-rn": patch
4+
"ferric-cli": patch
5+
"react-native-node-api": patch
6+
---
7+
8+
Add support for source maps across CLI bins

.changeset/rich-weeks-cry.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"cmake-rn": minor
3+
"ferric-cli": minor
4+
"react-native-node-api": minor
5+
---
6+
7+
Add support for building versioned frameworks for Apple Darwin / macOS

.changeset/tall-snakes-beg.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+
Detect ccache and use when building for Android and Apple

.github/workflows/check.yml

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ env:
44
# Version here should match the one in React Native template and packages/cmake-rn/src/cli.ts
55
NDK_VERSION: 27.1.12297006
66
# Building Hermes from source doesn't support CMake v4
7-
CMAKE_VERSION: 3.31.6
7+
CMAKE_VERSION: 4.2.2
88
# Enabling the Gradle test on CI (disabled by default because it downloads a lot)
99
ENABLE_GRADLE_TESTS: true
1010

@@ -28,10 +28,14 @@ jobs:
2828
- uses: actions/setup-node@v6
2929
with:
3030
node-version: lts/krypton
31-
- name: Setup clang-format
31+
- name: Setup cpp tools
3232
uses: aminya/setup-cpp@v1
3333
with:
3434
clang-format: true
35+
- name: ccache
36+
uses: hendrikmuhs/ccache-action@v1.2
37+
with:
38+
key: ${{ github.job }}-${{ runner.os }}
3539
# Set up JDK and Android SDK only because we need weak-node-api, to build ferric-example and to run the linting
3640
# TODO: Remove this once we have a way to run linting without building the native code
3741
- name: Set up JDK 17
@@ -71,10 +75,14 @@ jobs:
7175
- uses: actions/setup-node@v6
7276
with:
7377
node-version: lts/krypton
74-
- name: Setup clang-format
78+
- name: Setup cpp tools
7579
uses: aminya/setup-cpp@v1
7680
with:
7781
clang-format: true
82+
- name: ccache
83+
uses: hendrikmuhs/ccache-action@v1.2
84+
with:
85+
key: ${{ github.job }}-${{ runner.os }}
7886
- name: Set up JDK 17
7987
uses: actions/setup-java@v4
8088
with:
@@ -104,10 +112,14 @@ jobs:
104112
- uses: actions/setup-node@v6
105113
with:
106114
node-version: lts/krypton
107-
- name: Setup clang-format
115+
- name: Setup cpp tools
108116
uses: aminya/setup-cpp@v1
109117
with:
110118
clang-format: true
119+
- name: ccache
120+
uses: hendrikmuhs/ccache-action@v1.2
121+
with:
122+
key: ${{ github.job }}-${{ runner.os }}
111123
- run: npm ci
112124
- run: npm run build
113125
- name: Prepare weak-node-api
@@ -127,10 +139,14 @@ jobs:
127139
- uses: actions/setup-node@v6
128140
with:
129141
node-version: lts/krypton
130-
- name: Setup clang-format
142+
- name: Setup cpp tools
131143
uses: aminya/setup-cpp@v1
132144
with:
133145
clang-format: true
146+
- name: ccache
147+
uses: hendrikmuhs/ccache-action@v1.2
148+
with:
149+
key: ${{ github.job }}-${{ runner.os }}
134150
- name: Set up JDK 17
135151
uses: actions/setup-java@v3
136152
with:
@@ -151,7 +167,7 @@ jobs:
151167
- name: Run tests (iOS)
152168
run: npm run test:ios:allTests
153169
# TODO: Enable release mode when it works
154-
# run: npm run test:ios -- --mode Release
170+
# run: npm run test:ios:allTests -- --mode Release
155171
working-directory: apps/test-app
156172
test-macos:
157173
# Disabling this on main for now, as initializing the template takes a long time and
@@ -164,10 +180,14 @@ jobs:
164180
- uses: actions/setup-node@v6
165181
with:
166182
node-version: lts/krypton
167-
- name: Setup clang-format
183+
- name: Setup cpp tools
168184
uses: aminya/setup-cpp@v1
169185
with:
170186
clang-format: true
187+
- name: ccache
188+
uses: hendrikmuhs/ccache-action@v1.2
189+
with:
190+
key: ${{ github.job }}-${{ runner.os }}
171191
- name: Set up JDK 17
172192
uses: actions/setup-java@v3
173193
with:
@@ -187,9 +207,17 @@ jobs:
187207
- run: npm run init-macos-test-app
188208
- run: pod install --project-directory=macos
189209
working-directory: apps/macos-test-app
190-
- name: Run MacOS test app
191-
run: npm run test:allTests -- --mode Release
210+
- name: Bundle test app
211+
run: npx react-native bundle --entry-file index.js --platform macos --dev false --minify false --bundle-output dist/main.macos.jsbundle --assets-dest dist/res
192212
working-directory: apps/macos-test-app
213+
- name: Build test app
214+
run: xcodebuild archive -workspace MacOSTestApp.xcworkspace -configuration Release -scheme MacOSTestApp-macOS -destination generic/platform="macOS" -archivePath ./build/macos-test-app.xcarchive | xcbeautify
215+
working-directory: apps/macos-test-app/macos
216+
- name: Run test app
217+
run: npx mocha-remote --exit-on-error -- macos/build/macos-test-app.xcarchive/Products/Applications/MacOSTestApp.app/Contents/MacOS/MacOSTestApp
218+
working-directory: apps/macos-test-app
219+
env:
220+
MOCHA_REMOTE_CONTEXT: allTests
193221
test-android:
194222
if: github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'Android 🤖')
195223
name: Test app (Android)
@@ -199,10 +227,14 @@ jobs:
199227
- uses: actions/setup-node@v6
200228
with:
201229
node-version: lts/krypton
202-
- name: Setup clang-format
230+
- name: Setup cpp tools
203231
uses: aminya/setup-cpp@v1
204232
with:
205233
clang-format: true
234+
- name: ccache
235+
uses: hendrikmuhs/ccache-action@v1.2
236+
with:
237+
key: ${{ github.job }}-${{ runner.os }}
206238
- name: Set up JDK 17
207239
uses: actions/setup-java@v4
208240
with:
@@ -283,10 +315,14 @@ jobs:
283315
- uses: actions/setup-node@v6
284316
with:
285317
node-version: lts/krypton
286-
- name: Setup clang-format
318+
- name: Setup cpp tools
287319
uses: aminya/setup-cpp@v1
288320
with:
289321
clang-format: true
322+
- name: ccache
323+
uses: hendrikmuhs/ccache-action@v1.2
324+
with:
325+
key: ${{ github.job }}-${{ runner.os }}
290326
- name: Set up JDK 17
291327
uses: actions/setup-java@v3
292328
with:

.github/workflows/release.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ jobs:
2121
- uses: actions/setup-node@v6
2222
with:
2323
node-version: lts/krypton
24-
- name: Setup clang-format
24+
- name: Setup cpp tools
2525
uses: aminya/setup-cpp@v1
2626
with:
2727
clang-format: true
28+
- name: ccache
29+
uses: hendrikmuhs/ccache-action@v1.2
30+
with:
31+
key: ${{ github.job }}-${{ runner.os }}
2832
- name: Set up JDK 17
2933
uses: actions/setup-java@v3
3034
with:

apps/test-app/metro.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const config = makeMetroConfig({
1111
},
1212
});
1313

14-
if (config.watchFolders.length === 0) {
14+
if (config.projectRoot.endsWith("macos-test-app")) {
1515
// This patch is needed to locate packages in the monorepo from the MacOS app
1616
// which is intentionally kept outside of the workspaces configuration to prevent
1717
// duplicate react-native version and pollution of the package lock.

eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default tseslint.config(
1111
"**/dist/**",
1212
"**/build/**",
1313
"apps/test-app/ios/**",
14+
"apps/macos-test-app/**",
1415
"packages/host/hermes/**",
1516
"packages/node-addon-examples/examples/**",
1617
"packages/ferric-example/ferric_example.js",

packages/cmake-rn/bin/cmake-rn.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#!/usr/bin/env node
1+
#!/usr/bin/env -S node --enable-source-maps
22
import "../dist/run.js";

packages/cmake-rn/src/ccache.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import cp from "node:child_process";
2+
3+
export function getCcachePath(): string | null {
4+
const result = cp.spawnSync(
5+
process.platform === "win32" ? "where" : "which",
6+
["ccache"],
7+
);
8+
if (result.status === 0) {
9+
return result.stdout.toString().trim();
10+
} else {
11+
return null;
12+
}
13+
}

packages/cmake-rn/src/cli.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ import {
2020
platformHasTriplet,
2121
} from "./platforms.js";
2222
import { Platform } from "./platforms/types.js";
23+
import { getCcachePath } from "./ccache.js";
2324

2425
// We're attaching a lot of listeners when spawning in parallel
2526
EventEmitter.defaultMaxListeners = 100;
2627

27-
// TODO: Add automatic ccache support
28-
2928
const verboseOption = new Option(
3029
"--verbose",
3130
"Print more output during the build",
@@ -125,6 +124,11 @@ const cmakeJsOption = new Option(
125124
"Define CMAKE_JS_* variables used for compatibility with cmake-js",
126125
).default(false);
127126

127+
const ccachePathOption = new Option(
128+
"--ccache-path <path>",
129+
"Specify the path to the ccache executable",
130+
).default(getCcachePath());
131+
128132
let program = new Command("cmake-rn")
129133
.description("Build React Native Node API modules with CMake")
130134
.addOption(tripletOption)
@@ -139,7 +143,8 @@ let program = new Command("cmake-rn")
139143
.addOption(stripOption)
140144
.addOption(noAutoLinkOption)
141145
.addOption(noWeakNodeApiLinkageOption)
142-
.addOption(cmakeJsOption);
146+
.addOption(cmakeJsOption)
147+
.addOption(ccachePathOption);
143148

144149
for (const platform of platforms) {
145150
const allOption = new Option(
@@ -169,7 +174,14 @@ program = program.action(
169174
process.cwd(),
170175
expandTemplate(baseOptions.out, baseOptions),
171176
);
172-
const { verbose, clean, source, out, build: buildPath } = baseOptions;
177+
const {
178+
verbose,
179+
clean,
180+
source,
181+
out,
182+
build: buildPath,
183+
ccachePath,
184+
} = baseOptions;
173185

174186
assertFixable(
175187
fs.existsSync(path.join(source, "CMakeLists.txt")),
@@ -179,6 +191,10 @@ program = program.action(
179191
},
180192
);
181193

194+
if (ccachePath) {
195+
console.log(`♻️ Using ccache: ${chalk.dim(ccachePath)}`);
196+
}
197+
182198
if (clean) {
183199
await fs.promises.rm(buildPath, { recursive: true, force: true });
184200
}
@@ -228,9 +244,16 @@ program = program.action(
228244
triplet,
229245
platform,
230246
async spawn(command: string, args: string[], cwd?: string) {
247+
const outputPrefix = verbose ? chalk.dim(`[${triplet}] `) : undefined;
248+
if (verbose) {
249+
console.log(
250+
`${outputPrefix}» ${command} ${args.map((arg) => chalk.dim(`${arg}`)).join(" ")}`,
251+
cwd ? `(in ${chalk.dim(cwd)})` : "",
252+
);
253+
}
231254
await spawn(command, args, {
232255
outputMode: verbose ? "inherit" : "buffered",
233-
outputPrefix: verbose ? chalk.dim(`[${triplet}] `) : undefined,
256+
outputPrefix,
234257
cwd,
235258
});
236259
},

0 commit comments

Comments
 (0)