Skip to content

Commit 3208d49

Browse files
authored
Merge pull request #1258 from artemcm/EmitFeaturesInProcessAgain
Use libSwiftScan to query supported compiler flags in-process
2 parents 51a6c26 + 8267d18 commit 3208d49

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

Sources/SwiftDriver/Jobs/EmitSupportedFeaturesJob.swift

Lines changed: 27 additions & 18 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
@@ -58,25 +58,17 @@ extension Toolchain {
5858

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

79-
// Invoke `swift-frontend -emit-supported-features`
71+
// Fallback: Invoke `swift-frontend -emit-supported-features` and decode the output
8072
let frontendOverride = try FrontendOverride(&parsedOptions, diagnosticsEngine)
8173
frontendOverride.setUpForTargetInfo(toolchain)
8274
defer { frontendOverride.setUpForCompilation(toolchain) }
@@ -91,6 +83,23 @@ extension Driver {
9183
return Set(decodedSupportedFlagList)
9284
}
9385

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

0 commit comments

Comments
 (0)