From 0f76171cf4100e3fd887a7003863a09898a133dc Mon Sep 17 00:00:00 2001 From: jiacai2050 Date: Fri, 29 Nov 2024 09:18:49 +0800 Subject: [PATCH] fix build for zig 0.13 --- .gitignore | 2 +- .tool-versions | 1 + Makefile | 5 +++-- build.zig | 35 +++++++++++++++++------------------ build.zig.zon | 1 + emacs/omg.el | 2 +- 6 files changed, 24 insertions(+), 22 deletions(-) create mode 100644 .tool-versions diff --git a/.gitignore b/.gitignore index a8e8bc6..ac883bb 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ omg-cli *.dylib /.vagrant .DS_Store -zig-cache +.zig-cache zig-out .env .project diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..02050d7 --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +zig 0.13.0 diff --git a/Makefile b/Makefile index 4889a9f..53c88d1 100644 --- a/Makefile +++ b/Makefile @@ -79,8 +79,9 @@ memcheck: $(SO_FILE): $(EMACS_HEADERS) $(EMACS_OBJECTS) $(CC) -shared $(EMACS_OBJECTS) $(LDFLAGS) -o $(SO_FILE) -emacs-dyn: $(SO_FILE) - @echo "Emacs dynamic module saved to $(SO_FILE)" +emacs-dyn: + zig build -Doptimize=ReleaseFast + mv zig-out/lib/libomg-dyn.* emacs/omg-dyn.so install-deps: ifeq ($(uname_S), Darwin) diff --git a/build.zig b/build.zig index 18cf94f..1ffe1d8 100644 --- a/build.zig +++ b/build.zig @@ -6,11 +6,12 @@ const OptimizeMode = std.builtin.OptimizeMode; pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - const verbose = b.option(bool, "verbose", "Enable verbose log"); - const quick = b.option(bool, "quick", "Enable quick mode"); + const verbose = b.option(bool, "verbose", "Enable verbose log") orelse false; + const quick = b.option(bool, "quick", "Enable quick mode") orelse false; + const build_cli = b.option(bool, "build_cli", "Whether build cli") orelse false; const core_lib = b.addStaticLibrary(.{ .name = "omg-core", - .root_source_file = .{ .path = "core/omg.zig" }, + .root_source_file = b.path("core/omg.zig"), .target = target, .optimize = optimize, }); @@ -24,15 +25,11 @@ pub fn build(b: *std.Build) !void { try cflags.append("-Wno-unused-parameter"); try cflags.append("-Wno-gnu"); try cflags.append("-Wimplicit-fallthrough"); - if (verbose) |v| { - if (v) { - try cflags.append("-DVERBOSE"); - } + if (verbose) { + try cflags.append("-DVERBOSE"); } - if (quick) |v| { - if (v) { - try cflags.append("-DOMG_TEST"); - } + if (quick) { + try cflags.append("-DOMG_TEST"); } core_lib.addIncludePath(b.path("core")); core_lib.addCSourceFile(.{ @@ -46,12 +43,14 @@ pub fn build(b: *std.Build) !void { core_lib.linkLibC(); buildEmacsModule(b, core_lib, target, optimize, cflags.items); - buildCliTool( - b, - core_lib, - target, - optimize, - ); + if (build_cli) { + buildCliTool( + b, + core_lib, + target, + optimize, + ); + } inline for (.{ "core", "discussion" }) |name| { buildTest( @@ -94,7 +93,7 @@ fn buildCliTool( .optimize = optimize, }); - const zigcli_dep = b.dependency("zigcli", .{}); + const zigcli_dep = b.lazyDependency("zigcli", .{}) orelse return {}; exe.root_module.addImport("simargs", zigcli_dep.module("simargs")); exe.root_module.addImport("pretty-table", zigcli_dep.module("pretty-table")); diff --git a/build.zig.zon b/build.zig.zon index c627a7b..3810d5a 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -12,6 +12,7 @@ .zigcli = .{ .url = "https://github.com/jiacai2050/zigcli/archive/c0c48df7567ea02458e9fc1f35c4088271b8d4a6.tar.gz", .hash = "12206260a09f871fcd3726540c139d1801beeda788ca593a1bdb6eb0da671d3c3522", + .lazy = true, }, }, } diff --git a/emacs/omg.el b/emacs/omg.el index 6bf3b39..aa6a0d1 100644 --- a/emacs/omg.el +++ b/emacs/omg.el @@ -49,7 +49,7 @@ ;; Public main API ;;;###autoload -(defun omg-setup() +(defun omg-setup () "Setup oh-my-github" (unless omg-username (when-let ((user (omg--execute "config" "github.user")))