From 64a3b6c74a7c7cbcd1f3f6d31f0bae02d691d07e Mon Sep 17 00:00:00 2001 From: LordMZTE Date: Wed, 20 Mar 2024 20:45:59 +0100 Subject: [PATCH] create common zig lib for scripts --- lib/common-zig/.gitignore | 1 + lib/common-zig/README.md | 1 + build_common.zig => lib/common-zig/build.zig | 16 +++--- lib/common-zig/src/main.zig | 53 ++++++++++++++++++++ mzte-nv/build.zig | 4 +- mzte-nv/build.zig.zon | 1 + mzte-nv/build_common.zig | 1 - plugins/mzte-mpv/build.zig | 4 +- plugins/mzte-mpv/build.zig.zon | 8 +++ plugins/mzte-mpv/src/main.zig | 17 ++----- plugins/mzte-mpv/src/modules/LiveChat.zig | 2 +- scripts/alecor/build.zig | 2 + scripts/alecor/build.zig.zon | 8 +++ scripts/alecor/src/main.zig | 1 + scripts/hyprtool/build.zig | 2 + scripts/hyprtool/build.zig.zon | 8 +++ scripts/hyprtool/src/main.zig | 1 + scripts/mzteinit/build.zig | 6 ++- scripts/mzteinit/build.zig.zon | 1 + scripts/mzteinit/build_common.zig | 1 - scripts/mzteinit/src/main.zig | 32 ++---------- scripts/mzteinit/src/mzteinitctl.zig | 1 + scripts/mzteriver/build.zig | 5 +- scripts/mzteriver/build.zig.zon | 1 + scripts/mzteriver/build_common.zig | 1 - scripts/mzteriver/src/init.zig | 6 +-- scripts/mzteriver/src/main.zig | 13 ++--- scripts/openbrowser/build.zig | 3 ++ scripts/openbrowser/build.zig.zon | 8 +++ scripts/openbrowser/src/main.zig | 1 + scripts/playvid/build.zig | 2 + scripts/playvid/build.zig.zon | 8 +++ scripts/playvid/src/main.zig | 5 ++ scripts/prompt/build.zig | 1 + scripts/prompt/build.zig.zon | 3 +- scripts/prompt/src/main.zig | 5 ++ scripts/randomwallpaper/build.zig | 2 + scripts/randomwallpaper/build.zig.zon | 8 +++ scripts/randomwallpaper/src/main.zig | 1 + scripts/vinput/build.zig | 1 + scripts/vinput/build.zig.zon | 1 + scripts/vinput/src/main.zig | 1 + scripts/withjava/build.zig | 2 + scripts/withjava/build.zig.zon | 8 +++ scripts/withjava/src/main.zig | 5 ++ scripts/wlbg/build.zig | 1 + scripts/wlbg/build.zig.zon | 1 + scripts/wlbg/src/main.zig | 1 + 48 files changed, 196 insertions(+), 69 deletions(-) create mode 100644 lib/common-zig/.gitignore create mode 100644 lib/common-zig/README.md rename build_common.zig => lib/common-zig/build.zig (64%) create mode 100644 lib/common-zig/src/main.zig delete mode 120000 mzte-nv/build_common.zig create mode 100644 plugins/mzte-mpv/build.zig.zon create mode 100644 scripts/alecor/build.zig.zon create mode 100644 scripts/hyprtool/build.zig.zon delete mode 120000 scripts/mzteinit/build_common.zig delete mode 120000 scripts/mzteriver/build_common.zig create mode 100644 scripts/openbrowser/build.zig.zon create mode 100644 scripts/playvid/build.zig.zon create mode 100644 scripts/randomwallpaper/build.zig.zon create mode 100644 scripts/withjava/build.zig.zon diff --git a/lib/common-zig/.gitignore b/lib/common-zig/.gitignore new file mode 100644 index 0000000..fe95f8d --- /dev/null +++ b/lib/common-zig/.gitignore @@ -0,0 +1 @@ +/zig-* diff --git a/lib/common-zig/README.md b/lib/common-zig/README.md new file mode 100644 index 0000000..23db8c4 --- /dev/null +++ b/lib/common-zig/README.md @@ -0,0 +1 @@ +Common library for all my Zig scripts. diff --git a/build_common.zig b/lib/common-zig/build.zig similarity index 64% rename from build_common.zig rename to lib/common-zig/build.zig index 828e3aa..a293559 100644 --- a/build_common.zig +++ b/lib/common-zig/build.zig @@ -1,15 +1,19 @@ -//! Shared code for script build scripts const std = @import("std"); pub const confgen_json_opt = std.json.ParseOptions{ .ignore_unknown_fields = true }; +pub fn build(b: *std.Build) void { + _ = b.addModule("common", .{ + .root_source_file = .{ .path = "src/main.zig" }, + }); +} + +// TODO: make confgen generate zon and delete /// Retrieve some confgen options given a relative path to the dotfile root and a struct type /// with a field for each option. -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, .{}); +pub fn confgenGet(comptime T: type, alloc: std.mem.Allocator) !T { + const optjson_path = comptime std.fs.path.dirname(@src().file).? ++ "/../../cgout/opts.json"; + var file = try std.fs.cwd().openFile(optjson_path, .{}); defer file.close(); var buf_reader = std.io.bufferedReader(file.reader()); diff --git a/lib/common-zig/src/main.zig b/lib/common-zig/src/main.zig new file mode 100644 index 0000000..300f630 --- /dev/null +++ b/lib/common-zig/src/main.zig @@ -0,0 +1,53 @@ +const std = @import("std"); + +var stderr_isatty: ?bool = null; + +pub var log_file: ?std.fs.File = null; + +pub fn logFn( + comptime level: std.log.Level, + comptime scope: @TypeOf(.enum_literal), + comptime fmt: []const u8, + args: anytype, +) void { + const log_pfx: ?[]const u8 = if (@hasDecl(@import("root"), "mztecommon_log_pfx")) + @import("root").mztecommon_log_pfx + else + null; + + const color = log_file == null and stderr_isatty orelse blk: { + const isatty = std.os.isatty(std.os.STDERR_FILENO); + stderr_isatty = isatty; + break :blk isatty; + }; + + const logfile = log_file orelse std.io.getStdErr(); + + const scope_prefix = if (log_pfx) |lpfx| + if (scope != .default) + "[" ++ lpfx ++ " " ++ @tagName(scope) ++ "] " + else + "[" ++ lpfx ++ "] " + else if (scope != .default) + "[" ++ @tagName(scope) ++ "] " + else + ""; + + switch (color) { + inline else => |col| { + const lvl_prefix = comptime if (col) switch (level) { + .debug => "\x1b[1;34mD:\x1b[0m ", + .info => "\x1b[1;32mI:\x1b[0m ", + .warn => "\x1b[1;33mW:\x1b[0m ", + .err => "\x1b[1;31mE:\x1b[0m ", + } else switch (level) { + .debug => "D: ", + .info => "I: ", + .warn => "W: ", + .err => "E: ", + }; + + logfile.writer().print(scope_prefix ++ lvl_prefix ++ fmt ++ "\n", args) catch {}; + }, + } +} diff --git a/mzte-nv/build.zig b/mzte-nv/build.zig index 699112d..955f396 100644 --- a/mzte-nv/build.zig +++ b/mzte-nv/build.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const common = @import("build_common.zig"); +const common = @import("common"); pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); @@ -21,7 +21,7 @@ pub fn build(b: *std.Build) !void { const cg_opt = try common.confgenGet(struct { term_font: []u8, // TODO: this being non-const is a workaround for an std bug - }, "..", b.allocator); + }, b.allocator); const opts = b.addOptions(); opts.addOption([]const u8, "font", cg_opt.term_font); diff --git a/mzte-nv/build.zig.zon b/mzte-nv/build.zig.zon index 492f54a..10fcfd9 100644 --- a/mzte-nv/build.zig.zon +++ b/mzte-nv/build.zig.zon @@ -3,6 +3,7 @@ .version = "0.0.0", .dependencies = .{ + .common = .{ .path = "../lib/common-zig" }, .znvim = .{ .url = "git+https://git.mzte.de/LordMZTE/znvim.git#8e52c461dc071e6b88c8e77e49aa2805f225e7da", .hash = "122029929d792aa32a71c0b98bb67d344d971d269d6fea5b8f8693e29f0f45924951", diff --git a/mzte-nv/build_common.zig b/mzte-nv/build_common.zig deleted file mode 120000 index 7e1637d..0000000 --- a/mzte-nv/build_common.zig +++ /dev/null @@ -1 +0,0 @@ -../build_common.zig \ No newline at end of file diff --git a/plugins/mzte-mpv/build.zig b/plugins/mzte-mpv/build.zig index 9d9d959..aa35d72 100644 --- a/plugins/mzte-mpv/build.zig +++ b/plugins/mzte-mpv/build.zig @@ -7,11 +7,11 @@ pub fn build(b: *std.Build) void { const lib = b.addSharedLibrary(.{ .name = "mzte-mpv", .root_source_file = .{ .path = "src/main.zig" }, + .link_libc = true, .target = target, .optimize = optimize, }); - - lib.linkLibC(); + lib.root_module.addImport("common", b.dependency("common", .{}).module("common")); const install_step = b.addInstallArtifact(lib, .{ // this is not a standard MPV installation path, but instead one that makes sense. diff --git a/plugins/mzte-mpv/build.zig.zon b/plugins/mzte-mpv/build.zig.zon new file mode 100644 index 0000000..c4782f2 --- /dev/null +++ b/plugins/mzte-mpv/build.zig.zon @@ -0,0 +1,8 @@ +.{ + .name = "mzte-mpv", + .version = "0.0.0", + .paths = .{""}, + .dependencies = .{ + .common = .{ .path = "../../lib/common-zig" }, + } +} diff --git a/plugins/mzte-mpv/src/main.zig b/plugins/mzte-mpv/src/main.zig index 314fe7a..44c3d93 100644 --- a/plugins/mzte-mpv/src/main.zig +++ b/plugins/mzte-mpv/src/main.zig @@ -6,22 +6,11 @@ const util = @import("util.zig"); pub const std_options = std.Options{ .log_level = .debug, - .logFn = struct { - fn logFn( - comptime message_level: std.log.Level, - comptime scope: @TypeOf(.enum_literal), - comptime format: []const u8, - args: anytype, - ) void { - _ = scope; - - const stderr = std.io.getStdErr().writer(); - - stderr.print("[mzte-mpv {s}] " ++ format ++ "\n", .{@tagName(message_level)} ++ args) catch return; - } - }.logFn, + .logFn = @import("common").logFn, }; +pub const mztecommon_log_pfx = "mzte-mpv"; + export fn mpv_open_cplugin(handle: *c.mpv_handle) callconv(.C) c_int { tryMain(handle) catch |e| { if (@errorReturnTrace()) |ert| diff --git a/plugins/mzte-mpv/src/modules/LiveChat.zig b/plugins/mzte-mpv/src/modules/LiveChat.zig index 5b57571..0d04b92 100644 --- a/plugins/mzte-mpv/src/modules/LiveChat.zig +++ b/plugins/mzte-mpv/src/modules/LiveChat.zig @@ -35,7 +35,7 @@ pub fn onEvent(self: *LiveChat, mpv: *c.mpv_handle, ev: *c.mpv_event) !void { errdefer file.close(); std.log.info("initializing subtitle transcoder: {s}", .{fname}); - const pipe = try std.os.pipe2(0); + const pipe = try std.os.pipe2(.{}); // This needs to be done here instead of the separate thread. MPV will instantly // give up if there's nothing to be read from the pipe when the command is called. diff --git a/scripts/alecor/build.zig b/scripts/alecor/build.zig index 6361516..aea075b 100644 --- a/scripts/alecor/build.zig +++ b/scripts/alecor/build.zig @@ -11,6 +11,8 @@ pub fn build(b: *std.Build) void { .optimize = optimize, }); + exe.root_module.addImport("common", b.dependency("common", .{}).module("common")); + b.installArtifact(exe); const run_cmd = b.addRunArtifact(exe); diff --git a/scripts/alecor/build.zig.zon b/scripts/alecor/build.zig.zon new file mode 100644 index 0000000..dfc4394 --- /dev/null +++ b/scripts/alecor/build.zig.zon @@ -0,0 +1,8 @@ +.{ + .name = "alecor", + .version = "0.0.0", + .paths = .{""}, + .dependencies = .{ + .common = .{ .path = "../../lib/common-zig" }, + }, +} diff --git a/scripts/alecor/src/main.zig b/scripts/alecor/src/main.zig index b14e1d9..aa0c59a 100644 --- a/scripts/alecor/src/main.zig +++ b/scripts/alecor/src/main.zig @@ -5,6 +5,7 @@ const util = @import("util.zig"); pub const std_options = std.Options{ .log_level = .debug, + .logFn = @import("common").logFn, }; pub fn main() !void { diff --git a/scripts/hyprtool/build.zig b/scripts/hyprtool/build.zig index e91271c..a519295 100644 --- a/scripts/hyprtool/build.zig +++ b/scripts/hyprtool/build.zig @@ -11,6 +11,8 @@ pub fn build(b: *std.Build) void { .optimize = optimize, }); + exe.root_module.addImport("common", b.dependency("common", .{}).module("common")); + b.installArtifact(exe); const run_cmd = b.addRunArtifact(exe); diff --git a/scripts/hyprtool/build.zig.zon b/scripts/hyprtool/build.zig.zon new file mode 100644 index 0000000..a4934bb --- /dev/null +++ b/scripts/hyprtool/build.zig.zon @@ -0,0 +1,8 @@ +.{ + .name = "hyprtool", + .version = "0.0.0", + .paths = .{""}, + .dependencies = .{ + .common = .{ .path = "../../lib/common-zig" }, + }, +} diff --git a/scripts/hyprtool/src/main.zig b/scripts/hyprtool/src/main.zig index 2365b82..c455dd5 100644 --- a/scripts/hyprtool/src/main.zig +++ b/scripts/hyprtool/src/main.zig @@ -2,6 +2,7 @@ const std = @import("std"); pub const std_options = std.Options{ .log_level = .debug, + .logFn = @import("common").logFn, }; pub fn main() !void { diff --git a/scripts/mzteinit/build.zig b/scripts/mzteinit/build.zig index 5a417f5..70f4928 100644 --- a/scripts/mzteinit/build.zig +++ b/scripts/mzteinit/build.zig @@ -1,11 +1,12 @@ const std = @import("std"); -const common = @import("build_common.zig"); +const common = @import("common"); pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const ansi_term_mod = b.dependency("ansi_term", .{}).module("ansi-term"); + const common_mod = b.dependency("common", .{}).module("common"); const exe = b.addExecutable(.{ .name = "mzteinit", @@ -23,11 +24,12 @@ pub fn build(b: *std.Build) !void { inline for (.{ mzteinitctl, exe }) |e| { e.root_module.addImport("ansi-term", ansi_term_mod); + e.root_module.addImport("common", common_mod); } const cg_opt = try common.confgenGet(struct { gtk_theme: []u8, // TODO: this being non-const is a workaround for an std bug - }, "../..", b.allocator); + }, b.allocator); const opts = b.addOptions(); opts.addOption([]const u8, "gtk_theme", cg_opt.gtk_theme); diff --git a/scripts/mzteinit/build.zig.zon b/scripts/mzteinit/build.zig.zon index 941de81..895941a 100644 --- a/scripts/mzteinit/build.zig.zon +++ b/scripts/mzteinit/build.zig.zon @@ -3,6 +3,7 @@ .version = "0.0.0", .dependencies = .{ + .common = .{ .path = "../../lib/common-zig" }, .ansi_term = .{ .url = "git+https://github.com/LordMZTE/ansi-term.git#73c03175068679685535111dbea72cade075719e", .hash = "1220ea86ace34b38e49c1d737c5f857d88346af10695a992b38e10cb0a73b6a19ef7", diff --git a/scripts/mzteinit/build_common.zig b/scripts/mzteinit/build_common.zig deleted file mode 120000 index 821d564..0000000 --- a/scripts/mzteinit/build_common.zig +++ /dev/null @@ -1 +0,0 @@ -../../build_common.zig \ No newline at end of file diff --git a/scripts/mzteinit/src/main.zig b/scripts/mzteinit/src/main.zig index 82ca51c..cf720e2 100644 --- a/scripts/mzteinit/src/main.zig +++ b/scripts/mzteinit/src/main.zig @@ -1,5 +1,7 @@ const std = @import("std"); const at = @import("ansi-term"); +const common = @import("common"); + const env = @import("env.zig"); const command = @import("command.zig"); const util = @import("util.zig"); @@ -11,36 +13,12 @@ const msg = @import("message.zig").msg; pub const std_options = std.Options{ .log_level = .debug, - .logFn = struct { - pub fn logFn( - comptime msg_level: std.log.Level, - comptime scope: @TypeOf(.enum_literal), - comptime fmt: []const u8, - args: anytype, - ) void { - const logfile = log_file orelse return; - - if (scope != .default) { - logfile.writer().print("[{s}] ", .{@tagName(scope)}) catch return; - } - - logfile.writer().writeAll(switch (msg_level) { - .err => "E: ", - .warn => "W: ", - .info => "I: ", - .debug => "D: ", - }) catch return; - - logfile.writer().print(fmt ++ "\n", args) catch return; - } - }.logFn, + .logFn = common.logFn, }; -var log_file: ?std.fs.File = null; - pub fn main() void { - log_file = createLogFile() catch null; - defer if (log_file) |lf| lf.close(); + common.log_file = createLogFile() catch null; + defer if (common.log_file) |lf| lf.close(); tryMain() catch |e| { std.log.err("FATAL ERROR: {}", .{e}); diff --git a/scripts/mzteinit/src/mzteinitctl.zig b/scripts/mzteinit/src/mzteinitctl.zig index b4c5f62..5956ac4 100644 --- a/scripts/mzteinit/src/mzteinitctl.zig +++ b/scripts/mzteinit/src/mzteinitctl.zig @@ -4,6 +4,7 @@ const Client = @import("sock/Client.zig"); pub const std_options = std.Options{ .log_level = .debug, + .logFn = @import("common").logFn, }; pub fn main() !void { diff --git a/scripts/mzteriver/build.zig b/scripts/mzteriver/build.zig index 9c522ca..822c80f 100644 --- a/scripts/mzteriver/build.zig +++ b/scripts/mzteriver/build.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const common = @import("build_common.zig"); +const common = @import("common"); const Scanner = @import("wayland").Scanner; @@ -22,7 +22,7 @@ pub fn build(b: *std.Build) !void { theme: [:0]const u8, size: u32, }, - }, "../..", b.allocator); + }, b.allocator); const opts = b.addOptions(); opts.addOption([:0]const u8, "catppuccin_red", cg_opt.catppuccin.red); @@ -43,6 +43,7 @@ pub fn build(b: *std.Build) !void { .optimize = optimize, }); + exe.root_module.addImport("common", b.dependency("common", .{}).module("common")); exe.root_module.addImport("opts", opts.createModule()); exe.root_module.addImport("wayland", scanner.mod); diff --git a/scripts/mzteriver/build.zig.zon b/scripts/mzteriver/build.zig.zon index 2a01606..83994cf 100644 --- a/scripts/mzteriver/build.zig.zon +++ b/scripts/mzteriver/build.zig.zon @@ -3,6 +3,7 @@ .version = "0.0.0", .dependencies = .{ + .common = .{ .path = "../../lib/common-zig" }, .wayland = .{ .url = "git+https://git.mzte.de/LordMZTE/zig-wayland#4de9f2d6d5fddae1fbb29e21fd1dae69e646ab7d", .hash = "1220d6448c277e5c41348aa95ce2ba2fc92a92cb7a9e9783edf0f816cd0260122d31", diff --git a/scripts/mzteriver/build_common.zig b/scripts/mzteriver/build_common.zig deleted file mode 120000 index 821d564..0000000 --- a/scripts/mzteriver/build_common.zig +++ /dev/null @@ -1 +0,0 @@ -../../build_common.zig \ No newline at end of file diff --git a/scripts/mzteriver/src/init.zig b/scripts/mzteriver/src/init.zig index 54d67de..1e9436c 100644 --- a/scripts/mzteriver/src/init.zig +++ b/scripts/mzteriver/src/init.zig @@ -1,7 +1,7 @@ const std = @import("std"); const opts = @import("opts"); -const log = std.log.scoped(.mzteriver); +const log = std.log.scoped(.init); const Connection = @import("Connection.zig"); @@ -198,7 +198,7 @@ pub fn init(alloc: std.mem.Allocator, initial: bool) !void { defer alloc.free(cgfs_eval_path); const evalf = std.fs.cwd().openFile(cgfs_eval_path, .{ .mode = .write_only }) catch { - std.log.warn("unable to open confgenfs eval file", .{}); + log.warn("unable to open confgenfs eval file", .{}); break :confgenfs; }; defer evalf.close(); @@ -209,7 +209,7 @@ pub fn init(alloc: std.mem.Allocator, initial: bool) !void { } if (initial) { - std.log.info("spawning processes", .{}); + log.info("spawning processes", .{}); var child_arena = std.heap.ArenaAllocator.init(alloc); defer child_arena.deinit(); diff --git a/scripts/mzteriver/src/main.zig b/scripts/mzteriver/src/main.zig index a5849cd..46b378e 100644 --- a/scripts/mzteriver/src/main.zig +++ b/scripts/mzteriver/src/main.zig @@ -1,8 +1,6 @@ const std = @import("std"); const opts = @import("opts"); -const log = std.log.scoped(.mzteriver); - const init = @import("init.zig").init; pub const std_options = std.Options{ @@ -10,8 +8,11 @@ pub const std_options = std.Options{ .Debug => .debug, else => .info, }, + .logFn = @import("common").logFn, }; +pub const mztecommon_log_pfx = "mzteriver"; + pub fn main() !void { var dbg_gpa = if (@import("builtin").mode == .Debug) std.heap.GeneralPurposeAllocator(.{}){} else {}; defer if (@TypeOf(dbg_gpa) != void) { @@ -22,15 +23,15 @@ pub fn main() !void { if (std.mem.endsWith(u8, std.mem.span(std.os.argv[0]), "init") or (std.os.argv.len >= 2 and std.mem.orderZ(u8, std.os.argv[1], "init") == .eq)) { - log.info("running in init mode", .{}); + std.log.info("running in init mode", .{}); try init(alloc, true); } else if (std.mem.endsWith(u8, std.mem.span(std.os.argv[0]), "reinit") or (std.os.argv.len >= 2 and std.mem.orderZ(u8, std.os.argv[1], "reinit") == .eq)) { - log.info("running in reinit mode", .{}); + std.log.info("running in reinit mode", .{}); try init(alloc, false); } else { - log.info("running in launch mode", .{}); + std.log.info("running in launch mode", .{}); const logfd = logf: { const logf_path = try std.fmt.allocPrintZ( @@ -40,7 +41,7 @@ pub fn main() !void { ); defer alloc.free(logf_path); - log.info("river log file: {s}", .{logf_path}); + std.log.info("river log file: {s}", .{logf_path}); break :logf try std.os.openatZ( std.os.AT.FDCWD, diff --git a/scripts/openbrowser/build.zig b/scripts/openbrowser/build.zig index 98a4e34..03c3255 100644 --- a/scripts/openbrowser/build.zig +++ b/scripts/openbrowser/build.zig @@ -10,6 +10,9 @@ pub fn build(b: *std.Build) void { .target = target, .optimize = mode, }); + + exe.root_module.addImport("common", b.dependency("common", .{}).module("common")); + b.installArtifact(exe); const desktop_install_step = b.addInstallFile( diff --git a/scripts/openbrowser/build.zig.zon b/scripts/openbrowser/build.zig.zon new file mode 100644 index 0000000..cd2dd28 --- /dev/null +++ b/scripts/openbrowser/build.zig.zon @@ -0,0 +1,8 @@ +.{ + .name = "openbrowser", + .version = "0.0.0", + .paths = .{""}, + .dependencies = .{ + .common = .{ .path = "../../lib/common-zig" }, + }, +} diff --git a/scripts/openbrowser/src/main.zig b/scripts/openbrowser/src/main.zig index 8478b51..0386b09 100644 --- a/scripts/openbrowser/src/main.zig +++ b/scripts/openbrowser/src/main.zig @@ -3,6 +3,7 @@ const info = @import("info.zig"); pub const std_options = std.Options{ .log_level = .debug, + .logFn = @import("common").logFn, }; const browsers = &[_][]const u8{ diff --git a/scripts/playvid/build.zig b/scripts/playvid/build.zig index 499b233..c479c10 100644 --- a/scripts/playvid/build.zig +++ b/scripts/playvid/build.zig @@ -11,6 +11,8 @@ pub fn build(b: *std.Build) void { .optimize = optimize, }); + exe.root_module.addImport("common", b.dependency("common", .{}).module("common")); + b.installArtifact(exe); const run_cmd = b.addRunArtifact(exe); diff --git a/scripts/playvid/build.zig.zon b/scripts/playvid/build.zig.zon new file mode 100644 index 0000000..7626fd3 --- /dev/null +++ b/scripts/playvid/build.zig.zon @@ -0,0 +1,8 @@ +.{ + .name = "playvid", + .version = "0.0.0", + .paths = .{""}, + .dependencies = .{ + .common = .{ .path = "../../lib/common-zig" }, + }, +} diff --git a/scripts/playvid/src/main.zig b/scripts/playvid/src/main.zig index 4c8aa02..4f0a0f1 100644 --- a/scripts/playvid/src/main.zig +++ b/scripts/playvid/src/main.zig @@ -1,5 +1,10 @@ const std = @import("std"); +pub const std_options = std.Options{ + .log_level = .debug, + .logFn = @import("common").logFn, +}; + pub fn main() !u8 { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; defer _ = gpa.deinit(); diff --git a/scripts/prompt/build.zig b/scripts/prompt/build.zig index 0740657..942f10c 100644 --- a/scripts/prompt/build.zig +++ b/scripts/prompt/build.zig @@ -14,6 +14,7 @@ pub fn build(b: *std.Build) void { exe.linkLibC(); exe.linkSystemLibrary("libgit2"); + exe.root_module.addImport("common", b.dependency("common", .{}).module("common")); exe.root_module.addImport("ansi-term", b.dependency("ansi_term", .{}).module("ansi-term")); exe.root_module.addImport("known-folders", b.dependency("known_folders", .{}).module("known-folders")); diff --git a/scripts/prompt/build.zig.zon b/scripts/prompt/build.zig.zon index 9604631..7e8cb93 100644 --- a/scripts/prompt/build.zig.zon +++ b/scripts/prompt/build.zig.zon @@ -1,8 +1,10 @@ .{ .name = "promt", .version = "0.0.0", + .paths = .{""}, .dependencies = .{ + .common = .{ .path = "../../lib/common-zig" }, .ansi_term = .{ .url = "git+https://github.com/LordMZTE/ansi-term.git#73c03175068679685535111dbea72cade075719e", .hash = "1220ea86ace34b38e49c1d737c5f857d88346af10695a992b38e10cb0a73b6a19ef7", @@ -12,5 +14,4 @@ .hash = "12209925016f4b5486a713828ead3bcc900fa4f039c93de1894aa7d5253f7633b92c", }, }, - .paths = .{""}, } diff --git a/scripts/prompt/src/main.zig b/scripts/prompt/src/main.zig index 26276d7..d25d154 100644 --- a/scripts/prompt/src/main.zig +++ b/scripts/prompt/src/main.zig @@ -13,6 +13,11 @@ const fish_code = \\end ; +pub const std_options = std.Options{ + .log_level = .debug, + .logFn = @import("common").logFn, +}; + pub fn main() !void { if (std.os.argv.len < 2) return error.NotEnoughArguments; diff --git a/scripts/randomwallpaper/build.zig b/scripts/randomwallpaper/build.zig index 8084980..00219f3 100644 --- a/scripts/randomwallpaper/build.zig +++ b/scripts/randomwallpaper/build.zig @@ -15,6 +15,8 @@ pub fn build(b: *std.Build) void { exe.linkSystemLibrary("xcb"); exe.linkSystemLibrary("xcb-xinerama"); + exe.root_module.addImport("common", b.dependency("common", .{}).module("common")); + b.installArtifact(exe); const run_cmd = b.addRunArtifact(exe); diff --git a/scripts/randomwallpaper/build.zig.zon b/scripts/randomwallpaper/build.zig.zon new file mode 100644 index 0000000..afa5e2d --- /dev/null +++ b/scripts/randomwallpaper/build.zig.zon @@ -0,0 +1,8 @@ +.{ + .name = "randomwallpaper", + .version = "0.0.0", + .paths = .{""}, + .dependencies = .{ + .common = .{ .path = "../../lib/common-zig" }, + }, +} diff --git a/scripts/randomwallpaper/src/main.zig b/scripts/randomwallpaper/src/main.zig index a60571c..f607c8f 100644 --- a/scripts/randomwallpaper/src/main.zig +++ b/scripts/randomwallpaper/src/main.zig @@ -4,6 +4,7 @@ const Walker = @import("Walker.zig"); pub const std_options = std.Options{ .log_level = .debug, + .logFn = @import("common").logFn, }; pub fn main() !u8 { diff --git a/scripts/vinput/build.zig b/scripts/vinput/build.zig index c716349..a24679c 100644 --- a/scripts/vinput/build.zig +++ b/scripts/vinput/build.zig @@ -16,6 +16,7 @@ pub fn build(b: *std.Build) void { .optimize = mode, }); + exe.root_module.addImport("common", b.dependency("common", .{}).module("common")); exe.root_module.addImport("wayland", wayland_mod); scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml"); diff --git a/scripts/vinput/build.zig.zon b/scripts/vinput/build.zig.zon index 09ac583..211b5e9 100644 --- a/scripts/vinput/build.zig.zon +++ b/scripts/vinput/build.zig.zon @@ -3,6 +3,7 @@ .version = "0.0.0", .paths = .{""}, .dependencies = .{ + .common = .{ .path = "../../lib/common-zig" }, .wayland = .{ .url = "git+https://git.mzte.de/LordMZTE/zig-wayland#4de9f2d6d5fddae1fbb29e21fd1dae69e646ab7d", .hash = "1220d6448c277e5c41348aa95ce2ba2fc92a92cb7a9e9783edf0f816cd0260122d31", diff --git a/scripts/vinput/src/main.zig b/scripts/vinput/src/main.zig index 23c7b3f..b92ad83 100644 --- a/scripts/vinput/src/main.zig +++ b/scripts/vinput/src/main.zig @@ -4,6 +4,7 @@ const ClipboardConnection = @import("ClipboardConnection.zig"); pub const std_options = std.Options{ .log_level = .debug, + .logFn = @import("common").logFn, }; pub fn main() !void { diff --git a/scripts/withjava/build.zig b/scripts/withjava/build.zig index 0ece26c..a682e59 100644 --- a/scripts/withjava/build.zig +++ b/scripts/withjava/build.zig @@ -11,6 +11,8 @@ pub fn build(b: *std.Build) void { .optimize = optimize, }); + exe.root_module.addImport("common", b.dependency("common", .{}).module("common")); + b.installArtifact(exe); const run_cmd = b.addRunArtifact(exe); diff --git a/scripts/withjava/build.zig.zon b/scripts/withjava/build.zig.zon new file mode 100644 index 0000000..e7c1b77 --- /dev/null +++ b/scripts/withjava/build.zig.zon @@ -0,0 +1,8 @@ +.{ + .name = "withjava", + .version = "0.0.0", + .paths = .{""}, + .dependencies = .{ + .common = .{ .path = "../../lib/common-zig" }, + }, +} diff --git a/scripts/withjava/src/main.zig b/scripts/withjava/src/main.zig index 2f21a7d..e4c2be2 100644 --- a/scripts/withjava/src/main.zig +++ b/scripts/withjava/src/main.zig @@ -1,5 +1,10 @@ const std = @import("std"); +pub const std_options = std.Options{ + .log_level = .debug, + .logFn = @import("common").logFn, +}; + pub fn main() !u8 { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; defer _ = gpa.deinit(); diff --git a/scripts/wlbg/build.zig b/scripts/wlbg/build.zig index b8e7b08..7e52a37 100644 --- a/scripts/wlbg/build.zig +++ b/scripts/wlbg/build.zig @@ -16,6 +16,7 @@ pub fn build(b: *std.Build) void { .optimize = optimize, }); + exe.root_module.addImport("common", b.dependency("common", .{}).module("common")); exe.root_module.addImport("xev", b.dependency("xev", .{ .target = target, .optimize = optimize, diff --git a/scripts/wlbg/build.zig.zon b/scripts/wlbg/build.zig.zon index c6b3c38..de87aa7 100644 --- a/scripts/wlbg/build.zig.zon +++ b/scripts/wlbg/build.zig.zon @@ -3,6 +3,7 @@ .version = "0.0.0", .paths = .{""}, .dependencies = .{ + .common = .{ .path = "../../lib/common-zig" }, .wayland = .{ .url = "git+https://git.mzte.de/LordMZTE/zig-wayland#4de9f2d6d5fddae1fbb29e21fd1dae69e646ab7d", .hash = "1220d6448c277e5c41348aa95ce2ba2fc92a92cb7a9e9783edf0f816cd0260122d31", diff --git a/scripts/wlbg/src/main.zig b/scripts/wlbg/src/main.zig index 091281f..36cc349 100644 --- a/scripts/wlbg/src/main.zig +++ b/scripts/wlbg/src/main.zig @@ -18,6 +18,7 @@ const zxdg = wayland.client.zxdg; pub const std_options = std.Options{ .log_level = .debug, + .logFn = @import("common").logFn, }; pub fn main() !void {