From 0fa755d30ac5d7abb16dfa59b58d61deaaa7984c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Tue, 9 Apr 2024 12:27:48 +0900 Subject: [PATCH] feat(target): add support for powerpc64le-unknown-linux-gnu (#2023) * refactor: remove unused ci.ts * feat(target): add support for powerpc64le-unknown-linux-gnu --- .github/workflows/test-release.yaml | 67 +++++++++- cli/src/api/templates/ci-template.ts | 6 + cli/src/api/templates/js-binding.ts | 2 + .../__tests__/__snapshots__/target.spec.ts.md | 7 ++ .../__snapshots__/target.spec.ts.snap | Bin 1216 -> 1271 bytes cli/src/utils/ci.ts | 117 ------------------ cli/src/utils/index.ts | 1 - cli/src/utils/target.ts | 4 + examples/napi/index.cjs | 12 ++ triples/index.cjs | 6 +- triples/index.js | 6 +- 11 files changed, 102 insertions(+), 126 deletions(-) delete mode 100644 cli/src/utils/ci.ts diff --git a/.github/workflows/test-release.yaml b/.github/workflows/test-release.yaml index b0eec774..906062c6 100644 --- a/.github/workflows/test-release.yaml +++ b/.github/workflows/test-release.yaml @@ -238,6 +238,61 @@ jobs: run: yarn build:test -- --target ${{ matrix.settings.target }} --release shell: bash + build_for_test_in_docker: + name: build - ${{ matrix.settings.target }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + settings: + - target: powerpc64le-unknown-linux-gnu + setup: | + sudo apt-get update + sudo apt-get install -y gcc-powerpc64le-linux-gnu + + steps: + - uses: actions/checkout@v4 + + - name: Setup node + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'yarn' + + - name: Install + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + targets: ${{ matrix.settings.target }} + + - name: Cache cargo + uses: actions/cache@v4 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: stable-ubuntu-latest-${{ matrix.settings.target }}-cargo-cache + + - name: Setup toolchain + run: ${{ matrix.settings.setup }} + + - name: Install dependencies + run: yarn install --immutable --mode=skip-build + + - name: Cross build native tests + run: yarn build:test -- --target ${{ matrix.settings.target }} --release + shell: bash + + - uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.settings.target }}-example + path: examples/napi/*.node + - uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.settings.target }}-example-compat + path: examples/napi-compat-mode/index.node + build_in_docker: name: build - ${{ matrix.settings.target }} runs-on: ubuntu-latest @@ -304,7 +359,9 @@ jobs: test_in_docker: name: Test - ${{ matrix.settings.target }} - ${{ matrix.node }} runs-on: ubuntu-latest - needs: build_in_docker + needs: + - build_in_docker + - build_for_test_in_docker strategy: fail-fast: false matrix: @@ -320,6 +377,12 @@ jobs: args: '--platform linux/arm64' arch: 'arm64' libc: 'gnu' + - image: 'node:{:version}-slim' + target: powerpc64le-unknown-linux-gnu + args: '--platform linux/ppc64le' + arch: 'ppc64' + libc: 'gnu' + without-lerna: true - image: 'node:{:version}-alpine' target: x86_64-unknown-linux-musl args: '' @@ -369,7 +432,7 @@ jobs: ulimit -c && ulimit -c unlimited && ulimit -c && - yarn test + ${{ matrix.settings.without-lerna && 'yarn test:without-lerna' || 'yarn test' }} - name: List files run: | ls -la . diff --git a/cli/src/api/templates/ci-template.ts b/cli/src/api/templates/ci-template.ts index 40a8fc96..75fde639 100644 --- a/cli/src/api/templates/ci-template.ts +++ b/cli/src/api/templates/ci-template.ts @@ -79,6 +79,12 @@ jobs: sudo apt-get update sudo apt-get install gcc-riscv64-linux-gnu -y build: ${packageManager} build --platform --target riscv64gc-unknown-linux-gnu + - host: ubuntu-latest + target: 'powerpc64le-unknown-linux-gnu' + setup: | + sudo apt-get update + sudo apt-get install gcc-powerpc64le-linux-gnu -y + build: ${packageManager} build --platform --target powerpc64le-unknown-linux-gnu - host: ubuntu-latest target: 'wasm32-wasi-preview1-threads' build: ${packageManager} build --platform --target wasm32-wasi-preview1-threads diff --git a/cli/src/api/templates/js-binding.ts b/cli/src/api/templates/js-binding.ts index 1cb2ec3c..8b33dc25 100644 --- a/cli/src/api/templates/js-binding.ts +++ b/cli/src/api/templates/js-binding.ts @@ -136,6 +136,8 @@ function requireNative() { } else { ${requireTuple('linux-riscv64-gnu')} } + } else if (process.arch === 'ppc64') { + ${requireTuple('linux-ppc64-gnu')} } else if (process.arch === 's390x') { ${requireTuple('linux-s390x-gnu')} } else { diff --git a/cli/src/utils/__tests__/__snapshots__/target.spec.ts.md b/cli/src/utils/__tests__/__snapshots__/target.spec.ts.md index b022c3b5..6403f629 100644 --- a/cli/src/utils/__tests__/__snapshots__/target.spec.ts.md +++ b/cli/src/utils/__tests__/__snapshots__/target.spec.ts.md @@ -121,6 +121,13 @@ Generated by [AVA](https://avajs.dev). platformArchABI: 'linux-riscv64-gnu', triple: 'riscv64gc-unknown-linux-gnu', }, + { + abi: 'gnu', + arch: 'ppc64', + platform: 'linux', + platformArchABI: 'linux-ppc64-gnu', + triple: 'powerpc64le-unknown-linux-gnu', + }, { abi: 'wasi', arch: 'wasm32', diff --git a/cli/src/utils/__tests__/__snapshots__/target.spec.ts.snap b/cli/src/utils/__tests__/__snapshots__/target.spec.ts.snap index 3d019842695219af1279439188fe92fca1cad7d8..3c8261cf497ddaf309f825ec1e931f593522e158 100644 GIT binary patch literal 1271 zcmVn*+%N&s# zSNK86rXPz400000000BUmQ9EoWf;eQ?4bmkU8mtTDo$t0U#K-J<>|WZ`Ob91bL$mn zx>WN#r_`vNbp5Jb_ZMmn|I|{sY&Yzqg+`17!AB%Tz7DijA6^7r1Kt9bfV05Iz9*P%WX%dY*k!h`urm1EC>uh_n!gM7VHT2v2|zq5L3_ z6QR5q$XF+h$V@2J zI0!wI4+b(D%0?iKP<|LlGn79D(hB}Fb(aEr6*#ECQwqGKz(-2Yzxw3dvrefYCf1~B znj!X!0>3MeQsGV&j;Qd8Dq*n*c20%!DqK<_mVnz6a4aEV@d$Q00cR4hyc&Kn0csK+ zN=ld#!P-f9J_+w6;qxT?w5q345~fD5BPlqV0)I91jTC&Ef?s7U5yAFoaH|FnYf#qU zRSmw-BrF-h{?g!z29s%cAPvX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J)^Q)X|xOL8*QZ&5x`t_X&fA z3(@T*uf095M&($g+NyN@LT-Rte5K)+|6@68qgC7D;8RArBrSCU26NC7HjYJ+(>ojMs#6GC*Pi(d3>ayG0ZUyBQ(+> zWjcq{9_olDx=tgV&=7-TD63IA%jmR5dzhhdV^``r%#2<4%3SptJTLb46&pM*cHUBn zMbB{-{9&&yy<0xGsU{?)^?i2QS8>;lw9L*L%j`5(u#87UtLQt-@vxAnEP1y_M$SXp8mO0iLPgrTrg7$FGWR`UH~c{(hz#;X!X| zP`6Xb5x+WG8@@Ug`s^RMs6)kTzB_iP?N1f0QE{7&=iBm3+u?O>b+7BqmY3(tdfjOE z_Mi(c;kkaXxyzS9wsQjAr3YVhQ{Bp?;&$%3mhEr(UaBqIUl}|@`>nI-z0g^*& -> = { - 'x86_64-apple-darwin': { - host: 'macos-latest', - }, - 'x86_64-pc-windows-msvc': { - host: 'windows-latest', - }, - 'i686-pc-windows-msvc': { - host: 'windows-latest', - test: false, - }, - 'x86_64-unknown-linux-gnu': { - host: 'ubuntu-latest', - build_image: 'ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian', - }, - 'x86_64-unknown-linux-musl': { - host: 'ubuntu-latest', - build_image: 'ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine', - test_image: 'node:${{ matrix.node }}-alpine', - yarn_libc: 'musl', - }, - 'aarch64-apple-darwin': { - host: 'macos-latest', - build_setup: [ - 'sudo rm -Rf /Library/Developer/CommandLineTools/SDKs/*', - 'export CC=$(xcrun -f clang)', - 'export CXX=$(xcrun -f clang++)', - 'export SDK_ROOT=$(xcrun --sdk macosx --show-sdk-path)', - 'export CFLAGS="-isysroot $SDK_ROOT -isystem $SDK_ROOT"', - ], - test: false, - }, - 'aarch64-unknown-linux-gnu': { - host: 'ubuntu-latest', - build_image: 'ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64', - build_setup: [ - 'sudo apt-get update', - 'sudo apt-get install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu -y', - 'export CARGO_BUILD_TARGET=x86_64-unknown-linux-gnu', - ], - test_image: 'ghcr.io/napi-rs/napi-rs/nodejs:aarch64-${{ matrix.node }}', - yarn_cpu: 'arm64', - }, - 'aarch64-unknown-linux-musl': { - host: 'ubuntu-latest', - build_image: 'ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine', - build_setup: ['rustup target add aarch64-unknown-linux-musl'], - test_image: 'multiarch/alpine:aarch64-latest-stable', - test_setup: ['apk add nodejs npm yarn'], - yarn_cpu: 'arm64', - yarn_libc: 'musl', - }, - 'aarch64-pc-windows-msvc': { - host: 'windows-latest', - test: false, - }, - 'armv7-unknown-linux-gnueabihf': { - host: 'ubuntu-latest', - build_setup: [ - 'sudo apt-get update', - 'sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf -y', - ], - yarn_cpu: 'arm', - test_image: 'ghcr.io/napi-rs/napi-rs/nodejs:armhf-${{ matrix.node }}', - }, - 'armv7-unknown-linux-musleabihf': { - host: 'ubuntu-latest', - test: false, - yarn_cpu: 'arm', - yarn_libc: 'musl', - }, - 'aarch64-linux-android': { - host: 'ubuntu-latest', - build_setup: [ - 'export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang"', - 'export CC="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang"', - 'export CXX="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang++"', - 'export PATH="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin:${PATH}"', - ], - test: false, - }, - 'armv7-linux-androideabi': { - host: 'ubuntu-latest', - build_setup: [ - 'export CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang"', - 'export CC="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang"', - 'export CXX="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang++"', - 'export PATH="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin:${PATH}"', - ], - 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/index.ts b/cli/src/utils/index.ts index 14b584a1..df1f5e54 100644 --- a/cli/src/utils/index.ts +++ b/cli/src/utils/index.ts @@ -1,4 +1,3 @@ -export * from './ci.js' export * from './log.js' export * from './misc.js' export * from './target.js' diff --git a/cli/src/utils/target.ts b/cli/src/utils/target.ts index 9b4e7c96..f120895c 100644 --- a/cli/src/utils/target.ts +++ b/cli/src/utils/target.ts @@ -23,6 +23,7 @@ export const AVAILABLE_TARGETS = [ 'armv7-linux-androideabi', 'universal-apple-darwin', 'riscv64gc-unknown-linux-gnu', + 'powerpc64le-unknown-linux-gnu', 'wasm32-wasi-preview1-threads', ] as const @@ -38,6 +39,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', + 'powerpc64le-unknown-linux-gnu': 'powerpc64le-linux-gnu-gcc', } // https://nodejs.org/api/process.html#process_process_arch @@ -63,6 +65,7 @@ const CpuToNodeArch: Record = { i686: 'ia32', armv7: 'arm', riscv64gc: 'riscv64', + powerpc64le: 'ppc64', } export const NodeArchToCpu: Record = { @@ -71,6 +74,7 @@ export const NodeArchToCpu: Record = { ia32: 'i686', arm: 'armv7', riscv64: 'riscv64gc', + ppc64: 'powerpc64le', } const SysToNodePlatform: Record = { diff --git a/examples/napi/index.cjs b/examples/napi/index.cjs index 20dd6cf6..5f266644 100644 --- a/examples/napi/index.cjs +++ b/examples/napi/index.cjs @@ -297,6 +297,18 @@ function requireNative() { } } + } else if (process.arch === 'ppc64') { + try { + return require('./example.linux-ppc64-gnu.node') + } catch (e) { + loadErrors.push(e) + } + try { + return require('@examples/napi-linux-ppc64-gnu') + } catch (e) { + loadErrors.push(e) + } + } else if (process.arch === 's390x') { try { return require('./example.linux-s390x-gnu.node') diff --git a/triples/index.cjs b/triples/index.cjs index cd353e71..e8eeac56 100644 --- a/triples/index.cjs +++ b/triples/index.cjs @@ -309,12 +309,12 @@ module.exports.platformArchTriples = { abi: 'gnu', }, ], - powerpc64le: [ + ppc64: [ { triple: 'powerpc64le-unknown-linux-gnu', - platformArchABI: 'linux-powerpc64le-gnu', + platformArchABI: 'linux-ppc64-gnu', platform: 'linux', - arch: 'powerpc64le', + arch: 'ppc64', abi: 'gnu', }, ], diff --git a/triples/index.js b/triples/index.js index 79c07bd5..7b3e8130 100644 --- a/triples/index.js +++ b/triples/index.js @@ -310,12 +310,12 @@ export const platformArchTriples = { "abi": "gnu" } ], - "powerpc64le": [ + "ppc64": [ { "triple": "powerpc64le-unknown-linux-gnu", - "platformArchABI": "linux-powerpc64le-gnu", + "platformArchABI": "linux-ppc64-gnu", "platform": "linux", - "arch": "powerpc64le", + "arch": "ppc64", "abi": "gnu" } ],