Is it possible to compile em++ to JS and then use the compiled em++.js to compile C++ code to .js, inside the browser?

55 views
Skip to first unread message

Jozsef Hegedus

unread,
Nov 4, 2019, 8:17:59 AM11/4/19
to emscripten-discuss
Hi,

Is it possible to compile em++ to JS and then use the compiled em++.js to compile C++ code to .js, inside the browser?

I am asking this because I am thinking of porting Stan it JS : 


Cheers

Jozsef


Floh

unread,
Nov 4, 2019, 3:15:01 PM11/4/19
to emscripten-discuss
Ben Smith got clang running in the browser quite recently, basically a "client-side godbolt":


But this is just the "naked" WASM generation, the emscripten part is missing.

Clang is pretty big though, that page downloads nearly 80 MB data :/

Jozsef Hegedus

unread,
Nov 4, 2019, 7:35:27 PM11/4/19
to emscripten-discuss
hmm!!!

this is interesting... i think i really need to start to figure out what the hell is wasm, is it the same as JS ?

what do you mean by emscripten part ?

still this is quite a cool thing... at least so it sounds !

Jozsef Hegedus

unread,
Nov 4, 2019, 7:41:31 PM11/4/19
to emscripten-discuss
ok, i just read about it.... this is pretty decent !

hmm... then Stan can be ported to the browser ... nice...

Milan Raj

unread,
Nov 5, 2019, 4:10:45 PM11/5/19
to emscripten-discuss
The cib project did compilation and linking to an emscripten context: https://tbfleming.github.io/cib/

But doesn't look maintained anymore. And that example build has problems with streams, if you change to printf instead of cout it runs.
I took a quick and dirty stab at decoupling it from the UI to behave like a standalone library with reasonable success: https://rajsite.github.io/cib/CIB.gcomp/test.html

The cib project handled fancy things like dynamically fetching zips with additional C++ source libraries to link against, it's pretty neat.

Jozsef Hegedus

unread,
Nov 6, 2019, 12:15:41 AM11/6/19
to emscripten-discuss
WOW !

This looks awesome ! :)

Need to look into it.

thanks

so there is some hope ... 

i guess the code for this i can find somewhere on github right ?

looks promising !


Screenshot 2019-11-06 at 7.14.14.png

Jozsef Hegedus

unread,
Nov 6, 2019, 3:10:06 AM11/6/19
to emscripten-discuss
OK. Now I start to get the point.

So the main goal is to make Stan run in the browser:


```
Build a Stan program:

Given a Stan program at foo/bar.stan, build an executable by typing:
   > make foo/bar$(EXE)'

This target will:
1. Build the Stan compiler and the print utility if not built.
2. Use the Stan compiler to generate C++ code, foo/bar.hpp.
3. Compile the C++ code using $(CC) $(CC_MAJOR).$(CC_MINOR) to generate foo/bar$(EXE)'
```

first I was trying to do this using `em++`, and also got "halfway", I am quite beginner there... but now I just got hint on how to do the 2nd half :).

Namely, compile the C++ code to something that can run in the browser, because, to the best of my understanding I managed to get a `.js` and `.wasm` file for `stanc` but it does not really run in `node stan.js` and also not in the browsers.

Screenshot 2019-11-06 at 9.01.23.png


But then I got this in the browser : 


Screenshot 2019-11-06 at 9.08.12.png


 Anyway, baby steps, first I try to reproduce your examples, and some other ppl's examples, etc...

baby steps, but you gave me hope ! This is very cool news ! And thanks for the help in simplifying the em++ inside the browser compiler ... 
into something that can be used to compile a `C++` file into `.js` / `.wasm` file. 

Anyway, I want to get Stan running on node.js, or in the browser, and only after that I can try to compile it in the browser ... :)

baby steps,

thanks for this great news ! I am impressed. Looks cool !

Have a good Guys !
Cheers

Jozsef



On Tuesday, 5 November 2019 23:10:45 UTC+2, Milan Raj wrote:
Reply all
Reply to author
Forward
0 new messages