Skip to content

Commit 5684bd7

Browse files
authored
Merge pull request swiftlang#532 from swiftlang/automerge/merge-main-2025-05-28_16-25
Merge `main` into `release/6.2`
2 parents d4ff33b + 85f272c commit 5684bd7

31 files changed

+537
-280
lines changed

Sources/SWBAndroidPlatform/AndroidSDK.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ struct AndroidSDK: Sendable {
5757
}
5858

5959
struct LLVMTriple: Codable {
60-
let arch: String
61-
let vendor: String
62-
let system: String
63-
let environment: String
60+
var arch: String
61+
var vendor: String
62+
var system: String
63+
var environment: String
6464

6565
var description: String {
6666
"\(arch)-\(vendor)-\(system)-\(environment)"

Sources/SWBAndroidPlatform/Plugin.swift

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ struct AndroidEnvironmentExtension: EnvironmentExtension {
6565
}
6666

6767
struct AndroidPlatformExtension: PlatformInfoExtension {
68-
func knownDeploymentTargetMacroNames() -> Set<String> {
69-
["ANDROID_DEPLOYMENT_TARGET"]
70-
}
71-
7268
func additionalPlatforms(context: any PlatformInfoExtensionAdditionalPlatformsContext) throws -> [(path: Path, data: [String: PropertyListItem])] {
7369
[
7470
(.root, [
@@ -120,6 +116,37 @@ struct AndroidSDKRegistryExtension: SDKRegistryExtension {
120116
return []
121117
}
122118

119+
let allPossibleTriples = abis.values.flatMap { abi in
120+
(max(deploymentTargetRange.min, abi.min_os_version)...deploymentTargetRange.max).map { deploymentTarget in
121+
var triple = abi.llvm_triple
122+
triple.vendor = "unknown" // Android NDK uses "none", Swift SDKs use "unknown"
123+
triple.environment += "\(deploymentTarget)"
124+
return triple
125+
}
126+
}.map(\.description)
127+
128+
let androidSwiftSDKs = (try? SwiftSDK.findSDKs(
129+
targetTriples: allPossibleTriples,
130+
fs: context.fs,
131+
hostOperatingSystem: context.hostOperatingSystem
132+
)) ?? []
133+
134+
let swiftSettings: [String: PropertyListItem]
135+
// FIXME: We need a way to narrow down the list, possibly by passing down a Swift SDK identifier from SwiftPM
136+
// The resource path should be the same for all triples in an Android Swift SDK
137+
if let androidSwiftSDK = androidSwiftSDKs.only, let swiftResourceDir = Set(androidSwiftSDK.targetTriples.values.map { tripleProperties in androidSwiftSDK.path.join(tripleProperties.swiftResourcesPath) }).only {
138+
swiftSettings = [
139+
"SWIFT_LIBRARY_PATH": .plString(swiftResourceDir.join("android").str),
140+
"SWIFT_RESOURCE_DIR": .plString(swiftResourceDir.str),
141+
"SWIFT_TARGET_TRIPLE": .plString("$(CURRENT_ARCH)-unknown-$(SWIFT_PLATFORM_TARGET_PREFIX)$(LLVM_TARGET_TRIPLE_SUFFIX)"),
142+
"LIBRARY_SEARCH_PATHS": "$(inherited) $(SWIFT_RESOURCE_DIR)/../$(__ANDROID_TRIPLE_$(CURRENT_ARCH))",
143+
].merging(abis.map {
144+
("__ANDROID_TRIPLE_\($0.value.llvm_triple.arch)", .plString($0.value.triple))
145+
}, uniquingKeysWith: { _, new in new })
146+
} else {
147+
swiftSettings = [:]
148+
}
149+
123150
return [(androidSdk.sysroot ?? .root, androidPlatform, [
124151
"Type": .plString("SDK"),
125152
"Version": .plString("0.0.0"),
@@ -133,7 +160,7 @@ struct AndroidSDKRegistryExtension: SDKRegistryExtension {
133160
// FIXME: Make this configurable in a better way so we don't need to push build settings at the SDK definition level
134161
"LLVM_TARGET_TRIPLE_OS_VERSION": .plString("linux"),
135162
"LLVM_TARGET_TRIPLE_SUFFIX": .plString("-android$(ANDROID_DEPLOYMENT_TARGET)"),
136-
]),
163+
].merging(swiftSettings, uniquingKeysWith: { _, new in new })),
137164
"SupportedTargets": .plDict([
138165
"android": .plDict([
139166
"Archs": .plArray(abis.map { .plString($0.value.llvm_triple.arch) }),

Sources/SWBApplePlatform/Plugin.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,6 @@ struct XCStringsInputFileGroupingStrategyExtension: InputFileGroupingStrategyExt
207207
}
208208

209209
struct ApplePlatformInfoExtension: PlatformInfoExtension {
210-
func knownDeploymentTargetMacroNames() -> Set<String> {
211-
[
212-
"MACOSX_DEPLOYMENT_TARGET",
213-
"IPHONEOS_DEPLOYMENT_TARGET",
214-
"TVOS_DEPLOYMENT_TARGET",
215-
"WATCHOS_DEPLOYMENT_TARGET",
216-
"DRIVERKIT_DEPLOYMENT_TARGET",
217-
"XROS_DEPLOYMENT_TARGET",
218-
]
219-
}
220-
221210
func preferredArchValue(for platformName: String) -> String? {
222211
// FIXME: rdar://65011964 (Remove PLATFORM_PREFERRED_ARCH)
223212
// Don't add values for any new platforms

Sources/SWBBuildService/Messages.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,8 @@ private struct AllExportedMacrosAndValuesMsg: MessageHandler {
14401440
let settings = try getSettings(for: session, workspaceContext: workspaceContext, requestContext: message.context, purpose: .build)
14411441

14421442
// Get the list of setting names and evaluated values. We use the same algorithm as is used to export settings to shell script build phases.
1443-
let exportedMacrosAndValues = computeScriptEnvironment(.shellScriptPhase, scope: settings.globalScope, settings: settings, workspaceContext: workspaceContext)
1443+
// We explicitly pass an empty set for `allDeploymentTargetMacroNames` because in this context we are exporting the list of known macros and not applying the special case to only exported a single deployment target like we do in shell scripts.
1444+
let exportedMacrosAndValues = computeScriptEnvironment(.shellScriptPhase, scope: settings.globalScope, settings: settings, workspaceContext: workspaceContext, allDeploymentTargetMacroNames: [])
14441445

14451446
return AllExportedMacrosAndValuesResponse(result: exportedMacrosAndValues)
14461447
}

Sources/SWBBuildSystem/CleanOperation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ package final class CleanOperation: BuildSystemOperation, TargetDependencyResolv
207207
delegate.targetPreparationStarted(self, configuredTarget: configuredTarget)
208208
delegate.targetStarted(self, configuredTarget: configuredTarget)
209209

210-
let (executable, arguments, workingDirectory, environment) = constructCommandLine(for: configuredTarget.target as! SWBCore.ExternalTarget, action: "clean", settings: settings, workspaceContext: workspaceContext, scope: settings.globalScope)
210+
let (executable, arguments, workingDirectory, environment) = constructCommandLine(for: configuredTarget.target as! SWBCore.ExternalTarget, action: "clean", settings: settings, workspaceContext: workspaceContext, scope: settings.globalScope, allDeploymentTargetMacroNames: [])
211211
let commandLine = [executable] + arguments
212212

213213
let specLookupContext = SpecLookupCtxt(specRegistry: workspaceContext.core.specRegistry, platform: settings.platform)

Sources/SWBCore/Extensions/PlatformInfoExtension.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ public struct PlatformInfoExtensionPoint: ExtensionPoint, Sendable {
2222
}
2323

2424
public protocol PlatformInfoExtension: Sendable {
25-
func knownDeploymentTargetMacroNames() -> Set<String>
26-
2725
func preferredArchValue(for: String) -> String?
2826

2927
func additionalTestLibraryPaths(scope: MacroEvaluationScope, platform: Platform?, fs: any FSProxy) -> [Path]
@@ -40,10 +38,6 @@ public protocol PlatformInfoExtension: Sendable {
4038
}
4139

4240
extension PlatformInfoExtension {
43-
public func knownDeploymentTargetMacroNames() -> Set<String> {
44-
[]
45-
}
46-
4741
public func preferredArchValue(for: String) -> String? {
4842
nil
4943
}

Sources/SWBCore/LibSwiftDriver/PlannedBuild.swift

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ public struct SwiftDriverJob: Serializable, CustomDebugStringConvertible {
8080
public let outputs: [Path]
8181
/// The command line to execute for this job
8282
public let commandLine: [SWBUtil.ByteString]
83-
/// A signature which uniquely identifies the job.
84-
public let signature: SWBUtil.ByteString
8583
/// Cache keys for the swift-frontend invocation (one key per output producing input)
8684
public let cacheKeys: [String]
8785

@@ -103,15 +101,10 @@ public struct SwiftDriverJob: Serializable, CustomDebugStringConvertible {
103101
self.cacheKeys = job.outputCacheKeys.reduce(into: [String]()) { result, key in
104102
result.append(key.value)
105103
}.sorted()
106-
let md5 = InsecureHashContext()
107-
for arg in commandLine {
108-
md5.add(bytes: arg)
109-
}
110-
self.signature = md5.signature
111104
}
112105

113106
public func serialize<T>(to serializer: T) where T : Serializer {
114-
serializer.serializeAggregate(10) {
107+
serializer.serializeAggregate(9) {
115108
serializer.serialize(kind)
116109
serializer.serialize(ruleInfoType)
117110
serializer.serialize(moduleName)
@@ -120,13 +113,12 @@ public struct SwiftDriverJob: Serializable, CustomDebugStringConvertible {
120113
serializer.serialize(outputs)
121114
serializer.serialize(commandLine)
122115
serializer.serialize(descriptionForLifecycle)
123-
serializer.serialize(signature)
124116
serializer.serialize(cacheKeys)
125117
}
126118
}
127119

128120
public init(from deserializer: any Deserializer) throws {
129-
try deserializer.beginAggregate(10)
121+
try deserializer.beginAggregate(9)
130122
try self.kind = deserializer.deserialize()
131123
try self.ruleInfoType = deserializer.deserialize()
132124
try self.moduleName = deserializer.deserialize()
@@ -135,7 +127,6 @@ public struct SwiftDriverJob: Serializable, CustomDebugStringConvertible {
135127
try self.outputs = deserializer.deserialize()
136128
try self.commandLine = deserializer.deserialize()
137129
try self.descriptionForLifecycle = deserializer.deserialize()
138-
try self.signature = deserializer.deserialize()
139130
try self.cacheKeys = deserializer.deserialize()
140131
}
141132

@@ -173,29 +164,40 @@ extension LibSwiftDriver {
173164
public let dependencies: [JobKey]
174165
/// Working directory for running this job
175166
public let workingDirectory: Path
167+
/// A signature which uniquely identifies this planned job.
168+
public let signature: SWBUtil.ByteString
176169

177170
internal init(key: JobKey, driverJob: SwiftDriverJob, dependencies: [JobKey], workingDirectory: Path) {
178171
self.key = key
179172
self.driverJob = driverJob
180173
self.dependencies = dependencies
181174
self.workingDirectory = workingDirectory
175+
let md5 = InsecureHashContext()
176+
for arg in driverJob.commandLine {
177+
md5.add(bytes: arg)
178+
}
179+
md5.add(string: workingDirectory.str)
180+
md5.add(number: dependencies.hashValue)
181+
self.signature = md5.signature
182182
}
183183

184184
public func serialize<T>(to serializer: T) where T : Serializer {
185-
serializer.serializeAggregate(4) {
185+
serializer.serializeAggregate(5) {
186186
serializer.serialize(key)
187187
serializer.serialize(driverJob)
188188
serializer.serialize(dependencies)
189189
serializer.serialize(workingDirectory)
190+
serializer.serialize(signature)
190191
}
191192
}
192193

193194
public init(from deserializer: any Deserializer) throws {
194-
try deserializer.beginAggregate(4)
195+
try deserializer.beginAggregate(5)
195196
try key = deserializer.deserialize()
196197
try driverJob = deserializer.deserialize()
197198
try dependencies = deserializer.deserialize()
198199
try workingDirectory = deserializer.deserialize()
200+
try signature = deserializer.deserialize()
199201
}
200202

201203
public func addingDependencies(_ newDependencies: [JobKey]) -> PlannedSwiftDriverJob {

Sources/SWBCore/PlatformRegistry.swift

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,6 @@ public final class PlatformRegistry {
309309
/// The map of platforms by name.
310310
var platformsByName = Dictionary<String, Platform>()
311311

312-
/// The set of all known deployment target macro names, even if the platforms that use those settings are not installed.
313-
private(set) var allDeploymentTargetMacroNames = Set<String>()
314-
315312
/// The default deployment targets for all installed platforms.
316313
var defaultDeploymentTargets: [String: Version] {
317314
Dictionary(uniqueKeysWithValues: Dictionary(grouping: platforms, by: { $0.defaultSDKVariant?.deploymentTargetSettingName })
@@ -353,46 +350,6 @@ public final class PlatformRegistry {
353350
}
354351
}
355352

356-
private func loadDeploymentTargetMacroNames() {
357-
// We must have loaded the extended platform info before doing this,
358-
// since deploymentTargetMacro is set on the Platform objects through there.
359-
precondition(hasLoadedExtendedInfo)
360-
361-
// Set up allDeploymentTargetMacroNames in stages to detect issues.
362-
// First we add all deployment targets from installed platforms, and emit a warning if multiple platforms declare that they use the same deployment target.
363-
var platformsByDeploymentTarget = [String: Set<String>]()
364-
for platform in platforms {
365-
if let macroName = platform.deploymentTargetMacro?.name, !macroName.isEmpty {
366-
allDeploymentTargetMacroNames.insert(macroName)
367-
368-
// Don't count simulator platforms separately, as a simulator platform always shares a deployment target with its corresponding device platform.
369-
platformsByDeploymentTarget[macroName, default: Set<String>()].insert(platform.correspondingDevicePlatform?.name ?? platform.name)
370-
}
371-
}
372-
373-
// Now add in all deployment targets we know about. This is because clang also knows about these deployment targets intrinsically when they are passed as environment variables, so we sometimes need to work with them even if the platform which defines them is not installed.
374-
@preconcurrency @PluginExtensionSystemActor func platformInfoExtensions() -> [any PlatformInfoExtensionPoint.ExtensionProtocol] {
375-
delegate.pluginManager.extensions(of: PlatformInfoExtensionPoint.self)
376-
}
377-
378-
for platformExtension in platformInfoExtensions() {
379-
for knownDeploymentTargetMacroName in platformExtension.knownDeploymentTargetMacroNames() {
380-
allDeploymentTargetMacroNames.insert(knownDeploymentTargetMacroName)
381-
platformsByDeploymentTarget[knownDeploymentTargetMacroName] = nil
382-
}
383-
}
384-
385-
// For any macros left in the dictionary, emit a warning that it's a deployment target macro we didn't know about so we can add them to the list above in the future.
386-
for macroName in platformsByDeploymentTarget.keys.sorted() {
387-
guard let platformNames = platformsByDeploymentTarget[macroName], !platformNames.isEmpty else {
388-
// This is a weird scenario - should we emit a warning here?
389-
continue
390-
}
391-
let platformList: String = (platformNames.count > 1 ? "s: " : ": ") + platformNames.sorted().joined(separator: ", ")
392-
delegate.warning("found previously-unknown deployment target macro '\(macroName)' declared by platform\(platformList)")
393-
}
394-
}
395-
396353
/// Register all platforms in the given directory.
397354
private func registerPlatformsInDirectory(_ path: Path, _ fs: any FSProxy) async {
398355
for item in (try? localFS.listdir(path))?.sorted(by: <) ?? [] {
@@ -690,8 +647,6 @@ public final class PlatformRegistry {
690647
unregisterPlatform(platform)
691648
}
692649
}
693-
694-
loadDeploymentTargetMacroNames()
695650
}
696651
var hasLoadedExtendedInfo = false
697652

Sources/SWBCore/Settings/BuiltinMacros.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,8 @@ public final class BuiltinMacros {
13011301
// Info.plist Keys - Sticker Packs
13021302
public static let INFOPLIST_KEY_NSStickerSharingLevel = BuiltinMacros.declareEnumMacro("INFOPLIST_KEY_NSStickerSharingLevel") as EnumMacroDeclaration<StickerSharingLevel>
13031303

1304+
public static let __SKIP_BUILD = BuiltinMacros.declareBooleanMacro("__SKIP_BUILD")
1305+
13041306
// MARK: Built-in Macro Initialization
13051307

13061308
private static var initialized = false
@@ -2393,7 +2395,8 @@ public final class BuiltinMacros {
23932395
ENABLE_XOJIT_PREVIEWS,
23942396
BUILD_ACTIVE_RESOURCES_ONLY,
23952397
ENABLE_ONLY_ACTIVE_RESOURCES,
2396-
ENABLE_PLAYGROUND_RESULTS
2398+
ENABLE_PLAYGROUND_RESULTS,
2399+
__SKIP_BUILD
23972400
]
23982401

23992402
/// Force initialization of entitlements macros.

Sources/SWBCore/ShellScript.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public enum ScriptType: Sendable {
2626
/// - settings: The settings to use for computing the script's environment and search paths.
2727
/// - workspaceContext: The workspace context to use for computing the script's environment.
2828
/// - scope: The scope in which to expand build settings.
29-
public func constructCommandLine(for target: ExternalTarget, action: String, settings: Settings, workspaceContext: WorkspaceContext, scope: MacroEvaluationScope) -> (executable: String, arguments: [String], workingDirectory: Path, environment: [String: String]) {
29+
public func constructCommandLine(for target: ExternalTarget, action: String, settings: Settings, workspaceContext: WorkspaceContext, scope: MacroEvaluationScope, allDeploymentTargetMacroNames: Set<String>) -> (executable: String, arguments: [String], workingDirectory: Path, environment: [String: String]) {
3030
let scope = settings.globalScope
3131
func lookup(_ macro: MacroDeclaration) -> MacroExpression? {
3232
switch macro {
@@ -44,7 +44,7 @@ public func constructCommandLine(for target: ExternalTarget, action: String, set
4444
let workingDirectory = (settings.project?.sourceRoot ?? workspaceContext.workspace.path.dirname).join(Path(scope.evaluate(target.workingDirectory, lookup: lookup)))
4545
var environment: [String: String] = [:]
4646
if target.passBuildSettingsInEnvironment {
47-
environment = computeScriptEnvironment(.externalTarget, scope: scope, settings: settings, workspaceContext: workspaceContext)
47+
environment = computeScriptEnvironment(.externalTarget, scope: scope, settings: settings, workspaceContext: workspaceContext, allDeploymentTargetMacroNames: allDeploymentTargetMacroNames)
4848
}
4949

5050
// Always set ACTION in the environment.
@@ -77,7 +77,7 @@ public func constructCommandLine(for target: ExternalTarget, action: String, set
7777
/// - scope: The scope in which to expand build settings.
7878
/// - settings: The settings to use for computing the environment.
7979
/// - workspaceContext: The workspace context to use for computing the environment
80-
public func computeScriptEnvironment(_ type: ScriptType, scope: MacroEvaluationScope, settings: Settings, workspaceContext: WorkspaceContext) -> [String: String] {
80+
public func computeScriptEnvironment(_ type: ScriptType, scope: MacroEvaluationScope, settings: Settings, workspaceContext: WorkspaceContext, allDeploymentTargetMacroNames: Set<String>) -> [String: String] {
8181
var result = [String: String]()
8282

8383
// FIXME: Note that we merged this function for shell scripts with the very similar code that was used to build the environment for external build commands. Currently in order to retain perfect compatibility we do various things conditionally based on the mode, but really this code should just be a single function that is used for both contexts at some point.
@@ -202,7 +202,7 @@ public func computeScriptEnvironment(_ type: ScriptType, scope: MacroEvaluationS
202202

203203
// Remove deployment targets for platforms other than the one we're building for. <rdar://problem/20008508>
204204
let ourDeploymentTargetName = scope.evaluate(BuiltinMacros.DEPLOYMENT_TARGET_SETTING_NAME)
205-
for deploymentTargetNameToRemove in workspaceContext.core.platformRegistry.allDeploymentTargetMacroNames {
205+
for deploymentTargetNameToRemove in allDeploymentTargetMacroNames {
206206
if ourDeploymentTargetName.isEmpty || ourDeploymentTargetName != deploymentTargetNameToRemove {
207207
result.removeValue(forKey: deploymentTargetNameToRemove)
208208
}

0 commit comments

Comments
 (0)