From 5efb75c29151079c4e8e186fe178be9ec05a8316 Mon Sep 17 00:00:00 2001 From: Blue Date: Fri, 11 Aug 2023 10:57:27 -0600 Subject: [PATCH] project buils based on target instead of webexport --- README.md | 2 +- build.zig | 3 +-- project_setup.sh | 27 ++++----------------------- 3 files changed, 6 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index efb063f..eca8f18 100755 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ Once emsdk is installed, set it up by running Find the folder where it's installed and run -`zig build webexport --sysroot [path to emsdk]/upstream/emscripten` +`zig build -Dtarget=wasm32-emscripten --sysroot [path to emsdk]/upstream/emscripten` once that is finished, the exported project should be located at `zig-out/htmlout` diff --git a/build.zig b/build.zig index 5571f93..38e7d35 100755 --- a/build.zig +++ b/build.zig @@ -309,12 +309,11 @@ fn updateTargetForWeb(target: std.zig.CrossTarget) std.zig.CrossTarget { }; } -pub fn webExport(b: *std.Build, root_source_file: []const u8, comptime rl_path: []const u8) !*std.Build.Step { +pub fn webExport(b: *std.Build, root_source_file: []const u8, comptime rl_path: []const u8, optimize: std.builtin.OptimizeMode) !*std.Build.Step { // EXPORTING to WEB, the only reasonable output is emscripten ReleaseSafe. // (Safe because since when was performance the main goal of the internet?) //Note: the name doesn't matter, it's only used as the file name of a temporary object, so it's just called "project" const target = try std.zig.CrossTarget.parse(.{ .arch_os_abi = "wasm32-emscripten" }); - const optimize = std.builtin.OptimizeMode.ReleaseSafe; var raylib = rl.getModule(b, rl_path); var raylib_math = rl.math.getModule(b, rl_path); const build_step = try buildForEmscripten(b, "project", root_source_file, target, optimize, raylib, raylib_math); diff --git a/project_setup.sh b/project_setup.sh index e36319d..ed033e4 100755 --- a/project_setup.sh +++ b/project_setup.sh @@ -13,11 +13,10 @@ echo 'const std = @import("std"); const rl = @import("raylib-zig/build.zig"); pub fn build(b: *std.Build) !void { - const web_export = argsContainsWebexport(b.allocator); + const target = b.standardTargetOptions(.{}); + const web_export = target.getOsTag() == .emscripten; + const optimize = b.standardOptimizeOption(.{}); if (!web_export) { - const target = b.standardTargetOptions(.{}); - const optimize = b.standardOptimizeOption(.{}); - var raylib = rl.getModule(b, "raylib-zig"); var raylib_math = rl.math.getModule(b, "raylib-zig"); @@ -35,27 +34,9 @@ pub fn build(b: *std.Build) !void { } //web exports are completely separate, due to the amount of hackery required. - const export_step = b.step("webexport", "Export '$PROJECT_NAME' for the web"); if (web_export) { - export_step.dependOn(try rl.webExport(b, "src/main.zig", "raylib-zig")); + try rl.webExport(b, "src/main.zig", "raylib-zig", optimize); } - - // Building for web requires a --sysroot [emscripten and stuff] - // But asking for that for all builds is not a good user experience - // So it will only actually set up the build scripts if the web export is actually going to happen. -} - -fn argsContainsWebexport(allocator: std.mem.Allocator) bool { - const args = std.process.argsAlloc(allocator) catch { - return false; - }; - defer allocator.free(args); - for (args) |arg| { - if (std.mem.eql(u8, "webexport", arg)) { - return true; - } - } - return false; } ' >> build.zig