@rxflex/rom 0.0.1 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Cargo.toml CHANGED
@@ -1,7 +1,7 @@
1
1
  [package]
2
2
  name = "rom-node-native"
3
3
  description = "Native napi-rs bridge for the ROM Node.js bindings"
4
- version = "0.0.1"
4
+ version = "0.0.5"
5
5
  edition = "2024"
6
6
  homepage = "https://github.com/Rxflex/rom"
7
7
  license = "MIT"
package/README.md CHANGED
@@ -48,7 +48,15 @@ Config keys use the Rust runtime field names, so use snake_case such as `cors_en
48
48
  npm run build:native
49
49
  ```
50
50
 
51
- `npm pack` and `npm publish` now run the native release build automatically via `prepack`, and the produced `rom_node_native.node` is included in the published tarball for the platform that performed the publish.
51
+ Local `npm pack` and `npm publish` still build the native addon for the current platform via `prepack`.
52
+ Tagged GitHub releases assemble multi-platform prebuilds and publish a single npm package that includes:
53
+
54
+ - `linux-x64-gnu`
55
+ - `win32-x64-msvc`
56
+ - `darwin-x64`
57
+ - `darwin-arm64`
58
+
59
+ At runtime the loader picks the matching binary from `prebuilds/<platform>/rom_node_native.node`.
52
60
 
53
61
  ## Common methods
54
62
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rxflex/rom",
3
- "version": "0.0.1",
3
+ "version": "0.0.5",
4
4
  "type": "module",
5
5
  "description": "Node.js wrapper for the ROM browser-like runtime",
6
6
  "license": "MIT",
@@ -27,6 +27,7 @@
27
27
  "prepack": "node ./scripts/build-native.mjs --release",
28
28
  "build:native": "node ./scripts/build-native.mjs --release",
29
29
  "build:native:debug": "node ./scripts/build-native.mjs",
30
+ "stage:prebuilds": "node ./scripts/stage-prebuilds.mjs",
30
31
  "smoke": "node ./scripts/smoke.mjs",
31
32
  "pack:check": "npm pack --dry-run"
32
33
  },
@@ -36,7 +37,7 @@
36
37
  "types": "./src/index.d.ts",
37
38
  "files": [
38
39
  "README.md",
39
- "rom_node_native.node",
40
+ "prebuilds",
40
41
  "src",
41
42
  "scripts",
42
43
  "native",
@@ -2,14 +2,18 @@ import { copyFileSync, existsSync, mkdirSync } from "node:fs";
2
2
  import path from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import { spawnSync } from "node:child_process";
5
+ import { detectNativePrebuildId } from "../src/platform.js";
5
6
 
6
7
  const __filename = fileURLToPath(import.meta.url);
7
8
  const __dirname = path.dirname(__filename);
8
9
  const packageRoot = path.resolve(__dirname, "..");
9
- const profile = process.argv.includes("--release") ? "release" : "debug";
10
+ const args = process.argv.slice(2);
11
+ const profile = args.includes("--release") ? "release" : "debug";
10
12
  const targetDir = process.env.CARGO_TARGET_DIR || path.join(packageRoot, "target");
11
13
  const artifactDir = path.join(targetDir, profile);
12
- const outputPath = path.join(packageRoot, "rom_node_native.node");
14
+ const outputPath =
15
+ readOptionValue(args, "--output") ||
16
+ defaultOutputPath();
13
17
 
14
18
  const cargoArgs = ["build", "--manifest-path", "Cargo.toml"];
15
19
  if (profile === "release") {
@@ -42,3 +46,27 @@ if (!existsSync(artifactPath)) {
42
46
  mkdirSync(path.dirname(outputPath), { recursive: true });
43
47
  copyFileSync(artifactPath, outputPath);
44
48
  console.log(`Built ${outputPath}`);
49
+
50
+ function readOptionValue(argv, optionName) {
51
+ const index = argv.indexOf(optionName);
52
+ if (index === -1) {
53
+ return null;
54
+ }
55
+
56
+ const value = argv[index + 1];
57
+ if (!value || value.startsWith("--")) {
58
+ console.error(`Missing value for ${optionName}`);
59
+ process.exit(1);
60
+ }
61
+
62
+ return path.resolve(packageRoot, value);
63
+ }
64
+
65
+ function defaultOutputPath() {
66
+ const prebuildId = detectNativePrebuildId();
67
+ if (prebuildId === null) {
68
+ return path.join(packageRoot, "rom_node_native.node");
69
+ }
70
+
71
+ return path.join(packageRoot, "prebuilds", prebuildId, "rom_node_native.node");
72
+ }
@@ -0,0 +1,47 @@
1
+ import { cpSync, existsSync, mkdirSync, readdirSync, rmSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = path.dirname(__filename);
7
+ const packageRoot = path.resolve(__dirname, "..");
8
+ const args = process.argv.slice(2);
9
+ const sourceRoot =
10
+ readOptionValue(args, "--source") || path.join(packageRoot, "release-inputs", "prebuilds");
11
+ const outputRoot =
12
+ readOptionValue(args, "--output") || path.join(packageRoot, "prebuilds");
13
+
14
+ if (!existsSync(sourceRoot)) {
15
+ console.error(`Prebuild source directory not found: ${sourceRoot}`);
16
+ process.exit(1);
17
+ }
18
+
19
+ rmSync(outputRoot, { recursive: true, force: true });
20
+ mkdirSync(outputRoot, { recursive: true });
21
+
22
+ for (const entry of readdirSync(sourceRoot, { withFileTypes: true })) {
23
+ if (!entry.isDirectory()) {
24
+ continue;
25
+ }
26
+
27
+ const sourceDir = path.join(sourceRoot, entry.name);
28
+ const outputDir = path.join(outputRoot, entry.name);
29
+ cpSync(sourceDir, outputDir, { recursive: true });
30
+ }
31
+
32
+ console.log(`Staged prebuilds from ${sourceRoot} to ${outputRoot}`);
33
+
34
+ function readOptionValue(argv, optionName) {
35
+ const index = argv.indexOf(optionName);
36
+ if (index === -1) {
37
+ return null;
38
+ }
39
+
40
+ const value = argv[index + 1];
41
+ if (!value || value.startsWith("--")) {
42
+ console.error(`Missing value for ${optionName}`);
43
+ process.exit(1);
44
+ }
45
+
46
+ return path.resolve(packageRoot, value);
47
+ }
package/src/native.js CHANGED
@@ -2,6 +2,7 @@ import { existsSync } from "node:fs";
2
2
  import path from "node:path";
3
3
  import { createRequire } from "node:module";
4
4
  import { fileURLToPath } from "node:url";
5
+ import { detectNativePrebuildId } from "./platform.js";
5
6
 
6
7
  const require = createRequire(import.meta.url);
7
8
  const __filename = fileURLToPath(import.meta.url);
@@ -16,6 +17,12 @@ function candidatePaths() {
16
17
  }
17
18
 
18
19
  candidates.push(path.join(packageRoot, "rom_node_native.node"));
20
+
21
+ const prebuildId = detectNativePrebuildId();
22
+ if (prebuildId !== null) {
23
+ candidates.push(path.join(packageRoot, "prebuilds", prebuildId, "rom_node_native.node"));
24
+ }
25
+
19
26
  return candidates;
20
27
  }
21
28
 
@@ -0,0 +1,31 @@
1
+ import process from "node:process";
2
+
3
+ export function detectNativePrebuildId() {
4
+ if (process.platform === "linux" && process.arch === "x64") {
5
+ if (detectLinuxLibcFlavor() !== "gnu") {
6
+ return null;
7
+ }
8
+ return "linux-x64-gnu";
9
+ }
10
+
11
+ if (process.platform === "win32" && process.arch === "x64") {
12
+ return "win32-x64-msvc";
13
+ }
14
+
15
+ if (process.platform === "darwin" && process.arch === "x64") {
16
+ return "darwin-x64";
17
+ }
18
+
19
+ if (process.platform === "darwin" && process.arch === "arm64") {
20
+ return "darwin-arm64";
21
+ }
22
+
23
+ return null;
24
+ }
25
+
26
+ function detectLinuxLibcFlavor() {
27
+ const report = process.report?.getReport?.();
28
+ const glibcVersion =
29
+ report?.header?.glibcVersionRuntime ?? report?.header?.glibcVersionCompiler ?? null;
30
+ return glibcVersion ? "gnu" : "musl";
31
+ }