dotfiles/build_common.zig

22 lines
866 B
Zig
Raw Normal View History

//! Shared code for script build scripts
const std = @import("std");
pub const confgen_json_opt = std.json.ParseOptions{ .ignore_unknown_fields = true };
2023-06-01 16:38:18 +02:00
/// Retrieve some confgen options given a relative path to the dotfile root and a struct type
/// with a field for each option.
2023-06-01 16:38:18 +02:00
pub fn confgenGet(comptime T: type, root_path: []const u8, alloc: std.mem.Allocator) !T {
const optsjson = try std.fs.path.join(alloc, &.{ root_path, "cgout", "opts.json" });
defer alloc.free(optsjson);
var file = try std.fs.cwd().openFile(optsjson, .{});
defer file.close();
var buf_reader = std.io.bufferedReader(file.reader());
var reader = std.json.Reader(1024 * 8, @TypeOf(buf_reader.reader()))
.init(alloc, buf_reader.reader());
defer reader.deinit();
return try std.json.parseFromTokenSource(T, alloc, &reader, confgen_json_opt);
}