@@ -389,6 +389,7 @@ extension Array where Element == Toolchain {
389
389
/// The ToolchainRegistry manages the set of registered toolchains.
390
390
public final class ToolchainRegistry : @unchecked Sendable {
391
391
let fs : any FSProxy
392
+ let hostOperatingSystem : OperatingSystem
392
393
393
394
/// The map of toolchains by identifier.
394
395
@_spi ( Testing) public private( set) var toolchainsByIdentifier = Dictionary < String , Toolchain > ( )
@@ -402,6 +403,7 @@ public final class ToolchainRegistry: @unchecked Sendable {
402
403
403
404
@_spi ( Testing) public init ( delegate: any ToolchainRegistryDelegate , searchPaths: [ ( Path , strict: Bool ) ] , fs: any FSProxy , hostOperatingSystem: OperatingSystem ) async {
404
405
self . fs = fs
406
+ self . hostOperatingSystem = hostOperatingSystem
405
407
406
408
for (path, strict) in searchPaths {
407
409
if !strict && !fs. exists ( path) {
@@ -504,8 +506,16 @@ public final class ToolchainRegistry: @unchecked Sendable {
504
506
/// Look up the toolchain with the given identifier.
505
507
public func lookup( _ identifier: String ) -> Toolchain ? {
506
508
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
+ }
509
519
}
510
520
511
521
public var defaultToolchain : Toolchain ? {
0 commit comments