vercel / ncc

Compile a Node.js project into a single file. Supports TypeScript, binary addons, dynamic requires.
https://npmjs.com/@vercel/ncc
MIT License
9.11k stars 289 forks source link

How do I cross build a package for Raspberry Pi if I am on Mac/Linux? #576

Closed alextran1502 closed 4 years ago

alextran1502 commented 4 years ago

Hello,

There are some libraries such as serial-port or node-usb that needed to be built on the target platform to generate the correct binary. How do I cross build a project for Raspberry Pi if I am on Mac/Linux?

Thanks, Alex

styfle commented 4 years ago

Hi Alex,

ncc doesn't compile for a specific target, it bundles javascript from multiple js files into a single js file.

If you have native dependencies, you'll need to use npm install or yarn install with the correct target arch which it outside the scope of ncc.

See this answer: https://stackoverflow.com/a/45988975/266535

kohlerdominik commented 2 years ago

@alextran1502 did you find a solution for this? I'm currently stuck with serial-port and the same issue as you. Running ncc build in WSL and Github Actions seems to install the wrong binaries. If I build on the RPI, it works fine.

alextran1502 commented 2 years ago

You will have to build it from the RPI or choose the correct machine architecture on github action to build it on. If i remember correctly it is arm64v7

On Tue, Mar 8, 2022 at 11:23 AM Dominik Kohler @.***> wrote:

@alextran1502 https://github.com/alextran1502 did you find a solution for this? I'm currently stuck with serial-port and the same issue as you. Running ncc build in WSL and Github Actions seems to install the wrong binaries. If I build on the RPI, it works fine.

— Reply to this email directly, view it on GitHub https://github.com/vercel/ncc/issues/576#issuecomment-1062019065, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGONL7VBMVPUBBTBO7JYNETU66EHZANCNFSM4P7DGBUQ . You are receiving this because you were mentioned.Message ID: @.***>

kohlerdominik commented 2 years ago

As far as I'm aware there's no native possibility to use arm architecture with github actions yet.

Therefore I used an action using QEMU.

name: Build for RPI
on:
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: uraimo/run-on-arch-action@v2.1.1
      with:
        arch: aarch64
        distro: bullseye
        githubToken: ${{ github.token }}
        install: |
          apt-get update
          apt-get install -y ca-certificates curl wget build-essential --no-install-recommends
          curl -fsSL https://deb.nodesource.com/setup_16.x | bash -
          apt-get install -y nodejs
        run: |
          npm ci --no-audit
          npm run build