summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig97
1 files changed, 24 insertions, 73 deletions
diff --git a/build.zig b/build.zig
index 4302bcb..10ea9b1 100644
--- a/build.zig
+++ b/build.zig
@@ -3,25 +3,8 @@ const rlz = @import("raylib_zig");
const exe_name = "hackathon";
-const all_targets: []const std.Target.Query = &.{
- .{ .cpu_arch = .aarch64, .os_tag = .macos },
- // .{ .cpu_arch = .aarch64, .os_tag = .linux },
- .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .gnu },
- // .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .musl },
- .{ .cpu_arch = .x86_64, .os_tag = .windows },
- //
- // TODO: add WASM support
- //.{ .cpu_arch = .wasm32, .os_tag = .emscripten },
-};
-
-const wasm_targets: []const std.Target.Query = &.{
- // TODO: add WASM support
- .{ .cpu_arch = .wasm32, .os_tag = .emscripten },
-};
-
pub fn build(b: *std.Build) !void {
- const build_all = b.option(bool, "ball", "Build and package");
- const build_wasm = b.option(bool, "wasm", "Build and package WASM");
+ const build_wasm = b.option(bool, "bwasm", "Build and package WASM");
const emcc = rlz.emcc;
_ = emcc;
@@ -29,18 +12,15 @@ pub fn build(b: *std.Build) !void {
const optimize = b.standardOptimizeOption(.{});
const run_step = b.step("run", "Run the app");
- const pack_step = b.step("pack", "Build and package for each supported OS/arch");
-
- try buildRun(b, run_step, optimize);
- if (build_all orelse false) {
- try buildPack(b, pack_step, optimize, all_targets);
- } else if (build_wasm orelse false) {
- try buildPack(b, pack_step, optimize, wasm_targets);
+ if (build_wasm orelse false) {
+ try buildWasm(b, run_step, optimize);
+ } else {
+ try buildNative(b, run_step, optimize);
}
}
-fn buildRun(b: *std.Build, parent: *std.Build.Step, optimize: std.builtin.OptimizeMode) !void {
+fn buildNative(b: *std.Build, parent: *std.Build.Step, optimize: std.builtin.OptimizeMode) !void {
const target = b.standardTargetOptions(.{});
const exe_mod = b.createModule(.{
@@ -65,61 +45,32 @@ fn buildRun(b: *std.Build, parent: *std.Build.Step, optimize: std.builtin.Optimi
parent.dependOn(&run_cmd.step);
}
-const pkg_folder = "pkg";
-
-// TODO: fix this function
-fn buildPack(b: *std.Build, parent: *std.Build.Step, optimize: std.builtin.OptimizeMode, targets: []const std.Target.Query) !void {
- const rm_pkg = b.addSystemCommand(&.{ "rm", "-rf", pkg_folder });
-
- const mkdir_pkg = b.addSystemCommand(&.{ "mkdir", pkg_folder });
- mkdir_pkg.step.dependOn(&rm_pkg.step);
-
- for (targets) |t| {
- const target = b.resolveTargetQuery(t);
- const target_triple = try t.zigTriple(b.allocator);
+fn buildWasm(b: *std.Build, parent: *std.Build.Step, optimize: std.builtin.OptimizeMode) !void {
+ if (true)
+ @panic("WASM builds are not supported at this time");
- const exe = b.addExecutable(.{
- .name = exe_name,
- .root_source_file = b.path("src/main.zig"),
- .target = target,
- .optimize = optimize,
- });
-
- try addRaylibDep(b, exe, target, optimize);
-
- const target_output = b.addInstallArtifact(exe, .{
- .dest_dir = .{
- .override = .{
- .custom = target_triple,
- },
- },
- });
+ const target = b.standardTargetOptions(.{});
- b.getInstallStep().dependOn(&target_output.step);
+ const exe_mod = b.createModule(.{
+ .root_source_file = b.path("src/main.zig"),
+ .target = target,
+ .optimize = optimize,
+ });
- const move_output = b.addSystemCommand(&.{
- "mv",
- try std.fmt.allocPrint(b.allocator, "zig-out/{s}", .{target_triple}),
- ".",
- });
+ const exe = b.addExecutable(.{
+ .name = exe_name,
+ .root_module = exe_mod,
+ });
- move_output.step.dependOn(b.getInstallStep());
+ try addRaylibDep(b, exe, target, optimize);
- const zip = b.addSystemCommand(&.{
- "zip",
- "-r",
- try std.fmt.allocPrint(b.allocator, "{s}/{s}.zip", .{ pkg_folder, target_triple }),
- target_triple,
- });
+ b.installArtifact(exe);
- zip.step.dependOn(&mkdir_pkg.step);
- zip.step.dependOn(&move_output.step);
+ const run_cmd = b.addRunArtifact(exe);
- const rm_exe = b.addSystemCommand(&.{ "rm", "-rf", target_triple });
- rm_exe.step.dependOn(&zip.step);
+ run_cmd.step.dependOn(b.getInstallStep());
- parent.dependOn(&rm_exe.step);
- }
+ parent.dependOn(&run_cmd.step);
}
fn addRaylibDep(b: *std.Build, exe: *std.Build.Step.Compile, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) !void {