kassane / sokol-d

D bindings for the sokol headers (https://github.com/floooh/sokol)
http://sokol-d.dub.pm/
zlib License
11 stars 5 forks source link

Roadmap #3

Open kassane opened 6 months ago

kassane commented 6 months ago

External Reference

kassane commented 5 months ago

Improvement LDC support

All flags: https://github.com/ldc-developers/ldc/blob/master/driver%2Fcl_options.cpp https://github.com/dlang/dub/blob/master/source%2Fdub%2Fcompilers%2Fldc.d

Upstream issues

kassane commented 1 month ago

Based on some information, it is expected to improve support for nogc and/or betterC. Currently the user_data example requires GC because of AA (associative array)

kassane commented 1 month ago

Improvement wasm support

The latest changes are intended to remove support for custom-Druntime (obsolete and incomplete). Only wasm32-target as betterC will be allowed. #20 This needs to be re-tested and improved.

However, for a higher priority, it is still necessary to resolve the linking conflicts of the objects generated by ldmd2/ldc2

Note: ldmd2 is just the wrapper for the ldc2 compiler, using the dmd flags (ldc2 -ldmd - w/ dmd library).

Building wasm-target involves what steps?

Four steps (current)

Build tests

In the following, I have tested it manually (no zig build system).

ldc2-wasm (manual build-test) ```bash # sokol-d path == pwd $ mkdir $PWD/build $ ldc2 -ldmd -c -w -preview=all -Oz -release -enable-inlining -boundscheck=off -vcolumns -od=$PWD/build -cache=/home/kassane/sokol-d/zig-cache/o/27f92344914739129514f9188caf365b -oq -disable-verify -Hkeep-all-bodies -i -I/home/kassane/sokol-d/src /home/kassane/sokol-d/src/examples/clear.d --d-version=CarelessAlocation -L-allow-undefined -Xcc=-v -P-I/home/kassane/.cache/zig/p/122083537ec3463ee4b2d520bf86a36b1057ab05abfe712c32bae1048f9b0c6e2a13/upstream/emscripten/cache/sysroot/include -Xcc=-DIMPL -Xcc=-DSOKOL_GLES3 -mtriple=wasm32-unknown-unknown-wasm /home/kassane/sokol-d/zig-cache/o/e35346434b3113a9d28288ab4edc2b5d/libsokol.a -flto=thin $ tree build build └── examples.clear.o 1 directory, 1 file $ mkdir $PWD/build/web $ $HOME/.cache/zig/p/122083537ec3463ee4b2d520bf86a36b1057ab05abfe712c32bae1048f9b0c6e2a13/upstream/emscripten/emcc -sASSERTIONS=0 -Oz -flto --closure 1 -sUSE_WEBGL2=1 -sNO_FILESYSTEM=1 -sMALLOC='emmalloc' --shell-file=src/sokol/web/shell.html -o$PWD/build/web/clear.html -sUSE_OFFSET_CONVERTER=1 $PWD/build/examples.clear.o /home/kassane/sokol-d/zig-cache/o/e35346434b3113a9d28288ab4edc2b5d/libsokol.a wasm-ld: warning: Linking two modules of different target triples: '/home/kassane/.cache/zig/p/122083537ec3463ee4b2d520bf86a36b1057ab05abfe712c32bae1048f9b0c6e2a13/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/lto/libGL-webgl2-getprocaddr.a(webgl1.o at 11618)' is 'wasm32-unknown-emscripten' whereas 'ld-temp.o' is 'wasm32-unknown-unknown-wasm' wasm-ld: warning: Linking two modules of different target triples: '/home/kassane/.cache/zig/p/122083537ec3463ee4b2d520bf86a36b1057ab05abfe712c32bae1048f9b0c6e2a13/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/lto/libc.a(abort.o at 342416)' is 'wasm32-unknown-emscripten' whereas 'ld-temp.o' is 'wasm32-unknown-unknown-wasm' wasm-ld: warning: Linking two modules of different target triples: '/home/kassane/.cache/zig/p/122083537ec3463ee4b2d520bf86a36b1057ab05abfe712c32bae1048f9b0c6e2a13/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/lto/libc.a(library_pthread_stub.o at 2939600)' is 'wasm32-unknown-emscripten' whereas 'ld-temp.o' is 'wasm32-unknown-unknown-wasm' wasm-ld: warning: Linking two modules of different target triples: '/home/kassane/.cache/zig/p/122083537ec3463ee4b2d520bf86a36b1057ab05abfe712c32bae1048f9b0c6e2a13/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/lto/libc.a(roundf.o at 4345288)' is 'wasm32-unknown-emscripten' whereas 'ld-temp.o' is 'wasm32-unknown-unknown-wasm' # [...] SKIP (SAME warnings) $ tree build build ├── examples.clear.o └── web ├── clear.html ├── clear.js └── clear.wasm 2 directories, 4 files ``` **Output:** Black screen!! :cry:
ldc2-wasm (manual build-test) ```bash $ ldmd2 -c -w -preview=all -Oz -release -enable-inlining -boundscheck=off -vcolumns -od=$PWD/build -oq -disable-verify -Hkeep-all-bodies -i -I$HOME/sokol-d/src $HOME/sokol-d/src/examples/clear.d -L-allow-undefined -Xcc=-v -P-I$HOME/.cache/zig/p/122083537ec3463ee4b2d520bf86a36b1057ab05abfe712c32bae1048f9b0c6e2a13/upstream/emscripten/cache/sysroot/include -Xcc=-DIMPL -Xcc=-DSOKOL_GLES3 -mtriple=wasm32-unknown-unknown-wasm $HOME/sokol-d/zig-cache/o/e35346434b3113a9d28288ab4edc2b5d/libsokol.a $ zig build-obj $PWD/build/examples.clear.o /home/kassane/sokol-d/zig-cache/o/e35346434b3113a9d28288ab4edc2b5d/libsokol.a -OReleaseSmall -target wasm32-emscripten -mcpu baseline -I /home/kassane/sokol-d/zig-cache/o/6f5a8a62c22680ad92a78d948ac77f24 -lc --name clear -femit-bin=$PWD/build/clear.o -static $ tree build build ├── clear.o ├── examples.clear.o └── web $HOME/.cache/zig/p/122083537ec3463ee4b2d520bf86a36b1057ab05abfe712c32bae1048f9b0c6e2a13/upstream/emscripten/emcc -sASSERTIONS=0 -Oz -flto --closure 1 -sUSE_WEBGL2=1 -sNO_FILESYSTEM=1 -sMALLOC='emmalloc' --shell-file=src/sokol/web/shell.html -o$PWD/build/web/clear.html -sUSE_OFFSET_CONVERTER=1 $PWD/build/clear.o $HOME/sokol-d/zig-cache/o/e35346434b3113a9d28288ab4edc2b5d/libsokol.a wasm-ld: warning: function signature mismatch: sg_make_shader >>> defined as (i32, i32) -> void in /home/kassane/sokol-d/build/clear.o >>> defined as (i32) -> i32 in /home/kassane/sokol-d/zig-cache/o/e35346434b3113a9d28288ab4edc2b5d/libsokol.a(/home/kassane/sokol-d/zig-cache/o/54cced09d05b5ad8e831190d0960f355/sokol_gfx.o) wasm-ld: warning: function signature mismatch: sg_make_buffer >>> defined as (i32, i32) -> void in /home/kassane/sokol-d/build/clear.o >>> defined as (i32) -> i32 in /home/kassane/sokol-d/zig-cache/o/e35346434b3113a9d28288ab4edc2b5d/libsokol.a(/home/kassane/sokol-d/zig-cache/o/54cced09d05b5ad8e831190d0960f355/sokol_gfx.o) wasm-ld: warning: function signature mismatch: sg_gl_query_shader_info >>> defined as (i32, i32) -> void in /home/kassane/sokol-d/build/clear.o >>> defined as (i32) -> i32 in /home/kassane/sokol-d/zig-cache/o/e35346434b3113a9d28288ab4edc2b5d/libsokol.a(/home/kassane/sokol-d/zig-cache/o/54cced09d05b5ad8e831190d0960f355/sokol_gfx.o) wasm-ld: warning: function signature mismatch: sg_d3d11_query_sampler_info >>> defined as (i32, i32) -> void in /home/kassane/sokol-d/build/clear.o >>> defined as (i32) -> i32 in /home/kassane/sokol-d/zig-cache/o/e35346434b3113a9d28288ab4edc2b5d/libsokol.a(/home/kassane/sokol-d/zig-cache/o/54cced09d05b5ad8e831190d0960f355/sokol_gfx.o) # [...] SKIP (same warnings) $ tree build build ├── clear.o ├── examples.clear.o └── web ├── clear.html ├── clear.js └── clear.wasm 2 directories, 5 files ``` **Output:** Works :partying_face:
ldc2-wasm (manual build-test) ```bash # sokol-d path == pwd $ mkdir -p build/web $ ldmd2 -c -w -preview=all -Oz -release -enable-inlining -boundscheck=off -vcolumns -od=$PWD/build -oq -disable-verify -Hkeep-all-bodies -i -I$HOME/sokol-d/src $HOME/sokol-d/src/examples/clear.d -L-allow-undefined -Xcc=-v -P-I$HOME/.cache/zig/p/122083537ec3463ee4b2d520bf86a36b1057ab05abfe712c32bae1048f9b0c6e2a13/upstream/emscripten/cache/sysroot/include -Xcc=-DIMPL -Xcc=-DSOKOL_GLES3 -mtriple=wasm32-unknown-unknown-wasm $HOME/sokol-d/zig-cache/o/e35346434b3113a9d28288ab4edc2b5d/libsokol.a -gcc=$HOME/.cache/zig/p/122083537ec3463ee4b2d520bf86a36b1057ab05abfe712c32bae1048f9b0c6e2a13/upstream/emscripten/emcc --linker=$HOME/.cache/zig/p/122083537ec3463ee4b2d520bf86a36b1057ab05abfe712c32bae1048f9b0c6e2a13/upstream/emscripten/emcc -P-sASSERTIONS=0 -Xcc=-Oz -Xcc="--closure 1" -P-sUSE_WEBGL2=1 -P-sNO_FILESYSTEM=1 -P-sMALLOC='emmalloc' -Xcc=--shell-file=src/sokol/web/shell.html -Xcc=-o$PWD/build/web/clear.html -P-sUSE_OFFSET_CONVERTER=1 -flto=full $ $HOME/.cache/zig/p/122083537ec3463ee4b2d520bf86a36b1057ab05abfe712c32bae1048f9b0c6e2a13/upstream/emscripten/emcc -sASSERTIONS=0 -Oz --closure 1 -sUSE_WEBGL2=1 -sNO_FILESYSTEM=1 -sMALLOC='emmalloc' --shell-file=src/sokol/web/shell.html -o$PWD/build/web/clear.html -sUSE_OFFSET_CONVERTER=1 $PWD/build/examples.clear.o $HOME/sokol-d/zig-cache/o/e35346434b3113a9d28288ab4edc2b5d/libsokol.a # [...] *NO Warnings* $ tree build build ├── clear.o ├── examples.clear.o └── web ├── clear.html ├── clear.js └── clear.wasm 2 directories, 5 files ``` **Output:** Works :partying_face:

Note 2: LTO between ldc2 and emcc cause warnings. Prefer enable LTO in ldc2 only (no or minimum warnings)!!

wasm-ld: warning: Linking two modules of different data layouts: '/home/kassane/.cache/zig/p/122083537ec3463ee4b2d520bf86a36b1057ab05abfe712c32bae1048f9b0c6e2a13/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/lto/libc.a(llrintl.o at 2994444)' is 'e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20' whereas 'ld-temp.o' is 'e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20'

cc: @floooh

floooh commented 1 month ago

Just FIY, I'll be travelling until Thursday and will probably be unresponsive during that time.

kassane commented 1 month ago

Just FIY, I'll be travelling until Thursday and will probably be unresponsive during that time.

No trouble! Enjoy your travels.


Note 2: LTO between ldc2 and emcc cause warnings. Prefer enable LTO in ldc2 only (no or minimum warnings)!!

After fix ldc2 (master) issue (add wasm32-unknown-emscripten)... I have discovered a strange situation, in that when enabling LTO on all in release mode.

warning: Linking two modules of different target triples: '/home/kassane/sokol-d/zig-cache/o/11f2f18f48ea24e538f790ad4c0e12f8/libsokol.a(sokol_gfx.o at 101382)' is 'wasm32-unknown-emscripten-musl' whereas 'ld-temp.o' is 'wasm32-unknown-emscripten'

wasm32-unknown-emscripten-musl ?? Maybe based on wasi target. The issue is fixed (without warnings) when passing -Dtarget=wasm32-emscripten-none.

kassane commented 1 month ago

After new updates and the possible inclusion of imgui support. As you can see, build.zig is quite long and complicated.

Unlike the sokol-zig approach (by @floooh), sokol-d has everything included, which requires extending the support in build.zig. So far, the port of pacman.c/pacman.zig to pacman.d is in progress, as a first external solution using sokol-d.

Any suggestions for other approaches to reduce such complexity?

Maybe pacman.d can serve as a reference.