diff --git a/build.zig b/build.zig index 9dd54f7..ac38a2c 100644 --- a/build.zig +++ b/build.zig @@ -318,7 +318,7 @@ pub fn build(b: *std.Build) !void { for (examples) |ex| { if (target.query.os_tag == .emscripten) { - const exe_lib = emcc.compileForEmscripten(b, ex.name, ex.path, target, optimize); + const exe_lib = try emcc.compileForEmscripten(b, ex.name, ex.path, target, optimize); exe_lib.root_module.addImport("raylib", raylib); exe_lib.root_module.addImport("raygui", raygui); const raylib_lib = getRaylib(b, target, optimize, options); diff --git a/emcc.zig b/emcc.zig index 0bc17d4..d25de4c 100644 --- a/emcc.zig +++ b/emcc.zig @@ -39,19 +39,24 @@ pub fn compileForEmscripten( root_source_file: []const u8, target: std.Build.ResolvedTarget, optimize: std.builtin.Mode, -) *std.Build.Step.Compile { +) !*std.Build.Step.Compile { // TODO: It might be a good idea to create a custom compile step, that does // both the compile to static library and the link with emcc by overidding // the make function of the step. However it might also be a bad idea since // it messes with the build system itself. // The project is built as a library and linked later. - return b.addStaticLibrary(.{ + const lib = b.addStaticLibrary(.{ .name = name, .root_source_file = b.path(root_source_file), .target = target, .optimize = optimize, }); + + const emscripten_headers = try std.fs.path.join(b.allocator, &.{ b.sysroot.?, "cache", "sysroot", "include" }); + defer b.allocator.free(emscripten_headers); + lib.addIncludePath(.{ .cwd_relative = emscripten_headers }); + return lib; } // Links a set of items together using emscripten. diff --git a/project_setup.ps1 b/project_setup.ps1 index 88033d4..caab3d5 100644 --- a/project_setup.ps1 +++ b/project_setup.ps1 @@ -27,7 +27,7 @@ pub fn build(b: *std.Build) !void { //web exports are completely separate if (target.query.os_tag == .emscripten) { - const exe_lib = rlz.emcc.compileForEmscripten(b, "$PROJECT_NAME", "src/main.zig", target, optimize); + const exe_lib = try rlz.emcc.compileForEmscripten(b, "$PROJECT_NAME", "src/main.zig", target, optimize); exe_lib.linkLibrary(raylib_artifact); exe_lib.root_module.addImport("raylib", raylib); diff --git a/project_setup.sh b/project_setup.sh index 450ffd4..d255a47 100755 --- a/project_setup.sh +++ b/project_setup.sh @@ -26,7 +26,7 @@ pub fn build(b: *std.Build) !void { //web exports are completely separate if (target.query.os_tag == .emscripten) { - const exe_lib = rlz.emcc.compileForEmscripten(b, "'$PROJECT_NAME'", "src/main.zig", target, optimize); + const exe_lib = try rlz.emcc.compileForEmscripten(b, "'$PROJECT_NAME'", "src/main.zig", target, optimize); exe_lib.linkLibrary(raylib_artifact); exe_lib.root_module.addImport("raylib", raylib);