diff --git a/README.md b/README.md index ed7a195..aa7ed5e 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,8 @@ The following options are currently available. | `zig_lib_path` | `?[]const u8` | `null` | Zig library path, e.g. `/path/to/zig/lib/zig`, used to analyze std library imports | | `zig_exe_path` | `?[]const u8` | `null` | Zig executable path, e.g. `/path/to/zig/zig`, used to run the custom build runner. If `null`, zig is looked up in `PATH`. Will be used to infer the zig standard library path if none is provided | | `build_runner_path` | `?[]const u8` | `null` | Path to the `build_runner.zig` file provided by zls. null is equivalent to `${executable_directory}/build_runner.zig` | -| `global_cache_path` | `?[]const u8` | `null` | Path to a directroy that will be used as zig's cache. null is equivalent to `${KnownFloders.Cache}/zls` | +| `global_cache_path` | `?[]const u8` | `null` | Path to a directory that will be used as zig's cache. null is equivalent to `${KnownFloders.Cache}/zls` | +| `build_runner_global_cache_path` | `?[]const u8` | `null` | Path to a directory that will be used as the global cache path when executing a projects build.zig. null is equivalent to the path shown by `zig env` | ### Per-build Configuration Options diff --git a/schema.json b/schema.json index 5675491..2728d41 100644 --- a/schema.json +++ b/schema.json @@ -125,7 +125,12 @@ "default": "null" }, "global_cache_path": { - "description": "Path to a directroy that will be used as zig's cache. null is equivalent to `${KnownFloders.Cache}/zls`", + "description": "Path to a directory that will be used as zig's cache. null is equivalent to `${KnownFloders.Cache}/zls`", + "type": "string", + "default": "null" + }, + "build_runner_global_cache_path": { + "description": "Path to a directory that will be used as the global cache path when executing a projects build.zig. null is equivalent to the path shown by `zig env`", "type": "string", "default": "null" } diff --git a/src/Config.zig b/src/Config.zig index 4e48028..773a3b2 100644 --- a/src/Config.zig +++ b/src/Config.zig @@ -76,7 +76,10 @@ zig_exe_path: ?[]const u8 = null, /// Path to the `build_runner.zig` file provided by zls. null is equivalent to `${executable_directory}/build_runner.zig` build_runner_path: ?[]const u8 = null, -/// Path to a directroy that will be used as zig's cache. null is equivalent to `${KnownFloders.Cache}/zls` +/// Path to a directory that will be used as zig's cache. null is equivalent to `${KnownFloders.Cache}/zls` global_cache_path: ?[]const u8 = null, +/// Path to a directory that will be used as the global cache path when executing a projects build.zig. null is equivalent to the path shown by `zig env` +build_runner_global_cache_path: ?[]const u8 = null, + // DO NOT EDIT diff --git a/src/DocumentStore.zig b/src/DocumentStore.zig index 4863860..c4f0917 100644 --- a/src/DocumentStore.zig +++ b/src/DocumentStore.zig @@ -419,9 +419,6 @@ fn loadBuildConfiguration( // TODO extract this option from `BuildAssociatedConfig.BuildOption` const zig_cache_root: []const u8 = try std.fs.path.join(arena_allocator, &.{ directory_path, "zig-cache" }); - // Since we don't compile anything and no packages should put their - // files there this path can be ignored - const zig_global_cache_root: []const u8 = "ZLS_DONT_CARE"; const standard_args = [_][]const u8{ config.zig_exe_path.?, @@ -437,7 +434,7 @@ fn loadBuildConfiguration( config.zig_exe_path.?, directory_path, zig_cache_root, - zig_global_cache_root, + config.build_runner_global_cache_path.?, }; const arg_length = standard_args.len + if (build_file.build_associated_config) |cfg| if (cfg.build_options) |options| options.len else 0 else 0; diff --git a/src/config_gen/config.json b/src/config_gen/config.json index 8084ebf..6c3d5de 100644 --- a/src/config_gen/config.json +++ b/src/config_gen/config.json @@ -146,7 +146,13 @@ }, { "name": "global_cache_path", - "description": "Path to a directroy that will be used as zig's cache. null is equivalent to `${KnownFloders.Cache}/zls`", + "description": "Path to a directory that will be used as zig's cache. null is equivalent to `${KnownFloders.Cache}/zls`", + "type": "?[]const u8", + "default": "null" + }, + { + "name": "build_runner_global_cache_path", + "description": "Path to a directory that will be used as the global cache path when executing a projects build.zig. null is equivalent to the path shown by `zig env`", "type": "?[]const u8", "default": "null" } diff --git a/src/configuration.zig b/src/configuration.zig index ff211e8..d9571b7 100644 --- a/src/configuration.zig +++ b/src/configuration.zig @@ -78,14 +78,21 @@ pub fn configChanged(config: *Config, allocator: std.mem.Allocator, builtin_crea if (config.zig_exe_path) |exe_path| blk: { logger.info("Using zig executable {s}", .{exe_path}); - if (config.zig_lib_path != null) break :blk; + if (config.zig_lib_path != null and config.build_runner_global_cache_path != null) break :blk; var env = getZigEnv(allocator, exe_path) orelse break :blk; defer std.json.parseFree(Env, env, .{ .allocator = allocator }); - // Make sure the path is absolute - config.zig_lib_path = try std.fs.realpathAlloc(allocator, env.lib_dir.?); - logger.info("Using zig lib path '{s}'", .{config.zig_lib_path.?}); + if (config.zig_lib_path == null) { + // Make sure the path is absolute + config.zig_lib_path = try std.fs.realpathAlloc(allocator, env.lib_dir.?); + logger.info("Using zig lib path '{s}'", .{config.zig_lib_path.?}); + } + + if (config.build_runner_global_cache_path == null) { + config.build_runner_global_cache_path = try allocator.dupe(u8, env.global_cache_dir); + logger.info("Using build runner global cache path '{s}'", .{config.build_runner_global_cache_path.?}); + } } else { logger.warn("Zig executable path not specified in zls.json and could not be found in PATH", .{}); } diff --git a/src/special/build_runner.zig b/src/special/build_runner.zig index b6b79a1..a57c070 100644 --- a/src/special/build_runner.zig +++ b/src/special/build_runner.zig @@ -72,9 +72,7 @@ pub fn main() !void { const global_cache_directory = if (has_cache) Cache.Directory{ .path = global_cache_root, - // I don't know if with the incomming changes around caching whether `openDir` is correct, - // but `makeOpenPath` which zig build runner uses causes access denied - .handle = try std.fs.cwd().openDir(global_cache_root, .{}), + .handle = try std.fs.cwd().makeOpenPath(global_cache_root, .{}), } else global_cache_root; var cache = if (has_cache) Cache{