diff --git a/.github/workflows/test-build.yml b/.github/workflows/test-build.yml index 4eada11..3a1074f 100644 --- a/.github/workflows/test-build.yml +++ b/.github/workflows/test-build.yml @@ -14,3 +14,12 @@ jobs: submodules: 'recursive' - name: esp-idf build uses: espressif/esp-idf-ci-action@rust-latest + - name: Archive binaries + run: | + mkdir binaries + cp build/*.bin build/bootloader/*.bin build/partition_table/*.bin support/esptool/* binaries/ + - name: Archive artifact + uses: actions/upload-artifact@v2 + with: + name: binaries + path: binaries diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7558b7c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,37 @@ +FROM espressif/idf +#RUN apt update \ +# && apt install -y build-essential curl +ENV LC_ALL=C.UTF-8 +ENV LANG=C.UTF-8 +ENV RUSTUP_HOME=/opt/rust +ENV CARGO_HOME=/opt/cargo +ENV PATH=/opt/cargo/bin:/opt/rust/bin:/opt/xtensa-esp32-elf-clang/bin:/opt/llvm-patch/bin:$PATH +RUN curl https://sh.rustup.rs -sSf | bash -s -- --profile minimal --default-toolchain nightly -y +WORKDIR /opt + +RUN wget -q https://dl.espressif.com/dl/idf-rust/dist/x86_64-unknown-linux-gnu/bionic/rust-1.50.0-dev-x86_64-unknown-linux-gnu-bionic.tar.xz \ + && tar xvf rust-1.50.0-dev-x86_64-unknown-linux-gnu-bionic.tar.xz \ + && cd rust-1.50.0-dev-x86_64-unknown-linux-gnu \ + && ./install.sh --destdir=/opt/xtensa --prefix="" --without=rust-docs \ + && cd /opt \ + && rm -rf rust-1.50.0-dev-x86_64-unknown-linux-gnu* + +RUN wget -q https://dl.espressif.com/dl/idf-rust/dist/x86_64-unknown-linux-gnu/rust-src-1.50.0-dev.tar.xz \ + && tar xvf rust-src-1.50.0-dev.tar.xz \ + && cd rust-src-1.50.0-dev \ + && ./install.sh --destdir=/opt/xtensa --prefix="" --without=rust-docs \ + && cd /opt \ + && rm -rf rust-src-1.50.0-dev* \ + && rustup toolchain link xtensa /opt/xtensa \ + && rustup default xtensa + +RUN wget -q https://dl.espressif.com/dl/idf-rust/dist/x86_64-unknown-linux-gnu/xtensa-esp32-elf-llvm11_0_0-llvmorg-11-init-21247-g65ed48e-linux-amd64.tar.xz \ + && tar xf xtensa-esp32-elf-llvm11_0_0-llvmorg-11-init-21247-g65ed48e-linux-amd64.tar.xz \ + && rm xtensa-esp32-elf-llvm11_0_0-llvmorg-11-init-21247-g65ed48e-linux-amd64.tar.xz \ + && wget -q https://dl.espressif.com/dl/idf-rust/dist/x86_64-unknown-linux-gnu/bionic/llvm-patch-0.1.x86_64-unknown-linux-gnu-bionic.tar.gz \ + && tar xzf llvm-patch-0.1.x86_64-unknown-linux-gnu-bionic.tar.gz \ + && rm llvm-patch-0.1.x86_64-unknown-linux-gnu-bionic.tar.gz + +RUN git clone https://github.com/espressif/rust-esp32-example.git + +WORKDIR /opt/rust-esp32-example diff --git a/docs/rust-on-xtensa-installation-x86_64-unknown-linux-gnu-bionic.md b/docs/rust-on-xtensa-installation-x86_64-unknown-linux-gnu-bionic.md new file mode 100644 index 0000000..c0a83d4 --- /dev/null +++ b/docs/rust-on-xtensa-installation-x86_64-unknown-linux-gnu-bionic.md @@ -0,0 +1,44 @@ +# Rust on Xtensa Installation for Linux x64 + +Tested OS: Ubuntu 18 x64 + +## Prerequisites + +- rustup - installed with nightly toolchain - https://rustup.rs/ + +## Commands + +``` +sudo apt install gcc wget xz-utils + +rustup toolchain install nightly + +mkdir -p ~/.rustup/toolchains/xtensa + +wget https://dl.espressif.com/dl/idf-rust/dist/x86_64-unknown-linux-gnu/bionic/rust-1.50.0-dev-x86_64-unknown-linux-gnu-bionic.tar.xz +tar xvf rust-1.50.0-dev-x86_64-unknown-linux-gnu-bionic.tar.xz +pushd rust-1.50.0-dev-x86_64-unknown-linux-gnu +./install.sh --destdir=~/.rustup/toolchains/xtensa --prefix="" --without=rust-docs +popd + +wget https://dl.espressif.com/dl/idf-rust/dist/x86_64-unknown-linux-gnu/rust-src-1.50.0-dev.tar.xz +tar xvf rust-src-1.50.0-dev.tar.xz +pushd rust-src-1.50.0-dev +./install.sh --destdir=~/.rustup/toolchains/xtensa --prefix="" --without=rust-docs +popd + +rustup default xtensa + +wget https://dl.espressif.com/dl/idf-rust/dist/x86_64-unknown-linux-gnu/xtensa-esp32-elf-llvm11_0_0-llvmorg-11-init-21247-g65ed48e-linux-amd64.tar.xz +tar xf xtensa-esp32-elf-llvm11_0_0-llvmorg-11-init-21247-g65ed48e-linux-amd64.tar.xz +export PATH="`pwd`/xtensa-esp32-elf-clang/bin/:$PATH" + +wget https://dl.espressif.com/dl/idf-rust/dist/x86_64-unknown-linux-gnu/llvm-patch-0.1.x86_64-unknown-linux-gnu.tar.gz +tar xzf llvm-patch-0.1.x86_64-unknown-linux-gnu.tar.gz +export PATH="`pwd`/llvm-patch/bin/:$PATH" + +wget --continue https://github.com/espressif/rust-esp32-example/archive/refs/heads/main.zip +unzip main.zip +cd rust-esp32-example-main +idf.py build +``` diff --git a/docs/rust-on-xtensa-installation-x86_64-unknown-linux-gnu.md b/docs/rust-on-xtensa-installation-x86_64-unknown-linux-gnu.md index 513af0e..9109869 100644 --- a/docs/rust-on-xtensa-installation-x86_64-unknown-linux-gnu.md +++ b/docs/rust-on-xtensa-installation-x86_64-unknown-linux-gnu.md @@ -1,8 +1,8 @@ # Rust on Xtensa Installation for Linux x64 -Tested OS: Ubuntu 20 x64, Mint x64 +Tested OS: Ubuntu 20 x64, Mint 20 x64 -Limitation: Does not work with Ubuntu 18 Bionic - GLIBC problem in cargo: `/lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found.` +Ubuntu 18: Please follow instructions for [Linux Ubuntu 18 x64](rust-on-xtensa-installation-x86_64-unknown-linux-gnu-bionic.md) to avoid problem with `GLIBC_2.29' not found. ## Prerequisites diff --git a/docs/rust-on-xtensa.md b/docs/rust-on-xtensa.md index 93a586a..bfbacc6 100644 --- a/docs/rust-on-xtensa.md +++ b/docs/rust-on-xtensa.md @@ -2,9 +2,10 @@ ## Quick start -The installation process of ready to use custom build of Rust and LLVM is described here: +The installation process of ready to use custom build of Rust and LLVM is described here: -* [Linux Ubuntu x64/Mint x64](rust-on-xtensa-installation-x86_64-unknown-linux-gnu.md) +* [Linux Ubuntu 20 x64/Mint 20 x64](rust-on-xtensa-installation-x86_64-unknown-linux-gnu.md) +* [Linux Ubuntu 18 x64](rust-on-xtensa-installation-x86_64-unknown-linux-gnu-bionic.md) * [macOS Big Sur x64](rust-on-xtensa-installation-x86_64-apple-darwin.md) * [macOS Big Sur arm64](rust-on-xtensa-installation-aarch64-apple-darwin.md) * [Windows 10 x64](rust-on-xtensa-installation-x86_64-pc-windows-msvc.md) diff --git a/support/README.md b/support/README.md new file mode 100644 index 0000000..c9ab6e9 --- /dev/null +++ b/support/README.md @@ -0,0 +1,19 @@ +# Support files + +## Rust + +The directory `rust` contains Dockerfile to build custom version of rust compiler with enabled Xtensa support. + +### Usage + +Building and starting container: +``` +cd support/rust +docker build -t rust-xtensa:bionic -f Dockerfile . +docker run --rm --name rust-xtensa -it rust-xtensa:bionic /bin/bash +``` + +Copy Rust dist file from running container: +``` +docker cp rust-xtensa /opt/rust/build/dist/rust-dev-1.50.0-dev-x86_64-unknown-linux-gnu.tar.xz rust-1.50.0-dev-x86_64-unknown-linux-gnu-bionic.tar.xz +``` diff --git a/support/esptool/Flash-Chip.ps1 b/support/esptool/Flash-Chip.ps1 new file mode 100644 index 0000000..782c911 --- /dev/null +++ b/support/esptool/Flash-Chip.ps1 @@ -0,0 +1,16 @@ +$Command = "esptool.exe" +if (Test-Path -Path ".\esptool-v3.1-win64\esptool-v3.1-win64\esptool.exe" -PathType Leaf) { + $Command = ".\esptool-v3.1-win64\esptool-v3.1-win64\esptool.exe" +} +$OldPreference = $ErrorActionPreference +$ErrorActionPreference = 'stop' +try {if(Get-Command $Command){"$Command exists"}} +Catch { + "$Command not found. Downloading" + Invoke-WebRequest https://github.com/espressif/esptool/releases/download/v3.1/esptool-v3.1-win64.zip -OutFile esptool-v3.1-win64.zip + Expand-Archive -Path esptool-v3.1-win64.zip + $Command = ".\esptool-v3.1-win64\esptool-v3.1-win64\esptool.exe" + $ErrorActionPreference=$OldPreference +} + +&$Command -b 460800 --before default_reset --after hard_reset --chip esp32 write_flash --flash_mode dio --flash_size detect --flash_freq 40m 0x1000 bootloader.bin 0x8000 partition-table.bin 0x10000 esp32-hello-rust.bin diff --git a/support/llvm-project/Dockerfile b/support/llvm-project/Dockerfile new file mode 100644 index 0000000..7560f1f --- /dev/null +++ b/support/llvm-project/Dockerfile @@ -0,0 +1,11 @@ +FROM ubuntu:bionic +WORKDIR /opt +RUN apt update \ + && apt install -y gcc cmake ccache ninja-build git python3 curl g++ pkg-config libssl-dev + +RUN git clone https://github.com/espressif/llvm-project.git +ADD cmake/caches /opt/cmake/caches +RUN mkdir -p llvm-project/build \ + && cd llvm-project/build \ + && cmake -C /opt/cmake/caches/DistributionEspressif.cmake ../llvm -G "Ninja" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="Xtensa" -DCMAKE_BUILD_TYPE=Release \ + && ninja stage2-distribution || echo "Build failed - silencing error to persist current build artifacts" diff --git a/support/llvm-project/cmake/caches/DistributionEspressif-stage2.cmake b/support/llvm-project/cmake/caches/DistributionEspressif-stage2.cmake new file mode 100644 index 0000000..e08b36d --- /dev/null +++ b/support/llvm-project/cmake/caches/DistributionEspressif-stage2.cmake @@ -0,0 +1,37 @@ +# This file sets up a CMakeCache for the second stage of a simple distribution +# bootstrap build. + +#set(LLVM_ENABLE_PROJECTS "clang" CACHE STRING "") +set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld" CACHE STRING "") +set(LLVM_ENABLE_RUNTIMES "" CACHE STRING "") +#set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld" CACHE STRING "") +#set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi" CACHE STRING "") + +set(LLVM_TARGETS_TO_BUILD X86;AArch64 CACHE STRING "") +#set(LLVM_TARGETS_TO_BUILD X86;ARM;AArch64 CACHE STRING "") + +set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "") +set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -gline-tables-only -DNDEBUG" CACHE STRING "") +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -gline-tables-only -DNDEBUG" CACHE STRING "") + +# setup toolchain +set(LLVM_INSTALL_TOOLCHAIN_ONLY ON CACHE BOOL "") +set(LLVM_TOOLCHAIN_TOOLS + #dsymutil + #llvm-cov + #llvm-dwarfdump + #llvm-profdata + #llvm-objdump + #llvm-nm + #llvm-size + CACHE STRING "") + +set(LLVM_DISTRIBUTION_COMPONENTS + clang + #LTO + #clang-format + #clang-resource-headers + #builtins + #runtimes + ${LLVM_TOOLCHAIN_TOOLS} + CACHE STRING "") \ No newline at end of file diff --git a/support/llvm-project/cmake/caches/DistributionEspressif.cmake b/support/llvm-project/cmake/caches/DistributionEspressif.cmake new file mode 100644 index 0000000..4b42de5 --- /dev/null +++ b/support/llvm-project/cmake/caches/DistributionEspressif.cmake @@ -0,0 +1,55 @@ +# This file sets up a CMakeCache for a simple distribution bootstrap build. + +#Enable LLVM projects and runtimes +#set(LLVM_ENABLE_PROJECTS "clang" CACHE STRING "") +set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld" CACHE STRING "") +set(LLVM_ENABLE_RUNTIMES "compiler-rt" CACHE STRING "") +#set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld" CACHE STRING "") +#set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi" CACHE STRING "") + +# Only build the native target in stage1 since it is a throwaway build. +set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "") + +# Optimize the stage1 compiler, but don't LTO it because that wastes time. +set(CMAKE_BUILD_TYPE Release CACHE STRING "") + +# Setup vendor-specific settings. +set(PACKAGE_VENDOR LLVM.org CACHE STRING "") + +# Setting up the stage2 LTO option needs to be done on the stage1 build so that +# the proper LTO library dependencies can be connected. +set(BOOTSTRAP_LLVM_ENABLE_LTO OFF CACHE BOOL "") +#set(BOOTSTRAP_LLVM_ENABLE_LTO ON CACHE BOOL "") + +if (NOT APPLE) + # Since LLVM_ENABLE_LTO is ON we need a LTO capable linker + #set(BOOTSTRAP_LLVM_ENABLE_LLD ON CACHE BOOL "") + set(BOOTSTRAP_LLVM_ENABLE_LLD OFF CACHE BOOL "") +endif() + +# Expose stage2 targets through the stage1 build configuration. +set(CLANG_BOOTSTRAP_TARGETS + check-all + check-llvm + check-clang + llvm-config + test-suite + test-depends + llvm-test-depends + clang-test-depends + distribution + install-distribution + clang CACHE STRING "") + +# Setup the bootstrap build. +set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "") + +if(STAGE2_CACHE_FILE) + set(CLANG_BOOTSTRAP_CMAKE_ARGS + -C ${STAGE2_CACHE_FILE} + CACHE STRING "") +else() + set(CLANG_BOOTSTRAP_CMAKE_ARGS + -C ${CMAKE_CURRENT_LIST_DIR}/DistributionEspressif-stage2.cmake + CACHE STRING "") +endif() diff --git a/support/rust/Dockerfile b/support/rust/Dockerfile new file mode 100644 index 0000000..29b1c7e --- /dev/null +++ b/support/rust/Dockerfile @@ -0,0 +1,12 @@ +FROM ubuntu:bionic +WORKDIR /opt +RUN apt update \ + && apt install -y gcc cmake ccache ninja-build git python3 curl g++ pkg-config libssl-dev + +RUN git clone https://github.com/ivmarkov/rust.git \ + && cd rust \ + && git checkout stable \ + && ./configure --experimental-targets=Xtensa --enable-extended --tools=rustfmt --disable-docs --disable-compiler-docs --set="build.python=python3" \ + && python3 x.py dist --stage 2 || echo "Build failed - silencing error to persist current build artifacts" + +# speed-up rebuild: --set="local-rebuild=true" \ No newline at end of file