@@ -37,6 +37,17 @@ public enum CanImportVersion {
3737 case underlyingVersion( VersionTuple )
3838}
3939
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+
4051/// Captures information about the build configuration that can be
4152/// queried in a `#if` expression, including OS, compiler version,
4253/// enabled language features, and available modules.
@@ -214,6 +225,22 @@ public protocol BuildConfiguration {
214225 /// pointer authentication scheme.
215226 func isActiveTargetPointerAuthentication( name: String ) throws -> Bool
216227
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+
217244 /// The bit width of a data pointer for the target architecture.
218245 ///
219246 /// The target's pointer bit width (which also corresponds to the number of
@@ -276,3 +303,13 @@ public protocol BuildConfiguration {
276303 /// #endif
277304 var compilerVersion : VersionTuple { get }
278305}
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