the-argus / zig-compile-commands

A simple zig module to generate compile_commands.json from a slice of build targets.
GNU General Public License v3.0
18 stars 6 forks source link

missing get remote-package rootpath in CSource #6

Closed kassane closed 1 week ago

kassane commented 2 weeks ago

Hi @the-argus

zig version: v0.13.0/v0.14.0-dev

Recently I was testing cdb to view the dependencies graph in kde/codevis(compile_commands.json parser). However, there are some errors detecting the rootpath of remote packages in arguments.

my source: https://github.com/kassane/beast (boost/beast - w/ zig-build)

{
        "arguments": [
            "clang",
            "src/unsynchronized_pool_resource.cpp", <== not pkg rootpath
            "-o",
            "src/unsynchronized_pool_resource.cpp.o", <== not global_cache rootpath
            "-Wall",
            "-Wextra",
            "-Wpedantic",
            "-std=c++20",
            "-fexperimental-library",
            "-I/home/kassane/.cache/zig/p/122043257f5075e34f1572ef30a11121be1d9905373cde6f560807166edd8121fec3/include",
            "-I/home/kassane/.cache/zig/p/1220a4167dd25735ead67e3444575544b9bd9e497dc02932c3ff22e8bd14d9d92919/include",
            "-I/home/kassane/.cache/zig/p/12209097ed2bab41567145d8690d5cf7800b323664642cf81463625c40fe275378d7/include",
        ]
}

from:

lib.addCSourceFiles(.{
            .root = boostContainer,
            .files = &.{
                "src/pool_resource.cpp",
                "src/monotonic_buffer_resource.cpp",
                "src/synchronized_pool_resource.cpp",
                "src/unsynchronized_pool_resource.cpp",
                "src/global_resource.cpp",
            },
            .flags = cxxFlags,
        });
lib.addCSourceFiles(.{
            .root = boostJson,
            .files = &.{
                "src/src.cpp",
            },
            .flags = cxxFlags,
        });

maybe related: https://github.com/ziglang/zig/issues/21232

the-argus commented 1 week ago

I never properly cannonicalized the source paths since it worked for simple projects. Funnily enough, I encountered this issue myself and just did a weird hack (manually adding an -I flag pointing to the remote dep).

The issue of source path is fixed in the PR above. @kassane can you try it out using the url and hash provided at the top of the PR comment? The path to the object file is still not quite correct, but I think that may be fine for intellisense purposes.

kassane commented 1 week ago

@the-argus, works! image