@@ -37,6 +37,17 @@ public enum CanImportVersion {
37
37
case underlyingVersion( VersionTuple )
38
38
}
39
39
40
+ enum BuildConfigurationError : Error , CustomStringConvertible {
41
+ case experimentalFeature( name: String )
42
+
43
+ var description : String {
44
+ switch self {
45
+ case . experimentalFeature( let name) :
46
+ return " 'name' is an experimental feature "
47
+ }
48
+ }
49
+ }
50
+
40
51
/// Captures information about the build configuration that can be
41
52
/// queried in a `#if` expression, including OS, compiler version,
42
53
/// enabled language features, and available modules.
@@ -214,6 +225,22 @@ public protocol BuildConfiguration {
214
225
/// pointer authentication scheme.
215
226
func isActiveTargetPointerAuthentication( name: String ) throws -> Bool
216
227
228
+ /// Determine whether the given name is the active target object file format (e.g., ELF).
229
+ ///
230
+ /// The target object file format can only be queried by an experimental
231
+ /// syntax `_objectFileFormat(<name>)`, e.g.,
232
+ ///
233
+ /// ```swift
234
+ /// #if _objectFileFormat(ELF)
235
+ /// // Special logic for ELF object file formats
236
+ /// #endif
237
+ /// ```
238
+ /// - Parameters:
239
+ /// - name: The name of the object file format.
240
+ /// - Returns: Whether the target object file format matches the given name.
241
+ @_spi ( ExperimentalLanguageFeatures)
242
+ func isActiveTargetObjectFileFormat( name: String ) throws -> Bool
243
+
217
244
/// The bit width of a data pointer for the target architecture.
218
245
///
219
246
/// The target's pointer bit width (which also corresponds to the number of
@@ -276,3 +303,13 @@ public protocol BuildConfiguration {
276
303
/// #endif
277
304
var compilerVersion : VersionTuple { get }
278
305
}
306
+
307
+ /// Default implementation of BuildConfiguration, to avoid a revlock with the
308
+ /// swift repo, and breaking clients with the new addition to the protocol.
309
+ extension BuildConfiguration {
310
+ /// FIXME: This should be @_spi(ExperimentalLanguageFeatures) but cannot due
311
+ /// to rdar://147943518, https://github.com/swiftlang/swift/issues/80313
312
+ public func isActiveTargetObjectFileFormat( name: String ) throws -> Bool {
313
+ throw BuildConfigurationError . experimentalFeature ( name: " _objectFileFormat " )
314
+ }
315
+ }
0 commit comments