Created
January 16, 2021 00:32
-
-
Save Alxandr/90959fea6e994282b041a8426e791ad4 to your computer and use it in GitHub Desktop.
appartment-heater
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################ | |
## BASE IMAGE | |
############################################################ | |
FROM ubuntu:latest as base | |
ARG DEBIAN_FRONTEND=noninteractive | |
RUN apt-get update && \ | |
apt-get install -y software-properties-common && \ | |
apt-add-repository universe && \ | |
apt-get update -y && \ | |
apt-get upgrade -y && \ | |
apt-get install -y \ | |
## Various dependencies | |
wget sudo cmake clang python3 zlib1g make git \ | |
ninja-build llvm libssl-dev pkg-config curl \ | |
## ESP-IDF dependencies | |
## https://docs.espressif.com/projects/esp-idf/en/latest/get-started/linux-setup.html | |
git wget flex bison gperf python3 python3-pip python3-setuptools \ | |
python3-serial python3-click python3-cryptography python3-future python3-pyparsing \ | |
python3-pyelftools cmake ninja-build ccache libffi-dev libssl-dev | |
ENV BUILD_ROOT /src/xtensa | |
ENV LLVM_BUILD ${BUILD_ROOT}/llvm_build | |
ENV RUST_BUILD ${BUILD_ROOT}/rust_build | |
ENV ESP32_IDF /xtensa-esp32-elf | |
# ENV ESP8266_IDF /xtensa-lx106-elf | |
ENV CC clang | |
ENV CXX clang++ | |
ENV XARGO_RUST_SRC ${BUILD_ROOT}/rust-xtensa/src | |
ENV RUSTC ${RUST_BUILD}/bin/rustc | |
## Install rust & esptool | |
RUN cd / && \ | |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs >rustup.sh && \ | |
chmod +x ./rustup.sh && \ | |
./rustup.sh --default-toolchain nightly --profile default -y && \ | |
rm rustup.sh && \ | |
pip3 install esptool | |
############################################################ | |
## LLVM builder | |
############################################################ | |
FROM base as llvm-builder | |
## Build LLVM | |
## based on these build instructions | |
## http://quickhack.net/nom/blog/2019-05-14-build-rust-environment-for-esp32.html | |
RUN mkdir -p "${BUILD_ROOT}" && \ | |
cd "${BUILD_ROOT}" && \ | |
git clone https://github.com/espressif/llvm-project.git --depth 1 && \ | |
mkdir -p "${LLVM_BUILD}" && \ | |
cd "${LLVM_BUILD}" && \ | |
cmake ../llvm-project/llvm -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="Xtensa" -DLLVM_TARGETS_TO_BUILD="X86" -DCMAKE_BUILD_TYPE=Release -G "Ninja" && \ | |
cmake --build . | |
############################################################ | |
## Rust xtensa builder | |
############################################################ | |
FROM base as rust-xtensa-builder | |
COPY --from=llvm-builder ${BUILD_ROOT} ${BUILD_ROOT} | |
RUN mkdir -p "${BUILD_ROOT}" && \ | |
cd "${BUILD_ROOT}" && \ | |
git clone https://github.com/MabezDev/rust-xtensa.git --depth 1 && \ | |
cd "${BUILD_ROOT}/rust-xtensa" && \ | |
mkdir -p "${RUST_BUILD}" && \ | |
./configure --llvm-root="${LLVM_BUILD}" --prefix="${RUST_BUILD}" && \ | |
## | |
## Build the rust compiler | |
python3 ./x.py build && \ | |
python3 ./x.py install | |
############################################################ | |
## Esptool builder | |
############################################################ | |
FROM base as esptool-builder | |
RUN cd / && \ | |
wget https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0.tar.gz && \ | |
tar xzf xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0.tar.gz && \ | |
rm xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0.tar.gz && \ | |
wget https://dl.espressif.com/dl/xtensa-lx106-elf-linux64-1.22.0-100-ge567ec7-5.2.0.tar.gz && \ | |
tar xzf xtensa-lx106-elf-linux64-1.22.0-100-ge567ec7-5.2.0.tar.gz && \ | |
rm xtensa-lx106-elf-linux64-1.22.0-100-ge567ec7-5.2.0.tar.gz | |
############################################################ | |
## Exported builder | |
############################################################ | |
FROM base as builder | |
COPY --from=rust-xtensa-builder ${RUST_BUILD} ${RUST_BUILD} | |
COPY --from=esptool-builder ${ESP32_IDF} ${ESP32_IDF} | |
## Setup Xargo | |
RUN $HOME/.cargo/bin/rustup toolchain link xtensa "${RUST_BUILD}" && \ | |
$HOME/.cargo/bin/rustup run xtensa rustc --print target-list | grep xtensa && \ | |
$HOME/.cargo/bin/cargo install xargo | |
## Setup path | |
ENV HOME /root | |
ENV PATH ${ESP8266_IDF}/bin:${ESP32_IDF}/bin:/usr/local/bin:${HOME}/.cargo/bin:$PATH | |
############################################################ | |
## Test | |
############################################################ | |
FROM builder | |
WORKDIR / | |
RUN git clone https://github.com/mtnmts/xtensa-rust-quickstart | |
WORKDIR /xtensa-rust-quickstart | |
RUN xargo build --release |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment