diff --git a/.github/workflows/container-build.yml b/.github/workflows/container-build.yml deleted file mode 100644 index 22e4cdf..0000000 --- a/.github/workflows/container-build.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Build Container - -on: [push] - -jobs: - - build: - - runs-on: ubuntu-latest - - steps: - - - uses: actions/checkout@v1 - - - name: Build the image - run: docker build . --file Dockerfile --tag rust-esp:${{ github.sha }} - - - name: Authenticate - run: echo ${{ secrets.REGISTRY_PASSWORD }} | docker login quay.io --username ${{secrets.REGISTRY_USERNAME}} --password-stdin - - - name: Tag the image (master) - if: github.ref == 'refs/heads/master' - run: docker tag rust-esp:${{ github.sha }} quay.io/ctron/rust-esp:latest - - name: Push the image (master) - if: github.ref == 'refs/heads/master' - run: docker push quay.io/ctron/rust-esp:latest - - - name: Tag the image (develop) - if: github.ref == 'refs/heads/develop' - run: docker tag rust-esp:${{ github.sha }} quay.io/ctron/rust-esp:develop - - name: Push the image (develop) - if: github.ref == 'refs/heads/develop' - run: docker push quay.io/ctron/rust-esp:develop diff --git a/Dockerfile b/Dockerfile index 35ef3ea..89ffec7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,49 +1,11 @@ FROM debian:buster-slim -# ------------------------------------------------------------------- -# Toolchain Version Config -# ------------------------------------------------------------------- - -# Espressif toolchain -ARG ESP_VERSION="1.22.0-80-g6c4433a-5.2.0" - -# esp-idf framework -ARG IDF_VERSION="v3.3-beta3" - -# llvm-xtensa -ARG CLANG_VERSION="248d9ce8765248d953c3e5ef4022fb350bbe6c51" -ARG LLVM_VERSION="757e18f722dbdcd98b8479e25041b1eee1128ce9" - -# rust-xtensa -ARG RUSTC_VERSION="b365cff41a60df8fd5f1237ef71897edad0375dd" - -# ------------------------------------------------------------------- -# Toolchain Path Config -# ------------------------------------------------------------------- - -ARG TOOLCHAIN="/home/esp32-toolchain" - -ARG ESP_BASE="${TOOLCHAIN}/esp" -ENV ESP_PATH "${ESP_BASE}/esp-toolchain" -ENV IDF_PATH "${ESP_BASE}/esp-idf" - -ARG LLVM_BASE="${TOOLCHAIN}/llvm" -ARG LLVM_PATH="${LLVM_BASE}/llvm_xtensa" -ARG LLVM_BUILD_PATH="${LLVM_BASE}/llvm_build" -ARG LLVM_INSTALL_PATH="${LLVM_BASE}/llvm_install" - -ARG RUSTC_BASE="${TOOLCHAIN}/rustc" -ARG RUSTC_PATH="${RUSTC_BASE}/rust_xtensa" -ARG RUSTC_BUILD_PATH="${RUSTC_BASE}/rust_build" - -ENV PATH "/root/.cargo/bin:${ESP_PATH}/bin:${PATH}" - # ------------------------------------------------------------------- # Install expected depdendencies # ------------------------------------------------------------------- RUN apt-get update \ - && apt-get install -y \ + && apt-get install -y --no-install-recommends \ bison \ cmake \ curl \ @@ -53,87 +15,94 @@ RUN apt-get update \ git \ gperf \ libncurses-dev \ + libssl-dev \ + libusb-1.0 \ make \ ninja-build \ + pkg-config \ python \ python-pip \ + python-virtualenv \ wget \ && rm -rf /var/lib/apt/lists/* # ------------------------------------------------------------------- -# Setup esp32 toolchain +# Globals # ------------------------------------------------------------------- -WORKDIR "${ESP_BASE}" -RUN curl \ - --proto '=https' \ - --tlsv1.2 \ - -sSf \ - -o "${ESP_PATH}.tar.gz" \ - "https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-${ESP_VERSION}.tar.gz" \ - && mkdir "${ESP_PATH}" \ - && tar -xzf "${ESP_PATH}.tar.gz" -C "${ESP_PATH}" --strip-components 1 \ - && rm -rf "${ESP_PATH}.tar.gz" +ARG TOOLCHAIN="/opt/xtensa" # ------------------------------------------------------------------- # Setup esp-idf # ------------------------------------------------------------------- -WORKDIR "${ESP_BASE}" +ARG IDF_BRANCH="release/v4.2" + +ENV IDF_PATH="${TOOLCHAIN}/esp-idf" + RUN git clone \ - --recursive --single-branch -b "${IDF_VERSION}" \ + -b "${IDF_BRANCH}" --depth 1 --recursive --single-branch \ https://github.com/espressif/esp-idf.git \ - && pip install --user -r "${IDF_PATH}/requirements.txt" + "${IDF_PATH}" \ + && cd ${IDF_PATH} \ + && ./install.sh # ------------------------------------------------------------------- # Build llvm-xtensa # ------------------------------------------------------------------- -WORKDIR "${LLVM_BASE}" -RUN mkdir "${LLVM_PATH}" \ - && cd "${LLVM_PATH}" \ - && git init \ - && git remote add origin https://github.com/espressif/llvm-xtensa.git \ - && git fetch --depth 1 origin "${LLVM_VERSION}" \ - && git checkout FETCH_HEAD \ - && mkdir -p "${LLVM_PATH}/tools/clang" \ - && cd "${LLVM_PATH}/tools/clang" \ - && git init \ - && git remote add origin https://github.com/espressif/clang-xtensa.git \ - && git fetch --depth 1 origin "${CLANG_VERSION}" \ - && git checkout FETCH_HEAD \ - && mkdir -p "${LLVM_BUILD_PATH}" \ - && cd "${LLVM_BUILD_PATH}" \ - && cmake "${LLVM_PATH}" \ - -DLLVM_TARGETS_TO_BUILD="Xtensa;X86" \ +ARG LLVM_BRANCH="xtensa_release_10.0.1" +ARG LLVM_SRC="/tmp/llvm" +ARG LLVM_BUILD="${LLVM_SRC}/build" +ARG LLVM_INSTALL_PATH="${TOOLCHAIN}/llvm" + +RUN git clone \ + -b "${LLVM_BRANCH}" --depth 1 --single-branch \ + https://github.com/espressif/llvm-project.git \ + "${LLVM_SRC}" \ + && mkdir -p "${LLVM_BUILD}" \ + && cd "${LLVM_BUILD}" \ + && cmake "${LLVM_SRC}/llvm" \ + -DLLVM_TARGETS_TO_BUILD="X86" \ + -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="Xtensa" \ + -DLLVM_ENABLE_PROJECTS="clang;lld" \ -DLLVM_INSTALL_UTILS=ON \ - -DLLVM_BUILD_TESTS=0 \ + -DLLVM_INCLUDE_EXAMPLES=0 \ -DLLVM_INCLUDE_TESTS=0 \ + -DLLVM_INCLUDE_DOCS=0 \ + -DLLVM_INCLUDE_BENCHMARKS=0 \ -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX="${LLVM_BASE}/llvm_install" \ + -DCMAKE_INSTALL_PREFIX="${LLVM_INSTALL_PATH}" \ -DCMAKE_CXX_FLAGS="-w" \ -G "Ninja" \ && ninja install \ - && rm -rf "${LLVM_PATH}" "${LLVM_BUILD_PATH}" + && rm -rf "${LLVM_BUILD}" "${LLVM_SRC}" # ------------------------------------------------------------------- # Build rust-xtensa # ------------------------------------------------------------------- -WORKDIR "${RUSTC_BASE}" +# rust-xtensa +ARG RUST_VERSION="xtensa-v0.2.0" +ARG RUST_SRC="${TOOLCHAIN}/rust_src" +ARG RUST_INSTALL_PATH="${TOOLCHAIN}/rust" + RUN git clone \ - --recursive --single-branch \ + -b "${RUST_VERSION}" --depth 1 --single-branch \ https://github.com/MabezDev/rust-xtensa.git \ - "${RUSTC_PATH}" \ - && mkdir -p "${RUSTC_BUILD_PATH}" \ - && cd "${RUSTC_PATH}" \ - && git reset --hard "${RUSTC_VERSION}" \ + "${RUST_SRC}" \ + && cd "${RUST_SRC}" \ && ./configure \ + --disable-compiler-docs \ + --disable-docs \ + --enable-lld \ + --experimental-targets=Xtensa \ --llvm-root "${LLVM_INSTALL_PATH}" \ - --prefix "${RUSTC_BUILD_PATH}" \ + --prefix "${RUST_INSTALL_PATH}" \ && python ./x.py build \ - && python ./x.py install - + && python ./x.py install \ + && python ./x.py clean + # ------------------------------------------------------------------- # Setup rustup toolchain # ------------------------------------------------------------------- @@ -144,25 +113,25 @@ RUN curl \ -sSf \ https://sh.rustup.rs \ | sh -s -- -y --default-toolchain stable \ - && rustup component add rustfmt \ - && rustup toolchain link xtensa "${RUSTC_BUILD_PATH}" \ - && cargo install cargo-xbuild bindgen + && . $HOME/.cargo/env \ + && rustup toolchain link xtensa "${RUST_INSTALL_PATH}" \ + && cargo install bindgen cargo-xbuild # ------------------------------------------------------------------- # Our Project # ------------------------------------------------------------------- -ENV PROJECT="/home/project/" +ARG PROJECT="/home/project/" -ENV XARGO_RUST_SRC="${RUSTC_PATH}/src" -ENV TEMPLATES="${TOOLCHAIN}/templates" +#ENV CARGO_HOME="${PROJECT}target/cargo" ENV LIBCLANG_PATH="${LLVM_INSTALL_PATH}/lib" -ENV CARGO_HOME="${PROJECT}target/cargo" +ENV PATH="${LLVM_INSTALL_PATH}/bin:${RUST_INSTALL_PATH}/bin:${PATH}" +#ENV RUSTC="${RUST_INSTALL_PATH}/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" +ENV XARGO_RUST_SRC="${RUST_SRC}/library" VOLUME "${PROJECT}" WORKDIR "${PROJECT}" -COPY bindgen-project build-project create-project image-project xbuild-project flash-project /usr/local/bin/ -COPY templates/ "${TEMPLATES}" +COPY bindgen-project quick-build entrypoint.sh /usr/local/bin/ -CMD ["/usr/local/bin/build-project"] +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] diff --git a/build-project b/build-project deleted file mode 100755 index f6a0316..0000000 --- a/build-project +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bash - -set -e - -die() { echo "$*" 1>&2 ; exit 1 ; } - -test -f Cargo.toml || die "unable to find 'Cargo.toml'. You will need to map the container path /home/project to the path of your Rust project. You can do this using: docker run -ti -v $PWD:/home/project:z rust-esp" - -for i in esp-idf .cargo main; do - test -d "$i" || die "'$i' is missing. Use 'create-project' to set up the build." -done -for i in Makefile .cargo/config main/esp_app_main.c; do - test -f "$i" || die "'$i' is missing. Use 'create-project' to set up the build." -done - -test -f sdkconfig || die "'sdkconfig' is missing. You can create one running 'make menuconfig'" - -make -j app - -if test -d esp32-sys; then - if ! test -f esp32-sys/src/bindings.rs; then - echo "esp32-sys crate is present, but bindings.rs is missing, running bindgen-project" - bindgen-project - fi -fi - -xbuild-project -image-project - -echo Build complete diff --git a/create-project b/create-project deleted file mode 100755 index 589e73a..0000000 --- a/create-project +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash - -set -e - -die() { echo "$*" 1>&2 ; exit 1 ; } - -test -f Cargo.toml || die "unable to find 'Cargo.toml'. You will need to map the container path /home/project to the path of your Rust project. You can do this using: docker run -ti -v $PWD:/home/project/build:z rust-esp" - -echo "Creating Makefile (Makefile)" -cp "${TEMPLATES}/Makefile" Makefile - -echo "Creating esp-idf symlink (esp-idf -> /esp-idf)" -ln -sf "${IDF_PATH}" esp-idf - -echo "Creating cargo config (.cargo/config)" -mkdir -p .cargo -cp "${TEMPLATES}/cargo.config" .cargo/config - -echo "Creating main application wrapper (main/esp_app_main.c)" -mkdir -p main -cp "${TEMPLATES}/main.c" main/esp_app_main.c -cp "${TEMPLATES}/component.mk" main/ - diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..36d9ca7 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +# Initialize environment +source "$IDF_PATH/export.sh" +source "$HOME/.cargo/env" + +# Execute argument passed to `docker run`. If it's a shell (/bin/bash) will +# remain in the container +exec "$@" \ No newline at end of file diff --git a/flash-project b/flash-project deleted file mode 100755 index 8a22423..0000000 --- a/flash-project +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash - -set -e - -"$IDF_PATH/components/esptool_py/esptool/esptool.py" \ - --chip esp32 \ - --port /dev/ttyUSB0 \ - --baud 115200 \ - --before default_reset \ - --after hard_reset \ - write_flash \ - -z \ - --flash_mode dio \ - --flash_freq 40m \ - --flash_size detect \ - 0x1000 build/bootloader/bootloader.bin \ - 0x10000 build/esp-app.bin \ - 0x8000 build/partitions_singleapp.bin diff --git a/image-project b/image-project deleted file mode 100755 index 8d16014..0000000 --- a/image-project +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -set -e - -"${IDF_PATH}/components/esptool_py/esptool/esptool.py" \ - --chip esp32 \ - elf2image \ - -o build/esp-app.bin \ - target/xtensa-esp32-none-elf/release/esp-app - -echo "You can now flash 'build/esp-app.bin'" diff --git a/quick-build b/quick-build new file mode 100755 index 0000000..4684718 --- /dev/null +++ b/quick-build @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +set -euxo pipefail + +cargo +xtensa xbuild --target "${XARGO_TARGET:-xtensa-esp32-none-elf}" "$@" + +if [ -x ./image.sh ] +then + # If available, use script generated by esp_idf_build::esptool_write_script() + . ./image.sh +else + "${IDF_PATH}/components/esptool_py/esptool/esptool.py" \ + --chip esp32 \ + elf2image \ + -o build/esp-app.bin \ + target/xtensa-esp32-none-elf/release/esp-app +fi + +echo "You can now flash 'build/esp-app.bin'" diff --git a/templates/Makefile b/templates/Makefile deleted file mode 100644 index 1ccfece..0000000 --- a/templates/Makefile +++ /dev/null @@ -1,5 +0,0 @@ - -PROJECT_NAME := esp-app - -include $(IDF_PATH)/make/project.mk - diff --git a/templates/cargo.config b/templates/cargo.config deleted file mode 100644 index 12121da..0000000 --- a/templates/cargo.config +++ /dev/null @@ -1,59 +0,0 @@ -[build] -target = "xtensa-esp32-none-elf" - -[target.xtensa-esp32-none-elf] -rustflags = [ - "-C", "target-cpu=esp32", - "-C", "save-temps", - "-C", "link-arg=-nostdlib", -# "-C", "link-arg=-nostartfiles", - - "-C", "link-arg=-ucall_user_start_cpu0", - "-C", "link-arg=-u__cxa_guard_dummy", - "-C", "link-arg=-u__cxx_fatal_exception", - "-C", "link-arg=-uld_include_panic_highint_hdl", - "-C", "link-arg=-uesp_app_desc", - - "-C", "link-arg=-Wl,--gc-sections", - "-C", "link-arg=-Wl,-static", - "-C", "link-arg=-Wl,--start-group", - - "-C", "link-arg=-Lbuild/app_update", "-C", "link-arg=-lapp_update", - "-C", "link-arg=-Lbuild/driver", "-C", "link-arg=-ldriver", - "-C", "link-arg=-Lbuild/esp-tls", "-C", "link-arg=-lesp-tls", - "-C", "link-arg=-Lbuild/esp32", "-C", "link-arg=-lesp32", - "-C", "link-arg=esp-idf/components/esp32/libhal.a", - "-C", "link-arg=-Lesp-idf/components/esp32/lib", "-C", "link-arg=-lcore", - - "-C", "link-arg=-Lesp-idf/components/esp32/ld", - "-C", "link-arg=-Tesp32_out.ld", - "-C", "link-arg=-Tbuild/esp32/esp32.project.ld", - "-C", "link-arg=-Tesp32.rom.ld", - "-C", "link-arg=-Tesp32.peripherals.ld", - "-C", "link-arg=-Tesp32.rom.libgcc.ld", - "-C", "link-arg=-Tesp32.rom.spiram_incompatible_fns.ld", - - "-C", "link-arg=-Lbuild/esp_ringbuf", "-C", "link-arg=-lesp_ringbuf", - "-C", "link-arg=-Lbuild/freertos", "-C", "link-arg=-lfreertos", - - "-C", "link-arg=-Wl,--undefined=uxTopUsedPriority", - - "-C", "link-arg=-Lbuild/heap", "-C", "link-arg=-lheap", - "-C", "link-arg=-Lbuild/log", "-C", "link-arg=-llog", - - "-C", "link-arg=esp-idf/components/newlib/lib/libc.a", - "-C", "link-arg=esp-idf/components/newlib/lib/libm.a", - - "-C", "link-arg=-Lbuild/newlib", "-C", "link-arg=-lnewlib", - "-C", "link-arg=-Lbuild/pthread", "-C", "link-arg=-lpthread", - "-C", "link-arg=-Lbuild/soc", "-C", "link-arg=-lsoc", - "-C", "link-arg=-Lbuild/spi_flash", "-C", "link-arg=-lspi_flash", - "-C", "link-arg=-Lbuild/vfs", "-C", "link-arg=-lvfs", - "-C", "link-arg=-Lbuild/xtensa-debug-module", "-C", "link-arg=-lxtensa-debug-module", - - "-C", "link-arg=-lgcc", - "-C", "link-arg=-lstdc++", - "-C", "link-arg=-lgcov", - "-C", "link-arg=-Wl,--end-group", - "-C", "link-arg=-Wl,-EL", -] diff --git a/templates/component.mk b/templates/component.mk deleted file mode 100644 index b29d318..0000000 --- a/templates/component.mk +++ /dev/null @@ -1 +0,0 @@ -# empty "main" Makefile diff --git a/templates/main.c b/templates/main.c deleted file mode 100644 index 36b5510..0000000 --- a/templates/main.c +++ /dev/null @@ -1 +0,0 @@ -void app_main() {} diff --git a/xbuild-project b/xbuild-project deleted file mode 100755 index 6b05761..0000000 --- a/xbuild-project +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -set -e - -cargo +xtensa xbuild --target "${XARGO_TARGET:-xtensa-esp32-none-elf}" --release