Skip to content

Commit b2fd9a4

Browse files
Fix build of host&target destination products with --static-swift-stdlib
Given the following conditions: - `--static-swift-stdlib` is enabled (it only affects "target" destination products, "host" destination products are always dynamic) - the building subset contains both "host" and "target" destination products derived from the same product. - the product imports `Foundation` (that has private dependency libs) then the build randomly failed due to the race condition of the Objects.LinkFileList creation. This commit fixes the issue by distinguishing the temporary link file list response file name by the `-tool` suffix.
1 parent 71d4407 commit b2fd9a4

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Sources/Build/BuildDescription/ProductBuildDescription.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
6666

6767
/// Path to the temporary directory for this product.
6868
var tempsPath: AbsolutePath {
69-
self.buildParameters.buildPath.appending(component: self.product.name + ".product")
69+
let suffix = buildParameters.suffix
70+
return self.buildParameters.buildPath.appending(component: "\(self.product.name)\(suffix).product")
7071
}
7172

7273
/// Path to the link filelist file.

Tests/CommandsTests/PackageCommandTests.swift

+10-1
Original file line numberDiff line numberDiff line change
@@ -1574,6 +1574,14 @@ final class PackageCommandTests: CommandsTestCase {
15741574
}
15751575

15761576
func testBuildToolPlugin() throws {
1577+
try testBuildToolPlugin(staticStdlib: false)
1578+
}
1579+
1580+
func testBuildToolPluginWithStaticStdlib() throws {
1581+
try testBuildToolPlugin(staticStdlib: true)
1582+
}
1583+
1584+
func testBuildToolPlugin(staticStdlib: Bool) throws {
15771585
// Only run the test if the environment in which we're running actually supports Swift concurrency (which the plugin APIs require).
15781586
try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency")
15791587

@@ -1647,7 +1655,8 @@ final class PackageCommandTests: CommandsTestCase {
16471655
)
16481656

16491657
// Invoke it, and check the results.
1650-
let (stdout, stderr) = try SwiftPM.Build.execute(packagePath: packageDir)
1658+
let args = staticStdlib ? ["--static-swift-stdlib"] : []
1659+
let (stdout, stderr) = try SwiftPM.Build.execute(args, packagePath: packageDir)
16511660
XCTAssert(stdout.contains("Build complete!"))
16521661

16531662
// We expect a warning about `library.bar` but not about `library.foo`.

0 commit comments

Comments
 (0)