zls icon indicating copy to clipboard operation
zls copied to clipboard

addSystemCommand UX issues

Open yuyoyuppe opened this issue 2 years ago • 1 comments

Zig Version

0.11.0-dev.1564+4c7f8286d

Zig Language Server Version

0.11.0-dev.160+384f227

Steps to Reproduce

My build.zig has a CMake-based dependency library which I build like this:

std.fs.cwd().access(lib_out_path, .{}) catch |err| {
    // ...
    const build_cmd = b.addSystemCommand(&[_][]const u8{ "cmake", "--build", "build", "--config", "Release", "-j" });
    build_cmd.cwd = LIB_ROOT;
    try build_cmd.step.make();
}

Now, I've actually experienced 2 issues which are related to the whole addSystemCommand ux:

  1. std.fs.cwd().access is used to avoid invoking CMake when the library is already built. However, since zls invokes build_runner in a cwd which is not equal to the project's root, and since lib_out_path is a relative path, the library artifact is never found, triggering rebuild every time.
  2. cmake system command fails to run.

Expected Behavior

  1. zls uses project's root cwd to invoke build_runner, since using absolute paths in build.zig isn't very convenient. A workaround in this case is to use b.install_path as a prefix:
const solution_path = x: {
    if (std.fs.path.dirname(b.install_path)) |r| {
        break :x r;
    } else return error.FileNotFound;
};
  1. cmake command is invoked without issues.

Actual Behavior

  1. zls uses cwd value unrelated to the current project location.
  2. In its log, the failed command is:
error: (store ): Failed to execute build runner to collect build configuration, command:
S:\software\zig\zig.exe run %TEMP%\zls\build_runner.zig --cache-dir %TEMP%\zls --pkg-begin @build@ S:\test_proj\build.zig --pkg-e
nd -- S:\software\zig\zig.exe S:\test_proj S:\test_proj\zig-cache ZLS_DONT_CARE
Failed to create ConsoleBuf!
setActiveInputCodepage failed!
Failed to create ConsoleBuf!
setActiveInputCodepage failed!
Failed to create ConsoleBuf!
setActiveInputCodepage failed!
Failed to create ConsoleBuf!
setActiveInputCodepage failed!

error: (store ): Failed to load build configuration for file:///s%3A/test_proj/build.zig (error: error.RunFailed)

yuyoyuppe avatar Feb 04 '23 12:02 yuyoyuppe

Ironically enough the cause of this issue is the fix for another; see https://github.com/zigtools/zls/pull/898.

SuperAuguste avatar Feb 05 '23 06:02 SuperAuguste