Skip to content

Commit

Permalink
Emscripten uses its own glfw library (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckrowland authored Dec 15, 2024
1 parent ce756fa commit b780db3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ pub fn build(b: *std.Build) void {
const zglfw = b.dependency("zglfw", .{});
exe.root_module.addImport("zglfw", zglfw.module("root"));
exe.linkLibrary(zglfw.artifact("glfw"));
if (target.result.os.tag != .emscrpten) {
exe.linkLibrary(zglfw.artifact("glfw"));
}
}
```

Expand Down
2 changes: 2 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub fn build(b: *std.Build) void {
},
});

if (target.result.os.tag == .emscripten) return;

const glfw = if (options.shared) blk: {
const lib = b.addSharedLibrary(.{
.name = "glfw",
Expand Down
23 changes: 23 additions & 0 deletions src/zglfw.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1107,3 +1107,26 @@ fn _isLinuxDesktopLike() bool {
else => false,
};
}

//--------------------------------------------------------------------------------------------------
//
// Emscripten
//
//--------------------------------------------------------------------------------------------------
const os = builtin.target.os.tag;
usingnamespace if (os == .emscripten or os == .freestanding) struct {
// GLFW - emscripten uses older version that doesn't have these functions - implement dummies
var glfwGetGamepadStateWarnPrinted: bool = false;
pub export fn glfwGetGamepadState(_: i32, _: ?*anyopaque) i32 {
if (!glfwGetGamepadStateWarnPrinted) {
std.log.err("glfwGetGamepadState(): not implemented! Use emscripten specific functions: https://emscripten.org/docs/api_reference/html5.h.html?highlight=gamepadstate#c.emscripten_get_gamepad_status", .{});
glfwGetGamepadStateWarnPrinted = true;
}
return 0; // false - failure
}

/// use glfwSetCallback instead
pub export fn glfwGetError() i32 {
return 0; // no error
}
} else struct {};

0 comments on commit b780db3

Please sign in to comment.