Skip to content

CompileStep.emit_h setting puts headers in unexpected directory for zig build #15156

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

Open
leximayfield opened this issue Apr 2, 2023 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior zig build system std.Build, the build runner, `zig build` subcommand, package management
Milestone

Comments

@leximayfield
Copy link

Zig Version

0.11.0-dev.2336+5b82b4004

Steps to Reproduce and Observed Behavior

When creating a static library with zig build, adding emit_h to the CompileStep results in the header being output to the CWD, not the cache directory. This causes the install step to fail because although it knows that it needs to copy a header file, it tries to look in the cache directory and blows up with a FileNotFound.

Here is what I put in my build.zig file:

    var lib = b.addStaticLibrary(.{
        .name = "mercnet",
        .root_source_file = .{ .path = "src/mercnet.zig" },
        .target = target,
        .optimize = optimize,
    });
    lib.emit_h = true;

...and this is the output:

[leximax@DESKTOP-9USQ50S mercnet]$ zig build --verbose
/home/leximax/.opt/zig/zig build-lib -ofmt=c /home/leximax/workspace/mercnet/src/mercnet.zig -femit-h --cache-dir /home/leximax/workspace/mercnet/zig-cache --global-cache-dir /home/leximax/.cache/zig --name mercnet -static --enable-cache --listen=- 
install mercnet: error: unable to update file from '/home/leximax/workspace/mercnet/zig-cache/o/a5f288f5a4f10eb3a43c92bf0db3933c/mercnet.h' to '/home/leximax/workspace/mercnet/zig-out/include/mercnet.h': FileNotFound

It appears that -emit-h could in theory take a path parameter, but none is being passed.

Expected Behavior

No error, header file is installed to the zig-out directory.

@leximayfield leximayfield added the bug Observed behavior contradicts documented or intended behavior label Apr 2, 2023
@Vexu Vexu added the zig build system std.Build, the build runner, `zig build` subcommand, package management label Apr 2, 2023
@Vexu Vexu added this to the 0.11.0 milestone Apr 2, 2023
@leximayfield leximayfield changed the title CompileStep.emit_h setting puts headers in unexpected directory CompileStep.emit_h setting puts headers in unexpected directory for zig build Apr 2, 2023
@RossComputerGuy
Copy link
Contributor

Looks like the option for the filename isn't even passed to the respective Zig call. Looking at the zig build-lib help output, I think I can make a PR to fix this.

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 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.

4 participants