Docker Hub: https://hub.docker.com/r/sensorfu/rust-musl-arm/
This image uses rust Docker image and musl-cross-make tool to build the C/C++ cross compilation environment.
Everything should be set to automatically get cross compiled binaries. However, some Rust crates depend on external libraries which you have to cross compile yourself. See below for how to cross compile C/C++ libraries.
Mandatory Hello World example:
# export USER=root
# cargo new --bin helloworld
Created binary (application) `helloworld` project
# cd helloworld
# cargo build --release
Compiling helloworld v0.1.0 (file:///helloworld)
Finished release [optimized] target(s) in 0.41 secs
# file ./target/armv7-unknown-linux-musleabihf/release/helloworld
./target/armv7-unknown-linux-musleabihf/release/helloworld: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, not stripped
It's possible to use this image to cross compile C/C++ libraries targeting ARMv7
Musl. For autoconf based
projects it should be enough to call ./configure
script with
--host=armv7-linux-musleabihf
parameter.
Some environment variables are already set to help with cross compiling C/C++ libraries. See section "Environment variables" below.
For example compiling LibreSSL:
# export LIBRESSL="libressl-2.5.5"
# mkdir work && cd work
# curl -fo- https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/${LIBRESSL}.tar.gz | tar zxf -
# cd ${LIBRESSL}
# ./configure --host=armv7-linux-musleabihf --enable-shared=no && make -j$(nproc)
# file apps/openssl/openssl
apps/openssl/openssl: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-armhf.so.1, not stripped
Inside the image there are various environment variables set:
CC
: Points to ARMv7 GCC C compilerCXX
: Points to ARMv7 GCC C++ compilerLD
: Points to ARMv7 GCC linker
- Fetch musl-cross-make sources into tree:
git submodule update --init
- Build the docker image:
docker build -t sensorfu/rust-musl-arm .
- Push to Docker Hub:
docker push sensorfu/rust-musl-arm
Excerpt from https://www.rust-lang.org/en-US/legal.html:
Rust’s code is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0), with portions covered by various BSD-like licenses. See LICENSE-APACHE, LICENSE-MIT, and COPYRIGHT for details.
musl-cross-make doesn't specify license. Individual components installed by musl-cross-make have their own licenses.