Giter Club home page Giter Club logo

rust-crosscompiler-arm's Introduction

Docker image for Rust crosscompilation dedicated to ARM architectures v6 and more

Build Status

Keywords: rust arm raspberrypi crosscompilation docker armv6 armv7

Public trusted images available on:

This repository is used to build a Docker image based on Debian for the Rust programming language for arm (eg. : all models of Raspberry Pi) architectures and a few supporting tools. The image includes :

  • rustc
  • rustdoc
  • cargo
  • git
  • SSL certificates
  • build essentials
  • Linaro cross compiler
  • many libraries compiled for arm

So it should be able to run cargo build on most projects out of the box. The path /source is a volume where you can mount a Cargo project from the host machine.

Docker image is automatically build and published once a week, so this "stable" rust compiler it is always update-to-date with the official one.

Sample

You can see this Docker image in action in this project: https://github.com/dlecan/generic-dns-update

Look at Travis build scripts.

Why ?

To setup a full cross-compiling environment is complicated. You need:

  • a build toolchain for armhf architecture : not available on Debian, but easy to install on Ubuntu
  • a Rust compiler for armhf architecture : no binaries are available, so you need to compile it from sources
  • to tell Cargo how to cross compile
  • many development libraries (headers + lib) such as openssl, compiled for arm architecture
  • ...

After that, if you succeed, your workstation will be a real mess.

So I created this Docker image dedicated to Rust cross-compilation on arm.

Usage

The following command will run cargo build --release with the current directory on the host shared, with Rust 'stable' channel:

docker run -it --rm \
  -v $(pwd):/source \
  dlecan/rust-crosscompiler-arm:stable

Rust 'target' architecture is forced to arm-unknown-linux-gnueabihf within the container (parameter target=arm-unknown-linux-gnueabihf automatically added).

If you want to run another command from within the container, add it at the end of the previous command line. For example, to display Cargo version:

docker run -it --rm \
  -v $(pwd):/source \
  dlecan/rust-crosscompiler-arm:stable \
  cargo --version

Optimized usage

With the previous configuration, Cargo dependencies will be downloaded and compiled again and again each time you launch the Docker container. If you want to avoid this behavior, you must persist Cargo cache folders within the container on the host. The best is to share them with the Cargo cache folders of the host.

So you can use the following command line:

docker run -it --rm \
  -v $(pwd):/source \
  -v ~/.cargo/git:/root/.cargo/git \
  -v ~/.cargo/registry:/root/.cargo/registry \
  dlecan/rust-crosscompiler-arm:stable

This will cache and share sources of Cargo dependencies and Rust built librairies. It assumes that your Cargo configuration is located in ~/.cargo.

Caveat: unfortunately, with configuration, ~.cargo files will be owned by root user, so you will have to chown them to be able to use Cargo in the host.

To sum up, here is the script I use, located in /usr/local/sbin/rxc (rust cross compiler):

#!/bin/bash

docker run -it --rm \
  -v $(pwd):/source \
  -v ~/.cargo/git:/root/.cargo/git \
  -v ~/.cargo/registry:/root/.cargo/registry \
  dlecan/rust-crosscompiler-arm:stable "$@"

sudo chown -R `stat -c %u:%g $HOME` $(pwd) ~/.cargo

You can then rxc cargo build.

Usage with script

Inspiration

License

MIT

rust-crosscompiler-arm's People

Contributors

dlecan avatar jimmycuadra avatar superfluffy avatar celaus avatar frewsxcv avatar fbender avatar marikka avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.