From 0ca224993ff5477d8a63d3d4bfe2b583b5d86341 Mon Sep 17 00:00:00 2001 From: Vitalii Budnik Date: Wed, 3 Jun 2026 18:21:11 +0300 Subject: [PATCH] chore: musl and glibc bins for linux --- .github/workflows/build.yaml | 28 ++++++++++++ .github/workflows/release.yaml | 17 ++++++++ .../workflows/scripts/release/build-binary.sh | 43 ++++++++++++++++--- .../templates/prepare-swift/action.yaml | 21 +++++++++ .../select-swift-version/action.yaml | 8 ++++ .github/workflows/test.yaml | 16 +++++++ scripts/tools/swift/swift.sh | 27 ++++++++---- 7 files changed, 147 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 0b7fab3..38ea726 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -33,6 +33,19 @@ jobs: - os: ubuntu-latest swift-version: ${{ needs.load-env.outputs.swift-version }} container: swift:${{ needs.load-env.outputs.swift-version }} + sdk: musl + - os: ubuntu-26.04-arm + swift-version: ${{ needs.load-env.outputs.swift-version }} + container: swift:${{ needs.load-env.outputs.swift-version }} + sdk: musl + - os: ubuntu-latest + swift-version: ${{ needs.load-env.outputs.swift-version }} + container: swift:${{ needs.load-env.outputs.swift-version }} + sdk: gnu + - os: ubuntu-26.04-arm + swift-version: ${{ needs.load-env.outputs.swift-version }} + container: swift:${{ needs.load-env.outputs.swift-version }} + sdk: gnu runs-on: ${{ matrix.os }} container: ${{ matrix.container }} @@ -56,3 +69,18 @@ jobs: run: ./.github/workflows/scripts/release/build-binary.sh env: BINARY_NAME: ${{ needs.load-env.outputs.binary-name }} + SWIFT_SDK: ${{ matrix.sdk }} + + # Dummy job to check if build passed and easy to configure PR gates. + check: + name: Check + needs: + - load-env + - build-release-binary + runs-on: ubuntu-latest + if: success() + steps: + - name: Check + shell: bash + run: | + echo "Build passed" diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 4e7edaf..39e95ec 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -68,6 +68,22 @@ jobs: arch: x86_64 swift-version: ${{ needs.load-env.outputs.swift-version }} container: swift:${{ needs.load-env.outputs.swift-version }} + sdk: gnu + - os: ubuntu-26.04-arm + arch: arm64 + swift-version: ${{ needs.load-env.outputs.swift-version }} + container: swift:${{ needs.load-env.outputs.swift-version }} + sdk: gnu + - os: ubuntu-latest + arch: x86_64 + swift-version: ${{ needs.load-env.outputs.swift-version }} + container: swift:${{ needs.load-env.outputs.swift-version }} + sdk: musl + - os: ubuntu-26.04-arm + arch: arm64 + swift-version: ${{ needs.load-env.outputs.swift-version }} + container: swift:${{ needs.load-env.outputs.swift-version }} + sdk: musl runs-on: ${{ matrix.os }} container: ${{ matrix.container }} @@ -112,6 +128,7 @@ jobs: VERSION: ${{ needs.load-env.outputs.version }} ARCH: ${{ matrix.arch }} BINARY_NAME: ${{ needs.load-env.outputs.binary-name }} + SWIFT_SDK: ${{ matrix.sdk }} run: ./.github/workflows/scripts/release/build-binary.sh - name: Upload artifact diff --git a/.github/workflows/scripts/release/build-binary.sh b/.github/workflows/scripts/release/build-binary.sh index aab7c5c..9bd2846 100755 --- a/.github/workflows/scripts/release/build-binary.sh +++ b/.github/workflows/scripts/release/build-binary.sh @@ -8,7 +8,13 @@ VERSION="${VERSION#v}" BINARY_NAME="${BINARY_NAME:-"mpct"}" PLATFORM="${PLATFORM:-"$(uname -s)"}" ARCH="${ARCH:-"$(uname -m)"}" -ARCHIVE_NAME="${BINARY_NAME}-${VERSION}-${PLATFORM}-${ARCH}.zip" +SWIFT_SDK="${SWIFT_SDK:-""}" + +ARCHIVE_NAME="${BINARY_NAME}-${VERSION}-${PLATFORM}-${ARCH}" +if [[ -n "${SWIFT_SDK}" ]]; then + ARCHIVE_NAME="${ARCHIVE_NAME}-${SWIFT_SDK}" +fi +ARCHIVE_NAME="${ARCHIVE_NAME}.zip" echo "Building binary for platform: ${PLATFORM}, architecture: ${ARCH}, version: ${VERSION}" @@ -17,8 +23,35 @@ mkdir -p build function build() { local ARCH="${1}" - echo "Building ${ARCH} binary for ${PLATFORM}..." - ./scripts/tools/swift/swift.sh --action=build --configuration=release -- --arch "${ARCH}" --product "${BINARY_NAME}" + local SWIFT_SDK="${2}" + local SWIFT_SDK_PARAM="" + echo "Building ${ARCH} binary for ${PLATFORM} with Swift SDK: ${SWIFT_SDK}..." + if [[ -n "${SWIFT_SDK}" && "${PLATFORM}" == "Linux" ]]; then + + if [ "${SWIFT_SDK}" == "musl" ]; then + SWIFT_SDK_PARAM="swift-linux-musl" + elif [ "${SWIFT_SDK}" == "gnu" ]; then + SWIFT_SDK_PARAM="unknown-linux-gnu" + fi + if [[ ${ARCH} == "aarch64" ]]; then + SWIFT_SDK_PARAM="aarch64-${SWIFT_SDK_PARAM}" + elif [[ ${ARCH} == "x86_64" ]]; then + SWIFT_SDK_PARAM="x86_64-${SWIFT_SDK_PARAM}" + else + echo "Unsupported architecture: ${ARCH}" + exit 1 + fi + + if [ "${SWIFT_SDK}" == "gnu" ]; then + SWIFT_SDK_PARAM="" + fi + fi + + if [[ -n "${SWIFT_SDK_PARAM}" ]]; then + ./scripts/tools/swift/swift.sh --action=build --configuration=release -- --arch "${ARCH}" --product "${BINARY_NAME}" --swift-sdk "${SWIFT_SDK_PARAM}" + else + ./scripts/tools/swift/swift.sh --action=build --configuration=release -- --arch "${ARCH}" --product "${BINARY_NAME}" + fi } if [ "${PLATFORM}" == "Darwin" ] && [ "${ARCH}" == "universal" ]; then @@ -47,9 +80,9 @@ elif [ "${PLATFORM}" == "Darwin" ] && [[ ${ARCH} == "arm64" || ${ARCH} == "x86_6 echo "Verifying binary..." lipo "build/${BINARY_NAME}" -verify_arch "${ARCH}" -elif [ "${PLATFORM}" == "Linux" ] && [ "${ARCH}" == "x86_64" ]; then +elif [ "${PLATFORM}" == "Linux" ] && [[ ${ARCH} == "aarch64" || ${ARCH} == "x86_64" ]]; then # Build for Linux x86_64 - build "${ARCH}" + build "${ARCH}" "${SWIFT_SDK}" mv ".build/release/${BINARY_NAME}" "build/${BINARY_NAME}" # Verify the binary diff --git a/.github/workflows/templates/prepare-swift/action.yaml b/.github/workflows/templates/prepare-swift/action.yaml index 6647445..c9e461a 100644 --- a/.github/workflows/templates/prepare-swift/action.yaml +++ b/.github/workflows/templates/prepare-swift/action.yaml @@ -62,6 +62,27 @@ runs: if: ${{ runner.os != 'Linux' }} uses: jdx/mise-action@5ac50f778e26fac95da98d50503682459e86d566 + - uses: vapor/swiftly-action@v0.2 + if: ${{ runner.os == 'Linux' }} + with: + toolchain: ${{ inputs.swift-version }} + + - name: Install Swift SDK ${{ inputs.swift-version }} + if: ${{ runner.os == 'Linux' }} + shell: bash + run: | + swiftly install "${SWIFT_VERSION}" --assume-yes --use --verify --verbose + swiftly link --assume-yes --verbose + swiftly list + swiftly list "${SWIFT_VERSION}" --format json + env: + SWIFT_VERSION: ${{ inputs.swift-version }} + + - name: List Swift SDKs (all) + shell: bash + run: | + swift sdk list + - name: Select Swift Version uses: ./.github/workflows/templates/select-swift-version/ with: diff --git a/.github/workflows/templates/select-swift-version/action.yaml b/.github/workflows/templates/select-swift-version/action.yaml index 0dd9549..005a451 100644 --- a/.github/workflows/templates/select-swift-version/action.yaml +++ b/.github/workflows/templates/select-swift-version/action.yaml @@ -22,6 +22,14 @@ runs: env: XCODE_VERSION: ${{ inputs.xcode-version }} + - name: Use Swift SDK ${{ inputs.swift-version }} (Linux) + if: ${{ runner.os == 'Linux' }} + shell: bash + run: | + swiftly use --assume-yes --verbose "${SWIFT_VERSION}" + env: + SWIFT_VERSION: ${{ inputs.swift-version }} + # - name: Setup Swift (Linux) # if: ${{ inputs.swift-version != '' && runner.os == 'Linux' }} # uses: swift-actions/setup-swift@7d6348b84c07b33515ee21ebc40bbf974cc19d40 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 926c44d..fad0bc8 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -21,6 +21,7 @@ jobs: uses: ./.github/workflows/load-env.yaml test: + name: Test needs: - load-env env: @@ -91,3 +92,18 @@ jobs: - name: Lint run: mise tasks run lint + + # Dummy job to check if test and lint passed and easy to configure PR gates. + check: + name: Check + needs: + - load-env + - test + - lint + runs-on: ubuntu-latest + if: success() + steps: + - name: Check + shell: bash + run: | + echo "Test and lint passed" diff --git a/scripts/tools/swift/swift.sh b/scripts/tools/swift/swift.sh index 746339d..f8804bb 100755 --- a/scripts/tools/swift/swift.sh +++ b/scripts/tools/swift/swift.sh @@ -4,7 +4,13 @@ set -Eeo pipefail PLATFORM="${PLATFORM:-"$(uname -s)"}" -swift_install_sdk() { +if [ "${PLATFORM}" == "Linux" ]; then + SWIFT_COMMAND="swiftly run swift" +else + SWIFT_COMMAND="${SWIFT_BINARY:-"$(which swift || echo '/usr/bin/swift')"}" +fi + +swift_install_musl_sdk() { local ARTIFACT_BUNDLE_FILE SWIFT_VERSION SWIFT_SDK_FOLDER SWIFT_VERSION_SHORT SDK_URL SWIFT_VERSION="$(cat .swift-version | tr -d '[:space:]')" @@ -44,12 +50,12 @@ swift_install_sdk() { CHECKSUM="$(swift package compute-checksum "/tmp/${ARTIFACT_BUNDLE_FILE}.tar.gz")" echo "Installing Swift SDK..." - swift sdk install "/tmp/${ARTIFACT_BUNDLE_FILE}.tar.gz" --checksum "${CHECKSUM}" + ${SWIFT_COMMAND} sdk install "/tmp/${ARTIFACT_BUNDLE_FILE}.tar.gz" --checksum "${CHECKSUM}" rm -rf "/tmp/${ARTIFACT_BUNDLE_FILE}.tar.gz" fi - swift sdk list + ${SWIFT_COMMAND} sdk list echo "Swift SDK installed" } @@ -67,7 +73,6 @@ swift_run() { DEFAULT_ARGS+=( "--disable-index-store" "--static-swift-stdlib" - "--swift-sdk" "${SWIFT_SDK:-"x86_64-swift-linux-musl"}" ) elif [ "${ACTION}" == "test" ]; then DEFAULT_ARGS+=( @@ -82,12 +87,18 @@ swift_run() { fi if [ "${PLATFORM}" == "Linux" ]; then - swift_install_sdk + if [[ "${*}" == *"-musl"* ]]; then + swift_install_musl_sdk + fi fi - SWIFT_BINARY="${SWIFT_BINARY:-"$(which swift || echo '/usr/bin/swift')"}" - echo "${SWIFT_BINARY} ${ACTION} ${DEFAULT_ARGS[*]} ${*}" - "$SWIFT_BINARY" "${ACTION}" "${DEFAULT_ARGS[@]}" "${@}" + echo "swift sdk list" + swift sdk list + + echo "${SWIFT_COMMAND} sdk list" + ${SWIFT_COMMAND} sdk list + echo "${SWIFT_COMMAND} ${ACTION} ${DEFAULT_ARGS[*]} ${*}" + ${SWIFT_COMMAND} "${ACTION}" "${DEFAULT_ARGS[@]}" "${@}" } die() {