Skip to content

Trunk SwiftPM is unable to cross-compile swift-crypto for Android with this build system #1327

Description

@finagolfin

I'm testing out trunk SwiftPM with cross-compiling for Android and while a simple package like swift-system works fine, a package like swift-crypto which depends on a C module like CCryptoBoringSSL errors out:

> ANDROID_NDK_HOME=/Users/finagolfin/swift/ndk-27d ~/swift/build/Ninja-Release/toolchain-macosx-arm64/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift build --swift-sdk aarch64-unknown-linux-android28
Building for debugging...
error: SwiftCompile normal aarch64 failed with a nonzero exit code. Command line:     cd /Users/finagolfin/swift

/Users/finagolfin/swift/swift-crypto/Sources/Crypto/AEADs/AES/GCM/BoringSSL/AES-GCM_boring.swift:17:29: error: no such module 'CCryptoBoringSSL'
15 | @_exported import CryptoKit
16 | #else
17 | @_implementationOnly import CCryptoBoringSSL
   |                             `- error: no such module 'CCryptoBoringSSL'
18 | import CryptoBoringWrapper
19 | import Foundation
Failed frontend command:
/Users/finagolfin/swift/build/Ninja-Release/toolchain-macosx-arm64/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -emit-module -experimental-skip-non-inlinable-function-bodies-without-types /Users/finagolfin/swift/swift-crypto/.build/out/Intermediates.noindex/swift-crypto.build/Debug-android/Crypto-t.build/DerivedSources/resource_bundle_accessor.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/AEADs/AES/GCM/AES-GCM.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/AEADs/AES/GCM/BoringSSL/AES-GCM_boring.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/AEADs/ChachaPoly/BoringSSL/ChaChaPoly_boring.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/AEADs/ChachaPoly/ChaChaPoly.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/AEADs/Cipher.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/AEADs/Nonces.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/ASN1/ASN1.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/ASN1/Basic\ ASN1\ Types/ASN1Any.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/ASN1/Basic\ ASN1\ Types/ASN1BitString.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/ASN1/Basic\ ASN1\ Types/ASN1Boolean.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/ASN1/Basic\ ASN1\ Types/ASN1Identifier.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/ASN1/Basic\ ASN1\ Types/ASN1Integer.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/ASN1/Basic\ ASN1\ Types/ASN1Null.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/ASN1/Basic\ ASN1\ Types/ASN1OctetString.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/ASN1/Basic\ ASN1\ Types/ASN1Strings.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/ASN1/Basic\ ASN1\ Types/ArraySliceBigint.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/ASN1/Basic\ ASN1\ Types/GeneralizedTime.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/ASN1/Basic\ ASN1\ Types/ObjectIdentifier.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/ASN1/ECDSASignature.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/ASN1/PEMDocument.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/ASN1/PKCS8PrivateKey.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/ASN1/SEC1PrivateKey.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/ASN1/SubjectPublicKeyInfo.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/CryptoKitErrors.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Digests/BoringSSL/Digest_boring.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Digests/Digest.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Digests/Digests.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Digests/HashFunctions.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Digests/HashFunctions_SHA2.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/HPKE/Ciphersuite/HPKE-AEAD.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/HPKE/Ciphersuite/HPKE-Ciphersuite.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/HPKE/Ciphersuite/HPKE-KDF.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/HPKE/Ciphersuite/HPKE-KexKeyDerivation.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/HPKE/Ciphersuite/HPKE-LabeledExtract.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/HPKE/Ciphersuite/HPKE-Utils.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/HPKE/Ciphersuite/KEM/Conformances/DHKEM.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/HPKE/Ciphersuite/KEM/Conformances/HPKE-KEM-Curve25519.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/HPKE/Ciphersuite/KEM/Conformances/HPKE-NIST-EC-KEMs.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/HPKE/Ciphersuite/KEM/HPKE-KEM.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/HPKE/HPKE-Errors.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/HPKE/HPKE.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/HPKE/Key\ Schedule/HPKE-Context.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/HPKE/Key\ Schedule/HPKE-KeySchedule.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/HPKE/Modes/HPKE-Modes.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Insecure/Insecure.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Insecure/Insecure_HashFunctions.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/KEM/KEM.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Key\ Agreement/BoringSSL/ECDH_boring.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Key\ Agreement/DH.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Key\ Agreement/ECDH.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Key\ Derivation/HKDF.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Key\ Wrapping/AESWrap.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Key\ Wrapping/BoringSSL/AESWrap_boring.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Keys/EC/BoringSSL/Ed25519_boring.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Keys/EC/BoringSSL/NISTCurvesKeys_boring.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Keys/EC/BoringSSL/X25519Keys_boring.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Keys/EC/Curve25519.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Keys/EC/Ed25519Keys.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Keys/EC/NISTCurvesKeys.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Keys/EC/X25519Keys.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Keys/Symmetric/SymmetricKeys.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Message\ Authentication\ Codes/HMAC/HMAC.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Message\ Authentication\ Codes/MACFunctions.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Message\ Authentication\ Codes/MessageAuthenticationCode.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/PRF/AES.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Signatures/BoringSSL/ECDSASignature_boring.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Signatures/BoringSSL/ECDSA_boring.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Signatures/BoringSSL/EdDSA_boring.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Signatures/ECDSA.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Signatures/Ed25519.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Signatures/Signature.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Util/BoringSSL/CryptoKitErrors_boring.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Util/BoringSSL/RNG_boring.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Util/BoringSSL/SafeCompare_boring.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Util/BoringSSL/Zeroization_boring.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Util/PrettyBytes.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Util/SafeCompare.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Util/SecureBytes.swift /Users/finagolfin/swift/swift-crypto/Sources/Crypto/Util/Zeroization.swift -target aarch64-unknown-linux-android28 -Xllvm -aarch64-use-tbi -disable-objc-interop -sdk /Users/finagolfin/swift/ndk-27d/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -I /Users/finagolfin/swift/swift-crypto/.build/out/Products/Debug-android -module-cache-path /Users/finagolfin/swift/swift-crypto/.build/out/ModuleCache.noindex -color-diagnostics -Xcc -fcolor-diagnostics -enable-testing -g -debug-info-format\=dwarf -dwarf-version\=4 -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -D SWIFT_MODULE_RESOURCE_BUNDLE_AVAILABLE -D CRYPTO_IN_SWIFTPM -D CRYPTO_IN_SWIFTPM_FORCE_BUILD_API -D Xcode -serialize-debugging-options -enable-upcoming-feature MemberImportVisibility -enable-experimental-feature DebugDescriptionMacro -empty-abi-descriptor -external-plugin-path /Users/finagolfin/swift/build/Ninja-Release/toolchain-macosx-arm64/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins/testing\#/Users/finagolfin/swift/build/Ninja-Release/toolchain-macosx-arm64/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-plugin-server -validate-clang-modules-once -clang-build-session-file /Users/finagolfin/swift/swift-crypto/.build/out/ModuleCache.noindex/Session.modulevalidation -Xcc -working-directory -Xcc /Users/finagolfin/swift -resource-dir /Users/finagolfin/Library/org.swift.swiftpm/swift-sdks/swift-DEVELOPMENT-SNAPSHOT-2026-04-16-a_android.artifactbundle/swift-android/swift-resources/usr/lib/swift-aarch64 -enable-anonymous-context-mangled-names -file-compilation-dir /Users/finagolfin/swift -Xcc -resource-dir -Xcc /Users/finagolfin/swift/ndk-27d/toolchains/llvm/prebuilt/darwin-x86_64/lib/clang/18 -Xcc -fno-omit-frame-pointer -Xcc -D_LIBCPP_HARDENING_MODE\=_LIBCPP_HARDENING_MODE_DEBUG -Xcc -fmodules-prune-interval\=86400 -Xcc -fmodules-prune-after\=345600 -Xcc -I/Users/finagolfin/swift/swift-crypto/.build/out/Intermediates.noindex/swift-crypto.build/Debug-android/Crypto-t.build/swift-overrides.hmap -Xcc -I/Users/finagolfin/swift/swift-crypto/.build/out/Products/Debug-android/include -Xcc -I/Users/finagolfin/swift/swift-crypto/.build/out/Intermediates.noindex/swift-crypto.build/Debug-android/Crypto-t.build/DerivedSources-normal/aarch64 -Xcc -I/Users/finagolfin/swift/swift-crypto/.build/out/Intermediates.noindex/swift-crypto.build/Debug-android/Crypto-t.build/DerivedSources/aarch64 -Xcc -I/Users/finagolfin/swift/swift-crypto/.build/out/Intermediates.noindex/swift-crypto.build/Debug-android/Crypto-t.build/DerivedSources -Xcc -DSWIFT_PACKAGE -Xcc -DDEBUG\=1 -no-auto-bridging-header-chaining -module-name Crypto -package-name swift_crypto -const-gather-protocols-file /Users/finagolfin/swift/swift-crypto/.build/out/Intermediates.noindex/swift-crypto.build/Debug-android/Crypto-t.build/Objects-normal/aarch64/Crypto_const_extract_protocols.json -in-process-plugin-server-path /Users/finagolfin/swift/build/Ninja-Release/toolchain-macosx-arm64/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/libSwiftInProcPluginServer.dylib -plugin-path /Users/finagolfin/swift/build/Ninja-Release/toolchain-macosx-arm64/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Users/finagolfin/swift/build/Ninja-Release/toolchain-macosx-arm64/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -sysroot /Users/finagolfin/swift/ndk-27d/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -emit-module-doc-path /Users/finagolfin/swift/swift-crypto/.build/out/Intermediates.noindex/swift-crypto.build/Debug-android/Crypto-t.build/Objects-normal/aarch64/Modules/Crypto.swiftdoc -emit-module-source-info-path /Users/finagolfin/swift/swift-crypto/.build/out/Intermediates.noindex/swift-crypto.build/Debug-android/Crypto-t.build/Objects-normal/aarch64/Modules/Crypto.swiftsourceinfo -emit-objc-header-path /Users/finagolfin/swift/swift-crypto/.build/out/Intermediates.noindex/swift-crypto.build/Debug-android/Crypto-t.build/Objects-normal/aarch64/Crypto-Swift.h -serialize-diagnostics-path /Users/finagolfin/swift/swift-crypto/.build/out/Intermediates.noindex/swift-crypto.build/Debug-android/Crypto-t.build/Objects-normal/aarch64/Crypto-primary-emit-module.dia -emit-dependencies-path /Users/finagolfin/swift/swift-crypto/.build/out/Intermediates.noindex/swift-crypto.build/Debug-android/Crypto-t.build/Objects-normal/aarch64/Crypto-primary-emit-module.d -parse-as-library -o /Users/finagolfin/swift/swift-crypto/.build/out/Intermediates.noindex/swift-crypto.build/Debug-android/Crypto-t.build/Objects-normal/aarch64/Modules/Crypto.swiftmodule

error: Build failed

The local Swift toolchain I'm building has the source checked out to compiler commit 366b4d2d7 from late last week and corresponding commits from that time, like swift-build commit 440d404 and SwiftPM commit 7b7265859, with swiftlang/swift-package-manager#9955 applied. I downloaded this Android SDK bundle from the CI around that time, which works fine if I revert to --build-system native.

I tried reproducing with a recent trunk linux toolchain in a container building natively for linux but couldn't, so this appears specific to SDK bundle support. My guess is that swift-build is not computing the package's dependencies properly, as it tries to compile the Swift portion of the package right away, as opposed to native non-SDK compilation where it always compiles the CCryptoBoringSSL base dependency first.

@jakepetroules, let me know if you can reproduce, particularly with other trunk Swift SDKs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    androidSupport for the Android platformbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions