C import overflows

Trying to port one of my projects to 0.16 but getting a failure on C import:

src/main.zig:986:12: error: C import failed
const tb = @cImport({
           thread 111408 panic: integer overflow
/usr/local/lib/zig/std/zig/ErrorBundle.zig:218:27: 0x123d049 in renderErrorMessage (build)
            src.data.line + 1,
                          ^
/usr/local/lib/zig/std/zig/ErrorBundle.zig:187:31: 0x123c618 in renderToTerminal (build)
        try renderErrorMessage(eb, options, err_msg, t, "error", .red, 0);
                              ^
/usr/local/lib/zig/compiler/build_runner.zig:1494:58: 0x1239d50 in printErrorMessages (build)
    try failing_step.result_error_bundle.renderToTerminal(options, stderr);
                                                         ^
/usr/local/lib/zig/compiler/build_runner.zig:1388:27: 0x133f82d in makeStep (build)
        printErrorMessages(gpa, s, .{}, stderr.terminal(), run.error_style, run.multiline_errors) catch {};
                          ^
/usr/local/lib/zig/std/Io.zig:1245:17: 0x133f08d in start (build)
                _ = @as(Cancelable!void, @call(.auto, function, args_casted.*)) catch {};
                ^
/usr/local/lib/zig/std/Io/Threaded.zig:552:22: 0x11bb72a in start (build)
            task.func(task.contextPointer());
                     ^
/usr/local/lib/zig/std/Io/Threaded.zig:1797:29: 0x11ba510 in worker (build)
            runnable.startFn(runnable, &thread, t);
                            ^
/usr/local/lib/zig/std/Thread.zig:422:13: 0x11ba0af in callFn__anon_25235 (build)
            @call(.auto, f, args);
            ^
/usr/local/lib/zig/std/Thread.zig:752:30: 0x11b9f4e in entryFn (build)
                return callFn(f, args_ptr.*);

compiler bug? where to start? I am pretty sure termbox2 is fine

@cImport is deprecated, so you might try switching to the translate-c Build system integration?

1 Like

you mean translating manually? I am reading docs and looks like cImport is not going anywhere Documentation - The Zig Programming Language

interesting! you’re wrong: it’s already gone when you go to the master tab.

and no, i do not mean translating manually.

@cImport is indeed going away.

The rub is that if you try and use the version of the external translate-c package that is pinned for 0.16.0, you will likely run into the same issues.

If you (and others!) want a fairly up-to-date version, I’ve posted the backport that we’re using at Ghostty that I’ve been maintaining as we work to update to 0.16.0. Feel free to check it out!

2 Likes

Thanks! Yep, I switched to translate-c in the build system and getting the same overflow.

Managed to get thro with your fork, but still something is wrong

.zig-cache/o/d9ed066f3db7dec1cf37ee41697f01f0/termbox.c.zig:16466:21: error: expected type '[16]c_ulong', found 'comptime_int'
                ] = 0;

Tried all the options from the library, only default_init helped a little with missing struct objects:

const termbox: Translator = .init(translate_c_dep, .{
    .c_source_file = b.path("src/termbox.c"),
    .target = target,
    .optimize = optimize,
    .default_init = true,
});

termbox.addIncludePath(b.dependency("termbox2", .{}).path("."));