January 03
On Saturday, 23 November 2019 at 10:29:24 UTC, Johan Engelen wrote:
> On Saturday, 23 November 2019 at 09:51:13 UTC, Sebastiaan Koppe wrote:
>> This is my proposal for porting D runtime to WebAssembly. I would like to ask you to review it. You can find it here: https://gist.github.com/skoppe/7617ceba6afd67b2e20c6be4f922725d
>
> I'm assuming you already started some work in this area? Where can we track it?
>
> Great initiative!
>   Johan

You can track the work here: https://github.com/skoppe/druntime/tree/wasm

Almost all unittests pass.

I am in the process of getting `ldc-build-druntime` to build it, as well as hooking into main().

I really wanted to make a pr, so that others can build it as well, but I am pressed for time due to family weekend trip. It is on my list once I get back, as well as incorpareting all info from this thread back into the proposal.

Some things to tackle before going beta:

- AA unittests fail
- reals (probably are going to be unsupported)
- wasi libc needs to be distributed (either in source and compiled into wasm druntime) or statically linked
- CI (but should be doable once ldc-build-druntime works)
- hooking into main() (I thought about making a @weak _start() in druntime so that users can still override it when they want) (_start is the wasm's equivalent of _Dmain)
- probably need help from LDC to spill i32 pointer on the shadow stack

January 04
On Friday, 3 January 2020 at 10:34:40 UTC, Sebastiaan Koppe wrote:
> You can track the work here: https://github.com/skoppe/druntime/tree/wasm

I gave it a quick glance; looks pretty good, and like pretty much work. ;) - Thx.

The compiler should probably help a bit by firstly predefining a version `CRuntime_WASI` (either for all wasm targets, or for triples like wasm32-unknown-unknown-wasi) and secondly emitting TLS globals as regular globals for now, so that you don't have to add `__gshared` everywhere.

> - reals (probably are going to be unsupported)

It's probably just a matter of checking which type clang uses for C `long double` when targeting wasm, and making LDC use the same type.

> - wasi libc needs to be distributed (either in source and compiled into wasm druntime) or statically linked

I'd prefer a static lib (and referencing that one via `-defaultlib=druntime-ldc,phobos2-ldc,wasi` in ldc2.conf's wasm section).
Building it via LDC CI for inclusion in (some?) prebuilt LDC packages is probably not that much of a hassle with a clang host compiler.

> once ldc-build-druntime works

If you need some CMake help (excluding C files etc.), https://github.com/ldc-developers/ldc/pull/2787 might have something useful.

> (_start is the wasm's equivalent of _Dmain)

Not really; _start (in libc) is used on Linux too, which sets up the C runtime, then calls C main, which calls druntime's _d_run_main which in turn calls _Dmain.
January 05
On Friday, 3 January 2020 at 10:34:40 UTC, Sebastiaan Koppe wrote:

> - reals (probably are going to be unsupported)

It seems to me for now they can be threated as double without any problems
January 07
On Saturday, 4 January 2020 at 16:28:24 UTC, kinke wrote:
> On Friday, 3 January 2020 at 10:34:40 UTC, Sebastiaan Koppe wrote:
>> You can track the work here: https://github.com/skoppe/druntime/tree/wasm
>
> I gave it a quick glance; looks pretty good, and like pretty much work. ;) - Thx.

Great. Thanks for looking.

> The compiler should probably help a bit by firstly predefining a version `CRuntime_WASI` (either for all wasm targets, or for triples like wasm32-unknown-unknown-wasi) and secondly emitting TLS globals as regular globals for now, so that you don't have to add `__gshared` everywhere.

Yes. I will probably manage to do the first, but for the second one I definitely need some pointers.

>> - reals (probably are going to be unsupported)
>
> It's probably just a matter of checking which type clang uses for C `long double` when targeting wasm, and making LDC use the same type.

Could be. I personally prefer to avoid them because wasm only supports f32/f64, which I guess means they will be emulated (I have no idea though, maybe some wasm hosts do the right thing). But some people might need them, so if fixing the ABI is not a big deal, we could include them.

>> - wasi libc needs to be distributed (either in source and compiled into wasm druntime) or statically linked
>
> I'd prefer a static lib (and referencing that one via `-defaultlib=druntime-ldc,phobos2-ldc,wasi` in ldc2.conf's wasm section).

Good.

> Building it via LDC CI for inclusion in (some?) prebuilt LDC packages is probably not that much of a hassle with a clang host compiler.

I don't think so either. I have already got it building, so I just need to go over my notes.

>> once ldc-build-druntime works
>
> If you need some CMake help (excluding C files etc.), https://github.com/ldc-developers/ldc/pull/2787 might have something useful.

Thanks.

>> (_start is the wasm's equivalent of _Dmain)
>
> Not really; _start (in libc) is used on Linux too, which sets up the C runtime, then calls C main, which calls druntime's _d_run_main which in turn calls _Dmain.

Ahh, fumbling as I go along. Thanks for the correction.
January 07
On Sunday, 5 January 2020 at 08:24:21 UTC, Denis Feklushkin wrote:
> On Friday, 3 January 2020 at 10:34:40 UTC, Sebastiaan Koppe wrote:
>
>> - reals (probably are going to be unsupported)
>
> It seems to me for now they can be threated as double without any problems

Yeah, that is what I have done so far.
January 07
On Tuesday, 7 January 2020 at 08:17:37 UTC, Sebastiaan Koppe wrote:
> On Sunday, 5 January 2020 at 08:24:21 UTC, Denis Feklushkin wrote:
>> On Friday, 3 January 2020 at 10:34:40 UTC, Sebastiaan Koppe wrote:
>>
>>> - reals (probably are going to be unsupported)
>>
>> It seems to me for now they can be threated as double without any problems
>
> Yeah, that is what I have done so far.

I believe that's the best choice even long term. `real` is supposed to represent the largest natively supported FP type by the underlying ISA. In WebAssembly that's f64, so there's no need emulate anything. Of course, people who need wider integer/fixed/floating types can use third-party libraries for that.
There are other platforms where D's real type is the same as double, so I don't see a reason to worry.
January 15
>> (_start is the wasm's equivalent of _Dmain)
> Not really; _start (in libc) is used on Linux too, which sets up the C runtime, then calls C main, which calls druntime's _d_run_main which in turn calls _Dmain.

Small correction: _start generally calls __libc_start_main() or similar, with the addresses of main, argc, argv, envp, module ini and fini, and possibly some other stuff I forgot about.
Next ›   Last »
1 2 3 4