From dd3d4268a6889f0a123521d8681de31fd55e8cc1 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Wed, 27 Dec 2023 13:41:53 +0100 Subject: [PATCH] feat: Remove bash script --- .github/workflows/upload-installer.yaml | 61 --- README.md | 122 +---- build-template-project.sh | 2 +- install-rust-toolchain.sh | 671 ------------------------ 4 files changed, 14 insertions(+), 842 deletions(-) delete mode 100644 .github/workflows/upload-installer.yaml delete mode 100755 install-rust-toolchain.sh diff --git a/.github/workflows/upload-installer.yaml b/.github/workflows/upload-installer.yaml deleted file mode 100644 index 8a3ddb01..00000000 --- a/.github/workflows/upload-installer.yaml +++ /dev/null @@ -1,61 +0,0 @@ -name: Upload installer to release assets - -on: - workflow_dispatch: - inputs: - rust_build_branch: - description: "Branch of rust-build to use" - required: true - default: "main" - release_version: - description: "Release Version for generation" - required: true - default: "1.75.0.0" - rust_version: - description: "Version of esp rust to use" - required: true - default: "1.74.0" - -# We Break this down into individual jobs to avoid disk space issues -jobs: - get_release: - # https://github.com/octokit/request-action - name: Get release - runs-on: ubuntu-latest - outputs: - upload_url: ${{ steps.get_upload_url.outputs.url }} - steps: - - uses: octokit/request-action@v2.x - id: get_release - with: - route: GET /repos/{owner}/{repo}/releases/tags/v${{ github.event.inputs.release_version }} - owner: esp-rs - repo: rust-build - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: get upload url - id: get_upload_url - run: | - url=$(echo "$response" | jq -r '.upload_url') - echo "::set-output name=url::$url" - env: - response: ${{ steps.get_release.outputs.data }} - - upload-installers: - name: Upload installation scripts - runs-on: ubuntu-latest - needs: get_release - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.event.inputs.rust_build_branch }} - - name: Upload Bash installer - id: upload-bash-installer - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ needs.get_release.outputs.upload_url }} - asset_path: install-rust-toolchain.sh - asset_name: install-rust-toolchain.sh - asset_content_type: text/plain diff --git a/README.md b/README.md index df8612be..c2513867 100644 --- a/README.md +++ b/README.md @@ -10,33 +10,28 @@ If you want to know more about the Rust ecosystem on ESP targets, see [The Rust ## Table of Contents -- [rust-build](#rust-build) - - [Table of Contents](#table-of-contents) - - [Xtensa Installation](#xtensa-installation) +- [Xtensa Installation](#xtensa-installation) - [`espup` installation](#espup-installation) - - [Download installer in Bash](#download-installer-in-bash) - - [Linux and macOS](#linux-and-macos) - - [Prerequisites](#prerequisites) - - [Installation commands](#installation-commands) - - [Set up the environment variables](#set-up-the-environment-variables) - - [Arguments](#arguments) - - [Windows Long path limitation](#windows-long-path-limitation) - [Windows x86\_64 MSVC](#windows-x86_64-msvc) - [Prerequisites x86\_64 MSVC](#prerequisites-x86_64-msvc) - [Windows x86\_64 GNU](#windows-x86_64-gnu) - [Prerequisites x86\_64 GNU](#prerequisites-x86_64-gnu) - - [Long path limitation](#long-path-limitation) - - [RISC-V Installation](#risc-v-installation) - - [Building projects](#building-projects) - - [Cargo first approach](#cargo-first-approach) - - [Idf first approach](#idf-first-approach) - - [Using Containers](#using-containers) - - [Using Dev Containers](#using-dev-containers) +- [RISC-V Installation](#risc-v-installation) +- [Building projects](#building-projects) + - [Cargo first approach](#cargo-first-approach) + - [Idf first approach](#idf-first-approach) +- [Using Containers](#using-containers) +- [Using Dev Containers](#using-dev-containers) +- [Release process](#release-process) + - [Building release](#building-release) + - [Finalization of release (about 2-3 days later)](#finalization-of-release-about-2-3-days-later) + - [Rollback release](#rollback-release) + - [Uploading new image tags to espressif/idf-rust](#uploading-new-image-tags-to-espressifidf-rust) ## Xtensa Installation Deployment is done using [`espup`](https://github.com/esp-rs/espup#installation) -## `espup` installation +### `espup` installation ```sh cargo install espup espup install # To install Espressif Rust ecosystem @@ -89,89 +84,6 @@ Or, downloading the pre-compiled release binaries: > For Windows MSVC/GNU, Rust environment can also be installed with Universal Online idf-installer: https://dl.espressif.com/dl/esp-idf/ - -#### Download installer in Bash - -**Deprecated method** - -```bash -curl -LO https://github.com/esp-rs/rust-build/releases/download/v1.75.0.0/install-rust-toolchain.sh -chmod a+x install-rust-toolchain.sh -``` - -### Linux and macOS - -The following instructions are specific for the ESP32 and ESP32-S series based on Xtensa architecture. - -Instructions for ESP-C series based on RISC-V architecture are described in [RISC-V section](#risc-v-installation). - -#### Prerequisites - -- Linux: - - [Dependencies (command for Ubuntu/Debian)](https://github.com/esp-rs/esp-idf-template/blob/master/cargo/.devcontainer/Dockerfile#L16): - ```sh - apt-get install -y git curl gcc clang ninja-build cmake libudev-dev unzip xz-utils \ - python3 python3-pip python3-venv libusb-1.0-0 libssl-dev pkg-config libpython2.7 - ``` - -No prerequisites are needed for macOS. - -#### Installation commands - -```sh -git clone https://github.com/esp-rs/rust-build.git -cd rust-build -./install-rust-toolchain.sh -. ./export-esp.sh -``` - -Run `./install-rust-toolchain.sh --help` for more information about arguments. - -Installation of different version of the toolchain: - -``` -./install-rust-toolchain.sh --toolchain-version 1.75.0.0 -. ./export-esp.sh -``` - -#### Set up the environment variables -We need to update environment variables as some of the installed tools are not -yet added to the PATH environment variable, we also need to add LIBCLANG_PATH -environment variable to avoid conflicts with the system Clang. The environment -variables that we need to update are shown at the end of the install script and -stored in an export file. By default this export file is `export-esp.sh` but can -be modified with the `-f|--export-file` argument. - -We must set the environment variables in every terminal session. - - -> **Note** -> If the export variables are added to the shell startup script, the shell may need to be refreshed. - -#### Arguments -- `-b|--build-target`: Comma separated list of targets \[`esp32,esp32s2,esp32s3,esp32c3,all`]. Defaults to: `esp32,esp32s2,esp32s3` -- `-c|--cargo-home`: Cargo path. -- `-d|--toolchain-destination`: Toolchain installation folder. Defaults to: `/toolchains/esp` -- `-e|--extra-crates`: Extra crates to install. Defaults to: `ldproxy cargo-espflash` -- `-f|--export-file`: Destination of the export file generated. Defaults to: `export-esp.sh` -- `-i|--installation-mode`: Installation mode: \[`install, reinstall, uninstall`]. Defaults to: `install` -- `-k|--minified-llvm`: Use minified LLVM. Possible values: \[`YES, NO`]. Defaults to: `YES` -- `-l|--llvm-version`: LLVM version. -- `-m|--minified-esp-idf`: \[Only applies if using `-s|--esp-idf-version`]. Deletes some idf folders to save space. Possible values \[`YES, NO`]. Defaults to: `NO` -- `-n|--nightly-version`: Nightly Rust toolchain version. Defaults to: `nightly` -- `-r|--rustup-home`: Path to .rustup. Defaults to: `~/.rustup` -- `-s|--esp-idf-version`: [ESP-IDF branch](https://github.com/espressif/esp-idf/branches) to install. When empty, no esp-idf is installed. Default: `""` -- `-t|--toolchain-version`: Xtensa Rust toolchain version -- `-x|--clear-cache`: Removes cached distribution files. Possible values: \[`YES, NO`]. Defaults to: `YES` - -#### Windows Long path limitation - -Several build tools have problem with long paths on Windows including Git and CMake. We recommend to put project on short path or use command `subst` to map the directory with the project to separate disk letter. - -``` -subst "R:" "rust-project" -``` - ### Windows x86_64 MSVC The following instructions are specific for the ESP32 and ESP32-S series based on Xtensa architecture. If you do not have Visual Studio and Windows 10 SDK installed, consider the alternative option [Windows x86_64 GNU](#windows-x86_64-gnu). @@ -237,14 +149,6 @@ Invoke-WebRequest 'https://github.com/esp-rs/espup/releases/latest/download/espu .\espup.exe install ``` -#### Long path limitation - -Several build tools have problem with long paths on Windows including Git and CMake. We recommend to put project on short path or use command `subst` to map the directory with the project to separate disk letter. - -``` -subst "R:" "rust-project" -``` - ## RISC-V Installation The following instructions are specific for ESP32-C based on RISC-V architecture. diff --git a/build-template-project.sh b/build-template-project.sh index a03aa638..bde593dd 100644 --- a/build-template-project.sh +++ b/build-template-project.sh @@ -7,7 +7,7 @@ chmod u+x ${HOME}/.cargo/bin/cargo-generate export USER=esp source /home/esp/export-esp.sh -# Build esp-idf-template (release/v4.4) +# Build esp-idf-template cargo generate esp-rs/esp-idf-template cargo --name test-std-$1 --vcs none --silent -d mcu=$1 -d advanced=false cd test-std-$1 cargo build diff --git a/install-rust-toolchain.sh b/install-rust-toolchain.sh deleted file mode 100755 index df90b95e..00000000 --- a/install-rust-toolchain.sh +++ /dev/null @@ -1,671 +0,0 @@ -#!/usr/bin/env bash - -set -eu -#set -v - -# Default values -TOOLCHAIN_VERSION="1.75.0.0" -RUSTUP_HOME="${RUSTUP_HOME:-${HOME}/.rustup}" -CARGO_HOME="${CARGO_HOME:-${HOME}/.cargo}" -TOOLCHAIN_DESTINATION_DIR="${RUSTUP_HOME}/toolchains/esp" -BUILD_TARGET="esp32,esp32s2,esp32s3" -RUSTC_MINIMAL_MINOR_VERSION="55" -INSTALLATION_MODE="install" # reinstall, uninstall -LLVM_VERSION="esp-16.0.0-20230516" -LLVM_DIST_MIRROR="https://github.com/espressif/llvm-project/releases/download/${LLVM_VERSION}" -MINIFIED_LLVM="YES" -GCC_DIST_MIRROR="https://github.com/espressif/crosstool-NG/releases/download" -GCC_PATCH="esp-12.2.0_20230208" -GCC_VERSION="12.2.0_20230208" -NIGHTLY_VERSION="nightly" -CLEAR_DOWNLOAD_CACHE="YES" -EXTRA_CRATES="ldproxy cargo-espflash" -ESP_IDF_VERSION="" -MINIFIED_ESP_IDF="NO" -IS_XTENSA_INSTALLED=0 -IS_SCCACHE_INSTALLED=0 -EXPORT_FILE="export-esp.sh" - -echo "WARNING: This installation script is deprecated. Use espup(https://github.com/esp-rs/espup) instead." -echo "WARNING: This will be removed for Xtensa Rust 1.75.0." -display_help() { - echo "Usage: install-rust-toolchain.sh " - echo "Arguments: " - echo "-b|--build-target Comma separated list of targets [esp32,esp32c2,esp32c3,esp32c6,esp32h2,esp32s2,esp32s3,all]. Defaults to: esp32,esp32s2,esp32s3" - echo "-c|--cargo-home Cargo path" - echo "-d|--toolchain-destination Toolchain installation folder." - echo "-e|--extra-crates Extra crates to install. Defaults to: ldproxy cargo-espflash" - echo "-f|--export-file Destination of the export file generated. Defaults to: export-esp.sh" - echo "-i|--installation-mode Installation mode: [install, reinstall, uninstall]. Defaults to: install" - echo "-k|--minified-llvm Use minified LLVM. Possible values [YES, NO]" - echo "-l|--llvm-version LLVM version" - echo "-m|--minified-esp-idf [Only applies if using -s|--esp-idf-version]. Deletes some esp-idf folder to save space. Possible values [YES, NO]" - echo "-n|--nightly-version Nightly Rust toolchain version" - echo "-r|--rustup-home Path to .rustup" - echo "-s|--esp-idf-version ESP-IDF version. When empty, no esp-idf is installed. Default: \"\"" - echo "-t|--toolchain-version Xtensa Rust toolchain version" - echo "-x|--clear-cache Removes cached distribution files. Possible values [YES, NO]" -} - -# Process arguments -while [[ $# -gt 0 ]]; do - key="$1" - - case $key in - -h | --help) - display_help - exit 1 - ;; - -b | --build-target) - BUILD_TARGET="$2" - shift # past argument - shift # past value - ;; - -d | --toolchain-destination) - TOOLCHAIN_DESTINATION_DIR="$2" - shift # past argument - shift # past value - ;; - -e | --extra-crates) - EXTRA_CRATES="$2" - shift # past argument - shift # past value - ;; - -f | --export-file) - EXPORT_FILE="$2" - shift # past argument - shift # past value - ;; - -c | --cargo-home) - CARGO_HOME="$2" - shift # past argument - shift # past value - ;; - -i | --installation-mode) - INSTALLATION_MODE="$2" - shift # past argument - shift # past value - ;; - -k | --minified-llvm) - MINIFIED_LLVM="$2" - shift # past argument - shift # past value - ;; - -l | --llvm-version) - LLVM_VERSION="$2" - LLVM_DIST_MIRROR="https://github.com/espressif/llvm-project/releases/download/${LLVM_VERSION}" - shift # past argument - shift # past value - ;; - -m | --minified-esp-idf) - MINIFIED_ESP_IDF="$2" - shift # past argument - shift # past value - ;; - -n | --nightly-version) - NIGHTLY_VERSION="$2" - shift # past argument - shift # past value - ;; - -r | --rustup-home) - RUSTUP_HOME="$2" - shift # past argument - shift # past value - ;; - -s | --esp-idf-version) - ESP_IDF_VERSION="$2" - shift # past argument - shift # past value - ;; - -t | --toolchain-version) - TOOLCHAIN_VERSION="$2" - shift # past argument - shift # past value - ;; - -x | --clear-cache) - CLEAR_DOWNLOAD_CACHE="$2" - shift # past argument - shift # past value - ;; - *) # unknown option - echo "Warning: Unknown argument." - shift # past argument - ;; - esac -done - -echo "Processing configuration:" -echo "--build-target = ${BUILD_TARGET}" -echo "--cargo-home = ${CARGO_HOME}" -echo "--clear-cache = ${CLEAR_DOWNLOAD_CACHE}" -echo "--esp-idf-version = ${ESP_IDF_VERSION}" -echo "--export-file = ${EXPORT_FILE:-}" -echo "--extra-crates = ${EXTRA_CRATES}" -echo "--installation-mode = ${INSTALLATION_MODE}" -echo "--llvm-version = ${LLVM_VERSION}" -echo "--minified-esp-idf = ${MINIFIED_ESP_IDF}" -echo "--minified-llvm = ${MINIFIED_LLVM}" -echo "--nightly-version = ${NIGHTLY_VERSION}" -echo "--rustup-home = ${RUSTUP_HOME}" -echo "--toolchain-version = ${TOOLCHAIN_VERSION}" -echo "--toolchain-destination = ${TOOLCHAIN_DESTINATION_DIR}" - -function install_rustup() { - curl https://sh.rustup.rs -sSf | bash -s -- \ - --default-toolchain none --profile minimal -y -} - -function install_rust_toolchain() { - rustup toolchain install $1 --profile minimal -} - -function source_cargo() { - if [[ -e "${CARGO_HOME}/env" ]]; then - source "${CARGO_HOME}/env" - else - echo "Warning: Unable to source ${CARGO_HOME}/env. Verify that the path specified for ${CARGO_HOME} exists" - fi - export CARGO_HOME -} - -function install_esp_idf() { - mkdir -p ${IDF_TOOLS_PATH}/frameworks/ - NORMALIZED_VERSION=$(echo ${ESP_IDF_VERSION} | sed -e 's!/!-!g') - export IDF_PATH="${IDF_TOOLS_PATH}/frameworks/esp-idf-${NORMALIZED_VERSION}" - git clone --branch ${ESP_IDF_VERSION} --depth 1 --shallow-submodules \ - --recursive https://github.com/espressif/esp-idf.git \ - "${IDF_PATH}" - ${IDF_PATH}/install.sh "${BUILD_TARGET}" - python3 ${IDF_PATH}/tools/idf_tools.py install cmake - if [[ "${MINIFIED_ESP_IDF}" == "YES" ]]; then - rm -rf ${IDF_TOOLS_PATH}/dist - rm -rf ${IDF_TOOLS_PATH}/frameworks/esp-idf/docs - rm -rf ${IDF_TOOLS_PATH}/frameworks/esp-idf/examples - rm -rf ${IDF_TOOLS_PATH}/frameworks/esp-idf/tools/esp_app_trace - rm -rf ${IDF_TOOLS_PATH}/frameworks/esp-idf/tools/test_idf_size - fi -} - -function install_gcc() { - IDF_TOOL_GCC="${IDF_TOOLS_PATH}/tools/$1-gcc/${GCC_VERSION}-${ARCH}" - GCC_FILE="$1-${GCC_VERSION}-${GCC_ARCH}.tar.xz" - GCC_DIST_URL="${GCC_DIST_MIRROR}/${GCC_PATCH}/${GCC_FILE}" - echo "* installing ${IDF_TOOL_GCC} " - if [[ ! -d ${IDF_TOOL_GCC} ]]; then - if [[ ! -f "${GCC_FILE}" ]]; then - echo "** Downloading ${GCC_DIST_URL}" - curl -LO "${GCC_DIST_URL}" - fi - mkdir -p "${IDF_TOOL_GCC}" - echo "IDF_TOOL_GCC ${IDF_TOOL_GCC}" - tar xf ${GCC_FILE} -C "${IDF_TOOL_GCC}" --strip-components=1 - echo "done" - else - echo "already installed" - fi - IDF_TOOL_GCC_PATH="${IDF_TOOL_GCC}/bin/${IDF_TOOL_GCC_PATH:+:${IDF_TOOL_GCC_PATH}}" -} - -function install_rust_xtensa_toolchain() { - if [[ -d "${TOOLCHAIN_DESTINATION_DIR}" ]]; then - echo "Previous installation of toolchain exist in: ${TOOLCHAIN_DESTINATION_DIR}" - echo "Please, remove the directory before new installation." - exit 1 - fi - - if [[ ! -d ${TOOLCHAIN_DESTINATION_DIR} ]]; then - mkdir -p ${TOOLCHAIN_DESTINATION_DIR} - if [[ ! -f ./${RUST_DIST}/install.sh ]]; then - echo "** downloading: ${RUST_DIST_URL}" - curl -LO "${RUST_DIST_URL}" - mkdir -p ${RUST_DIST} - tar xf ${RUST_DIST}.tar.xz --strip-components=1 -C ${RUST_DIST} - fi - ./${RUST_DIST}/install.sh --destdir=${TOOLCHAIN_DESTINATION_DIR} --prefix="" --without=rust-docs-json-preview,rust-docs - if [[ ! -f ./${RUST_SRC_DIST}/install.sh ]]; then - curl -LO "https://github.com/esp-rs/rust-build/releases/download/v${TOOLCHAIN_VERSION}/${RUST_SRC_DIST}.tar.xz" - mkdir -p ${RUST_SRC_DIST} - tar xf ${RUST_SRC_DIST}.tar.xz --strip-components=1 -C ${RUST_SRC_DIST} - fi - ./${RUST_SRC_DIST}/install.sh --destdir=${TOOLCHAIN_DESTINATION_DIR} --prefix="" --without=rust-docs-json-preview,rust-docs - fi - - if [[ -z "${ESP_IDF_VERSION}" ]]; then - if [[ "${BUILD_TARGET}" =~ "esp32s3" ]]; then - install_gcc "xtensa-esp32s3-elf" - fi - if [[ "${BUILD_TARGET}" =~ "esp32s2" ]]; then - install_gcc "xtensa-esp32s2-elf" - fi - if [[ "${BUILD_TARGET}" =~ esp32[,|\ ] || "${BUILD_TARGET}" =~ esp32$ ]]; then - install_gcc "xtensa-esp32-elf" - fi - fi -} - -function install_llvm_clang() { - echo "* installing ${IDF_TOOL_XTENSA_ELF_CLANG} " - if [[ ! -d ${IDF_TOOL_XTENSA_ELF_CLANG} ]]; then - if [[ ! -f "${LLVM_FILE}" ]]; then - echo "** Downloading ${LLVM_DIST_URL}" - curl -LO "${LLVM_DIST_URL}" - fi - mkdir -p "${IDF_TOOL_XTENSA_ELF_CLANG}" - tar xf ${LLVM_FILE} -C "${IDF_TOOL_XTENSA_ELF_CLANG}" --strip-components=1 - echo "done" - else - echo "already installed" - fi -} - -function clear_download_cache() { - echo "Removing cached dist files:" - echo " - ${RUST_DIST}" - rm -rf "${RUST_DIST}" - - echo " - ${RUST_DIST}.tar.xz" - rm -f "${RUST_DIST}.tar.xz" - - echo " - ${RUST_SRC_DIST}" - rm -rf "${RUST_SRC_DIST}" - - echo " - ${RUST_SRC_DIST}.tar.xz" - rm -f "${RUST_SRC_DIST}.tar.xz" - - echo " - ${LLVM_FILE}" - rm -f "${LLVM_FILE}" - - if [[ -z "${ESP_IDF_VERSION}" ]]; then - echo " - *-elf-gcc*.tar.gz" - rm -f *-elf-gcc*.tar.gz - fi -} - -function install_rust_riscv_toolchain() { - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- \ - --default-toolchain ${NIGHTLY_VERSION} \ - --component rust-src \ - --profile minimal \ - --target riscv32imc-unknown-none-elf -y -} - -function install_crate_from_zip() { - CRATE_URL="$1" - CRATE_BIN="$2" - - if [[ -z "${CRATE_BIN}" ]]; then - return - fi - - if [[ -z "${CRATE_URL}" ]]; then - cargo install ${CRATE_BIN} - return - fi - - if [[ ! -e "${CRATE_BIN}" ]]; then - echo "Downloading ${CRATE_URL} to ${CRATE_BIN}.zip" - curl -L "${CRATE_URL}" -o "${CRATE_BIN}.zip" - unzip "${CRATE_BIN}.zip" -d "${CARGO_HOME}/bin/" - rm "${CRATE_BIN}.zip" - chmod u+x "${CRATE_BIN}" - echo "Using ${CRATE_BIN} binary release" - fi -} - -function install_crate_from_xz() { - CRATE_URL="$1" - CRATE_BIN="$2" - - if [[ -z "${CRATE_BIN}" ]]; then - return - fi - - if [[ -z "${CRATE_URL}" ]]; then - cargo install ${CRATE_BIN} - return - fi - - if [[ ! -e "${CRATE_BIN}" ]]; then - echo "Downloading ${CRATE_URL} to ${CRATE_BIN}.xz" - curl -L "${CRATE_URL}" -o "${CRATE_BIN}.xz" - unxz "${CRATE_BIN}.xz" - chmod u+x "${CRATE_BIN}" - echo "Using ${CRATE_BIN} binary release" - fi -} - -function install_crate_from_tar_gz() { - CRATE_URL="$1" - CRATE_BIN="$2" - STRIP_COMPONENTS="$3" - - if [[ -z "${CRATE_BIN}" ]]; then - return - fi - - if [[ -z "${CRATE_URL}" ]]; then - cargo install ${CRATE_BIN} - return - fi - - if [[ ! -e "${CRATE_BIN}" ]]; then - echo "Downloading ${CRATE_URL} to ${CRATE_BIN}.tar.gz" - curl -L "${CRATE_URL}" -o "${CRATE_BIN}.tar.gz" - if [[ -z "${STRIP_COMPONENTS}" ]]; then - tar xf "${CRATE_BIN}.tar.gz" -C ${CARGO_HOME}/bin - else - tar xf "${CRATE_BIN}.tar.gz" -C ${CARGO_HOME}/bin --strip-components 1 - fi - chmod u+x "${CRATE_BIN}" - echo "Using ${CRATE_BIN} binary release" - fi -} - -function install_extra_crates() { - if [[ "${EXTRA_CRATES}" =~ "cargo-espflash" ]] && [[ -n "${CARGO_ESPFLASH_URL}" ]] && [[ -n "${CARGO_ESPFLASH_BIN}" ]]; then - install_crate_from_zip "${CARGO_ESPFLASH_URL}" "${CARGO_ESPFLASH_BIN}" - EXTRA_CRATES="${EXTRA_CRATES/cargo-espflash/}" - fi - - if [[ "${EXTRA_CRATES}" =~ "espflash" ]] && [[ -n "${ESPFLASH_URL}" ]] && [[ -n "${ESPFLASH_BIN}" ]]; then - install_crate_from_zip "${ESPFLASH_URL}" "${ESPFLASH_BIN}" - EXTRA_CRATES="${EXTRA_CRATES/espflash/}" - fi - - if [[ "${EXTRA_CRATES}" =~ "ldproxy" ]] && [[ -n "${LDPROXY_URL}" ]] && [[ -n "${LDPROXY_BIN}" ]]; then - install_crate_from_zip "${LDPROXY_URL}" "${LDPROXY_BIN}" - EXTRA_CRATES="${EXTRA_CRATES/ldproxy/}" - fi - - if [[ "${EXTRA_CRATES}" =~ "cargo-generate" ]] && [[ -n "${GENERATE_URL}" ]] && [[ -n "${GENERATE_BIN}" ]]; then - install_crate_from_tar_gz "${GENERATE_URL}" "${GENERATE_BIN}" "" - EXTRA_CRATES="${EXTRA_CRATES/cargo-generate/}" - fi - - if [[ "${EXTRA_CRATES}" =~ "sccache" ]]; then - IS_SCCACHE_INSTALLED=1 - if [[ -n "${SCCACHE_URL}" ]] && [[ -n "${SCCACHE_BIN}" ]]; then - install_crate_from_tar_gz "${SCCACHE_URL}" "${SCCACHE_BIN}" "STRIP" - EXTRA_CRATES="${EXTRA_CRATES/sccache/}" - fi - fi - - if [[ "${EXTRA_CRATES}" =~ "web-flash" ]]; then - if [[ -n "${WEB_FLASH_URL}" ]] && [[ -n "${WEB_FLASH_BIN}" ]]; then - install_crate_from_zip "${WEB_FLASH_URL}" "${WEB_FLASH_BIN}" - else - cargo install web-flash --git https://github.com/bjoernQ/esp-web-flash-server - fi - EXTRA_CRATES="${EXTRA_CRATES/web-flash/}" - fi - - if [[ "${EXTRA_CRATES}" =~ "wokwi-server" ]]; then - if [[ -n "${WOKWI_SERVER_URL}" ]] && [[ -n "${WOKWI_SERVER_BIN}" ]]; then - install_crate_from_zip "${WOKWI_SERVER_URL}" "${WOKWI_SERVER_BIN}" - else - RUSTFLAGS="--cfg tokio_unstable" cargo install wokwi-server --git https://github.com/MabezDev/wokwi-server --locked - fi - EXTRA_CRATES="${EXTRA_CRATES/wokwi-server/}" - fi - - if ! [[ -z "${EXTRA_CRATES// /}" ]]; then - cargo install $EXTRA_CRATES - fi -} - -# Check required tooling - rustc, rustfmt -command -v rustup || install_rustup - -source_cargo - -if [[ "${BUILD_TARGET}" == all ]]; then - BUILD_TARGET="esp32,esp32c2,esp32c3,esp32c6,esp32h2,esp32s2,esp32s3" -fi - -# Deploy missing toolchains - Xtensa toolchain should be used on top of these -if [[ "${BUILD_TARGET}" =~ esp32s[2|3] || "${BUILD_TARGET}" =~ esp32[,|\ ] || "${BUILD_TARGET}" =~ esp32$ ]]; then - rustup toolchain list | grep ${NIGHTLY_VERSION} || install_rust_toolchain ${NIGHTLY_VERSION} -fi - -if [[ "${BUILD_TARGET}" =~ esp32c2 || "${BUILD_TARGET}" =~ esp32c3 || "${BUILD_TARGET}" =~ esp32c6 || "${BUILD_TARGET}" =~ esp32h2 ]]; then - install_rust_riscv_toolchain -fi - -# Check minimal rustc version -RUSTC_MINOR_VERSION=$(rustc --version | sed -e 's/^rustc 1\.\([^.]*\).*/\1/') -if [[ "${RUSTC_MINOR_VERSION}" -lt "${RUSTC_MINIMAL_MINOR_VERSION}" ]]; then - echo "rustc version is too low, requires 1.${RUSTC_MINIMAL_MINOR_VERSION}" - echo "calling rustup" - install_rustup -fi - -ARCH=$(rustup show | grep "Default host" | sed -e 's/.* //') -# Possible values of ARCH -#ARCH="aarch64-apple-darwin" -#ARCH="aarch64-unknown-linux-gnu" -#ARCH="x86_64-apple-darwin" -#ARCH="x86_64-unknown-linux-gnu" -#ARCH="x86_64-pc-windows-msvc" - -# Extra crates binary download support -ESPFLASH_URL="" -ESPFLASH_BIN="" -CARGO_ESPFLASH_URL="" -CARGO_ESPFLASH_BIN="" -LDPROXY_URL="" -LDPROXY_BIN="" -GENERATE_URL="" -GENERATE_BIN="" -SCCACHE_URL="" -SCCACHE_BIN="" -WOKWI_SERVER_URL="" -WOKWI_SERVER_BIN="" -WEB_FLASH_URL="" -WEB_FLASH_BIN="" -if [[ "${EXTRA_CRATES}" =~ "cargo-generate" ]]; then - GENERATE_VERSION=$(git ls-remote --refs --sort="version:refname" --tags "https://github.com/cargo-generate/cargo-generate" | cut -d/ -f3- | tail -n1) -fi -if [[ "${EXTRA_CRATES}" =~ "sccache" ]]; then - SCCACHE_VERSION=$(git ls-remote --refs --sort="version:refname" --tags "https://github.com/mozilla/sccache" | cut -d/ -f3- | tail -n1) -fi - -# Configuration overrides for specific architectures -if [[ ${ARCH} == "aarch64-apple-darwin" ]]; then - GCC_ARCH="${ARCH}" - LLVM_ARCH="macos-arm64" - CARGO_ESPFLASH_URL="https://github.com/esp-rs/espflash/releases/latest/download/cargo-espflash-${ARCH}.zip" - CARGO_ESPFLASH_BIN="${CARGO_HOME}/bin/cargo-espflash" - ESPFLASH_URL="https://github.com/esp-rs/espflash/releases/latest/download/espflash-${ARCH}.zip" - ESPFLASH_BIN="${CARGO_HOME}/bin/espflash" - LDPROXY_URL="https://github.com/esp-rs/embuild/releases/latest/download/ldproxy-${ARCH}.zip" - LDPROXY_BIN="${CARGO_HOME}/bin/ldproxy" - if [[ "${EXTRA_CRATES}" =~ "sccache" ]]; then - SCCACHE_URL="https://github.com/mozilla/sccache/releases/latest/download/sccache-${SCCACHE_VERSION}-${ARCH}.tar.gz" - fi - SCCACHE_BIN="${CARGO_HOME}/bin/sccache" - WOKWI_SERVER_URL="https://github.com/MabezDev/wokwi-server/releases/latest/download/wokwi-server-${ARCH}.zip" - WOKWI_SERVER_BIN="${CARGO_HOME}/bin/wokwi-server" - WEB_FLASH_URL="https://github.com/esp-rs/esp-web-flash-server/releases/latest/download/web-flash-${ARCH}.zip" - WEB_FLASH_BIN="${CARGO_HOME}/bin/web-flash" -elif [[ ${ARCH} == "x86_64-apple-darwin" ]]; then - GCC_ARCH="${ARCH}" - LLVM_ARCH="macos" - CARGO_ESPFLASH_URL="https://github.com/esp-rs/espflash/releases/latest/download/cargo-espflash-${ARCH}.zip" - CARGO_ESPFLASH_BIN="${CARGO_HOME}/bin/cargo-espflash" - ESPFLASH_URL="https://github.com/esp-rs/espflash/releases/latest/download/espflash-${ARCH}.zip" - ESPFLASH_BIN="${CARGO_HOME}/bin/espflash" - LDPROXY_URL="https://github.com/esp-rs/embuild/releases/latest/download/ldproxy-${ARCH}.zip" - LDPROXY_BIN="${CARGO_HOME}/bin/ldproxy" - if [[ "${EXTRA_CRATES}" =~ "sccache" ]]; then - SCCACHE_URL="https://github.com/mozilla/sccache/releases/latest/download/sccache-${SCCACHE_VERSION}-${ARCH}.tar.gz" - fi - SCCACHE_BIN="${CARGO_HOME}/bin/sccache" - if [[ "${EXTRA_CRATES}" =~ "cargo-generate" ]]; then - GENERATE_URL="https://github.com/cargo-generate/cargo-generate/releases/latest/download/cargo-generate-${GENERATE_VERSION}-${ARCH}.tar.gz" - fi - GENERATE_BIN="${CARGO_HOME}/bin/cargo-generate" - WOKWI_SERVER_URL="https://github.com/MabezDev/wokwi-server/releases/latest/download/wokwi-server-${ARCH}.zip" - WOKWI_SERVER_BIN="${CARGO_HOME}/bin/wokwi-server" - WEB_FLASH_URL="https://github.com/esp-rs/esp-web-flash-server/releases/latest/download/web-flash-${ARCH}.zip" - WEB_FLASH_BIN="${CARGO_HOME}/bin/web-flash" -elif [[ ${ARCH} == "x86_64-unknown-linux-gnu" ]]; then - GCC_ARCH="x86_64-linux-gnu" - LLVM_ARCH="linux-amd64" - CARGO_ESPFLASH_URL="https://github.com/esp-rs/espflash/releases/latest/download/cargo-espflash-${ARCH}.zip" - CARGO_ESPFLASH_BIN="${CARGO_HOME}/bin/cargo-espflash" - ESPFLASH_URL="https://github.com/esp-rs/espflash/releases/latest/download/espflash-${ARCH}.zip" - ESPFLASH_BIN="${CARGO_HOME}/bin/espflash" - LDPROXY_URL="https://github.com/esp-rs/embuild/releases/latest/download/ldproxy-${ARCH}.zip" - LDPROXY_BIN="${CARGO_HOME}/bin/ldproxy" - # if [[ "${EXTRA_CRATES}" =~ "cargo-generate" ]]; then - # GENERATE_URL="https://github.com/cargo-generate/cargo-generate/releases/latest/download/cargo-generate-${GENERATE_VERSION}-${ARCH}.tar.gz" - # fi - # GENERATE_BIN="${CARGO_HOME}/bin/cargo-generate" - WOKWI_SERVER_URL="https://github.com/MabezDev/wokwi-server/releases/latest/download/wokwi-server-${ARCH}.zip" - WOKWI_SERVER_BIN="${CARGO_HOME}/bin/wokwi-server" - WEB_FLASH_URL="https://github.com/esp-rs/esp-web-flash-server/releases/latest/download/web-flash-${ARCH}.zip" - WEB_FLASH_BIN="${CARGO_HOME}/bin/web-flash" -elif [[ ${ARCH} == "aarch64-unknown-linux-gnu" ]]; then - GCC_ARCH="aarch64-linux-gnu" - LLVM_ARCH="linux-arm64" - MINIFIED_LLVM="YES" - # if [[ "${EXTRA_CRATES}" =~ "cargo-generate" ]]; then - # GENERATE_URL="https://github.com/cargo-generate/cargo-generate/releases/latest/download/cargo-generate-${GENERATE_VERSION}-${ARCH}.tar.gz" - # fi - # GENERATE_BIN="${CARGO_HOME}/bin/cargo-generate" - CARGO_ESPFLASH_URL="https://github.com/esp-rs/espflash/releases/latest/download/cargo-espflash-${ARCH}.zip" - CARGO_ESPFLASH_BIN="${CARGO_HOME}/bin/cargo-espflash" - ESPFLASH_URL="https://github.com/esp-rs/espflash/releases/latest/download/espflash-${ARCH}.zip" - ESPFLASH_BIN="${CARGO_HOME}/bin/espflash" -elif [[ ${ARCH} == "x86_64-pc-windows-msvc" ]]; then - GCC_ARCH="x86_64-w64-mingw32" - LLVM_ARCH="win64" - CARGO_ESPFLASH_URL="https://github.com/esp-rs/espflash/releases/latest/download/cargo-espflash-${ARCH}.zip" - CARGO_ESPFLASH_BIN="${CARGO_HOME}/bin/cargo-espflash.exe" - ESPFLASH_URL="https://github.com/esp-rs/espflash/releases/latest/download/espflash-${ARCH}.zip" - ESPFLASH_BIN="${CARGO_HOME}/bin/espflash.exe" - LDPROXY_URL="https://github.com/esp-rs/embuild/releases/latest/download/ldproxy-${ARCH}.zip" - LDPROXY_BIN="${CARGO_HOME}/bin/ldproxy.exe" - if [[ "${EXTRA_CRATES}" =~ "sccache" ]]; then - SCCACHE_URL="https://github.com/mozilla/sccache/releases/latest/download/sccache-${SCCACHE_VERSION}-${ARCH}.tar.gz" - fi - SCCACHE_BIN="${CARGO_HOME}/bin/sccache" - if [[ "${EXTRA_CRATES}" =~ "cargo-generate" ]]; then - GENERATE_URL="https://github.com/cargo-generate/cargo-generate/releases/latest/download/cargo-generate-${GENERATE_VERSION}-${ARCH}.tar.gz" - fi - GENERATE_BIN="${CARGO_HOME}/bin/cargo-generate.exe" - WOKWI_SERVER_URL="https://github.com/MabezDev/wokwi-server/releases/latest/download/wokwi-server-${ARCH}.zip" - WOKWI_SERVER_BIN="${CARGO_HOME}/bin/wokwi-server.exe" - WEB_FLASH_URL="https://github.com/esp-rs/esp-web-flash-server/releases/latest/download/web-flash-${ARCH}.zip" - WEB_FLASH_BIN="${CARGO_HOME}/bin/web-flash.exe" -fi - -echo "Processing toolchain for ${ARCH} - operation: ${INSTALLATION_MODE}" - -RUST_DIST="rust-${TOOLCHAIN_VERSION}-${ARCH}" -RUST_SRC_DIST="rust-src-${TOOLCHAIN_VERSION}" -LLVM_FILE="llvm-${LLVM_VERSION}-${LLVM_ARCH}.tar.xz" -if [[ "${MINIFIED_LLVM}" == "YES" ]]; then - LLVM_FILE="libs_${LLVM_FILE}" -fi -LLVM_DIST_URL="${LLVM_DIST_MIRROR}/${LLVM_FILE}" -IDF_TOOLS_PATH="${IDF_TOOLS_PATH:-${HOME}/.espressif}" -IDF_TOOL_GCC_PATH="" -IDF_TOOL_XTENSA_ELF_CLANG="${IDF_TOOLS_PATH}/tools/xtensa-esp32-elf-clang/${LLVM_VERSION}-${ARCH}/esp-clang" - -RUST_DIST_URL="https://github.com/esp-rs/rust-build/releases/download/v${TOOLCHAIN_VERSION}/${RUST_DIST}.tar.xz" - -if [[ "${INSTALLATION_MODE}" == "uninstall" ]] || [[ "${INSTALLATION_MODE}" == "reinstall" ]]; then - echo "Removing:" - - echo " - ${TOOLCHAIN_DESTINATION_DIR}" - rm -rf "${TOOLCHAIN_DESTINATION_DIR}" - - echo " - ${IDF_TOOL_XTENSA_ELF_CLANG}" - rm -rf "${IDF_TOOL_XTENSA_ELF_CLANG}" - - if [[ "${CLEAR_DOWNLOAD_CACHE}" == "YES" ]]; then - clear_download_cache - fi - - if [[ "${INSTALLATION_MODE}" == "uninstall" ]]; then - exit 0 - fi -fi - -if [[ "${BUILD_TARGET}" =~ esp32s[2|3] || "${BUILD_TARGET}" =~ esp32[,|\ ] || "${BUILD_TARGET}" =~ esp32$ ]]; then - install_rust_xtensa_toolchain - IS_XTENSA_INSTALLED=1 - install_llvm_clang -fi - -if [[ -n "${ESP_IDF_VERSION}" ]]; then - install_esp_idf -elif [[ "${BUILD_TARGET}" =~ "esp32c2" || "${BUILD_TARGET}" =~ "esp32c3" || "${BUILD_TARGET}" =~ "esp32c6" || "${BUILD_TARGET}" =~ "esp32h2" ]]; then - install_gcc "riscv32-esp-elf" -fi -install_extra_crates - -if [[ "${CLEAR_DOWNLOAD_CACHE}" == "YES" ]]; then - clear_download_cache -fi - -printf "\n IMPORTANT!" -printf "\n The following environment variables need to be updated:\n" -if [[ ${IS_XTENSA_INSTALLED} -eq 1 ]]; then - echo export LIBCLANG_PATH=\"${IDF_TOOL_XTENSA_ELF_CLANG}/lib/\" -fi -if [[ -n "${ESP_IDF_VERSION}" ]]; then - echo "export IDF_TOOLS_PATH=${IDF_TOOLS_PATH}" - echo ". ${IDF_PATH}/export.sh" -else - echo export PATH=\"${IDF_TOOL_GCC_PATH}:\$PATH\" -fi -PROFILE_NAME="your default shell" -if grep -q "zsh" <<<"$SHELL"; then - PROFILE_NAME=~/.zshrc -elif grep -q "bash" <<<"$SHELL"; then - PROFILE_NAME=~/.bashrc -fi -printf "\n If you want to activate the environment required for Rust in ESP SoC's in every terminal session automatically, you can add the previous commands to \"$PROFILE_NAME\"" -printf "\n However, it is not recommended, as doing so activates the virtual environment in every terminal session (including those where is not needed), defeating the purpose of the virtual environment and likely affecting other software." - -if [[ -n "${EXPORT_FILE:-}" ]]; then - printf "\n The recommended approach is to source the export file: \". ./${EXPORT_FILE}\"" - printf "\n Note: This should be done in every terminal session.\n" - echo -n "" >"${EXPORT_FILE}" - if [[ ${IS_XTENSA_INSTALLED} -eq 1 ]]; then - echo export LIBCLANG_PATH=\"${IDF_TOOL_XTENSA_ELF_CLANG}/lib/\" >>"${EXPORT_FILE}" - fi - if [[ -n "${ESP_IDF_VERSION}" ]]; then - echo "export IDF_TOOLS_PATH=${IDF_TOOLS_PATH}" >>"${EXPORT_FILE}" - echo ". ${IDF_PATH}/export.sh /dev/null 2>&1" >>"${EXPORT_FILE}" - else - echo export PATH=\"${IDF_TOOL_GCC_PATH}:\$PATH\" >>"${EXPORT_FILE}" - fi - if [[ ${IS_SCCACHE_INSTALLED} -eq 1 ]]; then - echo "export CARGO_INCREMENTAL=0" >>"${EXPORT_FILE}" - echo "export RUSTC_WRAPPER=$(which sccache)" >>"${EXPORT_FILE}" - fi -else - PROFILE_NAME="your default shell" - if grep -q "zsh" <<<"$SHELL"; then - PROFILE_NAME=~/.zshrc - elif grep -q "bash" <<<"$SHELL"; then - PROFILE_NAME=~/.bashrc - fi - echo "Add following command to $PROFILE_NAME" - if [[ ${IS_XTENSA_INSTALLED} -eq 1 ]]; then - echo export LIBCLANG_PATH=\"${IDF_TOOL_XTENSA_ELF_CLANG}/lib/\" - fi - if [[ -n "${ESP_IDF_VERSION}" ]]; then - echo "export IDF_TOOLS_PATH=${IDF_TOOLS_PATH}" - echo "source ${IDF_PATH}/export.sh" - else - echo export PATH=\"${IDF_TOOL_GCC_PATH}:\$PATH\" - fi - if [[ ${IS_SCCACHE_INSTALLED} -eq 1 ]]; then - echo "export CARGO_INCREMENTAL=0" - echo "export RUSTC_WRAPPER=$(which sccache)" - fi -fi