D Language Foundation April 2023 Monthly Meeting Summary

Dennis dkorpel at gmail.com
Sun May 14 18:51:38 UTC 2023


On Sunday, 14 May 2023 at 16:02:00 UTC, ryuukk_ wrote:
> I wanted to target WASM, if your hooks call into libC, i can't 
> target WASM..

Good news, there's implementations of libc for WASM (example: 
https://archlinux.org/packages/community/any/wasi-libc/), and 
linking them doesn't even increase build time or binary size that 
much in my experience. I did this for 
[ctod](https://github.com/dkorpel/ctod/tree/master) because I had 
to (the tree-sitter library I use depends on it), but I also 
incorporated it in my other WASM projects to get a better 
`malloc/free` implementation.

> You keep tell us that the plan is "pay as you go", well, sir, 
> that kind of issue goes against your plan, so again, what's the 
> plan?

The "pay as you go" plan relates to druntime, not libc. Not that 
we deliberately depend on libc when it's not needed (don't need 
`itoa`, we have `unsignedToTempString`), but certain libc calls 
are so standard, common, and optimized, that there's not much 
benefit in trying to roll our own implementation for it. I'm 
talking about memset, memcpy, memcmp, malloc, free, realloc, off 
the top of my head.

Even when there's not a single mention of `memcpy` in druntime, 
LDC might still even emit it causing your WASM project to fail to 
link. Just check the asm for this code:

```D
struct S { char[1000] x; }

void c()
{
     S s = S.init; // emits a `memcpy` (-O0) or `memset` (-O3)
     f(&s);
}

void f(S* s);
```

There might be an obscure compiler flag to disable this, but it's 
a lot easier to just include an implementation of `memcpy`, 
`memset` and `memcmp` yourself.

> Then my project no longer compile, thanks a lot!

When you use a custom druntime, you can't expect stability when 
you upgrade the compiler but not your druntime. The real issue 
here is that there is no proper support for WebAssembly in 
upstream druntime.

> https://github.com/dlang/dmd/pull/14910
>
>
> Nobody care anymore.....

I fixed that for you: https://github.com/dlang/phobos/pull/8726





More information about the Digitalmars-d-announce mailing list