Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload releases for musl-libc and android #2149

Merged
merged 18 commits into from
Dec 15, 2023
Merged
2 changes: 1 addition & 1 deletion .github/util/initialize/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Initialize
description: Check out Dart Sass and build the embedded protocol buffer.
inputs:
github-token: {required: true}
node-version: {required: false, default: 18}
node-version: {required: false, default: 'lts/*'}
dart-sdk: {required: false, default: stable}
architecture: {required: false}
runs:
Expand Down
71 changes: 71 additions & 0 deletions .github/workflows/build-android.yml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we ever had anyone request native Android support for Dart Sass? I'm not sure this is worth the trouble.

Copy link
Contributor Author

@ntkme ntkme Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were a few people asking this from jekyll community. Interestingly, now there are some (very few) active users:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess another point is SWC (https://swc.rs/) also has native android support: https://www.npmjs.com/package/@swc/core-android-arm64

This means there are people out there using android for web development...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we ever had anyone request native Android support for Dart Sass? I'm not sure this is worth the trouble.

Now that dart-sass has an Android variant, I actually had a request to get my embedded host working on Android:
larsgrefer/dart-sass-java#461 (comment)

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Build for android

on:
workflow_call:
workflow_dispatch:

jobs:
build:
name: Build

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
include:
- arch: x64
lib: lib64
platform: linux/amd64
- arch: ia32
lib: lib
platform: linux/amd64
- arch: arm64
lib: lib64
platform: linux/arm64
- arch: arm
lib: lib
platform: linux/arm64

steps:
- uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
image: tonistiigi/binfmt:master # need qemu >= 7.0.0

- name: Compile Protobuf
run: |
docker run --rm -i \
--volume "$PWD:$PWD" \
--workdir "$PWD" \
docker.io/library/dart <<'EOF'
set -e
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
dart pub get
dart run grinder protobuf
EOF

- name: Build
run: |
docker run --rm -i \
--platform ${{ matrix.platform }} \
--privileged \
--volume "$PWD:$PWD" \
--workdir "$PWD" \
ghcr.io/dart-android/dart <<'EOF'
set -e
export DART_SDK=/system/${{ matrix.lib }}/dart
export PATH=$DART_SDK/bin:$PATH
dart pub get
dart run grinder pkg-standalone-android-${{ matrix.arch }}
EOF

- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: build-android-${{ matrix.arch }}
path: build/*.tar.gz
if-no-files-found: error
compression-level: 0
89 changes: 89 additions & 0 deletions .github/workflows/build-linux-musl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Build for linux-musl

on:
workflow_call:
workflow_dispatch:

jobs:
build:
name: Build

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
include:
- arch: x64
platform: linux/amd64
- arch: ia32
platform: linux/386
- arch: arm64
platform: linux/arm64
- arch: arm
platform: linux/arm/v7

steps:
- uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Compile Protobuf
run: |
docker run --rm -i \
--volume "$PWD:$PWD" \
--workdir "$PWD" \
docker.io/library/dart <<'EOF'
set -e
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
dart pub get
dart run grinder protobuf
EOF

# There is a bug in qemu's mremap causing pthread_getattr_np in musl to stuck in a loop on arm.
# Unless qemu fixes the bug or we get a real linux-arm runner, we cannot build aot-snapshot
# for arm on CI. So, we create an kernel snapshot for arm build in amd64 container instead.
#
# In addition, we need to rename the artifact from -linux- to -linux-musl- to avoid conflict
# with glibc builds.
- name: Build
run: |
docker run --rm -i \
--platform ${{ matrix.arch == 'arm' && 'linux/amd64' || matrix.platform }} \
--volume "$PWD:$PWD" \
--workdir "$PWD" \
ghcr.io/dart-musl/dart <<'EOF'
set -e
dart pub get
dart run grinder pkg-standalone-linux-${{ matrix.arch }}
find build -name '*.tar.gz' -print0 | xargs -0 -n 1 -- sh -xc 'mv "$1" "$(echo "$1" | sed -e "s/linux/linux-musl/")"' --
EOF

# The kernel snapshot created for arm in the previous step is bundling a glibc based dart runtime
# due to how cli_pkg download the sdk for building non-native platforms. Therefore we need to
# replace it with musl-libc based dart runtime to create a working linux-musl-arm package.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to build more of this logic into cli-pkg? We could teach it pkg-standalone-linux-musl-* with your SDK releases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's certainly possible, but I would consider that at a later time due to the complexity. The problem mainly lies on dart-sdk only have the knowledge of itself running as some "linux" variant, and have no concept of "linux-gnu" or "linux-musl", which would require lots of structural changes to cli_pkg to accommodate this. Also, we need a way to know what is the current running variant, that either the current running dart-sdk need to be able to tell what kind of linux variant by itself, or we need to parse the dart executable file as ELF, and then detect what it is based on the interpreter field.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible for your fork to add "musl" somewhere in the dart --version output? That seems like the easiest way to tell—we don't need an actual API call in the SDK itself necessarily.

Copy link
Contributor Author

@ntkme ntkme Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My "fork" does not modify any dart-sdk source code. Only thing it does is running a CI/CD with a different build toolchain for building dart-sdk on alpine linux.

The reason I said it is difficult to do in either dart or cli_pkg is because the platform logic in dart is closely tied to the Abi class in ffi package. For example, the dart --version pretty much prints Abi.current().toString(). In order to print musl, we can possibly either add new constant, but this will likely break existing code that does the platform detection via Abi class; or modify dart --version to hard code a different string instead of using constant, which again might be unexpected.

I don't think change the version string is the correct behavior. I think the right way to deal with this in dart-sdk would be to provide new API that returns the "target triplet". For example, in ruby we have RbConfig::CONFIG['arch'] which would return x86_64-linux-musl that clearly identify the right platform.

- name: Fix Dart Runtime
if: matrix.arch == 'arm'
run: |
docker run --rm -i \
--platform ${{ matrix.platform }} \
--volume $PWD:$PWD \
--workdir $PWD \
ghcr.io/dart-musl/dart <<'EOF'
set -e
apk add --no-cache tar
cd build
DART_RUNTIME=$(tar -tzf *.tar.gz --wildcards "*/src/dart")
tar -xzf *.tar.gz
cp $DART_SDK/bin/dart $DART_RUNTIME
tar -czf *.tar.gz "$(dirname "$(dirname "$DART_RUNTIME")")"
EOF

- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: build-linux-musl-${{ matrix.arch }}
path: build/*.tar.gz
if-no-files-found: error
compression-level: 0
62 changes: 62 additions & 0 deletions .github/workflows/build-linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Build for linux

on:
workflow_call:
workflow_dispatch:

jobs:
build:
name: Build

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
include:
- arch: x64
platform: linux/amd64
- arch: ia32
platform: linux/amd64
- arch: arm
platform: linux/arm/v7
- arch: arm64
platform: linux/arm64

steps:
- uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Compile Protobuf
run: |
docker run --rm -i \
--volume "$PWD:$PWD" \
--workdir "$PWD" \
docker.io/library/dart <<'EOF'
set -e
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
dart pub get
dart run grinder protobuf
EOF

- name: Build
run: |
docker run --rm -i \
--platform ${{ matrix.platform }} \
--volume "$PWD:$PWD" \
--workdir "$PWD" \
docker.io/library/dart:latest <<'EOF'
set -e
dart pub get
dart run grinder pkg-standalone-linux-${{ matrix.arch }}
EOF

- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: build-linux-${{ matrix.arch }}
path: build/*.tar.gz
if-no-files-found: error
compression-level: 0
38 changes: 38 additions & 0 deletions .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build for macos

on:
workflow_call:
workflow_dispatch:

jobs:
build:
name: Build

runs-on: ${{ matrix.runner }}

strategy:
fail-fast: false
matrix:
include:
- arch: x64
runner: macos-latest
# https://github.blog/2023-10-02-introducing-the-new-apple-silicon-powered-m1-macos-larger-runner-for-github-actions/
- arch: arm64
runner: macos-latest-xlarge

steps:
- uses: actions/checkout@v4

- uses: ./.github/util/initialize
with: {github-token: "${{ github.token }}"}

- name: Build
run: dart run grinder pkg-standalone-macos-${{ matrix.arch }}

- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: build-macos-${{ matrix.arch }}
path: build/*.tar.gz
if-no-files-found: error
compression-level: 0
39 changes: 39 additions & 0 deletions .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build for windows

on:
workflow_call:
workflow_dispatch:

jobs:
build:
name: Build

runs-on: ${{ matrix.runner }}

strategy:
fail-fast: false
matrix:
include:
- arch: x64
runner: windows-latest
- arch: ia32
runner: windows-latest
# - arch: arm64
# runner: windows-latest

steps:
- uses: actions/checkout@v4

- uses: ./.github/util/initialize
with: {github-token: "${{ github.token }}"}

- name: Build
run: dart run grinder pkg-standalone-windows-${{ matrix.arch }}

- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: build-windows-${{ matrix.arch }}
path: build/*.zip
if-no-files-found: error
compression-level: 0
Loading