Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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"
17 changes: 17 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down Expand Up @@ -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
Expand Down
43 changes: 38 additions & 5 deletions .github/workflows/scripts/release/build-binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/templates/prepare-swift/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/templates/select-swift-version/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
uses: ./.github/workflows/load-env.yaml

test:
name: Test
needs:
- load-env
env:
Expand Down Expand Up @@ -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"
27 changes: 19 additions & 8 deletions scripts/tools/swift/swift.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:]')"

Expand Down Expand Up @@ -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"
}

Expand All @@ -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+=(
Expand All @@ -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() {
Expand Down
Loading