Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerfile for aarch64 #2446

Open
ghost opened this issue Mar 27, 2023 · 3 comments
Open

Dockerfile for aarch64 #2446

ghost opened this issue Mar 27, 2023 · 3 comments

Comments

@ghost
Copy link

ghost commented Mar 27, 2023

I'm on an M2 Mac, and I've been trying to create a Dockerfile for aarch64, because the anchor build command takes over 15 minutes on my machine when using the current amd64 image.

I figured out how to build the Solana CLI tools from source (there's no aarch64 Linux binary), but now I'm stuck with the following error (when running anchor build):

/root/.rustup/toolchains/bpf/bin/cargo: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory

apt-file search libz.so.1 told me it belongs to zlib1g, but I already have it installed (the aarch64 version).

I managed to resolve the previous error

#16 228.0 qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory

by running

# apt-get install libc6-amd64-cross && mkdir /lib64 && ln -s /usr/x86_64-linux-gnu/lib/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2

but maybe that wasn't the correct approach?

Anyway, here's my Dockerfile (based on the official amd64 one):

FROM ubuntu:18.04

ARG DEBIAN_FRONTEND=noninteractive

ARG SOLANA_CLI
ARG ANCHOR_CLI

ENV NODE_VERSION="v17.0.1"
ENV HOME="/root"
ENV PATH="${HOME}/.cargo/bin:${PATH}"
ENV PATH="${HOME}/.local/share/solana/install/active_release/bin:${PATH}"
ENV PATH="${HOME}/.nvm/versions/node/${NODE_VERSION}/bin:${PATH}"

# Install base utilities.
RUN mkdir -p /workdir && mkdir -p /tmp && \
    apt-get update -qq && apt-get upgrade -qq && apt-get install -qq \
    build-essential git curl wget jq pkg-config python3-pip \
    libssl-dev libudev-dev clang libclang-dev \
    zlib1g-dev llvm cmake make libprotobuf-dev protobuf-compiler
    # https://github.com/solana-labs/solana/tree/v1.14.16#1-install-rustc-cargo-and-rustfmt

# Install rust.
RUN curl "https://sh.rustup.rs" -sfo rustup.sh && \
    sh rustup.sh -y && \
    rustup component add rustfmt clippy

# Install node / npm / yarn.
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
ENV NVM_DIR="${HOME}/.nvm"
RUN . $NVM_DIR/nvm.sh && \
    nvm install ${NODE_VERSION} && \
    nvm use ${NODE_VERSION} && \
    nvm alias default node && \
    npm install -g yarn

# Install Solana tools. https://docs.solana.com/cli/install-solana-cli-tools#build-from-source
RUN curl -L "https://github.com/solana-labs/solana/archive/refs/tags/v${SOLANA_CLI}.tar.gz" -o "${SOLANA_CLI}.tar.gz"
RUN tar xf "${SOLANA_CLI}.tar.gz"
WORKDIR "solana-${SOLANA_CLI}"
RUN ./scripts/cargo-install-all.sh /root/.local/share/solana/install/releases/1.14.16/solana-release
RUN echo "channel: v1.14.16\ncommit: 0fb2ffda2ec4abd71816f1c7f47223d547132c6d\ntarget: aarch64-unknown-linux-gnu">/root/.local/share/solana/install/releases/1.14.16/solana-release/version.yml

ENV PATH="/root/.local/share/solana/install/releases/1.14.16/solana-release/bin:$PATH"
RUN solana-install init "${SOLANA_CLI}"

# Install anchor.
RUN cargo install --git https://github.com/coral-xyz/anchor --tag ${ANCHOR_CLI} anchor-cli --locked

# Build a dummy program to bootstrap the BPF SDK (doing this speeds up builds).
RUN mkdir -p /tmp && cd /tmp && anchor init dummy && cd dummy && anchor build

The last command (anchor build) causes the above-mentioned errors.

The reason I'm doing this is because I want to make Solana development easier with my command-line tool create-solana-starter (a Grizzlython hackathon submission). Installing all the needed tools (Rust, Solana, Anchor, etc.) locally can be a hassle, so I would like to give users the option to use Docker instead.

Would appreciate any advice on how to proceed from here!

@buffalojoec
Copy link
Contributor

I got around the libssl issue by just manually installing the version it wanted, although I can't confidently say that it's safe or not:
https://github.com/Solana-Workshops/docker/blob/main/solana.Dockerfile#L14

@vadorovsky
Copy link
Contributor

I have the same issue and it seems that Rust Solana toolchain is x86_64 getting downloaded even on aarch64 Linux system. This is what I see in my aarch64 container (running on M2 Mac):

node@9fd3ed47fbfe:/tmp$ file /home/node/.rustup/toolchains/stable-aarch64-unknown-linux-gnu/bin/cargo
/home/node/.rustup/toolchains/stable-aarch64-unknown-linux-gnu/bin/cargo: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 4.1.49, with debug_info, not stripped
node@9fd3ed47fbfe:/tmp$ file /home/node/.rustup/toolchains/bpf/bin/cargo
/home/node/.rustup/toolchains/bpf/bin/cargo: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=8ce82da00b04ebeffef3123908ca46cc96f735ee, with debug_info, not stripped

What I need to figure out now is why is that x86_64 toolchain downloaded - whether it's Anchor or Solana scripts doing that.

@vadorovsky
Copy link
Contributor

OK, it's cargo-sbf-build doing that. It installs https://github.com/solana-labs/platform-tools here:

https://github.com/solana-labs/solana/blob/8c860e98949efafee878acfac9da67b0bf927cac/sdk/cargo-build-sbf/src/main.rs#L601-L607

And there are no binaries for linux-aarch64, the only aarch64 build is for macOS:

https://github.com/solana-labs/platform-tools/releases/tag/v1.37

There is an issue about that anza-xyz/platform-tools#66.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants