build_runner: provide valid global cache to the build runner (#1009)
This commit is contained in:
parent
c3f58538e8
commit
8bd5358748
@ -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_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 |
|
| `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` |
|
| `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` |
|
||||||
<!-- DO NOT EDIT -->
|
<!-- DO NOT EDIT -->
|
||||||
|
|
||||||
### Per-build Configuration Options
|
### Per-build Configuration Options
|
||||||
|
@ -125,7 +125,12 @@
|
|||||||
"default": "null"
|
"default": "null"
|
||||||
},
|
},
|
||||||
"global_cache_path": {
|
"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",
|
"type": "string",
|
||||||
"default": "null"
|
"default": "null"
|
||||||
}
|
}
|
||||||
|
@ -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`
|
/// 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,
|
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,
|
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
|
// DO NOT EDIT
|
||||||
|
@ -419,9 +419,6 @@ fn loadBuildConfiguration(
|
|||||||
|
|
||||||
// TODO extract this option from `BuildAssociatedConfig.BuildOption`
|
// TODO extract this option from `BuildAssociatedConfig.BuildOption`
|
||||||
const zig_cache_root: []const u8 = try std.fs.path.join(arena_allocator, &.{ directory_path, "zig-cache" });
|
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{
|
const standard_args = [_][]const u8{
|
||||||
config.zig_exe_path.?,
|
config.zig_exe_path.?,
|
||||||
@ -437,7 +434,7 @@ fn loadBuildConfiguration(
|
|||||||
config.zig_exe_path.?,
|
config.zig_exe_path.?,
|
||||||
directory_path,
|
directory_path,
|
||||||
zig_cache_root,
|
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;
|
const arg_length = standard_args.len + if (build_file.build_associated_config) |cfg| if (cfg.build_options) |options| options.len else 0 else 0;
|
||||||
|
@ -146,7 +146,13 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "global_cache_path",
|
"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",
|
"type": "?[]const u8",
|
||||||
"default": "null"
|
"default": "null"
|
||||||
}
|
}
|
||||||
|
@ -78,14 +78,21 @@ pub fn configChanged(config: *Config, allocator: std.mem.Allocator, builtin_crea
|
|||||||
if (config.zig_exe_path) |exe_path| blk: {
|
if (config.zig_exe_path) |exe_path| blk: {
|
||||||
logger.info("Using zig executable {s}", .{exe_path});
|
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;
|
var env = getZigEnv(allocator, exe_path) orelse break :blk;
|
||||||
defer std.json.parseFree(Env, env, .{ .allocator = allocator });
|
defer std.json.parseFree(Env, env, .{ .allocator = allocator });
|
||||||
|
|
||||||
|
if (config.zig_lib_path == null) {
|
||||||
// Make sure the path is absolute
|
// Make sure the path is absolute
|
||||||
config.zig_lib_path = try std.fs.realpathAlloc(allocator, env.lib_dir.?);
|
config.zig_lib_path = try std.fs.realpathAlloc(allocator, env.lib_dir.?);
|
||||||
logger.info("Using zig lib path '{s}'", .{config.zig_lib_path.?});
|
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 {
|
} else {
|
||||||
logger.warn("Zig executable path not specified in zls.json and could not be found in PATH", .{});
|
logger.warn("Zig executable path not specified in zls.json and could not be found in PATH", .{});
|
||||||
}
|
}
|
||||||
|
@ -72,9 +72,7 @@ pub fn main() !void {
|
|||||||
|
|
||||||
const global_cache_directory = if (has_cache) Cache.Directory{
|
const global_cache_directory = if (has_cache) Cache.Directory{
|
||||||
.path = global_cache_root,
|
.path = global_cache_root,
|
||||||
// I don't know if with the incomming changes around caching whether `openDir` is correct,
|
.handle = try std.fs.cwd().makeOpenPath(global_cache_root, .{}),
|
||||||
// but `makeOpenPath` which zig build runner uses causes access denied
|
|
||||||
.handle = try std.fs.cwd().openDir(global_cache_root, .{}),
|
|
||||||
} else global_cache_root;
|
} else global_cache_root;
|
||||||
|
|
||||||
var cache = if (has_cache) Cache{
|
var cache = if (has_cache) Cache{
|
||||||
|
Loading…
Reference in New Issue
Block a user