Skip to content

Commit

Permalink
Testing custom D runtime for Wasm targets.
Browse files Browse the repository at this point in the history
* This D custom runtime was started by Adam D. Ruppe, in arsd-webassembly.
* Some of the features are not yet implemented.
* This runtime may become version locked as the D runtime hooks keeps changing.
* This runtime is not yet fully tested.
  • Loading branch information
kassane committed Jan 21, 2024
1 parent f1ba5bb commit bc4722b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 47 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Auto-generated [D](https://dlang.org) bindings for the [sokol headers](https://g
**Required**

- [zig](https://ziglang.org/download) v0.12.0 or master
- [ldc](https://ldc-developers.github.io) v1.35.0 or latest-CI (nightly)
- [ldc](https://ldc-developers.github.io) v1.36.0 or latest-CI (nightly)

Supported platforms are: Windows, macOS, Linux (with X11)

Expand All @@ -27,11 +27,11 @@ zig build -Doptimize=ReleaseFast -Dshared
zig build run-blend -Doptimize=ReleaseFast
zig build run-clear -Doptimize=ReleaseFast
zig build run-cube -Doptimize=ReleaseFast
zig build run-debugtext-print -Doptimize=ReleaseFast
zig build run-debugtext_print -Doptimize=ReleaseFast
zig build run-mrt -Doptimize=ReleaseFast
zig build run-saudio -Doptimize=ReleaseFast
zig build run-sgl-context -Doptimize=ReleaseFast
zig build run-user-data -Doptimize=ReleaseFast
zig build run-sgl_context -Doptimize=ReleaseFast
zig build run-user_data -Doptimize=ReleaseFast
zig build run-triangle -Doptimize=ReleaseFast

zig build --help
Expand All @@ -50,8 +50,8 @@ zig build --help
# ReleaseFast
# ReleaseSmall
# -Dshared=[bool] Build sokol dynamic library (default: static)
# -DbetterC=[bool] Omit generating some runtime information and helper functions. (default: false)
# -DzigCC=[bool] Use zig cc as compiler and linker. (default: false)
# -DbetterC=[bool] Omit generating some runtime information and helper functions (default: false)
# -DzigCC=[bool] Use zig cc as compiler and linker (default: false)
```

## Shaders
Expand Down
6 changes: 4 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ pub fn build(b: *Build) !void {
"saudio",
"sgl_context",
"debugtext_print",
// "user_data", // Need GC for user data [associative array]
"user_data", // Need GC for user data [associative array]
};

inline for (examples) |example| {
Expand All @@ -237,8 +237,10 @@ pub fn build(b: *Build) !void {
"-w", // warnings as error
// more info: ldc2 -preview=help (list all specs)
"-preview=all",
"-lowmem",
},
.d_packages = if (target.result.isWasm()) &[_][]const u8{
b.dependency("wasmd", .{}).path("arsd-webassembly").getPath(b),
} else null,
// fixme: https://github.com/kassane/sokol-d/issues/1 - betterC works on darwin
.zig_cc = if (target.result.isDarwin() and !enable_betterC) false else enable_zigcc,
.target = target,
Expand Down
4 changes: 4 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@
.url = "git+https://github.com/emscripten-core/emsdk#0bbae74935d57ff41739648c12cf90b56668398f",
.hash = "1220f1340cd871b444021c600661f921f96091ce0815fa43008528f4844cece7e245",
},
.wasmd = .{
.url = "git+https://github.com/kassane/webassembly#800870e68be1518eeffbb2c0814e23b9543a89cb",
.hash = "12203c2350903f04a07f746b448abb22824a452e8d81500b2fa11a0c3a5ea896b3f6",
},
},
}
33 changes: 0 additions & 33 deletions dub.json

This file was deleted.

19 changes: 13 additions & 6 deletions src/examples/user_data.d
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,20 @@ void frame_userdata(scope void* userdata) @trusted
auto state = cast(ExampleUserData*) userdata;

state.data++;
if (state.data % 13 == 0) {
state.map[state.data] = state.data * 13 / 3;

version(WebAssembly){
// TODO support
}
if (state.data % 12 == 0 && state.data % 15 == 0) {
state.map.clear();
else
{
if (state.data % 13 == 0) {
state.map[state.data] = state.data * 13 / 3;
}
if (state.data % 12 == 0 && state.data % 15 == 0) {
state.map.clear();
}
}
debug {
debug {
import std.stdio : writeln;
try {
writeln(*state);
Expand All @@ -52,7 +59,7 @@ void cleanup() @safe

void main()
{
ExampleUserData userData;
auto userData = ExampleUserData(0, null);

sapp.Desc runner = {
window_title: "user-data.d",
Expand Down

0 comments on commit bc4722b

Please sign in to comment.