2023-03-09 20:47:22 +00:00
|
|
|
const std = @import("std");
|
2023-03-30 00:07:26 +00:00
|
|
|
const AsciiPrintableStep = @import("AsciiPrintableStep.zig");
|
2023-03-09 20:47:22 +00:00
|
|
|
|
2023-03-30 00:07:26 +00:00
|
|
|
pub fn build(b: *std.build.Builder) !void {
|
2023-03-09 20:47:22 +00:00
|
|
|
// comptime {
|
|
|
|
// const current_zig = builtin.zig_version;
|
|
|
|
// const min_zig = std.SemanticVersion.parse("0.11.0-dev.1254+1f8f79cd5") catch return; // add helper functions to std.zig.Ast
|
|
|
|
// if (current_zig.order(min_zig) == .lt) {
|
|
|
|
// @compileError(std.fmt.comptimePrint("Your Zig version v{} does not meet the minimum build requirement of v{}", .{ current_zig, min_zig }));
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// Standard target options allows the person running `zig build` to choose
|
|
|
|
// what target to build for. Here we do not override the defaults, which
|
|
|
|
// means any target is allowed, and the default is native. Other options
|
|
|
|
// for restricting supported target set are available.
|
|
|
|
const target = b.standardTargetOptions(.{});
|
|
|
|
|
2023-03-19 17:54:51 +00:00
|
|
|
// Standard optimization options allow the person running `zig build` to select
|
|
|
|
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
|
|
|
|
// set a preferred release mode, allowing the user to decide how to optimize.
|
|
|
|
const optimize = b.standardOptimizeOption(.{});
|
2023-03-09 20:47:22 +00:00
|
|
|
|
|
|
|
// Dependency based on the package manager MVP:
|
|
|
|
// https://github.com/ziglang/zig/pull/14265
|
|
|
|
// This is highly subject to change, and without tooling at the moment
|
|
|
|
const im_dep = b.dependency("ImageMagick", .{});
|
|
|
|
const z_dep = b.dependency("libz", .{});
|
|
|
|
|
2023-03-19 17:54:51 +00:00
|
|
|
const i2cdriver = b.addStaticLibrary(.{
|
|
|
|
.name = "i2cdriver",
|
|
|
|
.target = target,
|
|
|
|
.optimize = optimize,
|
|
|
|
});
|
2023-03-09 20:47:22 +00:00
|
|
|
i2cdriver.addCSourceFile("lib/i2cdriver/i2cdriver.c", &[_][]const u8{ "-Wall", "-Wpointer-sign", "-Werror" });
|
|
|
|
i2cdriver.linkLibC();
|
|
|
|
|
2023-03-19 17:54:51 +00:00
|
|
|
const exe = b.addExecutable(.{
|
|
|
|
.name = "i2c",
|
|
|
|
.root_source_file = .{ .path = "src/main.zig" },
|
|
|
|
.target = target,
|
|
|
|
.optimize = optimize,
|
|
|
|
});
|
2023-03-09 20:47:22 +00:00
|
|
|
exe.linkLibrary(im_dep.artifact("MagickWand"));
|
|
|
|
exe.linkLibrary(z_dep.artifact("z"));
|
|
|
|
exe.linkLibrary(i2cdriver);
|
|
|
|
exe.addIncludePath("lib/i2cdriver");
|
|
|
|
exe.install();
|
|
|
|
|
2023-04-03 17:40:53 +00:00
|
|
|
// TODO: I believe we can use runArtifact on a second
|
|
|
|
// exe with a different source file for font generation
|
|
|
|
// taking us to a series of 5 byte arrays for each
|
|
|
|
// character in a font.
|
2023-03-30 00:07:26 +00:00
|
|
|
exe.step.dependOn(&AsciiPrintableStep.create(b, .{ .path = "src/images" }).step);
|
|
|
|
// exe.step.dependOn((try fontGeneration(b, target)));
|
2023-03-09 20:47:22 +00:00
|
|
|
const run_cmd = exe.run();
|
|
|
|
run_cmd.step.dependOn(b.getInstallStep());
|
|
|
|
if (b.args) |args| {
|
|
|
|
run_cmd.addArgs(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
const run_step = b.step("run", "Run the app");
|
|
|
|
run_step.dependOn(&run_cmd.step);
|
|
|
|
|
2023-03-19 17:54:51 +00:00
|
|
|
const exe_tests = b.addTest(.{
|
|
|
|
.root_source_file = .{ .path = "src/main.zig" },
|
|
|
|
.target = target,
|
|
|
|
.optimize = optimize,
|
|
|
|
});
|
2023-03-09 20:47:22 +00:00
|
|
|
|
|
|
|
const test_step = b.step("test", "Run unit tests");
|
|
|
|
test_step.dependOn(&exe_tests.step);
|
|
|
|
}
|
2023-03-30 00:07:26 +00:00
|
|
|
|
|
|
|
// Should be able to remove this
|
|
|
|
fn fontGeneration(b: *std.build.Builder, target: anytype) !*std.build.Step {
|
|
|
|
if (target.getOs().tag != .linux) return error.UnsupportedBuildOS;
|
|
|
|
const fontgen = b.step("gen", "Generate font image files");
|
|
|
|
fontgen.dependOn(&b.addSystemCommand(&.{ "/bin/sh", "-c", "./fontgen" }).step);
|
|
|
|
|
|
|
|
// This can probably be triggered instead by GitRepoStep cloning the repo
|
|
|
|
// exe.step.dependOn(cg);
|
|
|
|
return fontgen;
|
|
|
|
}
|