zigtools / zls

A Zig language server supporting Zig developers with features like autocomplete and goto definition
MIT License
2.89k stars 290 forks source link

gnu/stubs-32.h file not found #1915

Open TeamPuzel opened 3 months ago

TeamPuzel commented 3 months ago

Zig Version

0.13.0 (compiled from source a few days ago)

Zig Language Server Version

0.14.0-dev.1+c5ceadf

Client / Code Editor / Extensions

VSCode

Steps to Reproduce and Observed Behavior

image

I was working on an application and at some point zls stopped working correctly with this error. I've been working on the build.zig for a while so I didn't notice, so I do not know what started causing it. Code suggestions completely stopped working for gtk libraries.

The code is available here https://github.com/TeamPuzel/Crates

I am using Fedora 40 on aarch64 (M2 Mac)

Expected Behavior

This error is incorrect, building with zig works perfectly fine.

Relevant log output

No response

TeamPuzel commented 3 months ago

I got no output before but now there's this:

error: (store ): Failed to load build configuration for file:///home/lua/Projects/adwaita-test/build.zig (error: error.RunFailed)
error: (store ): Failed to execute build runner to collect build configuration, command:
/home/lua/Toolchains/zig/zig build --build-runner /home/lua/.cache/zig/build_runner/21872970afd69e48a0847077e5196711/build_runner.zig
Error: error: FileNotFound

error: (store ): Failed to load build configuration for file:///home/lua/Projects/adwaita-test/build.zig (error: error.RunFailed)
TeamPuzel commented 3 months ago

Okay, I figured out what causes the issue (kind of) image I renamed the folder with cross compilation shared libraries and zls magically started working again.

It is used like so:

    if (!target.query.isNative()) {
        if (target.result.cpu.arch == .x86_64) {
            exe.addLibraryPath(b.path("cross/x86_64/usr/lib64"));
            exe.addIncludePath(b.path("cross/x86_64/usr/include"));
        } else if (target.result.cpu.arch == .aarch64) {
            exe.addLibraryPath(b.path("cross/aarch64/usr/lib64"));
            exe.addIncludePath(b.path("cross/aarch64/usr/include"));
        }
    } else {
        exe.addLibraryPath(.{ .cwd_relative = "/usr/lib64" });
        exe.addIncludePath(.{ .cwd_relative = "/usr/include" });
    }

I don't know what zls is even doing, commenting this out entirely does not fix the issue. Where is it even getting the paths to the cross compilation libraries from.

Techatrix commented 3 months ago

Could you post the entire log output of ZLS? Ideally with a debug build.

MMUTFX2053 commented 3 months ago

i had the same thing happen, im still learning zig so i thought i wrote some bad code, checked it over and over again XD

TeamPuzel commented 3 months ago

Could you post the entire log output of ZLS? Ideally with a debug build.

Unfortunately I was already on the macOS 15 beta and I would like to avoid booting into linux until I am sure it's not going to break :( Still, there was no other log output besides some startup information, so I will have to build zls in debug mode.

Techatrix commented 3 months ago

I just tested your project on my Arch Linux system and everything worked. I didn't even need to install any missing system dependencies.

Running ZLS's custom build runner with zig build --build-file ~/repos/Crates/build.zig --build-runner ~/repos/zls/src/build_runner/0.12.0.zig yielded the following output:

build runner output at fed56dcb3e17678d905c6108b9e2d9da9bf077dc ```json { "deps_build_roots": [], "packages": [ { "name": "root", "path": "/home/techatrix/repos/Crates/src/main.zig" }, { "name": "config", "path": "/home/techatrix/repos/Crates/.zig-cache/c/bb3f36a4897a57caa44e307416750dad/options.zig" } ], "include_dirs": [ "/usr/include/libadwaita-1", "/usr/include/gtk-4.0", "/usr/include/pango-1.0", "/usr/include/harfbuzz", "/usr/include/gdk-pixbuf-2.0", "/usr/include/cairo", "/usr/include/freetype2", "/usr/include/graphene-1.0", "/usr/lib/graphene-1.0/include", "/usr/include/glib-2.0", "/usr/lib/glib-2.0/include", "/usr/include/libmount", "/usr/include/blkid", "/usr/include/sysprof-6", "/usr/include/libpng16", "/usr/include/pixman-1", "/usr/include/fribidi", "/usr/include/appstream", "/home/techatrix/repos/Crates/cross/x86_64/usr/include", "/home/techatrix/repos/Crates/cross/aarch64/usr/include" ], "available_options": { "dynamic-linker": { "name": "dynamic-linker", "type_id": "string", "description": "Path to interpreter on the target system", "enum_options": null }, "version": { "name": "version", "type_id": "string", "description": "Manually specify a value", "enum_options": null }, "target": { "name": "target", "type_id": "string", "description": "The CPU architecture, OS, and ABI to build for", "enum_options": null }, "build-id": { "name": "build-id", "type_id": "int", "description": "Manually specify a value", "enum_options": null }, "cpu": { "name": "cpu", "type_id": "string", "description": "Target CPU features to add or subtract", "enum_options": null }, "stable": { "name": "stable", "type_id": "bool", "description": "Configure the application to the stable appearance", "enum_options": null }, "optimize": { "name": "optimize", "type_id": "enum", "description": "Prioritize performance, safety, or binary size", "enum_options": [ "Debug", "ReleaseSafe", "ReleaseFast", "ReleaseSmall" ] } } } ```
build runner output at 4e1f823a036e0b866cd5c519c97b0ebd26a1b49f ```json { "deps_build_roots": [], "packages": [ { "name": "root", "path": "/home/techatrix/repos/Crates/src/main.zig" }, { "name": "config", "path": "/home/techatrix/repos/Crates/.zig-cache/c/fda2f3ba544bc0fe2d4be908ec70a05f/options.zig" } ], "include_dirs": [ "/usr/include/libadwaita-1", "/usr/include/gtk-4.0", "/usr/include/pango-1.0", "/usr/include/harfbuzz", "/usr/include/gdk-pixbuf-2.0", "/usr/include/cairo", "/usr/include/freetype2", "/usr/include/graphene-1.0", "/usr/lib/graphene-1.0/include", "/usr/include/glib-2.0", "/usr/lib/glib-2.0/include", "/usr/include/libmount", "/usr/include/blkid", "/usr/include/sysprof-6", "/usr/include/libpng16", "/usr/include/pixman-1", "/usr/include/fribidi", "/usr/include/appstream", "/home/techatrix/repos/Crates/cross/x86_64/usr/include", "/home/techatrix/repos/Crates/cross/aarch64/usr/include", "/usr/include" ], "available_options": { "dynamic-linker": { "name": "dynamic-linker", "type_id": "string", "description": "Path to interpreter on the target system", "enum_options": null }, "version": { "name": "version", "type_id": "string", "description": "Manually specify a value", "enum_options": null }, "target": { "name": "target", "type_id": "string", "description": "The CPU architecture, OS, and ABI to build for", "enum_options": null }, "build-id": { "name": "build-id", "type_id": "int", "description": "Manually specify a value", "enum_options": null }, "cpu": { "name": "cpu", "type_id": "string", "description": "Target CPU features to add or subtract", "enum_options": null }, "stable": { "name": "stable", "type_id": "bool", "description": "Configure the application to the stable appearance", "enum_options": null }, "optimize": { "name": "optimize", "type_id": "enum", "description": "Prioritize performance, safety, or binary size", "enum_options": [ "Debug", "ReleaseSafe", "ReleaseFast", "ReleaseSmall" ] } } } ```

The final Zig file can then be produced with the following command:

zig translate-c header.h -I /usr/local/include -I /usr/include/x86_64-linux-gnu -I /usr/include  -I/usr/include/libadwaita-1 -I/usr/include/gtk-4.0 -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/cairo -I/usr/include/freetype2 -I/usr/include/graphene-1.0 -I/usr/lib/graphene-1.0/include -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/sysprof-6 -I/usr/include/libpng16 -I/usr/include/pixman-1 -I/usr/include/fribidi -I/usr/include/appstream -I/home/techatrix/repos/Crates/cross/x86_64/usr/include -I/home/techatrix/repos/Crates/cross/aarch64/usr/include

The first three include paths are added by default on Linux.

// header.h
#include <libadwaita-1/adwaita.h>
TeamPuzel commented 3 months ago

Maybe it was using some cached data from earlier x86 cross compilation? I tried deleting both the local and global cache and it didn't help, it only started working again after I renamed that folder. It then kept working even after renaming it back.

You do seem to have these in the output:

"/home/techatrix/repos/Crates/cross/x86_64/usr/include",
"/home/techatrix/repos/Crates/cross/aarch64/usr/include"

So if headers for the wrong architecture were to be found first, wouldn't that cause an issue?

Techatrix commented 3 months ago

So if headers for the wrong architecture were to be found first, wouldn't that cause an issue?

I believe that is possible. I do not have a Crates directory so this could explain why I don't have such an issue.

Adwaith-Rajesh commented 3 months ago

I'm having the exact same issue. Running ZLS 0.13.0 on Ubuntu 23.10

EDIT: adding an include path to the module does not work, but adding the same include path to an exe makes it work.