|
| 1 | +name: Build for linux-musl |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + workflow_dispatch: |
| 6 | + |
| 7 | +jobs: |
| 8 | + build: |
| 9 | + name: Build |
| 10 | + |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + strategy: |
| 14 | + fail-fast: false |
| 15 | + matrix: |
| 16 | + include: |
| 17 | + - arch: x64 |
| 18 | + platform: linux/amd64 |
| 19 | + - arch: ia32 |
| 20 | + platform: linux/386 |
| 21 | + - arch: arm64 |
| 22 | + platform: linux/arm64 |
| 23 | + - arch: arm |
| 24 | + platform: linux/arm/v7 |
| 25 | + |
| 26 | + steps: |
| 27 | + - uses: actions/checkout@v4 |
| 28 | + |
| 29 | + - name: Set up QEMU |
| 30 | + uses: docker/setup-qemu-action@v3 |
| 31 | + |
| 32 | + - name: Compile Protobuf |
| 33 | + run: | |
| 34 | + docker run --rm -i \ |
| 35 | + --volume "$PWD:$PWD" \ |
| 36 | + --workdir "$PWD" \ |
| 37 | + docker.io/library/dart <<'EOF' |
| 38 | + set -e |
| 39 | + curl -fsSL -H "Authorization: Bearer ${{ github.token }}" "https://github.com/bufbuild/buf/releases/latest/download/buf-$(uname -s)-$(uname -m).tar.gz" | tar -xzC /usr/local --strip-components 1 |
| 40 | + dart pub get |
| 41 | + dart run grinder protobuf |
| 42 | + EOF |
| 43 | +
|
| 44 | + # https://gitlab.com/qemu-project/qemu/-/issues/1729 |
| 45 | + # |
| 46 | + # There is a bug in qemu's mremap causing pthread_getattr_np in musl to stuck in a loop on arm. |
| 47 | + # Unless qemu fixes the bug or we get a real linux-arm runner, we cannot build aot-snapshot |
| 48 | + # for arm on CI. So, we create a kernel snapshot for arm build in amd64 container instead. |
| 49 | + - name: Build |
| 50 | + run: | |
| 51 | + docker run --rm -i \ |
| 52 | + --platform ${{ matrix.arch == 'arm' && 'linux/amd64' || matrix.platform }} \ |
| 53 | + --volume "$PWD:$PWD" \ |
| 54 | + --workdir "$PWD" \ |
| 55 | + ghcr.io/dart-musl/dart <<'EOF' |
| 56 | + set -e |
| 57 | + dart pub get |
| 58 | + dart run grinder pkg-standalone-linux-${{ matrix.arch }} |
| 59 | + # Rename the artifact from -linux- to -linux-musl- to avoid conflict with glibc builds. |
| 60 | + find build -name '*.tar.gz' -print0 | xargs -0 -n 1 -- sh -xc 'mv "$1" "$(echo "$1" | sed -e "s/linux/linux-musl/")"' -- |
| 61 | + EOF |
| 62 | +
|
| 63 | + # The kernel snapshot created for arm in the previous step is bundling a glibc based dart runtime |
| 64 | + # due to how cli_pkg downloads the sdk for building non-native platforms. Therefore we need to |
| 65 | + # replace it with musl-libc based dart runtime to create a working linux-musl-arm package. |
| 66 | + - name: Fix Dart Runtime |
| 67 | + if: matrix.arch == 'arm' |
| 68 | + run: | |
| 69 | + docker run --rm -i \ |
| 70 | + --platform ${{ matrix.platform }} \ |
| 71 | + --volume $PWD:$PWD \ |
| 72 | + --workdir $PWD \ |
| 73 | + ghcr.io/dart-musl/dart <<'EOF' |
| 74 | + set -e |
| 75 | + apk add --no-cache tar |
| 76 | + cd build |
| 77 | + DART_RUNTIME=$(tar -tzf *.tar.gz --wildcards "*/src/dart") |
| 78 | + tar -xzf *.tar.gz |
| 79 | + cp $DART_SDK/bin/dart $DART_RUNTIME |
| 80 | + tar -czf *.tar.gz "$(dirname "$(dirname "$DART_RUNTIME")")" |
| 81 | + EOF |
| 82 | +
|
| 83 | + - name: Upload Artifact |
| 84 | + uses: actions/upload-artifact@v4 |
| 85 | + with: |
| 86 | + name: build-linux-musl-${{ matrix.arch }} |
| 87 | + path: build/*.tar.gz |
| 88 | + if-no-files-found: error |
| 89 | + compression-level: 0 |
0 commit comments