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

Fix deprecated getStderrMutex usage #1904

Merged
merged 5 commits into from
May 30, 2024
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
4 changes: 2 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const zls_version = std.SemanticVersion{ .major = 0, .minor = 13, .patch = 0 };
const zls_version_is_tagged: bool = false;

/// Specify the minimum Zig version that is required to compile and test ZLS:
/// Run: add output directory arguments
/// rework std.Progress
///
/// Must match the `minimum_zig_version` in `build.zig.zon`.
const minimum_zig_version = "0.13.0-dev.79+6bc0cef60";
const minimum_zig_version = "0.13.0-dev.336+963ffe9d5";

/// Specify the minimum Zig version that is required to run ZLS:
/// Release 0.12.0
Expand Down
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Must match the `zls_version` in `build.zig`
.version = "0.13.0-dev",
// Must match the `minimum_zig_version` in `build.zig`
.minimum_zig_version = "0.13.0-dev.79+6bc0cef60",
.minimum_zig_version = "0.13.0-dev.336+963ffe9d5",
// whenever the dependencies are updated, run `nix run github:acristoffers/zon2nix > deps.nix`
.dependencies = .{
.known_folders = .{
Expand Down
42 changes: 30 additions & 12 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 31 additions & 17 deletions src/build_runner/0.12.0.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ const Step = std.Build.Step;

pub const dependencies = @import("@dependencies");

const writeFile2_removed_version =
std.SemanticVersion.parse("0.13.0-dev.68+b86c4bde6") catch unreachable;
const std_progress_rework_version =
std.SemanticVersion.parse("0.13.0-dev.336+963ffe9d5") catch unreachable;

const ProgressNode = if (builtin.zig_version.order(std_progress_rework_version) == .lt)
*std.Progress.Node
else
std.Progress.Node;

///! This is a modified build runner to extract information out of build.zig
///! Modified version of lib/build_runner.zig
pub fn main() !void {
Expand Down Expand Up @@ -276,13 +286,21 @@ pub fn main() !void {
}
}

var progress: std.Progress = .{ .terminal = null };
const main_progress_node = progress.start("", 0);
var progress = if (comptime builtin.zig_version.order(std_progress_rework_version) == .lt)
std.Progress{ .terminal = null }
else {};

const main_progress_node = if (comptime builtin.zig_version.order(std_progress_rework_version) == .lt)
progress.start("", 0)
else
std.Progress.start(.{
.disable_printing = true,
});

builder.debug_log_scopes = debug_log_scopes.items;
builder.resolveInstallPrefix(install_prefix, dir_list);
{
var prog_node = main_progress_node.start("user build.zig logic", 0);
var prog_node = main_progress_node.start("Configure", 0);
defer prog_node.end();
try builder.runBuild(root);
}
Expand All @@ -296,14 +314,10 @@ pub fn main() !void {
const s = std.fs.path.sep_str;
const tmp_sub_path = "tmp" ++ s ++ (output_tmp_nonce orelse fatal("missing -Z arg", .{}));

const writeFileFn = comptime blk: {
const writeFile2_removed_version =
std.SemanticVersion.parse("0.13.0-dev.68+b86c4bde6") catch unreachable;
break :blk if (builtin.zig_version.order(writeFile2_removed_version) == .lt)
std.fs.Dir.writeFile2
else
std.fs.Dir.writeFile;
};
const writeFileFn = if (comptime builtin.zig_version.order(writeFile2_removed_version) == .lt)
std.fs.Dir.writeFile2
else
std.fs.Dir.writeFile;

writeFileFn(local_cache_directory.handle, .{
.sub_path = tmp_sub_path,
Expand Down Expand Up @@ -363,7 +377,7 @@ fn runSteps(
arena: std.mem.Allocator,
b: *std.Build,
steps: []const *Step,
parent_prog_node: *std.Progress.Node,
parent_prog_node: ProgressNode,
thread_pool_options: std.Thread.Pool.Options,
run: *Run,
seed: u32,
Expand Down Expand Up @@ -426,7 +440,7 @@ fn runSteps(

wait_group.start();
thread_pool.spawn(workerMakeOneStep, .{
&wait_group, &thread_pool, b, step, &step_prog, run,
&wait_group, &thread_pool, b, step, if (comptime builtin.zig_version.order(std_progress_rework_version) == .lt) &step_prog else step_prog, run,
}) catch @panic("OOM");
}
}
Expand Down Expand Up @@ -541,7 +555,7 @@ fn workerMakeOneStep(
thread_pool: *std.Thread.Pool,
b: *std.Build,
s: *Step,
prog_node: *std.Progress.Node,
prog_node: ProgressNode,
run: *Run,
) void {
defer wg.finish();
Expand Down Expand Up @@ -594,10 +608,10 @@ fn workerMakeOneStep(
}

var sub_prog_node = prog_node.start(s.name, 0);
sub_prog_node.activate();
if (comptime builtin.zig_version.order(std_progress_rework_version) == .lt) sub_prog_node.activate();
defer sub_prog_node.end();

const make_result = s.make(&sub_prog_node);
const make_result = s.make(if (comptime builtin.zig_version.order(std_progress_rework_version) == .lt) &sub_prog_node else sub_prog_node);

handle_result: {
if (make_result) |_| {
Expand Down Expand Up @@ -745,7 +759,7 @@ const Packages = struct {
fn extractBuildInformation(
b: *std.Build,
arena: std.mem.Allocator,
main_progress_node: *std.Progress.Node,
main_progress_node: ProgressNode,
thread_pool_options: std.Thread.Pool.Options,
run: *Run,
seed: u32,
Expand Down
4 changes: 2 additions & 2 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ fn logFn(
const scope_txt = comptime @tagName(scope);

const stderr = std.io.getStdErr().writer();
std.debug.getStderrMutex().lock();
defer std.debug.getStderrMutex().unlock();
std.debug.lockStdErr();
defer std.debug.unlockStdErr();

stderr.print("{s:<5}: ({s:^6}): ", .{ level_txt, if (comptime std.mem.startsWith(u8, scope_txt, "zls_")) scope_txt[4..] else scope_txt }) catch return;
stderr.print(format, args) catch return;
Expand Down
4 changes: 2 additions & 2 deletions tests/lsp_features/completion.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3585,8 +3585,8 @@ fn searchCompletionItemWithLabel(completion_list: types.CompletionList, label: [
if (std.mem.eql(u8, item.label, label)) return item;
}

std.debug.getStderrMutex().lock();
defer std.debug.getStderrMutex().unlock();
std.debug.lockStdErr();
defer std.debug.unlockStdErr();

const stderr = std.io.getStdErr().writer();

Expand Down