diff --git a/.github/actions/build-for-distribution/action.yml b/.github/actions/build-for-distribution/action.yml index 13d1c0e..4dcf4ea 100644 --- a/.github/actions/build-for-distribution/action.yml +++ b/.github/actions/build-for-distribution/action.yml @@ -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 @@ -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 }} diff --git a/.github/actions/build-with-sysroot/action.yml b/.github/actions/build-with-sysroot/action.yml index 7bc23a3..df6e475 100644 --- a/.github/actions/build-with-sysroot/action.yml +++ b/.github/actions/build-with-sysroot/action.yml @@ -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: @@ -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 @@ -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 }} \ @@ -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 diff --git a/.github/actions/checkout-swift/action.yml b/.github/actions/checkout-swift/action.yml index 5664d8f..64e9663 100644 --- a/.github/actions/checkout-swift/action.yml +++ b/.github/actions/checkout-swift/action.yml @@ -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 diff --git a/.github/workflows/build-swift-latest.yml b/.github/workflows/build-swift-latest.yml index e9ba708..a1f19b1 100644 --- a/.github/workflows/build-swift-latest.yml +++ b/.github/workflows/build-swift-latest.yml @@ -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 }} diff --git a/.github/workflows/build-swift-nightly.yml b/.github/workflows/build-swift-nightly.yml index 00ebb5a..81c7e23 100644 --- a/.github/workflows/build-swift-nightly.yml +++ b/.github/workflows/build-swift-nightly.yml @@ -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 }} diff --git a/.github/workflows/build-swift-release.yml b/.github/workflows/build-swift-release.yml index bc791ce..6039b71 100644 --- a/.github/workflows/build-swift-release.yml +++ b/.github/workflows/build-swift-release.yml @@ -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: @@ -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: @@ -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." diff --git a/README.md b/README.md index ee66d96..4eff208 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/build-dispatch.sh b/build-dispatch.sh index aa9f58a..dd497f6 100755 --- a/build-dispatch.sh +++ b/build-dispatch.sh @@ -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/ diff --git a/build-foundation.sh b/build-foundation.sh index 114c892..abcd600 100755 --- a/build-foundation.sh +++ b/build-foundation.sh @@ -49,8 +49,9 @@ 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/ @@ -58,6 +59,6 @@ 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/ diff --git a/build-in-container.sh b/build-in-container.sh index 29238ff..6d0569c 100755 --- a/build-in-container.sh +++ b/build-in-container.sh @@ -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 diff --git a/build-linux-cross-sdk.sh b/build-linux-cross-sdk.sh index 81761bb..a274c0c 100755 --- a/build-linux-cross-sdk.sh +++ b/build-linux-cross-sdk.sh @@ -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 " diff --git a/build-swift-testing.sh b/build-swift-testing.sh index 07e329b..c30e52c 100755 --- a/build-swift-testing.sh +++ b/build-swift-testing.sh @@ -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/ diff --git a/build-sysroot.sh b/build-sysroot.sh index 5951478..411133f 100755 --- a/build-sysroot.sh +++ b/build-sysroot.sh @@ -4,16 +4,19 @@ set -e SRC_ROOT=$(pwd) -CONTAINER_NAME=swift-armv7-sysroot -DISTRIUBTION=$1 -SYSROOT=$2 +DISTRIBUTION_NAME=$1 +DISTRIUBTION_VERSION=$2 +SYSROOT=$3 if [ -z $SYSROOT ]; then - SYSROOT=sysroot-$(echo "$DISTRIUBTION" | tr : -) + SYSROOT=sysroot-$DISTRIBUTION_NAME-$DISTRIUBTION_VERSION fi +SYSROOT=$(pwd)/$SYSROOT -case $DISTRIUBTION in - ubuntu:focal) +DISTRIBUTION="$DISTRIBUTION_NAME:$DISTRIUBTION_VERSION" + +case $DISTRIUBTION_VERSION in + "focal") INSTALL_DEPS_CMD=" \ apt-get update && \ apt-get install -y \ @@ -29,7 +32,9 @@ case $DISTRIUBTION in libsystemd-dev \ " ;; - "debian:bullseye") + "bullseye") + RASPIOS_VERSION="2024-10-22" + RASPIOS_URL=https://downloads.raspberrypi.com/raspios_oldstable_lite_armhf/images/raspios_oldstable_lite_armhf-2024-10-28 INSTALL_DEPS_CMD=" \ apt-get update && \ apt-get install -y \ @@ -45,7 +50,9 @@ case $DISTRIUBTION in libsystemd-dev \ " ;; - "ubuntu:jammy" | "debian:bookworm") + "jammy" | "bookworm") + RASPIOS_VERSION="2024-11-19" + RASPIOS_URL=https://downloads.raspberrypi.com/raspios_lite_armhf/images/raspios_lite_armhf-$RASPIOS_VERSION INSTALL_DEPS_CMD=" \ apt-get update && \ apt-get install -y \ @@ -61,7 +68,7 @@ case $DISTRIUBTION in libsystemd-dev \ " ;; - "ubuntu:mantic" | "ubuntu:noble") + "mantic" | "noble") INSTALL_DEPS_CMD=" \ apt-get update && \ apt-get install -y \ @@ -84,40 +91,116 @@ case $DISTRIUBTION in ;; esac +if [[ $DISTRIBUTION_NAME = "raspios" ]]; then + INSTALL_DEPS_CMD="$INSTALL_DEPS_CMD symlinks" +fi + if [ ! -z $EXTRA_PACKAGES ]; then echo "Including extra packages: $EXTRA_PACKAGES" INSTALL_DEPS_CMD="$INSTALL_DEPS_CMD && apt-get install -y $EXTRA_PACKAGES" fi -echo "Starting up qemu emulation" -docker run --privileged --rm tonistiigi/binfmt --install all - -echo "Building $DISTRIUBTION distribution for sysroot" -docker rm --force $CONTAINER_NAME -docker run \ - --platform linux/arm/v7 \ - --name $CONTAINER_NAME \ - $DISTRIUBTION \ - /bin/bash -c "$INSTALL_DEPS_CMD" - -echo "Extracting sysroot folders to $SYSROOT" -rm -rf $SYSROOT -mkdir -p $SYSROOT/usr -docker cp $CONTAINER_NAME:/lib $SYSROOT/lib -docker cp $CONTAINER_NAME:/usr/lib $SYSROOT/usr/lib -docker cp $CONTAINER_NAME:/usr/include $SYSROOT/usr/include - -# Find broken links, re-copy -cd $SYSROOT -BROKEN_LINKS=$(find . -xtype l) -while IFS= read -r link; do - # Ignore empty links - if [ -z "${link}" ]; then continue; fi - - echo "Replacing broken symlink: $link" - link=$(echo $link | sed '0,/./ s/.//') - docker cp -L $CONTAINER_NAME:$link $(dirname .$link) -done <<< "$BROKEN_LINKS" - -echo "Cleaning up" -docker rm $CONTAINER_NAME +# This is for supporting armv6 +if [[ $DISTRIBUTION_NAME = "raspios" ]]; then + echo "Installing host dependencies..." + sudo apt update && sudo apt install qemu-user-static p7zip xz-utils + + mkdir artifacts && true + cd artifacts + + echo "Downloading raspios $RASPIOS_VERSION for $DISTRIUBTION_VERSION..." + IMAGE_FILE=$RASPIOS_VERSION-raspios-$DISTRIUBTION_VERSION-armhf-lite.img + DOWNLOAD_URL=$RASPIOS_URL/$IMAGE_FILE.xz + wget -q -N $DOWNLOAD_URL + + if [ ! -f $IMAGE_FILE ]; then + echo "Uncompressing $IMAGE_FILE.gz and extracting contents..." + xz -dk $IMAGE_FILE.xz && true + fi + 7z e -y $IMAGE_FILE + + echo "Mounting 1.img and needed passthroughs..." + sudo umount -R sysroot && true + rm -rf sysroot && mkdir sysroot + sudo mount -o loop 1.img sysroot + sudo mount --bind /dev sysroot/dev + sudo mount --bind /dev/pts sysroot/dev/pts + sudo mount --bind /proc sysroot/proc + sudo mount --bind /sys sysroot/sys + + echo "Starting chroot to update dependencies & fix symlinks..." + REMOVE_DEPS_CMD="apt-get remove -y --purge \ + apparmor \ + bluez \ + network-manager \ + linux-image* \ + *firmware* \ + openssh* \ + p7zip* \ + perl \ + perl-modules* \ + raspi* \ + rpi* \ + libqt5core5a \ + " + sudo cp /usr/bin/qemu-arm-static sysroot/usr/bin + sudo chroot sysroot qemu-arm-static /bin/bash -c "$REMOVE_DEPS_CMD && $INSTALL_DEPS_CMD && apt-get autoremove -y" + sudo chroot sysroot qemu-arm-static /bin/bash -c "apt list --installed && symlinks -cr /usr/include && symlinks -cr /usr/lib" + + echo "Copying files from sysroot to $SYSROOT..." + rm -rf $SYSROOT + mkdir -p $SYSROOT/usr/lib + cp -r sysroot/lib $SYSROOT/lib + cp -r sysroot/usr/include $SYSROOT/usr/include + cp -r sysroot/usr/lib/ld-linux-armhf.so.3 $SYSROOT/usr/lib/ + cp -r sysroot/usr/lib/os-release $SYSROOT/usr/lib/ + cp -r sysroot/usr/lib/arm-linux-gnueabihf $SYSROOT/usr/lib/ + cp -r sysroot/usr/lib/linux $SYSROOT/usr/lib/ && true + cp -r sysroot/usr/lib/gcc $SYSROOT/usr/lib/ + + # Cleanup + rm -rf $SYSROOT/usr/include/aarch64-linux-gnu + rm -rf $SYSROOT/usr/lib/gcc/arm-linux-gnueabihf/7 + rm -rf $SYSROOT/usr/lib/gcc/arm-linux-gnueabihf/7.5.0 + rm -rf $SYSROOT/usr/lib/gcc/arm-linux-gnueabihf/8 + + echo "Umounting and cleaning up..." + sudo umount -R sysroot + rm -f *.fat + rm -f *.img +else + echo "Starting up qemu emulation" + docker run --privileged --rm tonistiigi/binfmt --install all + + CONTAINER_NAME=swift-armhf-sysroot + + echo "Building $DISTRIBUTION distribution for sysroot" + docker rm --force $CONTAINER_NAME + docker run \ + --platform linux/armhf \ + --name $CONTAINER_NAME \ + $DISTRIBUTION \ + /bin/bash -c "$INSTALL_DEPS_CMD" + + echo "Extracting sysroot folders to $SYSROOT" + rm -rf $SYSROOT + mkdir -p $SYSROOT/usr + docker cp $CONTAINER_NAME:/lib $SYSROOT/lib + docker cp $CONTAINER_NAME:/usr/include $SYSROOT/usr/include + docker cp $CONTAINER_NAME:/usr/lib $SYSROOT/usr/lib + + # Find broken links, re-copy + cd $SYSROOT + BROKEN_LINKS=$(find . -xtype l) + while IFS= read -r link; do + # Ignore empty links + if [ -z "${link}" ]; then continue; fi + + echo "Replacing broken symlink: $link" + link=$(echo $link | sed '0,/./ s/.//') + docker cp -L $CONTAINER_NAME:$link $(dirname .$link) + done <<< "$BROKEN_LINKS" + + echo "Cleaning up" + docker rm $CONTAINER_NAME +fi diff --git a/build-xctest.sh b/build-xctest.sh index 2b814e3..ca35ff1 100755 --- a/build-xctest.sh +++ b/build-xctest.sh @@ -41,5 +41,5 @@ echo "Install XCTest" cp -rf ${LIBDISPATCH_INSTALL_PREFIX}/* ${STAGING_DIR}/usr/ echo "Install XCTest to sysroot" -mv ${XCTEST_INSTALL_PREFIX}/lib/swift/linux/"$(uname -m)" ${XCTEST_INSTALL_PREFIX}/lib/swift/linux/armv7 +mv ${XCTEST_INSTALL_PREFIX}/lib/swift/linux/"$(uname -m)" ${XCTEST_INSTALL_PREFIX}/lib/swift/linux/${SWIFT_TARGET_ARCH} cp -rf ${XCTEST_INSTALL_PREFIX}/* ${STAGING_DIR}/usr/ diff --git a/fetch-sources.sh b/fetch-sources.sh index 69ab591..65f8ce0 100755 --- a/fetch-sources.sh +++ b/fetch-sources.sh @@ -7,6 +7,9 @@ mkdir -p ./downloads # Fetch sources cd ./downloads if [[ -d "$SWIFT_SRCDIR" ]]; then + cd swift-corelibs-foundation + git stash + echo "$SWIFT_SRCDIR exists" cd $SWIFT_SRCDIR git stash @@ -67,6 +70,5 @@ patch -d . -p1 <$SRC_ROOT/patches/0001-Swift-fix-find-libstdc++-for-cxx-interop. if [[ $SWIFT_VERSION == *"5.9"* ]]; then echo "Apply Foundation strlcpy/strlcat patch for Swift 5.9" cd ../swift-corelibs-foundation - git stash patch -d . -p1 <$SRC_ROOT/patches/0002-Foundation-5.9-check-for-strlcpy-strlcat.patch fi diff --git a/swift-define b/swift-define index 9ae5478..c8a98f8 100644 --- a/swift-define +++ b/swift-define @@ -1,7 +1,22 @@ # Version SWIFT_VERSION=${SWIFT_VERSION:=swift-6.0.3-RELEASE} -SWIFT_TARGET_ARCH=armv7 -SWIFT_TARGET_NAME=armv7-unknown-linux-gnueabihf +SWIFT_TARGET_ARCH=${SWIFT_TARGET_ARCH:=armv7} + +case ${SWIFT_TARGET_ARCH} in + armv6) + # The only version of armv6 supported is the RPI ARM1176JZF-S, which is only supported by Raspbian + # If you attempt to build for armv6 with a Ubuntu or Debian sysroot, binaries will fail to run!!! + EXTRA_FLAGS="-march=armv6z -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard" + ;; + armv7) + EXTRA_FLAGS="-march=armv7-a -mfpu=neon -mfloat-abi=hard" + ;; + *) + echo "Unsupported architecture $SWIFT_TARGET_ARCH!" + exit -1 + ;; +esac +SWIFT_TARGET_NAME=${SWIFT_TARGET_ARCH}-unknown-linux-gnueabihf # Configurable SRC_ROOT="${SRC_ROOT:=$(pwd)}" @@ -17,6 +32,11 @@ SWIFT_BUILD_CONFIGURATION="${SWIFT_BUILD_CONFIGURATION:=Release}" SWIFTPM_CONFIGURATION="${SWIFTPM_CONFIGURATION:=release}" SWIFT_PACKAGE_SRCDIR="${SWIFT_PACKAGE_SRCDIR:=$SRC_ROOT/swift-hello}" SWIFT_PACKAGE_BUILDDIR="${SWIFT_PACKAGE_BUILDDIR:=$SWIFT_PACKAGE_SRCDIR/.build}" +if [ -d ${STAGING_DIR} ]; then + GCC_INSTALL_DIR=$(dirname $(find ${STAGING_DIR} -name crtbegin.o)) +else + GCC_INSTALL_DIR=${STAGING_DIR} +fi # Build Paths LLVM_SRCDIR=$SRC_ROOT/downloads/llvm-project @@ -44,9 +64,8 @@ INSTALL_TAR=${INSTALL_TAR:=$SRC_ROOT/build/swift-$SWIFT_TARGET_ARCH-$SWIFT_VERSI PREBUILT_XCTOOLCHAIN=$SRC_ROOT/downloads/${SWIFT_VERSION}-osx.pkg # Compilation flags -EXTRA_FLAGS="-march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard" -RUNTIME_FLAGS="-w -fuse-ld=lld --sysroot=${STAGING_DIR} -target ${SWIFT_TARGET_NAME}" -LINK_FLAGS="--sysroot=${STAGING_DIR} -target ${SWIFT_TARGET_NAME} ${EXTRA_FLAGS} -latomic" +RUNTIME_FLAGS="-w -fuse-ld=lld --sysroot=${STAGING_DIR} --gcc-install-dir=${GCC_INSTALL_DIR} -target ${SWIFT_TARGET_NAME} ${EXTRA_FLAGS}" +LINK_FLAGS="--sysroot=${STAGING_DIR} --gcc-install-dir=${GCC_INSTALL_DIR} -target ${SWIFT_TARGET_NAME} ${EXTRA_FLAGS} -latomic" ASM_FLAGS="--sysroot=${STAGING_DIR} -target ${SWIFT_TARGET_NAME}" SWIFTC_FLAGS="-target ${SWIFT_TARGET_NAME} \