Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Zig build system #5

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
42 changes: 42 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
@@ -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);
}