tools: fix compilation errors

This commit is contained in:
Andrew Kelley 2025-12-22 22:30:49 -08:00
parent 7a09d579b5
commit c05e2720a1
8 changed files with 27 additions and 25 deletions

View file

@ -25,11 +25,15 @@ pub fn main() !void {
var general_purpose_allocator: std.heap.GeneralPurposeAllocator(.{}) = .init;
const gpa = general_purpose_allocator.allocator();
var threaded: std.Io.Threaded = .init(gpa, .{});
defer threaded.deinit();
const io = threaded.io();
const args = try std.process.argsAlloc(arena);
return cmdObjCopy(gpa, arena, args[1..]);
return cmdObjCopy(arena, io, args[1..]);
}
fn cmdObjCopy(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
fn cmdObjCopy(arena: Allocator, io: Io, args: []const []const u8) !void {
var i: usize = 0;
var opt_out_fmt: ?std.Target.ObjectFormat = null;
var opt_input: ?[]const u8 = null;
@ -57,7 +61,7 @@ fn cmdObjCopy(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
fatal("unexpected positional argument: '{s}'", .{arg});
}
} else if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
return Io.File.stdout().writeAll(usage);
return Io.File.stdout().writeStreamingAll(io, usage);
} else if (mem.eql(u8, arg, "-O") or mem.eql(u8, arg, "--output-target")) {
i += 1;
if (i >= args.len) fatal("expected another argument after '{s}'", .{arg});
@ -148,11 +152,7 @@ fn cmdObjCopy(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
const input = opt_input orelse fatal("expected input parameter", .{});
const output = opt_output orelse fatal("expected output parameter", .{});
var threaded: std.Io.Threaded = .init(gpa, .{});
defer threaded.deinit();
const io = threaded.io();
const input_file = Io.Dir.cwd().openFile(input, .{}) catch |err| fatal("failed to open {s}: {t}", .{ input, err });
const input_file = Io.Dir.cwd().openFile(io, input, .{}) catch |err| fatal("failed to open {s}: {t}", .{ input, err });
defer input_file.close(io);
const stat = input_file.stat(io) catch |err| fatal("failed to stat {s}: {t}", .{ input, err });
@ -178,9 +178,9 @@ fn cmdObjCopy(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
}
};
const mode = if (out_fmt != .elf or only_keep_debug) Io.File.default_mode else stat.mode;
const permissions: Io.File.Permissions = if (out_fmt != .elf or only_keep_debug) .default_file else stat.permissions;
var output_file = try Io.Dir.cwd().createFile(io, output, .{ .mode = mode });
var output_file = try Io.Dir.cwd().createFile(io, output, .{ .permissions = permissions });
defer output_file.close(io);
var out = output_file.writer(io, &output_buffer);
@ -223,7 +223,7 @@ fn cmdObjCopy(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
if (listen) {
var stdin_reader = Io.File.stdin().reader(io, &stdin_buffer);
var stdout_writer = Io.File.stdout().writer(&stdout_buffer);
var stdout_writer = Io.File.stdout().writer(io, &stdout_buffer);
var server = try Server.init(.{
.in = &stdin_reader.interface,
.out = &stdout_writer.interface,

View file

@ -51,8 +51,8 @@ pub fn main() !void {
var coverage: std.debug.Coverage = .init;
defer coverage.deinit(gpa);
var debug_info = std.debug.Info.load(gpa, exe_path, &coverage, target.ofmt, target.cpu.arch) catch |err| {
fatal("failed to load debug info for {f}: {s}", .{ exe_path, @errorName(err) });
var debug_info = std.debug.Info.load(gpa, io, exe_path, &coverage, target.ofmt, target.cpu.arch) catch |err| {
fatal("failed to load debug info for {f}: {t}", .{ exe_path, err });
};
defer debug_info.deinit(gpa);

View file

@ -930,8 +930,9 @@ fn parseHexInt(text: []const u8) !u31 {
}
fn usageAndExit(arg0: []const u8, code: u8) noreturn {
const stderr, _ = std.debug.lockStderrWriter(&.{});
stderr.print(
const stderr = std.debug.lockStderr(&.{});
const w = &stderr.file_writer.interface;
w.print(
\\Usage: {s} <SPIRV-Headers repository path> <path/to/zig/src/codegen/spirv/extinst.zig.grammar.json>
\\
\\Generates Zig bindings for SPIR-V specifications found in the SPIRV-Headers

View file

@ -181,8 +181,8 @@ pub fn main() !void {
const args = try std.process.argsAlloc(gpa);
if (args.len < 2 or mem.eql(u8, args[1], "--help")) {
const w, _ = std.debug.lockStderrWriter(&.{});
defer std.debug.unlockStderrWriter();
const stderr = std.debug.lockStderr(&.{});
const w = &stderr.file_writer.interface;
usage(w, args[0]) catch std.process.exit(2);
std.process.exit(1);
}

View file

@ -197,7 +197,7 @@ pub fn main() !void {
try dir_stack.append(target_include_dir);
while (dir_stack.pop()) |full_dir_name| {
var dir = Dir.cwd().openDir(full_dir_name, .{ .iterate = true }) catch |err| switch (err) {
var dir = Dir.cwd().openDir(io, full_dir_name, .{ .iterate = true }) catch |err| switch (err) {
error.FileNotFound => continue :search,
error.AccessDenied => continue :search,
else => return err,
@ -213,7 +213,7 @@ pub fn main() !void {
.file => {
const rel_path = try Dir.path.relative(arena, target_include_dir, full_path);
const max_size = 2 * 1024 * 1024 * 1024;
const raw_bytes = try Dir.cwd().readFileAlloc(full_path, arena, .limited(max_size));
const raw_bytes = try Dir.cwd().readFileAlloc(io, full_path, arena, .limited(max_size));
const trimmed = std.mem.trim(u8, raw_bytes, " \r\n\t");
total_bytes += raw_bytes.len;
const hash = try arena.alloc(u8, 32);

View file

@ -961,8 +961,8 @@ fn objectLessThan(context: void, a: *json.ObjectMap, b: *json.ObjectMap) bool {
}
fn printUsageAndExit(arg0: []const u8) noreturn {
const w, _ = std.debug.lockStderrWriter(&.{});
defer std.debug.unlockStderrWriter();
const stderr = std.debug.lockStderr(&.{});
const w = &stderr.file_writer.interface;
printUsage(w, arg0) catch std.process.exit(2);
std.process.exit(1);
}

View file

@ -2426,8 +2426,9 @@ fn processOneTarget(io: Io, job: Job) void {
}
fn usageAndExit(arg0: []const u8, code: u8) noreturn {
const stderr, _ = std.debug.lockStderrWriter(&.{});
stderr.print(
const stderr = std.debug.lockStderr(&.{});
const w = &stderr.file_writer.interface;
w.print(
\\Usage: {s} /path/to/llvm-tblgen /path/git/llvm-project /path/git/zig [zig_name filter]
\\
\\Updates lib/std/target/<target>.zig from llvm/lib/Target/<Target>/<Target>.td .

View file

@ -195,8 +195,8 @@ pub fn main() anyerror!void {
}
fn printUsageAndExit(arg0: []const u8) noreturn {
const w, _ = std.debug.lockStderrWriter(&.{});
defer std.debug.unlockStderrWriter();
const stderr = std.debug.lockStderr(&.{});
const w = &stderr.file_writer.interface;
printUsage(w, arg0) catch std.process.exit(2);
std.process.exit(1);
}