Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: refactoring the project using Rust and N-API #10

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
231 changes: 231 additions & 0 deletions .github/workflows/napi_build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
name: Build N-API

env:
DEBUG: napi:*
APP_NAME: bilicli-napi
APP_DIR: packages/bilicli-napi

on:
workflow_dispatch:
push:
branches:
- main

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

jobs:
build:
if: '!contains(github.event.head_commit.message, ''skip ci'')'
strategy:
fail-fast: false
matrix:
settings:
- host: macos-latest
target: x86_64-apple-darwin
architecture: x64
build: |
cd $APP_DIR
pnpm build
strip -x *.node
- host: windows-latest
build: |
cd $APP_DIR
pnpm build
target: x86_64-pc-windows-msvc
architecture: x64
- host: windows-latest
build: |
cd $APP_DIR
pnpm build --target i686-pc-windows-msvc
target: i686-pc-windows-msvc
architecture: x86
- host: ubuntu-latest
target: x86_64-unknown-linux-gnu
setup: |
sudo apt-get update
sudo apt-get install pkg-config libx11-dev libssl-dev
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
build: |-
set -e &&
rustup target add x86_64-unknown-linux-gnu &&
pnpm build --target x86_64-unknown-linux-gnu &&
llvm-strip -x *.node
- host: ubuntu-latest
target: x86_64-unknown-linux-musl
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
build: set -e && apk add perl && pnpm build && strip *.node
- host: macos-latest
target: aarch64-apple-darwin
build: |
cd $APP_DIR
sudo rm -Rf /Library/Developer/CommandLineTools/SDKs/*;
export CC=$(xcrun -f clang);
export CXX=$(xcrun -f clang++);
SYSROOT=$(xcrun --sdk macosx --show-sdk-path);
export CFLAGS="-isysroot $SYSROOT -isystem $SYSROOT";
pnpm build --target aarch64-apple-darwin
strip -x *.node
- host: ubuntu-latest
target: aarch64-unknown-linux-gnu
setup: |
sudo apt-get update
sudo apt-get install pkg-config libx11-dev libssl-dev
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64
build: >-
set -e &&
export CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc &&
export CC=aarch64-linux-gnu-gcc &&
sudo apt update &&
sudo apt install -y gcc-aarch64-linux-gnu &&
rustup target add aarch64-unknown-linux-gnu &&
pnpm build --target aarch64-unknown-linux-gnu &&
aarch64-unknown-linux-gnu-strip *.node
- host: ubuntu-latest
architecture: x64
target: armv7-unknown-linux-gnueabihf
setup: |
sudo apt-get update
sudo apt-get install libssl-dev gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf -y
build: |
cd $APP_DIR
pnpm build --target=armv7-unknown-linux-gnueabihf
arm-linux-gnueabihf-strip *.node
- host: ubuntu-latest
architecture: x64
target: aarch64-unknown-linux-musl
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
build: |-
set -e &&
apk add perl &&
rustup target add aarch64-unknown-linux-musl &&
pnpm build --target aarch64-unknown-linux-musl &&
/aarch64-linux-musl-cross/bin/aarch64-linux-musl-strip *.node
- host: windows-latest
architecture: x64
target: aarch64-pc-windows-msvc
build: |
cd $APP_DIR
pnpm build --target aarch64-pc-windows-msvc
name: stable - ${{ matrix.settings.target }} - node@20
runs-on: ${{ matrix.settings.host }}
steps:
- uses: actions/checkout@v3
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: latest
- name: Setup node
uses: actions/setup-node@v3
if: ${{ !matrix.settings.docker }}
with:
node-version: latest
check-latest: true
cache: pnpm
cache-dependency-path: pnpm-lock.yaml
architecture: ${{ matrix.settings.architecture }}
- name: Install
uses: actions-rs/toolchain@v1
if: ${{ !matrix.settings.docker }}
with:
toolchain: nightly
override: true
components: rustfmt, clippy
target: ${{ matrix.settings.target }}
- name: Cache cargo
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ matrix.settings.target }}-cargo-registry
- name: Cache cargo index
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: ${{ matrix.settings.target }}-cargo-index
- name: Cache NPM dependencies
uses: actions/cache@v3
with:
path: ${{ env.APP_DIR }}/node_modules
key: npm-cache-build-${{ matrix.settings.target }}-node@16
- name: Setup toolchain
run: ${{ matrix.settings.setup }}
if: ${{ matrix.settings.setup }}
shell: bash
- name: Install dependencies
working-directory: ${{ env.APP_DIR }}
run: pnpm install --no-frozen-lockfile --registry https://registry.npmjs.org
- name: Build in docker
uses: addnab/docker-run-action@v3
if: ${{ matrix.settings.docker }}
with:
image: ${{ matrix.settings.docker }}
options: '-v ${{ env.HOME }}/.cargo/git:/root/.cargo/git -v ${{ env.HOME }}/.cargo/registry:/root/.cargo/registry -v ${{ github.workspace }}:/build -w /build/${{ env.APP_DIR }}'
run: ${{ matrix.settings.build }}
- name: Build
run: ${{ matrix.settings.build }}
if: ${{ !matrix.settings.docker }}
shell: bash
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: bindings-${{ matrix.settings.target }}
path: ${{ env.APP_DIR }}/${{ env.APP_NAME }}.*.node
if-no-files-found: error

publish:
name: Publish
runs-on: ubuntu-latest
needs:
- build
steps:
- uses: actions/checkout@v3
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: latest
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: latest
check-latest: true
cache: pnpm
cache-dependency-path: pnpm-lock.yaml
- name: Cache NPM dependencies
uses: actions/cache@v3
with:
path: node_modules
key: npm-cache-ubuntu-latest-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: |
npm-cache-
- name: Install dependencies
working-directory: ${{ env.APP_DIR }}
run: pnpm install --no-frozen-lockfile --registry https://registry.npmjs.org
- name: Download all artifacts
uses: actions/download-artifact@v3
with:
path: ${{ env.APP_DIR }}/artifacts
- name: Move artifacts
working-directory: ${{ env.APP_DIR }}
run: pnpm artifacts
- name: List packages
working-directory: ${{ env.APP_DIR }}
run: ls -R ./npm
shell: bash
- name: Publish
working-directory: ${{ env.APP_DIR }}
run: |
if git log -1 --pretty=%B | grep "chore: release v[0-9]\+\.[0-9]\+\.[0-9]\+$";
then
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
npm publish --access public
elif git log -1 --pretty=%B | grep "chore: release v[0-9]\+\.[0-9]\+\.[0-9]\+";
then
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
npm publish --tag next --access public
else
echo "Not a release, skipping publish"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 16.x
node-version: lts/*

- run: npx changelogithub # or changelogithub@0.12 if ensure the stable result
- run: npx changelogithub
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
11 changes: 9 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@
"blive",
"danmu",
"temir"
]
}
],
"rust-analyzer.linkedProjects": [
"./packages/bilicli-napi/Cargo.toml"
],
"rust-analyzer.cargo.features": [
"platform-napi"
],
"rust-analyzer.procMacro.ignored": { "napi-derive": ["napi"] }
}
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
"tui"
],
"author": "ddiu8081 <ddiu8081@gmail.com>",
"scripts": {
"build": "pnpm -r --parallel build"
},
"devDependencies": {
"@types/node": "^18.11.10",
"tsup": "^6.5.0",
"typescript": "^4.9.3"
"@types/node": "22.5.2",
"tsup": "8.2.4",
"typescript": "5.5.4"
}
}
15 changes: 15 additions & 0 deletions packages/bilicli-napi/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"

[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"

[target.x86_64-unknown-linux-musl]
rustflags = [
"-C",
"target-feature=-crt-static",
]

[target.aarch64-unknown-linux-musl]
linker = "aarch64-linux-musl-gcc"
rustflags = ["-C", "target-feature=-crt-static"]
Loading