Skip to content

Use libSwiftScan to query supported compiler flags in-process #1258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 27 additions & 18 deletions Sources/SwiftDriver/Jobs/EmitSupportedFeaturesJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import SwiftOptions
import struct Foundation.Data
import class Foundation.JSONDecoder

import struct TSCBasic.Diagnostic
import class TSCBasic.DiagnosticsEngine
import protocol TSCBasic.FileSystem
import struct TSCBasic.RelativePath
Expand Down Expand Up @@ -58,25 +58,17 @@ extension Toolchain {

extension Driver {
static func computeSupportedCompilerArgs(of toolchain: Toolchain, hostTriple: Triple,
parsedOptions: inout ParsedOptions,
diagnosticsEngine: DiagnosticsEngine,
fileSystem: FileSystem,
executor: DriverExecutor, env: [String: String])
parsedOptions: inout ParsedOptions,
diagnosticsEngine: DiagnosticsEngine,
fileSystem: FileSystem,
executor: DriverExecutor, env: [String: String])
throws -> Set<String> {
// TODO: Once we are sure libSwiftScan is deployed across supported platforms and architectures
// we should deploy it here.
// let swiftScanLibPath = try Self.getScanLibPath(of: toolchain,
// hostTriple: hostTriple,
// env: env)
//
// if fileSystem.exists(swiftScanLibPath) {
// let libSwiftScanInstance = try SwiftScan(dylib: swiftScanLibPath)
// if libSwiftScanInstance.canQuerySupportedArguments() {
// return try libSwiftScanInstance.querySupportedArguments()
// }
// }
if let supportedArgs = try querySupportedCompilerArgsInProcess(of: toolchain, hostTriple: hostTriple,
fileSystem: fileSystem, env: env) {
return supportedArgs
}

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

static func querySupportedCompilerArgsInProcess(of toolchain: Toolchain,
hostTriple: Triple,
fileSystem: FileSystem,
env: [String: String])
throws -> Set<String>? {
let swiftScanLibPath = try Self.getScanLibPath(of: toolchain,
hostTriple: hostTriple,
env: env)
if fileSystem.exists(swiftScanLibPath) {
let libSwiftScanInstance = try SwiftScan(dylib: swiftScanLibPath)
if libSwiftScanInstance.canQuerySupportedArguments() {
return try libSwiftScanInstance.querySupportedArguments()
}
}
return nil
}

static func computeSupportedCompilerFeatures(of toolchain: Toolchain,
env: [String: String]) throws -> Set<String> {
struct FeatureInfo: Codable {
Expand Down