@@ -74,54 +74,24 @@ public final class SwiftTargetBuildDescription {
74
74
self . target. sources. paths + self . derivedSources. paths + self . pluginDerivedSources. paths
75
75
}
76
76
77
- /// The list of all source files in the target, including the derived ones.
78
- private var relativeSources : [ RelativePath ] {
79
- self . target. sources. relativePaths + self . derivedSources. relativePaths + self
80
- . pluginDerivedSources. relativePaths
81
- }
82
-
83
77
/// The list of all resource files in the target, including the derived ones.
84
78
public var resources : [ Resource ] {
85
79
self . target. underlyingTarget. resources + self . pluginDerivedResources
86
80
}
87
81
88
- private var producesBitcodeObjects : Bool {
89
- get throws {
90
- try self . compileArguments ( ) . contains {
91
- // Using -lto=x will result in bitcode generation.
92
- $0. hasPrefix ( " -lto= " )
93
- // Using -embed-bitcode will result in bitcode generation.
94
- || $0 == " -embed-bitcode "
95
- }
96
- }
97
- }
98
-
99
82
/// The objects in this target, containing either machine code or bitcode
100
- /// depending on the compiler flags used.
83
+ /// depending on the build parameters used.
101
84
public var objects : [ AbsolutePath ] {
102
85
get throws {
103
- // Prefer bitcode objects over machine code objects if they are
104
- // produced.
105
- try self . producesBitcodeObjects
106
- ? self . bitcodeObjects
107
- : self . machineCodeObjects
108
- }
109
- }
110
-
111
- /// The machine code objects in this target.
112
- private var machineCodeObjects : [ AbsolutePath ] {
113
- get throws {
114
- try self . relativeSources. map {
115
- try AbsolutePath ( validating: " \( $0. pathString) .o " , relativeTo: tempsPath)
116
- }
117
- }
118
- }
119
-
120
- /// The bitcode objects in this target.
121
- private var bitcodeObjects : [ AbsolutePath ] {
122
- get throws {
123
- try self . relativeSources. map {
124
- try AbsolutePath ( validating: " \( $0. pathString) .bc " , relativeTo: tempsPath)
86
+ let relativeSources = self . target. sources. relativePaths
87
+ + self . derivedSources. relativePaths
88
+ + self . pluginDerivedSources. relativePaths
89
+ let ltoEnabled = self . buildParameters. linkTimeOptimizationMode != nil
90
+ let objectFileExtension = ltoEnabled ? " bc " : " o "
91
+ return try relativeSources. map {
92
+ try AbsolutePath (
93
+ validating: " \( $0. pathString) . \( objectFileExtension) " ,
94
+ relativeTo: self . tempsPath)
125
95
}
126
96
}
127
97
}
@@ -548,6 +518,16 @@ public final class SwiftTargetBuildDescription {
548
518
// // User arguments (from -Xcxx) should follow generated arguments to allow user overrides
549
519
// args += self.buildParameters.flags.cxxCompilerFlags.asSwiftcCXXCompilerFlags()
550
520
521
+ // Enable the correct lto mode if requested.
522
+ switch self . buildParameters. linkTimeOptimizationMode {
523
+ case nil :
524
+ break
525
+ case . full:
526
+ args += [ " -lto=llvm-full " ]
527
+ case . thin:
528
+ args += [ " -lto=llvm-thin " ]
529
+ }
530
+
551
531
// suppress warnings if the package is remote
552
532
if self . package . isRemote {
553
533
args += [ " -suppress-warnings " ]
@@ -716,6 +696,16 @@ public final class SwiftTargetBuildDescription {
716
696
// // User arguments (from -Xcxx) should follow generated arguments to allow user overrides
717
697
// result += self.buildParameters.flags.cxxCompilerFlags.asSwiftcCXXCompilerFlags()
718
698
699
+ // Enable the correct lto mode if requested.
700
+ switch self . buildParameters. linkTimeOptimizationMode {
701
+ case nil :
702
+ break
703
+ case . full:
704
+ result += [ " -lto=llvm-full " ]
705
+ case . thin:
706
+ result += [ " -lto=llvm-thin " ]
707
+ }
708
+
719
709
result += try self . macroArguments ( )
720
710
return result
721
711
}
@@ -766,13 +756,13 @@ public final class SwiftTargetBuildDescription {
766
756
767
757
// Write out the entries for each source file.
768
758
let sources = self . sources
769
- let machineCodeObjects = try self . machineCodeObjects
770
- let bitcodeObjects = try self . bitcodeObjects
759
+ let objects = try self . objects
760
+ let ltoEnabled = self . buildParameters. linkTimeOptimizationMode != nil
761
+ let objectKey = ltoEnabled ? " llvm-bc " : " object "
771
762
772
763
for idx in 0 ..< sources. count {
773
764
let source = sources [ idx]
774
- let machineCodeObject = machineCodeObjects [ idx]
775
- let bitcodeObject = bitcodeObjects [ idx]
765
+ let object = objects [ idx]
776
766
777
767
let sourceFileName = source. basenameWithoutExt
778
768
let partialModulePath = self . tempsPath. appending ( component: sourceFileName + " ~partial.swiftmodule " )
@@ -794,11 +784,9 @@ public final class SwiftTargetBuildDescription {
794
784
// FIXME: Need to record this deps file for processing it later.
795
785
}
796
786
797
-
798
787
content +=
799
788
#"""
800
- "object": " \#( machineCodeObject. _nativePathString ( escaped: true ) ) ",
801
- "llvm-bc": " \#( bitcodeObject. _nativePathString ( escaped: true ) ) ",
789
+ " \#( objectKey) ": " \#( object. _nativePathString ( escaped: true ) ) ",
802
790
"swiftmodule": " \#( partialModulePath. _nativePathString ( escaped: true ) ) ",
803
791
"swift-dependencies": " \#( swiftDepsPath. _nativePathString ( escaped: true ) ) "
804
792
} \#( ( idx + 1 ) < sources. count ? " , " : " " )
0 commit comments