-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Make wasm32 buildbot test LLVM backend #42784
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @aturon (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
The only thing this PR is missing to make the wasm32 builder fully functional is that clang (https://github.com/kripken/emscripten-fastcomp-clang/tree/incoming) needs to be in the src/llvm/tools directory so that emscripten can build the wasm libc bitcode files. It would be great if we could instead have a binary download to populate the emscripten cache or some other workaround, since having clang in-tree is undesirable. Edit: I am exploring having the builder download a wasm-ready emscripten from the WebAssembly waterfall (https://wasm-stat.us/console) as a workaround. |
@@ -20,7 +20,7 @@ RUN sh /scripts/dumb-init.sh | |||
# emscripten | |||
COPY scripts/emscripten.sh /scripts/ | |||
RUN bash /scripts/emscripten.sh | |||
COPY wasm32/node.sh /usr/local/bin/node | |||
COPY disabled/wasm32/node.sh /usr/local/bin/node |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would have to be changed if the builder was ever moved out of the docker/disabled directory, but for now lets the builder be run locally without modification.
src/tools/compiletest/src/runtest.rs
Outdated
let mut env = self.props.rustc_env.clone(); | ||
// Tell emscripten to link using libc produced with LLVM backend | ||
if self.config.target.contains("wasm32") && self.config.target.contains("experimental") { | ||
env.push(("EMCC_WASM_BACKEND".to_string(), "1".to_string())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this something that rustc should do automatically itself? (when compiling for the experimental wasm target)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this environment variable set, Emscripten tries to link the wasm bitcode file with the cached libc bitcode files for asmjs, which fails because asmjs and wasm have different memory layouts. Since this isn't just a debugging variable, rustc should definitely be setting it itself. When/if wasm32-experimental-emscripten is renamed to replace wasm32-unknown-emscripten, the part checking for "experimental" will need to be removed. It can't be removed now because then the current wasm32-unknown-emscripten would break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah sure having this is fine, it just seems like it should be in rustc's backend (e.g. the invocation of the linker) rather than only in compiletest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh good point! I'll fix that for the next revision.
src/ci/docker/scripts/emscripten.sh
Outdated
rm -f a.* | ||
|
||
# Make emscripten use Rust's LLVM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind expanding the comment here a bit? I'm actually not even sure what it means for emscripten to use someone else's llvm, isn't it precompiled?
|
||
ENV RUST_CONFIGURE_ARGS --target=$TARGETS | ||
ENV RUST_CONFIGURE_ARGS --target=$TARGETS --experimental-targets=WebAssembly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is problematic because as far as I know, rustc and LLVM aren't rebuilt for each bot. To actually get LLVM built with WebAssembly enabled will require setting this flag when it is built the first time. Is there a specific builder that is responsible for that initial build?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We rebuild LLVM and rustc in each bot. The LLVM build will possibly be problematic, since we normally cache it, so with this I'm not sure whether the cache will work properly for both the wasm32 and the non-wasm32 bots.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh this is fine, everything will work out with this configuration!
@tlively at a high level can you explain to me why clang is needed? My current understanding of wasm is that the experimental backend in LLVM emites pure-wasm files (not bitcode) and then we use... something (emcc?) to link these together in the way that |
@alexcrichton Unfortunately it's not quite as powerful as that. In the new experimental target, rustc still just emits bitcode files and tosses them over the fence to emcc. The difference is that it also tells emcc to use the experimental LLVM wasm backend, instead of going through fastcomp and asm.js like it otherwise would. In order for this to work 1) emscripten needs to be configured to use llvm tools built with the wasm backend enabled, and 2) emscripten needs to be able to build libc using the wasm backend or have it already cached so libc can be linked with the rustc-generated bitcode files. There are three ways to meet these requirements.
|
Ok thanks for the info! So it sounds like even though we're enabling the I guess though that emscripten then uses the wasm backend in LLVM to emit wasm files? (loads up bitcode and emits wasm files). Where does this libc come from? Is it a bunch of C files that are compiled to wasm as well? I guess what I'm sort of getting at is that this sounds like we're pretty close to not depending on wasm at all. If we leveraged LLVM's wasm back to generate wasm code, found some sort of linker for wasm code (maybe this is just LLVM?), and then got our "libc" written in Rust perhaps (or prebuilt), then we wouldn't need emcc at all? I may be totally off base here though and not understanding. If you'd like I wouldn't mind chatting about this in a more high bandwidth setting (video/irc/etc), feel free to ping me on IRC if you'd like that! |
As far as I know, at the moment we don't have a great solution for linking wasm object files together. @sbc100 is making quick progress on this though, so hopefully we'll have something soon if we don't have it already. |
Good to hear @eholk! For posterity @eholk, @tlively, and I chatted a bit on video about this, and the things I learned were:
So it sounded to me like the
In the longer term we'll:
That "script" will ideally be usable by the community as well, and should hopefully enable easy usage of the native wasm backend of LLVM! |
This adds the experimental targets option to configure so it can be used by the builders and changes the wasm32 Dockerfile accordingly. Instead of using LLVM from the emsdk, the builder's emscripten tools now uses the Rust in-tree LLVM, since this is the one built with wasm support.
This is used in wasm32-experimental-emscripten to ensure that emscripten links against the libc bitcode files produced by the wasm LLVM backend, instead of using fastcomp.
This modifies the builder to download and use the LLVM tools from the last known good build on the WebAssembly buildbot waterfall, since these tools are built with the WebAssembly LLVM backend enabled.
@alexcrichton This should be good to go! Instead of needing to symlink the wasm-ready LLVM tools, I only needed to change the emscripten configuration file, which should be relatively easy for end users to do. One advantage of this strategy over the previous one is that the builder automatically picks up the latest improvements to the wasm LLVM backend. There are tests that fail in WebAssembly instruction selection, but I have verified that these are real bugs, not bugs in the setup of the builder. I will let the right people know about these bugs and hopefully they will get fixed quickly. |
Looks good! It looks like one of the tests is failing though. We currently verify that we can roundtrip a You can find deserialization here and serialization here. Perhaps this could be serialize/deserialized as a flat list of strings (with |
FYI @vadimcn |
Also turn WebAssembly backend back on in its builder.
@bors: r+ Looks great! |
📌 Commit 4ad6a95 has been approved by |
⌛ Testing commit 4ad6a95 with merge 3a90ff1d8ebb94c6354072608bbf3a27751ab7dd... |
💔 Test failed - status-travis |
Looks like the asmjs failure is non-spurious:
|
@bors: r+ |
📌 Commit c130b83 has been approved by |
Make wasm32 buildbot test LLVM backend This adds the experimental targets option to configure so it can be used by the builders and changes the wasm32 Dockerfile accordingly. Instead of using LLVM from the emsdk, the builder's emscripten tools now uses the Rust in-tree LLVM, since this is the one built with wasm support.
☀️ Test successful - status-appveyor, status-travis |
Split old and experimental wasm builders #42784 introduced configuration errors in the wasm builder by mixing different versions of the tools. This PR separates the wasm32-unknown-emscripten and wasm32-experimental-emscripten builders to resolve these errors.
This adds the experimental targets option to configure so it can be used
by the builders and changes the wasm32 Dockerfile accordingly. Instead
of using LLVM from the emsdk, the builder's emscripten tools now uses
the Rust in-tree LLVM, since this is the one built with wasm support.