Add wasm32-unknown-emscripten triple support#2105
Conversation
|
@swift-ci test |
|
Can you also add support for this platform in Swift Build's SWBWebAssembly plugin? |
Done in swiftlang/swift-build#1335 |
|
@swift-ci test |
c232995 to
d8ce09e
Compare
|
@swift-ci test |
|
@swift-ci test windows |
|
|
||
| public let dummyForTestingObjectFormat = Triple.ObjectFormat.wasm | ||
|
|
||
| public var targetTriple: Triple? |
There was a problem hiding this comment.
Could we parameterize makeLinkerOutputFilename instead? Even though it means updating unrelated toolchains, I'd rather we thread the triple to the decision point where we need it, instead of this kind of mutable state that's post-hoc initialized.
There was a problem hiding this comment.
Creating a separate EmscriptenToolchain should address this as well.
| components: "embedded", targetTriple.triple | ||
| ) | ||
| commandLine.append(.flag("-Xlinker")) | ||
| if !isEmscripten { |
There was a problem hiding this comment.
I don't know if I have a better suggestion, but it feels a bit unwieldy to special case things like this. Would there be too much duplication if we factor out the emcc code path out of here?
There was a problem hiding this comment.
Addressed by creating separate EmscriptenToolchain.
|
@swift-ci test |
|
@swift-ci test windows |
| commandLine.appendFlag(linkerOpt.argument.asSingle) | ||
| } | ||
| // `-Xemcc-linker` passes arguments directly to `emcc`. | ||
| try commandLine.appendAllArguments(.XemccLinker, from: &parsedOptions) |
There was a problem hiding this comment.
If we pass -Xemcc-linker values to emcc, then I'm wondering if we really need a separate option name for emcc. Can't we just use -Xclang-linker? We can treat it just like "X flag for linker driver, not the linker itself" rather than strictly treating it only for "clang linker driver". emcc is meant to be used as drop-in-replacement as clang command, so this model should work I believe. Otherwise the build invoker has to switch the option based on if a target is emscripten or not, which is something I'm not a big fan of.
There was a problem hiding this comment.
It's not a drop-in replacement unfortunately, flags and options it supports differ substantially. I think keeping -Xclang-linker for it would be very confusing, as very few of the existing options work and require explicit updates. I'm totally fine with introducing -Xlinker-driver separately though.
There was a problem hiding this comment.
It's not a drop-in replacement unfortunately, flags and options it supports differ substantially.
Oh, really. I know many options specific to emcc but don't know much about clang options not working for emcc. Do you have examples?
There was a problem hiding this comment.
I know of at least 3 cases that break or warn:
-resource-dir PATHand--sysroot PATH:emcchas a silent flag-drop: it swallows the flag word but lets the path leak as a positional input leading towasm-ld: error: cannot open PATH: Is a directory. Same bug hits-B PATH. Joined forms work.-nostdlib: accepted but semantically incompatible (emcc's runtime needs symbols-nostdlibdrops)-Wl,-z,max-page-size=16384:wasm-ldwarns and no-ops
As for the asymmetry: emcc-only flags like -sENVIRONMENT=shell, --shell-file= are hard errors under clang (unknown argument).
| public static let Wwarning: Option = Option("-Wwarning", .separate, attributes: [.helpHidden, .frontend], metaVar: "<diagnostic_group>", helpText: "Treat this warning group as warning", group: .warningTreating) | ||
| public static let Xcc: Option = Option("-Xcc", .separate, attributes: [.frontend, .synthesizeInterface], metaVar: "<arg>", helpText: "Pass <arg> to the C/C++/Objective-C compiler") | ||
| public static let XclangLinker: Option = Option("-Xclang-linker", .separate, attributes: [.helpHidden], metaVar: "<arg>", helpText: "Pass <arg> to Clang when it is used for linking.") | ||
| public static let XemccLinker: Option = Option("-Xemcc-linker", .separate, attributes: [.helpHidden], metaVar: "<arg>", helpText: "Pass <arg> to emcc when it is used for linking.") |
There was a problem hiding this comment.
A reminder to follow the process here:
https://github.com/swiftlang/swift-driver#rebuilding-optionsswift
| ) | ||
|
|
||
| // `emcc` supports `-Xlinker` for passing flags to `wasm-ld`, but | ||
| // `-Xclang-linker` is `clang`-specific and must not be forwarded. |
There was a problem hiding this comment.
Should we warn when -Xclang-linker is used and we are on the emcc code path, instead of dropping them silently?
There was a problem hiding this comment.
It does emit a working in EmscriptenToolchain validation function, I've updated this comment to mention that in #2136
|
|
||
| // Delegate to Clang for sanitizers. It will figure out the correct linker | ||
| // options. | ||
| if linkerOutputType == .executable && !sanitizers.isEmpty { |
There was a problem hiding this comment.
From what I can tell, in the code as-is, linkerOutputType == .executable is always going to be true. Do we think that can change in the future? If not, do we still need linkerOutputType here?
|
Ah, sorry about the auto-merge that I forgot to disable, I'll submit a follow up PR! |
One of the necessary steps for implementing the Emscripten pitch: https://forums.swift.org/t/pitch-emscripten-target-support-for-swift/85310.
Depends on swiftlang/swift#88732