-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Support compiling to JavaScript with Emscripten #9430
Comments
I've tried and given up on this a couple of times, so I'm describing my progress to date in case anyone has advice or wants to try it. It's easy to generate a large LLVM bitcode file containing the julia/base library. Run the following from within the julia/base directory:
Now, you should have an XX.bc file in the base directory. To identify functions in the
That'll give something like:
To compile one of these functions to JavaScript, use
A few of the simplest functions will compile to working JavaScript code. Several others will error as described below. Here are current issues:
Another issue is compiling libjulia to bitcode. I've gotten about 80% or more of it to compile with emcc. I had to strip out the libuv stuff. I haven't tried building any of the third-party libraries. |
Dup of #2418. |
If anything, I would close the other one because it is fairly speculative whereas this issue is substantive (if only partially actionable in base). Emscripten keeps coming up, so we might as well have a central place to point people to. |
I'd favor that – #2418 was pretty vague. |
This sounds awesome. I am having some difficulty getting Emscripten installed, but once I do, I can try to play around with this. Getting all of Julia including REPL compiled sounds ambitious, but it looks like bits and pieces already can be compiled. Would it makes sense to try to compile a small version of Julia (Juliet?) into Javascript as a start? I think it would already be super cool if we could do basic matrix algebra and maybe an svd or eig here and there and lean on JS proper for a lot of the other stuff. For this smaller scope, we could probably even write a parser in JS if that helps. Just so I understand, if we were able to do this, would we be able to write code like this in the JS console:
One can dream :D What would the usage look like? By the way, Tom, I noticed it appears you managed to compile CLAPACK to JS. How is that? I'd love to learn how to use that. |
Or just translate LAPACK to Julia. However there are too many other libraries we depend on. |
Baby steps... Running a Julia function from the JS console in Chrome... The JS code:
|
Someone is also looking to make this work with Numba (Python/NumPy that uses LLVM): |
It is interesting to know it. Everything go on Web now. However, still On Wed, Feb 18, 2015 at 4:56 PM, Tom Short [email protected] wrote:
Best regards, |
Given the recent announcements about WebAssembly, the best path may be to wait until that is ready. Their development plan is to build an official LLVM backend. Emscripten uses an out-of-tree fork of LLVM, so version issues can be a problem. With a built-in backend for WebAssembly, compilation for the web might be an easier path. |
WebAssembly is pretty exciting – it makes running Julia code in the browser a real prospect. |
Very cool. Thanks for the heads up. |
While WebAssembly is ultimately the way to go, has anyone actually put any effort into makin a Julia -> JavaScript transpiler for the time being a la Opal's methodology? The more I look at Julia, the more desirous I become to be able to develop an isomorphic Julia stack so that it can be used for server and client side development. Volt is a fantastic example of that and is what Meteor should have been for JS. I can imagine a Julia based isomorphic framework that would just burn down many performance and language barriers that cause debugging headaches at present. |
It's pretty tricky largely because of big honking dependencies on LLVM, BLAS and OpenLibm: I don't think that EmScripten can transpile LLVM itself; and BLAS and OpenLibm are not pure C – they include inline assembly, which I'm pretty certain EmScripten cannot handle. |
@ylluminate I spent a few hours writing a transpiler. It's easy to do but hard to make it fast. If I could figure out how to reuse parts of Julia's compilation pipeline like type inference and hopefully some function to make the AST more abstract that would make things a lot easier. |
Has anyone explored this, which says it will "Run LLVM Assembly In Your Browser?" Just poking around without exploring yet... |
@StefanKarpinski Once julia can be statically compiled those difficulties will be obviated correct? |
Not unless someone writes pure-julia replacements for all of the |
Wouldn't compiled binary emitted by a hypothetical slimmed down non-numerical Julia work with Web assembly? |
Not unless someone writes a transpiler from x86 assembly to WebAssembly, which is, of course, entirely possible, but would have to be done. |
How about with this web assembly LLVM JIT VM? https://github.com/WebAssembly/wasm-jit-prototype |
OpenLibm and BLAS have inline assembly – not inline LLVM assembly. |
|
yes, there's a reference implementation in C. lapack is a bit harder, since it is in fortran, but it turns out there is an SO post on the topic: http://stackoverflow.com/questions/21990243/use-emscripten-with-fortran-lapack-binding |
Dragonegg is basically dead, unfortunately. End of this year the Nvidia/PGI Fortran LLVM front-end should get released. |
@datnamer I think that is also the way we are going to, see:
Also currently @ScottPJones is working on a julia-lite version, that we are testing on RaspberryPi2, see:
Discussion at Gitter chat room: |
It might be worth trying again to get this working with emscripten - around a year passed since the last attempt based on the history here. Fixes since then might have helped. In particular, the Rust work mentioned above has matured, including struct fixes and so forth. There is also a current PR for another possibly relevant issue. |
👍 @kripken |
Maybe with the revamped Julia -> c transpiler, the c code can be compiled to web assembly. |
this will be cool when it is possible, and we intend to continue working towards this (going through the Julia2C transpiler is not the best path forward), but I'm going to close the issue since it's not particularly actionable as a bug report. (although discussion here and on julia-dev is still encouraged to continue) |
@vtjnash: The issue tracker is not just for bug reports, but also for feature requests. I'll leave this one closed since we don't really need an issue to track it, but please don't close everything that's not a bug. |
i'm not attempting to close all feature requests, only ones (like this one) that aren't specifically actionable and thus don't need an issue to track it |
So what is being thought of as the most potentially successful path forward if not the c transpilation? |
Going through LLVM without C would be simpler. |
Has anyone evaluated @kripken's remarks wrt emscripten? |
Is this "actionable" now (at least for @ScottPJones's Julia-lite branch, that is available), with or without Julia2C? The PR that @kripken mentioned is merged. "Maybe with the revamped Julia -> c transpiler, the c code can be compiled to web assembly." [or asm.js], anyway is Julia2C broken (or only for 0.3?), would if be much work to get it to work if it is, maybe not for this. [Was this not actionable, only because of assembly/BLAS/LAPACK: "yes, there's a reference implementation in C. lapack is a bit harder, since it is in fortran"? I would be ok without BLAS/LAPACK. There are many functions besides matrix multiply, but how far would e.g. pure-Julia native [naive] matrix multiply get you (ans say pow)?] [Also more discussion at https://github.com//issues/2418#issuecomment-168565188 (that was closed in favor of this one), since, I'm just not sure what "Biwa" is.] |
With Julia's improved static compilation, compilation to JavaScript is getting closer. This feature would allow Julia code to be run from static web pages. Eventually, it may be possible to compile all of Julia, REPL and all.
The text was updated successfully, but these errors were encountered: