Skip to content

Commit eff859e

Browse files
committed
Use libSwiftScan to query supported compiler flags in-process
1 parent 3e33739 commit eff859e

File tree

1 file changed

+36
-19
lines changed

1 file changed

+36
-19
lines changed

Sources/SwiftDriver/Jobs/EmitSupportedFeaturesJob.swift

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import SwiftOptions
1414
import struct Foundation.Data
1515
import class Foundation.JSONDecoder
16-
16+
import struct TSCBasic.Diagnostic
1717
import class TSCBasic.DiagnosticsEngine
1818
import protocol TSCBasic.FileSystem
1919
import struct TSCBasic.RelativePath
@@ -56,27 +56,27 @@ extension Toolchain {
5656
}
5757
}
5858

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+
5965
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])
6572
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+
}
7877

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())
8080
let frontendOverride = try FrontendOverride(&parsedOptions, diagnosticsEngine)
8181
frontendOverride.setUpForTargetInfo(toolchain)
8282
defer { frontendOverride.setUpForCompilation(toolchain) }
@@ -91,6 +91,23 @@ extension Driver {
9191
return Set(decodedSupportedFlagList)
9292
}
9393

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+
94111
static func computeSupportedCompilerFeatures(of toolchain: Toolchain,
95112
env: [String: String]) throws -> Set<String> {
96113
struct FeatureInfo: Codable {

0 commit comments

Comments
 (0)