From 7d62be63e2f578270d9ddbb6efc52b88719179cf Mon Sep 17 00:00:00 2001 From: Blue Date: Mon, 14 Aug 2023 00:09:46 -0600 Subject: [PATCH] small modification to emscripten build --- build.zig | 12 ++++-------- project_setup.sh | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/build.zig b/build.zig index 946e97e..5a32ef1 100755 --- a/build.zig +++ b/build.zig @@ -179,7 +179,9 @@ pub fn build(b: *std.Build) !void { const raylib_artifact = getArtifact(b, target, optimize); // Note that raylib itself isn't actually added to the exe_lib output file, so it also needs to be linked with emscripten. exe_lib.linkLibrary(raylib_artifact); - const link_step = try linkWithEmscripten(b, &[_]*std.Build.Step.Compile{ exe_lib, raylib_artifact }, &[_]std.Build.LazyPath{.{ .path = "resources/" }}); + const link_step = try linkWithEmscripten(b, &[_]*std.Build.Step.Compile{ exe_lib, raylib_artifact }); + link_step.addArg("--embed-file"); + link_step.addArg("resources/"); link_step.step.dependOn(&raylib_artifact.step); link_step.step.dependOn(&exe_lib.step); const run_step = try emscriptenRunStep(b); @@ -249,7 +251,7 @@ pub fn compileForEmscripten(b: *std.Build, name: []const u8, root_source_file: [ // TODO: test if shared libraries are accepted, I don't remember if emcc can link a shared library with a project or not // TODO: add a way to convert from an input path to the output path, if emscripten even allows such a thing. // TODO: add a parameter that allows a custom output directory -pub fn linkWithEmscripten(b: *std.Build, itemsToLink: []const *std.Build.Step.Compile, filesToInclude: []const std.Build.LazyPath) !*std.Build.Step.Run { +pub fn linkWithEmscripten(b: *std.Build, itemsToLink: []const *std.Build.Step.Compile) !*std.Build.Step.Run { //Raylib uses --sysroot in order to find emscripten, so do the same here if (b.sysroot == null) { @panic("Pass '--sysroot \"[path to emsdk installation]/upstream/emscripten\"'"); @@ -275,12 +277,6 @@ pub fn linkWithEmscripten(b: *std.Build, itemsToLink: []const *std.Build.Step.Co //This puts the file in zig-out/htmlout/index.html emcc_command.step.dependOn(&mkdir_command.step); emcc_command.addArgs(&[_][]const u8{ "-o", emccOutputDir ++ emccOutputFile, "-sFULL-ES3=1", "-sUSE_GLFW=3", "-sASYNCIFY", "-O3", "--emrun" }); - - //Web builds can't just have the files next to the executable, they have to be linked with the program - for (filesToInclude) |file| { - emcc_command.addArg("--embed-file"); - emcc_command.addArg(file.path); - } return emcc_command; } diff --git a/project_setup.sh b/project_setup.sh index 7e921a4..5b18cfd 100755 --- a/project_setup.sh +++ b/project_setup.sh @@ -25,7 +25,7 @@ pub fn build(b: *std.Build) !void { const raylib_artifact = rl.getArtifact(b, target, optimize); // Note that raylib itself is not actually added to the exe_lib output file, so it also needs to be linked with emscripten. exe_lib.linkLibrary(raylib_artifact); - const link_step = try rl.linkWithEmscripten(b, &[_]*std.Build.Step.Compile{ exe_lib, raylib_artifact }, &[_]std.Build.LazyPath{.{ .path = "resources/" }}); + const link_step = try rl.linkWithEmscripten(b, &[_]*std.Build.Step.Compile{ exe_lib, raylib_artifact }); link_step.step.dependOn(&raylib_artifact.step); link_step.step.dependOn(&exe_lib.step); b.getInstallStep().dependOn(&link_step.step);