diff --git a/build_common.zig b/build_common.zig new file mode 100644 index 0000000..59ea0cd --- /dev/null +++ b/build_common.zig @@ -0,0 +1,32 @@ +//! Shared code for script build scripts +const std = @import("std"); + +pub const confgen_json_opt = std.json.ParseOptions{ .ignore_unknown_fields = true }; + +/// Retrieve some confgen options given a path to the cgfile and a struct type +/// with a field for each option. +pub fn confgenGet(comptime T: type, cgfile: []const u8, alloc: std.mem.Allocator) !T { + const info = @typeInfo(T); + + const field_names = comptime blk: { + var names: [info.Struct.fields.len][]const u8 = undefined; + for (info.Struct.fields, 0..) |f, i| + names[i] = f.name; + + break :blk names; + }; + + const out = try std.ChildProcess.exec(.{ + .allocator = alloc, + .argv = &[_][]const u8{ "confgen", "--json-opt", cgfile } ++ field_names, + }); + defer { + alloc.free(out.stdout); + alloc.free(out.stderr); + } + + if (!std.meta.eql(out.term, .{ .Exited = 0 })) + return error.UnexpectedExitCode; + + return try std.json.parseFromSlice(T, alloc, out.stdout, confgen_json_opt); +} diff --git a/mzte-nv/build.zig b/mzte-nv/build.zig index 0ca3738..ae56df3 100644 --- a/mzte-nv/build.zig +++ b/mzte-nv/build.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const common = @import("build_common.zig"); pub fn build(b: *std.build.Builder) !void { const target = b.standardTargetOptions(.{}); @@ -18,6 +19,14 @@ pub fn build(b: *std.build.Builder) !void { const znvim_dep = b.dependency("znvim", .{ .target = target, .optimize = mode }); + const cg_opt = try common.confgenGet(struct { + term_font: []const u8, + }, "../confgen.lua", b.allocator); + + const opts = b.addOptions(); + opts.addOption([]const u8, "font", cg_opt.term_font); + lib.addOptions("opts", opts); + lib.addModule("nvim", znvim_dep.module("nvim_c")); lib.addModule("znvim", znvim_dep.module("znvim")); diff --git a/mzte-nv/build_common.zig b/mzte-nv/build_common.zig new file mode 120000 index 0000000..7e1637d --- /dev/null +++ b/mzte-nv/build_common.zig @@ -0,0 +1 @@ +../build_common.zig \ No newline at end of file diff --git a/mzte-nv/src/options.zig b/mzte-nv/src/options.zig index aef911c..81be8f7 100644 --- a/mzte-nv/src/options.zig +++ b/mzte-nv/src/options.zig @@ -2,10 +2,14 @@ const std = @import("std"); const znvim = @import("znvim"); const nvim = @import("nvim"); +const opts = @import("opts"); + const log = std.log.scoped(.options); /// Initializes neovim options. pub fn initOptions() !void { + var buf: [512]u8 = undefined; + // Shell (defaults to mzteinit since that's my login shell) try setOption("shell", "fish"); @@ -27,7 +31,7 @@ pub fn initOptions() !void { try setOption("colorcolumn", "100"); try setOption("cursorcolumn", true); try setOption("cursorline", true); - try setOption("guifont", "Iosevka Nerd Font Mono:h10"); + try setOption("guifont", try std.fmt.bufPrintZ(&buf, "{s}:h10", .{opts.font})); try setOption("mouse", "a"); try setOption("number", true); try setOption("relativenumber", true); @@ -55,7 +59,6 @@ pub fn initOptions() !void { "perl", "node", }) |garbage| { - var buf: [64]u8 = undefined; const opt = try std.fmt.bufPrintZ(&buf, "g:loaded_{s}_provider", .{garbage}); setVar(opt, .{ .bool = false }); }