Files
swift-crypto/scripts/generate-linux-sdks.sh
Gwynne Raskind c661debfc2 Update BoringSSL to 0226f30467f540a3f62ef48d453f93927da199b6 (#406)
Fix multiple issues in the BoringSSL vendoring script and update
BoringSSL to 0226f30467f540a3f62ef48d453f93927da199b6

### Checklist
- [x] I've run tests to see all new and existing tests pass
- [x] I've followed the code style of the rest of the project
- [x] I've read the [Contribution Guidelines](CONTRIBUTING.md)
- [x] I've updated the documentation if necessary

### Motivation:

The `vendor-boringssl.sh` script is currently broken in a number of
ways, both in general and relative to the latest BoringSSL version:

- `--enable-test-discovery` is still in use
- The Linux Swift SDKs being generated are out of date (5.10-jammy)
- The script does not prefix exported C++ symbols
- Invoking the script without a `BORINGSSL_REVISION` results in an
unconditional error
- The `PATTERNS` list is out of date for the latest BoringSSL
- The latest BoringSSL contains a bug which fails to apply `extern "C"`
to two exported symbols, allowing for collisions.

In addition, the latest BoringSSL has made `BN_MONT_CTX` opaque,
necessitating that it be referenced with `OpaquePointer` rather than
`UnsafePointer<>`.

### Modifications:

The following changes are included:

- `--enable-test-discovery` has been removed
- `vendor-boringssl.sh` and `generate-linux-sdks.sh` have been updated
to use Swift 6.1.2 SDKs built for Ubuntu Noble
- The `mangle_cpp_structures` function from `swift-nio-ssl`'s version
of `vendor-boringssl.sh` has been copied over (thanks @Lukasa!)
- `BORINGSSL_REVISION` is now allowed to be an empty string
- The `PATTERNS` array has been updated
- A patch has been added which applies `extern "C"` to the functions
which should have it
- `s/UnsafePointer<BN_MONT_CTX>/OpaquePointer/g`
- Updated `CMakeLists.txt` per `update-cmake-lists.sh`
- Update BoringSSL to
`0226f30467f540a3f62ef48d453f93927da199b6`

### Result:

Vendoring the latest BoringSSL will work again.
The latest BoringSSL is vendored.
2025-09-15 15:21:20 +01:00

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=6.1.2
DISTRO_NAME=ubuntu
DISTRO_VERSION=noble
DISTRO_VERSION_GENERATOR=24.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"