Compare commits
No commits in common. "cf4dea84d99b3353953c53213e68e8b69d39e6dc" and "9286a82d8621650bc279c93e982400014ba90e06" have entirely different histories.
cf4dea84d9
...
9286a82d86
71
build.zig
71
build.zig
@ -15,57 +15,56 @@ pub fn build(b: *std.Build) void {
|
||||
// set a preferred release mode, allowing the user to decide how to optimize.
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
// Build harness based on https://github.com/SpexGuy/Zig-AoC-Template.
|
||||
|
||||
// Build, run, and install targets for "all."
|
||||
const build_all = b.step("all", "Build all days");
|
||||
const run_all = b.step("run", "Run all days");
|
||||
const test_all = b.step("test", "Run all tests");
|
||||
|
||||
// Generate build, run, and install targets for all days that have been
|
||||
// created.
|
||||
for (1..25) |day| {
|
||||
const day_string = b.fmt("day{:0>2}", .{day});
|
||||
const src = b.fmt("src/{s}.zig", .{day_string});
|
||||
std.fs.cwd().access(src, .{}) catch continue;
|
||||
|
||||
// Build and install
|
||||
const exe = b.addExecutable(.{
|
||||
.name = b.fmt("aoc23-{s}", .{day_string}),
|
||||
.root_source_file = .{ .path = src },
|
||||
.name = "aoc23",
|
||||
// In this case the main source file is merely a path, however, in more
|
||||
// complicated build scripts, this could be a generated file.
|
||||
.root_source_file = .{ .path = "src/main.zig" },
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
b.installArtifact(exe);
|
||||
build_all.dependOn(&exe.step);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
const run_step = b.step(
|
||||
b.fmt("run-{s}", .{day_string}),
|
||||
b.fmt("Run {s} executable", .{day_string}),
|
||||
);
|
||||
// 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);
|
||||
run_all.dependOn(&run_cmd.step);
|
||||
|
||||
// Test
|
||||
const unit_test = b.addTest(.{
|
||||
.root_source_file = .{ .path = src },
|
||||
// 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 test_cmd = b.addRunArtifact(unit_test);
|
||||
const test_step = b.step(
|
||||
b.fmt("test-{s}", .{day_string}),
|
||||
b.fmt("Run {s} tests", .{day_string}),
|
||||
);
|
||||
test_step.dependOn(&test_cmd.step);
|
||||
test_all.dependOn(&test_cmd.step);
|
||||
}
|
||||
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(&run_unit_tests.step);
|
||||
}
|
||||
|
@ -14,11 +14,7 @@
|
||||
in
|
||||
{
|
||||
devShells.default = pkgs.mkShellNoCC {
|
||||
buildInputs = [
|
||||
pkgs.aoc-cli
|
||||
zig
|
||||
pkgs.zls
|
||||
];
|
||||
buildInputs = [ zig pkgs.zls ];
|
||||
};
|
||||
|
||||
packages.default = pkgs.stdenv.mkDerivation {
|
||||
|
@ -1,4 +0,0 @@
|
||||
const std = @import("std");
|
||||
const util = @import("util.zig");
|
||||
|
||||
pub fn main() !void {}
|
24
src/main.zig
Normal file
24
src/main.zig
Normal file
@ -0,0 +1,24 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn main() !void {
|
||||
// Prints to stderr (it's a shortcut based on `std.io.getStdErr()`)
|
||||
std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
|
||||
|
||||
// stdout is for the actual output of your application, for example if you
|
||||
// are implementing gzip, then only the compressed bytes should be sent to
|
||||
// stdout, not any debugging messages.
|
||||
const stdout_file = std.io.getStdOut().writer();
|
||||
var bw = std.io.bufferedWriter(stdout_file);
|
||||
const stdout = bw.writer();
|
||||
|
||||
try stdout.print("Run `zig build test` to run the tests.\n", .{});
|
||||
|
||||
try bw.flush(); // don't forget to flush!
|
||||
}
|
||||
|
||||
test "simple test" {
|
||||
var list = std.ArrayList(i32).init(std.testing.allocator);
|
||||
defer list.deinit(); // try commenting this out and see if zig detects the memory leak!
|
||||
try list.append(42);
|
||||
try std.testing.expectEqual(@as(i32, 42), list.pop());
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
const gpa_impl = std.heap.GeneralPurposeAllocator(.{});
|
||||
pub const gpa = gpa_impl.allocator();
|
Loading…
Reference in New Issue
Block a user