Skip to content
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,3 +1,3 @@
zig-out
zig-cache
.zig-cache
gbdk
27 changes: 19 additions & 8 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
const std = @import("std");
const builtin = @import("builtin");
const utils = @import("utils.zig");

const emulator = "vbam";

pub fn build(b: *std.build.Builder) !void {
b.build_root = try utils.root(b.build_root);
fn buildImpl(b: *std.Build) !void {
// Obtenir la racine du projet (cwd lors de l'invocation de zig build)
const root_path = try std.process.getCwdAlloc(b.allocator);
defer b.allocator.free(root_path);

// Télécharge + extrait le toolchain GBDK si absent
try utils.ensure_tar(
b.allocator,
b.build_root,
root_path,
"gbdk",
"https://github.com/gbdk-2020/gbdk-2020/releases/download/4.0.6/gbdk-linux64.tar.gz",
"https://github.com/gbdk-2020/gbdk-2020/releases/download/4.4.0/gbdk-linux64.tar.gz",
);
const folder = try std.fs.openDirAbsolute(b.build_root, .{});

const folder = try std.fs.openDirAbsolute(root_path, .{});
folder.makeDir("zig-out") catch {};

const obj = b.addSystemCommand(&.{
Expand All @@ -24,18 +28,25 @@ pub fn build(b: *std.build.Builder) !void {
"zig-gb.o",
"../src/main.c",
});
obj.cwd = "zig-out";
obj.cwd = b.path("zig-out");

const gb = b.addSystemCommand(&.{
"../gbdk/bin/lcc", "-Wa-l", "-DUSE_SFR_FOR_REG", "-o", "zig-gb.gb", "zig-gb.o",
});
gb.cwd = "zig-out";
gb.cwd = b.path("zig-out");

b.default_step.dependOn(&gb.step);
gb.step.dependOn(&obj.step);

const run_step = b.step("run", "Run in Visual Boy Advance");
const vbam = b.addSystemCommand(&.{ emulator, "-F", "zig-out/zig-gb.gb" });
vbam.cwd = b.path(".");
run_step.dependOn(&gb.step);
run_step.dependOn(&vbam.step);
}

pub fn build(b: *std.Build) void {
buildImpl(b) catch |err| {
std.log.err("build failed: {s}", .{@errorName(err)});
};
}
11 changes: 7 additions & 4 deletions utils.zig
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ test "root" {

/// Run shell command
pub fn exec(allocator: std.mem.Allocator, cwd: []const u8, argv: []const []const u8, opts: Options) !void {
var child = try std.ChildProcess.init(argv, allocator);
var child = std.process.Child.init(argv, allocator);
child.cwd = cwd;
if (opts.enable_stdout) child.stdout = std.io.getStdOut() else child.stdout = null;
if (opts.enable_stderr) child.stderr = std.io.getStdErr() else child.stderr = null;
_ = try child.spawnAndWait();
// Comportement des flux selon options
child.stdin_behavior = .Ignore;
child.stdout_behavior = if (opts.enable_stdout) .Inherit else .Ignore;
child.stderr_behavior = if (opts.enable_stderr) .Inherit else .Ignore;
try child.spawn();
_ = try child.wait();
}

/// Ensure repository exists, if not clone it with git. cwd is absolute path
Expand Down