13
13
import SwiftOptions
14
14
import struct Foundation. Data
15
15
import class Foundation. JSONDecoder
16
-
16
+ import struct TSCBasic . Diagnostic
17
17
import class TSCBasic. DiagnosticsEngine
18
18
import protocol TSCBasic. FileSystem
19
19
import struct TSCBasic. RelativePath
@@ -56,27 +56,27 @@ extension Toolchain {
56
56
}
57
57
}
58
58
59
+ extension Diagnostic . Message {
60
+ static func warn_supported_features_frontend_fallback( ) -> Diagnostic . Message {
61
+ . warning( " Fallback to `swift-frontend` for supported compiler features query " )
62
+ }
63
+ }
64
+
59
65
extension Driver {
60
- static func computeSupportedCompilerArgs( of toolchain: Toolchain , hostTriple: Triple ,
61
- parsedOptions: inout ParsedOptions ,
62
- diagnosticsEngine: DiagnosticsEngine ,
63
- fileSystem: FileSystem ,
64
- executor: DriverExecutor , env: [ String : String ] )
66
+ static func computeSupportedCompilerArgs( of toolchain: Toolchain ,
67
+ hostTriple: Triple ,
68
+ parsedOptions: inout ParsedOptions ,
69
+ diagnosticsEngine: DiagnosticsEngine ,
70
+ fileSystem: FileSystem ,
71
+ executor: DriverExecutor , env: [ String : String ] )
65
72
throws -> Set < String > {
66
- // TODO: Once we are sure libSwiftScan is deployed across supported platforms and architectures
67
- // we should deploy it here.
68
- // let swiftScanLibPath = try Self.getScanLibPath(of: toolchain,
69
- // hostTriple: hostTriple,
70
- // env: env)
71
- //
72
- // if fileSystem.exists(swiftScanLibPath) {
73
- // let libSwiftScanInstance = try SwiftScan(dylib: swiftScanLibPath)
74
- // if libSwiftScanInstance.canQuerySupportedArguments() {
75
- // return try libSwiftScanInstance.querySupportedArguments()
76
- // }
77
- // }
73
+ if let supportedArgs = try querySupportedCompilerArgsInProcess ( of: toolchain, hostTriple: hostTriple,
74
+ fileSystem: fileSystem, env: env) {
75
+ return supportedArgs
76
+ }
78
77
79
- // Invoke `swift-frontend -emit-supported-features`
78
+ // Fallback: Invoke `swift-frontend -emit-supported-features` and decode the output
79
+ diagnosticsEngine. emit ( . warn_supported_features_frontend_fallback( ) )
80
80
let frontendOverride = try FrontendOverride ( & parsedOptions, diagnosticsEngine)
81
81
frontendOverride. setUpForTargetInfo ( toolchain)
82
82
defer { frontendOverride. setUpForCompilation ( toolchain) }
@@ -91,6 +91,23 @@ extension Driver {
91
91
return Set ( decodedSupportedFlagList)
92
92
}
93
93
94
+ static func querySupportedCompilerArgsInProcess( of toolchain: Toolchain ,
95
+ hostTriple: Triple ,
96
+ fileSystem: FileSystem ,
97
+ env: [ String : String ] )
98
+ throws -> Set < String > ? {
99
+ let swiftScanLibPath = try Self . getScanLibPath ( of: toolchain,
100
+ hostTriple: hostTriple,
101
+ env: env)
102
+ if fileSystem. exists ( swiftScanLibPath) {
103
+ let libSwiftScanInstance = try SwiftScan ( dylib: swiftScanLibPath)
104
+ if libSwiftScanInstance. canQuerySupportedArguments ( ) {
105
+ return try libSwiftScanInstance. querySupportedArguments ( )
106
+ }
107
+ }
108
+ return nil
109
+ }
110
+
94
111
static func computeSupportedCompilerFeatures( of toolchain: Toolchain ,
95
112
env: [ String : String ] ) throws -> Set < String > {
96
113
struct FeatureInfo : Codable {
0 commit comments