aboutsummaryrefslogtreecommitdiffhomepage
path: root/.github/workflows/linux.yml
blob: 8bb92e0832c24202f04dfc18e2b054ee24dee2e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
name: Linux

on:
  pull_request:
  push:
    branches:
      - dev
      - release

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  build-linux:
    # Build Linux binaries, ready for release.
    # This runs inside an Alpine Linux container so we can more easily create a
    # statically linked binary.
    runs-on: ubuntu-latest
    container:
      image: golang:1.22-alpine
    steps:
      - name: Install apk dependencies
        # tar: needed for actions/cache@v4
        # git+openssh: needed for checkout (I think?)
        # ruby: needed to install fpm
        run: apk add tar git openssh make g++ ruby-dev
      - name: Work around CVE-2022-24765
        # We're not on a multi-user machine, so this is safe.
        run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
      - name: Checkout
        uses: actions/checkout@v4
        with:
          submodules: true
      - name: Cache Go
        uses: actions/cache@v4
        with:
          key: go-cache-linux-alpine-v1-${{ hashFiles('go.mod') }}
          path: |
            ~/.cache/go-build
            ~/go/pkg/mod
      - name: Restore LLVM source cache
        uses: actions/cache/restore@v4
        id: cache-llvm-source
        with:
          key: llvm-source-18-linux-alpine-v1
          path: |
            llvm-project/clang/lib/Headers
            llvm-project/clang/include
            llvm-project/compiler-rt
            llvm-project/lld/include
            llvm-project/llvm/include
      - name: Download LLVM source
        if: steps.cache-llvm-source.outputs.cache-hit != 'true'
        run: make llvm-source
      - name: Save LLVM source cache
        uses: actions/cache/save@v4
        if: steps.cache-llvm-source.outputs.cache-hit != 'true'
        with:
          key: ${{ steps.cache-llvm-source.outputs.cache-primary-key }}
          path: |
            llvm-project/clang/lib/Headers
            llvm-project/clang/include
            llvm-project/compiler-rt
            llvm-project/lld/include
            llvm-project/llvm/include
      - name: Restore LLVM build cache
        uses: actions/cache/restore@v4
        id: cache-llvm-build
        with:
          key: llvm-build-18-linux-alpine-v1
          path: llvm-build
      - name: Build LLVM
        if: steps.cache-llvm-build.outputs.cache-hit != 'true'
        run: |
          # fetch LLVM source
          rm -rf llvm-project
          make llvm-source
          # install dependencies
          apk add cmake samurai python3
          # build!
          make llvm-build
          # Remove unnecessary object files (to reduce cache size).
          find llvm-build -name CMakeFiles -prune -exec rm -r '{}' \;
      - name: Save LLVM build cache
        uses: actions/cache/save@v4
        if: steps.cache-llvm-build.outputs.cache-hit != 'true'
        with:
          key: ${{ steps.cache-llvm-build.outputs.cache-primary-key }}
          path: llvm-build
      - name: Cache Binaryen
        uses: actions/cache@v4
        id: cache-binaryen
        with:
          key: binaryen-linux-alpine-v1
          path: build/wasm-opt
      - name: Build Binaryen
        if: steps.cache-binaryen.outputs.cache-hit != 'true'
        run: |
          apk add cmake samurai python3
          make binaryen STATIC=1
      - name: Cache wasi-libc
        uses: actions/cache@v4
        id: cache-wasi-libc
        with:
          key: wasi-libc-sysroot-linux-alpine-v2
          path: lib/wasi-libc/sysroot
      - name: Build wasi-libc
        if: steps.cache-wasi-libc.outputs.cache-hit != 'true'
        run: make wasi-libc
      - name: Install fpm
        run: |
          gem install --version 4.0.7 public_suffix
          gem install --version 2.7.6 dotenv
          gem install --no-document fpm
      - name: Run linter
        run: make lint
      - name: Build TinyGo release
        run: |
          make release deb -j3 STATIC=1
          cp -p build/release.tar.gz /tmp/tinygo.linux-amd64.tar.gz
          cp -p build/release.deb    /tmp/tinygo_amd64.deb
      - name: Publish release artifact
        uses: actions/upload-artifact@v4
        with:
          name: linux-amd64-double-zipped
          path: |
            /tmp/tinygo.linux-amd64.tar.gz
            /tmp/tinygo_amd64.deb
  test-linux-build:
    # Test the binaries built in the build-linux job by running the smoke tests.
    runs-on: ubuntu-latest
    needs: build-linux
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          submodules: true
      - name: Install Go
        uses: actions/setup-go@v5
        with:
          go-version: '1.22'
          cache: true
      - name: Install wasmtime
        uses: bytecodealliance/actions/wasmtime/setup@v1
        with:
          version: "19.0.1"
      - name: Install wasm-tools
        uses: bytecodealliance/actions/wasm-tools/setup@v1
      - name: Download release artifact
        uses: actions/download-artifact@v4
        with:
          name: linux-amd64-double-zipped
      - name: Extract release tarball
        run: |
          mkdir -p ~/lib
          tar -C ~/lib -xf tinygo.linux-amd64.tar.gz
          ln -s ~/lib/tinygo/bin/tinygo ~/go/bin/tinygo
      - run: make tinygo-test-wasip1-fast
      - run: make tinygo-test-wasip2-fast
      - run: make smoketest
  assert-test-linux:
    # Run all tests that can run on Linux, with LLVM assertions enabled to catch
    # potential bugs.
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          submodules: true
      - name: Install apt dependencies
        run: |
          echo "Show cpuinfo; sometimes useful when troubleshooting"
          cat /proc/cpuinfo
          sudo apt-get update
          sudo apt-get install --no-install-recommends \
              qemu-system-arm \
              qemu-system-riscv32 \
              qemu-user \
              simavr \
              ninja-build
      - name: Install Go
        uses: actions/setup-go@v5
        with:
          go-version: '1.22'
          cache: true
      - name: Install Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '18'
      - name: Install wasmtime
        uses: bytecodealliance/actions/wasmtime/setup@v1
        with:
          version: "19.0.1"
      - name: Setup `wasm-tools`
        uses: bytecodealliance/actions/wasm-tools/setup@v1
      - name: Restore LLVM source cache
        uses: actions/cache/restore@v4
        id: cache-llvm-source
        with:
          key: llvm-source-18-linux-asserts-v1
          path: |
            llvm-project/clang/lib/Headers
            llvm-project/clang/include
            llvm-project/compiler-rt
            llvm-project/lld/include
            llvm-project/llvm/include
      - name: Download LLVM source
        if: steps.cache-llvm-source.outputs.cache-hit != 'true'
        run: make llvm-source
      - name: Save LLVM source cache
        uses: actions/cache/save@v4
        if: steps.cache-llvm-source.outputs.cache-hit != 'true'
        with:
          key: ${{ steps.cache-llvm-source.outputs.cache-primary-key }}
          path: |
            llvm-project/clang/lib/Headers
            llvm-project/clang/include
            llvm-project/compiler-rt
            llvm-project/lld/include
            llvm-project/llvm/include
      - name: Restore LLVM build cache
        uses: actions/cache/restore@v4
        id: cache-llvm-build
        with:
          key: llvm-build-18-linux-asserts-v1
          path: llvm-build
      - name: Build LLVM
        if: steps.cache-llvm-build.outputs.cache-hit != 'true'
        run: |
          # fetch LLVM source
          rm -rf llvm-project
          make llvm-source
          # build!
          make llvm-build ASSERT=1
          # Remove unnecessary object files (to reduce cache size).
          find llvm-build -name CMakeFiles -prune -exec rm -r '{}' \;
      - name: Save LLVM build cache
        uses: actions/cache/save@v4
        if: steps.cache-llvm-build.outputs.cache-hit != 'true'
        with:
          key: ${{ steps.cache-llvm-build.outputs.cache-primary-key }}
          path: llvm-build
      - name: Cache Binaryen
        uses: actions/cache@v4
        id: cache-binaryen
        with:
          key: binaryen-linux-asserts-v1
          path: build/wasm-opt
      - name: Build Binaryen
        if: steps.cache-binaryen.outputs.cache-hit != 'true'
        run: make binaryen
      - name: Cache wasi-libc
        uses: actions/cache@v4
        id: cache-wasi-libc
        with:
          key: wasi-libc-sysroot-linux-asserts-v6
          path: lib/wasi-libc/sysroot
      - name: Build wasi-libc
        if: steps.cache-wasi-libc.outputs.cache-hit != 'true'
        run: make wasi-libc
      - run: make gen-device -j4
      - name: Test TinyGo
        run: make ASSERT=1 test
      - name: Build TinyGo
        run: |
          make ASSERT=1
          echo "$(pwd)/build" >> $GITHUB_PATH
      - name: Test stdlib packages
        run: make tinygo-test
      - run: make smoketest
      - run: make wasmtest
      - run: make tinygo-baremetal
  build-linux-cross:
    # Build ARM Linux binaries, ready for release.
    # This intentionally uses an older Linux image, so that we compile against
    # an older glibc version and therefore are compatible with a wide range of
    # Linux distributions.
    # It is set to "needs: build-linux" because it modifies the release created
    # in that process to avoid doing lots of duplicate work and to avoid
    # complications around precompiled libraries such as compiler-rt shipped as
    # part of the release tarball.
    strategy:
      matrix:
        goarch: [ arm, arm64 ]
        include:
          - goarch: arm64
            toolchain: aarch64-linux-gnu
            libc: arm64
          - goarch: arm
            toolchain: arm-linux-gnueabihf
            libc: armhf
    runs-on: ubuntu-20.04
    needs: build-linux
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Install apt dependencies
        run: |
          sudo apt-get update
          sudo apt-get install --no-install-recommends \
              qemu-user \
              g++-${{ matrix.toolchain }} \
              libc6-dev-${{ matrix.libc }}-cross
      - name: Install Go
        uses: actions/setup-go@v5
        with:
          go-version: '1.22'
          cache: true
      - name: Restore LLVM source cache
        uses: actions/cache/restore@v4
        id: cache-llvm-source
        with:
          key: llvm-source-18-linux-v1
          path: |
            llvm-project/clang/lib/Headers
            llvm-project/clang/include
            llvm-project/compiler-rt
            llvm-project/lld/include
            llvm-project/llvm/include
      - name: Download LLVM source
        if: steps.cache-llvm-source.outputs.cache-hit != 'true'
        run: make llvm-source
      - name: Save LLVM source cache
        uses: actions/cache/save@v4
        if: steps.cache-llvm-source.outputs.cache-hit != 'true'
        with:
          key: ${{ steps.cache-llvm-source.outputs.cache-primary-key }}
          path: |
            llvm-project/clang/lib/Headers
            llvm-project/clang/include
            llvm-project/compiler-rt
            llvm-project/lld/include
            llvm-project/llvm/include
      - name: Restore LLVM build cache
        uses: actions/cache/restore@v4
        id: cache-llvm-build
        with:
          key: llvm-build-18-linux-${{ matrix.goarch }}-v1
          path: llvm-build
      - name: Build LLVM
        if: steps.cache-llvm-build.outputs.cache-hit != 'true'
        run: |
          # fetch LLVM source
          rm -rf llvm-project
          make llvm-source
          # Install build dependencies.
          sudo apt-get install --no-install-recommends ninja-build
          # build!
          make llvm-build CROSS=${{ matrix.toolchain }}
          # Remove unnecessary object files (to reduce cache size).
          find llvm-build -name CMakeFiles -prune -exec rm -r '{}' \;
      - name: Save LLVM build cache
        uses: actions/cache/save@v4
        if: steps.cache-llvm-build.outputs.cache-hit != 'true'
        with:
          key: ${{ steps.cache-llvm-build.outputs.cache-primary-key }}
          path: llvm-build
      - name: Cache Binaryen
        uses: actions/cache@v4
        id: cache-binaryen
        with:
          key: binaryen-linux-${{ matrix.goarch }}-v4
          path: build/wasm-opt
      - name: Build Binaryen
        if: steps.cache-binaryen.outputs.cache-hit != 'true'
        run: |
          sudo apt-get install --no-install-recommends ninja-build
          git submodule update --init lib/binaryen
          make CROSS=${{ matrix.toolchain }} binaryen
      - name: Install fpm
        run: |
          sudo gem install --version 4.0.7 public_suffix
          sudo gem install --version 2.7.6 dotenv
          sudo gem install --no-document fpm
      - name: Build TinyGo binary
        run: |
          make CROSS=${{ matrix.toolchain }}
      - name: Download amd64 release
        uses: actions/download-artifact@v4
        with:
          name: linux-amd64-double-zipped
      - name: Extract amd64 release
        run: |
          mkdir -p build/release
          tar -xf tinygo.linux-amd64.tar.gz -C build/release tinygo
      - name: Modify release
        run: |
          cp -p build/tinygo   build/release/tinygo/bin
          cp -p build/wasm-opt build/release/tinygo/bin
      - name: Create ${{ matrix.goarch }} release
        run: |
          make release deb RELEASEONLY=1 DEB_ARCH=${{ matrix.libc }}
          cp -p build/release.tar.gz /tmp/tinygo.linux-${{ matrix.goarch }}.tar.gz
          cp -p build/release.deb    /tmp/tinygo_${{ matrix.libc }}.deb
      - name: Publish release artifact
        uses: actions/upload-artifact@v4
        with:
          name: linux-${{ matrix.goarch }}-double-zipped
          path: |
            /tmp/tinygo.linux-${{ matrix.goarch }}.tar.gz
            /tmp/tinygo_${{ matrix.libc }}.deb