From 72fcd03d982e2926bcc623061bbf287e2990f1e1 Mon Sep 17 00:00:00 2001 From: kxxt Date: Thu, 25 May 2023 22:05:50 +0800 Subject: [PATCH 1/2] feat(target): riscv64gc-unknown-linux-gnu --- cli/src/api/templates/js-binding.ts | 5 +++++ .../__tests__/__snapshots__/target.spec.ts.md | 7 +++++++ .../__snapshots__/target.spec.ts.snap | Bin 991 -> 1042 bytes cli/src/utils/target.ts | 5 +++++ triples/index.cjs | 6 +++--- triples/index.js | 6 +++--- 6 files changed, 23 insertions(+), 6 deletions(-) diff --git a/cli/src/api/templates/js-binding.ts b/cli/src/api/templates/js-binding.ts index fd236c24..efbe5d15 100644 --- a/cli/src/api/templates/js-binding.ts +++ b/cli/src/api/templates/js-binding.ts @@ -85,6 +85,11 @@ function loadNapiModule(binaryName: string, packageName: string) { case 'arm': candidates.push('linux-arm-gnueabihf') break + // type Architecture doesn't contain riscv64 yet + // @ts-expect-error + case 'riscv64': + candidates.push('linux-riscv64-gnu') + break } break } diff --git a/cli/src/utils/__tests__/__snapshots__/target.spec.ts.md b/cli/src/utils/__tests__/__snapshots__/target.spec.ts.md index 8cd87f38..89060666 100644 --- a/cli/src/utils/__tests__/__snapshots__/target.spec.ts.md +++ b/cli/src/utils/__tests__/__snapshots__/target.spec.ts.md @@ -107,4 +107,11 @@ Generated by [AVA](https://avajs.dev). platformArchABI: 'darwin-universal', triple: 'universal-apple-darwin', }, + { + abi: 'gnu', + arch: 'riscv64', + platform: 'linux', + platformArchABI: 'linux-riscv64-gnu', + triple: 'riscv64gc-unknown-linux-gnu', + }, ] diff --git a/cli/src/utils/__tests__/__snapshots__/target.spec.ts.snap b/cli/src/utils/__tests__/__snapshots__/target.spec.ts.snap index 19ac3f83b2f1221924aa36f68b3db8b8f1c4e947..51908e449f56e19f98f5907d21fc3360166a5e47 100644 GIT binary patch literal 1042 zcmV+t1nv7lRzVaI&z%$O z$6)y^5Fd*O00000000BMmP=?8Q5c2qG|A+hnbP{GQmnWT7g?w!x)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B2EY`!3%>BSm|*LS6S5l|18HytJd1O-xM2H@k|ofg5OM@$!K}jB zl$Ev^>n{a0o;KQlc!<2}pw6^6#{I{qn&~0u!mpa6scx1oohP6g88feETn38SANpX5ESBI0UWQ-X3al_8Xe08$!4_9M;F5QmW=_p*CU9*zjEOf4S=K7acW&)!#0fZ>d1m)U-j%?a>vn%j-8)I~S=sPqTgH(^a8m znrkej(pYp{7oF9nr+QKi_f-f_sfO#J?3ycv9e6{Z!q)1!m0axxxOknY9Xl+xnB%Rt ze6+6Fhz-6^C6>KUC2PztoL(&9iWjPiYyGVjDjE8iW?CxW=uMts3HuCNZFs)vs&y+4 Nv%e3&F((!f008I0++Y9z diff --git a/cli/src/utils/target.ts b/cli/src/utils/target.ts index 69c0f32e..341ecf37 100644 --- a/cli/src/utils/target.ts +++ b/cli/src/utils/target.ts @@ -15,6 +15,7 @@ export const AVAILABLE_TARGETS = [ 'armv7-unknown-linux-gnueabihf', 'armv7-linux-androideabi', 'universal-apple-darwin', + 'riscv64gc-unknown-linux-gnu', ] as const export type TargetTriple = (typeof AVAILABLE_TARGETS)[number] @@ -27,6 +28,7 @@ export const DEFAULT_TARGETS = [ export const TARGET_LINKER: Record = { 'aarch64-unknown-linux-musl': 'aarch64-linux-musl-gcc', + 'riscv64gc-unknown-linux-gnu': 'riscv64-linux-gnu-gcc', } // https://nodejs.org/api/process.html#process_process_arch @@ -38,6 +40,7 @@ type NodeJSArch = | 'mipsel' | 'ppc' | 'ppc64' + | 'riscv64' | 's390' | 's390x' | 'x32' @@ -49,6 +52,7 @@ const CpuToNodeArch: Record = { aarch64: 'arm64', i686: 'ia32', armv7: 'arm', + riscv64gc: 'riscv64', } export const NodeArchToCpu: Record = { @@ -56,6 +60,7 @@ export const NodeArchToCpu: Record = { arm64: 'aarch64', ia32: 'i686', arm: 'armv7', + riscv64: 'riscv64gc', } const SysToNodePlatform: Record = { diff --git a/triples/index.cjs b/triples/index.cjs index 4a790689..26414523 100644 --- a/triples/index.cjs +++ b/triples/index.cjs @@ -319,12 +319,12 @@ module.exports.platformArchTriples = { "abi": "gnu" } ], - "riscv64gc": [ + "riscv64": [ { "triple": "riscv64gc-unknown-linux-gnu", - "platformArchABI": "linux-riscv64gc-gnu", + "platformArchABI": "linux-riscv64-gnu", "platform": "linux", - "arch": "riscv64gc", + "arch": "riscv64", "abi": "gnu" } ], diff --git a/triples/index.js b/triples/index.js index dd8e1733..79c07bd5 100644 --- a/triples/index.js +++ b/triples/index.js @@ -319,12 +319,12 @@ export const platformArchTriples = { "abi": "gnu" } ], - "riscv64gc": [ + "riscv64": [ { "triple": "riscv64gc-unknown-linux-gnu", - "platformArchABI": "linux-riscv64gc-gnu", + "platformArchABI": "linux-riscv64-gnu", "platform": "linux", - "arch": "riscv64gc", + "arch": "riscv64", "abi": "gnu" } ], From 173553c0372e66e03bdab19e0e6c2dd44daa14a0 Mon Sep 17 00:00:00 2001 From: kxxt Date: Fri, 26 May 2023 08:55:00 +0800 Subject: [PATCH 2/2] ci: add riscv64gc-unknown-linux-gnu --- .github/workflows/linux-riscv64.yaml | 53 ++++++++++++++++++++++++++++ cli/src/api/templates/ci-template.ts | 8 +++++ cli/src/utils/ci.ts | 9 +++++ 3 files changed, 70 insertions(+) create mode 100644 .github/workflows/linux-riscv64.yaml diff --git a/.github/workflows/linux-riscv64.yaml b/.github/workflows/linux-riscv64.yaml new file mode 100644 index 00000000..8da3d411 --- /dev/null +++ b/.github/workflows/linux-riscv64.yaml @@ -0,0 +1,53 @@ +name: Linux-riscv64 + +env: + DEBUG: 'napi:*' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +on: + push: + branches: + - main + pull_request: + +jobs: + build: + name: stable - riscv64-unknown-linux-gnu - node@18 + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Setup node + uses: actions/setup-node@v3 + with: + node-version: 18 + cache: 'yarn' + + - name: Install + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + targets: riscv64gc-unknown-linux-gnu + + - name: Cache cargo + uses: actions/cache@v3 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: stable-linux-riscv64-gnu-node@18-cargo-cache + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y gcc-riscv64-linux-gnu + yarn config set --json supportedArchitectures.cpu '["current", "riscv64"]' + yarn config set supportedArchitectures.libc "glibc" + yarn install --immutable --mode=skip-build + + - name: Cross build native tests + run: yarn build:test -- --target riscv64gc-unknown-linux-gnu diff --git a/cli/src/api/templates/ci-template.ts b/cli/src/api/templates/ci-template.ts index 783aa411..ee1dfdc4 100644 --- a/cli/src/api/templates/ci-template.ts +++ b/cli/src/api/templates/ci-template.ts @@ -94,6 +94,14 @@ jobs: - host: windows-latest target: 'aarch64-pc-windows-msvc' build: yarn build --platform --target aarch64-pc-windows-msvc + - host: ubuntu-latest + target: 'riscv64gc-unknown-linux-gnu' + setup: | + sudo apt-get update + sudo apt-get install gcc-riscv64-linux-gnu -y + build: | + yarn build --platform --target riscv64gc-unknown-linux-gnu + riscv64-linux-gnu-strip *.node name: stable - \${{ matrix.settings.target }} - node@18 runs-on: \${{ matrix.settings.host }} diff --git a/cli/src/utils/ci.ts b/cli/src/utils/ci.ts index 3084bb38..d77148db 100644 --- a/cli/src/utils/ci.ts +++ b/cli/src/utils/ci.ts @@ -99,4 +99,13 @@ export const CIConfig: Partial< ], test: false, }, + 'riscv64gc-unknown-linux-gnu': { + host: 'ubuntu-latest', + build_setup: [ + 'sudo apt-get update', + 'sudo apt-get install g++-riscv64-linux-gnu gcc-riscv64-linux-gnu -y', + ], + // No official nodejs docker image for riscv64 + test: false, + }, }