Skip to content

zig build: FileNotFound when lib.ofmt = .c #13407

Closed
@hryx

Description

@hryx

Zig Version

0.11.0-dev.12+ebf9ffd34

Steps to Reproduce and Observed Behavior

In build.zig:

    // ...
    const lib = b.addStaticLibrary("scanner", "scanner.zig");
    lib.ofmt = .c;
    // ...

Then run zig build.

Output

error: FileNotFound
/home/hryx/bin/zig-git/lib/zig/std/os.zig:1741:23: 0x2cb3c8 in openatZ (build)
            .NOENT => return error.FileNotFound,
                      ^
/home/hryx/bin/zig-git/lib/zig/std/fs.zig:1175:13: 0x2b7b26 in openFileZ (build)
            try os.openatZ(self.fd, sub_path, os_flags, 0);
            ^
/home/hryx/bin/zig-git/lib/zig/std/fs.zig:1102:9: 0x29be28 in openFile (build)
        return self.openFileZ(&path_c, flags);
        ^
/home/hryx/bin/zig-git/lib/zig/std/fs.zig:2532:24: 0x30171a in updateFile (build)
        var src_file = try source_dir.openFile(source_path, .{});
                       ^
/home/hryx/bin/zig-git/lib/zig/std/build.zig:1089:29: 0x30b517 in updateFile (build)
        const prev_status = try fs.Dir.updateFile(cwd, source_path, cwd, dest_path, .{});
                            ^
/home/hryx/bin/zig-git/lib/zig/std/build.zig:3416:9: 0x2f5e74 in make (build)
        try builder.updateFile(self.artifact.getOutputSource().getPath(builder), full_dest_path);
        ^
/home/hryx/bin/zig-git/lib/zig/std/build.zig:3648:9: 0x28b377 in make (build)
        try self.makeFn(self);
        ^
/home/hryx/bin/zig-git/lib/zig/std/build.zig:509:9: 0x279114 in makeOneStep (build)
        try s.make();
        ^
/home/hryx/bin/zig-git/lib/zig/std/build.zig:503:17: 0x279082 in makeOneStep (build)
                return err;
                ^
/home/hryx/bin/zig-git/lib/zig/std/build.zig:464:13: 0x278de2 in make (build)
            try self.makeOneStep(s);
            ^
/home/hryx/bin/zig-git/lib/zig/build_runner.zig:223:21: 0x27bd4a in main (build)
            else => return err,
                    ^

The generated C file is correctly placed, but zig.h is not.

Expected Behavior

No error trace, and zig.h is next to the generated C file

If I understand, it's trying to copy $PREFIX/lib/zig/include/zig.h to the output directory from the wrong location. Manually copying the file is a workaround.

Related: #12965 (duplicate?), #12968 (does not fix), #11643

Metadata

Metadata

Assignees

No one assigned

    Labels

    backend-cThe C backend (CBE) outputs C source code.bugObserved behavior contradicts documented or intended behaviorzig build systemstd.Build, the build runner, `zig build` subcommand, package management

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions