Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Jan 24, 2024
1 parent 583f079 commit be0fc3f
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 182 deletions.
41 changes: 15 additions & 26 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ pub fn buildLibSokol(b: *Build, options: LibSokolOptions) !*CompileStep {
csrc_root ++ "sokol_time.c",
csrc_root ++ "sokol_audio.c",
csrc_root ++ "sokol_gl.c",
csrc_root ++ "sokol_glue.c",
csrc_root ++ "sokol_debugtext.c",
csrc_root ++ "sokol_shape.c",
};
Expand Down Expand Up @@ -408,7 +407,9 @@ pub fn ldcBuildStep(b: *Build, options: DCompileStep) !*RunStep {
// https://github.com/ldc-developers/ldc/issues/4501
try cmds.append("-L-w"); // hide linker warnings
}

if (options.target.result.isWasm()) {
try cmds.append("--d-version=CarelessAlocation");
try cmds.append("-L-allow-undefined");
}

Expand All @@ -425,7 +426,12 @@ pub fn ldcBuildStep(b: *Build, options: DCompileStep) !*RunStep {

// C include path
for (lib_sokol.root_module.include_dirs.items) |include_dir| {
const path = include_dir.path_system.getPath(b);
const path = if (include_dir == .path)
include_dir.path.getPath(b)
else if (include_dir == .path_system)
include_dir.path_system.getPath(b)
else
include_dir.path_after.getPath(b);
try cmds.append(b.fmt("-P-I{s}", .{path}));
}

Expand Down Expand Up @@ -453,7 +459,7 @@ pub fn ldcBuildStep(b: *Build, options: DCompileStep) !*RunStep {
// C defines
for (lib_sokol.root_module.c_macros.items) |cdefine| {
if (cdefine.len > 0) // skip empty cdefines
try cmds.append(b.fmt("-Xcc=-D{s}", .{cdefine}));
try cmds.append(b.fmt("-P-D{s}", .{cdefine}));
break;
}

Expand Down Expand Up @@ -534,11 +540,7 @@ pub fn ldcBuildStep(b: *Build, options: DCompileStep) !*RunStep {
b.step("test", "Run all tests");

if (options.target.result.isWasm()) {
const artifact = addArtifact(options, b, .{
.name = options.name,
.target = options.target,
.optimize = options.optimize,
});
const artifact = addArtifact(b, options);
artifact.addObjectFile(.{ .path = b.fmt("{s}/examples.{s}.o", .{ objpath, options.name }) });
artifact.linkLibrary(options.artifact.?);
artifact.step.dependOn(&ldc_exec.step);
Expand Down Expand Up @@ -583,28 +585,15 @@ pub const DCompileStep = struct {
artifact: ?*Build.Step.Compile = null,
emsdk: ?*Build.Dependency = null,
};
pub fn addArtifact(self: DCompileStep, b: *Build, options: Build.ObjectOptions) *Build.Step.Compile {
pub fn addArtifact(b: *Build, options: DCompileStep) *Build.Step.Compile {
return Build.Step.Compile.create(b, .{
.name = options.name,
.root_module = .{
.target = self.target,
.optimize = self.optimize,
.link_libc = options.link_libc,
.single_threaded = options.single_threaded,
.pic = options.pic,
.strip = options.strip,
.unwind_tables = options.unwind_tables,
.omit_frame_pointer = options.omit_frame_pointer,
.sanitize_thread = options.sanitize_thread,
.error_tracing = options.error_tracing,
.code_model = options.code_model,
.target = options.target,
.optimize = options.optimize,
},
.linkage = self.linkage,
.kind = self.kind,
.max_rss = options.max_rss,
.use_llvm = options.use_llvm,
.use_lld = options.use_lld,
.zig_lib_dir = options.zig_lib_dir orelse b.zig_lib_dir,
.linkage = options.linkage,
.kind = options.kind,
});
}

Expand Down
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
.hash = "1220f1340cd871b444021c600661f921f96091ce0815fa43008528f4844cece7e245",
},
.wasmd = .{
.url = "git+https://github.com/kassane/webassembly#800870e68be1518eeffbb2c0814e23b9543a89cb",
.hash = "12203c2350903f04a07f746b448abb22824a452e8d81500b2fa11a0c3a5ea896b3f6",
.url = "git+https://github.com/kassane/wasmd#067e21e29aea24ec936d6c6b859f7c9a79894f78",
.hash = "122006f8e097d5bd627f26d2aa3b397d92b400c786f13396c47afed66fed1e8ef2c1",
},
},
}
2 changes: 1 addition & 1 deletion src/sokol/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ enum AndroidTooltype {
}
extern(C)
struct Touchpoint {
size_t identifier;
ulong identifier;
float pos_x;
float pos_y;
AndroidTooltype android_tooltype;
Expand Down
4 changes: 2 additions & 2 deletions src/sokol/c/sokol_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -8249,8 +8249,8 @@ _SOKOL_PRIVATE bool _sapp_android_touch_event(const AInputEvent* e) {
for (int32_t i = 0; i < _sapp.event.num_touches; i++) {
sapp_touchpoint* dst = &_sapp.event.touches[i];
dst->identifier = (uintptr_t)AMotionEvent_getPointerId(e, (size_t)i);
dst->pos_x = (AMotionEvent_getRawX(e, (size_t)i) / _sapp.window_width) * _sapp.framebuffer_width;
dst->pos_y = (AMotionEvent_getRawY(e, (size_t)i) / _sapp.window_height) * _sapp.framebuffer_height;
dst->pos_x = (AMotionEvent_getX(e, (size_t)i) / _sapp.window_width) * _sapp.framebuffer_width;
dst->pos_y = (AMotionEvent_getY(e, (size_t)i) / _sapp.window_height) * _sapp.framebuffer_height;
dst->android_tooltype = (sapp_android_tooltype) AMotionEvent_getToolType(e, (size_t)i);
if (action == AMOTION_EVENT_ACTION_POINTER_DOWN ||
action == AMOTION_EVENT_ACTION_POINTER_UP) {
Expand Down
3 changes: 0 additions & 3 deletions src/sokol/c/sokol_gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -13291,9 +13291,6 @@ _SOKOL_PRIVATE void _sg_wgpu_init_caps(void) {
_sg.features.mrt_independent_blend_state = true;
_sg.features.mrt_independent_write_mask = true;

// FIXME: in webgpu.h, wgpuDeviceGetLimits() has a boolean return value, but
// the JS shim doesn't actually return anything
// (see: https://github.com/emscripten-core/emscripten/issues/20278)
wgpuDeviceGetLimits(_sg.wgpu.dev, &_sg.wgpu.limits);

const WGPULimits* l = &_sg.wgpu.limits.limits;
Expand Down
7 changes: 0 additions & 7 deletions src/sokol/c/sokol_glue.c

This file was deleted.

136 changes: 0 additions & 136 deletions src/sokol/c/sokol_glue.h

This file was deleted.

31 changes: 26 additions & 5 deletions src/sokol/glue.d
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
// machine generated, do not edit

module sokol.glue;

import sg = sokol.gfx;
import sapp = sokol.app;

extern(C) sg.ContextDesc sapp_sgcontext() @system @nogc nothrow;
sg.ContextDesc context() @trusted @nogc nothrow {
return sapp_sgcontext();
extern(C) sg.ContextDesc context() @trusted @nogc nothrow {
sg.ContextDesc ctx = {
color_format: sapp.colorFormat(),
depth_format: sapp.depthFormat(),
sample_count: sapp.sampleCount(),
metal: {
device: sapp.metalGetDevice(),
renderpass_descriptor_cb: &sapp.sapp_metal_get_renderpass_descriptor,
drawable_cb: &sapp.sapp_metal_get_drawable,
},
d3d11: {
device: sapp.d3d11GetDevice(),
device_context: sapp.d3d11GetDeviceContext(),
render_target_view_cb: &sapp.sapp_d3d11_get_render_target_view,
depth_stencil_view_cb: &sapp.sapp_d3d11_get_depth_stencil_view,
},
wgpu: {
device: sapp.wgpuGetDevice(),
render_view_cb: &sapp.sapp_wgpu_get_render_view,
resolve_view_cb: &sapp.sapp_wgpu_get_resolve_view,
depth_stencil_view_cb: &sapp.sapp_wgpu_get_depth_stencil_view,
},
};
return ctx;
}

0 comments on commit be0fc3f

Please sign in to comment.