singularity-forge/native/scripts/build.js
ace-pm 172753c3b2 refactor(forge): complete gsd → forge rebrand across native, logging, and build system
- Rename native Rust crates: gsd-engine → forge-engine, gsd-ast → forge-ast, gsd-grep → forge-grep
- Update all crate dependencies (Cargo.toml, .rs source) and N-API artifacts
- Mass rename log prefix [gsd] → [forge] across 81 files (scripts, src/, extensions, tests)
- Rename log prefix "gsd-db:" → "forge-db:" in template literals
- Update nix flake: add sf-run-native devShell with Rust toolchain for native addon builds
- Update CI workflow artifact names (build-native.yml)
- Verify only packages/native/* touched (no upstream pi-* packages renamed)

Rationale: Complete gsd-2 → singularity-forge rebrand (2026-04-15). Native addon is
sf-run-specific; all gsd-prefixed logging and crate names must align with new identity.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 14:11:45 +02:00

81 lines
2.3 KiB
JavaScript

#!/usr/bin/env node
/**
* Build script for the GSD native Rust addon.
*
* Usage:
* node native/scripts/build.js # release build
* node native/scripts/build.js --dev # debug build
*
* Runs `cargo build` in the engine crate directory and copies the resulting
* shared library to `native/addon/` with a `.node` extension so Node.js
* can load it via `require()`.
*/
import { execSync } from "node:child_process";
import * as fs from "node:fs";
import * as path from "node:path";
import { fileURLToPath } from "node:url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const nativeRoot = path.resolve(__dirname, "..");
const engineDir = path.join(nativeRoot, "crates", "engine");
const addonDir = path.join(nativeRoot, "addon");
const isDev = process.argv.includes("--dev");
const profile = isDev ? "debug" : "release";
const cargoArgs = ["build"];
if (!isDev) cargoArgs.push("--release");
console.log(`Building forge-engine (${profile})...`);
try {
execSync(`cargo ${cargoArgs.join(" ")}`, {
cwd: engineDir,
stdio: "inherit",
env: {
...process.env,
// Optimize for native CPU when building locally
RUSTFLAGS: process.env.RUSTFLAGS || "-C target-cpu=native",
},
});
} catch {
process.exit(1);
}
// Locate the built library
const cargoTargetRoot = process.env.CARGO_TARGET_DIR
? path.resolve(process.env.CARGO_TARGET_DIR)
: path.join(nativeRoot, "target");
const targetDir = path.join(cargoTargetRoot, profile);
const platformTag = `${process.platform}-${process.arch}`;
const libraryNames = {
darwin: "libforge_engine.dylib",
linux: "libforge_engine.so",
win32: "forge_engine.dll",
};
const libName = libraryNames[process.platform];
if (!libName) {
console.error(`Unsupported platform: ${process.platform}`);
process.exit(1);
}
const sourcePath = path.join(targetDir, libName);
if (!fs.existsSync(sourcePath)) {
console.error(`Built library not found at: ${sourcePath}`);
process.exit(1);
}
fs.mkdirSync(addonDir, { recursive: true });
const destFilename = isDev
? "forge_engine.dev.node"
: `forge_engine.${platformTag}.node`;
const destPath = path.join(addonDir, destFilename);
fs.copyFileSync(sourcePath, destPath);
console.log(`Installed: ${destPath}`);
console.log("Build complete.");