Automatically include Emscripten headers (#173)

* add emscripten headers

* update func to return error
This commit is contained in:
Daniel Koucher Machado 2024-11-26 16:18:33 -03:00 committed by GitHub
parent 606d9bb9ba
commit de8c2d4585
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 10 additions and 5 deletions

View File

@ -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);

View File

@ -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.

View File

@ -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);

View File

@ -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);