std: all Dir functions moved to std.Io

This commit is contained in:
Andrew Kelley
2025-12-03 20:37:43 -08:00
parent 81214278ca
commit d1d2c37af2
24 changed files with 3064 additions and 3650 deletions
+22 -13
View File
@@ -1,18 +1,20 @@
const std = @import("std");
const builtin = std.builtin;
const tests = @import("test/tests.zig");
const BufMap = std.BufMap;
const mem = std.mem;
const io = std.io;
const fs = std.fs;
const InstallDirectoryOptions = std.Build.InstallDirectoryOptions;
const assert = std.debug.assert;
const Io = std.Io;
const tests = @import("test/tests.zig");
const DevEnv = @import("src/dev.zig").Env;
const ValueInterpretMode = enum { direct, by_name };
const zig_version: std.SemanticVersion = .{ .major = 0, .minor = 16, .patch = 0 };
const stack_size = 46 * 1024 * 1024;
const ValueInterpretMode = enum { direct, by_name };
pub fn build(b: *std.Build) !void {
const only_c = b.option(bool, "only-c", "Translate the Zig compiler to C code, with only the C backend enabled") orelse false;
const target = b.standardTargetOptions(.{
@@ -306,8 +308,10 @@ pub fn build(b: *std.Build) !void {
if (enable_llvm) {
const cmake_cfg = if (static_llvm) null else blk: {
const io = b.graph.io;
const cwd: Io.Dir = .cwd();
if (findConfigH(b, config_h_path_option)) |config_h_path| {
const file_contents = fs.cwd().readFileAlloc(config_h_path, b.allocator, .limited(max_config_h_bytes)) catch unreachable;
const file_contents = cwd.readFileAlloc(io, config_h_path, b.allocator, .limited(max_config_h_bytes)) catch unreachable;
break :blk parseConfigH(b, file_contents);
} else {
std.log.warn("config.h could not be located automatically. Consider providing it explicitly via \"-Dconfig_h\"", .{});
@@ -1153,10 +1157,13 @@ const CMakeConfig = struct {
const max_config_h_bytes = 1 * 1024 * 1024;
fn findConfigH(b: *std.Build, config_h_path_option: ?[]const u8) ?[]const u8 {
const io = b.graph.io;
const cwd: Io.Dir = .cwd();
if (config_h_path_option) |path| {
var config_h_or_err = fs.cwd().openFile(path, .{});
var config_h_or_err = cwd.openFile(io, path, .{});
if (config_h_or_err) |*file| {
file.close();
file.close(io);
return path;
} else |_| {
std.log.err("Could not open provided config.h: \"{s}\"", .{path});
@@ -1166,13 +1173,13 @@ fn findConfigH(b: *std.Build, config_h_path_option: ?[]const u8) ?[]const u8 {
var check_dir = fs.path.dirname(b.graph.zig_exe).?;
while (true) {
var dir = fs.cwd().openDir(check_dir, .{}) catch unreachable;
defer dir.close();
var dir = cwd.openDir(io, check_dir, .{}) catch unreachable;
defer dir.close(io);
// Check if config.h is present in dir
var config_h_or_err = dir.openFile("config.h", .{});
var config_h_or_err = dir.openFile(io, "config.h", .{});
if (config_h_or_err) |*file| {
file.close();
file.close(io);
return fs.path.join(
b.allocator,
&[_][]const u8{ check_dir, "config.h" },
@@ -1183,9 +1190,9 @@ fn findConfigH(b: *std.Build, config_h_path_option: ?[]const u8) ?[]const u8 {
}
// Check if we reached the source root by looking for .git, and bail if so
var git_dir_or_err = dir.openDir(".git", .{});
var git_dir_or_err = dir.openDir(io, ".git", .{});
if (git_dir_or_err) |*git_dir| {
git_dir.close();
git_dir.close(io);
return null;
} else |_| {}
@@ -1581,6 +1588,8 @@ const llvm_libs_xtensa = [_][]const u8{
};
fn generateLangRef(b: *std.Build) std.Build.LazyPath {
const io = b.graph.io;
const doctest_exe = b.addExecutable(.{
.name = "doctest",
.root_module = b.createModule(.{
@@ -1590,7 +1599,7 @@ fn generateLangRef(b: *std.Build) std.Build.LazyPath {
}),
});
var dir = b.build_root.handle.openDir("doc/langref", .{ .iterate = true }) catch |err| {
var dir = b.build_root.handle.openDir(io, "doc/langref", .{ .iterate = true }) catch |err| {
std.debug.panic("unable to open '{f}doc/langref' directory: {s}", .{
b.build_root, @errorName(err),
});