From 2a1419b50b9c3e0148029feb09bbf0b44e7bc210 Mon Sep 17 00:00:00 2001 From: Mahdi Sharifi Date: Tue, 9 Apr 2024 14:28:27 +0330 Subject: [PATCH] Add cross compilation --- .github/workflows/linux-daily-check.yml | 77 +++++++++++++++-------- .github/workflows/macos-daily-check.yml | 26 +++++--- .github/workflows/windows-daily-check.yml | 13 ++-- index.js | 60 ++++++++++++++---- 4 files changed, 123 insertions(+), 53 deletions(-) diff --git a/.github/workflows/linux-daily-check.yml b/.github/workflows/linux-daily-check.yml index 610b789..884b026 100644 --- a/.github/workflows/linux-daily-check.yml +++ b/.github/workflows/linux-daily-check.yml @@ -1,4 +1,4 @@ -name: Linux daily check +name: Linux on: schedule: @@ -7,34 +7,57 @@ on: jobs: update: - name: Linux daily check + name: Linux runs-on: ubuntu-latest strategy: matrix: arch: [amd64, arm64] + include: + - arch: arm64 + is_arm: true + # container: + # image: ubuntu:devel steps: - - name: Update system - run: sudo apt-get update && sudo apt-get --yes upgrade - - - name: Install Nodejs 21 repo - run: sudo apt-get install --yes ca-certificates curl gnupg && curl -sL https://deb.nodesource.com/setup_21.x | sudo bash - && sudo apt-get update - - - name: Install building tools - run: sudo apt-get install --yes git python3 python3-pip gcc g++ make ninja-build nodejs sudo - - - name: Clone the repo - run: git clone https://github.com/devraymondsh/libnode-distributable - - - name: Run sccache-cache - uses: mozilla-actions/sccache-action@v0.0.4 - - - name: Run the script - env: - CC: "sccache gcc" - CXX: "sccache g++" - ARCH: ${{ matrix.arch }} - SCCACHE_GHA_ENABLED: "true" - run: cd libnode-distributable && node index.js - - - name: Find the shared library - run: find libnode-distributable/node -name libnode.so\* -not -name '*.TOC' -not -name '*.toc' -exec ls {} \; + # - name: Update system + # run: apt-get update && apt-get install -y sudo + + - uses: pguyot/arm-runner-action@v2 + with: + # base_image: raspios_lite_arm64:latest + base_image: https://dietpi.com/downloads/images/testing/DietPi_RPi5-ARMv8-Bookworm.img.xz + commands: | + apt-get update + apt-get install --yes ca-certificates curl gnupg && curl -sL https://deb.nodesource.com/setup_21.x | bash - && apt-get update + apt-get install --yes git python3 python3-pip gcc g++ make linux-headers-generic build-essential binutils libz-dev linux-libc-dev ninja-build nodejs + git clone https://github.com/devraymondsh/libnode-distributable + ARCH=arm64 cd libnode-distributable && node index.js + + # - name: Install Nodejs 21 repo + # run: apt-get install --yes ca-certificates curl gnupg && curl -sL https://deb.nodesource.com/setup_21.x | bash - && apt-get update + + # - name: Install building tools + # run: apt-get install --yes git python3 python3-pip gcc g++ make linux-headers-generic build-essential binutils libz-dev linux-libc-dev ninja-build nodejs + + # - if: ${{ matrix.is_arm }} + # name: Install cross platform building tools + # run: apt-get install --yes crossbuild-essential-arm64 linux-libc-dev-arm64-cross binutils-aarch64-linux-gnu gcc-aarch64-linux-gnu g++-aarch64-linux-gnu + + # - name: Clone the repo + # run: git clone https://github.com/devraymondsh/libnode-distributable + + # # - if: ${{ ! matrix.is_arm }} + # - name: Run ccache-cache + # uses: hendrikmuhs/ccache-action@v1.2 + # with: + # create-symlink: true + # key: ${{ github.workflow }}-${{ matrix.arch }} + + # - name: Run the script + # env: + # CC: "gcc" + # CXX: "g++" + # ARCH: ${{ matrix.arch }} + # run: cd libnode-distributable && node index.js + + # - name: Find the shared library + # run: find libnode-distributable/node -name libnode.so\* -not -name '*.TOC' -not -name '*.toc' -exec ls {} \; diff --git a/.github/workflows/macos-daily-check.yml b/.github/workflows/macos-daily-check.yml index 4519324..097e8e9 100644 --- a/.github/workflows/macos-daily-check.yml +++ b/.github/workflows/macos-daily-check.yml @@ -1,4 +1,4 @@ -name: Macos daily check +name: Macos on: schedule: @@ -7,11 +7,17 @@ on: jobs: update: - name: Macos daily check - runs-on: macos-latest + name: Macos strategy: matrix: arch: [amd64, arm64] + include: + - arch: arm64 + os: macos-14 + is_arm: true + - arch: amd64 + os: macos-13 + runs-on: ${{ matrix.os }} steps: - name: Install building tools run: brew install node python ninja nasm git @@ -19,16 +25,18 @@ jobs: - name: Clone the repo run: git clone https://github.com/devraymondsh/libnode-distributable - - name: Run sccache-cache - uses: mozilla-actions/sccache-action@v0.0.4 + - name: Run ccache-cache + uses: hendrikmuhs/ccache-action@v1.2 + with: + create-symlink: true + key: ${{ github.workflow }}-${{ matrix.arch }} - name: Run the script env: - CC: "sccache cc" - CXX: "sccache c++" + CC: "cc" + CXX: "c++" ARCH: ${{ matrix.arch }} - SCCACHE_GHA_ENABLED: "true" run: cd libnode-distributable && node index.js - name: Find the shared library - run: find libnode-distributable/node -name libnode.so\* -not -name '*.TOC' -not -name '*.toc' -exec ls {} \; + run: find libnode-distributable/node -name libnode.dylib\* -not -name '*.TOC' -not -name '*.toc' -exec ls {} \; diff --git a/.github/workflows/windows-daily-check.yml b/.github/workflows/windows-daily-check.yml index 0db1bde..5c9bc3b 100644 --- a/.github/workflows/windows-daily-check.yml +++ b/.github/workflows/windows-daily-check.yml @@ -1,4 +1,4 @@ -name: Windows daily check +name: Windows on: schedule: @@ -7,7 +7,7 @@ on: jobs: update: - name: Windows daily check + name: Windows runs-on: windows-latest strategy: matrix: @@ -19,7 +19,6 @@ jobs: - uses: MinoruSekine/setup-scoop@v3 with: - buckets: extras update_path: true run_as_admin: true scoop_update: true @@ -30,13 +29,15 @@ jobs: - name: Clone the repo run: git clone https://github.com/devraymondsh/libnode-distributable - - name: Run sccache-cache - uses: mozilla-actions/sccache-action@v0.0.4 + - name: Run ccache-cache + uses: hendrikmuhs/ccache-action@v1.2 + with: + # create-symlink: true + key: ${{ github.workflow }}-${{ matrix.arch }} - name: Run the script env: ARCH: ${{ matrix.arch }} - SCCACHE_GHA_ENABLED: "true" run: cd libnode-distributable ; node index.js - name: Find the shared library diff --git a/index.js b/index.js index 858192f..10a15ec 100644 --- a/index.js +++ b/index.js @@ -3,16 +3,12 @@ import { cpus } from "node:os"; import fs from "node:fs/promises"; import { spawn } from "node:child_process"; -let CC = process.env.CC; -let CXX = process.env.CXX; -let ARCH = process.env.ARCH; -if (!CC) CC = "gcc"; -if (!CXX) CXX = "g++"; -if (!ARCH) ARCH = "amd64"; +// let ARCH = process.env.ARCH; +// const arch = ARCH == "amd64" ? "x64" : "arm64"; +const arch = "arm64"; const coreCount = cpus().length; const threadCount = coreCount * 2; -const arch = ARCH == "amd64" ? "x64" : "arm64"; let os; switch (process.platform) { case "darwin": @@ -57,7 +53,7 @@ const isANewerVersion = (oldVer, newVer) => { const spawnAsync = (program, args, cwd) => new Promise((resolve, reject) => { - console.log([program, ...args].join(" ")); + console.log("Running:", [program, ...args].join(" ")); const child = spawn(program, args, cwd ? { cwd } : {}); @@ -85,16 +81,58 @@ if (!syncFs.existsSync("node")) { `v${latestNodeVersion}`, "--depth=1", ], - undefined + undefined, + {} ); } +let extraArgs = []; if (process.platform == "win32") { - await spawnAsync("vcbuild.bat", [arch, "dll"], "node"); + await spawnAsync( + ".\\vcbuild.bat", + [ + arch, + "dll", + // "/p:CLToolExe=cl.exe /p:CLToolPath=C:\\Users\\runneradmin\\.cargo\\bin\\cl.exe", + ], + "node" + ); } else { + if (arch === "arm64") { + extraArgs.push("--with-arm-float-abi"); + extraArgs.push("hard"); + extraArgs.push("--with-arm-fpu"); + extraArgs.push("neon"); + + // if (process.platform === "linux") { + // extraArgs.push("--cross-compiling"); + + // // process.env.ARCH = "aarch64"; + // process.env.GYP_CROSSCOMPILE = "1"; + // process.env.CROSS_COMPILE = "aarch64-linux-gnu-"; + + // process.env.AR_host = "ar"; + // process.env.CC_host = "ccache gcc"; + // process.env.CXX_host = "ccache g++"; + // process.env.LD = "aarch64-linux-gnu-ld"; + // process.env.AR = "aarch64-linux-gnu-ar"; + // process.env.AS = "aarch64-linux-gnu-as"; + // process.env.NM = "aarch64-linux-gnu-nm"; + // process.env.STRIP = "aarch64-linux-gnu-strip"; + // process.env.RANLIB = "aarch64-linux-gnu-ranlib"; + // process.env.CC = "ccache aarch64-linux-gnu-gcc"; + // process.env.CXX = "ccache aarch64-linux-gnu-g++"; + // process.env.OBJDUMP = "aarch64-linux-gnu-objdump"; + + // // process.env.CFLAGS = "-march=armv8 -mfpu=neon -mfloat-abi=hard"; + // // process.env.CFLAGS = "-march=arm64"; + // // process.env.CXXFLAGS = process.env.CFLAGS; + // } + } + await spawnAsync( "./configure", - ["--ninja", "--shared", "--dest-cpu", arch, "--dest-os", os], + ["--shared", "--dest-cpu", arch, "--dest-os", os, ...extraArgs], "node" ); await spawnAsync("make", [`-j${threadCount}`], "node");