Skip to content
Merged
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
134 changes: 134 additions & 0 deletions .github/workflows/build-native.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
name: Build Native

on:
push:
tags:
- 'v*'
workflow_dispatch:

permissions:
contents: write

jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
package: '@optave/codegraph-linux-x64-gnu'
node-arch: x64
node-os: linux
- os: macos-latest
target: aarch64-apple-darwin
package: '@optave/codegraph-darwin-arm64'
node-arch: arm64
node-os: darwin
- os: macos-13
target: x86_64-apple-darwin
package: '@optave/codegraph-darwin-x64'
node-arch: x64
node-os: darwin
- os: windows-latest
target: x86_64-pc-windows-msvc
package: '@optave/codegraph-win32-x64-msvc'
node-arch: x64
node-os: win32

runs-on: ${{ matrix.os }}
name: Build ${{ matrix.target }}

steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: 'https://registry.npmjs.org'

- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}

- name: Rust cache
uses: Swatinem/rust-cache@v2
with:
workspaces: crates/codegraph-core

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

- name: Build native addon
working-directory: crates/codegraph-core
run: napi build --release --target ${{ matrix.target }}

- name: Prepare platform package
shell: bash
run: |
PKG_DIR="npm/${{ matrix.node-os }}-${{ matrix.node-arch }}"
mkdir -p "$PKG_DIR"

# Copy the built .node file (use glob to avoid Windows find issues)
cp crates/codegraph-core/*.node "$PKG_DIR/codegraph-core.node"

# Read version from root package.json
VERSION=$(node -p "require('./package.json').version")

# Generate package.json for the platform package
cat > "$PKG_DIR/package.json" <<EOF
{
"name": "${{ matrix.package }}",
"version": "${VERSION}",
"description": "Native codegraph-core binary for ${{ matrix.node-os }}-${{ matrix.node-arch }}",
"os": ["${{ matrix.node-os }}"],
"cpu": ["${{ matrix.node-arch }}"],
"main": "codegraph-core.node",
"files": ["codegraph-core.node"],
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "https://github.com/optave/codegraph.git"
}
}
EOF

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: native-${{ matrix.node-os }}-${{ matrix.node-arch }}
path: npm/${{ matrix.node-os }}-${{ matrix.node-arch }}/
if-no-files-found: error

publish:
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')

steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: 'https://registry.npmjs.org'

- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts/

- name: Publish platform packages
shell: bash
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
for dir in artifacts/native-*/; do
echo "Publishing $(cat "$dir/package.json" | grep '"name"')"
cd "$dir"
npm publish --access public || true
cd -
done
53 changes: 53 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: CI

on:
push:
branches: [main]
pull_request:

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node-version: [20, 22]

runs-on: ${{ matrix.os }}
name: Test Node ${{ matrix.node-version }} (${{ matrix.os }})

steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: npm install --legacy-peer-deps

- name: Run tests
run: npm test

rust-check:
runs-on: ubuntu-latest
name: Rust compile check

steps:
- uses: actions/checkout@v4

- name: Setup Rust
uses: dtolnay/rust-toolchain@stable

- name: Rust cache
uses: Swatinem/rust-cache@v2
with:
workspaces: crates/codegraph-core

- name: Check compilation
run: cargo check --workspace
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[workspace]
members = ["crates/codegraph-core"]
resolver = "2"
30 changes: 30 additions & 0 deletions crates/codegraph-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "codegraph-core"
version = "0.1.0"
edition = "2021"
license = "Apache-2.0"

[lib]
crate-type = ["cdylib"]

[dependencies]
napi = { version = "3", features = ["serde-json"] }
napi-derive = "3"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tree-sitter = "0.24"
tree-sitter-javascript = "0.23"
tree-sitter-typescript = "0.23"
tree-sitter-python = "0.23"
tree-sitter-go = "0.23"
tree-sitter-rust = "0.23"
tree-sitter-java = "0.23"
tree-sitter-c-sharp = "0.23"
tree-sitter-ruby = "0.23"
tree-sitter-php = "0.23"
tree-sitter-hcl = "1"
rayon = "1"
send_wrapper = "0.6"

[build-dependencies]
napi-build = "2"
5 changes: 5 additions & 0 deletions crates/codegraph-core/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extern crate napi_build;

fn main() {
napi_build::setup();
}
Loading