2023-06-01 15:58:51 +02:00
|
|
|
const std = @import("std");
|
|
|
|
|
|
|
|
pub const confgen_json_opt = std.json.ParseOptions{ .ignore_unknown_fields = true };
|
|
|
|
|
2024-03-20 20:45:59 +01:00
|
|
|
pub fn build(b: *std.Build) void {
|
|
|
|
_ = b.addModule("common", .{
|
2024-06-21 18:43:42 +02:00
|
|
|
.root_source_file = b.path("src/main.zig"),
|
2024-03-20 20:45:59 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: make confgen generate zon and delete
|
2023-06-01 16:38:18 +02:00
|
|
|
/// Retrieve some confgen options given a relative path to the dotfile root and a struct type
|
2023-06-01 15:58:51 +02:00
|
|
|
/// with a field for each option.
|
2024-03-20 20:45:59 +01:00
|
|
|
pub fn confgenGet(comptime T: type, alloc: std.mem.Allocator) !T {
|
2024-06-29 21:36:13 +02:00
|
|
|
const optjson_path = comptime std.fs.path.dirname(@src().file).? ++ "/../../cgout/_cgfs/opts.json";
|
2024-03-20 20:45:59 +01:00
|
|
|
var file = try std.fs.cwd().openFile(optjson_path, .{});
|
2023-06-01 16:27:35 +02:00
|
|
|
defer file.close();
|
|
|
|
var buf_reader = std.io.bufferedReader(file.reader());
|
2023-06-01 15:58:51 +02:00
|
|
|
|
2023-06-01 16:27:35 +02:00
|
|
|
var reader = std.json.Reader(1024 * 8, @TypeOf(buf_reader.reader()))
|
|
|
|
.init(alloc, buf_reader.reader());
|
|
|
|
defer reader.deinit();
|
2023-06-01 15:58:51 +02:00
|
|
|
|
2023-06-27 23:20:35 +02:00
|
|
|
const ret = try std.json.parseFromTokenSource(T, alloc, &reader, confgen_json_opt);
|
|
|
|
|
2023-06-25 23:57:51 +02:00
|
|
|
// We just grab the value from the parse result as this data will almost certainly have been
|
|
|
|
// allocated with the builder's arena anyways.
|
2023-06-27 23:20:35 +02:00
|
|
|
return ret.value;
|
2023-06-01 15:58:51 +02:00
|
|
|
}
|