From 584e79ad2ed085423aa6996560aa0186bc94f2dd Mon Sep 17 00:00:00 2001 From: George Barnett Date: Tue, 17 Sep 2024 14:25:40 +0100 Subject: [PATCH] Only include privacy manifest on Darwin Motivation: The privacy manifest is only required on Darwin. It's currently included on all platforms which results in build warnings. Modifications: - Only include manifest on Darwin - Exclude the privacy manifest from the build on other platforms Result: - Fewer warnings - Resolves #256 --- Package.swift | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/Package.swift b/Package.swift index 11134382..3344d624 100644 --- a/Package.swift +++ b/Package.swift @@ -57,6 +57,18 @@ if development { ] } +// This doesn't work when cross-compiling: the privacy manifest will be included in the Bundle and +// Foundation will be linked. This is, however, strictly better than unconditionally adding the +// resource. +#if canImport(Darwin) +let privacyManifestExclude: [String] = [] +let privacyManifestResource: [PackageDescription.Resource] = [.copy("PrivacyInfo.xcprivacy")] +#else +// Exclude on other platforms to avoid build warnings. +let privacyManifestExclude: [String] = ["PrivacyInfo.xcprivacy"] +let privacyManifestResource: [PackageDescription.Resource] = [] +#endif + let package = Package( name: "swift-crypto", platforms: [ @@ -76,7 +88,7 @@ let package = Package( targets: [ .target( name: "CCryptoBoringSSL", - exclude: [ + exclude: privacyManifestExclude + [ "hash.txt", "include/boringssl_prefix_symbols_nasm.inc", "CMakeLists.txt", @@ -88,9 +100,7 @@ let package = Package( "crypto/bio/socket_helper.c", "crypto/bio/socket.c" ], - resources: [ - .copy("PrivacyInfo.xcprivacy"), - ], + resources: privacyManifestResource, cSettings: [ // These defines come from BoringSSL's build system .define("_HAS_EXCEPTIONS", to: "0", .when(platforms: [Platform.windows])), @@ -107,26 +117,22 @@ let package = Package( .target( name: "CCryptoBoringSSLShims", dependencies: ["CCryptoBoringSSL"], - exclude: [ + exclude: privacyManifestExclude + [ "CMakeLists.txt" ], - resources: [ - .copy("PrivacyInfo.xcprivacy"), - ] + resources: privacyManifestResource ), .target( name: "Crypto", dependencies: dependencies, - exclude: [ + exclude: privacyManifestExclude + [ "CMakeLists.txt", "AEADs/Nonces.swift.gyb", "Digests/Digests.swift.gyb", "Key Agreement/ECDH.swift.gyb", "Signatures/ECDSA.swift.gyb", ], - resources: [ - .copy("PrivacyInfo.xcprivacy"), - ], + resources: privacyManifestResource, swiftSettings: swiftSettings + [.define("MODULE_IS_CRYPTO")] ), .target( @@ -137,12 +143,10 @@ let package = Package( "CryptoBoringWrapper", "Crypto" ], - exclude: [ + exclude: privacyManifestExclude + [ "CMakeLists.txt", ], - resources: [ - .copy("PrivacyInfo.xcprivacy"), - ], + resources: privacyManifestResource, swiftSettings: swiftSettings ), .target( @@ -151,12 +155,10 @@ let package = Package( "CCryptoBoringSSL", "CCryptoBoringSSLShims" ], - exclude: [ + exclude: privacyManifestExclude + [ "CMakeLists.txt", ], - resources: [ - .copy("PrivacyInfo.xcprivacy"), - ] + resources: privacyManifestResource ), .executableTarget(name: "crypto-shasum", dependencies: ["Crypto"]), .testTarget(