Skip to content

Commit 436119b

Browse files
committed
abstract the cmake invocation to a script file so we can make the project generation avoid XCode on non-Apple platforms.
1 parent 4c8f14c commit 436119b

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

packages/node-addon-examples/scripts/build-examples.mts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
11
import { execSync } from "node:child_process";
2+
import { platform } from "node:os";
23

34
import { findCMakeProjects } from "./cmake-projects.mjs";
45

56
const projectDirectories = findCMakeProjects();
67

8+
// Platform-specific build command
9+
let buildCommand: string;
10+
switch (platform()) {
11+
case "darwin":
12+
// macOS: build for both Android and Apple
13+
buildCommand = "react-native-node-api-cmake --android --apple";
14+
break;
15+
case "win32":
16+
case "linux":
17+
// Windows and Linux: only Android
18+
buildCommand = "react-native-node-api-cmake --android";
19+
break;
20+
default:
21+
console.error(`Unsupported platform: ${platform()}`);
22+
process.exit(1);
23+
}
24+
725
for (const projectDirectory of projectDirectories) {
8-
console.log(`Running "react-native-node-api-cmake" in ${projectDirectory}`);
26+
console.log(`Running "${buildCommand}" in ${projectDirectory}`);
927
execSync(
10-
"react-native-node-api-cmake --android --apple",
28+
buildCommand,
1129
// "react-native-node-api-cmake --triplet aarch64-linux-android --triplet arm64-apple-ios-sim",
1230
{
1331
cwd: projectDirectory,

packages/react-native-node-api-modules/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"copy-node-api-headers": "tsx scripts/copy-node-api-headers.ts",
4444
"generate-weak-node-api": "tsx scripts/generate-weak-node-api.ts",
4545
"generate-weak-node-api-injector": "tsx scripts/generate-weak-node-api-injector.ts",
46-
"build-weak-node-api": "npm run generate-weak-node-api && react-native-node-api-cmake --android --apple --no-auto-link --no-weak-node-api-linkage --xcframework-extension --source ./weak-node-api",
46+
"build-weak-node-api": "tsx scripts/build-weak-node-api.ts",
4747
"test": "tsx --test src/node/**/*.test.ts src/node/*.test.ts"
4848
},
4949
"keywords": [
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env tsx
2+
3+
import { execSync } from "node:child_process";
4+
import { platform } from "node:os";
5+
6+
// First generate the weak node API
7+
execSync("npm run generate-weak-node-api", { stdio: "inherit" });
8+
9+
// Build command with common flags
10+
const baseCommand = "react-native-node-api-cmake --no-auto-link --no-weak-node-api-linkage --source ./weak-node-api";
11+
12+
// Platform-specific flags
13+
let platformFlags = "";
14+
switch (platform()) {
15+
case "darwin":
16+
// macOS: build for both Android and Apple
17+
platformFlags = "--android --apple --xcframework-extension";
18+
break;
19+
case "win32":
20+
// Windows: only Android (no Apple/Xcode support)
21+
platformFlags = "--android";
22+
break;
23+
case "linux":
24+
// Linux: only Android
25+
platformFlags = "--android";
26+
break;
27+
default:
28+
console.error(`Unsupported platform: ${platform()}`);
29+
process.exit(1);
30+
}
31+
32+
const fullCommand = `${baseCommand} ${platformFlags}`;
33+
console.log(`Running: ${fullCommand}`);
34+
execSync(fullCommand, { stdio: "inherit" });

0 commit comments

Comments
 (0)