From 9e34ca9e5fee67ac931643492bfbb850cee65781 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Thu, 3 Nov 2022 16:13:12 +0100 Subject: [PATCH] esp: use LLVM Xtensa linker instead of Espressif toolchain The Espressif fork of LLVM now has Xtensa support in the linker LLD. (This support was written mosly by me). This means we don't have to use the Espressif GNU toolchain anymore and makes installing TinyGo simpler. In the future, this also paves the way for ThinLTO support. Right now it is mostly just a way to simplify TinyGo installation and speed up CI slightly. --- .circleci/config.yml | 12 ------------ .github/workflows/build-macos.yml | 11 ++--------- .github/workflows/linux.yml | 28 ++++++++-------------------- .github/workflows/windows.yml | 6 +++--- Dockerfile | 12 +----------- targets/esp32.json | 2 +- targets/esp8266.json | 2 +- 7 files changed, 16 insertions(+), 57 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 38621258..b8f8f406 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,18 +6,6 @@ commands: - run: name: "Pull submodules" command: git submodule update --init - install-xtensa-toolchain: - parameters: - variant: - type: string - steps: - - run: - name: "Install Xtensa toolchain" - command: | - curl -L https://github.com/espressif/crosstool-NG/releases/download/esp-2020r2/xtensa-esp32-elf-gcc8_2_0-esp-2020r2-<>.tar.gz -o xtensa-esp32-elf-gcc8_2_0-esp-2020r2-<>.tar.gz - sudo tar -C /usr/local -xf xtensa-esp32-elf-gcc8_2_0-esp-2020r2-<>.tar.gz - sudo ln -s /usr/local/xtensa-esp32-elf/bin/xtensa-esp32-elf-ld /usr/local/bin/xtensa-esp32-elf-ld - rm xtensa-esp32-elf-gcc8_2_0-esp-2020r2-<>.tar.gz llvm-source-linux: steps: - restore_cache: diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml index 08e5a364..68095809 100644 --- a/.github/workflows/build-macos.yml +++ b/.github/workflows/build-macos.yml @@ -20,13 +20,6 @@ jobs: shell: bash run: | HOMEBREW_NO_AUTO_UPDATE=1 brew install qemu binaryen - - name: Install Xtensa toolchain - shell: bash - run: | - curl -L https://github.com/espressif/crosstool-NG/releases/download/esp-2020r2/xtensa-esp32-elf-gcc8_2_0-esp-2020r2-macos.tar.gz -o xtensa-esp32-elf-gcc8_2_0-esp-2020r2-macos.tar.gz - sudo tar -C /usr/local -xf xtensa-esp32-elf-gcc8_2_0-esp-2020r2-macos.tar.gz - sudo ln -s /usr/local/xtensa-esp32-elf/bin/xtensa-esp32-elf-ld /usr/local/bin/xtensa-esp32-elf-ld - rm xtensa-esp32-elf-gcc8_2_0-esp-2020r2-macos.tar.gz - name: Checkout uses: actions/checkout@v3 with: @@ -40,7 +33,7 @@ jobs: uses: actions/cache@v3 id: cache-llvm-source with: - key: llvm-source-15-macos-v1 + key: llvm-source-15-macos-v2 path: | llvm-project/clang/lib/Headers llvm-project/clang/include @@ -54,7 +47,7 @@ jobs: uses: actions/cache@v3 id: cache-llvm-build with: - key: llvm-build-15-macos-v1 + key: llvm-build-15-macos-v2 path: llvm-build - name: Build LLVM if: steps.cache-llvm-build.outputs.cache-hit != 'true' diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index ff3275fb..8a5a1c28 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -43,7 +43,7 @@ jobs: uses: actions/cache@v3 id: cache-llvm-source with: - key: llvm-source-15-linux-alpine-v1 + key: llvm-source-15-linux-alpine-v2 path: | llvm-project/clang/lib/Headers llvm-project/clang/include @@ -57,7 +57,7 @@ jobs: uses: actions/cache@v3 id: cache-llvm-build with: - key: llvm-build-15-linux-alpine-v1 + key: llvm-build-15-linux-alpine-v2 path: llvm-build - name: Build LLVM if: steps.cache-llvm-build.outputs.cache-hit != 'true' @@ -138,12 +138,6 @@ jobs: sudo apt-get install --no-install-recommends \ gcc-avr \ avr-libc - - name: "Install Xtensa toolchain" - run: | - curl -L https://github.com/espressif/crosstool-NG/releases/download/esp-2020r2/xtensa-esp32-elf-gcc8_2_0-esp-2020r2-linux-amd64.tar.gz -o xtensa-esp32-elf-gcc8_2_0-esp-2020r2-linux-amd64.tar.gz - sudo tar -C /usr/local -xf xtensa-esp32-elf-gcc8_2_0-esp-2020r2-linux-amd64.tar.gz - sudo ln -s /usr/local/xtensa-esp32-elf/bin/xtensa-esp32-elf-ld /usr/local/bin/xtensa-esp32-elf-ld - rm xtensa-esp32-elf-gcc8_2_0-esp-2020r2-linux-amd64.tar.gz - run: make tinygo-test-wasi-fast - run: make smoketest assert-test-linux: @@ -185,7 +179,7 @@ jobs: uses: actions/cache@v3 id: cache-llvm-source with: - key: llvm-source-15-linux-asserts-v1 + key: llvm-source-15-linux-asserts-v2 path: | llvm-project/clang/lib/Headers llvm-project/clang/include @@ -199,7 +193,7 @@ jobs: uses: actions/cache@v3 id: cache-llvm-build with: - key: llvm-build-15-linux-asserts-v1 + key: llvm-build-15-linux-asserts-v2 path: llvm-build - name: Build LLVM if: steps.cache-llvm-build.outputs.cache-hit != 'true' @@ -238,12 +232,6 @@ jobs: echo "$(pwd)/build" >> $GITHUB_PATH - name: Test stdlib packages run: make tinygo-test - - name: Install Xtensa toolchain - run: | - curl -L https://github.com/espressif/crosstool-NG/releases/download/esp-2020r2/xtensa-esp32-elf-gcc8_2_0-esp-2020r2-linux-amd64.tar.gz -o xtensa-esp32-elf-gcc8_2_0-esp-2020r2-linux-amd64.tar.gz - sudo tar -C /usr/local -xf xtensa-esp32-elf-gcc8_2_0-esp-2020r2-linux-amd64.tar.gz - sudo ln -s /usr/local/xtensa-esp32-elf/bin/xtensa-esp32-elf-ld /usr/local/bin/xtensa-esp32-elf-ld - rm xtensa-esp32-elf-gcc8_2_0-esp-2020r2-linux-amd64.tar.gz - run: make smoketest - run: make wasmtest - run: make tinygo-baremetal @@ -277,7 +265,7 @@ jobs: uses: actions/cache@v3 id: cache-llvm-source with: - key: llvm-source-15-linux-v1 + key: llvm-source-15-linux-v2 path: | llvm-project/clang/lib/Headers llvm-project/clang/include @@ -291,7 +279,7 @@ jobs: uses: actions/cache@v3 id: cache-llvm-build with: - key: llvm-build-15-linux-arm-v1 + key: llvm-build-15-linux-arm-v2 path: llvm-build - name: Build LLVM if: steps.cache-llvm-build.outputs.cache-hit != 'true' @@ -377,7 +365,7 @@ jobs: uses: actions/cache@v3 id: cache-llvm-source with: - key: llvm-source-15-linux-v1 + key: llvm-source-15-linux-v2 path: | llvm-project/clang/lib/Headers llvm-project/clang/include @@ -391,7 +379,7 @@ jobs: uses: actions/cache@v3 id: cache-llvm-build with: - key: llvm-build-15-linux-arm64-v1 + key: llvm-build-15-linux-arm64-v2 path: llvm-build - name: Build LLVM if: steps.cache-llvm-build.outputs.cache-hit != 'true' diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 249a821b..0aa3357e 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -35,7 +35,7 @@ jobs: uses: actions/cache@v3 id: cache-llvm-source with: - key: llvm-source-15-windows-v1 + key: llvm-source-15-windows-v2 path: | llvm-project/clang/lib/Headers llvm-project/clang/include @@ -49,7 +49,7 @@ jobs: uses: actions/cache@v3 id: cache-llvm-build with: - key: llvm-build-15-windows-v1 + key: llvm-build-15-windows-v2 path: llvm-build - name: Build LLVM if: steps.cache-llvm-build.outputs.cache-hit != 'true' @@ -125,7 +125,7 @@ jobs: run: 7z x release.zip -r - name: Smoke tests shell: bash - run: make smoketest TINYGO=$(PWD)/build/tinygo/bin/tinygo AVR=0 XTENSA=0 + run: make smoketest TINYGO=$(PWD)/build/tinygo/bin/tinygo AVR=0 stdlib-test-windows: runs-on: windows-2022 diff --git a/Dockerfile b/Dockerfile index da6d8123..10061c6f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,18 +15,8 @@ FROM tinygo-llvm AS tinygo-llvm-build RUN cd /tinygo/ && \ make llvm-build -# tinygo-xtensa stage installs tools needed for ESP32 -FROM tinygo-llvm-build AS tinygo-xtensa - -ARG xtensa_version="1.22.0-80-g6c4433a-5.2.0" -RUN cd /tmp/ && \ - wget -q https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-${xtensa_version}.tar.gz && \ - tar xzf xtensa-esp32-elf-linux64-${xtensa_version}.tar.gz && \ - cp ./xtensa-esp32-elf/bin/xtensa-esp32-elf-ld /usr/local/bin/ && \ - rm -rf /tmp/xtensa* - # tinygo-compiler stage builds the compiler itself -FROM tinygo-xtensa AS tinygo-compiler +FROM tinygo-llvm-build AS tinygo-compiler COPY . /tinygo diff --git a/targets/esp32.json b/targets/esp32.json index 376d457c..c0b0f76a 100644 --- a/targets/esp32.json +++ b/targets/esp32.json @@ -5,7 +5,7 @@ "build-tags": ["esp32", "esp"], "scheduler": "tasks", "serial": "uart", - "linker": "xtensa-esp32-elf-ld", + "linker": "ld.lld", "default-stack-size": 2048, "rtlib": "compiler-rt", "libc": "picolibc", diff --git a/targets/esp8266.json b/targets/esp8266.json index 277181fe..bb02c3db 100644 --- a/targets/esp8266.json +++ b/targets/esp8266.json @@ -4,7 +4,7 @@ "features": "+debug,+density,+exception,+extendedl32r,+highpriinterrupts,+interrupt,+mul32,+nsa,+prid,+regprotect,+rvector,+timerint", "build-tags": ["esp8266", "esp"], "scheduler": "tasks", - "linker": "xtensa-esp32-elf-ld", + "linker": "ld.lld", "default-stack-size": 2048, "rtlib": "compiler-rt", "libc": "picolibc",