Skip to content

Commit 086c822

Browse files
Merge pull request #1712 from kateinoigakukun/yt/unlock-profile-generate-wasm
Unlock `-profile-generate` for WebAssembly targets
2 parents 5d72bf1 + 10caa6e commit 086c822

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

Sources/SwiftDriver/Jobs/WebAssemblyToolchain+LinkerSupport.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,11 @@ extension WebAssemblyToolchain {
160160
throw Error.sanitizersUnsupportedForTarget(targetTriple.triple)
161161
}
162162

163-
guard !parsedOptions.hasArgument(.profileGenerate) else {
164-
throw Error.profilingUnsupportedForTarget(targetTriple.triple)
163+
if parsedOptions.hasArgument(.profileGenerate) {
164+
let libProfile = VirtualPath.lookup(targetInfo.runtimeResourcePath.path)
165+
.appending(components: "clang", "lib", targetTriple.osName,
166+
"libclang_rt.profile-\(targetTriple.archName).a")
167+
commandLine.appendPath(libProfile)
165168
}
166169

167170
if let lto = lto {

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4430,6 +4430,27 @@ final class SwiftDriverTests: XCTestCase {
44304430
}
44314431
#endif
44324432

4433+
// -profile-generate should add libclang_rt.profile for WebAssembly targets
4434+
try withTemporaryDirectory { resourceDir in
4435+
try localFileSystem.writeFileContents(resourceDir.appending(components: "wasi", "static-executable-args.lnk")) {
4436+
$0.send("garbage")
4437+
}
4438+
4439+
for triple in ["wasm32-unknown-wasi", "wasm32-unknown-wasip1-threads"] {
4440+
var driver = try Driver(args: [
4441+
"swiftc", "-profile-generate", "-target", triple, "test.swift",
4442+
"-resource-dir", resourceDir.pathString
4443+
])
4444+
let plannedJobs = try driver.planBuild().removingAutolinkExtractJobs()
4445+
4446+
XCTAssertEqual(plannedJobs.count, 2)
4447+
XCTAssertEqual(plannedJobs[0].kind, .compile)
4448+
4449+
XCTAssertEqual(plannedJobs[1].kind, .link)
4450+
XCTAssert(plannedJobs[1].commandLine.containsPathWithBasename("libclang_rt.profile-wasm32.a"))
4451+
}
4452+
}
4453+
44334454
for explicitUseLd in [true, false] {
44344455
var args = ["swiftc", "-profile-generate", "-target", "x86_64-unknown-windows-msvc", "test.swift"]
44354456
if explicitUseLd {

0 commit comments

Comments
 (0)