github.com/ebitengine/purego@v0.8.0-alpha.2.0.20240512170805-6cd12240d332/.github/workflows/test.yml (about)

     1  name: Test
     2  
     3  on: [push, pull_request]
     4  
     5  jobs:
     6    test:
     7      strategy:
     8        matrix:
     9          os: [ubuntu-latest, macos-latest, windows-latest]
    10          go: ['1.18.x', '1.19.x', '1.20.x', '1.21.x', '1.22.x']
    11      name: Test with Go ${{ matrix.go }} on ${{ matrix.os }}
    12      runs-on: ${{ matrix.os }}
    13      defaults:
    14        run:
    15          shell: bash
    16      steps:
    17        - name: Git
    18          run: |
    19            # See actions/checkout#135
    20            git config --global core.autocrlf false
    21            git config --global core.eol lf
    22  
    23        - name: Checkout
    24          uses: actions/checkout@v3
    25  
    26        - name: Setup Go
    27          uses: actions/setup-go@v4
    28          with:
    29            go-version: ${{ matrix.go }}
    30  
    31        - name: Set up the prerequisites
    32          if: runner.os == 'Linux'
    33          run: |
    34            sudo apt-get update
    35            sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu qemu-user
    36  
    37        - name: go vet
    38          if: runner.os != 'Windows' && runner.os != 'macOS'
    39          run: |
    40            go vet -v ./...
    41  
    42        - name: go build
    43          run: |
    44            go build -v ./...
    45            # Compile without optimization to check potential stack overflow.
    46            # The option '-gcflags=all=-N -l' is often used at Visual Studio Code.
    47            # See also https://go.googlesource.com/vscode-go/+/HEAD/docs/debugging.md#launch and the issue hajimehoshi/ebiten#2120.
    48            go build "-gcflags=all=-N -l" -v ./...
    49  
    50            # Check cross-compiling Windows binaries.
    51            env GOOS=windows GOARCH=386 go build -v ./...
    52            env GOOS=windows GOARCH=amd64 go build -v ./...
    53            env GOOS=windows GOARCH=arm go build -v ./...
    54            env GOOS=windows GOARCH=arm64 go build -v ./...
    55  
    56            # Check cross-compiling macOS binaries.
    57            env GOOS=darwin GOARCH=amd64 go build -v ./...
    58            env GOOS=darwin GOARCH=arm64 go build -v ./...
    59  
    60            # Check cross-compiling Linux binaries.
    61            env GOOS=linux GOARCH=amd64 go build -v ./...
    62            env GOOS=linux GOARCH=arm64 go build -v ./...
    63  
    64            # Check cross-compiling FreeBSD binaries.
    65            # gcflags -std is necessary to make fakecgo the Cgo for
    66            # FreeBSD to add the symbols that libc.so depends on.
    67            env GOOS=freebsd GOARCH=amd64 go build -gcflags="github.com/ebitengine/purego/internal/fakecgo=-std" -v ./...
    68            env GOOS=freebsd GOARCH=arm64 go build -gcflags="github.com/ebitengine/purego/internal/fakecgo=-std" -v ./...
    69  
    70        - name: go mod vendor
    71          if: runner.os != 'Linux'
    72          run: |
    73            mkdir /tmp/vendoring
    74            cd /tmp/vendoring
    75            go mod init foo
    76            echo 'package main' > main.go
    77            echo 'import (' >> main.go
    78            echo '  _ "github.com/ebitengine/purego"' >> main.go
    79            echo ')' >> main.go
    80            echo 'func main() {}' >> main.go
    81            go mod edit -replace github.com/ebitengine/purego=$GITHUB_WORKSPACE
    82            go mod tidy
    83            go mod vendor
    84            go build -v .
    85  
    86        - name: go test
    87          run: |
    88            env CGO_ENABLED=0 go test -shuffle=on -v -count=10 ./...
    89            env CGO_ENABLED=1 go test -shuffle=on -v -count=10 ./...
    90  
    91        - name: go test (Linux arm64)
    92          if: runner.os == 'Linux'
    93          run: |
    94            go env -w CC=aarch64-linux-gnu-gcc
    95            go env -w CXX=aarch64-linux-gnu-g++
    96            env GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go test -c -o=purego-test-nocgo .
    97            env QEMU_LD_PREFIX=/usr/aarch64-linux-gnu qemu-aarch64 ./purego-test-nocgo -test.shuffle=on -test.v -test.count=10
    98            env GOOS=linux GOARCH=arm64 CGO_ENABLED=1 go test -c -o=purego-test-cgo .
    99            env QEMU_LD_PREFIX=/usr/aarch64-linux-gnu qemu-aarch64 ./purego-test-cgo -test.shuffle=on -test.v -test.count=10
   100            go env -u CC
   101            go env -u CXX
   102  
   103        - name: go test (Windows 386)
   104          if: runner.os == 'Windows'
   105          run: |
   106            env CGO_ENABLED=0 GOARCH=386 go test -shuffle=on -v -count=10 ./...
   107            env CGO_ENABLED=1 GOARCH=386 go test -shuffle=on -v -count=10 ./...
   108  
   109        - name: go test (Linux 386)
   110          if: runner.os == 'Linux'
   111          run: |
   112             sudo apt-get install gcc-multilib
   113             sudo apt-get install g++-multilib
   114             env CGO_ENABLED=1 GOARCH=386 go test -shuffle=on -v -count=10 ./...
   115  
   116        - name: go test race
   117          if: ${{ !startsWith(matrix.go, '1.18.') && !startsWith(matrix.go, '1.19.') }}
   118          run: |
   119            go test -race -shuffle=on -v -count=10 ./...
   120  
   121    freebsd:
   122      strategy:
   123        matrix:
   124          go: ['1.18.10', '1.19.13', '1.20.14', '1.21.7', '1.22.0']
   125      name: Test with Go ${{ matrix.go }} on FreeBSD
   126      runs-on: ubuntu-22.04
   127      defaults:
   128        run:
   129          shell: bash
   130      steps:
   131        - uses: actions/checkout@v3
   132        - name: Run in freebsd
   133          uses: vmactions/freebsd-vm@v1
   134          with:
   135            usesh: true
   136            prepare: |
   137              fetch https://go.dev/dl/go${{matrix.go}}.freebsd-amd64.tar.gz
   138              rm -fr /usr/local/go && tar -C /usr/local -xf go${{matrix.go}}.freebsd-amd64.tar.gz
   139              ln -s /usr/local/go/bin/go /usr/local/bin
   140            run: |
   141              # FreeBSD tests run within QEMU on Ubuntu.
   142              # vmactions/freebsd-vm only supports a single "step" where it
   143              # brings down the VM at the end of the step, so all
   144              # the commands to run need to be put into this single block.
   145  
   146              echo "Running tests on $(uname -a) at $PWD"
   147  
   148              # verify Go is available
   149              go version
   150  
   151              echo "=> go build"
   152              go build -v ./...
   153              # Compile without optimization to check potential stack overflow.
   154              # The option '-gcflags=all=-N -l' is often used at Visual Studio Code.
   155              # See also https://go.googlesource.com/vscode-go/+/HEAD/docs/debugging.md#launch and the issue hajimehoshi/ebiten#2120.
   156              go build "-gcflags=all=-N -l" -v ./...
   157  
   158              # Check cross-compiling Windows binaries.
   159              env GOOS=windows GOARCH=386 go build -v ./...
   160              env GOOS=windows GOARCH=amd64 go build -v ./...
   161              env GOOS=windows GOARCH=arm go build -v ./...
   162              env GOOS=windows GOARCH=arm64 go build -v ./...
   163  
   164              # Check cross-compiling macOS binaries.
   165              env GOOS=darwin GOARCH=amd64 go build -v ./...
   166              env GOOS=darwin GOARCH=arm64 go build -v ./...
   167  
   168              # Check cross-compiling Linux binaries.
   169              env GOOS=linux GOARCH=amd64 go build -v ./...
   170              env GOOS=linux GOARCH=arm64 go build -v ./...
   171  
   172              # Check cross-compiling FreeBSD binaries.
   173              env GOOS=freebsd GOARCH=amd64 go build -gcflags="github.com/ebitengine/purego/internal/fakecgo=-std" -v ./...
   174              env GOOS=freebsd GOARCH=arm64 go build -gcflags="github.com/ebitengine/purego/internal/fakecgo=-std" -v ./...
   175  
   176              echo "=> go mod vendor"
   177              mkdir /tmp/vendoring
   178              cd /tmp/vendoring
   179              go mod init foo
   180              echo 'package main' > main.go
   181              echo 'import (' >> main.go
   182              echo '  _ "github.com/ebitengine/purego"' >> main.go
   183              echo ')' >> main.go
   184              echo 'func main() {}' >> main.go
   185              go mod edit -replace github.com/ebitengine/purego=$GITHUB_WORKSPACE
   186              go mod tidy
   187              go mod vendor
   188              go build -v .
   189  
   190              cd $GITHUB_WORKSPACE
   191              echo "=> go test CGO_ENABLED=0"
   192              env CGO_ENABLED=0 go test -gcflags="github.com/ebitengine/purego/internal/fakecgo=-std" -shuffle=on -v -count=10 ./...
   193  
   194              echo "=> go test CGO_ENABLED=1"
   195              env CGO_ENABLED=1 go test -shuffle=on -v -count=10 ./...
   196  
   197              if [ -z "$(echo ${{matrix.go}} | grep '^1.1')" ]; then
   198                echo "=> go test race"
   199                go test -race -shuffle=on -v -count=10 ./...
   200              fi