ssd1306_oled_display_cli/build.zig

97 lines
3.8 KiB
Zig
Raw Normal View History

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
2024-05-01 04:27:37 +00:00
pub fn build(b: *std.Build) !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(.{});
// 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", .{});
const i2cdriver = b.addStaticLibrary(.{
.name = "i2cdriver",
.target = target,
.optimize = optimize,
});
2024-05-01 04:27:37 +00:00
i2cdriver.addCSourceFile(.{
.file = b.path("lib/i2cdriver/i2cdriver.c"),
.flags = &[_][]const u8{ "-Wall", "-Wpointer-sign", "-Werror" },
});
2023-03-09 20:47:22 +00:00
i2cdriver.linkLibC();
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);
2024-05-01 04:27:37 +00:00
exe.addIncludePath(b.path("lib/i2cdriver"));
b.installArtifact(exe);
2023-03-09 20:47:22 +00:00
const exe_fontgen = b.addExecutable(.{
.name = "fontgen",
.root_source_file = .{ .path = "src/fontgen.zig" },
.target = target,
.optimize = optimize,
});
exe_fontgen.linkLibrary(im_dep.artifact("MagickWand"));
exe_fontgen.linkLibrary(z_dep.artifact("z"));
2024-05-01 04:27:37 +00:00
exe.step.dependOn(&b.addRunArtifact(exe_fontgen).step);
2023-04-09 00:03:04 +00:00
// If image based characters are needed, uncomment this
// exe.step.dependOn(&AsciiPrintableStep.create(b, .{ .path = "src/images" }).step);
2024-05-01 04:27:37 +00:00
const run_cmd = b.addRunArtifact(exe);
2023-03-09 20:47:22 +00:00
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);
const exe_tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
2023-04-03 22:12:31 +00:00
exe_tests.linkLibrary(im_dep.artifact("MagickWand"));
exe_tests.linkLibrary(z_dep.artifact("z"));
exe_tests.linkLibrary(i2cdriver);
2024-05-01 04:27:37 +00:00
exe_tests.addIncludePath(b.path("lib/i2cdriver"));
2023-03-09 20:47:22 +00:00
const test_step = b.step("test", "Run unit tests");
2024-05-01 04:27:37 +00:00
test_step.dependOn(&b.addRunArtifact(exe_tests).step);
2023-03-09 20:47:22 +00:00
}
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;
}