Skip to content

Instantly share code, notes, and snippets.

@pepyakin
Last active March 22, 2022 12:05
Show Gist options
  • Save pepyakin/2ff227c2d837a2eacd8d3879d5e0c94f to your computer and use it in GitHub Desktop.
Save pepyakin/2ff227c2d837a2eacd8d3879d5e0c94f 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
@CyberDuck79
Copy link

CyberDuck79 commented Apr 1, 2021

Get this error while trying to compile:

error: unsupported platform
   --> /home/rust/src/cargo_home/registry/src/github.com-1ecc6299db9ec823/wasmtime-runtime-0.22.0/src/traphandlers.rs:174:21
    |
174 |                     compile_error!("unsupported platform");
    |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0308]: mismatched types
   --> /home/rust/src/cargo_home/registry/src/github.com-1ecc6299db9ec823/wasmtime-runtime-0.22.0/src/traphandlers.rs:156:52
    |
156 |         unsafe fn get_pc(cx: *mut libc::c_void) -> *const u8 {
    |                   ------                           ^^^^^^^^^ expected *-ptr, found `()`
    |                   |
    |                   implicitly returns `()` as its body has no tail or `return` expression
    |
    = note: expected raw pointer `*const u8`
                 found unit type `()`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.
error: could not compile `wasmtime-runtime`

I read on other places on the internet that wasmtime-runtime can't be compiled for arm, but they don't say either that substrate can't be compiled for arm so I don't really understand did you have this problem ?

@kukabi
Copy link

kukabi commented May 30, 2021

I'm getting the same as @CyberDuck79. Any news on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment