Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion .github/workflows/build-native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,34 @@ jobs:
target: x86_64-unknown-linux-gnu
node_arch: x64
node_os: linux
artifact_key: linux-x64
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
node_arch: arm64
node_os: linux
artifact_key: linux-arm64
cross: true
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
node_arch: x64
node_os: linux
artifact_key: linux-x64-musl
cross: true
- os: macos-latest
target: aarch64-apple-darwin
node_arch: arm64
node_os: darwin
artifact_key: darwin-arm64
- os: macos-14
target: x86_64-apple-darwin
node_arch: x64
node_os: darwin
artifact_key: darwin-x64
- os: windows-latest
target: x86_64-pc-windows-msvc
node_arch: x64
node_os: win32
artifact_key: win32-x64

runs-on: ${{ matrix.os }}
name: Build ${{ matrix.target }}
Expand All @@ -56,6 +72,29 @@ jobs:
with:
workspaces: crates/codegraph-core

- name: Install cross-compilation tools (aarch64-gnu)
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
echo "CC=aarch64-linux-gnu-gcc" >> "$GITHUB_ENV"
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> "$GITHUB_ENV"

- name: Install cross-compilation tools (x86_64-musl)
if: matrix.target == 'x86_64-unknown-linux-musl'
run: |
sudo apt-get update
sudo apt-get install -y musl-tools
# Create linker script so -lgcc_s resolves to static libgcc
MUSL_LIB_DIR="$(dirname "$(musl-gcc -print-libgcc-file-name)")"
echo 'INPUT(-lgcc)' | sudo tee "${MUSL_LIB_DIR}/libgcc_s.so" > /dev/null
echo "CC_x86_64_unknown_linux_musl=musl-gcc" >> "$GITHUB_ENV"
echo "CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=musl-gcc" >> "$GITHUB_ENV"
# Symlink libgcc_s into Rust sysroot so rust-lld can find it for host builds
GNU_LIB="$(rustc --print sysroot)/lib/rustlib/x86_64-unknown-linux-gnu/lib"
sudo ln -sf /lib/x86_64-linux-gnu/libgcc_s.so.1 "${GNU_LIB}/libgcc_s.so"
sudo ln -sf /lib/x86_64-linux-gnu/libgcc_s.so.1 "${GNU_LIB}/libgcc_s.so.1"

- name: Install napi-rs CLI
run: npm install -g @napi-rs/cli@3

Expand All @@ -66,6 +105,6 @@ jobs:
- name: Upload artifact
uses: actions/upload-artifact@v7
with:
name: native-${{ matrix.node_os }}-${{ matrix.node_arch }}
name: native-${{ matrix.artifact_key }}
path: crates/codegraph-core/*.node
if-no-files-found: error
103 changes: 87 additions & 16 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,34 @@ jobs:
target: x86_64-unknown-linux-gnu
node_arch: x64
node_os: linux
artifact_key: linux-x64
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
node_arch: arm64
node_os: linux
artifact_key: linux-arm64
cross: true
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
node_arch: x64
node_os: linux
artifact_key: linux-x64-musl
cross: true
- os: macos-latest
target: aarch64-apple-darwin
node_arch: arm64
node_os: darwin
artifact_key: darwin-arm64
- os: macos-14
target: x86_64-apple-darwin
node_arch: x64
node_os: darwin
artifact_key: darwin-x64
- os: windows-latest
target: x86_64-pc-windows-msvc
node_arch: x64
node_os: win32
artifact_key: win32-x64

runs-on: ${{ matrix.os }}
name: Build ${{ matrix.target }}
Expand All @@ -133,6 +149,29 @@ jobs:
with:
workspaces: crates/codegraph-core

- name: Install cross-compilation tools (aarch64-gnu)
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
echo "CC=aarch64-linux-gnu-gcc" >> "$GITHUB_ENV"
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> "$GITHUB_ENV"

- name: Install cross-compilation tools (x86_64-musl)
if: matrix.target == 'x86_64-unknown-linux-musl'
run: |
sudo apt-get update
sudo apt-get install -y musl-tools
# Create linker script so -lgcc_s resolves to static libgcc
MUSL_LIB_DIR="$(dirname "$(musl-gcc -print-libgcc-file-name)")"
echo 'INPUT(-lgcc)' | sudo tee "${MUSL_LIB_DIR}/libgcc_s.so" > /dev/null
echo "CC_x86_64_unknown_linux_musl=musl-gcc" >> "$GITHUB_ENV"
echo "CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=musl-gcc" >> "$GITHUB_ENV"
# Symlink libgcc_s into Rust sysroot so rust-lld can find it for host builds
GNU_LIB="$(rustc --print sysroot)/lib/rustlib/x86_64-unknown-linux-gnu/lib"
sudo ln -sf /lib/x86_64-linux-gnu/libgcc_s.so.1 "${GNU_LIB}/libgcc_s.so"
sudo ln -sf /lib/x86_64-linux-gnu/libgcc_s.so.1 "${GNU_LIB}/libgcc_s.so.1"

- name: Install napi-rs CLI
run: npm install -g @napi-rs/cli@3

Expand All @@ -143,7 +182,7 @@ jobs:
- name: Upload native binary
uses: actions/upload-artifact@v7
with:
name: native-${{ matrix.node_os }}-${{ matrix.node_arch }}
name: native-${{ matrix.artifact_key }}
path: crates/codegraph-core/*.node
if-no-files-found: error

Expand Down Expand Up @@ -189,32 +228,46 @@ jobs:
VERSION: ${{ needs.compute-version.outputs.version }}
shell: bash
run: |
# Format: pkg_name|os|cpu|libc (libc empty for non-linux)
declare -A PACKAGES=(
["linux-x64"]="@optave/codegraph-linux-x64-gnu"
["darwin-arm64"]="@optave/codegraph-darwin-arm64"
["darwin-x64"]="@optave/codegraph-darwin-x64"
["win32-x64"]="@optave/codegraph-win32-x64-msvc"
["linux-x64"]="@optave/codegraph-linux-x64-gnu|linux|x64|glibc"
["linux-x64-musl"]="@optave/codegraph-linux-x64-musl|linux|x64|musl"
["linux-arm64"]="@optave/codegraph-linux-arm64-gnu|linux|arm64|glibc"
["darwin-arm64"]="@optave/codegraph-darwin-arm64|darwin|arm64|"
["darwin-x64"]="@optave/codegraph-darwin-x64|darwin|x64|"
["win32-x64"]="@optave/codegraph-win32-x64-msvc|win32|x64|"
)

ARTIFACTS="${RUNNER_TEMP}/artifacts"
PKG_DIR="${RUNNER_TEMP}/pkg"

for artifact_dir in "${ARTIFACTS}"/native-*/; do
platform=$(basename "$artifact_dir" | sed 's/^native-//')
pkg_name=${PACKAGES[$platform]}
node_os=${platform%%-*}
node_arch=${platform##*-}
entry=${PACKAGES[$platform]}
if [ -z "$entry" ]; then
echo "::warning::Unknown platform artifact: $platform — skipping"
continue
fi

IFS='|' read -r pkg_name node_os node_arch libc <<< "$entry"

mkdir -p "${PKG_DIR}/$platform"
cp "$artifact_dir"/*.node "${PKG_DIR}/$platform/codegraph-core.node"

# Build libc field for Linux packages
libc_field=""
if [ -n "$libc" ]; then
libc_field="\"libc\": [\"${libc}\"],"
fi

cat > "${PKG_DIR}/$platform/package.json" <<PKGJSON
{
"name": "${pkg_name}",
"version": "${VERSION}",
"description": "Native codegraph-core binary for ${node_os}-${node_arch}",
"os": ["${node_os}"],
"cpu": ["${node_arch}"],
${libc_field}
"main": "codegraph-core.node",
"files": ["codegraph-core.node"],
"license": "Apache-2.0",
Expand Down Expand Up @@ -288,8 +341,12 @@ jobs:
npm install ${{ github.server_url }}/${{ github.repository }}/releases/download/${TAG}/optave-codegraph-${VERSION}.tgz

# For native performance, also install your platform package:
# Linux x64:
# Linux x64 (glibc):
npm install ${{ github.server_url }}/${{ github.repository }}/releases/download/${TAG}/optave-codegraph-linux-x64-gnu-${VERSION}.tgz
# Linux x64 (musl/Alpine):
npm install ${{ github.server_url }}/${{ github.repository }}/releases/download/${TAG}/optave-codegraph-linux-x64-musl-${VERSION}.tgz
# Linux arm64 (glibc):
npm install ${{ github.server_url }}/${{ github.repository }}/releases/download/${TAG}/optave-codegraph-linux-arm64-gnu-${VERSION}.tgz
# macOS arm64:
npm install ${{ github.server_url }}/${{ github.repository }}/releases/download/${TAG}/optave-codegraph-darwin-arm64-${VERSION}.tgz
\`\`\`
Expand Down Expand Up @@ -363,32 +420,46 @@ jobs:
NPM_TAG: ${{ needs.compute-version.outputs.npm_tag }}
shell: bash
run: |
# Format: pkg_name|os|cpu|libc (libc empty for non-linux)
declare -A PACKAGES=(
["linux-x64"]="@optave/codegraph-linux-x64-gnu"
["darwin-arm64"]="@optave/codegraph-darwin-arm64"
["darwin-x64"]="@optave/codegraph-darwin-x64"
["win32-x64"]="@optave/codegraph-win32-x64-msvc"
["linux-x64"]="@optave/codegraph-linux-x64-gnu|linux|x64|glibc"
["linux-x64-musl"]="@optave/codegraph-linux-x64-musl|linux|x64|musl"
["linux-arm64"]="@optave/codegraph-linux-arm64-gnu|linux|arm64|glibc"
["darwin-arm64"]="@optave/codegraph-darwin-arm64|darwin|arm64|"
["darwin-x64"]="@optave/codegraph-darwin-x64|darwin|x64|"
["win32-x64"]="@optave/codegraph-win32-x64-msvc|win32|x64|"
)

ARTIFACTS="${RUNNER_TEMP}/artifacts"
PKG_DIR="${RUNNER_TEMP}/pkg"

for artifact_dir in "${ARTIFACTS}"/native-*/; do
platform=$(basename "$artifact_dir" | sed 's/^native-//')
pkg_name=${PACKAGES[$platform]}
node_os=${platform%%-*}
node_arch=${platform##*-}
entry=${PACKAGES[$platform]}
if [ -z "$entry" ]; then
echo "::warning::Unknown platform artifact: $platform — skipping"
continue
fi

IFS='|' read -r pkg_name node_os node_arch libc <<< "$entry"

mkdir -p "${PKG_DIR}/$platform"
cp "$artifact_dir"/*.node "${PKG_DIR}/$platform/codegraph-core.node"

# Build libc field for Linux packages
libc_field=""
if [ -n "$libc" ]; then
libc_field="\"libc\": [\"${libc}\"],"
fi

cat > "${PKG_DIR}/$platform/package.json" <<PKGJSON
{
"name": "${pkg_name}",
"version": "${VERSION}",
"description": "Native codegraph-core binary for ${node_os}-${node_arch}",
"os": ["${node_os}"],
"cpu": ["${node_arch}"],
${libc_field}
"main": "codegraph-core.node",
"files": ["codegraph-core.node"],
"license": "Apache-2.0",
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. See [commit

* **ast:** use single transaction for AST node insertion — astMs drops from ~3600ms to ~350ms (native) and ~547ms (WASM), reducing overall native build from 24.9 to 8.5 ms/file ([#333](https://github.com/optave/codegraph/pull/333))


## [3.0.2](https://github.com/optave/codegraph/compare/v3.0.1...v3.0.2) (2026-03-04)

**Dataflow goes multi-language, build performance recovery, and native engine parity fixes.** This patch extends dataflow analysis from JS/TS-only to all 11 supported languages, recovers build performance lost after CFG/dataflow became default-on, fixes language-aware identifier collection in dataflow, and closes a native engine scoping bug for constants.
Expand Down
2 changes: 2 additions & 0 deletions crates/codegraph-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"binaryName": "codegraph-core",
"targets": [
"x86_64-unknown-linux-gnu",
"aarch64-unknown-linux-gnu",
"x86_64-unknown-linux-musl",
"aarch64-apple-darwin",
"x86_64-apple-darwin",
"x86_64-pc-windows-msvc"
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@
"@modelcontextprotocol/sdk": "^1.0.0",
"@optave/codegraph-darwin-arm64": "3.0.3",
"@optave/codegraph-darwin-x64": "3.0.3",
"@optave/codegraph-linux-arm64-gnu": "3.0.3",
"@optave/codegraph-linux-arm64-musl": "3.0.3",
"@optave/codegraph-linux-x64-gnu": "3.0.3",
"@optave/codegraph-linux-x64-musl": "3.0.3",
"@optave/codegraph-win32-x64-msvc": "3.0.3"
},
"devDependencies": {
Expand Down
26 changes: 23 additions & 3 deletions src/native.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,27 @@ import os from 'node:os';
let _cached; // undefined = not yet tried, null = failed, object = module
let _loadError = null;

/** Map of (platform-arch) → npm package name. */
/**
* Detect whether the current Linux environment uses glibc or musl.
* Returns 'gnu' for glibc, 'musl' for musl, 'gnu' as fallback.
*/
function detectLibc() {
try {
const { readdirSync } = require('node:fs');
const files = readdirSync('/lib');
if (files.some((f) => f.startsWith('ld-musl-') && f.endsWith('.so.1'))) {
return 'musl';
}
} catch {}
return 'gnu';
}

/** Map of (platform-arch[-libc]) → npm package name. */
const PLATFORM_PACKAGES = {
'linux-x64': '@optave/codegraph-linux-x64-gnu',
'linux-x64-gnu': '@optave/codegraph-linux-x64-gnu',
'linux-x64-musl': '@optave/codegraph-linux-x64-musl',
'linux-arm64-gnu': '@optave/codegraph-linux-arm64-gnu',
'linux-arm64-musl': '@optave/codegraph-linux-arm64-musl', // not yet published — placeholder for future CI target
'darwin-arm64': '@optave/codegraph-darwin-arm64',
'darwin-x64': '@optave/codegraph-darwin-x64',
'win32-x64': '@optave/codegraph-win32-x64-msvc',
Expand All @@ -29,7 +47,9 @@ export function loadNative() {

const require = createRequire(import.meta.url);

const key = `${os.platform()}-${os.arch()}`;
const platform = os.platform();
const arch = os.arch();
const key = platform === 'linux' ? `${platform}-${arch}-${detectLibc()}` : `${platform}-${arch}`;
const pkg = PLATFORM_PACKAGES[key];
if (pkg) {
try {
Expand Down