Skip to content

Commit

Permalink
modernize build.zigs (no longer works with 0.13.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
floooh committed Dec 20, 2024
1 parent 220023a commit b410340
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

8-bit emulator experiments in Zig.

> NOTE: no longer works with Zig 0.13.0, instead use the Zig nightly version
## Usage

### Arcade Machines:
Expand Down
17 changes: 11 additions & 6 deletions emus/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,25 @@ const EmuOptions = struct {
};

fn addEmulator(b: *Build, opts: EmuOptions) void {
const exe = b.addExecutable(.{
.name = opts.name,
const mod = b.createModule(.{
.root_source_file = b.path(opts.src),
.target = opts.target,
.optimize = opts.optimize,
.imports = &.{
.{ .name = "chipz", .module = opts.mod_chipz },
.{ .name = "host", .module = opts.mod_host },
.{ .name = "sokol", .module = opts.mod_sokol },
},
});
if (opts.model != .NONE) {
const options = b.addOptions();
options.addOption(Model, "model", opts.model);
exe.root_module.addOptions("build_options", options);
mod.addOptions("build_options", options);
}
exe.root_module.addImport("chipz", opts.mod_chipz);
exe.root_module.addImport("host", opts.mod_host);
exe.root_module.addImport("sokol", opts.mod_sokol);
const exe = b.addExecutable(.{
.name = opts.name,
.root_module = mod,
});
b.installArtifact(exe);

const run_cmd = b.addRunArtifact(exe);
Expand Down
22 changes: 15 additions & 7 deletions tests/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ pub fn build(b: *Build, opts: Options) void {
inline for (tests) |name| {
const exe = b.addExecutable(.{
.name = name,
.root_source_file = b.path(b.fmt("{s}/{s}.zig", .{ opts.src_dir, name })),
.target = opts.target,
.optimize = opts.optimize,
.root_module = b.createModule(.{
.root_source_file = b.path(b.fmt("{s}/{s}.zig", .{ opts.src_dir, name })),
.target = opts.target,
.optimize = opts.optimize,
.imports = &.{
.{ .name = "chipz", .module = opts.mod_chipz },
},
}),
});
exe.root_module.addImport("chipz", opts.mod_chipz);
b.installArtifact(exe);

const run = b.addRunArtifact(exe);
Expand All @@ -46,11 +50,15 @@ pub fn build(b: *Build, opts: Options) void {
inline for (unit_tests) |name| {
const unit_test = b.addTest(.{
.name = name ++ ".test",
.root_source_file = b.path(b.fmt("{s}/{s}.test.zig", .{ opts.src_dir, name })),
.target = opts.target,
.root_module = b.createModule(.{
.root_source_file = b.path(b.fmt("{s}/{s}.test.zig", .{ opts.src_dir, name })),
.target = opts.target,
.imports = &.{
.{ .name = "chipz", .module = opts.mod_chipz },
},
}),
});
b.installArtifact(unit_test); // install an exe for debugging
unit_test.root_module.addImport("chipz", opts.mod_chipz);
const run_unit_test = b.addRunArtifact(unit_test);
test_step.dependOn(&run_unit_test.step);
}
Expand Down
8 changes: 5 additions & 3 deletions tools/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ const ToolOptions = struct {
fn buildTool(b: *Build, options: ToolOptions) void {
const exe = b.addExecutable(.{
.name = options.name,
.root_source_file = b.path(options.src),
.target = options.target,
.optimize = options.optimize,
.root_module = b.createModule(.{
.root_source_file = b.path(options.src),
.target = options.target,
.optimize = options.optimize,
}),
});
b.installArtifact(exe);

Expand Down

0 comments on commit b410340

Please sign in to comment.