libvaxis/build.zig
Jora Troosh 4a463cfa3a
refactor: make code more idiomatic
- Added standard .gitattributes file for Zig projects.
- Reworked build.zig a little, hopefully it's a bit clearer. Also, now zig build will run all steps.
- outer: while in examples was redundant since there's only one loop to break from. switch expressions don't allow breaking from them, so breaking is only for loops, i.e. while and for.
- When returning a struct instance from a function, the compiler infers the return type from function signature, so instead of return MyType{...}; , it's more idiomatic to write return .{...};.
- Logging adds a new line by default, so you don't usually need to write \n like here: log.debug("event: {}\r\n", .{event});.
2024-02-11 12:59:33 -06:00

63 lines
1.9 KiB
Zig

const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const root_source_file = std.Build.LazyPath.relative("src/main.zig");
// Dependencies
const ziglyph_dep = b.dependency("ziglyph", .{
.optimize = optimize,
.target = target,
});
const zigimg_dep = b.dependency("zigimg", .{
.optimize = optimize,
.target = target,
});
// Module
const vaxis_mod = b.addModule("vaxis", .{ .root_source_file = root_source_file });
vaxis_mod.addImport("ziglyph", ziglyph_dep.module("ziglyph"));
vaxis_mod.addImport("zigimg", zigimg_dep.module("zigimg"));
// Examples
const example_step = b.step("example", "Run examples");
const example = b.addExecutable(.{
.name = "vaxis_pathological_example",
.root_source_file = std.Build.LazyPath.relative("examples/pathological.zig"),
.target = target,
.optimize = optimize,
});
example.root_module.addImport("vaxis", vaxis_mod);
const example_run = b.addRunArtifact(example);
example_step.dependOn(&example_run.step);
b.default_step.dependOn(example_step);
// Tests
const tests_step = b.step("test", "Run tests");
const tests = b.addTest(.{
.root_source_file = root_source_file,
.target = target,
.optimize = optimize,
});
tests.root_module.addImport("ziglyph", ziglyph_dep.module("ziglyph"));
tests.root_module.addImport("zigimg", zigimg_dep.module("zigimg"));
const tests_run = b.addRunArtifact(tests);
tests_step.dependOn(&tests_run.step);
b.default_step.dependOn(tests_step);
// Lints
const lints_step = b.step("lint", "Run lints");
const lints = b.addFmt(.{
.paths = &.{ "src", "build.zig" },
.check = true,
});
lints_step.dependOn(&lints.step);
b.default_step.dependOn(lints_step);
}