Skip to content

Commit

Permalink
Merge pull request #269 from murat-dogan/new-github-actions
Browse files Browse the repository at this point in the history
New GitHub actions
  • Loading branch information
murat-dogan committed Jun 30, 2024
2 parents b1c04e7 + 4154f85 commit bc2d8a8
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 91 deletions.
157 changes: 75 additions & 82 deletions .github/workflows/build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,98 +14,91 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
node-version: [ 16.x]
node-version: [16]
arch: [amd64, arm64, arm]
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
# 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
- triple_arch: x86_64
node_arch: x64
arch: amd64
- triple_arch: armv7
node_arch: arm
triple_postfix: eabihf
arch: arm
flags: -march=armv7-a -mfpu=neon-vfpv4 -mfloat-abi=hard -fPIC
- triple_arch: aarch64
node_arch: arm64
arch: arm64
flags: -march=armv8-a -fPIC
# Set edge case overrides for specific platform + architecture
# also define gcc commands for each architecture
- arch: amd64
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`
# 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: arm-linux-gnueabihf-gcc

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
platforms: ${{ matrix.arch }}
- name: Install system dependencies
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
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 --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
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.triple_arch }}-${{ matrix.triple }}${{ matrix.triple_postfix }}
COMPILER_FLAGS: ${{ matrix.flags }}
LIBC: ${{ matrix.libc }}
GCC: ${{ matrix.gcc }}
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
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
- 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.node_arch }} -r napi --upload -u ${{ secrets.GITHUB_TOKEN }}
env:
LIBC: ${{ matrix.libc }}
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 }}
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ npm install node-datachannel

`node-datachannel` targets N-API version 8 and supports NodeJS v16 and above. It is tested on Linux, Windows and MacOS. For N-API compatibility please check [here](https://nodejs.org/api/n-api.html#n_api_n_api_version_matrix).

| | Linux-x64 | Linux-armv7 | Linux-arm64(1) | Windows-x86 | Windows-x64 | Mac (M1 + x64) |
| -------- | :-------: | :---------: | :------------: | :---------: | :---------: | :------------: |
| Node V16 | + | + | + | + | + | + |
| Node V17 | + | + | + | + | + | + |
| Node V18 | + | + | + | + | + | + |
| Node V19 | + | + | + | + | + | + |
| Node V20 | + | + | + | + | + | + |

1. Please note that; For Linux-arm64 platform we need OpenSSL to be installed locally.
| | Linux [x64,armv7,arm64] (1) | Windows [x86,x64] | Mac [M1,x64] |
| -------- | :-------------------------: | :---------------: | :----------: |
| Node V16 | + | + | + |
| Node V17 | + | + | + |
| Node V18 | + | + | + |
| Node V19 | + | + | + |
| Node V20 | + | + | + |

**(1)** For Linux musl + libc

## Electron

Expand Down
6 changes: 6 additions & 0 deletions build-containers/Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ARG version=3.16
ARG node_version=16
FROM node:${node_version}-alpine${version}
RUN apk add build-base openssl-libs-static openssl-dev

WORKDIR /usr/app/
7 changes: 7 additions & 0 deletions build-containers/Dockerfile.debian
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ARG version=bullseye
ARG node_version=16
FROM node:${node_version}-${version}
RUN apt update
RUN apt install -y build-essential libssl-dev

WORKDIR /usr/app/
23 changes: 23 additions & 0 deletions cmake/toolchain/ci.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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})
if (CMAKE_C_COMPILER MATCHES clang)
add_link_options("-fuse-ld=lld")
endif()

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}")

0 comments on commit bc2d8a8

Please sign in to comment.