zig-gpio/build.zig

72 lines
2.3 KiB
Zig
Raw Normal View History

2023-12-12 03:20:44 +00:00
const std = @import("std");
2023-12-14 01:19:46 +00:00
const Item = struct {
name: []const u8,
src: []const u8,
};
/// List of examples
const examples = [_]Item{
2023-12-14 01:28:19 +00:00
.{ .name = "blinky", .src = "src/examples/blinky.zig" },
.{ .name = "multi", .src = "src/examples/multi.zig" },
2023-12-14 01:19:46 +00:00
};
/// List of commands
const commands = [_]Item{
2023-12-14 01:21:18 +00:00
.{ .name = "gpiodetect", .src = "src/cmd/detect.zig" },
.{ .name = "gpioinfo", .src = "src/cmd/info.zig" },
2023-12-25 20:04:03 +00:00
.{ .name = "gpioget", .src = "src/cmd/get.zig" },
2023-12-25 20:50:17 +00:00
.{ .name = "gpioset", .src = "src/cmd/set.zig" },
2023-12-14 01:19:46 +00:00
};
2023-12-12 03:20:44 +00:00
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
2023-12-14 01:19:46 +00:00
// Add the gpio module so it can be used by the package manager
2024-04-26 21:17:36 +00:00
const gpio_module = b.createModule(.{ .root_source_file = .{ .path = "src/index.zig" } });
2023-12-12 03:20:44 +00:00
try b.modules.put(b.dupe("gpio"), gpio_module);
2023-12-14 01:19:46 +00:00
// Create a step to build all the examples
2023-12-12 03:20:44 +00:00
const examples_step = b.step("examples", "build all the examples");
2023-12-14 01:19:46 +00:00
// Add all the examples
inline for (examples) |cfg| {
2023-12-12 03:20:44 +00:00
const desc = try std.fmt.allocPrint(b.allocator, "build the {s} example", .{cfg.name});
const step = b.step(cfg.name, desc);
const exe = b.addExecutable(.{
.name = cfg.name,
.root_source_file = .{ .path = cfg.src },
.target = target,
.optimize = optimize,
});
2024-04-26 21:17:36 +00:00
exe.root_module.addImport("gpio", gpio_module);
2023-12-12 03:20:44 +00:00
const build_step = b.addInstallArtifact(exe, .{});
step.dependOn(&build_step.step);
examples_step.dependOn(&build_step.step);
}
2023-12-14 01:19:46 +00:00
// Create a step to build all the commands
const commands_step = b.step("commands", "build all the commands");
// Add all the commands
inline for (commands) |cfg| {
const desc = try std.fmt.allocPrint(b.allocator, "build the {s} command", .{cfg.name});
const step = b.step(cfg.name, desc);
const exe = b.addExecutable(.{
.name = cfg.name,
.root_source_file = .{ .path = cfg.src },
.target = target,
.optimize = optimize,
});
2024-04-26 21:17:36 +00:00
exe.root_module.addImport("gpio", gpio_module);
2023-12-14 01:19:46 +00:00
const build_step = b.addInstallArtifact(exe, .{});
step.dependOn(&build_step.step);
commands_step.dependOn(&build_step.step);
}
2023-12-12 03:20:44 +00:00
}