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

fix build on latest zig #4

Open
wants to merge 2 commits into
base: master
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
zig-out
zig-cache
.zig-cache
24 changes: 12 additions & 12 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const emulator = "mgba";
const flags = .{"-lgba"};
const devkitpro = "/opt/devkitpro";

pub fn build(b: *std.build.Builder) void {
pub fn build(b: *std.Build) void {
const target = std.zig.CrossTarget{
.cpu_arch = .thumb,
.os_tag = .freestanding,
Expand All @@ -15,15 +15,15 @@ pub fn build(b: *std.build.Builder) void {

const obj = b.addObject(.{
.name = "zig-gba",
.root_source_file = .{ .path = "src/main.zig" },
.root_source_file = b.path("src/main.zig"),
.link_libc = true,
.target = target,
.target = b.resolveTargetQuery(target),
.optimize = optimize,
});
obj.setLibCFile(std.build.FileSource{ .path = "libc.txt" });
obj.addIncludePath(devkitpro ++ "/libgba/include");
obj.addIncludePath(devkitpro ++ "/portlibs/gba/include");
obj.addIncludePath(devkitpro ++ "/portlibs/armv4/include");
obj.setLibCFile(std.Build.LazyPath{ .cwd_relative = "libc.txt" });
obj.addIncludePath(std.Build.LazyPath{ .cwd_relative = devkitpro ++ "/libgba/include"});
obj.addIncludePath(std.Build.LazyPath{ .cwd_relative = devkitpro ++ "/portlibs/gba/include"});
obj.addIncludePath(std.Build.LazyPath{ .cwd_relative = devkitpro ++ "/portlibs/armv4/include"});

const extension = if (builtin.target.os.tag == .windows) ".exe" else "";
const elf = b.addSystemCommand(&.{
Expand All @@ -33,8 +33,8 @@ pub fn build(b: *std.build.Builder) void {
"-mthumb-interwork",
});
_ = elf.addPrefixedOutputFileArg("-Wl,-Map,", "zig-gba.map");
elf.addPrefixedFileSourceArg("-specs=", .{ .path = devkitpro ++ "/devkitARM/arm-none-eabi/lib/gba.specs" });
elf.addFileSourceArg(obj.getOutputSource());
elf.addPrefixedFileArg("-specs=", std.Build.LazyPath{ .cwd_relative = devkitpro ++ "/devkitARM/arm-none-eabi/lib/gba.specs" });
elf.addFileArg(obj.getEmittedBin());
elf.addArgs(&.{
"-L" ++ devkitpro ++ "/libgba/lib",
"-L" ++ devkitpro ++ "/portlibs/gba/lib",
Expand All @@ -49,11 +49,11 @@ pub fn build(b: *std.build.Builder) void {
"-O",
"binary",
});
gba.addFileSourceArg(elf_file);
gba.addFileArg(elf_file);
const gba_file = gba.addOutputFileArg("zig-gba.gba");

const fix = b.addSystemCommand(&.{devkitpro ++ "/tools/bin/gbafix" ++ extension});
fix.addFileSourceArg(gba_file);
fix.addFileArg(gba_file);

const install = b.addInstallBinFile(gba_file, "zig-gba.gba");

Expand All @@ -65,7 +65,7 @@ pub fn build(b: *std.build.Builder) void {

const run_step = b.step("run", "Run in mGBA");
const mgba = b.addSystemCommand(&.{emulator});
mgba.addFileSourceArg(gba_file);
mgba.addFileArg(gba_file);
run_step.dependOn(&install.step);
run_step.dependOn(&mgba.step);
}