Skip to content

Commit

Permalink
use a different build_runner file based on the runtime zig version
Browse files Browse the repository at this point in the history
  • Loading branch information
leecannon committed Aug 19, 2023
1 parent eee9b83 commit 4a8bcaf
Show file tree
Hide file tree
Showing 9 changed files with 1,038 additions and 22 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build_runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ on:
push:
paths:
- ".github/workflows/build_runner.yml"
- "src/special/build_runner.zig"
- "src/build_runner/**"
pull_request:
paths:
- ".github/workflows/build_runner.yml"
- "src/special/build_runner.zig"
- "src/build_runner/**"
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
Expand All @@ -30,11 +30,11 @@ jobs:
submodules: true

- name: Grab zig
uses: goto-bus-stop/setup-zig@v1
uses: goto-bus-stop/setup-zig@v2
with:
version: ${{ matrix.zig_version }}

- name: Check build_runner builds on master
run: |
pwd
zig build --build-runner src/special/build_runner.zig
zig build --build-runner src/build_runner/master.zig
2 changes: 1 addition & 1 deletion .github/workflows/fuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
echo "FUZZING_DURATION=15m" >> $GITHUB_ENV
- name: Grab zig
uses: goto-bus-stop/setup-zig@v1
uses: goto-bus-stop/setup-zig@v2
with:
version: master

Expand Down
2 changes: 1 addition & 1 deletion src/DocumentStore.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const offsets = @import("offsets.zig");
const log = std.log.scoped(.zls_store);
const Ast = std.zig.Ast;
const BuildAssociatedConfig = @import("BuildAssociatedConfig.zig");
const BuildConfig = @import("special/build_runner.zig").BuildConfig;
const BuildConfig = @import("build_runner/BuildConfig.zig");
const tracy = @import("tracy.zig");
const Config = @import("Config.zig");
const ZigVersionWrapper = @import("ZigVersionWrapper.zig");
Expand Down
31 changes: 25 additions & 6 deletions src/Server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const InternPool = @import("analyser/analyser.zig").InternPool;
const ZigVersionWrapper = @import("ZigVersionWrapper.zig");
const Transport = @import("Transport.zig");
const known_folders = @import("known-folders");
const BuildRunnerVersion = @import("build_runner/BuildRunnerVersion.zig").BuildRunnerVersion;

const signature_help = @import("features/signature_help.zig");
const references = @import("features/references.zig");
Expand Down Expand Up @@ -1049,15 +1050,33 @@ fn resolveConfiguration(server: *Server, config_arena: std.mem.Allocator, config
try std.fs.cwd().makePath(config.global_cache_path.?);
}

if (config.build_runner_path == null) blk: {
if (config.global_cache_path == null) break :blk;
if (config.build_runner_path == null and
config.global_cache_path != null and
config.zig_exe_path != null and
server.runtime_zig_version != null)
{
const build_runner_version = BuildRunnerVersion.selectBuildRunnerVersion(server.runtime_zig_version.?.version);

const build_runner_file_name = try std.fmt.allocPrint(config_arena, "build_runner_{s}.zig", .{@tagName(build_runner_version)});
const build_runner_path = try std.fs.path.resolve(config_arena, &[_][]const u8{ config.global_cache_path.?, build_runner_file_name });

const build_runner_file = try std.fs.createFileAbsolute(build_runner_path, .{});
defer build_runner_file.close();

config.build_runner_path = try std.fs.path.resolve(config_arena, &[_][]const u8{ config.global_cache_path.?, "build_runner.zig" });
const build_config_path = try std.fs.path.resolve(config_arena, &[_][]const u8{ config.global_cache_path.?, "BuildConfig.zig" });

const file = try std.fs.createFileAbsolute(config.build_runner_path.?, .{});
defer file.close();
const build_config_file = try std.fs.createFileAbsolute(build_config_path, .{});
defer build_config_file.close();

try build_config_file.writeAll(@embedFile("build_runner/BuildConfig.zig"));

try build_runner_file.writeAll(
switch (build_runner_version) {
inline else => |tag| @embedFile("build_runner/" ++ @tagName(tag) ++ ".zig"),
},
);

try file.writeAll(@embedFile("special/build_runner.zig"));
config.build_runner_path = build_runner_path;
}

if (config.builtin_path == null) blk: {
Expand Down
Loading

0 comments on commit 4a8bcaf

Please sign in to comment.