Skip to content

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

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

Closed
hryx opened this issue Nov 2, 2022 · 5 comments · Fixed by #18965
Closed

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

hryx opened this issue Nov 2, 2022 · 5 comments · Fixed by #18965
Labels
backend-c The C backend (CBE) outputs C source code. bug Observed behavior contradicts documented or intended behavior zig build system std.Build, the build runner, `zig build` subcommand, package management
Milestone

Comments

@hryx
Copy link
Contributor

hryx commented Nov 2, 2022

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

@hryx hryx added the bug Observed behavior contradicts documented or intended behavior label Nov 2, 2022
@andrewrk andrewrk added the zig build system std.Build, the build runner, `zig build` subcommand, package management label Nov 2, 2022
@andrewrk andrewrk added this to the 0.11.0 milestone Nov 2, 2022
@andrewrk
Copy link
Member

andrewrk commented Nov 2, 2022

Workaround: Edit your target, setting target.ofmt = .c; before calling setTarget. (Thanks to @jacobly0 for finding this workaround in #13389)

@jacobly0
Copy link
Member

jacobly0 commented Nov 5, 2022

Can this be closed now that #13389 is merged, and lib.ofmt no longer exists?

@hryx
Copy link
Contributor Author

hryx commented Nov 5, 2022

After changing lib.ofmt = .c to lib.target.ofmt = .c and running zig build with the latest nightly, I don't get the error anymore. But zig.h is still not getting copied to the output dir. I could make a separate issue if you like, and if so, this can be closed.

@andrewrk
Copy link
Member

andrewrk commented Nov 5, 2022

It also should not set the executable bit on the .c file

@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Jun 19, 2023
@andrewrk andrewrk modified the milestones: 0.13.0, 0.12.0 Aug 5, 2023
@andrewrk andrewrk modified the milestones: 0.12.0, 0.13.0 Feb 14, 2024
@jacobly0 jacobly0 modified the milestones: 0.13.0, 0.12.0 Feb 17, 2024
@jacobly0 jacobly0 added the backend-c The C backend (CBE) outputs C source code. label Feb 17, 2024
@jacobly0
Copy link
Member

But zig.h is still not getting copied to the output dir.

Covered by #13528

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend-c The C backend (CBE) outputs C source code. bug Observed behavior contradicts documented or intended behavior zig build system std.Build, the build runner, `zig build` subcommand, package management
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants