singularity-forge/native
Lex Christopherson bd8380315c feat: per-platform optional dependencies for native binary distribution
Add the esbuild/swc pattern for distributing platform-specific native
binaries via npm optional dependencies. Each supported platform gets its
own @gsd/engine-{platform} package containing just the .node binary.

- 5 platform package stubs (darwin-arm64, darwin-x64, linux-x64-gnu,
  linux-arm64-gnu, win32-x64-msvc) with os/cpu filters
- Rewritten native loader: tries npm package first, then local build
- Version sync script keeps platform packages in lock-step with root
- GitHub Actions workflow for cross-platform build + publish on tag push

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-13 14:36:18 -06:00
..
.cargo feat: Rust native engine scaffold with grep module 2026-03-13 12:21:09 -06:00
crates feat: add native Rust GSD file parser for .gsd/ directory parsing 2026-03-13 14:12:17 -06:00
npm feat: per-platform optional dependencies for native binary distribution 2026-03-13 14:36:18 -06:00
scripts feat: per-platform optional dependencies for native binary distribution 2026-03-13 14:36:18 -06:00
.gitignore feat: Rust native engine scaffold with grep module 2026-03-13 12:21:09 -06:00
.npmignore fix: include darwin-arm64 native binary in npm tarball (Phase A hotfix) 2026-03-13 14:33:37 -06:00
Cargo.lock chore: update Cargo.lock 2026-03-13 14:21:14 -06:00
Cargo.toml feat: Rust native engine scaffold with grep module 2026-03-13 12:21:09 -06:00
README.md feat: Rust native engine scaffold with grep module 2026-03-13 12:21:09 -06:00

GSD Native Engine

Rust N-API addon providing high-performance native modules for GSD.

Architecture

JS (packages/native) -> N-API -> Rust crates
                                  ├── engine/  (N-API bindings, cdylib)
                                  └── grep/    (ripgrep internals, pure Rust lib)

Inspired by Oh My Pi's pi-natives, adapted for GSD's Node.js runtime.

Prerequisites

Build

# Release build (optimized)
npm run build:native

# Debug build (fast compile, no optimizations)
npm run build:native:dev

The build script compiles the Rust code and copies the .node shared library to native/addon/.

Test

# Rust unit tests
cd native && cargo test

# Node.js integration tests
npm run test:native

Modules

grep

Ripgrep-backed regex search using the grep-regex, grep-searcher, and grep-matcher crates.

Functions:

  • search(content, options) — Search in-memory Buffer/Uint8Array content
  • grep(options) — Search files on disk with glob filtering and .gitignore support

TypeScript usage:

import { grep, searchContent } from "@gsd/native";

// Search files
const result = grep({
  pattern: "TODO",
  path: "./src",
  glob: "*.ts",
  ignoreCase: true,
  maxCount: 100,
});

// Search content
const contentResult = searchContent(Buffer.from(fileContent), {
  pattern: "function\\s+\\w+",
  contextBefore: 2,
  contextAfter: 2,
});

Adding New Modules

  1. Create a new crate in native/crates/ (pure Rust library)
  2. Add N-API bindings in native/crates/engine/src/
  3. Add TypeScript wrapper in packages/native/src/
  4. Add the crate to engine/Cargo.toml dependencies