mirror of
https://github.com/apple/swift-crypto
synced 2026-11-24 04:37:48 +00:00
Swift SDK solution for adding armv7 symbols for swift-crypto using the [swift-sdk-generator](https://github.com/swiftlang/swift-sdk-generator). ### Motivation: As outlined in #223, the necessary symbols for armv7 are missing from swift-crypto, and we'd like to add them in some way that could be accepted by the team. It was discussed that using Swift SDKs generated from the swift-sdk-generator could be a solution that could be easily vetted, since the swift-sdk-generator is a component maintained by Apple and the swiftlang organization. ### Modifications: - Added a new `./scripts/generate-linux-sdks.sh` script to clone & build the swift-sdk-generator, and create Swift SDKs for x86_64, aarch64, and armv7. - Modified the `./scripts/vendor-boringssl.sh` script to use these installed Swift SDKs to cross-compile for Linux architectures in the script. - Ran the scripts against the exact revision of BoringSSL to avoid source updates, which adds the missing symbols for armv7. ### Result: Swift SDKs are used to generate symbols for Linux architectures instead of Docker, and missing symbols for armv7 are added as well. I have a few pros and cons for this solution: - Pros - Swift SDKs are used to cross-compile for Linux instead of Docker, which performs better than Rosetta 2 emulation. Docker does not have to be used at all for this solution. - Switching to using Swift SDKs is the more "correct" way to cross-compile for Linux targets, and much of the ecosystem for cross-compilation of Swift packages is moving to using Swift SDKs. - Cons - Lots of downloads need to happen since the swift-sdk-generator needs to download the host macOS toolchain for Swift 5.10, plus Ubuntu packages and target toolchains for each architecture (x86_64, aarch64, armv7). This results in ~15GB of artifacts in the /tmp directory for just the generator artifacts. However, this only needs to be run once before running the vendoring script. Let me know what you think @Lukasa.
79 lines
2.9 KiB
Bash
Executable File
79 lines
2.9 KiB
Bash
Executable File
#!/bin/bash
|
|
##===----------------------------------------------------------------------===##
|
|
##
|
|
## This source file is part of the SwiftCrypto open source project
|
|
##
|
|
## Copyright (c) 2019-2025 Apple Inc. and the SwiftCrypto project authors
|
|
## Licensed under Apache License v2.0
|
|
##
|
|
## See LICENSE.txt for license information
|
|
## See CONTRIBUTORS.txt for the list of SwiftCrypto project authors
|
|
##
|
|
## SPDX-License-Identifier: Apache-2.0
|
|
##
|
|
##===----------------------------------------------------------------------===##
|
|
#
|
|
# This script generates Swift SDKs for Linux targets using the swift-sdk-generator.
|
|
# It should be run once before running the `vendor-boringssl.sh` script, which requires
|
|
# the Linux Swift SDKs to be installed.
|
|
#
|
|
# Usage:
|
|
# 1. Run this script to generate and install the Swift SDKs. This script can be re-run to
|
|
# re-generate Swift SDKs if needed. Old SDKs will be removed before installing newly
|
|
# generated ones.
|
|
#
|
|
|
|
set -e
|
|
|
|
SWIFT_VERSION=5.10
|
|
DISTRO_NAME=ubuntu
|
|
DISTRO_VERSION=jammy
|
|
DISTRO_VERSION_GENERATOR=22.04
|
|
TMPDIR=$(mktemp -d /tmp/.workingXXXXXX)
|
|
|
|
function generate_swift_sdk {
|
|
TARGET_ARCH=$1
|
|
SDK_NAME="${SWIFT_VERSION}-RELEASE_${DISTRO_NAME}_${DISTRO_VERSION}_${TARGET_ARCH}"
|
|
|
|
cd "$TMPDIR"
|
|
if [ ! -d swift-sdk-generator ]; then
|
|
echo "Cloning SDK generator..."
|
|
git clone https://github.com/swiftlang/swift-sdk-generator.git
|
|
fi
|
|
|
|
cd swift-sdk-generator
|
|
|
|
if [ "$TARGET_ARCH" = "armv7" ]; then
|
|
DOWNLOAD_FILE=swift-${SWIFT_VERSION}-RELEASE-${DISTRO_NAME}-${DISTRO_VERSION}-armv7-install
|
|
DOWNLOAD_PATH="${TMPDIR}/${DOWNLOAD_FILE}"
|
|
echo "Downloading armv7 runtime..."
|
|
wget -nc https://github.com/swift-embedded-linux/armhf-debian/releases/download/${SWIFT_VERSION}/${DOWNLOAD_FILE}.tar.gz && \
|
|
echo "Extracting armv7 runtime..." && \
|
|
mkdir "${DOWNLOAD_PATH}" && true && \
|
|
tar -xf ${DOWNLOAD_FILE}.tar.gz -C "${DOWNLOAD_PATH}"
|
|
|
|
echo "Creating Swift SDK for ${TARGET_ARCH}..."
|
|
swift run swift-sdk-generator make-linux-sdk \
|
|
--swift-version ${SWIFT_VERSION}-RELEASE \
|
|
--distribution-name ${DISTRO_NAME} \
|
|
--distribution-version ${DISTRO_VERSION_GENERATOR} \
|
|
--target armv7-unknown-linux-gnueabihf \
|
|
--target-swift-package-path "${DOWNLOAD_PATH}"
|
|
else
|
|
echo "Creating Swift SDK for ${TARGET_ARCH}..."
|
|
swift run swift-sdk-generator make-linux-sdk \
|
|
--swift-version ${SWIFT_VERSION}-RELEASE \
|
|
--distribution-name ${DISTRO_NAME} \
|
|
--distribution-version ${DISTRO_VERSION_GENERATOR} \
|
|
--target "${TARGET_ARCH}-unknown-linux-gnu"
|
|
fi
|
|
|
|
swift sdk remove "${SDK_NAME}" || true # ignore error if it doesn't exist
|
|
swift sdk install "Bundles/${SDK_NAME}.artifactbundle"
|
|
}
|
|
|
|
echo "Generating Swift SDKs for Linux targets..."
|
|
generate_swift_sdk "x86_64"
|
|
generate_swift_sdk "aarch64"
|
|
generate_swift_sdk "armv7"
|