Skip to content

Commit

Permalink
build: switch to prebuildify
Browse files Browse the repository at this point in the history
  • Loading branch information
ObserverOfTime authored and amaanq committed Mar 10, 2024
1 parent 245510c commit 2bdc76a
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 89 deletions.
64 changes: 27 additions & 37 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ on:
push:
branches:
- master
tags:
- v*
pull_request:
branches:
- master
release:
types:
- released

env:
PREBUILD_CMD: npx prebuild -r napi --all --strip -u ${{ secrets.GH_TOKEN }}
concurrency:
group: ${{github.workflow}}-${{github.ref}}
cancel-in-progress: true

jobs:

jobs:
test:
strategy:
matrix:
os:
- windows-2019
- windows-2022
- macos-14
- ubuntu-20.04
- ubuntu-22.04
node:
- 18
- 20
Expand All @@ -37,15 +37,23 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}

- run: npm install
- run: npm run build -- --arch x64
- if: runner.os == 'macOS'
run: npm run build -- --arch arm64
- run: npm test
- uses: actions/upload-artifact@v4
if: github.ref_type == 'tag' && matrix.node == 20
with:
path: prebuilds/**
name: prebuilds-${{matrix.os}}
retention-days: 2

publish:
if: ${{ github.event_name == 'release' }}
if: github.ref_type == 'tag'
name: Publish to npm
runs-on: ubuntu-20.04
needs: test
runs-on: ubuntu-22.04
needs: [test]
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -55,31 +63,13 @@ jobs:
with:
node-version: 20
registry-url: https://registry.npmjs.org
- uses: actions/download-artifact@v4
with:
path: prebuilds
pattern: prebuilds-*
merge-multiple: true
- run: tree prebuilds
- run: npm install
- run: npm publish --access public
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

prebuild:
strategy:
matrix:
os:
- windows-2019
- macos-14
- ubuntu-20.04
fail-fast: false
name: Prebuild for ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs: publish
steps:
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm install
- run: ${{ env.PREBUILD_CMD }}
- if: runner.os == 'macOS'
run: ${{ env.PREBUILD_CMD }} --arch arm64
57 changes: 30 additions & 27 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"targets": [
{
"target_name": "tree_sitter_runtime_binding",
"dependencies": ["tree_sitter", "<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except"],
"dependencies": [
"tree_sitter",
"<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except",
],
"sources": [
"src/binding.cc",
"src/conversions.cc",
Expand All @@ -21,40 +24,40 @@
"defines": [
"NAPI_VERSION=<(napi_build_version)",
],
'cflags': [
'-std=c++17'
"cflags": [
"-std=c++17"
],
'cflags_cc': [
'-std=c++17'
"cflags_cc": [
"-std=c++17"
],
'conditions': [
['OS=="mac"', {
'xcode_settings': {
'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', # -fvisibility=hidden
'CLANG_CXX_LANGUAGE_STANDARD': 'c++17',
'MACOSX_DEPLOYMENT_TARGET': '10.9',
"conditions": [
["OS=='mac'", {
"xcode_settings": {
"GCC_SYMBOLS_PRIVATE_EXTERN": "YES", # -fvisibility=hidden
"CLANG_CXX_LANGUAGE_STANDARD": "c++17",
"MACOSX_DEPLOYMENT_TARGET": "10.9",
},
}],
['OS=="win"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': [
'/std:c++17',
["OS=='win'", {
"msvs_settings": {
"VCCLCompilerTool": {
"AdditionalOptions": [
"/std:c++17",
],
'RuntimeLibrary': 0,
"RuntimeLibrary": 0,
},
},
}],
['OS == "linux"', {
'cflags_cc': [
'-Wno-cast-function-type'
["OS == 'linux'", {
"cflags_cc": [
"-Wno-cast-function-type"
]
}],
]
},
{
"target_name": "tree_sitter",
'type': 'static_library',
"type": "static_library",
"sources": [
"vendor/tree-sitter/lib/src/lib.c"
],
Expand All @@ -63,14 +66,14 @@
"vendor/tree-sitter/lib/include",
],
"cflags": [
"-std=c99"
"-std=c11"
]
}
],
'variables': {
'runtime%': 'node',
'openssl_fips': '',
'v8_enable_pointer_compression%': 0,
'v8_enable_31bit_smis_on_64bit_arch%': 0,
"variables": {
"runtime%": "node",
"openssl_fips": "",
"v8_enable_pointer_compression%": 0,
"v8_enable_31bit_smis_on_64bit_arch%": 0,
}
}
15 changes: 3 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
let binding;
try {
binding = require('./build/Release/tree_sitter_runtime_binding');
} catch (e) {
try {
binding = require('./build/Debug/tree_sitter_runtime_binding');
} catch (_) {
throw e;
}
}

const util = require('util')
const binding = require('node-gyp-build')(__dirname);
const {Query, Parser, NodeMethods, Tree, TreeCursor, LookaheadIterator} = binding;

const util = require('util');

/*
* Tree
*/
Expand Down
39 changes: 26 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,43 @@
{
"name": "tree-sitter",
"version": "0.20.6",
"version": "0.21.0",
"description": "Incremental parsers for node",
"author": "Max Brunsfeld",
"contributors": [
"Segev Finer",
"Boris Verkhovskiy",
"Amaan Qureshi"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "http://github.com/tree-sitter/node-tree-sitter.git"
},
"keywords": [
"parser",
"lexer"
"incremental",
"parsing",
"tree-sitter"
],
"main": "index.js",
"types": "tree-sitter.d.ts",
"files": [
"binding.gyp",
"tree-sitter.d.ts",
"prebuilds/*",
"src/*",
"vendor/tree-sitter/lib/include/*",
"vendor/tree-sitter/lib/src/*"
],
"dependencies": {
"node-addon-api": "^7.1.0",
"prebuild-install": "^7.1.1"
"node-gyp-build": "^4.8.0"
},
"devDependencies": {
"@types/node": "^20.11.16",
"chai": "^4.3.10",
"mocha": "^8.4.0",
"node-gyp": "^10.0.1",
"prebuild": "^13.0.0",
"prebuildify": "^6.0.0",
"tmp": "^0.2.1",
"tree-sitter-c": "github:amaanq/tree-sitter-c#napi",
"tree-sitter-embedded-template": "github:tree-sitter/tree-sitter-embedded-template#napi",
Expand All @@ -32,17 +46,16 @@
"tree-sitter-javascript": "github:amaanq/tree-sitter-javascript#napi",
"tree-sitter-json": "github:tree-sitter/tree-sitter-json#napi",
"tree-sitter-python": "github:amaanq/tree-sitter-python#napi",
"tree-sitter-rust": "github:amaanq/tree-sitter-rust#napi",
"tree-sitter-ruby": "github:tree-sitter/tree-sitter-ruby#napi"
"tree-sitter-ruby": "github:tree-sitter/tree-sitter-ruby#napi",
"tree-sitter-rust": "github:amaanq/tree-sitter-rust#napi"
},
"scripts": {
"install": "prebuild-install -r napi || node-gyp rebuild",
"build": "node-gyp build",
"install": "node-gyp-build",
"build": "prebuildify --napi --strip",
"rebuild": "node-gyp rebuild",
"test": "mocha"
},
"binary": {
"napi_versions": [
8
]
"publishConfig": {
"access": "public"
}
}

0 comments on commit 2bdc76a

Please sign in to comment.