From 1b6b2e274e85105bfa155183145a1dcfd63331f1 Mon Sep 17 00:00:00 2001 From: mrcararia Date: Mon, 20 Apr 2026 10:37:39 +0200 Subject: [PATCH] Add module anchor to fix empty dynamic framework on Xcode 26 (#436) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Fixes #435. On Apple platforms every source file in the `Crypto` target compiles to just `@_exported import CryptoKit` (because `CRYPTO_IN_SWIFTPM` is defined but `CRYPTO_IN_SWIFTPM_FORCE_BUILD_API` is not), producing **zero exported symbols**. Xcode 26 changed how SPM packages are built for test-target dependencies: each package product is built as a separate dynamic framework. A module with no symbols generates a `.framework` directory but no Mach-O binary, causing a linker error: ``` clang: error: no such file or directory: '.../PackageFrameworks/Crypto_17A3B1FFC41E47_PackageProduct.framework/Crypto_17A3B1FFC41E47_PackageProduct' ``` ## Fix Added a minimal `_CryptoModuleAnchor` public enum (outside the conditional compilation guard) so the module always produces at least one exported symbol, regardless of how it is linked. The type is prefixed with `_` to signal it is not intended for public use. ## Test plan - [ ] Build a project with a test target that has `swift-crypto` (or a transitive dependency like `swift-certificates`) as a `packageProductDependency` on Xcode 26 targeting iOS Simulator — should now succeed - [ ] Verify existing tests still pass (`swift test`) --------- Co-authored-by: Niccolò Calamai Co-authored-by: Cory Benfield --- Sources/Crypto/CMakeLists.txt | 1 + .../Util/BoringSSL/_CryptoModuleAnchor.swift | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 Sources/Crypto/Util/BoringSSL/_CryptoModuleAnchor.swift diff --git a/Sources/Crypto/CMakeLists.txt b/Sources/Crypto/CMakeLists.txt index 1b560e78..0dc9f4f4 100644 --- a/Sources/Crypto/CMakeLists.txt +++ b/Sources/Crypto/CMakeLists.txt @@ -102,6 +102,7 @@ add_library(Crypto "Util/BoringSSL/RNG_boring.swift" "Util/BoringSSL/SafeCompare_boring.swift" "Util/BoringSSL/Zeroization_boring.swift" + "Util/BoringSSL/_CryptoModuleAnchor.swift" "Util/PrettyBytes.swift" "Util/SafeCompare.swift" "Util/SecureBytes.swift" diff --git a/Sources/Crypto/Util/BoringSSL/_CryptoModuleAnchor.swift b/Sources/Crypto/Util/BoringSSL/_CryptoModuleAnchor.swift new file mode 100644 index 00000000..24f239b5 --- /dev/null +++ b/Sources/Crypto/Util/BoringSSL/_CryptoModuleAnchor.swift @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the SwiftCrypto open source project +// +// Copyright (c) 2024-2026 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 +// +//===----------------------------------------------------------------------===// + +// On Apple platforms the Crypto module re-exports CryptoKit and produces no +// symbols of its own. When Xcode 26+ builds SPM packages as dynamic +// frameworks (e.g. for test-target dependencies), an empty module generates a +// framework directory with no Mach-O binary, causing a linker error. +// +// This symbol ensures at least one exported entry is always present in the +// binary, regardless of how the package is linked. +// See: https://github.com/apple/swift-crypto/issues/435 + +@usableFromInline +internal func _cryptoModuleAnchor() {}