September 13, 2021

On Monday, 13 September 2021 at 17:19:23 UTC, Ferhat Kurtulmuş wrote:

>

You don't need to compile d code to c. You can use d code with emscripten. Sebastiaan Koppe was working on druntime1 to make it possible to use it with webassembly. Dunno its current status. Here is also my d game using wasm. It even links with c libraries compiled with emscripten.

https://aferust.github.io/drawee/
https://github.com/aferust/drawee

Yeah, thanks for answering! Sounds like you guys got it figured out. You can just use the LLVM compiler to compile to LLVM intermediate code and then feed that directly into Emscripten.

I wasn't able to find this info online, specifically. If this is true then D is
100% fully executable on via Emscripten Wasm.

September 13, 2021
On Monday, 13 September 2021 at 16:19:31 UTC, Kenneth Dallmann wrote:
>    Rumor has it that D can compile to Wasm, but only in the "BetterC"
> subset.

True. Or alternatively, you probably can do it by simply not using the unported DRuntime parts, and defining a few stub functions for those runtime calls that remain in the binary anyway.

>    LLVM can compile to Wasm, but unfortunately it may not support
> systems IO calls because of the lack of operating system access.

You're supposed to create the system hooks for WASM yourself, or use a library for doing that. https://code.dlang.org/packages/spasm should be your first stop when using D. I think WASM is designed so you can run code unprivileged code in it, as opposed to asm.js which always has full access to it's environment.

> Emscripten is a compiler that can transform C into something that
> can run on Wasm without holes in the Standard Library.  It does
> this by simulating an operating system, which adds overhead to the
> runtime, but allows a full range of C to be used, to my understanding.

You can compile D to asm.js using the Emscripten backend, and then call the C API. No need for a C transpilation. However, I prefer WASM myself. It does not require a massive framework like Emscripten, and also it felt less buggy. And you can use Spasm with it.
September 13, 2021
On Monday, 13 September 2021 at 18:11:22 UTC, Kenneth Dallmann wrote:
> Yeah, thanks for answering! Sounds like you guys got it figured out. You can just use the LLVM compiler to compile to LLVM intermediate code and then feed that directly into Emscripten.
>
>   I wasn't able to find this info online, specifically. If this is true then D is
> 100% fully executable on via Emscripten Wasm.

You don't need Emscripten at all. LDC can target WASM directly.
September 13, 2021

On Monday, 13 September 2021 at 17:19:23 UTC, Ferhat Kurtulmuş wrote:

>

You don't need to compile d code to c. You can use d code with emscripten. Sebastiaan Koppe was working on druntime1 to make it possible to use it with webassembly. Dunno its current status. Here is also my d game using wasm. It even links with c libraries compiled with emscripten.

https://aferust.github.io/drawee/
https://github.com/aferust/drawee

Yes, just yesterday I started to get back to that work again. I am currently updating to latest ldc and wasi sdk. Couple of months ago all druntime/phobos tests were passing and I hope to get there again (well, all except thread/fibers/exceptions, since they aren't suported).

You can already use the forks to build ldc phobos/druntime libs for use in wasm. It is a bit cumbersome to setup but it works.

If that isn't your cup of tea - won't blame you - you'll have to stick to adam's custom runtime or plain betterC, which also works fine. Especially since spasm has bindings to all web api's.

examples:

https://skoppe.github.io/spasm/examples/todo-mvc/
https://skoppe.github.io/spasm/examples/underrun/
https://skoppe.github.io/spasm-imgui/

September 13, 2021

On Monday, 13 September 2021 at 21:14:16 UTC, Sebastiaan Koppe wrote:

>

On Monday, 13 September 2021 at 17:19:23 UTC, Ferhat Kurtulmuş wrote:

>

[...]

Yes, just yesterday I started to get back to that work again. I am currently updating to latest ldc and wasi sdk. Couple of months ago all druntime/phobos tests were passing and I hope to get there again (well, all except thread/fibers/exceptions, since they aren't suported).

You can already use the forks to build ldc phobos/druntime libs for use in wasm. It is a bit cumbersome to setup but it works.

If that isn't your cup of tea - won't blame you - you'll have to stick to adam's custom runtime or plain betterC, which also works fine. Especially since spasm has bindings to all web api's.

examples:

https://skoppe.github.io/spasm/examples/todo-mvc/
https://skoppe.github.io/spasm/examples/underrun/
https://skoppe.github.io/spasm-imgui/

Thank you Sebastiaan. Latest wasi support sounds awesome. If I remember correctly, the supported version was 8. It is nice to know you keep working on it.

September 14, 2021

On Monday, 13 September 2021 at 16:36:10 UTC, Kenneth Dallmann wrote:

>

On Monday, 13 September 2021 at 16:29:45 UTC, jfondren wrote:

>

On Monday, 13 September 2021 at 16:19:31 UTC, Kenneth Dallmann wrote:

>

Why can't
we just compile D code to C, as a compiler output, and then run that
through Emscripten?

The immediate problem is that a D->C compiler does not exist.

I read somewhere that BetterC can though, and maybe that's how it works.
Although, with the LLVM you can compile it to Wasm, it just won't have
the standard library, a technical nightmare.

Maybe a D to C compiler would be a good project, to increase the portability of D.

Would be a cool project

September 15, 2021

On Monday, 13 September 2021 at 16:36:28 UTC, Paul Backus wrote:

>

On Monday, 13 September 2021 at 16:19:31 UTC, Kenneth Dallmann wrote:

>

With D not being able to be run on Wasm in a meaning way: Why can't
we just compile D code to C, as a compiler output, and then run that
through Emscripten?

The [D language runtime][1] uses inline assembly for some low-level features (e.g., threads), and therefore cannot be compiled to C.
Emscripten itself has [similar limitations.][2]

Time to remind everyone about my project: https://github.com/denizzzka/d_c_arm_test

It just allows to take these things into a small "backend":
https://github.com/denizzzka/d_c_arm_test/tree/master/d/freertos_druntime_backend/external

It is possible to write same backend for webasm or any other platform.

(But now there is a tiny problem with the Meson, which does not allow to package arbitrary dub and any others repositories into Meson. PR is waiting for approval.)

1 2
Next ›   Last »