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/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 19ac3f83..51908e44 100644 Binary files a/cli/src/utils/__tests__/__snapshots__/target.spec.ts.snap and b/cli/src/utils/__tests__/__snapshots__/target.spec.ts.snap differ 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, + }, } 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" } ],