Thread overview
LDC wasm target: suppressing needless exports?
Feb 01
Sergey
Feb 01
ryuukk_
Feb 01
ryuukk_
Feb 01
ryuukk_
February 01
Lately I've been playing around with targeting wasm using LDC's wasm target.  (So far got enough of it working that I can write betterC-level D code and have it work in the browser -- certainly a welcome change from having to deal with Javascript's oddities and limitations. Plans are on the way to getting a rudimentary minimal druntime running so that I can start writing "real" D. :-P)

One thing I noticed, though, is that LDC seems to export all functions (including private ones!) to the generated .wasm file's export section. Meaning that they can be accessed from the JS side, etc..  Most of this is actually unnecessary, though, since I only have about 2-3 functions that actually need to be called from JS; everything else is internal D code.  Is there a way to suppress this auto-exporting and only do it for a few select functions?

It's mostly harmless, except that when I start using template functions the size of the symbols explode and needlessly bloats up my .wasm executable. Would be nice to trim off this fat.


T

-- 
Ignorance is bliss... until you suffer the consequences!
February 01
On Thursday, 1 February 2024 at 18:41:10 UTC, H. S. Teoh wrote:

> Plans are on the way to getting a rudimentary minimal druntime running so that I can start writing "real" D. :-P)

Just in case you didn't see those links before:

DRuntime work:
https://forum.dlang.org/thread/zsmhhoruiyzplskgjtgr@forum.dlang.org

And some other works related to betterC mode:
https://github.com/etcimon/libwasm

Article: Getting started with D on WebAssembly: https://brianush1.github.io/wasm-setup.html (glue code: https://github.com/brianush1/d-wasm-glue)
February 01

On Thursday, 1 February 2024 at 18:41:10 UTC, H. S. Teoh wrote:

>

Lately I've been playing around with targeting wasm using LDC's wasm target. (So far got enough of it working that I can write betterC-level D code and have it work in the browser -- certainly a welcome change from having to deal with Javascript's oddities and limitations. Plans are on the way to getting a rudimentary minimal druntime running so that I can start writing "real" D. :-P)

One thing I noticed, though, is that LDC seems to export all functions (including private ones!) to the generated .wasm file's export section. Meaning that they can be accessed from the JS side, etc.. Most of this is actually unnecessary, though, since I only have about 2-3 functions that actually need to be called from JS; everything else is internal D code. Is there a way to suppress this auto-exporting and only do it for a few select functions?

It's mostly harmless, except that when I start using template functions the size of the symbols explode and needlessly bloats up my .wasm executable. Would be nice to trim off this fat.

T

Try to compile with:

--f-visibility=hidden

February 01

oops, it is: --fvisibility=hidden

February 01

Also this to optimize/trim your wasm files:

wasm-opt -Oz -o bin/game.wasm

This tool comes with emscripten package