Skip to content

Commit daac154

Browse files
committed
Exclude PrivacyInfo.xcprivacy resource on Android
Declaring a resource on the SQLite target makes SwiftPM generate a Bundle.module accessor that unconditionally imports Foundation and calls Bundle.main/Bundle(path:), which requires linking all of Foundation (plus FoundationInternationalization and ICU on affected SDKs) even for consumers that otherwise only need FoundationEssentials. PrivacyInfo.xcprivacy only has meaning for the Apple App Store, so this excludes it under a TARGET_OS_ANDROID environment variable, following the same convention swift-android-native uses to detect an Android cross-compile from Package.swift (which always evaluates on the host and has no direct way to see the build destination). No effect on existing consumers since the variable is unset by default.
1 parent ccaae3d commit daac154

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

Package.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
import PackageDescription
33
let applePlatforms: [PackageDescription.Platform] = [.iOS, .macOS, .watchOS, .tvOS, .visionOS]
44

5+
// Package.swift always compiles for the host, so it can't see the build
6+
// destination directly — an environment variable (matching the convention
7+
// used by swift-android-native's own `TARGET_OS_ANDROID` check) is the only
8+
// way to detect an Android cross-compile here. `PrivacyInfo.xcprivacy` is
9+
// only meaningful for the Apple App Store; declaring it as a resource makes
10+
// SwiftPM generate a `Bundle.module` accessor that requires linking all of
11+
// Foundation on Android, so it's excluded there.
12+
let isAndroid = Context.environment["TARGET_OS_ANDROID"] ?? "0" != "0"
13+
514
let target: Target = .target(
615
name: "SQLite",
716
dependencies: [
@@ -12,8 +21,8 @@ let target: Target = .target(
1221
package: "SQLCipher.swift",
1322
condition: .when(platforms: applePlatforms, traits: ["SQLCipher"]))
1423
],
15-
exclude: ["Info.plist"],
16-
resources: [.copy("PrivacyInfo.xcprivacy")],
24+
exclude: isAndroid ? ["Info.plist", "PrivacyInfo.xcprivacy"] : ["Info.plist"],
25+
resources: isAndroid ? [] : [.copy("PrivacyInfo.xcprivacy")],
1726
cSettings: [
1827
.define("SQLITE_HAS_CODEC", .when(platforms: applePlatforms, traits: ["SQLCipher"]))
1928
]

0 commit comments

Comments
 (0)