Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple build runners #1411

Merged
merged 4 commits into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 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 @@ -18,7 +18,7 @@ jobs:
if: github.repository_owner == 'zigtools'
strategy:
matrix:
zig_version: [master]
zig_version: [master, 0.11.0]

runs-on: ubuntu-latest

Expand All @@ -30,11 +30,17 @@ 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
- name: Create temp zig project
run: |
pwd
zig build --build-runner src/special/build_runner.zig
mkdir $RUNNER_TEMP/TEMP_ZIG_PROJECT
cd $RUNNER_TEMP/TEMP_ZIG_PROJECT
zig init-exe

- name: Check build_runner builds
run: |
cd $RUNNER_TEMP/TEMP_ZIG_PROJECT
zig build --build-runner $GITHUB_WORKSPACE/src/build_runner/${{ matrix.zig_version }}*.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
6 changes: 4 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn build(b: *std.build.Builder) !void {
exe_options.addOption(bool, "use_gpa", b.option(bool, "use_gpa", "Good for debugging") orelse (optimize == .Debug));
exe_options.addOption(bool, "coverage", coverage);

const version = v: {
const version_string = v: {
const version_string = b.fmt("{d}.{d}.{d}", .{ zls_version.major, zls_version.minor, zls_version.patch });
const build_root_path = b.build_root.path orelse ".";

Expand Down Expand Up @@ -79,8 +79,10 @@ pub fn build(b: *std.build.Builder) !void {
},
}
};
exe_options.addOption([]const u8, "version_string", version_string);

exe_options.addOption([]const u8, "version", version);
const version = try std.SemanticVersion.parse(version_string);
exe_options.addOption(std.SemanticVersion, "version", version);

const known_folders_module = b.dependency("known_folders", .{}).module("known-folders");
exe.addModule("known-folders", known_folders_module);
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
46 changes: 32 additions & 14 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 @@ -493,38 +494,37 @@ fn initializeHandler(server: *Server, _: std.mem.Allocator, request: types.Initi

if (server.runtime_zig_version) |zig_version_wrapper| {
const zig_version = zig_version_wrapper.version;
const zls_version = comptime std.SemanticVersion.parse(build_options.version) catch unreachable;

const zig_version_simple = std.SemanticVersion{
.major = zig_version.major,
.minor = zig_version.minor,
.patch = 0,
};
const zls_version_simple = std.SemanticVersion{
.major = zls_version.major,
.minor = zls_version.minor,
.major = build_options.version.major,
.minor = build_options.version.minor,
.patch = 0,
};

switch (zig_version_simple.order(zls_version_simple)) {
.lt => {
server.showMessage(.Warning,
\\Zig `{}` is older than ZLS `{}`. Update Zig to avoid unexpected behavior.
, .{ zig_version, zls_version });
\\Zig `{s}` is older than ZLS `{s}`. Update Zig to avoid unexpected behavior.
, .{ zig_version_wrapper.raw_string, build_options.version_string });
},
.eq => {},
.gt => {
server.showMessage(.Warning,
\\Zig `{}` is newer than ZLS `{}`. Update ZLS to avoid unexpected behavior.
, .{ zig_version, zls_version });
\\Zig `{s}` is newer than ZLS `{s}`. Update ZLS to avoid unexpected behavior.
, .{ zig_version_wrapper.raw_string, build_options.version_string });
},
}
}

return .{
.serverInfo = .{
.name = "zls",
.version = build_options.version,
.version = build_options.version_string,
},
.capabilities = .{
.positionEncoding = switch (server.offset_encoding) {
Expand Down Expand Up @@ -1050,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