Skip to content

Commit 1c7df7b

Browse files
committed
use napi-rs
1 parent 25c3951 commit 1c7df7b

File tree

23 files changed

+2546
-1
lines changed

23 files changed

+2546
-1
lines changed
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
name: node-js builds
2+
env:
3+
DEBUG: napi:*
4+
APP_NAME: cpp-linter
5+
MACOSX_DEPLOYMENT_TARGET: '10.13'
6+
permissions:
7+
contents: write
8+
id-token: write
9+
on:
10+
push:
11+
branches:
12+
- main
13+
tags-ignore:
14+
- '**'
15+
paths-ignore:
16+
- '**/*.md'
17+
- LICENSE
18+
- '**/*.gitignore'
19+
- .editorconfig
20+
- docs/**
21+
pull_request: null
22+
jobs:
23+
build:
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
settings:
28+
- host: macos-latest
29+
target: x86_64-apple-darwin
30+
build: yarn build --target x86_64-apple-darwin
31+
- host: windows-latest
32+
build: yarn build --target x86_64-pc-windows-msvc
33+
target: x86_64-pc-windows-msvc
34+
- host: ubuntu-latest
35+
target: x86_64-unknown-linux-gnu
36+
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
37+
build: yarn build --target x86_64-unknown-linux-gnu
38+
name: stable - ${{ matrix.settings.target }} - node@20
39+
runs-on: ${{ matrix.settings.host }}
40+
steps:
41+
- uses: actions/checkout@v4
42+
- name: Setup node
43+
uses: actions/setup-node@v4
44+
if: ${{ !matrix.settings.docker }}
45+
with:
46+
node-version: 20
47+
cache: yarn
48+
- name: Install
49+
uses: dtolnay/rust-toolchain@stable
50+
if: ${{ !matrix.settings.docker }}
51+
with:
52+
toolchain: stable
53+
targets: ${{ matrix.settings.target }}
54+
- name: Cache cargo
55+
uses: actions/cache@v4
56+
with:
57+
path: |
58+
~/.cargo/registry/index/
59+
~/.cargo/registry/cache/
60+
~/.cargo/git/db/
61+
.cargo-cache
62+
target/
63+
key: ${{ matrix.settings.target }}-cargo-${{ matrix.settings.host }}
64+
- uses: goto-bus-stop/setup-zig@v2
65+
if: ${{ matrix.settings.target == 'armv7-unknown-linux-gnueabihf' || matrix.settings.target == 'armv7-unknown-linux-musleabihf' }}
66+
with:
67+
version: 0.13.0
68+
- name: Setup toolchain
69+
run: ${{ matrix.settings.setup }}
70+
if: ${{ matrix.settings.setup }}
71+
shell: bash
72+
- name: Setup node x86
73+
working-directory: node-binding
74+
if: matrix.settings.target == 'i686-pc-windows-msvc'
75+
run: yarn config set supportedArchitectures.cpu "ia32"
76+
shell: bash
77+
- name: Install dependencies
78+
working-directory: node-binding
79+
run: yarn install
80+
- name: Setup node x86
81+
uses: actions/setup-node@v4
82+
if: matrix.settings.target == 'i686-pc-windows-msvc'
83+
with:
84+
node-version: 20
85+
cache: yarn
86+
architecture: x86
87+
- name: Build in docker
88+
uses: addnab/docker-run-action@v3
89+
if: ${{ matrix.settings.docker }}
90+
with:
91+
image: ${{ matrix.settings.docker }}
92+
options: >-
93+
--user 0:0
94+
-v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db
95+
-v ${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache
96+
-v ${{ github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index
97+
-v ${{ github.workspace }}:/build
98+
-w /build/node-binding
99+
run: ${{ matrix.settings.build }}
100+
- name: Build
101+
run: ${{ matrix.settings.build }}
102+
if: ${{ !matrix.settings.docker }}
103+
working-directory: node-binding
104+
shell: bash
105+
- name: Upload artifact
106+
uses: actions/upload-artifact@v4
107+
with:
108+
name: bindings-${{ matrix.settings.target }}
109+
path: node-binding/${{ env.APP_NAME }}.*.node
110+
if-no-files-found: error
111+
test-macOS-windows-binding:
112+
name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
113+
needs:
114+
- build
115+
strategy:
116+
fail-fast: false
117+
matrix:
118+
settings:
119+
- host: macos-latest
120+
target: x86_64-apple-darwin
121+
- host: windows-latest
122+
target: x86_64-pc-windows-msvc
123+
node:
124+
- '18'
125+
- '20'
126+
runs-on: ${{ matrix.settings.host }}
127+
steps:
128+
- uses: actions/checkout@v4
129+
- name: Setup node
130+
uses: actions/setup-node@v4
131+
with:
132+
node-version: ${{ matrix.node }}
133+
cache: yarn
134+
architecture: x64
135+
- name: Install dependencies
136+
working-directory: node-binding
137+
run: yarn install
138+
- name: Download artifacts
139+
uses: actions/download-artifact@v4
140+
with:
141+
name: bindings-${{ matrix.settings.target }}
142+
path: node-binding
143+
- name: List packages
144+
run: ls -R .
145+
working-directory: node-binding
146+
shell: bash
147+
- name: Test bindings
148+
working-directory: node-binding
149+
run: yarn test
150+
test-linux-x64-gnu-binding:
151+
name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
152+
needs:
153+
- build
154+
strategy:
155+
fail-fast: false
156+
matrix:
157+
node:
158+
- '18'
159+
- '20'
160+
runs-on: ubuntu-latest
161+
steps:
162+
- uses: actions/checkout@v4
163+
- name: Setup node
164+
uses: actions/setup-node@v4
165+
with:
166+
node-version: ${{ matrix.node }}
167+
cache: yarn
168+
- name: Install dependencies
169+
run: yarn install
170+
- name: Download artifacts
171+
uses: actions/download-artifact@v4
172+
with:
173+
name: bindings-x86_64-unknown-linux-gnu
174+
path: node-binding
175+
- name: List packages
176+
run: ls -R .
177+
working-directory: node-binding
178+
shell: bash
179+
- name: Test bindings
180+
run: >-
181+
docker run --rm
182+
-v $(pwd):/build
183+
-w /build/node-binding
184+
node:${{ matrix.node }}-slim
185+
yarn test
186+
publish:
187+
name: Publish
188+
runs-on: ubuntu-latest
189+
needs:
190+
- test-macOS-windows-binding
191+
- test-linux-x64-gnu-binding
192+
steps:
193+
- uses: actions/checkout@v4
194+
- name: Setup node
195+
uses: actions/setup-node@v4
196+
with:
197+
node-version: 20
198+
cache: yarn
199+
- name: Install dependencies
200+
run: yarn install
201+
- name: Download all artifacts
202+
uses: actions/download-artifact@v4
203+
with:
204+
path: node-binding/artifacts
205+
- name: Move artifacts
206+
working-directory: node-binding
207+
run: yarn artifacts
208+
- name: List packages
209+
run: ls -R ./npm
210+
working-directory: node-binding
211+
shell: bash
212+
- name: Publish
213+
run: |
214+
npm config set provenance true
215+
if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$";
216+
then
217+
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
218+
npm publish --access public
219+
elif git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+";
220+
then
221+
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
222+
npm publish --tag next --access public
223+
else
224+
echo "Not a release, skipping publish"
225+
fi
226+
working-directory: node-binding
227+
env:
228+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
229+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ repos:
55
- id: trailing-whitespace
66
exclude: cpp-linter/tests/.*\.(?:patch|diff)
77
- id: end-of-file-fixer
8+
exclude: node-binding/.*package\.json
89
- id: check-docstring-first
910
- id: check-added-large-files
1011
args: [--maxkb=9000]

Cargo.lock

Lines changed: 103 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
22

33
[workspace]
4-
members = ["cpp-linter", "py-binding", "docs"]
4+
members = ["cpp-linter", "py-binding", "node-binding", "docs"]
55
resolver = "2"
66

77
[workspace.package]
@@ -13,3 +13,7 @@ authors = [
1313
description = "Run clang-format and clang-tidy on a batch of files."
1414
homepage = "https://cpp-linter.github.io/cpp_linter_rs"
1515
license = "MIT"
16+
17+
[profile.release]
18+
lto = true
19+
strip = "symbols"

0 commit comments

Comments
 (0)