@@ -389,6 +389,7 @@ extension Array where Element == Toolchain {
389389/// The ToolchainRegistry manages the set of registered toolchains.
390390public final class ToolchainRegistry : @unchecked Sendable {
391391 let fs : any FSProxy
392+ let hostOperatingSystem : OperatingSystem
392393
393394 /// The map of toolchains by identifier.
394395 @_spi ( Testing) public private( set) var toolchainsByIdentifier = Dictionary < String , Toolchain > ( )
@@ -402,6 +403,7 @@ public final class ToolchainRegistry: @unchecked Sendable {
402403
403404 @_spi ( Testing) public init ( delegate: any ToolchainRegistryDelegate , searchPaths: [ ( Path , strict: Bool ) ] , fs: any FSProxy , hostOperatingSystem: OperatingSystem ) async {
404405 self . fs = fs
406+ self . hostOperatingSystem = hostOperatingSystem
405407
406408 for (path, strict) in searchPaths {
407409 if !strict && !fs. exists ( path) {
@@ -504,8 +506,16 @@ public final class ToolchainRegistry: @unchecked Sendable {
504506 /// Look up the toolchain with the given identifier.
505507 public func lookup( _ identifier: String ) -> Toolchain ? {
506508 let lowercasedIdentifier = identifier. lowercased ( )
507- let identifier = [ " default " , " xcode " ] . contains ( lowercasedIdentifier) ? ToolchainRegistry . defaultToolchainIdentifier : identifier
508- return toolchainsByIdentifier [ identifier] ?? toolchainsByAlias [ lowercasedIdentifier]
509+ if [ " default " , " xcode " ] . contains ( lowercasedIdentifier) {
510+ if hostOperatingSystem == . macOS {
511+ return toolchainsByIdentifier [ ToolchainRegistry . defaultToolchainIdentifier] ?? toolchainsByAlias [ lowercasedIdentifier]
512+ } else {
513+ // On non-Darwin, assume if there is only one registered toolchain, it is the default.
514+ return toolchainsByIdentifier [ ToolchainRegistry . defaultToolchainIdentifier] ?? toolchainsByAlias [ lowercasedIdentifier] ?? toolchainsByIdentifier. values. only
515+ }
516+ } else {
517+ return toolchainsByIdentifier [ identifier] ?? toolchainsByAlias [ lowercasedIdentifier]
518+ }
509519 }
510520
511521 public var defaultToolchain : Toolchain ? {
0 commit comments