Linking many bitcode files into WASM

182 views
Skip to first unread message

sha...@infograph.com

unread,
Oct 1, 2018, 7:43:07 PM10/1/18
to emscripten-discuss
Hello, I am new to WebAssembly and Emscriptem.
I am converting a large C/C++ project (hundreds of source files) to WASM.
I see how I can compile every source file to a bitcode file:

emcc -O3 hello.c -o hello.bc
emcc -O3 foo.c -o foo.bc
emcc -O3 bar.c -o bar.bc

When I link them into a wasm, js, html set of output files, it looks like this:

emcc -O3 -s WASM=1 hello.bc foo.bc bar.bc -o hello.html

But what if I have more than 3 bitcode files?  What if I have over 700?
That won't fit on the commandline.  
I tried using a wildcard:

emcc -O3 -s WASM=1 *.bc -o hello.html

but that gave an error.

Any ideas?
Could I write all the input files into a file and specify that filename instead?

be...@beuc.net

unread,
Oct 2, 2018, 3:35:46 AM10/2/18
to emscripte...@googlegroups.com
Hi!

On 02/10/2018 01:43, sha...@infograph.com wrote:
> Hello, I am new to WebAssembly and Emscriptem.
> I am converting a large C/C++ project (hundreds of source files) to WASM.
> I see how I can compile every source file to a bitcode file:
>
> emcc -O3 hello.c -o hello.bc
> emcc -O3 foo.c -o foo.bc
> emcc -O3 bar.c -o bar.bc
>
> When I link them into a wasm, js, html set of output files, it looks
> like this:
>
> emcc -O3 -s WASM=1 hello.bc foo.bc bar.bc -o hello.html
>
> But what if I have more than 3 bitcode files?  What if I have over 700?
> That won't fit on the commandline.  
> I tried using a wildcard:
>
> emcc -O3 -s WASM=1 *.bc -o hello.html
>
> but that gave an error.

And, what was the error?

> Any ideas?
> Could I write all the input files into a file and specify that
> filename instead?

Can you run xargs --show-limits and copy/paste the output?
Nowadays you get 2MB of command line size which should allow at least
8000+ files at once.
(if you're using GNU/Linux, that is)

Cheers!
Sylvain

Floh

unread,
Oct 2, 2018, 5:52:54 AM10/2/18
to emscripten-discuss
Hi, you should read up on build systems for that.

I'd recommend cmake, if you have a web developer background, it's a bit like webpack, but for C/C++ projects :)

It's not the greatest tool on earth, but 'simple things are (reasonably) simple', it's well supported by emscripten (https://github.com/kripken/emscripten/tree/incoming/cmake/Modules), and it has established itself as some sort of standard in the C/C++ world.

The wildcard thing you tried most likely behaves differently depending on operating system and shell (it might work on Linux/OSX because there the shell does the wildcard expansion, but it most likely won't work on Windows, because there the invoked tool needs to the expansion themselves).

Cheers,
-Floh.

Floh

unread,
Oct 2, 2018, 6:06:08 AM10/2/18
to emscripten-discuss
PS: maybe I should also mention my own 'fips' build system wrapper, since this somewhat simplifies setting up and working with cross-compiling projects (it's easy to switch between native and emscripten builds for instance), it also adds a few convenience functions for writing cmake build files.

It's a bit of an "all or nothing" approach though, so it might not be the right tool for your situation:


Here are a few projects which use fips (have a look at the fips.yml and CMakeLists.txt files):



Reply all
Reply to author
Forward
0 new messages