project buils based on target instead of webexport

This commit is contained in:
Blue 2023-08-11 10:57:27 -06:00
parent 6d5722ba35
commit 5efb75c291
3 changed files with 6 additions and 26 deletions

View File

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

View File

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

View File

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