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

For some reason ZLS fails to find conditional headers that Zig has no trouble with? #1851

Open
TUSF opened this issue Apr 10, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@TUSF
Copy link

TUSF commented Apr 10, 2024

Zig Version

0.12.0-dev.3609+ac21ade66

Zig Language Server Version

4e01c08

Client / Code Editor / Extensions

Helix

Steps to Reproduce and Observed Behavior

I've ported a few C libraries' build system to Zig for my own projects, and one of them let you enable a feature by passing a build option, and this would add header files to be installed.

The library in question: https://git.sr.ht/~tusf/libdom

The option in question is whether or not to build with libhubbub, an HTML parser. If you ran zig build -Dhubbub it would compile an executable with the proper parsing code, and the zig-out/include directory would include dom/bindings/hubbub.

In my build.zig file, I have:

const dom = b.dependency("libdom", .{ .hubbub = true });

However, when I used this package in a project, ZLS seems to have trouble with headers located here. Given this example:

pub const c = @cImport({
    @cInclude("dom/dom.h");
    @cInclude("dom/bindings/hubbub/parser.h");
});

pub fn main() u8 {
    // Just a test to make sure the above is actually evaluated by Zig.
    return c.DOM_HUBBUB_DOM;
}

This compiles just fine, and the return value is just fine:

> ./zig-out/bin/test
> echo $?
3

However, ZLS refuses to completion for c, and marks the whole thing with an error: `'dom/bindings/hubbub/parser.h' file not found (cImport)

Expected Behavior

I expect to get completions for the contents of c, and for the cImport to not fail.

Relevant log output

No response

@TUSF TUSF added the bug Something isn't working label Apr 10, 2024
@Techatrix
Copy link
Member

I am unable to build this project:

Fetch Packages [10/9] libhubbub... /home/techatrix/.cache/zig/p/122051ea687b4220961d4c1fa43b9b5b3c6bb73c10d8408473cc9e7acb5ede999dbf/build.zig.zon:12:21: error: hash mismatch: manifest declares 12206a4a94fccc8bb322d36fe55e38a73273c8f964318ddaf2165e7e072d79c43109 but the fetched package has 12207e7044b4f64f71ea1b0781df70dc02af0a49190d6ceaa430cc7fb2c4e5a8e78d
            .hash = "12206a4a94fccc8bb322d36fe55e38a73273c8f964318ddaf2165e7e072d79c43109",

When I use the expected hash I get a new error:

install
└─ install zig-testspace
   └─ zig build-exe zig-testspace Debug native
      └─ zig build-lib dom Debug native
         └─ WriteFile  failure
error: unable to open source directory '/home/techatrix/.cache/zig/p/12207e7044b4f64f71ea1b0781df70dc02af0a49190d6ceaa430cc7fb2c4e5a8e78d/include': FileNotFound
install
└─ install zig-testspace
   └─ zig build-exe zig-testspace Debug native
      └─ zig build-lib dom Debug native
         └─ zig build-lib wapcaplet Debug native 1 errors
error: unable to check cache: stat file '/home/techatrix/.cache/zig/p/12207e7044b4f64f71ea1b0781df70dc02af0a49190d6ceaa430cc7fb2c4e5a8e78d/src/libwapcaplet.c' failed: FileNotFound
error: the following command failed with 1 compilation errors:
/nix/store/2jazjwxdb0i7i7p878vck9z0yldayz5w-zig-0.12.0-dev.3652+a59ad719d/bin/zig build-lib -cflags -std=c99 -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_ALIGNED=__attribute__((aligned)) -DSTMTEXPR=1 -Wall -W -Wundef -Wpointer-arith -Wcast-align -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Werror -- /home/techatrix/.cache/zig/p/12207e7044b4f64f71ea1b0781df70dc02af0a49190d6ceaa430cc7fb2c4e5a8e78d/src/libwapcaplet.c -ODebug -I /home/techatrix/.cache/zig/p/12207e7044b4f64f71ea1b0781df70dc02af0a49190d6ceaa430cc7fb2c4e5a8e78d/include -Mroot -lc --cache-dir /home/techatrix/zig-testspace/zig-cache --global-cache-dir /home/techatrix/.cache/zig --name wapcaplet -static --listen=- 
Build Summary: 7/13 steps succeeded; 2 failed (disable with --summary none)
install transitive failure
└─ install zig-testspace transitive failure
   └─ zig build-exe zig-testspace Debug native transitive failure
      └─ zig build-lib dom Debug native transitive failure
         ├─ zig build-lib wapcaplet Debug native 1 errors
         └─ WriteFile  failure
error: the following build command failed with exit code 1:
/home/techatrix/zig-testspace/zig-cache/o/32179b0942d05292b14153ed68af30f4/build /nix/store/2jazjwxdb0i7i7p878vck9z0yldayz5w-zig-0.12.0-dev.3652+a59ad719d/bin/zig /home/techatrix/zig-testspace /home/techatrix/zig-testspace/zig-cache /home/techatrix/.cache/zig --seed 0x88f32fab -Z1e4c1c9bf5d90137

AFAICT, everything in https://source.netsurf-browser.org/libwapcaplet.git/snapshot/libwapcaplet-release/0.4.3.tar.gz in inside a libwapcaplet-release/0.4.3/ subfolder but the build.zig calls wcl.path("include") instead of wcl.path("libwapcaplet-release/0.4.3/include"). The line I am referring to is here. That file also references a api/main.zig which doesn't exist.

After trying to fix the paths, I end up here:

/home/techatrix/zig-testspace/zig-cache/o/d4460a11815e291e1d976ce3a778b089/dom/core/string.h:13:10: error: 'libwapcaplet/libwapcaplet.h' file not found

@ArtuArtaza
Copy link

For me it's happening the same with raylib. Im using nvim-lspconfig. It's weird because in vscode works well...

@everystone
Copy link

Same issue here with raylib on Windows 10

E:\dev\zig\game [master ≡ +1 ~3 -0 !]> zig version
0.12.0-dev.3653+e45bdc6bd
E:\dev\zig\game [master ≡ +1 ~3 -0 !]> zls --version
0.12.0-dev.513+172c8f2

Getting 'raylib.h' file not found, while zig compiles fine.

@Techatrix
Copy link
Member

Please open a new issue about raylib and provide all necessary information so that anyone else can try and reproduce the issue.

@sarumjanuch
Copy link

sarumjanuch commented Jun 3, 2024

Same here on MacOS, but with ffmpeg, it feels more, that it is about libs that are linked with pkg-config, and are not in system libs..
ZLS: 0.13.0-dev.48+af9401b
ZIG: 0.13.0-dev.351+64ef45eb0

Simpliest main file:

const std = @import("std");

const avformat = @cImport({
    @cInclude("libavformat/avformat.h");
});

pub fn main() !void {
    const stdout_file = std.io.getStdOut().writer();
    var bw = std.io.bufferedWriter(stdout_file);
    const stdout = bw.writer();

    try stdout.print("FFmpeg version: {}\n", .{avformat.avformat_version()});
    try bw.flush();
}

In build file i am using:
exe.linkSystemLibrary("libavformat"); which links it with pkg-config. How does zls knows about pkg-config stuff and what is going on in build file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants