From 28f51b48f7c19f06ee8e98abc7f955ccf0a960cf Mon Sep 17 00:00:00 2001 From: Brad Marsden Date: Tue, 18 Jun 2024 21:56:47 +0100 Subject: [PATCH 1/4] feat: add musl prebuilds and refactor linux/arm prebuilds Co-authored-by: funniray Co-authored-by: Brad Marsden --- .github/workflows/build-linux.yml | 152 +++++++++++++---------------- build-containers/Dockerfile.alpine | 3 + build-containers/Dockerfile.ubuntu | 4 + cmake/toolchain/ci.cmake | 20 ++++ 4 files changed, 95 insertions(+), 84 deletions(-) create mode 100644 build-containers/Dockerfile.alpine create mode 100644 build-containers/Dockerfile.ubuntu create mode 100644 cmake/toolchain/ci.cmake diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index fc6ad1c..fd62d27 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -11,101 +11,85 @@ env: jobs: build-linux: - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 strategy: matrix: - node-version: [ 16.x] + node-version: [16] + arch: [amd64, arm64, arm] + platform: [ubuntu, alpine] + include: + # Set baselines per platform + - triple: "alpine-linux-musl" + platform: alpine + version: 3.16 + libc: musl + - triple: "linux-gnu" + platform: ubuntu + version: 20.04 + # Set baselines per architecture + - archid: x86_64 + nodearch: x64 + arch: amd64 + gcc-install: gcc g++ + gcc: gcc + - archid: armv7 + archpost: eabihf + nodearch: arm + arch: arm + flags: -march=armv7-a -mfpu=neon-vfpv4 -mfloat-abi=hard -fPIC + gcc-install: gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf + gcc: arm-linux-gnueabihf-gcc + - archid: aarch64 + nodearch: arm64 + arch: arm64 + flags: -march=armv8-a -fPIC + gcc-install: gcc-aarch64-linux-gnu g++-aarch64-linux-gnu + gcc: aarch64-linux-gnu-gcc + # Set edge case overrides for specific platform + architecture + # gcc has issues building on the same arch but for a different libc, use clang instead + - arch: amd64 + platform: alpine + gcc-install: clang lld + gcc: clang + # ubuntu uses the triple `arm-linux-gnueabihf` instead of alpine's `armv7-alpine-linux-musleabihf` + - archid: arm + arch: arm + platform: ubuntu + # ubuntu 20.04 uses openssl 1.1.1f, however static versions of openssl 1.1.1 are bugged on aarch64, use ubuntu 22.04 instead + - version: 22.04 + arch: arm64 + platform: ubuntu steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - - name: Build - run: npm install --build-from-source + - name: Install node dependencies + run: npm install --ignore-scripts env: CI: true - - name: Test - run: npm run test - env: - CI: true - - name: Upload - run: node_modules/.bin/prebuild -r napi --upload -u ${{ secrets.GITHUB_TOKEN }} - env: - CI: true - - build-linux-armv7: - runs-on: ubuntu-20.04 - - strategy: - matrix: - node-version: [16.x] - steps: - - uses: actions/checkout@v2 - - name: Prepare Cross Compile - run: | - sudo apt update - sudo apt install -y g++-arm-linux-gnueabihf gcc-arm-linux-gnueabihf - mkdir sysroot && cd sysroot - wget https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/ef5c4f84bcafb7a3796d36bb1db7826317dde51c/debian_sid_arm_sysroot.tar.xz - tar xf debian_sid_arm_sysroot.tar.xz - echo "ARM_SYSROOT=$(pwd)" >> $GITHUB_ENV - ls -l - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 + - if: matrix.arch != 'amd64' + name: Set up QEMU + uses: docker/setup-qemu-action@v3 with: - node-version: ${{ matrix.node-version }} - - name: Build & Upload - run: | - npm install --ignore-scripts - node_modules/.bin/prebuild -r napi --backend cmake-js --arch arm --upload -u ${{ secrets.GITHUB_TOKEN }} -- --CDCMAKE_TOOLCHAIN_FILE:FILEPATH=./cmake/toolchain/armv7.cmake - env: - CI: true - - build-linux-arm64: - runs-on: ubuntu-20.04 - - strategy: - matrix: - node-version: [16.x] - steps: - - uses: actions/checkout@v2 - - name: Prepare Cross Compile + platforms: ${{ matrix.arch }} + - name: Install system dependencies run: | sudo apt update - sudo apt install -y g++-aarch64-linux-gnu gcc-aarch64-linux-gnu - mkdir sysroot && cd sysroot - wget https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/41a6c8dec4c4304d6509e30cbaf9218dffb4438e/debian_bullseye_arm64_sysroot.tar.xz - tar xf debian_bullseye_arm64_sysroot.tar.xz - echo "ARM64_SYSROOT=$(pwd)" >> $GITHUB_ENV - ls -l - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - name: Build & Upload - run: | - npm install --ignore-scripts - node_modules/.bin/prebuild -r napi --backend cmake-js --arch arm64 --upload -u ${{ secrets.GITHUB_TOKEN }} -- --CDCMAKE_TOOLCHAIN_FILE:FILEPATH=./cmake/toolchain/arm64.cmake + sudo apt install -y podman ninja-build ${{ matrix.gcc-install }} + - name: Build sysroot + run: sudo podman build -t ndc-buildroot:${{ matrix.platform }}-${{ matrix.arch }} ./build-containers --file Dockerfile.${{ matrix.platform }} --platform linux/${{ matrix.arch }} --build-arg="version=${{ matrix.version }}" + - name: Mount sysroot + id: sysroot + run: echo "sysroot=$(sudo podman image mount ndc-buildroot:${{ matrix.platform }}-${{ matrix.arch }})" >> $GITHUB_OUTPUT + - name: Build and upload + run: sudo --preserve-env=SYSROOT,TRIPLE,COMPILER_FLAGS,LIBC,GCC,CI,PATH node_modules/.bin/prebuild --arch ${{ matrix.nodearch }} -r napi --backend cmake-js --upload -u ${{ secrets.GITHUB_TOKEN }} -- --CDCMAKE_TOOLCHAIN_FILE:FILEPATH=./cmake/toolchain/ci.cmake env: + SYSROOT: ${{ steps.sysroot.outputs.sysroot }} + TRIPLE: ${{ matrix.archid }}-${{ matrix.triple }}${{ matrix.archpost }} + COMPILER_FLAGS: ${{ matrix.flags }} + LIBC: ${{ matrix.libc }} + GCC: ${{ matrix.gcc }} CI: true - - # npm-publish: - # needs: [build-linux, build-linux-armv7, build-linux-arm64] - # name: npm-publish - # runs-on: ubuntu-latest - # steps: - # - name: Checkout repository - # uses: actions/checkout@v2 - # - name: Set up Node.js - # uses: actions/setup-node@v1 - # with: - # node-version: 16.x - # registry-url: "https://registry.npmjs.org" - # - name: Publish - # run: | - # npm install - # npm publish - # env: - # NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} diff --git a/build-containers/Dockerfile.alpine b/build-containers/Dockerfile.alpine new file mode 100644 index 0000000..dbe6d71 --- /dev/null +++ b/build-containers/Dockerfile.alpine @@ -0,0 +1,3 @@ +ARG version=3.16 +FROM alpine:${version} +RUN apk add build-base openssl-libs-static openssl-dev \ No newline at end of file diff --git a/build-containers/Dockerfile.ubuntu b/build-containers/Dockerfile.ubuntu new file mode 100644 index 0000000..fc282af --- /dev/null +++ b/build-containers/Dockerfile.ubuntu @@ -0,0 +1,4 @@ +ARG version=20.04 +FROM ubuntu:${version} +RUN apt update +RUN apt install -y build-essential libssl-dev \ No newline at end of file diff --git a/cmake/toolchain/ci.cmake b/cmake/toolchain/ci.cmake new file mode 100644 index 0000000..0d12b0e --- /dev/null +++ b/cmake/toolchain/ci.cmake @@ -0,0 +1,20 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(triple $ENV{TRIPLE}) + +# use clang and lld +set(CMAKE_C_COMPILER $ENV{GCC}) +set(CMAKE_CXX_COMPILER $ENV{GCC}) + +set(CMAKE_SYSROOT "$ENV{SYSROOT}") +message(STATUS "Using sysroot: ${CMAKE_SYSROOT}") + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +set(CMAKE_C_COMPILER_TARGET ${triple}) +set(CMAKE_CXX_COMPILER_TARGET ${triple}) +message(STATUS "Compiling for: ${triple}") + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} $ENV{COMPILER_FLAGS}") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} $ENV{COMPILER_FLAGS}") From 3f0df18cb6d4aef1c1089a0abcecac52c8b507a9 Mon Sep 17 00:00:00 2001 From: Brad Marsden Date: Wed, 19 Jun 2024 20:53:53 +0100 Subject: [PATCH 2/4] fix: glibc builds, add and run tests on all platforms Reverts back to using ubuntu-20.04 for builds to keep in-line with existing worker. Uses debian instead of ubuntu for sysroot for newer version of OpenSSL. Runs all tests on all platforms to ensure everything works, rather than just x64. Co-authored-by: funniray Co-authored-by: Brad Marsden --- .github/workflows/build-linux.yml | 51 +++++++++++++++++------------- build-containers/Dockerfile.alpine | 7 ++-- build-containers/Dockerfile.debian | 7 ++++ build-containers/Dockerfile.ubuntu | 4 --- cmake/toolchain/ci.cmake | 3 ++ 5 files changed, 44 insertions(+), 28 deletions(-) create mode 100644 build-containers/Dockerfile.debian delete mode 100644 build-containers/Dockerfile.ubuntu diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index fd62d27..8926572 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -11,54 +11,52 @@ env: jobs: build-linux: - runs-on: ubuntu-24.04 + runs-on: ubuntu-20.04 strategy: matrix: node-version: [16] arch: [amd64, arm64, arm] - platform: [ubuntu, alpine] + platform: [debian, alpine] include: # Set baselines per platform - triple: "alpine-linux-musl" platform: alpine version: 3.16 libc: musl + gcc-install: clang lld + gcc: clang - triple: "linux-gnu" - platform: ubuntu - version: 20.04 + platform: debian + version: bullseye # Set baselines per architecture - archid: x86_64 nodearch: x64 arch: amd64 - gcc-install: gcc g++ - gcc: gcc - archid: armv7 archpost: eabihf nodearch: arm arch: arm flags: -march=armv7-a -mfpu=neon-vfpv4 -mfloat-abi=hard -fPIC - gcc-install: gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf - gcc: arm-linux-gnueabihf-gcc - archid: aarch64 nodearch: arm64 arch: arm64 flags: -march=armv8-a -fPIC - gcc-install: gcc-aarch64-linux-gnu g++-aarch64-linux-gnu - gcc: aarch64-linux-gnu-gcc # Set edge case overrides for specific platform + architecture # gcc has issues building on the same arch but for a different libc, use clang instead - arch: amd64 - platform: alpine - gcc-install: clang lld - gcc: clang - # ubuntu uses the triple `arm-linux-gnueabihf` instead of alpine's `armv7-alpine-linux-musleabihf` + platform: debian + gcc-install: gcc g++ + gcc: gcc + - arch: arm64 + platform: debian + gcc-install: gcc-aarch64-linux-gnu g++-aarch64-linux-gnu + gcc: aarch64-linux-gnu-gcc + # debian uses the triple `arm-linux-gnueabihf` instead of alpine's `armv7-alpine-linux-musleabihf` - archid: arm arch: arm - platform: ubuntu - # ubuntu 20.04 uses openssl 1.1.1f, however static versions of openssl 1.1.1 are bugged on aarch64, use ubuntu 22.04 instead - - version: 22.04 - arch: arm64 - platform: ubuntu + platform: debian + gcc-install: gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf + gcc: arm-linux-gnueabihf-gcc steps: - uses: actions/checkout@v4 @@ -79,13 +77,15 @@ jobs: run: | sudo apt update sudo apt install -y podman ninja-build ${{ matrix.gcc-install }} + - name: List installed libc + run: apt list --installed | grep libc6-dev - name: Build sysroot - run: sudo podman build -t ndc-buildroot:${{ matrix.platform }}-${{ matrix.arch }} ./build-containers --file Dockerfile.${{ matrix.platform }} --platform linux/${{ matrix.arch }} --build-arg="version=${{ matrix.version }}" + run: sudo podman build --isolation=chroot -t ndc-buildroot:${{ matrix.platform }}-${{ matrix.arch }} ./build-containers --file Dockerfile.${{ matrix.platform }} --platform linux/${{ matrix.arch }} --build-arg="version=${{ matrix.version }}" --build-arg="node_version=${{ matrix.node-version }}" - name: Mount sysroot id: sysroot run: echo "sysroot=$(sudo podman image mount ndc-buildroot:${{ matrix.platform }}-${{ matrix.arch }})" >> $GITHUB_OUTPUT - - name: Build and upload - run: sudo --preserve-env=SYSROOT,TRIPLE,COMPILER_FLAGS,LIBC,GCC,CI,PATH node_modules/.bin/prebuild --arch ${{ matrix.nodearch }} -r napi --backend cmake-js --upload -u ${{ secrets.GITHUB_TOKEN }} -- --CDCMAKE_TOOLCHAIN_FILE:FILEPATH=./cmake/toolchain/ci.cmake + - name: Build + run: sudo --preserve-env=SYSROOT,TRIPLE,COMPILER_FLAGS,LIBC,GCC,CI,PATH node_modules/.bin/prebuild --arch ${{ matrix.nodearch }} -r napi --backend cmake-js -- --CDCMAKE_TOOLCHAIN_FILE:FILEPATH=./cmake/toolchain/ci.cmake env: SYSROOT: ${{ steps.sysroot.outputs.sysroot }} TRIPLE: ${{ matrix.archid }}-${{ matrix.triple }}${{ matrix.archpost }} @@ -93,3 +93,10 @@ jobs: LIBC: ${{ matrix.libc }} GCC: ${{ matrix.gcc }} CI: true + - name: Test + run: sudo podman run --rm -v $(pwd):/usr/app/ -e CI=true --platform linux/${{ matrix.arch }} -t ndc-buildroot:${{ matrix.platform }}-${{ matrix.arch }} npm run test + - name: Upload + run: sudo --preserve-env=CI,LIBC node_modules/.bin/prebuild --arch ${{ matrix.nodearch }} -r napi --upload -u ${{ secrets.GITHUB_TOKEN }} + env: + LIBC: ${{ matrix.libc }} + CI: true diff --git a/build-containers/Dockerfile.alpine b/build-containers/Dockerfile.alpine index dbe6d71..57fa7f2 100644 --- a/build-containers/Dockerfile.alpine +++ b/build-containers/Dockerfile.alpine @@ -1,3 +1,6 @@ ARG version=3.16 -FROM alpine:${version} -RUN apk add build-base openssl-libs-static openssl-dev \ No newline at end of file +ARG node_version=16 +FROM node:${node_version}-alpine${version} +RUN apk add build-base openssl-libs-static openssl-dev + +WORKDIR /usr/app/ diff --git a/build-containers/Dockerfile.debian b/build-containers/Dockerfile.debian new file mode 100644 index 0000000..ad23889 --- /dev/null +++ b/build-containers/Dockerfile.debian @@ -0,0 +1,7 @@ +ARG version=buster +ARG node_version=16 +FROM node:${node_version}-${version} +RUN apt update +RUN apt install -y build-essential libssl-dev + +WORKDIR /usr/app/ diff --git a/build-containers/Dockerfile.ubuntu b/build-containers/Dockerfile.ubuntu deleted file mode 100644 index fc282af..0000000 --- a/build-containers/Dockerfile.ubuntu +++ /dev/null @@ -1,4 +0,0 @@ -ARG version=20.04 -FROM ubuntu:${version} -RUN apt update -RUN apt install -y build-essential libssl-dev \ No newline at end of file diff --git a/cmake/toolchain/ci.cmake b/cmake/toolchain/ci.cmake index 0d12b0e..0b75c7e 100644 --- a/cmake/toolchain/ci.cmake +++ b/cmake/toolchain/ci.cmake @@ -4,6 +4,9 @@ set(triple $ENV{TRIPLE}) # use clang and lld set(CMAKE_C_COMPILER $ENV{GCC}) set(CMAKE_CXX_COMPILER $ENV{GCC}) +if (CMAKE_C_COMPILER MATCHES clang) + add_link_options("-fuse-ld=lld") +endif() set(CMAKE_SYSROOT "$ENV{SYSROOT}") message(STATUS "Using sysroot: ${CMAKE_SYSROOT}") From 135399fb30234cad1471f01d54316b2f70a87722 Mon Sep 17 00:00:00 2001 From: funniray Date: Sat, 22 Jun 2024 22:33:39 +0100 Subject: [PATCH 3/4] clarify matrix variable names --- .github/workflows/build-linux.yml | 36 ++++++++++++++++--------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index 8926572..dc0944e 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -23,39 +23,41 @@ jobs: platform: alpine version: 3.16 libc: musl - gcc-install: clang lld + gcc_install: clang lld gcc: clang + # libc is intentionally not set here, as prebuild-install requires libc to not be set for glibc builds - triple: "linux-gnu" platform: debian version: bullseye # Set baselines per architecture - - archid: x86_64 - nodearch: x64 + - triple_arch: x86_64 + node_arch: x64 arch: amd64 - - archid: armv7 - archpost: eabihf - nodearch: arm + - triple_arch: armv7 + node_arch: arm + triple_postfix: eabihf arch: arm flags: -march=armv7-a -mfpu=neon-vfpv4 -mfloat-abi=hard -fPIC - - archid: aarch64 - nodearch: arm64 + - triple_arch: aarch64 + node_arch: arm64 arch: arm64 flags: -march=armv8-a -fPIC # Set edge case overrides for specific platform + architecture - # gcc has issues building on the same arch but for a different libc, use clang instead + # also define gcc commands for each architecture - arch: amd64 platform: debian - gcc-install: gcc g++ + gcc_install: gcc g++ gcc: gcc - arch: arm64 platform: debian - gcc-install: gcc-aarch64-linux-gnu g++-aarch64-linux-gnu + gcc_install: gcc-aarch64-linux-gnu g++-aarch64-linux-gnu gcc: aarch64-linux-gnu-gcc # debian uses the triple `arm-linux-gnueabihf` instead of alpine's `armv7-alpine-linux-musleabihf` - - archid: arm + # because of this, we explicitly override triple_arch for debian arm + - triple_arch: arm arch: arm platform: debian - gcc-install: gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf + gcc_install: gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf gcc: arm-linux-gnueabihf-gcc steps: @@ -76,7 +78,7 @@ jobs: - name: Install system dependencies run: | sudo apt update - sudo apt install -y podman ninja-build ${{ matrix.gcc-install }} + sudo apt install -y podman ninja-build ${{ matrix.gcc_install }} - name: List installed libc run: apt list --installed | grep libc6-dev - name: Build sysroot @@ -85,10 +87,10 @@ jobs: id: sysroot run: echo "sysroot=$(sudo podman image mount ndc-buildroot:${{ matrix.platform }}-${{ matrix.arch }})" >> $GITHUB_OUTPUT - name: Build - run: sudo --preserve-env=SYSROOT,TRIPLE,COMPILER_FLAGS,LIBC,GCC,CI,PATH node_modules/.bin/prebuild --arch ${{ matrix.nodearch }} -r napi --backend cmake-js -- --CDCMAKE_TOOLCHAIN_FILE:FILEPATH=./cmake/toolchain/ci.cmake + run: sudo --preserve-env=SYSROOT,TRIPLE,COMPILER_FLAGS,LIBC,GCC,CI,PATH node_modules/.bin/prebuild --arch ${{ matrix.node_arch }} -r napi --backend cmake-js -- --CDCMAKE_TOOLCHAIN_FILE:FILEPATH=./cmake/toolchain/ci.cmake env: SYSROOT: ${{ steps.sysroot.outputs.sysroot }} - TRIPLE: ${{ matrix.archid }}-${{ matrix.triple }}${{ matrix.archpost }} + TRIPLE: ${{ matrix.triple_arch }}-${{ matrix.triple }}${{ matrix.triple_postfix }} COMPILER_FLAGS: ${{ matrix.flags }} LIBC: ${{ matrix.libc }} GCC: ${{ matrix.gcc }} @@ -96,7 +98,7 @@ jobs: - name: Test run: sudo podman run --rm -v $(pwd):/usr/app/ -e CI=true --platform linux/${{ matrix.arch }} -t ndc-buildroot:${{ matrix.platform }}-${{ matrix.arch }} npm run test - name: Upload - run: sudo --preserve-env=CI,LIBC node_modules/.bin/prebuild --arch ${{ matrix.nodearch }} -r napi --upload -u ${{ secrets.GITHUB_TOKEN }} + run: sudo --preserve-env=CI,LIBC node_modules/.bin/prebuild --arch ${{ matrix.node_arch }} -r napi --upload -u ${{ secrets.GITHUB_TOKEN }} env: LIBC: ${{ matrix.libc }} CI: true From cf6a28952771870de18d0514bbedd66ffee31dec Mon Sep 17 00:00:00 2001 From: funniray Date: Sat, 22 Jun 2024 22:34:39 +0100 Subject: [PATCH 4/4] default debian container to bullseye --- build-containers/Dockerfile.debian | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-containers/Dockerfile.debian b/build-containers/Dockerfile.debian index ad23889..067d1f7 100644 --- a/build-containers/Dockerfile.debian +++ b/build-containers/Dockerfile.debian @@ -1,4 +1,4 @@ -ARG version=buster +ARG version=bullseye ARG node_version=16 FROM node:${node_version}-${version} RUN apt update