add stack traces to mzte-nv errors

This commit is contained in:
LordMZTE 2023-05-27 01:27:08 +02:00
parent f74f7b0fd4
commit 2fa42e1507
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
4 changed files with 38 additions and 28 deletions

View file

@ -24,7 +24,10 @@ pub fn build(b: *std.build.Builder) !void {
lib.linkLibC();
lib.linkSystemLibrary("luajit");
lib.strip = mode != .Debug;
lib.strip = switch (mode) {
.Debug, .ReleaseSafe => false,
.ReleaseFast, .ReleaseSmall => true,
};
lib.unwind_tables = true;
b.getInstallStep().dependOn(&b.addInstallFile(lib.getOutputSource(), "share/nvim/mzte-nv.so").step);

View file

@ -11,13 +11,20 @@ pub fn luaFunc(comptime func: fn (*c.lua_State) anyerror!c_int) c.lua_CFunction
return &struct {
fn f(l: ?*c.lua_State) callconv(.C) c_int {
return func(l.?) catch |e| {
var buf: [128]u8 = undefined;
const err_s = std.fmt.bufPrintZ(
&buf,
"Zig Error: {s}",
.{@errorName(e)},
) catch unreachable;
c.lua_pushstring(l, err_s.ptr);
var buf: [1024 * 4]u8 = undefined;
var fbs = std.io.fixedBufferStream(&buf);
fbs.writer().print("Zig Error: {s}\n", .{@errorName(e)}) catch @panic("OOM");
if (@errorReturnTrace()) |ert| {
std.debug.writeStackTrace(
ert.*,
fbs.writer(),
std.heap.c_allocator,
std.debug.getSelfDebugInfo() catch @panic("WTF"),
.no_color,
) catch @panic("OOM");
}
luaPushString(l, fbs.getWritten());
_ = c.lua_error(l);
unreachable;
};

View file

@ -4,7 +4,7 @@
(define (run)
(define nvim-config-dir (build-path (find-system-path 'home-dir) ".config" "nvim"))
(install-zig "mzte-nv")
(install-zig "mzte-nv" "ReleaseSafe")
(rm nvim-config-dir)
(copy "mzte-nv/conf" nvim-config-dir)
(cmd "mzte-nv-compile" (path->string nvim-config-dir))

View file

@ -34,26 +34,26 @@
(define-logging copy copy-directory/files)
(define-logging install-zig
(λ (path)
(parameterize ([current-directory path] [log-calls #f])
(cmd "zig" "build" "-p" (output-bin-path) "-Doptimize=ReleaseFast"))))
(λ (path [mode "ReleaseFast"])
(parameterize ([current-directory path] [log-calls #f])
(cmd "zig" "build" "-p" (output-bin-path) (string-append "-Doptimize=" mode)))))
(define-logging install-rust
(λ (path)
(parameterize ([current-directory path] [log-calls #f])
(cmd "cargo"
"-Z"
"unstable-options"
"build"
"--release"
"--out-dir"
(build-path (output-bin-path) "bin")))))
(λ (path)
(parameterize ([current-directory path] [log-calls #f])
(cmd "cargo"
"-Z"
"unstable-options"
"build"
"--release"
"--out-dir"
(build-path (output-bin-path) "bin")))))
(define-logging
install-roswell
(λ (path)
(parameterize ([log-calls #f])
(match-let*-values ([(_ filename _) (split-path path)]
[(outpath)
(build-path (output-bin-path) "bin" (path-replace-extension filename ""))])
(cmd "ros" "dump" "executable" path "-o" outpath)))))
install-roswell
(λ (path)
(parameterize ([log-calls #f])
(match-let*-values ([(_ filename _) (split-path path)]
[(outpath)
(build-path (output-bin-path) "bin" (path-replace-extension filename ""))])
(cmd "ros" "dump" "executable" path "-o" outpath)))))