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
143 changes: 109 additions & 34 deletions .github/workflows/build-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,79 +26,154 @@ on:
required: true
default: '3.1.2'
type: string
swift_version_linux:
description: 'The Swift toolchain version to install on the Linux runner'
required: true
default: '6.2'
type: string

# Surface inputs as env vars so shell bodies can read them as `$VARS`
# rather than `${{ ... }}` (Semgrep flags context-var expansion in `run:`).
env:
RELEASE_TAG: ${{ inputs.tag }}${{ inputs.build_number != '' && format('+{0}', inputs.build_number) || '' }}
SWIFT_SYNTAX_VERSION: ${{ inputs.tag }}
BUILD_NUMBER: ${{ inputs.build_number }}
XCODE_VERSION: ${{ inputs.xcode_version }}
MACOS_VERSION: ${{ inputs.macos_version }}
RULES_SWIFT_VERSION: ${{ inputs.rules_swift_version }}
SWIFT_VERSION_LINUX: ${{ inputs.swift_version_linux }}

# Read-only by default; publish job opts in to contents:write.
permissions:
contents: read

jobs:
build-publish:
build-macos-arm64:
runs-on: macos-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
XCODE_VERSION: ${{ github.event.inputs.xcode_version }}
RULES_SWIFT_VERSION: ${{ github.event.inputs.rules_swift_version }}
MACOS_VERSION: ${{ github.event.inputs.macos_version }}
TARGET_PLATFORM: macos-arm64
steps:
- name: Install brew dependencies
run: |
brew install buildozer
run: brew install buildozer
- name: Select Xcode ${{ env.XCODE_VERSION }}
run: sudo xcode-select -s /Applications/Xcode_${{ env.XCODE_VERSION }}.app
- name: Clone repo
uses: actions/checkout@v4
- name: Clone SwiftSyntax
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh repo clone apple/swift-syntax -- \
--depth 1 \
--branch ${{ github.event.inputs.tag }} \
--branch "$SWIFT_SYNTAX_VERSION" \
--single-branch
- name: Build & Publish SwiftSyntax prebuilt binary
- name: Build SwiftSyntax for macos-arm64
run: ./build.sh build
- name: Upload per-platform staging artifact
uses: actions/upload-artifact@v4
with:
name: staging-macos-arm64
path: staging/macos-arm64.tar.gz
if-no-files-found: error

build-linux-x86_64:
runs-on: ubuntu-latest
env:
TARGET_PLATFORM: linux-x86_64
# rules_swift's Linux toolchain requires clang; ubuntu-latest defaults to gcc.
CC: clang
CXX: clang++
steps:
- name: Install Swift ${{ env.SWIFT_VERSION_LINUX }}
uses: swift-actions/setup-swift@7ca6abe6b3b0e8b5421b88be48feee39cbf52c6a # v2.4.0
with:
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
swift-version: ${{ env.SWIFT_VERSION_LINUX }}
- name: Install clang + buildozer + jq
run: |
set -euo pipefail
sudo apt-get update
sudo apt-get install -y clang jq
curl -sSL -o /tmp/buildozer \
https://github.com/bazelbuild/buildtools/releases/latest/download/buildozer-linux-amd64
chmod +x /tmp/buildozer
sudo mv /tmp/buildozer /usr/local/bin/buildozer
- name: Clone repo
uses: actions/checkout@v4
- name: Clone SwiftSyntax
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh repo clone apple/swift-syntax -- \
--depth 1 \
--branch "$SWIFT_SYNTAX_VERSION" \
--single-branch
- name: Build SwiftSyntax for linux-x86_64
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
run: ./build.sh build
- name: Upload per-platform staging artifact
uses: actions/upload-artifact@v4
with:
name: staging-linux-x86_64
path: staging/linux-x86_64.tar.gz
if-no-files-found: error

release_tag="${{ github.event.inputs.tag }}"
if [ -n "${{ github.event.inputs.build_number }}" ]; then
release_tag="$release_tag+${{ github.event.inputs.build_number }}"
fi

archive_name="swift-syntax-$release_tag"
publish:
needs:
- build-macos-arm64
- build-linux-x86_64
runs-on: ubuntu-latest
permissions:
contents: write # gh release create
steps:
- name: Clone repo
uses: actions/checkout@v4
- name: Download per-platform staging artifacts
uses: actions/download-artifact@v4
with:
path: staging
pattern: staging-*
merge-multiple: true
- name: Package SwiftSyntax prebuilt archive
run: ./build.sh package
- name: Build & Publish SwiftSyntax prebuilt binary
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail

# Run the build and create the archive
SWIFT_SYNTAX_VERSION=${{ github.event.inputs.tag }} \
RULES_SWIFT_VERSION=${{ env.RULES_SWIFT_VERSION }} \
MACOS_VERSION=${{ env.MACOS_VERSION }} \
BUILD_NUMBER=${{ github.event.inputs.build_number }} \
./build.sh
archive_name="swift-syntax-${RELEASE_TAG}"
bzlmod_sha256=$(cat "${archive_name}.tar.gz.sha256")

# Make the release notes
cat > release-notes.md <<EOF
# SwiftSyntax Prebuilt $release_tag
# SwiftSyntax Prebuilt $RELEASE_TAG

This release contains the pre-built binaries for SwiftSyntax \`${{ github.event.inputs.tag }}\`.
This release contains the pre-built binaries for SwiftSyntax \`$SWIFT_SYNTAX_VERSION\`.

Built with:
- Xcode \`${{ env.XCODE_VERSION }}\`
- macOS \`${{ env.MACOS_VERSION }}\`
- Xcode \`$XCODE_VERSION\` (macOS)
- macOS \`$MACOS_VERSION\`
- Swift \`$SWIFT_VERSION_LINUX\` (Linux)

Supported architectures:
- arm64
Supported platforms:
- macOS arm64
- Linux x86_64

Dependencies:
- [rules_swift](https://github.com/bazelbuild/rules_swift) \`${{ env.RULES_SWIFT_VERSION }}\`
- [rules_swift](https://github.com/bazelbuild/rules_swift) \`$RULES_SWIFT_VERSION\`

Use in your \`MODULE.bazel\` file with \`archive_override\`:

\`\`\`starlark
archive_override(
module_name = "swift-syntax",
integrity = "$bzlmod_sha256",
strip_prefix = "swift-syntax-$release_tag",
urls = ["https://github.com/square/swift-syntax-prebuilt/releases/download/$release_tag/swift-syntax-$release_tag.tar.gz"],
strip_prefix = "swift-syntax-$RELEASE_TAG",
urls = ["https://github.com/square/swift-syntax-prebuilt/releases/download/$RELEASE_TAG/swift-syntax-$RELEASE_TAG.tar.gz"],
)
\`\`\`
EOF

# Publish the tarball to GitHub Releases.
gh release create "$release_tag" \
--title "swift-syntax-prebuilt version $release_tag" \
gh release create "$RELEASE_TAG" \
--title "swift-syntax-prebuilt version $RELEASE_TAG" \
--notes-file release-notes.md \
"${archive_name}.tar.gz" \
"${archive_name}.tar.gz.sha256"
98 changes: 81 additions & 17 deletions .github/workflows/dry-run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,108 @@ on:
branches:
- main

permissions:
contents: read

env:
SWIFT_SYNTAX_VERSION: 602.0.0
XCODE_VERSION: 26.3.0
RULES_SWIFT_VERSION: 3.1.2
MACOS_VERSION: 13.0
SWIFT_VERSION_LINUX: "6.2"

jobs:
dry-run:
build-macos-arm64:
runs-on: macos-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SWIFT_SYNTAX_VERSION: 602.0.0
XCODE_VERSION: 26.3.0
RULES_SWIFT_VERSION: 3.1.2
MACOS_VERSION: 13.0
TARGET_PLATFORM: macos-arm64
steps:
- name: Install brew dependencies
run: |
brew install buildozer
run: brew install buildozer
- name: Select Xcode ${{ env.XCODE_VERSION }}
run: sudo xcode-select -s /Applications/Xcode_${{ env.XCODE_VERSION }}.app
- name: Clone repo
uses: actions/checkout@v4
- name: Clone SwiftSyntax
# $SWIFT_SYNTAX_VERSION via env to dodge Semgrep shell-injection rule.
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh repo clone apple/swift-syntax -- \
--depth 1 \
--branch ${{ env.SWIFT_SYNTAX_VERSION }} \
--branch "$SWIFT_SYNTAX_VERSION" \
--single-branch
- name: Build & Publish SwiftSyntax prebuilt binary
- name: Build SwiftSyntax for macos-arm64
run: ./build.sh build
- name: Upload per-platform staging artifact
uses: actions/upload-artifact@v4
with:
name: staging-macos-arm64
path: staging/macos-arm64.tar.gz
if-no-files-found: error

build-linux-x86_64:
runs-on: ubuntu-latest
env:
TARGET_PLATFORM: linux-x86_64
# rules_swift's Linux toolchain requires clang; ubuntu-latest defaults to gcc.
CC: clang
CXX: clang++
steps:
- name: Install Swift ${{ env.SWIFT_VERSION_LINUX }}
uses: swift-actions/setup-swift@7ca6abe6b3b0e8b5421b88be48feee39cbf52c6a # v2.4.0
with:
swift-version: ${{ env.SWIFT_VERSION_LINUX }}
- name: Install clang + buildozer + jq
run: |
set -euo pipefail
sudo apt-get update
sudo apt-get install -y clang jq
curl -sSL -o /tmp/buildozer \
https://github.com/bazelbuild/buildtools/releases/latest/download/buildozer-linux-amd64
chmod +x /tmp/buildozer
sudo mv /tmp/buildozer /usr/local/bin/buildozer
- name: Clone repo
uses: actions/checkout@v4
- name: Clone SwiftSyntax
# $SWIFT_SYNTAX_VERSION via env to dodge Semgrep shell-injection rule.
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh repo clone apple/swift-syntax -- \
--depth 1 \
--branch "$SWIFT_SYNTAX_VERSION" \
--single-branch
- name: Build SwiftSyntax for linux-x86_64
run: ./build.sh build
- name: Upload per-platform staging artifact
uses: actions/upload-artifact@v4
with:
name: staging-linux-x86_64
path: staging/linux-x86_64.tar.gz
if-no-files-found: error

# Run the build and create the archive
SWIFT_SYNTAX_VERSION=${{ env.SWIFT_SYNTAX_VERSION }} \
RULES_SWIFT_VERSION=${{ env.RULES_SWIFT_VERSION }} \
MACOS_VERSION=${{ env.MACOS_VERSION }} \
./build.sh
- name: Upload SwiftSyntax prebuilt binary
package:
needs:
- build-macos-arm64
- build-linux-x86_64
runs-on: ubuntu-latest
steps:
- name: Clone repo
uses: actions/checkout@v4
- name: Download per-platform staging artifacts
uses: actions/download-artifact@v4
with:
path: staging
pattern: staging-*
merge-multiple: true
- name: Package SwiftSyntax prebuilt archive
run: ./build.sh package
- name: Upload SwiftSyntax prebuilt archive
uses: actions/upload-artifact@v4
with:
name: swift-syntax
path: |
swift-syntax-${{ env.SWIFT_SYNTAX_VERSION }}.tar.gz
swift-syntax-${{ env.SWIFT_SYNTAX_VERSION }}.tar.gz.sha256
if-no-files-found: error

9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
.DS_Store
swift-syntax
swift-syntax-*
swift-syntax-*

# Per-platform build outputs from build.sh build (CI artifacts).
staging/

# Final release archive is produced by build.sh package and published from CI.
swift-syntax-*.tar.gz
swift-syntax-*.tar.gz.sha256
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

This repository is designed to provide pre-built Bazel compatible targets for the [apple/swift-syntax](https://github.com/apple/swift-syntax) repository.

## Supported platforms

Each release ships a single tarball with binary artifacts for multiple platforms; the embedded `BUILD.bazel` selects the right artifacts for the consumer's target via `@platforms//os` + `@platforms//cpu` constraints, so a single `archive_override` works for every supported platform:

- macOS arm64
- Linux x86_64

## Usage

Update your `MODULE.bazel` file to override the `swift-syntax` repository with this one.
Expand All @@ -24,3 +31,25 @@ archive_override(

- File an issue if the version you want is not available.
- Maintainer will run the [build-publish](https://github.com/square/swift-syntax-prebuilt/actions/workflows/build-publish.yml) action.

## Build script (`build.sh`)

`build.sh` runs in two phases so the work can be split across heterogeneous CI runners (macOS for `darwin-*` targets, Linux for `linux-*` targets):

```bash
# Phase 1: build for one platform. Run once per supported TARGET_PLATFORM
# (macos-arm64, linux-x86_64, linux-arm64). Outputs ./staging/<platform>.tar.gz.
SWIFT_SYNTAX_VERSION=602.0.0 \
RULES_SWIFT_VERSION=3.1.2 \
TARGET_PLATFORM=macos-arm64 \
./build.sh build

# Phase 2: combine all per-platform staging tarballs into the final release
# archive. Generates a BUILD.bazel that uses select() over (os, cpu) plus a
# top-level MODULE.bazel.
SWIFT_SYNTAX_VERSION=602.0.0 \
RULES_SWIFT_VERSION=3.1.2 \
./build.sh package
```

The GitHub Actions workflows (`dry-run.yml`, `build-publish.yml`) wire these phases into a fan-out / fan-in pipeline: one build job per platform, then a single packaging job that downloads each platform's staging artifact and produces the released tarball.
Loading
Loading