-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Does our LLVM need the fastcomp backend for emscripten? #36356
Comments
Yes, that is 100% correct. If Rust has an LLVM with the proper target triple, and emits LLVM bitcode, and Rust's LLVM is the same version as emscripten's (so the two LLVMs can swap bitcodes), then that would work. Rust would emit the bitcode, emscripten would read it, and emscripten would process it into asm.js or wasm, etc. The user would have two copies of LLVM, which is I guess the downside. Note that at some point the asm.js and wasm triples hope to merge. At such a time, the Rust side here could be plain vanilla LLVM, no toppings/patches. However, I'm not sure when that will be, we have some plans but not a timeline. |
@kripken awesome, thanks for the clarification! Out of curiosity, if we do have the fastcomp backend, would it be trivial to emit JS like |
Not trivial, but possible, for limited use cases. On the one hand, the asm.js backend in fastcomp emits asm.js functions plus some metadata. You can almost just run those functions. However, it needs a little post-processing to create the asm.js module around it and set up integration with the outside (using that metadata). But that's just for raw asm.js output. If you want integration with the web platform (e.g. to have printf print somewhere, or render graphics, or receive input, or have a virtual filesystem, etc.) then you need emscripten's JS runtime + JS libraries, which emcc links up with the backend's output. That enters into the area of "tons of things" ;) |
Ok cool, sounds like we should:
Thanks for the clarifications @kripken! |
I looked into this and it wasn't obvious what to do. Right now we need to pass the triples to the LLVM target registry to construct a target machine. In theory we don't need a target machine at all, but it would require some amount of surgery to make rustc understand that. So either we have to (as @alexcrichton suggested) keep a minimal LLVM patch to preserve the registry/target machine changes, or do some rustc refactoring to make the target machine optional. |
Working asmjs and wasm targets This patch set results in a working standard library for the asmjs-unknown-emscripten and wasm32-unknown-emscripten targets. It is based on the work of @badboy and @rschulman. It does a few things: - Updates LLVM with the emscripten [fastcomp](rust-lang/llvm#50) patches, which include the pnacl IR legalizer and the asm.js backend. This patch is thought not to have any significant effect on existing targets. - Teaches rustbuild to correctly link C code with emscripten - Updates gcc-rs to work correctly with emscripten - Teaches rustbuild to run crate tests for emscripten with node - Modifies Thread::new to return an error on emscripten, to facilitate debugging a common failure mode - Modifies libtest to run in single-threaded mode for emscripten - Ignores a host of tests that don't work yet, mostly dealing with threads and I/O - Updates libc with wasm32 definitions (presently the same as asmjs) - Adds a wasm32-unknown-emscripten target that feeds the output of LLVM's asmjs backend through emcc to generate wasm Notes and caveats: - This is only known to work with `--enable-rustbuild`. - The wasm32 target can't be tested correctly yet because of issues in compiletest and limitations in node emscripten-core/emscripten#4542, but hello.rs does seem to work when run on node via the binaryen interpreter - This requires an up to date installation of the emscripten sdk from its incoming branch - Unwinding is very broken - When enabling the emscripten targets jemalloc is disabled for all targets, which results in test failures for the host Next steps are to fix the jemalloc issue, start building the two emscripten targets on the auto builders, then start producing nightlies. #36317 tracks work on this. Fixes #36515 Fixes #36515 Fixes #36356
In #36339 we're updating LLVM to include the fastcomp backend. Upon reflection, however, I'm not actually sure if we need it in our fork of LLVM? I'm led to believe that it's our (rustc's) job to emit LLVM bytecode which
emcc
then slurps up and generates JS with. I'm led to believe thatemcc
needs and runs the fastcomp backend, but we as the Rust compiler generating bytecode otherwise wouldn't use it at all. I do believe, however, that we would need at least the definition of the asmjs target to LLVM. That is, we'd need some minor patch so it understands what the "asmjs" target is.cc @sunfish, @kripken, does this sound right? This would certainly reduce the maintenance burden on both sides! All we'd need to do is ensure that we're both working with equivalent versions of LLVM (which shouldn't be too hard)
The text was updated successfully, but these errors were encountered: