@@ -16,6 +16,7 @@ import PackageGraph
16
16
import PackageLoading
17
17
import Foundation
18
18
import SPMBuildCore
19
+ @_implementationOnly import SwiftDriver
19
20
20
21
extension String {
21
22
fileprivate var asSwiftStringLiteralConstant : String {
@@ -690,7 +691,17 @@ public final class SwiftTargetBuildDescription {
690
691
let path = derivedSources. root. appending ( subpath)
691
692
try fs. writeIfChanged ( path: path, bytes: stream. bytes)
692
693
}
693
-
694
+
695
+ public static func checkSupportedFrontendFlags( flags: Set < String > , fs: FileSystem ) -> Bool {
696
+ do {
697
+ let executor = try SPMSwiftDriverExecutor ( resolver: ArgsResolver ( fileSystem: fs) , fileSystem: fs, env: [ : ] )
698
+ let driver = try Driver ( args: [ " swiftc " ] , executor: executor)
699
+ return driver. supportedFrontendFlags. intersection ( flags) == flags
700
+ } catch {
701
+ return false
702
+ }
703
+ }
704
+
694
705
/// The arguments needed to compile this target.
695
706
public func compileArguments( ) -> [ String ] {
696
707
var args = [ String] ( )
@@ -733,8 +744,12 @@ public final class SwiftTargetBuildDescription {
733
744
// can construct the linker flags. In the future we will use a generated
734
745
// code stub for the cases in which the linker doesn't support it, so that
735
746
// we can rename the symbol unconditionally.
736
- if buildParameters. linkerFlagsForRenamingMainFunction ( of: target) != nil {
737
- args += [ " -Xfrontend " , " -entry-point-function-name " , " -Xfrontend " , " \( target. c99name) _main " ]
747
+ // No `-` for these flags because the set of Strings in driver.supportedFrontendFlags do
748
+ // not have a leading `-`
749
+ if SwiftTargetBuildDescription . checkSupportedFrontendFlags ( flags: [ " entry-point-function-name " ] , fs: self . fs) {
750
+ if buildParameters. linkerFlagsForRenamingMainFunction ( of: target) != nil {
751
+ args += [ " -Xfrontend " , " -entry-point-function-name " , " -Xfrontend " , " \( target. c99name) _main " ]
752
+ }
738
753
}
739
754
}
740
755
@@ -2080,7 +2095,7 @@ private func generateResourceInfoPlist(
2080
2095
return true
2081
2096
}
2082
2097
2083
- fileprivate extension Triple {
2098
+ fileprivate extension TSCUtility . Triple {
2084
2099
var isSupportingStaticStdlib : Bool {
2085
2100
isLinux ( ) || arch == . wasm32
2086
2101
}
0 commit comments