@@ -612,6 +612,9 @@ public final class ProductBuildDescription {
612
612
/// The build parameters.
613
613
let buildParameters : BuildParameters
614
614
615
+ /// The file system reference.
616
+ let fs : FileSystem
617
+
615
618
/// The path to the product binary produced.
616
619
public var binary : AbsolutePath {
617
620
return buildParameters. buildPath. appending ( outname)
@@ -670,10 +673,11 @@ public final class ProductBuildDescription {
670
673
}
671
674
672
675
/// Create a build description for a product.
673
- init ( product: ResolvedProduct , buildParameters: BuildParameters ) {
676
+ init ( product: ResolvedProduct , buildParameters: BuildParameters , fs : FileSystem ) {
674
677
assert ( product. type != . library( . automatic) , " Automatic type libraries should not be described. " )
675
678
self . product = product
676
679
self . buildParameters = buildParameters
680
+ self . fs = fs
677
681
}
678
682
679
683
/// Strips the arguments which should *never* be passed to Swift compiler
@@ -759,6 +763,15 @@ public final class ProductBuildDescription {
759
763
// User arguments (from -Xlinker and -Xswiftc) should follow generated arguments to allow user overrides
760
764
args += buildParameters. linkerFlags
761
765
args += stripInvalidArguments ( buildParameters. swiftCompilerFlags)
766
+
767
+ // Add toolchain's libdir at the very end (even after the user -Xlinker arguments).
768
+ //
769
+ // This will allow linking to libraries shipped in the toolchain.
770
+ let toolchainLibDir = buildParameters. toolchain. toolchainLibDir
771
+ if fs. isDirectory ( toolchainLibDir) {
772
+ args += [ " -L " , toolchainLibDir. pathString]
773
+ }
774
+
762
775
return args
763
776
}
764
777
@@ -921,7 +934,9 @@ public class BuildPlan {
921
934
// for automatic libraries because they don't produce any output.
922
935
for product in graph. allProducts where product. type != . library( . automatic) {
923
936
productMap [ product] = ProductBuildDescription (
924
- product: product, buildParameters: buildParameters)
937
+ product: product, buildParameters: buildParameters,
938
+ fs: fileSystem
939
+ )
925
940
}
926
941
927
942
self . productMap = productMap
0 commit comments