github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/.github/workflows/linux.yml (about)

     1  name: Linux
     2  
     3  on:
     4    pull_request:
     5    push:
     6      branches:
     7        - dev
     8        - release
     9  
    10  concurrency:
    11    group: ${{ github.workflow }}-${{ github.ref }}
    12    cancel-in-progress: true
    13  
    14  jobs:
    15    build-linux:
    16      # Build Linux binaries, ready for release.
    17      # This runs inside an Alpine Linux container so we can more easily create a
    18      # statically linked binary.
    19      runs-on: ubuntu-latest
    20      container:
    21        image: golang:1.22-alpine
    22      steps:
    23        - name: Install apk dependencies
    24          # tar: needed for actions/cache@v4
    25          # git+openssh: needed for checkout (I think?)
    26          # ruby: needed to install fpm
    27          run: apk add tar git openssh make g++ ruby
    28        - name: Work around CVE-2022-24765
    29          # We're not on a multi-user machine, so this is safe.
    30          run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
    31        - name: Checkout
    32          uses: actions/checkout@v4
    33          with:
    34            submodules: true
    35        - name: Cache Go
    36          uses: actions/cache@v4
    37          with:
    38            key: go-cache-linux-alpine-v1-${{ hashFiles('go.mod') }}
    39            path: |
    40              ~/.cache/go-build
    41              ~/go/pkg/mod
    42        - name: Restore LLVM source cache
    43          uses: actions/cache/restore@v4
    44          id: cache-llvm-source
    45          with:
    46            key: llvm-source-17-linux-alpine-v1
    47            path: |
    48              llvm-project/clang/lib/Headers
    49              llvm-project/clang/include
    50              llvm-project/compiler-rt
    51              llvm-project/lld/include
    52              llvm-project/llvm/include
    53        - name: Download LLVM source
    54          if: steps.cache-llvm-source.outputs.cache-hit != 'true'
    55          run: make llvm-source
    56        - name: Save LLVM source cache
    57          uses: actions/cache/save@v4
    58          if: steps.cache-llvm-source.outputs.cache-hit != 'true'
    59          with:
    60            key: ${{ steps.cache-llvm-source.outputs.cache-primary-key }}
    61            path: |
    62              llvm-project/clang/lib/Headers
    63              llvm-project/clang/include
    64              llvm-project/compiler-rt
    65              llvm-project/lld/include
    66              llvm-project/llvm/include
    67        - name: Restore LLVM build cache
    68          uses: actions/cache/restore@v4
    69          id: cache-llvm-build
    70          with:
    71            key: llvm-build-17-linux-alpine-v1
    72            path: llvm-build
    73        - name: Build LLVM
    74          if: steps.cache-llvm-build.outputs.cache-hit != 'true'
    75          run: |
    76            # fetch LLVM source
    77            rm -rf llvm-project
    78            make llvm-source
    79            # install dependencies
    80            apk add cmake samurai python3
    81            # build!
    82            make llvm-build
    83            # Remove unnecessary object files (to reduce cache size).
    84            find llvm-build -name CMakeFiles -prune -exec rm -r '{}' \;
    85        - name: Save LLVM build cache
    86          uses: actions/cache/save@v4
    87          if: steps.cache-llvm-build.outputs.cache-hit != 'true'
    88          with:
    89            key: ${{ steps.cache-llvm-build.outputs.cache-primary-key }}
    90            path: llvm-build
    91        - name: Cache Binaryen
    92          uses: actions/cache@v4
    93          id: cache-binaryen
    94          with:
    95            key: binaryen-linux-alpine-v1
    96            path: build/wasm-opt
    97        - name: Build Binaryen
    98          if: steps.cache-binaryen.outputs.cache-hit != 'true'
    99          run: |
   100            apk add cmake samurai python3
   101            make binaryen STATIC=1
   102        - name: Cache wasi-libc
   103          uses: actions/cache@v4
   104          id: cache-wasi-libc
   105          with:
   106            key: wasi-libc-sysroot-linux-alpine-v2
   107            path: lib/wasi-libc/sysroot
   108        - name: Build wasi-libc
   109          if: steps.cache-wasi-libc.outputs.cache-hit != 'true'
   110          run: make wasi-libc
   111        - name: Install fpm
   112          run: |
   113            gem install --version 4.0.7 public_suffix
   114            gem install --version 2.7.6 dotenv
   115            gem install --no-document fpm
   116        - name: Build TinyGo release
   117          run: |
   118            make release deb -j3 STATIC=1
   119            cp -p build/release.tar.gz /tmp/tinygo.linux-amd64.tar.gz
   120            cp -p build/release.deb    /tmp/tinygo_amd64.deb
   121        - name: Publish release artifact
   122          uses: actions/upload-artifact@v4
   123          with:
   124            name: linux-amd64-double-zipped
   125            path: |
   126              /tmp/tinygo.linux-amd64.tar.gz
   127              /tmp/tinygo_amd64.deb
   128    test-linux-build:
   129      # Test the binaries built in the build-linux job by running the smoke tests.
   130      runs-on: ubuntu-latest
   131      needs: build-linux
   132      steps:
   133        - name: Checkout
   134          uses: actions/checkout@v4
   135        - name: Install Go
   136          uses: actions/setup-go@v5
   137          with:
   138            go-version: '1.22'
   139            cache: true
   140        - name: Install wasmtime
   141          run: |
   142            mkdir -p $HOME/.wasmtime $HOME/.wasmtime/bin
   143            curl https://github.com/bytecodealliance/wasmtime/releases/download/v14.0.4/wasmtime-v14.0.4-x86_64-linux.tar.xz -o wasmtime-v14.0.4-x86_64-linux.tar.xz -SfL
   144            tar -C $HOME/.wasmtime/bin --wildcards -xf wasmtime-v14.0.4-x86_64-linux.tar.xz --strip-components=1 wasmtime-v14.0.4-x86_64-linux/*
   145            echo "$HOME/.wasmtime/bin" >> $GITHUB_PATH
   146        - name: Download release artifact
   147          uses: actions/download-artifact@v4
   148          with:
   149            name: linux-amd64-double-zipped
   150        - name: Extract release tarball
   151          run: |
   152            mkdir -p ~/lib
   153            tar -C ~/lib -xf tinygo.linux-amd64.tar.gz
   154            ln -s ~/lib/tinygo/bin/tinygo ~/go/bin/tinygo
   155        - run: make tinygo-test-wasi-fast
   156        - run: make tinygo-test-wasip1-fast
   157        - run: make smoketest
   158    assert-test-linux:
   159      # Run all tests that can run on Linux, with LLVM assertions enabled to catch
   160      # potential bugs.
   161      runs-on: ubuntu-latest
   162      steps:
   163        - name: Checkout
   164          uses: actions/checkout@v4
   165          with:
   166            submodules: true
   167        - name: Install apt dependencies
   168          run: |
   169            echo "Show cpuinfo; sometimes useful when troubleshooting"
   170            cat /proc/cpuinfo
   171            sudo apt-get update
   172            sudo apt-get install --no-install-recommends \
   173                qemu-system-arm \
   174                qemu-system-riscv32 \
   175                qemu-user \
   176                simavr \
   177                ninja-build
   178        - name: Install Go
   179          uses: actions/setup-go@v5
   180          with:
   181            go-version: '1.22'
   182            cache: true
   183        - name: Install Node.js
   184          uses: actions/setup-node@v4
   185          with:
   186            node-version: '18'
   187        - name: Install wasmtime
   188          run: |
   189            mkdir -p $HOME/.wasmtime $HOME/.wasmtime/bin
   190            curl -L https://github.com/bytecodealliance/wasmtime/releases/download/v14.0.4/wasmtime-v14.0.4-x86_64-linux.tar.xz -o wasmtime-v14.0.4-x86_64-linux.tar.xz -SfL
   191            tar -C $HOME/.wasmtime/bin --wildcards -xf wasmtime-v14.0.4-x86_64-linux.tar.xz --strip-components=1 wasmtime-v14.0.4-x86_64-linux/*
   192            echo "$HOME/.wasmtime/bin" >> $GITHUB_PATH
   193        - name: Restore LLVM source cache
   194          uses: actions/cache/restore@v4
   195          id: cache-llvm-source
   196          with:
   197            key: llvm-source-17-linux-asserts-v1
   198            path: |
   199              llvm-project/clang/lib/Headers
   200              llvm-project/clang/include
   201              llvm-project/compiler-rt
   202              llvm-project/lld/include
   203              llvm-project/llvm/include
   204        - name: Download LLVM source
   205          if: steps.cache-llvm-source.outputs.cache-hit != 'true'
   206          run: make llvm-source
   207        - name: Save LLVM source cache
   208          uses: actions/cache/save@v4
   209          if: steps.cache-llvm-source.outputs.cache-hit != 'true'
   210          with:
   211            key: ${{ steps.cache-llvm-source.outputs.cache-primary-key }}
   212            path: |
   213              llvm-project/clang/lib/Headers
   214              llvm-project/clang/include
   215              llvm-project/compiler-rt
   216              llvm-project/lld/include
   217              llvm-project/llvm/include
   218        - name: Restore LLVM build cache
   219          uses: actions/cache/restore@v4
   220          id: cache-llvm-build
   221          with:
   222            key: llvm-build-17-linux-asserts-v1
   223            path: llvm-build
   224        - name: Build LLVM
   225          if: steps.cache-llvm-build.outputs.cache-hit != 'true'
   226          run: |
   227            # fetch LLVM source
   228            rm -rf llvm-project
   229            make llvm-source
   230            # build!
   231            make llvm-build ASSERT=1
   232            # Remove unnecessary object files (to reduce cache size).
   233            find llvm-build -name CMakeFiles -prune -exec rm -r '{}' \;
   234        - name: Save LLVM build cache
   235          uses: actions/cache/save@v4
   236          if: steps.cache-llvm-build.outputs.cache-hit != 'true'
   237          with:
   238            key: ${{ steps.cache-llvm-build.outputs.cache-primary-key }}
   239            path: llvm-build
   240        - name: Cache Binaryen
   241          uses: actions/cache@v4
   242          id: cache-binaryen
   243          with:
   244            key: binaryen-linux-asserts-v1
   245            path: build/wasm-opt
   246        - name: Build Binaryen
   247          if: steps.cache-binaryen.outputs.cache-hit != 'true'
   248          run: make binaryen
   249        - name: Cache wasi-libc
   250          uses: actions/cache@v4
   251          id: cache-wasi-libc
   252          with:
   253            key: wasi-libc-sysroot-linux-asserts-v6
   254            path: lib/wasi-libc/sysroot
   255        - name: Build wasi-libc
   256          if: steps.cache-wasi-libc.outputs.cache-hit != 'true'
   257          run: make wasi-libc
   258        - run: make gen-device -j4
   259        - name: Test TinyGo
   260          run: make ASSERT=1 test
   261        - name: Build TinyGo
   262          run: |
   263            make ASSERT=1
   264            echo "$(pwd)/build" >> $GITHUB_PATH
   265        - name: Test stdlib packages
   266          run: make tinygo-test
   267        - run: make smoketest
   268        - run: make wasmtest
   269        - run: make tinygo-baremetal
   270    build-linux-cross:
   271      # Build ARM Linux binaries, ready for release.
   272      # This intentionally uses an older Linux image, so that we compile against
   273      # an older glibc version and therefore are compatible with a wide range of
   274      # Linux distributions.
   275      # It is set to "needs: build-linux" because it modifies the release created
   276      # in that process to avoid doing lots of duplicate work and to avoid
   277      # complications around precompiled libraries such as compiler-rt shipped as
   278      # part of the release tarball.
   279      strategy:
   280        matrix:
   281          goarch: [ arm, arm64 ]
   282          include:
   283            - goarch: arm64
   284              toolchain: aarch64-linux-gnu
   285              libc: arm64
   286            - goarch: arm
   287              toolchain: arm-linux-gnueabihf
   288              libc: armhf
   289      runs-on: ubuntu-20.04
   290      needs: build-linux
   291      steps:
   292        - name: Checkout
   293          uses: actions/checkout@v4
   294        - name: Install apt dependencies
   295          run: |
   296            sudo apt-get update
   297            sudo apt-get install --no-install-recommends \
   298                qemu-user \
   299                g++-${{ matrix.toolchain }} \
   300                libc6-dev-${{ matrix.libc }}-cross
   301        - name: Install Go
   302          uses: actions/setup-go@v5
   303          with:
   304            go-version: '1.22'
   305            cache: true
   306        - name: Restore LLVM source cache
   307          uses: actions/cache/restore@v4
   308          id: cache-llvm-source
   309          with:
   310            key: llvm-source-17-linux-v1
   311            path: |
   312              llvm-project/clang/lib/Headers
   313              llvm-project/clang/include
   314              llvm-project/compiler-rt
   315              llvm-project/lld/include
   316              llvm-project/llvm/include
   317        - name: Download LLVM source
   318          if: steps.cache-llvm-source.outputs.cache-hit != 'true'
   319          run: make llvm-source
   320        - name: Save LLVM source cache
   321          uses: actions/cache/save@v4
   322          if: steps.cache-llvm-source.outputs.cache-hit != 'true'
   323          with:
   324            key: ${{ steps.cache-llvm-source.outputs.cache-primary-key }}
   325            path: |
   326              llvm-project/clang/lib/Headers
   327              llvm-project/clang/include
   328              llvm-project/compiler-rt
   329              llvm-project/lld/include
   330              llvm-project/llvm/include
   331        - name: Restore LLVM build cache
   332          uses: actions/cache/restore@v4
   333          id: cache-llvm-build
   334          with:
   335            key: llvm-build-17-linux-${{ matrix.goarch }}-v1
   336            path: llvm-build
   337        - name: Build LLVM
   338          if: steps.cache-llvm-build.outputs.cache-hit != 'true'
   339          run: |
   340            # fetch LLVM source
   341            rm -rf llvm-project
   342            make llvm-source
   343            # Install build dependencies.
   344            sudo apt-get install --no-install-recommends ninja-build
   345            # build!
   346            make llvm-build CROSS=${{ matrix.toolchain }}
   347            # Remove unnecessary object files (to reduce cache size).
   348            find llvm-build -name CMakeFiles -prune -exec rm -r '{}' \;
   349        - name: Save LLVM build cache
   350          uses: actions/cache/save@v4
   351          if: steps.cache-llvm-build.outputs.cache-hit != 'true'
   352          with:
   353            key: ${{ steps.cache-llvm-build.outputs.cache-primary-key }}
   354            path: llvm-build
   355        - name: Cache Binaryen
   356          uses: actions/cache@v4
   357          id: cache-binaryen
   358          with:
   359            key: binaryen-linux-${{ matrix.goarch }}-v4
   360            path: build/wasm-opt
   361        - name: Build Binaryen
   362          if: steps.cache-binaryen.outputs.cache-hit != 'true'
   363          run: |
   364            sudo apt-get install --no-install-recommends ninja-build
   365            git submodule update --init lib/binaryen
   366            make CROSS=${{ matrix.toolchain }} binaryen
   367        - name: Install fpm
   368          run: |
   369            sudo gem install --version 4.0.7 public_suffix
   370            sudo gem install --version 2.7.6 dotenv
   371            sudo gem install --no-document fpm
   372        - name: Build TinyGo binary
   373          run: |
   374            make CROSS=${{ matrix.toolchain }}
   375        - name: Download amd64 release
   376          uses: actions/download-artifact@v4
   377          with:
   378            name: linux-amd64-double-zipped
   379        - name: Extract amd64 release
   380          run: |
   381            mkdir -p build/release
   382            tar -xf tinygo.linux-amd64.tar.gz -C build/release tinygo
   383        - name: Modify release
   384          run: |
   385            cp -p build/tinygo   build/release/tinygo/bin
   386            cp -p build/wasm-opt build/release/tinygo/bin
   387        - name: Create ${{ matrix.goarch }} release
   388          run: |
   389            make release deb RELEASEONLY=1 DEB_ARCH=${{ matrix.libc }}
   390            cp -p build/release.tar.gz /tmp/tinygo.linux-${{ matrix.goarch }}.tar.gz
   391            cp -p build/release.deb    /tmp/tinygo_${{ matrix.libc }}.deb
   392        - name: Publish release artifact
   393          uses: actions/upload-artifact@v4
   394          with:
   395            name: linux-${{ matrix.goarch }}-double-zipped
   396            path: |
   397              /tmp/tinygo.linux-${{ matrix.goarch }}.tar.gz
   398              /tmp/tinygo_${{ matrix.libc }}.deb