Skip to content
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 @@ -122,15 +122,6 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
return ["-Xlinker", "-dead_strip"]
} else if triple.isWindows() {
return ["-Xlinker", "/OPT:REF"]
} else if triple.arch == .wasm32 {
// FIXME: wasm-ld strips data segments referenced through __start/__stop symbols
// during GC, and it removes Swift metadata sections like swift5_protocols
// We should add support of SHF_GNU_RETAIN-like flag for __attribute__((retain))
// to LLVM and wasm-ld
// This workaround is required for not only WASI but also all WebAssembly triples
// using wasm-ld (e.g. wasm32-unknown-unknown). So this branch is conditioned by
// arch == .wasm32
return []
} else {
return ["-Xlinker", "--gc-sections"]
}
Expand Down
33 changes: 33 additions & 0 deletions Tests/BuildTests/CrossCompilationBuildPlanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,39 @@ final class CrossCompilationBuildPlanTests: XCTestCase {
)
}

func testWasmTargetRelease() throws {
let pkgPath = AbsolutePath("/Pkg")

let (graph, fs, observabilityScope) = try trivialPackageGraph(pkgRootPath: pkgPath)

var parameters = mockBuildParameters(
config: .release, targetTriple: .wasi, linkerDeadStrip: true
)
parameters.linkingParameters.shouldLinkStaticSwiftStdlib = true
let result = try BuildPlanResult(plan: BuildPlan(
buildParameters: parameters,
graph: graph,
fileSystem: fs,
observabilityScope: observabilityScope
))
let buildPath = result.plan.productsBuildPath

let appBuildDescription = try result.buildProduct(for: "app")
XCTAssertEqual(
try appBuildDescription.linkArguments(),
[
result.plan.destinationBuildParameters.toolchain.swiftCompilerPath.pathString,
"-L", buildPath.pathString,
"-o", buildPath.appending(components: "app.wasm").pathString,
"-module-name", "app", "-static-stdlib", "-emit-executable",
"-Xlinker", "--gc-sections",
"@\(buildPath.appending(components: "app.product", "Objects.LinkFileList"))",
"-target", "wasm32-unknown-wasi",
"-g",
]
)
}

func testWASITarget() throws {
let pkgPath = AbsolutePath("/Pkg")

Expand Down