├── README.md └── Dockerfile /README.md: -------------------------------------------------------------------------------- 1 | # docker-rust-esp 2 | 3 | Provides a `Dockerfile` defining a Rust build environment for the ESP32 and ESP8266. Builds LLVM and Rust with support for the Xtensa ISA. 4 | 5 | For more information on the Xtensa Rust toolchain, refer to the following repositories: 6 | https://github.com/esp-rs/rust 7 | https://github.com/MabezDev/xtensa-rust-quickstart 8 | 9 | ## Building 10 | 11 | Ensure that [Docker](https://www.docker.com/) is installed on your system. At least _4GB_ of RAM (_6GB_+ recommended) should be available to the container; too little memory can cause the build to fail. Note that this process can be lengthy, potentially taking hours depending on your hardware. Please be patient. 12 | 13 | To build the image (tagging it with the name `rust-esp`): 14 | 15 | ```bash 16 | $ git clone https://github.com/esp-rs/docker-rust-esp.git 17 | $ cd docker-rust-esp/ 18 | $ docker build -t rust-esp . 19 | ``` 20 | 21 | ## Usage 22 | 23 | Once the image has been built, from the root directory of your project (ie. that containing `Cargo.toml`), run: 24 | 25 | ```bash 26 | $ docker run -v $PWD:/project --rm rust-esp 27 | ``` 28 | 29 | This will build the application using `xargo` in `release` mode, targeting the architecture specified in your `.cargo/config` file. 30 | 31 | https://github.com/japaric/xargo 32 | 33 | Alternatively if you would prefer an interactive session: 34 | 35 | ```bash 36 | $ docker run -v $PWD:/project -it --rm rust-esp /bin/bash 37 | ``` 38 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:bionic 2 | MAINTAINER Jesse Braham 3 | 4 | 5 | ## Update apt's package cache and install all build dependencies. Clean up the 6 | ## package cache when we're finished. 7 | ## 8 | ## Setting DEBIAN_FRONTEND to noninteractive ensures that `apt-get` will never 9 | ## try to interact with us. 10 | ## https://manpages.ubuntu.com/manpages/xenial/man7/debconf.7.html 11 | ARG DEBIAN_FRONTEND=noninteractive 12 | RUN apt-get update && apt-get install -y \ 13 | clang \ 14 | cmake \ 15 | curl \ 16 | git \ 17 | libssl-dev \ 18 | ninja-build \ 19 | pkg-config \ 20 | python3-minimal \ 21 | wget \ 22 | && rm -rf /var/lib/apt/lists/* 23 | 24 | 25 | ## Install the most recent version of the nightly Rust toolchain using rustup. 26 | ## Use the minimal profile to keep the image size down as much as possible. 27 | ## https://rustup.rs/ 28 | ENV HOME /root 29 | WORKDIR ${HOME} 30 | RUN curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs > rustup.sh \ 31 | && chmod +x rustup.sh \ 32 | && ./rustup.sh --default-toolchain nightly --profile minimal -y \ 33 | && rm rustup.sh 34 | 35 | 36 | ## Check out the Xtensa fork of Rust. Build and install LLVM and Rust with 37 | ## support for the Xtensa target. 38 | ## https://github.com/MabezDev/xtensa-rust-quickstart#rust-xtensa 39 | ## 40 | ## When done, remove any documentation, build artifacts, or files/directories 41 | ## which are otherwise not required; this drastically reduces the size of the 42 | ## resulting image. 43 | ENV BUILD_ROOT ${HOME}/.xtensa 44 | ENV RUST_ESP ${BUILD_ROOT}/rust 45 | ENV RUST_BUILD ${RUST_ESP}/build 46 | ENV RUST_TOOLCHAIN ${RUST_BUILD}/x86_64-unknown-linux-gnu/stage2 47 | WORKDIR ${BUILD_ROOT} 48 | RUN git clone -b esp https://github.com/esp-rs/rust.git \ 49 | && cd "${RUST_ESP}" \ 50 | && mkdir -p "${RUST_BUILD}" \ 51 | && ./configure --enable-extended \ 52 | --experimental-targets="Xtensa" \ 53 | --prefix="${RUST_BUILD}" \ 54 | --tools=rustfmt \ 55 | && python3 x.py build --stage=2 \ 56 | && python3 x.py install \ 57 | && $HOME/.cargo/bin/rustup toolchain link esp "${RUST_TOOLCHAIN}" \ 58 | && find . -maxdepth 1 -not -name "." \ 59 | -not -name ".." \ 60 | -not -name "build" \ 61 | -not -name "src" \ 62 | -not -name "Cargo.lock" \ 63 | -exec rm -rv {} + \ 64 | && cd "${RUST_BUILD}" \ 65 | && rm -rf bootstrap cache tmp \ 66 | && cd "${RUST_BUILD}/x86_64-unknown-linux-gnu" \ 67 | && rm -rf compiler-doc crate-docs doc md-doc stage0* stage1* 68 | 69 | 70 | ## Set up the xtensa-esp32-elf & xtensa-lx106-elf toolchains. Set the PATH 71 | ## environment variable to include all relevant executable directories. 72 | ## https://github.com/MabezDev/xtensa-rust-quickstart#xtensa-esp32-elf-toolchain 73 | ENV ESP32_TOOLS ${BUILD_ROOT}/xtensa-esp32-elf 74 | ENV ESP8266_TOOLS ${BUILD_ROOT}/xtensa-lx106-elf 75 | WORKDIR ${BUILD_ROOT} 76 | RUN wget https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_2_0-esp-2020r2-linux-amd64.tar.gz \ 77 | && tar xzf xtensa-esp32-elf-gcc8_2_0-esp-2020r2-linux-amd64.tar.gz \ 78 | && rm xtensa-esp32-elf-gcc8_2_0-esp-2020r2-linux-amd64.tar.gz \ 79 | && wget https://dl.espressif.com/dl/xtensa-lx106-elf-linux64-1.22.0-100-ge567ec7-5.2.0.tar.gz \ 80 | && tar xzf xtensa-lx106-elf-linux64-1.22.0-100-ge567ec7-5.2.0.tar.gz \ 81 | && rm xtensa-lx106-elf-linux64-1.22.0-100-ge567ec7-5.2.0.tar.gz 82 | ENV PATH ${ESP32_TOOLS}/bin:${ESP8266_TOOLS}/bin:${HOME}/.cargo/bin:$PATH 83 | 84 | 85 | ## Set up Xargo to allow for cross-compilation. 86 | ## https://github.com/japaric/xargo 87 | ## https://github.com/MabezDev/xtensa-rust-quickstart#xargo-or-cargo-xbuild 88 | RUN cargo install xargo 89 | ENV RUSTC ${RUST_BUILD}/bin/rustc 90 | ENV XARGO_RUST_SRC ${RUST_ESP}/src 91 | 92 | 93 | ## By default, build the project located in /project. Additional parameters 94 | ## can be passed to `xargo build` during the invocation of this image. 95 | WORKDIR /project 96 | CMD ["xargo", "build", "--release"] 97 | --------------------------------------------------------------------------------