Add gpiodetect and gpioinfo commands
This commit is contained in:
46
build.zig
46
build.zig
@@ -1,18 +1,35 @@
|
||||
const std = @import("std");
|
||||
|
||||
const Item = struct {
|
||||
name: []const u8,
|
||||
src: []const u8,
|
||||
};
|
||||
|
||||
/// List of examples
|
||||
const examples = [_]Item{
|
||||
.{ .name = "blinky", .src = "_examples/blinky.zig" },
|
||||
.{ .name = "multi", .src = "_examples/multi.zig" },
|
||||
};
|
||||
|
||||
/// List of commands
|
||||
const commands = [_]Item{
|
||||
.{ .name = "gpiodetect", .src = "cmd/detect.zig" },
|
||||
.{ .name = "gpioinfo", .src = "cmd/info.zig" },
|
||||
};
|
||||
|
||||
pub fn build(b: *std.Build) !void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
// Add the gpio module so it can be used by the package manager
|
||||
var gpio_module = b.createModule(.{ .source_file = .{ .path = "index.zig" } });
|
||||
try b.modules.put(b.dupe("gpio"), gpio_module);
|
||||
|
||||
// Create a step to build all the examples
|
||||
const examples_step = b.step("examples", "build all the examples");
|
||||
|
||||
inline for ([_]struct { name: []const u8, src: []const u8 }{
|
||||
.{ .name = "blinky", .src = "_examples/blinky.zig" },
|
||||
.{ .name = "multi", .src = "_examples/multi.zig" },
|
||||
}) |cfg| {
|
||||
// Add all the examples
|
||||
inline for (examples) |cfg| {
|
||||
const desc = try std.fmt.allocPrint(b.allocator, "build the {s} example", .{cfg.name});
|
||||
const step = b.step(cfg.name, desc);
|
||||
|
||||
@@ -28,4 +45,25 @@ pub fn build(b: *std.Build) !void {
|
||||
step.dependOn(&build_step.step);
|
||||
examples_step.dependOn(&build_step.step);
|
||||
}
|
||||
|
||||
// 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,
|
||||
});
|
||||
exe.addModule("gpio", gpio_module);
|
||||
|
||||
const build_step = b.addInstallArtifact(exe, .{});
|
||||
step.dependOn(&build_step.step);
|
||||
commands_step.dependOn(&build_step.step);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user