Skip to content

Commit

Permalink
armv7 && arm64 support (#17)
Browse files Browse the repository at this point in the history
* arm support

* arm test yml

* arm toolchain

* fix toolchain path

* install compilers

* add sudo

* export ARM_SYSROOT

* env

* test

* fix root path

* include dir

* fix

* try

* test

* tests

* test arm

* delete arm-test yml

* arm64

* compile args

* test

* check if arm64

* finalize arm64

* v0.0.15
  • Loading branch information
murat-dogan authored Nov 23, 2020
1 parent 8e70899 commit a9fb633
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 10 deletions.
63 changes: 62 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,60 @@ jobs:
env:
CI: true

build-linux-armv7:
runs-on: ubuntu-20.04

strategy:
matrix:
node-version: [10.x, 11.x, 12.x, 13.x, 14.x]
steps:
- uses: actions/checkout@v2
- name: Prepare Cross Compile
run: |
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
with:
node-version: ${{ matrix.node-version }}
- name: Build & Upload
run: |
npm install --ignore-scripts
node_modules/.bin/prebuild --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: [10.x, 11.x, 12.x, 13.x, 14.x]
steps:
- uses: actions/checkout@v2
- name: Prepare Cross Compile
run: |
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/953c2471bc7e71a788309f6c2d2003e8b703305d/debian_sid_arm64_sysroot.tar.xz
tar xf debian_sid_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 --backend cmake-js --arch arm64 --upload -u ${{ secrets.GITHUB_TOKEN }} -- --CDCMAKE_TOOLCHAIN_FILE:FILEPATH=./cmake/toolchain/arm64.cmake
env:
CI: true

build-windows-x64:
runs-on: windows-latest
strategy:
Expand Down Expand Up @@ -130,7 +184,14 @@ jobs:
CI: true

npm-publish:
needs: [build-linux, build-windows-x64, build-windows-x86, build-macos]
needs:
[
build-linux,
build-linux-armv7,
build-windows-x64,
build-windows-x86,
build-macos,
]
name: npm-publish
runs-on: ubuntu-latest
steps:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/build
/prebuilds
node_modules
.vscode/ipch
.vscode/ipch
/tmp
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
cmake_minimum_required(VERSION 3.14)
project(node_datachannel VERSION 0.0.14)
project(node_datachannel VERSION 0.0.15)

include_directories(${CMAKE_JS_INC})

set(CMAKE_BUILD_TYPE Release)

set(OPENSSL_USE_STATIC_LIBS TRUE)
find_package(OpenSSL REQUIRED)
# Got linker error for arm64
# /usr/lib/gcc-cross/aarch64-linux-gnu/9/../../../../aarch64-linux-gnu/bin/ld: ../sysroot/usr/lib/aarch64-linux-gnu/libcrypto.a(sha1-armv8.o): relocation R_AARCH64_PREL64 against symbol `OPENSSL_armcap_P' which may bind externally can not be used when making a shared object; recompile with -fPIC
# ../sysroot/usr/lib/aarch64-linux-gnu/libcrypto.a(sha1-armv8.o): in function `sha1_block_armv8':
# (.text+0x1240): dangerous relocation: unsupported relocation
if(NOT ${NODE_ARCH} STREQUAL "arm64")
set(OPENSSL_USE_STATIC_LIBS TRUE)
find_package(OpenSSL REQUIRED)
endif()


include(FetchContent)

Expand Down
17 changes: 17 additions & 0 deletions cmake/toolchain/arm64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
set(CMAKE_SYSTEM_NAME Linux)
set(TOOLCHAIN_PREFIX aarch64-linux-gnu)

# cross compilers to use for C and C++
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)

# Needed sysroot
# https://github.com/webrtc-uwp/chromium-build/blob/master/linux/sysroot_scripts/sysroots.json
set(CMAKE_SYSROOT "$ENV{ARM64_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_FLAGS "-march=armv8-a -fPIC -Wno-error=format-truncation" CACHE STRING "Compiler Flags")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "Compiler Flags")
17 changes: 17 additions & 0 deletions cmake/toolchain/armv7.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
set(CMAKE_SYSTEM_NAME Linux)
set(TOOLCHAIN_PREFIX arm-linux-gnueabihf)

# cross compilers to use for C and C++
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)

# Needed sysroot
# https://github.com/webrtc-uwp/chromium-build/blob/master/linux/sysroot_scripts/sysroots.json
set(CMAKE_SYSROOT "$ENV{ARM_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_FLAGS "-march=armv7-a -mfpu=neon-vfpv4 -mfloat-abi=hard -fPIC -Wno-error=format-truncation" CACHE STRING "Compiler Flags")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "Compiler Flags")
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-datachannel",
"version": "0.0.14",
"version": "0.0.15",
"description": "libdatachannel node bindings",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand All @@ -11,9 +11,9 @@
"_from": "node-datachannel@latest",
"scripts": {
"install": "prebuild-install || (npm install --ignore-scripts --only=dev && npm run _prebuild)",
"install-nice": "npm run clean && cmake-js build --CDUSE_NICE=1 --CDNO_EXAMPLES=1 --CDNO_TESTS=1 -DUSE_GNUTLS=0",
"build": "cmake-js build --CDNO_EXAMPLES=1 --CDNO_TESTS=1",
"_prebuild": "prebuild --backend cmake-js -- --CDNO_EXAMPLES=1 --CDNO_TESTS=1 -DUSE_GNUTLS=0",
"install-nice": "npm run clean && cmake-js build --CDUSE_NICE=1",
"build": "cmake-js build",
"_prebuild": "prebuild --backend cmake-js",
"clean": "cmake-js clean",
"test": "jest --forceExit"
},
Expand Down

0 comments on commit a9fb633

Please sign in to comment.