Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

translate-c build step causing crash in build system #20648

Closed
Tracked by #20630
andrewrk opened this issue Jul 16, 2024 · 2 comments
Closed
Tracked by #20630

translate-c build step causing crash in build system #20648

andrewrk opened this issue Jul 16, 2024 · 2 comments
Labels
bug Observed behavior contradicts documented or intended behavior contributor friendly This issue is limited in scope and/or knowledge of Zig internals. frontend Tokenization, parsing, AstGen, Sema, and Liveness. regression It worked in a previous version of Zig, but stopped working.
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Jul 16, 2024

Zig Version

0.14.0-dev.321+888708ec8

Steps to Reproduce and Observed Behavior

Use a translate-c build step in a build script:

    const translate_c = b.addTranslateC(.{
        .root_source_file = b.path("src/c.h"),
        .target = target,
        .optimize = optimize,
    });
    exe.root_module.addImport("c", translate_c.createModule());
thread 160006 panic: index out of bounds: index 0, len 0
/home/andy/local/lib/zig/std/Build/Step.zig:551:103: 0x1211890 in zigProcessUpdate (build)
                    const prefix_index: std.zig.Server.Message.PathPrefix = @enumFromInt(prefixed_path[0] - 1);
                                                                                                      ^
/home/andy/local/lib/zig/std/Build/Step.zig:441:40: 0x1214fb0 in evalZigProcess (build)
    const result = try zigProcessUpdate(s, zp, watch);
                                       ^
/home/andy/local/lib/zig/std/Build/Step/TranslateC.zig:158:48: 0x11c8cc5 in make (build)
    const output_path = try step.evalZigProcess(argv_list.items, prog_node, false);
                                               ^
/home/andy/local/lib/zig/std/Build/Step.zig:231:13: 0x117ae67 in make (build)
    s.makeFn(s, options) catch |err| switch (err) {
            ^
/home/andy/local/lib/zig/compiler/build_runner.zig:1046:31: 0x112bacc in workerMakeOneStep (build)
    const make_result = s.make(.{
                              ^
/home/andy/local/lib/zig/std/Thread/Pool.zig:115:39: 0x112c461 in runFn (build)
            @call(.auto, func, closure.arguments);
                                      ^
/home/andy/local/lib/zig/std/Thread/Pool.zig:291:32: 0x11ac0b5 in worker (build)
            run_node.data.runFn(&run_node.data, id);
                               ^
/home/andy/local/lib/zig/std/Thread.zig:409:13: 0x1179b7d in callFn__anon_15720 (build)
            @call(.auto, f, args);
            ^
/home/andy/local/lib/zig/std/Thread.zig:1234:30: 0x112b197 in entryFn (build)
                return callFn(f, self.fn_args);
                             ^
/home/andy/dev/zig/lib/c.zig:239:13: 0x131eff0 in clone (c)
            asm volatile (
            ^

Expected Behavior

No crash.


Regression caused by #20580

Related to #20630

The panic happens because the frontend fails to report file system inputs in the translate-c logic. This is a bug in the frontend, not the build system.

Should be an easy fix, just need to send a non-empty file_system_inputs message here:

zig/src/main.zig

Line 4089 in 888708e

try server.serveStringMessage(.file_system_inputs, file_system_inputs.items);

@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness. zig build system std.Build, the build runner, `zig build` subcommand, package management regression It worked in a previous version of Zig, but stopped working. labels Jul 16, 2024
@andrewrk andrewrk added this to the 0.14.0 milestone Jul 16, 2024
@andrewrk andrewrk added contributor friendly This issue is limited in scope and/or knowledge of Zig internals. and removed zig build system std.Build, the build runner, `zig build` subcommand, package management labels Jul 16, 2024
@der-teufel-programming
Copy link
Contributor

Could you share the whole build script and the command you run that crashes? I have trouble getting the crash locally

@andrewrk
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior contributor friendly This issue is limited in scope and/or knowledge of Zig internals. frontend Tokenization, parsing, AstGen, Sema, and Liveness. regression It worked in a previous version of Zig, but stopped working.
Projects
None yet
Development

No branches or pull requests

2 participants