mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2024-06-15 01:39:25 +02:00
zig scripts can now use options from confgen!
This commit is contained in:
parent
0cc96946f5
commit
e7bd7d0f08
32
build_common.zig
Normal file
32
build_common.zig
Normal file
|
@ -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);
|
||||
}
|
|
@ -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"));
|
||||
|
||||
|
|
1
mzte-nv/build_common.zig
Symbolic link
1
mzte-nv/build_common.zig
Symbolic link
|
@ -0,0 +1 @@
|
|||
../build_common.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 });
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue