From 2c775c5be6a8ad01f8185903cad7aedb0f074145 Mon Sep 17 00:00:00 2001 From: Mathew R Gordon <72643694+mgord9518@users.noreply.github.com> Date: Mon, 7 Oct 2024 21:28:56 -0600 Subject: [PATCH 1/2] Add build.zig --- build.zig | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 build.zig diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..9405dee --- /dev/null +++ b/build.zig @@ -0,0 +1,42 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) !void { + const strip = b.option(bool, "strip", "remove debug symbols from executable") orelse false; + + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + const exe = b.addExecutable(.{ + .name = "z64decompress", + .target = target, + .optimize = optimize, + .strip = strip, + }); + + exe.addCSourceFiles(.{ + .files = &.{ + "src/main.c", + "src/file.c", + "src/n64crc.c", + "src/wow.c", + "src/decoder/aplib.c", + "src/decoder/lzo.c", + "src/decoder/ucl.c", + "src/decoder/yaz.c", + "src/decoder/zlib.c", + }, + }); + + exe.linkLibC(); + + b.installArtifact(exe); + + const run_cmd = b.addRunArtifact(exe); + run_cmd.step.dependOn(b.getInstallStep()); + if (b.args) |args| { + run_cmd.addArgs(args); + } + + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); +} \ No newline at end of file From a8779135fceb1c28802f6b0d8e83b4a864702e0f Mon Sep 17 00:00:00 2001 From: Mathew R Gordon <72643694+mgord9518@users.noreply.github.com> Date: Mon, 7 Oct 2024 21:32:54 -0600 Subject: [PATCH 2/2] Add Zig build instructions --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index b4de75c..354715d 100644 --- a/README.md +++ b/README.md @@ -30,3 +30,9 @@ z64decompress "file-in.yaz" "file-out.bin" -c yaz -i ## Building I have included shell scripts for building Linux and Windows binaries. Windows binaries are built using a cross compiler ([I recommend `MXE`](https://mxe.cc/)). +Zig may also be used for easy cross-compilation: +```sh +zig build -Dtarget=x86_64-linux-musl +zig build -Dtarget=x86_64-windows +zig build -Dtarget=aarch64-macos +```