Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Help: How to build for RPi - armv7l ? #1221

Closed
dimzeta opened this issue Jun 16, 2021 · 16 comments
Closed

Help: How to build for RPi - armv7l ? #1221

dimzeta opened this issue Jun 16, 2021 · 16 comments

Comments

@dimzeta
Copy link

dimzeta commented Jun 16, 2021

Hi guys,
First of all thank you for this package, it looks awesome.

I would like to build my NodeJS app for my Raspberry PI, working on armv7l.

I've been trying to do that for a week, no success.
I am pretty new in this world, so any help is really appreciated.

Currently I'm working on MacOS, but if needed I can move to a Linux machine if it's simpler to do it.
I tried to compile directly via a RPi, but it takes endless hours, and my RPi is hot as hell.
Then I tried to emulate a RPi with QEMU, I did not succeed.

I'm stuck, I don't know what to do.

Thanks for your help!

@robertsLando
Copy link
Contributor

Requires pkg-fetch 3.2.0

Ref: #1215

@dimzeta
Copy link
Author

dimzeta commented Jun 16, 2021

Thank you @robertsLando.

I use this workaround to force pkg to use pkg-fetch 3.2.0:

{
  "resolutions": {
    "pkg/pkg-fetch": "^3.2"
  }
}

But it seems it doesn't want to use linuxstatic:

npx pkg package.json --targets node14.17.0-linuxstatic-armv7 --debug
> pkg@5.2.1
> Fetching base Node.js binaries to PKG_CACHE_PATH
  fetched-v14.17.0-linux-armv7        [                    ] 0%
> Error! 404: Not Found
> Not found in remote cache:
  {"tag":"v3.2","name":"node-v14.17.0-linux-armv7"}
> Building base binary from source:
  built-v14.17.0-linux-armv7
> Cloning Node.js repository from GitHub...

@robertsLando
Copy link
Contributor

robertsLando commented Jun 16, 2021

Based on this: https://github.com/vercel/pkg/blob/master/lib/index.ts#L163

Seems that linuxstatic binaries are only used when host platform is different from target and the target is linux or alpine, platform comes from here: https://github.com/vercel/pkg-fetch/blob/main/lib/system.ts#L61

I would suggest to allow override this with an option @jesec @erossignon ? Maybe --static.

@dimitribocquet What you could do is to patch the code on your side and edit that line to force linuxstatic for now to see if it works

@dimzeta
Copy link
Author

dimzeta commented Jun 16, 2021

I have hardcoded fabPlatform = 'linuxstatic' and the compilation works well on my RPi.
If I compile from my OSX to my RPi, I've got some warnings, but it seems the executable is working as well:

/Users/dimitribocquet/.pkg-cache/v3.2/fetched-v14.17.0-linuxstatic-armv7: /Users/dimitribocquet/.pkg-cache/v3.2/fetched-v14.17.0-linuxstatic-armv7: cannot execute binary file
/Users/dimitribocquet/.pkg-cache/v3.2/fetched-v14.17.0-linuxstatic-armv7: /Users/dimitribocquet/.pkg-cache/v3.2/fetched-v14.17.0-linuxstatic-armv7: cannot execute binary file
> Warning Failed to make bytecode node14.17.0-armv7 for file /snapshot/hello-world/index.js
/Users/dimitribocquet/.pkg-cache/v3.2/fetched-v14.17.0-linuxstatic-armv7: /Users/dimitribocquet/.pkg-cache/v3.2/fetched-v14.17.0-linuxstatic-armv7: cannot execute binary file
/Users/dimitribocquet/.pkg-cache/v3.2/fetched-v14.17.0-linuxstatic-armv7: /Users/dimitribocquet/.pkg-cache/v3.2/fetched-v14.17.0-linuxstatic-armv7: cannot execute binary file
> Warning Failed to make bytecode node14.17.0-armv7 for file /snapshot/hello-world/node_modules/express/index.js
...

@robertsLando
Copy link
Contributor

Ok so creating an option like --static would be good here. Would you like to submit a PR for that?

@jesec
Copy link
Contributor

jesec commented Jun 17, 2021

Based on this: https://github.com/vercel/pkg/blob/master/lib/index.ts#L163

Seems that linuxstatic binaries are only used when host platform is different from target and the target is linux or alpine, platform comes from here: https://github.com/vercel/pkg-fetch/blob/main/lib/system.ts#L61

I would suggest to allow override this with an option @jesec @erossignon ? Maybe --static.

@dimitribocquet What you could do is to patch the code on your side and edit that line to force linuxstatic for now to see if it works

Not a good idea. linuxstatic-armv7 platform is supported on best-effort basis, and it does not worth the complexity of a top-level command line argument. That argument is confusing, hard to maintain and pretty much only useful in extremely limited scenarios (and, provided the users understand the implications).

OP is doing things wrong. You are not supposed to emulate armv7 platform. Instead, you should use Linux x86-64, and configure binfmt to allow armv7 binaries to execute.

Additionally, read README again.

@robertsLando
Copy link
Contributor

@jesec Ok so just to know how should someone build an armv7 linux image from for example an x86/64 or arm64 linux?

@jesec
Copy link
Contributor

jesec commented Jun 17, 2021

@jesec Ok so just to know how should someone build an armv7 linux image from for example an x86/64 or arm64 linux?

Read README. You have to either setup emulation (so armv7 binaries can be executed) or disable bytecode generation.

@dimzeta
Copy link
Author

dimzeta commented Jun 17, 2021

@jesec I understand that this option is not a good idea.

Here I try to pkg my app with a real RPi, using pkg-fetch node-v14.17.0-linuxstatic-armv7.
But it seems it doesn't want to use linuxstatic (see my comment before).

This is the reason why this option appears. Maybe there is another way to do that?

@blami
Copy link

blami commented Sep 4, 2021

I am running into inverted problem here. Our buildfarm is arm64 and we are trying to build both arm64 and armv7 binaries. It is perfectly possible to do so (in fact e.g. Ubuntu compiles the entire distribution armv7 binaries on arm64 too).

Because build host arch (arm64) != target arch (armv7), pkg forces linux to linuxstatic which is not needed (in fact it will break build in fetch with Not able to build 'linuxstatic' ...). I think it would be good to have a way to tell pkg to use whatever destination triplet user selected and not replace linux with linuxstatic based on host and target mismatch.

@dotob
Copy link

dotob commented Sep 28, 2021

i have the same problem as @dimitribocquet. pkg on a pi which downloads linuxstatic but does not use it somehow. is there any way to support? may a bountyhunt or something similar help?

pkg for raspi would be awesome.

thanks for great work so far.

@QuickJack
Copy link

@dotob I have created #1275 that fixes native builds. This should allow native builds of linuxstatic targets for the armv7 architecture. I does not require additional command line options.

I am using this inside an arm32v7/node:14 container. But it should also work directly on real armv7 hardware.

@dotob
Copy link

dotob commented Oct 13, 2021

thanks @QuickJack sounds great. i will test it asap

@pfried
Copy link

pfried commented Nov 9, 2021

@QuickJack could you open a PR for this?

@QuickJack
Copy link

I already created a PR. Unfortunately, it was rejected (s. #1275). But you are free to use/test my fork.

@jesec
Copy link
Contributor

jesec commented Nov 10, 2021

I am running into inverted problem here. Our buildfarm is arm64 and we are trying to build both arm64 and armv7 binaries. It is perfectly possible to do so (in fact e.g. Ubuntu compiles the entire distribution armv7 binaries on arm64 too).

Because build host arch (arm64) != target arch (armv7), pkg forces linux to linuxstatic which is not needed (in fact it will break build in fetch with Not able to build 'linuxstatic' ...). I think it would be good to have a way to tell pkg to use whatever destination triplet user selected and not replace linux with linuxstatic based on host and target mismatch.

It is necessary because it is extremely difficult to set up an environment to run normal linux binaries of a different architecture. One would have to install all common system libs (libc, libstdc++, etc.) of that architecture and carefully configure the library paths. With linuxstatic, it is just "one QEMU install" away.

As for armv7 with arm64, unfortunately, today, you can no longer treat arm64 as a fully armv7 compatible architecture. ARM made it clear that next reference design would ditch armv7 compatibility. In fact, I happen to have one arm64 machine that can't run armv7 executables without emulation.

@vercel vercel locked and limited conversation to collaborators Nov 10, 2021
@jesec jesec closed this as completed Nov 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants