Skip to content

Fix build of host&target destination products with --static-swift-stdlib #7695

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
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription

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

/// Path to the link filelist file.
Expand Down
2 changes: 2 additions & 0 deletions Tests/BuildTests/LLBuildManifestBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -218,5 +218,7 @@ final class LLBuildManifestBuilderTests: XCTestCase {
let manifest = try builder.generateManifest(at: "/manifest")

XCTAssertNotNil(manifest.commands["C.SwiftSyntax-aarch64-unknown-linux-gnu-debug-tool.module"])
// Ensure that Objects.LinkFileList is -tool suffixed.
XCTAssertNotNil(manifest.commands["/path/to/build/aarch64-unknown-linux-gnu/debug/MMIOMacros-tool.product/Objects.LinkFileList"])
}
}
27 changes: 26 additions & 1 deletion Tests/CommandsTests/PackageCommandTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,30 @@ final class PackageCommandTests: CommandsTestCase {
}

func testBuildToolPlugin() async throws {
try await testBuildToolPlugin(staticStdlib: false)
}

func testBuildToolPluginWithStaticStdlib() async throws {
// Skip if the toolchain cannot compile a simple program with static stdlib.
do {
let args = try [
UserToolchain.default.swiftCompilerPath.pathString,
"-static-stdlib", "-emit-executable", "-o", "/dev/null", "-"
]
let process = AsyncProcess(arguments: args)
let stdin = try process.launch()
stdin.write(sequence: "".utf8)
try stdin.close()
let result = try await process.waitUntilExit()
try XCTSkipIf(
result.exitStatus != .terminated(code: 0),
"skipping because static stdlib is not supported by the toolchain"
)
}
try await testBuildToolPlugin(staticStdlib: true)
}

func testBuildToolPlugin(staticStdlib: Bool) async throws {
// Only run the test if the environment in which we're running actually supports Swift concurrency (which the plugin APIs require).
try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency")

Expand Down Expand Up @@ -1647,7 +1671,8 @@ final class PackageCommandTests: CommandsTestCase {
)

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

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