@@ -36,6 +36,14 @@ public final class ToolchainRegistry {
36
36
/// Mutex for registering and accessing toolchains.
37
37
var queue : DispatchQueue = DispatchQueue ( label: " toolchain-registry-queue " )
38
38
39
+ /// The currently selected toolchain identifier on Darwin.
40
+ public internal( set) lazy var darwinToolchainOverride : String ? = {
41
+ if let id = getenv ( " TOOLCHAINS " ) , !id. isEmpty, id != " default " {
42
+ return id
43
+ }
44
+ return nil
45
+ } ( )
46
+
39
47
/// Creates an empty toolchain registry.
40
48
public init ( ) { }
41
49
}
@@ -75,16 +83,16 @@ extension ToolchainRegistry {
75
83
76
84
/// The default toolchain.
77
85
///
78
- /// On Darwin, this is typically the toolchain with the identifier
79
- /// `darwinDefaultToolchainIdentifier`, i.e. the default toolchain of the active Xcode. Otherwise
80
- /// it is the first toolchain that was registered, if any.
86
+ /// On Darwin, this is typically the toolchain with the identifier `darwinToolchainIdentifier`,
87
+ /// i.e. the default toolchain of the active Xcode. Otherwise it is the first toolchain that was
88
+ /// registered, if any.
81
89
///
82
90
/// The default toolchain must be only of the registered toolchains.
83
91
public var `default` : Toolchain ? {
84
92
get {
85
93
return queue. sync {
86
94
if _default == nil {
87
- if let tc = toolchainIdentifiers [ ToolchainRegistry . darwinDefaultToolchainIdentifier ] {
95
+ if let tc = toolchainIdentifiers [ darwinToolchainIdentifier ] {
88
96
_default = tc
89
97
} else {
90
98
_default = _toolchains. first
@@ -108,10 +116,16 @@ extension ToolchainRegistry {
108
116
}
109
117
110
118
/// The standard default toolchain identifier on Darwin.
119
+ public static let darwinDefaultToolchainIdentifier : String = " com.apple.dt.toolchain.XcodeDefault "
120
+
121
+ /// The current toolchain identifier on Darwin, which is either specified byt the `TOOLCHAINS`
122
+ /// environment variable, or defaults to `darwinDefaultToolchainIdentifier`.
111
123
///
112
124
/// The value of `default.identifier` may be different if the default toolchain has been
113
- /// explicitly overridden, or if there is no toolchain with this identifier.
114
- public static let darwinDefaultToolchainIdentifier : String = " com.apple.dt.toolchain.XcodeDefault "
125
+ /// explicitly overridden in code, or if there is no toolchain with this identifier.
126
+ public var darwinToolchainIdentifier : String {
127
+ return darwinToolchainOverride ?? ToolchainRegistry . darwinDefaultToolchainIdentifier
128
+ }
115
129
116
130
/// All toolchains, in the order they were added.
117
131
public var toolchains : [ Toolchain ] {
0 commit comments