Skip to content

Commit d9f0025

Browse files
committed
Use libSwiftScan to query supported compiler flags in-process
1 parent cee8c66 commit d9f0025

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

Sources/SwiftDriver/Jobs/EmitSupportedFeaturesJob.swift

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,19 @@ extension Toolchain {
5757
}
5858

5959
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])
60+
static func computeSupportedCompilerArgs(of toolchain: Toolchain,
61+
hostTriple: Triple,
62+
parsedOptions: inout ParsedOptions,
63+
diagnosticsEngine: DiagnosticsEngine,
64+
fileSystem: FileSystem,
65+
executor: DriverExecutor, env: [String: String])
6566
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-
// }
67+
if let supportedArgs = try querySupportedCompilerArgsInProcess(of: toolchain, hostTriple: hostTriple,
68+
fileSystem: fileSystem, env: env) {
69+
return supportedArgs
70+
}
7871

79-
// Invoke `swift-frontend -emit-supported-features`
72+
// Fallback: Invoke `swift-frontend -emit-supported-features` and decode the output
8073
let frontendOverride = try FrontendOverride(&parsedOptions, diagnosticsEngine)
8174
frontendOverride.setUpForTargetInfo(toolchain)
8275
defer { frontendOverride.setUpForCompilation(toolchain) }
@@ -91,6 +84,23 @@ extension Driver {
9184
return Set(decodedSupportedFlagList)
9285
}
9386

87+
static func querySupportedCompilerArgsInProcess(of toolchain: Toolchain,
88+
hostTriple: Triple,
89+
fileSystem: FileSystem,
90+
env: [String: String])
91+
throws -> Set<String>? {
92+
let swiftScanLibPath = try Self.getScanLibPath(of: toolchain,
93+
hostTriple: hostTriple,
94+
env: env)
95+
if fileSystem.exists(swiftScanLibPath) {
96+
let libSwiftScanInstance = try SwiftScan(dylib: swiftScanLibPath)
97+
if libSwiftScanInstance.canQuerySupportedArguments() {
98+
return try libSwiftScanInstance.querySupportedArguments()
99+
}
100+
}
101+
return nil
102+
}
103+
94104
static func computeSupportedCompilerFeatures(of toolchain: Toolchain,
95105
env: [String: String]) throws -> Set<String> {
96106
struct FeatureInfo: Codable {

0 commit comments

Comments
 (0)