Skip to content

Handle pre-built frameworks in universal binary build #20

Handle pre-built frameworks in universal binary build

Handle pre-built frameworks in universal binary build #20

Workflow file for this run

name: Build and Release
on:
push:
branches:
- main
paths:
- 'Sources/SwiftMacPackage/main.swift'
- '.github/workflows/release.yml'
jobs:
check-version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get-version.outputs.version }}
version-changed: ${{ steps.check-tag.outputs.changed }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get version from main.swift
id: get-version
run: |
VERSION=$(grep 'let version = ' Sources/SwiftMacPackage/main.swift | sed 's/.*"\(.*\)".*/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Found version: $VERSION"
- name: Check if version tag exists
id: check-tag
run: |
VERSION="${{ steps.get-version.outputs.version }}"
if git rev-parse "v$VERSION" >/dev/null 2>&1; then
echo "changed=false" >> $GITHUB_OUTPUT
echo "Tag v$VERSION already exists"
else
echo "changed=true" >> $GITHUB_OUTPUT
echo "Tag v$VERSION does not exist - will create release"
fi
build-and-release:
needs: check-version
if: needs.check-version.outputs.version-changed == 'true'
runs-on: macos-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Swift
uses: swift-actions/setup-swift@v2
- name: Build for Apple Silicon (arm64)
run: |
echo "Building for Apple Silicon (arm64)..."
swift build --configuration release --arch arm64
mkdir -p build-artifacts/arm64
cp .build/release/swiftmac build-artifacts/arm64/
cp -r .build/release/ogg.framework build-artifacts/arm64/
cp -r .build/release/vorbis.framework build-artifacts/arm64/
echo "Saved arm64 build artifacts"
file build-artifacts/arm64/swiftmac
- name: Clean build directory
run: |
echo "Cleaning build directory..."
rm -rf .build
- name: Build for Intel (x86_64)
run: |
echo "Building for Intel (x86_64)..."
swift build --configuration release --arch x86_64
mkdir -p build-artifacts/x86_64
cp .build/release/swiftmac build-artifacts/x86_64/
cp -r .build/release/ogg.framework build-artifacts/x86_64/
cp -r .build/release/vorbis.framework build-artifacts/x86_64/
echo "Saved x86_64 build artifacts"
file build-artifacts/x86_64/swiftmac
- name: Create Universal Binary
run: |
echo "Creating universal binary..."
# Verify source binaries
echo "ARM64 binary:"
file build-artifacts/arm64/swiftmac
lipo -info build-artifacts/arm64/swiftmac
echo "x86_64 binary:"
file build-artifacts/x86_64/swiftmac
lipo -info build-artifacts/x86_64/swiftmac
# Create universal binary for swiftmac executable
lipo -create \
build-artifacts/arm64/swiftmac \
build-artifacts/x86_64/swiftmac \
-output swiftmac-universal
# Verify it's universal
echo "Universal binary:"
file swiftmac-universal
lipo -info swiftmac-universal
# Check framework architectures
mkdir -p universal-frameworks
echo ""
echo "Checking ogg.framework architectures..."
echo "ARM64 version:"
lipo -info build-artifacts/arm64/ogg.framework/ogg || true
echo "x86_64 version:"
lipo -info build-artifacts/x86_64/ogg.framework/ogg || true
# Handle ogg framework - check if architectures differ
ARM_OGG_ARCH=$(lipo -info build-artifacts/arm64/ogg.framework/ogg 2>&1 | grep -o 'arm64\|x86_64' | head -1)
X86_OGG_ARCH=$(lipo -info build-artifacts/x86_64/ogg.framework/ogg 2>&1 | grep -o 'arm64\|x86_64' | head -1)
if [ "$ARM_OGG_ARCH" = "$X86_OGG_ARCH" ]; then
echo "ogg.framework has same architecture in both builds, using as-is"
cp -r build-artifacts/arm64/ogg.framework universal-frameworks/
else
echo "Creating universal ogg.framework"
cp -r build-artifacts/arm64/ogg.framework universal-frameworks/
lipo -create \
build-artifacts/arm64/ogg.framework/ogg \
build-artifacts/x86_64/ogg.framework/ogg \
-output universal-frameworks/ogg.framework/ogg
fi
echo ""
echo "Checking vorbis.framework architectures..."
echo "ARM64 version:"
lipo -info build-artifacts/arm64/vorbis.framework/vorbis || true
echo "x86_64 version:"
lipo -info build-artifacts/x86_64/vorbis.framework/vorbis || true
# Handle vorbis framework - check if architectures differ
ARM_VORBIS_ARCH=$(lipo -info build-artifacts/arm64/vorbis.framework/vorbis 2>&1 | grep -o 'arm64\|x86_64' | head -1)
X86_VORBIS_ARCH=$(lipo -info build-artifacts/x86_64/vorbis.framework/vorbis 2>&1 | grep -o 'arm64\|x86_64' | head -1)
if [ "$ARM_VORBIS_ARCH" = "$X86_VORBIS_ARCH" ]; then
echo "vorbis.framework has same architecture in both builds, using as-is"
cp -r build-artifacts/arm64/vorbis.framework universal-frameworks/
else
echo "Creating universal vorbis.framework"
cp -r build-artifacts/arm64/vorbis.framework universal-frameworks/
lipo -create \
build-artifacts/arm64/vorbis.framework/vorbis \
build-artifacts/x86_64/vorbis.framework/vorbis \
-output universal-frameworks/vorbis.framework/vorbis
fi
# Verify final frameworks
echo ""
echo "Final framework architectures:"
lipo -info universal-frameworks/ogg.framework/ogg
lipo -info universal-frameworks/vorbis.framework/vorbis
- name: Create release archive
run: |
VERSION="${{ needs.check-version.outputs.version }}"
echo "Building swiftmac version $VERSION (Universal Binary)"
# Create release directory
mkdir -p swiftmac
# Copy universal binary and frameworks
cp swiftmac-universal swiftmac/swiftmac
cp -rf universal-frameworks/ogg.framework swiftmac/
cp -rf universal-frameworks/vorbis.framework swiftmac/
# Copy support files
cp swiftmac-voices.el swiftmac/
cp cloud-swiftmac swiftmac/
cp log-swiftmac swiftmac/
# Copy documentation
cp LICENSE swiftmac/
cp Readme.org swiftmac/
cp Readme.emacspeak.org swiftmac/
# Create tarball
tar -czf swiftmac-$VERSION.tar.gz swiftmac
echo "Release archive created: swiftmac-$VERSION.tar.gz"
ls -lh swiftmac-$VERSION.tar.gz
shell: bash
- name: Create Git tag
run: |
VERSION="${{ needs.check-version.outputs.version }}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "v$VERSION" -m "Release version $VERSION"
git push origin "v$VERSION"
- name: Extract changelog
id: changelog
run: |
VERSION="${{ needs.check-version.outputs.version }}"
# Get commits since last tag
LAST_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -z "$LAST_TAG" ]; then
CHANGES=$(git log --pretty=format:"- %s" -10)
else
CHANGES=$(git log --pretty=format:"- %s" ${LAST_TAG}..HEAD)
fi
# Save to file for multiline output
echo "$CHANGES" > CHANGELOG.txt
echo "Extracted changelog for release"
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.check-version.outputs.version }}
name: SwiftMac ${{ needs.check-version.outputs.version }}
body_path: CHANGELOG.txt
files: |
swiftmac-${{ needs.check-version.outputs.version }}.tar.gz
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update latest release symlink
run: |
VERSION="${{ needs.check-version.outputs.version }}"
echo "Released SwiftMac version $VERSION"
echo "Download: https://github.com/robertmeta/swiftmac/releases/download/v$VERSION/swiftmac-$VERSION.tar.gz"