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 @@ -160,8 +160,11 @@ extension WebAssemblyToolchain {
throw Error.sanitizersUnsupportedForTarget(targetTriple.triple)
}

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

if let lto = lto {
Expand Down
21 changes: 21 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4463,6 +4463,27 @@ final class SwiftDriverTests: XCTestCase {
}
#endif

// -profile-generate should add libclang_rt.profile for WebAssembly targets
try withTemporaryDirectory { resourceDir in
try localFileSystem.writeFileContents(resourceDir.appending(components: "wasi", "static-executable-args.lnk")) {
$0.send("garbage")
}

for triple in ["wasm32-unknown-wasi", "wasm32-unknown-wasip1-threads"] {
var driver = try Driver(args: [
"swiftc", "-profile-generate", "-target", triple, "test.swift",
"-resource-dir", resourceDir.pathString
])
let plannedJobs = try driver.planBuild().removingAutolinkExtractJobs()

XCTAssertEqual(plannedJobs.count, 2)
XCTAssertEqual(plannedJobs[0].kind, .compile)

XCTAssertEqual(plannedJobs[1].kind, .link)
XCTAssert(plannedJobs[1].commandLine.containsPathWithBasename("libclang_rt.profile-wasm32.a"))
}
}

for explicitUseLd in [true, false] {
var args = ["swiftc", "-profile-generate", "-target", "x86_64-unknown-windows-msvc", "test.swift"]
if explicitUseLd {
Expand Down