Skip to content

Instantly share code, notes, and snippets.

@woss
Forked from pepyakin/Dockerfile
Created March 22, 2022 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woss/0f208426747b2fa66377e21a3cfea748 to your computer and use it in GitHub Desktop.
Save woss/0f208426747b2fa66377e21a3cfea748 to your computer and use it in GitHub Desktop.
Substrate Raspberry PI cross-compile build
#!/bin/bash
# Run this script from the directory with the Cargo project.
docker run --rm -it \
--env BINDGEN_EXTRA_CLANG_ARGS="--sysroot=/usr/arm-linux-gnueabihf -D__ARM_PCS_VFP -mfpu=vfp -mfloat-abi=hard" \
--env CARGO_HOME=/home/rust/src/cargo_home \
-v "$(pwd)":/home/rust/src <containter id> \
cargo build --target=armv7-unknown-linux-gnueabihf --release
# Put this file in the root of substrate / polkadot directory and build the image using
# the following command:
#
# docker build -t <container id> .
#
# you can pick <container id> yourself. For example: `johndoe/rpi-cross`.
#
FROM rust:latest
RUN dpkg --add-architecture armhf && \
apt-get update && apt-get upgrade -y && \
apt-get install -y aptitude && \
aptitude install -y \
gcc-arm-linux-gnueabihf \
g++-arm-linux-gnueabihf \
pkg-config \
cmake \
libssl-dev \
git \
clang \
libclang-dev \
libssl-dev:armhf
# Install nightly with w32-u-u and add arvm7 to stable
RUN rustup target add armv7-unknown-linux-gnueabihf
RUN rustup install nightly && \
rustup target add wasm32-unknown-unknown --toolchain nightly &&\
cargo +nightly install --git https://github.com/alexcrichton/wasm-gc --force
ENV CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER arm-linux-gnueabihf-gcc
ENV PKG_CONFIG_ALLOW_CROSS 1
ENV PKG_CONFIG_PATH /usr/lib/arm-linux-gnueabihf/pkgconfig/
# Disallow the `pkg-config` crate to look for the config for zlib, because build.rs of `libz-sys`
# gets confused and pulls the system-wide library (i.e. of the host) instead of the target when
# cross-compiling. This essentially leads to static linking of zlib.
#
# Alternatively, we can supply LIBZ_SYS_STATIC=1. Weirdly enough, installing libgtk-3-dev:armhf
# also solves the problem somehow.
#
# Here is the related issue: https://github.com/rust-lang/libz-sys/issues/49
ENV ZLIB_NO_PKG_CONFIG 1
# This is for compiling GUI apps.
# RUN aptitude install -y libasound2-dev:armhf libgtk-3-dev:armhf libsdl2-dev:armhf
RUN useradd rust --user-group --create-home --shell /bin/bash --groups sudo
WORKDIR /home/rust/src
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment