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 3d019842..3c8261cf 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 deleted file mode 100644 index 9e3af6b0..00000000 --- a/cli/src/utils/ci.ts +++ /dev/null @@ -1,117 +0,0 @@ -import { TargetTriple } from './target.js' - -export const CIConfig: Partial< - Record< - TargetTriple, - { - host: string - build_image?: string - build_setup?: string[] - test?: boolean - test_image?: string - test_setup?: string[] - yarn_cpu?: string - yarn_libc?: string - } - > -> = { - '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" } ],