Skip to content

Commit

Permalink
Merge pull request #20 from xtremekforever/main
Browse files Browse the repository at this point in the history
Add Armv6 support
  • Loading branch information
colemancda authored Jan 13, 2025
2 parents e27e6c3 + c24e548 commit 562ee4f
Show file tree
Hide file tree
Showing 16 changed files with 262 additions and 94 deletions.
8 changes: 6 additions & 2 deletions .github/actions/build-for-distribution/action.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
name: Build Swift for a given armv7 distribution
name: Build Swift for a given distribution
description: This wraps all the functionality of other actions to build Swift for a given distribution
inputs:
swift-tag:
description: The Swift tag version that is being built
required: true
swift-target-arch:
description: The target architecture to build Swift for (e.g., armv6 or armv7)
required: true
swift-workspace-cache:
description: The name of the Swift workspace directory to restore
required: true
Expand All @@ -27,6 +30,7 @@ runs:
name: Build Swift + SDK using Sysroot
with:
swift-tag: ${{ inputs.swift-tag }}
sysroot-name: sysroot-${{ inputs.distribution }}-armv7
sysroot-name: sysroot-${{ inputs.distribution }}
swift-target-arch: ${{ inputs.swift-target-arch }}
distribution: ${{ inputs.distribution }}
builder-tag: ${{ inputs.builder-tag }}
38 changes: 29 additions & 9 deletions .github/actions/build-with-sysroot/action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build Swift with a provided armv7 sysroot for a given sysroot
name: Build Swift with a provided sysroot and for a target architecture
description: This contains the functionality to build/restore a sysroot, build Swift, and build an SDK
inputs:
swift-tag:
Expand All @@ -7,6 +7,9 @@ inputs:
sysroot-name:
description: The name of the sysroot to use to build Swift
required: true
swift-target-arch:
description: The target architecture to build Swift for (e.g., armv6 or armv7)
required: true
distribution:
description: The name of the distribution to build for
required: true
Expand All @@ -16,33 +19,50 @@ inputs:
runs:
using: "composite"
steps:
- name: Build
- name: Restore Sysroot
id: restore-sysroot
uses: actions/cache/restore@v4
with:
key: ${{ inputs.sysroot-name }}
path: ${{ inputs.sysroot-name }}
- if: ${{ steps.restore-sysroot.outputs.cache-hit != 'true' }}
name: Build Sysroot
shell: bash
env:
DISTRIBUTION: ${{ inputs.distribution }}
run: ./build-sysroot.sh $(echo ${DISTRIBUTION/-/:}) ${{ inputs.sysroot-name }}
run: ./build-sysroot.sh $(echo ${DISTRIBUTION/-/ }) ${{ inputs.sysroot-name }}
- name: Compress
shell: bash
run: tar -czf ${{ inputs.sysroot-name }}.tar.gz ${{ inputs.sysroot-name }}
- name: Cache Sysroot
id: cache-sysroot
if: steps.restore-sysroot.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
key: ${{ inputs.sysroot-name }}
path: ${{ inputs.sysroot-name }}
- name: Build Swift
shell: bash
run: |
docker run --rm --user runner --workdir ${{ github.workspace }} -v $HOME:$HOME \
-e SWIFT_VERSION=${{ inputs.swift-tag }} \
-e INSTALL_TAR=$(pwd)/${{ inputs.swift-tag }}-${{ inputs.distribution }}-armv7-install.tar.gz \
-e INSTALL_TAR=$(pwd)/${{ inputs.swift-tag }}-${{ inputs.distribution }}-${{ inputs.swift-target-arch }}-install.tar.gz \
-e STAGING_DIR=$(pwd)/${{ inputs.sysroot-name }} \
-e SWIFT_TARGET_ARCH=${{ inputs.swift-target-arch }} \
-e SKIP_FETCH_SOURCES=1 \
xtremekforever/swift-builder:${{ inputs.builder-tag }} \
/bin/bash ./build.sh
- name: Build SDK for Linux
shell: bash
run: |
INSTALLABLE_SDK_PACKAGE=$(pwd)/${{ inputs.swift-tag }}-${{ inputs.distribution }}-armv7-sdk.tar.gz SYSROOT=${{ inputs.sysroot-name }} \
INSTALLABLE_SDK_PACKAGE=$(pwd)/${{ inputs.swift-tag }}-${{ inputs.distribution }}-${{ inputs.swift-target-arch }}-sdk.tar.gz \
SYSROOT=${{ inputs.sysroot-name }} \
TARGET_ARCH=${{ inputs.swift-target-arch }} \
./build-linux-cross-sdk.sh ${{ inputs.swift-tag }} ${{ inputs.distribution }}
- name: Test SDK for Linux
shell: bash
env:
SDK_NAME: ${{ inputs.swift-tag }}-${{ inputs.distribution }}-armv7
SDK_NAME: ${{ inputs.swift-tag }}-${{ inputs.distribution }}-${{ inputs.swift-target-arch }}
run: |
docker run --rm --user runner --workdir ${{ github.workspace }} -v $HOME:$HOME -v ${{ github.workspace }}/artifacts:/opt \
xtremekforever/swift-builder:${{ inputs.builder-tag }} \
Expand All @@ -54,8 +74,8 @@ runs:
- uses: actions/upload-artifact@v4
name: Publish
with:
name: ${{ inputs.swift-tag }}-${{ inputs.distribution }}-armv7
name: ${{ inputs.swift-tag }}-${{ inputs.distribution }}-${{ inputs.swift-target-arch }}
path: |
${{ inputs.sysroot-name }}.tar.gz
${{ inputs.swift-tag }}*-armv7-install.tar.gz
${{ inputs.swift-tag }}*-armv7-sdk.tar.gz
${{ inputs.swift-tag }}*-${{ inputs.swift-target-arch }}-install.tar.gz
${{ inputs.swift-tag }}*-${{ inputs.swift-target-arch }}-sdk.tar.gz
6 changes: 2 additions & 4 deletions .github/actions/checkout-swift/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ runs:
with:
key: ${{ inputs.swift-workspace-cache }}
path: downloads
- if: ${{ steps.restore-workspace.outputs.cache-hit != 'true' }}
name: Checkout Sources
- name: Checkout Sources
shell: bash
run: SWIFT_VERSION=${{ inputs.swift-tag }} ./fetch-sources.sh
- if: ${{ steps.restore-workspace.outputs.cache-hit != 'true' }}
uses: actions/cache/save@v4
- uses: actions/cache/save@v4
with:
key: ${{ inputs.swift-workspace-cache }}
path: downloads
24 changes: 12 additions & 12 deletions .github/workflows/build-swift-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,34 @@ on:
pull_request:
branches: [ "main" ]

env:
DISTRIBUTION: debian-bookworm

jobs:
build-latest:
strategy:
matrix:
version: ["6.0.3"]
swift-target-arch: ["armv7"]
distribution: ["debian-bookworm"]
include:
- swift-target-arch: "armv6"
distribution: "raspios-bookworm"
env:
SWIFT_VERSION: ${{ matrix.version }}
SWIFT_TAG: swift-${{ matrix.version }}-RELEASE
SWIFT_VERSION: "6.0.3"
SWIFT_TAG: swift-6.0.3-RELEASE
name: Build Swift
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/checkout-swift
name: Fetch Swift Sources
name: Fetch Swift ${{ env.SWIFT_TAG }}
with:
swift-tag: ${{ env.SWIFT_TAG }}
swift-workspace-cache: swift-workspace
- name: Generate Builder Container
shell: bash
run: |
source ./swift-builder/swift-builder-common
./swift-builder/build-container.sh
run: ./swift-builder/build-container.sh
- uses: ./.github/actions/build-for-distribution
name: Build & Publish Swift
name: Build & Publish Swift ${{ env.SWIFT_VERSION }}
with:
swift-tag: ${{ env.SWIFT_TAG }}
distribution: ${{ env.DISTRIBUTION }}
swift-target-arch: ${{ matrix.swift-target-arch }}
distribution: ${{ matrix.distribution }}
builder-tag: ${{ env.SWIFT_VERSION }}
5 changes: 2 additions & 3 deletions .github/workflows/build-swift-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ jobs:
swift-workspace-cache: ${{ env.SWIFT_WORKSPACE_CACHE }}
- name: Build Swift Nightly Container
shell: bash
run: |
source ./swift-builder/swift-builder-common
./swift-builder/build-container.sh
run: ./swift-builder/build-container.sh
- uses: ./.github/actions/build-for-distribution
name: Build & Publish Swift
with:
swift-tag: ${{ env.SWIFT_TAG }}
swift-target-arch: armv7
distribution: ${{ env.DISTRIBUTION }}
builder-tag: ${{ env.SWIFT_VERSION }}
52 changes: 44 additions & 8 deletions .github/workflows/build-swift-release.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: Build Swift Release

on:
release:
types: [published]
push:
branches: [ "release/6.0.3" ]

env:
SWIFT_VERSION: ${{ github.event.release.tag_name }}
SWIFT_TAG: swift-${{ github.event.release.tag_name }}-RELEASE
SWIFT_VERSION: "6.0.3"
SWIFT_TAG: swift-6.0.3-RELEASE
SWIFT_WORKSPACE_CACHE: swift-workspace

jobs:
Expand All @@ -31,7 +31,42 @@ jobs:
"ubuntu-jammy",
"ubuntu-noble"
]
name: Build Swift
name: Build for armv7
runs-on: ubuntu-latest
needs: [fetch-sources]
steps:
- uses: actions/checkout@v4
- name: Generate Builder Container
shell: bash
run: ./swift-builder/build-container.sh
- uses: ./.github/actions/build-for-distribution
name: "Build & Publish Swift ${{ env.SWIFT_VERSION }}"
with:
swift-tag: ${{ env.SWIFT_TAG }}
swift-workspace-cache: ${{ env.SWIFT_WORKSPACE_CACHE }}
swift-target-arch: armv7
distribution: ${{ matrix.distribution }}
builder-tag: ${{ env.SWIFT_VERSION }}
- name: Update Release ${{ env.SWIFT_VERSION }}
uses: ncipollo/release-action@v1
with:
allowUpdates: true
name: Swift ${{ env.SWIFT_VERSION }} for armhf
tag: ${{ env.SWIFT_VERSION }}
commit: ${{ github.sha }}
artifactErrorsFailBuild: true
artifacts: "*.tar.gz"
body: "See the [README](https://github.com/xtremekforever/swift-armv7#continuous-integration) for more information on build artifacts."

build-for-raspios:
strategy:
matrix:
distribution-version: [
"bullseye",
"bookworm"
]
swift-target-arch: ["armv6", "armv7"]
name: Build for RaspiOS
runs-on: ubuntu-latest
needs: [fetch-sources]
steps:
Expand All @@ -46,15 +81,16 @@ jobs:
with:
swift-tag: ${{ env.SWIFT_TAG }}
swift-workspace-cache: ${{ env.SWIFT_WORKSPACE_CACHE }}
distribution: ${{ matrix.distribution }}
swift-target-arch: ${{ matrix.swift-target-arch }}
distribution: raspios-${{ matrix.distribution-version }}
builder-tag: ${{ env.SWIFT_VERSION }}
- name: Update Release ${{ env.SWIFT_VERSION }}
uses: ncipollo/release-action@v1
with:
allowUpdates: true
name: Swift ${{ env.SWIFT_VERSION }} for armv7
name: Swift ${{ env.SWIFT_VERSION }} for armhf
tag: ${{ env.SWIFT_VERSION }}
commit: ${{ github.sha }}
artifactErrorsFailBuild: true
artifactErrorsFailBuild: false
artifacts: "*.tar.gz"
body: "See the [README](https://github.com/xtremekforever/swift-armv7#continuous-integration) for more information on build artifacts."
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Some main goals:
- Provide SDKs that can be downloaded and used to cross-compile user applications and libraries to armv7.
- Maintain a CI that can build snapshots/nightly versions of Swift to find and fix issues.

NOTE: Building for armv6 is also now supported, although it is limited to working with the `raspios`
distribution since that is the only version of Debian that supports the ARMv6 architecture. However,
this makes this project also compatible with older Raspberry Pi models such as the RPI 1, Zero, and so on.

## Compilation

There are various options for compiling Swift for armv7 with these scripts.
Expand Down
2 changes: 1 addition & 1 deletion build-dispatch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ echo "Install Dispatch"
(cd $LIBDISPATCH_BUILDDIR && ninja install)

echo "Install Dispatch to sysroot"
mv ${LIBDISPATCH_INSTALL_PREFIX}/lib/swift/linux/"$(uname -m)"/ ${LIBDISPATCH_INSTALL_PREFIX}/lib/swift/linux/armv7/
mv ${LIBDISPATCH_INSTALL_PREFIX}/lib/swift/linux/"$(uname -m)"/ ${LIBDISPATCH_INSTALL_PREFIX}/lib/swift/linux/${SWIFT_TARGET_ARCH}/
cp -rf ${LIBDISPATCH_INSTALL_PREFIX}/* ${STAGING_DIR}/usr/
7 changes: 4 additions & 3 deletions build-foundation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ echo "Install Foundation"
(cd $FOUNDATION_BUILDDIR && ninja install)

echo "Fix-up archs"
find ${FOUNDATION_INSTALL_PREFIX}/lib/swift/linux -name "x86_64*.swiftmodule" -execdir mv {} armv7-unknown-linux-gnueabihf.swiftmodule \;
find ${FOUNDATION_INSTALL_PREFIX}/lib/swift/linux -name "x86_64*.swiftdoc" -execdir mv {} armv7-unknown-linux-gnueabihf.swiftdoc \;
HOST_ARCH=$(uname -m)
find ${FOUNDATION_INSTALL_PREFIX}/lib/swift/linux -name "${HOST_ARCH}*.swiftmodule" -execdir mv {} ${SWIFT_TARGET_ARCH}-unknown-linux-gnueabihf.swiftmodule \;
find ${FOUNDATION_INSTALL_PREFIX}/lib/swift/linux -name "${HOST_ARCH}*.swiftdoc" -execdir mv {} ${SWIFT_TARGET_ARCH}-unknown-linux-gnueabihf.swiftdoc \;

# Restore Dispatch headers
cp -rf ${LIBDISPATCH_INSTALL_PREFIX}/* ${STAGING_DIR}/usr/

echo "Install Foundation into sysroot"
FOUNDATION_MODULES_DIR=${FOUNDATION_INSTALL_PREFIX}/lib/swift/linux/"$(uname -m)"
if [ -d $FOUNDATION_MODULES_DIR ]; then
mv ${FOUNDATION_MODULES_DIR} ${FOUNDATION_INSTALL_PREFIX}/lib/swift/linux/armv7
mv ${FOUNDATION_MODULES_DIR} ${FOUNDATION_INSTALL_PREFIX}/lib/swift/linux/${SWIFT_TARGET_ARCH}
fi
cp -rf ${FOUNDATION_INSTALL_PREFIX}/* ${STAGING_DIR}/usr/
2 changes: 2 additions & 0 deletions build-in-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ docker run \
-e SWIFT_VERSION=${SWIFT_TAG} \
-e STAGING_DIR=${STAGING_DIR} \
-e INSTALL_TAR=${INSTALL_TAG} \
-e SKIP_FETCH_SOURCES=${SKIP_FETCH_SOURCES} \
-e SWIFT_TARGET_ARCH=${SWIFT_TARGET_ARCH} \
${DOCKER_TAG} \
./build.sh
4 changes: 2 additions & 2 deletions build-linux-cross-sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ set -e

SRC_ROOT=$(pwd)
ARTIFACTS_DIR=$SRC_ROOT/artifacts
TARGET_TRIPLE=armv7-unknown-linux-gnueabihf
TARGET_ARCH=armv7
TARGET_ARCH=${TARGET_ARCH:=armv7}
TARGET_TRIPLE=${TARGET_ARCH}-unknown-linux-gnueabihf

function print_usage() {
echo "$0 <swift-tag> <distribution>"
Expand Down
4 changes: 2 additions & 2 deletions build-swift-testing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ echo "Install swift-testing"
(cd $SWIFT_TESTING_BUILDDIR && ninja install)

echo "Fix-up archs"
find ${SWIFT_TESTING_INSTALL_PREFIX}/lib/swift/linux -name "x86_64*.swiftmodule" -execdir mv {} armv7-unknown-linux-gnueabihf.swiftmodule \;
find ${SWIFT_TESTING_INSTALL_PREFIX}/lib/swift/linux -name "x86_64*.swiftdoc" -execdir mv {} armv7-unknown-linux-gnueabihf.swiftdoc \;
find ${SWIFT_TESTING_INSTALL_PREFIX}/lib/swift/linux -name "x86_64*.swiftmodule" -execdir mv {} ${SWIFT_TARGET_ARCH}-unknown-linux-gnueabihf.swiftmodule \;
find ${SWIFT_TESTING_INSTALL_PREFIX}/lib/swift/linux -name "x86_64*.swiftdoc" -execdir mv {} ${SWIFT_TARGET_ARCH}-unknown-linux-gnueabihf.swiftdoc \;

echo "Install swift-testing to sysroot"
cp -rf ${SWIFT_TESTING_INSTALL_PREFIX}/* ${STAGING_DIR}/usr/
Loading

0 comments on commit 562ee4f

Please sign in to comment.