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

[examples/minimal-zig] Fix breaking changes of zig nightly / v0.11 #21

Open
wants to merge 1 commit 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
53 changes: 43 additions & 10 deletions examples/minimal-zig/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ pub fn build(b: *std.build.Builder) void {

// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const mode = b.standardReleaseOptions();
const optimize = b.standardOptimizeOption(.{});

// const exe = b.addExecutable("minimal-zig", "src/main.zig");

const exe = b.addExecutable(.{
.name = "minimal-zig",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});

const exe = b.addExecutable("minimal-zig", "src/main.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
exe.addIncludePath("src");
exe.addCSourceFile("src/fenster.c", &[_][]const u8{});
if (exe.target.isDarwin()) {
Expand All @@ -24,21 +30,48 @@ pub fn build(b: *std.build.Builder) void {
exe.linkSystemLibrary("X11");
}
exe.linkSystemLibrary("c");
exe.install();

const run_cmd = exe.run();
// This declares intent for the executable to be installed into the
// standard location when the user invokes the "install" step (the default
// step when running `zig build`).
b.installArtifact(exe);

// This *creates* a Run step in the build graph, to be executed when another
// step is evaluated that depends on it. The next line below will establish
// such a dependency.
const run_cmd = b.addRunArtifact(exe);

// By making the run step depend on the install step, it will be run from the
// installation directory rather than directly from within the cache directory.
// This is not necessary, however, if the application depends on other installed
// files, this ensures they will be present and in the expected location.
run_cmd.step.dependOn(b.getInstallStep());

// This allows the user to pass arguments to the application in the build
// command itself, like this: `zig build run -- arg1 arg2 etc`
if (b.args) |args| {
run_cmd.addArgs(args);
}

// This creates a build step. It will be visible in the `zig build --help` menu,
// and can be selected like this: `zig build run`
// This will evaluate the `run` step rather than the default, which is "install".
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);

const exe_tests = b.addTest("src/main.zig");
exe_tests.setTarget(target);
exe_tests.setBuildMode(mode);
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const unit_tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});

const run_unit_tests = b.addRunArtifact(unit_tests);

// Similar to creating the run step earlier, this exposes a `test` step to
// the `zig build --help` menu, providing a way for the user to request
// running the unit tests.
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&exe_tests.step);
test_step.dependOn(&run_unit_tests.step);
}
2 changes: 1 addition & 1 deletion examples/minimal-zig/src/fenster.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub const Fenster = struct {
};

pub fn new(comptime w: i32, comptime h: i32, title: [:0]const u8) type {
var buf: [w*h]u32 = undefined;
var buf: [w * h]u32 = undefined;
const f = .{
.width = w,
.height = h,
Expand Down
4 changes: 2 additions & 2 deletions examples/minimal-zig/src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ pub fn main() void {
break;
}
// Render x^y^t pattern
for (buf) |_, i| {
buf[i] = @intCast(u32, i % 320) ^ @intCast(u32, i / 240) ^ t;
for (buf, 0..) |_, i| {
buf[i] = @as(u32, @intCast(i % 320)) ^ @as(u32, @intCast(i / 240)) ^ t;
}
t +%= 1;
// Keep ~60 FPS
Expand Down