Deno: Building for arm64

Created on 27 Feb 2019  路  9Comments  路  Source: denoland/deno

Builds for arm64 are now in CI, but are not ready for release. We still need to make some changes to make the tests work with this build.
I managed to get deno to build for arm64 using the aarch64-unknown-linux-gnu target. Currently It doesn't execute successfully on a raspberry pi 3b+ running a preview image of debian buster arm64/aarch64. It gives me the following print out:

root@rpi3:~/deno-build# ./deno https://deno.land/welcome.ts
#
# Fatal error in , line 0
# unreachable code
#
#
#
#FailureMessage Object: 0xfffff58d4d10
==== C stack trace ===============================

    ./deno(+0x8ad5fc) [0xaaaaafc445fc]
    ./deno(+0x9dd72c) [0xaaaaafd7472c]
    ./deno(+0x8a9f10) [0xaaaaafc40f10]
    ./deno(+0x83aa08) [0xaaaaafbd1a08]
    ./deno(+0x69c070) [0xaaaaafa33070]
    ./deno(+0x7bdbb4) [0xaaaaafb54bb4]
    ./deno(+0x7bdb00) [0xaaaaafb54b00]
    ./deno(+0x7bc6bc) [0xaaaaafb536bc]
    ./deno(+0x7bd9f8) [0xaaaaafb549f8]
    ./deno(+0x7bbbb8) [0xaaaaafb52bb8]
    ./deno(+0x2165dc) [0xaaaaaf5ad5dc]
    ./deno(+0x7c0be4) [0xaaaaafb57be4]
    ./deno(+0x663f68) [0xaaaaaf9faf68]
    ./deno(+0x7c0124) [0xaaaaafb57124]
    ./deno(+0x1c8e80) [0xaaaaaf55fe80]
    ./deno(+0x1c8f68) [0xaaaaaf55ff68]
    ./deno(+0x1b3dec) [0xaaaaaf54adec]
    ./deno(+0xce2f0) [0xaaaaaf4652f0]
    ./deno(+0x112b78) [0xaaaaaf4a9b78]
    ./deno(+0x11ef74) [0xaaaaaf4b5f74]
    ./deno(+0xb80c38) [0xaaaaaff17c38]
    ./deno(+0xb8fcf4) [0xaaaaaff26cf4]
    ./deno(+0xb814ec) [0xaaaaaff184ec]
    ./deno(+0x112d50) [0xaaaaaf4a9d50]
    /lib/aarch64-linux-gnu/libc.so.6(__libc_start_main+0xe4) [0xffff8644ed24]
    ./deno(+0xbae4c) [0xaaaaaf451e4c]

I opened up the executable with a arm compatible disassembler, and located the last call from within deno before failure, 0x1b3dec. It looks like this call occurs here https://github.com/denoland/deno/blob/b8a537d020f5e4495572daa4d8a59f51fa3b20d1/libdeno/api.cc#L54 This leads me to suspect an issue with loading the snapshot.


I managed to get this working successfully with the changes in my forked branch.

To replicate my arm64 build you will need docker installed.
Then it should be as simple as:

  1. Add the following options to .gn
target_cpu = "arm64"
v8_target_cpu = "arm64"
  1. Add the following to Dockerfile in your deno repo root
FROM ubuntu:bionic

RUN apt update && apt install -y curl

RUN curl https://sh.rustup.rs -sSf | sh -s -- -y

RUN /root/.cargo/bin/rustup target add aarch64-unknown-linux-gnu

RUN echo "[target.aarch64-unknown-linux-gnu]\nlinker = \"aarch64-linux-gnu-gcc\"" > /root/.cargo/config

RUN apt install -y nodejs yarn python build-essential cmake make

RUN apt -yq --no-install-suggests --no-install-recommends install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu g++-7-multilib libc6-arm64-cross

WORKDIR /deno

RUN echo "source $HOME/.cargo/env" > /root/.bash

CMD ["/bin/bash", "--init-file", "/root/.bash"]
  1. Run docker build -f Dockerfile -t deno-arm64-build . && docker run -it -v "$PWD/:/deno" -u $(id -u root):$(id -g ${USER}) deno-arm64-build in your deno repo root. This should build a docker image with the required tools and drop you into a bash shell on said image with your deno repo mounted at /deno.
  2. From this point you simply need to run cargo build --target=aarch64-unknown-linux-gnu --release
  3. Once the build completes the executable should be located at target/aarch64-unknown-linux-gnu/release/deno

I wasn't able to get a build working with tools/build.py, since I couldn't find a way to specify a target for rust it might be possible to use env vars like CC, AR, CFLAGS, etc. I might try that at some point, but I'm putting my efforts into figuring out if the snapshots are even being included in the build correctly right now.
I not sure what changed, but I can't get the build to work anymore with docker. I can still get this to work outside of docker though. I'm working on getting this into CI see #1887. The main problem with getting this into CI is how long it takes to build.

Edit: fixed some issues with the Dockerfile
Edit: added the current user group to the docker run command so this doesn't break your repo as much
Edit: my forked branch has modifications to make this work now

build feat

Most helpful comment

basic arm support added in 8c7a12d1b258f0ef5ab27f49c424331d43e8d97f

All 9 comments

@ry My guess at this point is that v8 snapshots are not independent of the binaries used to generate them. That would make since considering that the snapshots are generated by the compiler host using a native binary. Can you confirm this is the case with v8?

@afinch7 I'll have to dig into this later when I have some time - but one random guess - try v8_multi_arch_build = true

@ry Turns out I was right chromium has had a similar issue with cross compiled builds using snapshots. My plan at this point remove inclusion of compile time generated snapshots on cross compiled builds, and setup some logic to allow them to generate the snapshots during the first runtime(and store them on disk for next time). I would build on aarch64, but depot_tools doesn't seem to have a gn binary for aarch64. #1852

basic arm support added in 8c7a12d1b258f0ef5ab27f49c424331d43e8d97f

I have a project where deno would fit perfectly, I made some tests on x86_64 and it works well, but I will need arm support in the future, so does this have a place in the roadmap? What is the current status? What does it mean "basic support"?

ARM64 support was reverted some time ago... re-opening.

FYI, not sure if deno is using Travis CI in conjunction with github but Travis CI now supports multi arch including arm64, see https://docs.travis-ci.com/user/multi-cpu-architectures/ and you don't need to use qemu for that (as far as I understood, I didn't test it by myself)

I've also had zero issues building an aarch64 build for the last couple of versions that I've tested. I'd be happy to donate a few Raspberry Pi 4 (8GB) to this project in order to make a stable release happen. Now that the Mac has released their ARM hardware, I can also build the same on there for that.

FYI, not sure if deno is using Travis CI in conjunction with github but Travis CI

We use GitHub Actions exclusively. We are working with GitHub on the potential of their ARM64 support.

I'd be happy to donate a few Raspberry Pi 4 (8GB) to this project in order to make a stable release happen.

That isn't necessary, and likely wouldn't solve the problem of integrating it reliably into a repeatable and supportable APIs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

justjavac picture justjavac  路  3Comments

zugende picture zugende  路  3Comments

doutchnugget picture doutchnugget  路  3Comments

kitsonk picture kitsonk  路  3Comments

kyeotic picture kyeotic  路  3Comments