Skip to content

Commit 678ba17

Browse files
committed
Produce only universal Node.js binaries by default
1 parent 69abd27 commit 678ba17

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

packages/cmake-rn/src/cli.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ program = program.action(
117117
// Forcing the types a bit here, since the platform id option is dynamically added
118118
if ((baseOptions as Record<string, unknown>)[platform.id]) {
119119
for (const target of platform.targets) {
120+
// Skip redundant targets
121+
if (platform.redundantTargets?.includes(target)) {
122+
continue;
123+
}
120124
targets.add(target);
121125
}
122126
}

packages/cmake-rn/src/platforms/node.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ import type { Platform } from "./types.js";
1515
import { toDeclarationArguments } from "../cmake.js";
1616
import { getNodeApiIncludeDirectories } from "../headers.js";
1717

18+
type Architecture = "arm64" | "x86_64" | "arm64;x86_64";
19+
20+
const ARCHITECTURES = {
21+
"arm64-apple-darwin": "arm64",
22+
"x86_64-apple-darwin": "x86_64",
23+
"arm64;x86_64-apple-darwin": "arm64;x86_64",
24+
} satisfies Record<NodeTriplet, Architecture>;
25+
1826
type Target = `${NodeTriplet}-node`;
1927

2028
type NodeOpts = Record<string, unknown>;
@@ -51,6 +59,7 @@ export const platform: Platform<Target[], NodeOpts> = {
5159
"x86_64-apple-darwin-node",
5260
"arm64;x86_64-apple-darwin-node",
5361
],
62+
redundantTargets: ["arm64-apple-darwin-node", "x86_64-apple-darwin-node"],
5463
defaultTargets() {
5564
if (process.platform === "darwin") {
5665
if (process.arch === "arm64") {
@@ -64,12 +73,14 @@ export const platform: Platform<Target[], NodeOpts> = {
6473
amendCommand(command) {
6574
return command;
6675
},
67-
configureArgs({ target }) {
76+
configureArgs({ target }, { configuration }) {
6877
const triplet = tripletFromTarget(target);
6978
return [
7079
"-G",
7180
"Ninja",
7281
...toDeclarationArguments({
82+
CMAKE_BUILD_TYPE: configuration,
83+
CMAKE_OSX_ARCHITECTURES: ARCHITECTURES[triplet],
7384
// TODO: Make this names less "cmake-js" specific with an option to use the CMAKE_JS prefix
7485
CMAKE_JS_INC: getNodeApiIncludeDirectories(),
7586
CMAKE_SHARED_LINKER_FLAGS: getLinkerFlags(triplet),

packages/cmake-rn/src/platforms/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ export type Platform<
3737
* All the targets supported by this platform.
3838
*/
3939
targets: Readonly<Targets>;
40+
/**
41+
* Targets which are redundant when building all supported targets.
42+
* Ex. universal / multi-arch targets that are already produced by other targets.
43+
*/
44+
redundantTargets?: Readonly<Targets>;
4045
/**
4146
* Get the limited subset of targets that should be built by default for this platform, to support a development workflow.
4247
*/

packages/host/src/node/prebuilds/node.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import { NodeTriplet } from "./triplets.js";
77

88
type OSArchName =
99
| `${typeof process.platform}-${typeof process.arch}`
10-
| "darwin-arm64;x86_64";
10+
| "darwin-arm64;x64";
1111

1212
const DIRECTORY_NAMES_PER_TARGET = {
13-
"arm64;x86_64-apple-darwin": "darwin-arm64;x86_64",
13+
"arm64;x86_64-apple-darwin": "darwin-arm64;x64",
1414
"arm64-apple-darwin": "darwin-arm64",
1515
"x86_64-apple-darwin": "darwin-x64",
1616
} satisfies Record<NodeTriplet, OSArchName>;

0 commit comments

Comments
 (0)