zls
zls copied to clipboard
addSystemCommand UX issues
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:
-
std.fs.cwd().accessis used to avoid invoking CMake when the library is already built. However, since zls invokes build_runner in acwdwhich is not equal to the project's root, and sincelib_out_pathis a relative path, the library artifact is never found, triggering rebuild every time. -
cmakesystem command fails to run.
Expected Behavior
- zls uses project's root cwd to invoke
build_runner, since using absolute paths inbuild.zigisn't very convenient. A workaround in this case is to useb.install_pathas a prefix:
const solution_path = x: {
if (std.fs.path.dirname(b.install_path)) |r| {
break :x r;
} else return error.FileNotFound;
};
-
cmakecommand is invoked without issues.
Actual Behavior
- zls uses
cwdvalue unrelated to the current project location. - 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)
Ironically enough the cause of this issue is the fix for another; see https://github.com/zigtools/zls/pull/898.