mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 02:44:43 +01:00
compiler: update various code to new fs API
This commit is contained in:
parent
e1cf753db7
commit
16f8af1b9a
32 changed files with 228 additions and 219 deletions
2
lib/compiler/aro/main.zig
vendored
2
lib/compiler/aro/main.zig
vendored
|
|
@ -43,7 +43,7 @@ pub fn main() u8 {
|
|||
return 1;
|
||||
};
|
||||
|
||||
const aro_name = std.fs.selfExePathAlloc(gpa) catch {
|
||||
const aro_name = process.executablePathAlloc(io, gpa) catch {
|
||||
std.debug.print("unable to find Aro executable path\n", .{});
|
||||
if (fast_exit) process.exit(1);
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -1330,7 +1330,7 @@ test "cache file and then recall it" {
|
|||
var cache: Cache = .{
|
||||
.io = io,
|
||||
.gpa = testing.allocator,
|
||||
.manifest_dir = try tmp.dir.makeOpenPath(temp_manifest_dir, .{}),
|
||||
.manifest_dir = try tmp.dir.makeOpenPath(io, temp_manifest_dir, .{}),
|
||||
};
|
||||
cache.addPrefix(.{ .path = null, .handle = tmp.dir });
|
||||
defer cache.manifest_dir.close(io);
|
||||
|
|
@ -1396,7 +1396,7 @@ test "check that changing a file makes cache fail" {
|
|||
var cache: Cache = .{
|
||||
.io = io,
|
||||
.gpa = testing.allocator,
|
||||
.manifest_dir = try tmp.dir.makeOpenPath(temp_manifest_dir, .{}),
|
||||
.manifest_dir = try tmp.dir.makeOpenPath(io, temp_manifest_dir, .{}),
|
||||
};
|
||||
cache.addPrefix(.{ .path = null, .handle = tmp.dir });
|
||||
defer cache.manifest_dir.close(io);
|
||||
|
|
@ -1456,7 +1456,7 @@ test "no file inputs" {
|
|||
var cache: Cache = .{
|
||||
.io = io,
|
||||
.gpa = testing.allocator,
|
||||
.manifest_dir = try tmp.dir.makeOpenPath(temp_manifest_dir, .{}),
|
||||
.manifest_dir = try tmp.dir.makeOpenPath(io, temp_manifest_dir, .{}),
|
||||
};
|
||||
cache.addPrefix(.{ .path = null, .handle = tmp.dir });
|
||||
defer cache.manifest_dir.close(io);
|
||||
|
|
@ -1515,7 +1515,7 @@ test "Manifest with files added after initial hash work" {
|
|||
var cache: Cache = .{
|
||||
.io = io,
|
||||
.gpa = testing.allocator,
|
||||
.manifest_dir = try tmp.dir.makeOpenPath(temp_manifest_dir, .{}),
|
||||
.manifest_dir = try tmp.dir.makeOpenPath(io, temp_manifest_dir, .{}),
|
||||
};
|
||||
cache.addPrefix(.{ .path = null, .handle = tmp.dir });
|
||||
defer cache.manifest_dir.close(io);
|
||||
|
|
|
|||
|
|
@ -84,14 +84,14 @@ pub fn openDir(
|
|||
return p.root_dir.handle.openDir(io, joined_path, args);
|
||||
}
|
||||
|
||||
pub fn makeOpenPath(p: Path, sub_path: []const u8, opts: Io.Dir.OpenOptions) !Io.Dir {
|
||||
pub fn makeOpenPath(p: Path, io: Io, sub_path: []const u8, opts: Io.Dir.OpenOptions) !Io.Dir {
|
||||
var buf: [fs.max_path_bytes]u8 = undefined;
|
||||
const joined_path = if (p.sub_path.len == 0) sub_path else p: {
|
||||
break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{
|
||||
p.sub_path, sub_path,
|
||||
}) catch return error.NameTooLong;
|
||||
};
|
||||
return p.root_dir.handle.makeOpenPath(joined_path, opts);
|
||||
return p.root_dir.handle.makeOpenPath(io, joined_path, opts);
|
||||
}
|
||||
|
||||
pub fn statFile(p: Path, io: Io, sub_path: []const u8) !Io.Dir.Stat {
|
||||
|
|
|
|||
|
|
@ -1588,7 +1588,7 @@ pub const CopyFileOptions = struct {
|
|||
|
||||
pub const CopyFileError = File.OpenError || File.StatError ||
|
||||
File.Atomic.InitError || File.Atomic.FinishError ||
|
||||
File.Reader.Error || File.WriteError || error{InvalidFileName};
|
||||
File.Reader.Error || File.Writer.Error || error{InvalidFileName};
|
||||
|
||||
/// Atomically creates a new file at `dest_path` within `dest_dir` with the
|
||||
/// same contents as `source_path` within `source_dir`, overwriting any already
|
||||
|
|
|
|||
|
|
@ -242,8 +242,7 @@ pub fn addCertsFromFilePath(
|
|||
}
|
||||
|
||||
pub const AddCertsFromFileError = Allocator.Error ||
|
||||
Io.File.GetSeekPosError ||
|
||||
Io.File.ReadError ||
|
||||
Io.File.Reader.Error ||
|
||||
ParseCertError ||
|
||||
std.base64.Error ||
|
||||
error{ CertificateAuthorityBundleTooBig, MissingEndCertificateMarker, Streaming };
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ const mem = std.mem;
|
|||
const Allocator = std.mem.Allocator;
|
||||
const Bundle = @import("../Bundle.zig");
|
||||
|
||||
pub const RescanMacError = Allocator.Error || Io.File.OpenError || Io.File.ReadError || Io.File.SeekError || Bundle.ParseCertError || error{EndOfStream};
|
||||
pub const RescanMacError = Allocator.Error || Io.File.OpenError || Io.File.Reader.Error || Io.File.SeekError || Bundle.ParseCertError || error{EndOfStream};
|
||||
|
||||
pub fn rescanMac(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp) RescanMacError!void {
|
||||
cb.bytes.clearRetainingCapacity();
|
||||
|
|
|
|||
|
|
@ -213,7 +213,7 @@ test "Dir.readLink" {
|
|||
// test 3: relative path symlink
|
||||
const parent_file = ".." ++ fs.path.sep_str ++ "target.txt";
|
||||
const canonical_parent_file = try ctx.toCanonicalPathSep(parent_file);
|
||||
var subdir = try ctx.dir.makeOpenPath("subdir", .{});
|
||||
var subdir = try ctx.dir.makeOpenPath(io, "subdir", .{});
|
||||
defer subdir.close(io);
|
||||
try setupSymlink(io, subdir, canonical_parent_file, "relative-link.txt", .{});
|
||||
try testReadLink(io, subdir, canonical_parent_file, "relative-link.txt");
|
||||
|
|
@ -411,7 +411,7 @@ test "openDir non-cwd parent '..'" {
|
|||
var tmp = tmpDir(.{});
|
||||
defer tmp.cleanup();
|
||||
|
||||
var subdir = try tmp.dir.makeOpenPath("subdir", .{});
|
||||
var subdir = try tmp.dir.makeOpenPath(io, "subdir", .{});
|
||||
defer subdir.close(io);
|
||||
|
||||
var dir = try subdir.openDir(io, "..", .{});
|
||||
|
|
@ -613,7 +613,7 @@ test "Dir.Iterator but dir is deleted during iteration" {
|
|||
defer tmp.cleanup();
|
||||
|
||||
// Create directory and setup an iterator for it
|
||||
var subdir = try tmp.dir.makeOpenPath("subdir", .{ .iterate = true });
|
||||
var subdir = try tmp.dir.makeOpenPath(io, "subdir", .{ .iterate = true });
|
||||
defer subdir.close(io);
|
||||
|
||||
var iterator = subdir.iterate();
|
||||
|
|
@ -862,7 +862,7 @@ test "makeOpenPath parent dirs do not exist" {
|
|||
var tmp_dir = tmpDir(.{});
|
||||
defer tmp_dir.cleanup();
|
||||
|
||||
var dir = try tmp_dir.dir.makeOpenPath("root_dir/parent_dir/some_dir", .{});
|
||||
var dir = try tmp_dir.dir.makeOpenPath(io, "root_dir/parent_dir/some_dir", .{});
|
||||
dir.close(io);
|
||||
|
||||
// double check that the full directory structure was created
|
||||
|
|
@ -1010,7 +1010,7 @@ test "Dir.rename directory onto non-empty dir" {
|
|||
|
||||
try ctx.dir.makeDir(io, test_dir_path, .default_dir);
|
||||
|
||||
var target_dir = try ctx.dir.makeOpenPath(target_dir_path, .{});
|
||||
var target_dir = try ctx.dir.makeOpenPath(io, target_dir_path, .{});
|
||||
var file = try target_dir.createFile(io, "test_file", .{ .read = true });
|
||||
file.close(io);
|
||||
target_dir.close(io);
|
||||
|
|
@ -1147,7 +1147,7 @@ test "deleteTree does not follow symlinks" {
|
|||
|
||||
try tmp.dir.makePath(io, "b");
|
||||
{
|
||||
var a = try tmp.dir.makeOpenPath("a", .{});
|
||||
var a = try tmp.dir.makeOpenPath(io, "a", .{});
|
||||
defer a.close(io);
|
||||
|
||||
try setupSymlink(io, a, "../b", "b", .{ .is_directory = true });
|
||||
|
|
@ -1346,7 +1346,7 @@ test "makepath ignores '.'" {
|
|||
fn testFilenameLimits(io: Io, iterable_dir: Dir, maxed_filename: []const u8) !void {
|
||||
// setup, create a dir and a nested file both with maxed filenames, and walk the dir
|
||||
{
|
||||
var maxed_dir = try iterable_dir.makeOpenPath(maxed_filename, .{});
|
||||
var maxed_dir = try iterable_dir.makeOpenPath(io, maxed_filename, .{});
|
||||
defer maxed_dir.close(io);
|
||||
|
||||
try maxed_dir.writeFile(io, .{ .sub_path = maxed_filename, .data = "" });
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ test "linkat with different directories" {
|
|||
const target_name = "link-target";
|
||||
const link_name = "newlink";
|
||||
|
||||
const subdir = try tmp.dir.makeOpenPath("subdir", .{});
|
||||
const subdir = try tmp.dir.makeOpenPath(io, "subdir", .{});
|
||||
|
||||
defer tmp.dir.deleteFile(io, target_name) catch {};
|
||||
try tmp.dir.writeFile(io, .{ .sub_path = target_name, .data = "example" });
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ pub const EndRecord = extern struct {
|
|||
return record;
|
||||
}
|
||||
|
||||
pub const FindFileError = File.Reader.SizeError || File.SeekError || File.ReadError || error{
|
||||
pub const FindFileError = File.Reader.SizeError || File.SeekError || File.Reader.Error || error{
|
||||
ZipNoEndRecord,
|
||||
EndOfStream,
|
||||
ReadFailed,
|
||||
|
|
@ -560,7 +560,7 @@ pub const Iterator = struct {
|
|||
|
||||
const out_file = blk: {
|
||||
if (std.fs.path.dirname(filename)) |dirname| {
|
||||
var parent_dir = try dest.makeOpenPath(dirname, .{});
|
||||
var parent_dir = try dest.makeOpenPath(io, dirname, .{});
|
||||
defer parent_dir.close(io);
|
||||
|
||||
const basename = std.fs.path.basename(filename);
|
||||
|
|
|
|||
|
|
@ -832,7 +832,7 @@ pub const Directories = struct {
|
|||
const nonempty_path = if (path.len == 0) "." else path;
|
||||
const handle_or_err = switch (thing) {
|
||||
.@"zig lib" => Io.Dir.cwd().openDir(io, nonempty_path, .{}),
|
||||
.@"global cache", .@"local cache" => Io.Dir.cwd().makeOpenPath(nonempty_path, .{}),
|
||||
.@"global cache", .@"local cache" => Io.Dir.cwd().makeOpenPath(io, nonempty_path, .{}),
|
||||
};
|
||||
return .{
|
||||
.path = if (path.len == 0) null else path,
|
||||
|
|
@ -2111,7 +2111,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
|
|||
cache.* = .{
|
||||
.gpa = gpa,
|
||||
.io = io,
|
||||
.manifest_dir = options.dirs.local_cache.handle.makeOpenPath("h", .{}) catch |err| {
|
||||
.manifest_dir = options.dirs.local_cache.handle.makeOpenPath(io, "h", .{}) catch |err| {
|
||||
return diag.fail(.{ .create_cache_path = .{ .which = .local, .sub = "h", .err = err } });
|
||||
},
|
||||
};
|
||||
|
|
@ -2161,7 +2161,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
|
|||
// to redundantly happen for each AstGen operation.
|
||||
const zir_sub_dir = "z";
|
||||
|
||||
var local_zir_dir = options.dirs.local_cache.handle.makeOpenPath(zir_sub_dir, .{}) catch |err| {
|
||||
var local_zir_dir = options.dirs.local_cache.handle.makeOpenPath(io, zir_sub_dir, .{}) catch |err| {
|
||||
return diag.fail(.{ .create_cache_path = .{ .which = .local, .sub = zir_sub_dir, .err = err } });
|
||||
};
|
||||
errdefer local_zir_dir.close(io);
|
||||
|
|
@ -2169,7 +2169,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
|
|||
.handle = local_zir_dir,
|
||||
.path = try options.dirs.local_cache.join(arena, &.{zir_sub_dir}),
|
||||
};
|
||||
var global_zir_dir = options.dirs.global_cache.handle.makeOpenPath(zir_sub_dir, .{}) catch |err| {
|
||||
var global_zir_dir = options.dirs.global_cache.handle.makeOpenPath(io, zir_sub_dir, .{}) catch |err| {
|
||||
return diag.fail(.{ .create_cache_path = .{ .which = .global, .sub = zir_sub_dir, .err = err } });
|
||||
};
|
||||
errdefer global_zir_dir.close(io);
|
||||
|
|
@ -2440,7 +2440,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
|
|||
const digest = hash.final();
|
||||
|
||||
const artifact_sub_dir = "o" ++ fs.path.sep_str ++ digest;
|
||||
var artifact_dir = options.dirs.local_cache.handle.makeOpenPath(artifact_sub_dir, .{}) catch |err| {
|
||||
var artifact_dir = options.dirs.local_cache.handle.makeOpenPath(io, artifact_sub_dir, .{}) catch |err| {
|
||||
return diag.fail(.{ .create_cache_path = .{ .which = .local, .sub = artifact_sub_dir, .err = err } });
|
||||
};
|
||||
errdefer artifact_dir.close(io);
|
||||
|
|
@ -2895,7 +2895,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
|
|||
tmp_dir_rand_int = std.crypto.random.int(u64);
|
||||
const tmp_dir_sub_path = "tmp" ++ fs.path.sep_str ++ std.fmt.hex(tmp_dir_rand_int);
|
||||
const path = try comp.dirs.local_cache.join(arena, &.{tmp_dir_sub_path});
|
||||
const handle = comp.dirs.local_cache.handle.makeOpenPath(tmp_dir_sub_path, .{}) catch |err| {
|
||||
const handle = comp.dirs.local_cache.handle.makeOpenPath(io, tmp_dir_sub_path, .{}) catch |err| {
|
||||
return comp.setMiscFailure(.open_output, "failed to create output directory '{s}': {t}", .{ path, err });
|
||||
};
|
||||
break :d .{ .path = path, .handle = handle };
|
||||
|
|
@ -2976,7 +2976,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
|
|||
tmp_dir_rand_int = std.crypto.random.int(u64);
|
||||
const tmp_dir_sub_path = "tmp" ++ fs.path.sep_str ++ std.fmt.hex(tmp_dir_rand_int);
|
||||
const path = try comp.dirs.local_cache.join(arena, &.{tmp_dir_sub_path});
|
||||
const handle = comp.dirs.local_cache.handle.makeOpenPath(tmp_dir_sub_path, .{}) catch |err| {
|
||||
const handle = comp.dirs.local_cache.handle.makeOpenPath(io, tmp_dir_sub_path, .{}) catch |err| {
|
||||
return comp.setMiscFailure(.open_output, "failed to create output directory '{s}': {t}", .{ path, err });
|
||||
};
|
||||
break :d .{ .path = path, .handle = handle };
|
||||
|
|
@ -5267,7 +5267,7 @@ fn docsCopyFallible(comp: *Compilation) anyerror!void {
|
|||
const io = comp.io;
|
||||
|
||||
const docs_path = comp.resolveEmitPath(comp.emit_docs.?);
|
||||
var out_dir = docs_path.root_dir.handle.makeOpenPath(docs_path.sub_path, .{}) catch |err| {
|
||||
var out_dir = docs_path.root_dir.handle.makeOpenPath(io, docs_path.sub_path, .{}) catch |err| {
|
||||
return comp.lockAndSetMiscFailure(
|
||||
.docs_copy,
|
||||
"unable to create output directory '{f}': {s}",
|
||||
|
|
@ -5509,7 +5509,7 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) SubU
|
|||
assert(docs_bin_file.sub_path.len > 0); // emitted binary is not a directory
|
||||
|
||||
const docs_path = comp.resolveEmitPath(comp.emit_docs.?);
|
||||
var out_dir = docs_path.root_dir.handle.makeOpenPath(docs_path.sub_path, .{}) catch |err| {
|
||||
var out_dir = docs_path.root_dir.handle.makeOpenPath(io, docs_path.sub_path, .{}) catch |err| {
|
||||
comp.lockAndSetMiscFailure(
|
||||
.docs_copy,
|
||||
"unable to create output directory '{f}': {t}",
|
||||
|
|
@ -5699,7 +5699,7 @@ pub fn translateC(
|
|||
const tmp_basename = std.fmt.hex(std.crypto.random.int(u64));
|
||||
const tmp_sub_path = "tmp" ++ fs.path.sep_str ++ tmp_basename;
|
||||
const cache_dir = comp.dirs.local_cache.handle;
|
||||
var cache_tmp_dir = try cache_dir.makeOpenPath(tmp_sub_path, .{});
|
||||
var cache_tmp_dir = try cache_dir.makeOpenPath(io, tmp_sub_path, .{});
|
||||
defer cache_tmp_dir.close(io);
|
||||
|
||||
const translated_path = try comp.dirs.local_cache.join(arena, &.{ tmp_sub_path, translated_basename });
|
||||
|
|
@ -6274,7 +6274,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
|
|||
// We can't know the digest until we do the C compiler invocation,
|
||||
// so we need a temporary filename.
|
||||
const out_obj_path = try comp.tmpFilePath(arena, o_basename);
|
||||
var zig_cache_tmp_dir = try comp.dirs.local_cache.handle.makeOpenPath("tmp", .{});
|
||||
var zig_cache_tmp_dir = try comp.dirs.local_cache.handle.makeOpenPath(io, "tmp", .{});
|
||||
defer zig_cache_tmp_dir.close(io);
|
||||
|
||||
const out_diag_path = if (comp.clang_passthrough_mode or !ext.clangSupportsDiagnostics())
|
||||
|
|
@ -6439,7 +6439,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
|
|||
// Rename into place.
|
||||
const digest = man.final();
|
||||
const o_sub_path = try fs.path.join(arena, &[_][]const u8{ "o", &digest });
|
||||
var o_dir = try comp.dirs.local_cache.handle.makeOpenPath(o_sub_path, .{});
|
||||
var o_dir = try comp.dirs.local_cache.handle.makeOpenPath(io, o_sub_path, .{});
|
||||
defer o_dir.close(io);
|
||||
const tmp_basename = fs.path.basename(out_obj_path);
|
||||
try Io.Dir.rename(zig_cache_tmp_dir, tmp_basename, o_dir, o_basename, io);
|
||||
|
|
@ -6528,7 +6528,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
|
|||
const digest = man.final();
|
||||
|
||||
const o_sub_path = try fs.path.join(arena, &.{ "o", &digest });
|
||||
var o_dir = try comp.dirs.local_cache.handle.makeOpenPath(o_sub_path, .{});
|
||||
var o_dir = try comp.dirs.local_cache.handle.makeOpenPath(io, o_sub_path, .{});
|
||||
defer o_dir.close(io);
|
||||
|
||||
const in_rc_path = try comp.dirs.local_cache.join(comp.gpa, &.{
|
||||
|
|
@ -6616,7 +6616,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
|
|||
const rc_basename_noext = src_basename[0 .. src_basename.len - fs.path.extension(src_basename).len];
|
||||
|
||||
const digest = if (try man.hit()) man.final() else blk: {
|
||||
var zig_cache_tmp_dir = try comp.dirs.local_cache.handle.makeOpenPath("tmp", .{});
|
||||
var zig_cache_tmp_dir = try comp.dirs.local_cache.handle.makeOpenPath(io, "tmp", .{});
|
||||
defer zig_cache_tmp_dir.close(io);
|
||||
|
||||
const res_filename = try std.fmt.allocPrint(arena, "{s}.res", .{rc_basename_noext});
|
||||
|
|
@ -6687,7 +6687,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
|
|||
// Rename into place.
|
||||
const digest = man.final();
|
||||
const o_sub_path = try fs.path.join(arena, &[_][]const u8{ "o", &digest });
|
||||
var o_dir = try comp.dirs.local_cache.handle.makeOpenPath(o_sub_path, .{});
|
||||
var o_dir = try comp.dirs.local_cache.handle.makeOpenPath(io, o_sub_path, .{});
|
||||
defer o_dir.close(io);
|
||||
const tmp_basename = fs.path.basename(out_res_path);
|
||||
try Io.Dir.rename(zig_cache_tmp_dir, tmp_basename, o_dir, res_filename, io);
|
||||
|
|
|
|||
|
|
@ -500,12 +500,12 @@ fn runResource(
|
|||
var tmp_directory: Cache.Directory = .{
|
||||
.path = tmp_directory_path,
|
||||
.handle = handle: {
|
||||
const dir = cache_root.handle.makeOpenPath(tmp_dir_sub_path, .{
|
||||
const dir = cache_root.handle.makeOpenPath(io, tmp_dir_sub_path, .{
|
||||
.iterate = true,
|
||||
}) catch |err| {
|
||||
try eb.addRootErrorMessage(.{
|
||||
.msg = try eb.printString("unable to create temporary directory '{s}': {s}", .{
|
||||
tmp_directory_path, @errorName(err),
|
||||
.msg = try eb.printString("unable to create temporary directory '{s}': {t}", .{
|
||||
tmp_directory_path, err,
|
||||
}),
|
||||
});
|
||||
return error.FetchFailed;
|
||||
|
|
@ -524,7 +524,7 @@ fn runResource(
|
|||
if (native_os == .linux and f.job_queue.work_around_btrfs_bug) {
|
||||
// https://github.com/ziglang/zig/issues/17095
|
||||
pkg_path.root_dir.handle.close(io);
|
||||
pkg_path.root_dir.handle = cache_root.handle.makeOpenPath(tmp_dir_sub_path, .{
|
||||
pkg_path.root_dir.handle = cache_root.handle.makeOpenPath(io, tmp_dir_sub_path, .{
|
||||
.iterate = true,
|
||||
}) catch @panic("btrfs workaround failed");
|
||||
}
|
||||
|
|
@ -1366,7 +1366,7 @@ fn unpackGitPack(f: *Fetch, out_dir: Io.Dir, resource: *Resource.Git) anyerror!U
|
|||
// we do not attempt to replicate the exact structure of a real .git
|
||||
// directory, since that isn't relevant for fetching a package.
|
||||
{
|
||||
var pack_dir = try out_dir.makeOpenPath(".git", .{});
|
||||
var pack_dir = try out_dir.makeOpenPath(io, ".git", .{});
|
||||
defer pack_dir.close(io);
|
||||
var pack_file = try pack_dir.createFile(io, "pkg.pack", .{ .read = true });
|
||||
defer pack_file.close(io);
|
||||
|
|
@ -1743,7 +1743,7 @@ const HashedFile = struct {
|
|||
|
||||
const Error =
|
||||
Io.File.OpenError ||
|
||||
Io.File.ReadError ||
|
||||
Io.File.Reader.Error ||
|
||||
Io.File.StatError ||
|
||||
Io.File.ChmodError ||
|
||||
Io.Dir.ReadLinkError;
|
||||
|
|
@ -2258,7 +2258,7 @@ const TestFetchBuilder = struct {
|
|||
cache_parent_dir: std.Io.Dir,
|
||||
path_or_url: []const u8,
|
||||
) !*Fetch {
|
||||
const cache_dir = try cache_parent_dir.makeOpenPath("zig-global-cache", .{});
|
||||
const cache_dir = try cache_parent_dir.makeOpenPath(io, "zig-global-cache", .{});
|
||||
|
||||
self.http_client = .{ .allocator = allocator, .io = io };
|
||||
self.global_cache_directory = .{ .handle = cache_dir, .path = null };
|
||||
|
|
|
|||
|
|
@ -1720,10 +1720,10 @@ pub fn main() !void {
|
|||
var pack_file_reader = pack_file.reader(io, &pack_file_buffer);
|
||||
|
||||
const commit = try Oid.parse(format, args[3]);
|
||||
var worktree = try Io.Dir.cwd().makeOpenPath(args[4], .{});
|
||||
var worktree = try Io.Dir.cwd().makeOpenPath(io, args[4], .{});
|
||||
defer worktree.close(io);
|
||||
|
||||
var git_dir = try worktree.makeOpenPath(".git", .{});
|
||||
var git_dir = try worktree.makeOpenPath(io, ".git", .{});
|
||||
defer git_dir.close(io);
|
||||
|
||||
std.debug.print("Starting index...\n", .{});
|
||||
|
|
|
|||
|
|
@ -1200,7 +1200,7 @@ pub const EmbedFile = struct {
|
|||
/// `.none` means the file was not loaded, so `stat` is undefined.
|
||||
val: InternPool.Index,
|
||||
/// If this is `null` and `val` is `.none`, the file has never been loaded.
|
||||
err: ?(Io.File.OpenError || Io.File.StatError || Io.File.ReadError || error{UnexpectedEof}),
|
||||
err: ?(Io.File.OpenError || Io.File.StatError || Io.File.Reader.Error || error{UnexpectedEof}),
|
||||
stat: Cache.File.Stat,
|
||||
|
||||
pub const Index = enum(u32) {
|
||||
|
|
|
|||
|
|
@ -95,19 +95,19 @@ fn dumpCrashContext() Io.Writer.Error!void {
|
|||
|
||||
// TODO: this does mean that a different thread could grab the stderr mutex between the context
|
||||
// and the actual panic printing, which would be quite confusing.
|
||||
const stderr, _ = std.debug.lockStderrWriter(&.{});
|
||||
const stderr = std.debug.lockStderrWriter(&.{});
|
||||
defer std.debug.unlockStderrWriter();
|
||||
|
||||
try stderr.writeAll("Compiler crash context:\n");
|
||||
try stderr.interface.writeAll("Compiler crash context:\n");
|
||||
|
||||
if (CodegenFunc.current) |*cg| {
|
||||
const func_nav = cg.zcu.funcInfo(cg.func_index).owner_nav;
|
||||
const func_fqn = cg.zcu.intern_pool.getNav(func_nav).fqn;
|
||||
try stderr.print("Generating function '{f}'\n\n", .{func_fqn.fmt(&cg.zcu.intern_pool)});
|
||||
try stderr.interface.print("Generating function '{f}'\n\n", .{func_fqn.fmt(&cg.zcu.intern_pool)});
|
||||
} else if (AnalyzeBody.current) |anal| {
|
||||
try dumpCrashContextSema(anal, stderr, &S.crash_heap);
|
||||
try dumpCrashContextSema(anal, &stderr.interface, &S.crash_heap);
|
||||
} else {
|
||||
try stderr.writeAll("(no context)\n\n");
|
||||
try stderr.interface.writeAll("(no context)\n\n");
|
||||
}
|
||||
}
|
||||
fn dumpCrashContextSema(anal: *AnalyzeBody, stderr: *Io.Writer, crash_heap: []u8) Io.Writer.Error!void {
|
||||
|
|
|
|||
12
src/fmt.zig
12
src/fmt.zig
|
|
@ -59,7 +59,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
|
|||
const arg = args[i];
|
||||
if (mem.startsWith(u8, arg, "-")) {
|
||||
if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
|
||||
try Io.File.stdout().writeAll(usage_fmt);
|
||||
try Io.File.stdout().writeStreamingAll(io, usage_fmt);
|
||||
return process.cleanExit();
|
||||
} else if (mem.eql(u8, arg, "--color")) {
|
||||
if (i + 1 >= args.len) {
|
||||
|
|
@ -154,7 +154,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
|
|||
process.exit(code);
|
||||
}
|
||||
|
||||
return Io.File.stdout().writeAll(formatted);
|
||||
return Io.File.stdout().writeStreamingAll(io, formatted);
|
||||
}
|
||||
|
||||
if (input_files.items.len == 0) {
|
||||
|
|
@ -162,7 +162,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
|
|||
}
|
||||
|
||||
var stdout_buffer: [4096]u8 = undefined;
|
||||
var stdout_writer = Io.File.stdout().writer(&stdout_buffer);
|
||||
var stdout_writer = Io.File.stdout().writer(io, &stdout_buffer);
|
||||
|
||||
var fmt: Fmt = .{
|
||||
.gpa = gpa,
|
||||
|
|
@ -231,7 +231,7 @@ fn fmtPathDir(
|
|||
if (try fmt.seen.fetchPut(stat.inode, {})) |_| return;
|
||||
|
||||
var dir_it = dir.iterate();
|
||||
while (try dir_it.next()) |entry| {
|
||||
while (try dir_it.next(io)) |entry| {
|
||||
const is_dir = entry.kind == .directory;
|
||||
|
||||
if (mem.startsWith(u8, entry.name, ".")) continue;
|
||||
|
|
@ -244,7 +244,7 @@ fn fmtPathDir(
|
|||
try fmtPathDir(fmt, full_path, check_mode, dir, entry.name);
|
||||
} else {
|
||||
fmtPathFile(fmt, full_path, check_mode, dir, entry.name) catch |err| {
|
||||
std.log.err("unable to format '{s}': {s}", .{ full_path, @errorName(err) });
|
||||
std.log.err("unable to format '{s}': {t}", .{ full_path, err });
|
||||
fmt.any_error = true;
|
||||
return;
|
||||
};
|
||||
|
|
@ -355,7 +355,7 @@ fn fmtPathFile(
|
|||
try fmt.stdout_writer.interface.print("{s}\n", .{file_path});
|
||||
fmt.any_error = true;
|
||||
} else {
|
||||
var af = try dir.atomicFile(sub_path, .{ .mode = stat.mode, .write_buffer = &.{} });
|
||||
var af = try dir.atomicFile(io, sub_path, .{ .permissions = stat.permissions, .write_buffer = &.{} });
|
||||
defer af.deinit();
|
||||
|
||||
try af.file_writer.interface.writeAll(fmt.out_buffer.written());
|
||||
|
|
|
|||
|
|
@ -3,10 +3,9 @@ const build_options = @import("build_options");
|
|||
|
||||
const std = @import("std");
|
||||
const Io = std.Io;
|
||||
const Dir = std.Io.Dir;
|
||||
const mem = std.mem;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const os = std.os;
|
||||
const fs = std.fs;
|
||||
const Cache = std.Build.Cache;
|
||||
|
||||
const Compilation = @import("Compilation.zig");
|
||||
|
|
@ -16,11 +15,11 @@ const Package = @import("Package.zig");
|
|||
/// The path of the returned Directory is relative to `base`.
|
||||
/// The handle of the returned Directory is open.
|
||||
fn testZigInstallPrefix(io: Io, base_dir: Io.Dir) ?Cache.Directory {
|
||||
const test_index_file = "std" ++ fs.path.sep_str ++ "std.zig";
|
||||
const test_index_file = "std" ++ Dir.path.sep_str ++ "std.zig";
|
||||
|
||||
zig_dir: {
|
||||
// Try lib/zig/std/std.zig
|
||||
const lib_zig = "lib" ++ fs.path.sep_str ++ "zig";
|
||||
const lib_zig = "lib" ++ Dir.path.sep_str ++ "zig";
|
||||
var test_zig_dir = base_dir.openDir(io, lib_zig, .{}) catch break :zig_dir;
|
||||
const file = test_zig_dir.openFile(io, test_index_file, .{}) catch {
|
||||
test_zig_dir.close(io);
|
||||
|
|
@ -44,13 +43,13 @@ fn testZigInstallPrefix(io: Io, base_dir: Io.Dir) ?Cache.Directory {
|
|||
pub fn findZigLibDir(gpa: Allocator, io: Io) !Cache.Directory {
|
||||
const cwd_path = try getResolvedCwd(gpa);
|
||||
defer gpa.free(cwd_path);
|
||||
const self_exe_path = try fs.selfExePathAlloc(gpa);
|
||||
const self_exe_path = try std.process.executablePathAlloc(io, gpa);
|
||||
defer gpa.free(self_exe_path);
|
||||
|
||||
return findZigLibDirFromSelfExe(gpa, io, cwd_path, self_exe_path);
|
||||
}
|
||||
|
||||
/// Like `std.process.getCwdAlloc`, but also resolves the path with `std.fs.path.resolve`. This
|
||||
/// Like `std.process.getCwdAlloc`, but also resolves the path with `Dir.path.resolve`. This
|
||||
/// means the path has no repeated separators, no "." or ".." components, and no trailing separator.
|
||||
/// On WASI, "" is returned instead of ".".
|
||||
pub fn getResolvedCwd(gpa: Allocator) error{
|
||||
|
|
@ -68,8 +67,8 @@ pub fn getResolvedCwd(gpa: Allocator) error{
|
|||
}
|
||||
const cwd = try std.process.getCwdAlloc(gpa);
|
||||
defer gpa.free(cwd);
|
||||
const resolved = try fs.path.resolve(gpa, &.{cwd});
|
||||
std.debug.assert(fs.path.isAbsolute(resolved));
|
||||
const resolved = try Dir.path.resolve(gpa, &.{cwd});
|
||||
std.debug.assert(Dir.path.isAbsolute(resolved));
|
||||
return resolved;
|
||||
}
|
||||
|
||||
|
|
@ -84,12 +83,12 @@ pub fn findZigLibDirFromSelfExe(
|
|||
) error{ OutOfMemory, FileNotFound }!Cache.Directory {
|
||||
const cwd = Io.Dir.cwd();
|
||||
var cur_path: []const u8 = self_exe_path;
|
||||
while (fs.path.dirname(cur_path)) |dirname| : (cur_path = dirname) {
|
||||
while (Dir.path.dirname(cur_path)) |dirname| : (cur_path = dirname) {
|
||||
var base_dir = cwd.openDir(io, dirname, .{}) catch continue;
|
||||
defer base_dir.close(io);
|
||||
|
||||
const sub_directory = testZigInstallPrefix(io, base_dir) orelse continue;
|
||||
const p = try fs.path.join(allocator, &.{ dirname, sub_directory.path.? });
|
||||
const p = try Dir.path.join(allocator, &.{ dirname, sub_directory.path.? });
|
||||
defer allocator.free(p);
|
||||
|
||||
const resolved = try resolvePath(allocator, cwd_path, &.{p});
|
||||
|
|
@ -113,18 +112,18 @@ pub fn resolveGlobalCacheDir(allocator: Allocator) ![]u8 {
|
|||
if (builtin.os.tag != .windows) {
|
||||
if (std.zig.EnvVar.XDG_CACHE_HOME.getPosix()) |cache_root| {
|
||||
if (cache_root.len > 0) {
|
||||
return fs.path.join(allocator, &.{ cache_root, appname });
|
||||
return Dir.path.join(allocator, &.{ cache_root, appname });
|
||||
}
|
||||
}
|
||||
if (std.zig.EnvVar.HOME.getPosix()) |home| {
|
||||
return fs.path.join(allocator, &.{ home, ".cache", appname });
|
||||
return Dir.path.join(allocator, &.{ home, ".cache", appname });
|
||||
}
|
||||
}
|
||||
|
||||
return fs.getAppDataDir(allocator, appname);
|
||||
return std.fs.getAppDataDir(allocator, appname);
|
||||
}
|
||||
|
||||
/// Similar to `fs.path.resolve`, but converts to a cwd-relative path, or, if that would
|
||||
/// Similar to `Dir.path.resolve`, but converts to a cwd-relative path, or, if that would
|
||||
/// start with a relative up-dir (".."), an absolute path based on the cwd. Also, the cwd
|
||||
/// returns the empty string ("") instead of ".".
|
||||
pub fn resolvePath(
|
||||
|
|
@ -136,7 +135,7 @@ pub fn resolvePath(
|
|||
) Allocator.Error![]u8 {
|
||||
if (builtin.target.os.tag == .wasi) {
|
||||
std.debug.assert(mem.eql(u8, cwd_resolved, ""));
|
||||
const res = try fs.path.resolve(gpa, paths);
|
||||
const res = try Dir.path.resolve(gpa, paths);
|
||||
if (mem.eql(u8, res, ".")) {
|
||||
gpa.free(res);
|
||||
return "";
|
||||
|
|
@ -146,16 +145,16 @@ pub fn resolvePath(
|
|||
|
||||
// Heuristic for a fast path: if no component is absolute and ".." never appears, we just need to resolve `paths`.
|
||||
for (paths) |p| {
|
||||
if (fs.path.isAbsolute(p)) break; // absolute path
|
||||
if (Dir.path.isAbsolute(p)) break; // absolute path
|
||||
if (mem.indexOf(u8, p, "..") != null) break; // may contain up-dir
|
||||
} else {
|
||||
// no absolute path, no "..".
|
||||
const res = try fs.path.resolve(gpa, paths);
|
||||
const res = try Dir.path.resolve(gpa, paths);
|
||||
if (mem.eql(u8, res, ".")) {
|
||||
gpa.free(res);
|
||||
return "";
|
||||
}
|
||||
std.debug.assert(!fs.path.isAbsolute(res));
|
||||
std.debug.assert(!Dir.path.isAbsolute(res));
|
||||
std.debug.assert(!isUpDir(res));
|
||||
return res;
|
||||
}
|
||||
|
|
@ -164,19 +163,19 @@ pub fn resolvePath(
|
|||
// Optimization: `paths` often has just one element.
|
||||
const path_resolved = switch (paths.len) {
|
||||
0 => unreachable,
|
||||
1 => try fs.path.resolve(gpa, &.{ cwd_resolved, paths[0] }),
|
||||
1 => try Dir.path.resolve(gpa, &.{ cwd_resolved, paths[0] }),
|
||||
else => r: {
|
||||
const all_paths = try gpa.alloc([]const u8, paths.len + 1);
|
||||
defer gpa.free(all_paths);
|
||||
all_paths[0] = cwd_resolved;
|
||||
@memcpy(all_paths[1..], paths);
|
||||
break :r try fs.path.resolve(gpa, all_paths);
|
||||
break :r try Dir.path.resolve(gpa, all_paths);
|
||||
},
|
||||
};
|
||||
errdefer gpa.free(path_resolved);
|
||||
|
||||
std.debug.assert(fs.path.isAbsolute(path_resolved));
|
||||
std.debug.assert(fs.path.isAbsolute(cwd_resolved));
|
||||
std.debug.assert(Dir.path.isAbsolute(path_resolved));
|
||||
std.debug.assert(Dir.path.isAbsolute(cwd_resolved));
|
||||
|
||||
if (!std.mem.startsWith(u8, path_resolved, cwd_resolved)) return path_resolved; // not in cwd
|
||||
if (path_resolved.len == cwd_resolved.len) {
|
||||
|
|
@ -184,7 +183,7 @@ pub fn resolvePath(
|
|||
gpa.free(path_resolved);
|
||||
return "";
|
||||
}
|
||||
if (path_resolved[cwd_resolved.len] != std.fs.path.sep) return path_resolved; // not in cwd (last component differs)
|
||||
if (path_resolved[cwd_resolved.len] != Dir.path.sep) return path_resolved; // not in cwd (last component differs)
|
||||
|
||||
// in cwd; extract sub path
|
||||
const sub_path = try gpa.dupe(u8, path_resolved[cwd_resolved.len + 1 ..]);
|
||||
|
|
@ -192,9 +191,8 @@ pub fn resolvePath(
|
|||
return sub_path;
|
||||
}
|
||||
|
||||
/// TODO move this to std.fs.path
|
||||
pub fn isUpDir(p: []const u8) bool {
|
||||
return mem.startsWith(u8, p, "..") and (p.len == 2 or p[2] == fs.path.sep);
|
||||
return mem.startsWith(u8, p, "..") and (p.len == 2 or p[2] == Dir.path.sep);
|
||||
}
|
||||
|
||||
pub const default_local_zig_cache_basename = ".zig-cache";
|
||||
|
|
@ -205,12 +203,12 @@ pub const default_local_zig_cache_basename = ".zig-cache";
|
|||
pub fn resolveSuitableLocalCacheDir(arena: Allocator, io: Io, cwd: []const u8) Allocator.Error!?[]u8 {
|
||||
var cur_dir = cwd;
|
||||
while (true) {
|
||||
const joined = try fs.path.join(arena, &.{ cur_dir, Package.build_zig_basename });
|
||||
const joined = try Dir.path.join(arena, &.{ cur_dir, Package.build_zig_basename });
|
||||
if (Io.Dir.cwd().access(io, joined, .{})) |_| {
|
||||
return try fs.path.join(arena, &.{ cur_dir, default_local_zig_cache_basename });
|
||||
return try Dir.path.join(arena, &.{ cur_dir, default_local_zig_cache_basename });
|
||||
} else |err| switch (err) {
|
||||
error.FileNotFound => {
|
||||
cur_dir = fs.path.dirname(cur_dir) orelse return null;
|
||||
cur_dir = Dir.path.dirname(cur_dir) orelse return null;
|
||||
continue;
|
||||
},
|
||||
else => return null,
|
||||
|
|
|
|||
|
|
@ -444,7 +444,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
|
|||
var cache: Cache = .{
|
||||
.gpa = gpa,
|
||||
.io = io,
|
||||
.manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath("h", .{}),
|
||||
.manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath(io, "h", .{}),
|
||||
};
|
||||
cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
|
||||
cache.addPrefix(comp.dirs.zig_lib);
|
||||
|
|
@ -477,7 +477,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
|
|||
const o_sub_path = try path.join(arena, &[_][]const u8{ "o", &digest });
|
||||
|
||||
var o_directory: Cache.Directory = .{
|
||||
.handle = try comp.dirs.global_cache.handle.makeOpenPath(o_sub_path, .{}),
|
||||
.handle = try comp.dirs.global_cache.handle.makeOpenPath(io, o_sub_path, .{}),
|
||||
.path = try comp.dirs.global_cache.join(arena, &.{o_sub_path}),
|
||||
};
|
||||
defer o_directory.handle.close(io);
|
||||
|
|
|
|||
|
|
@ -679,7 +679,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
|
|||
var cache: Cache = .{
|
||||
.gpa = gpa,
|
||||
.io = io,
|
||||
.manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath("h", .{}),
|
||||
.manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath(io, "h", .{}),
|
||||
};
|
||||
cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
|
||||
cache.addPrefix(comp.dirs.zig_lib);
|
||||
|
|
@ -712,7 +712,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
|
|||
const o_sub_path = try path.join(arena, &[_][]const u8{ "o", &digest });
|
||||
|
||||
var o_directory: Cache.Directory = .{
|
||||
.handle = try comp.dirs.global_cache.handle.makeOpenPath(o_sub_path, .{}),
|
||||
.handle = try comp.dirs.global_cache.handle.makeOpenPath(io, o_sub_path, .{}),
|
||||
.path = try comp.dirs.global_cache.join(arena, &.{o_sub_path}),
|
||||
};
|
||||
defer o_directory.handle.close(io);
|
||||
|
|
|
|||
|
|
@ -258,7 +258,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
|
|||
var cache: Cache = .{
|
||||
.gpa = gpa,
|
||||
.io = io,
|
||||
.manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath("h", .{}),
|
||||
.manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath(io, "h", .{}),
|
||||
};
|
||||
cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
|
||||
cache.addPrefix(comp.dirs.zig_lib);
|
||||
|
|
@ -297,7 +297,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
|
|||
|
||||
const digest = man.final();
|
||||
const o_sub_path = try std.fs.path.join(arena, &[_][]const u8{ "o", &digest });
|
||||
var o_dir = try comp.dirs.global_cache.handle.makeOpenPath(o_sub_path, .{});
|
||||
var o_dir = try comp.dirs.global_cache.handle.makeOpenPath(io, o_sub_path, .{});
|
||||
defer o_dir.close(io);
|
||||
|
||||
const aro = @import("aro");
|
||||
|
|
|
|||
|
|
@ -385,7 +385,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
|
|||
var cache: Cache = .{
|
||||
.gpa = gpa,
|
||||
.io = io,
|
||||
.manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath("h", .{}),
|
||||
.manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath(io, "h", .{}),
|
||||
};
|
||||
cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
|
||||
cache.addPrefix(comp.dirs.zig_lib);
|
||||
|
|
@ -418,7 +418,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
|
|||
const o_sub_path = try path.join(arena, &[_][]const u8{ "o", &digest });
|
||||
|
||||
var o_directory: Cache.Directory = .{
|
||||
.handle = try comp.dirs.global_cache.handle.makeOpenPath(o_sub_path, .{}),
|
||||
.handle = try comp.dirs.global_cache.handle.makeOpenPath(io, o_sub_path, .{}),
|
||||
.path = try comp.dirs.global_cache.join(arena, &.{o_sub_path}),
|
||||
};
|
||||
defer o_directory.handle.close(io);
|
||||
|
|
|
|||
15
src/link.zig
15
src/link.zig
|
|
@ -2170,28 +2170,27 @@ fn resolvePathInputLib(
|
|||
}) {
|
||||
var file = test_path.root_dir.handle.openFile(io, test_path.sub_path, .{}) catch |err| switch (err) {
|
||||
error.FileNotFound => return .no_match,
|
||||
else => |e| fatal("unable to search for {s} library '{f}': {s}", .{
|
||||
@tagName(link_mode), std.fmt.alt(test_path, .formatEscapeChar), @errorName(e),
|
||||
else => |e| fatal("unable to search for {t} library '{f}': {t}", .{
|
||||
link_mode, std.fmt.alt(test_path, .formatEscapeChar), e,
|
||||
}),
|
||||
};
|
||||
errdefer file.close(io);
|
||||
try ld_script_bytes.resize(gpa, @max(std.elf.MAGIC.len, std.elf.ARMAG.len));
|
||||
const n = file.preadAll(ld_script_bytes.items, 0) catch |err| fatal("failed to read '{f}': {s}", .{
|
||||
std.fmt.alt(test_path, .formatEscapeChar), @errorName(err),
|
||||
});
|
||||
const n = file.readPositionalAll(io, ld_script_bytes.items, 0) catch |err|
|
||||
fatal("failed to read '{f}': {t}", .{ std.fmt.alt(test_path, .formatEscapeChar), err });
|
||||
const buf = ld_script_bytes.items[0..n];
|
||||
if (mem.startsWith(u8, buf, std.elf.MAGIC) or mem.startsWith(u8, buf, std.elf.ARMAG)) {
|
||||
// Appears to be an ELF or archive file.
|
||||
return finishResolveLibInput(resolved_inputs, test_path, file, link_mode, pq.query);
|
||||
}
|
||||
const stat = file.stat(io) catch |err|
|
||||
fatal("failed to stat {f}: {s}", .{ test_path, @errorName(err) });
|
||||
fatal("failed to stat {f}: {t}", .{ test_path, err });
|
||||
const size = std.math.cast(u32, stat.size) orelse
|
||||
fatal("{f}: linker script too big", .{test_path});
|
||||
try ld_script_bytes.resize(gpa, size);
|
||||
const buf2 = ld_script_bytes.items[n..];
|
||||
const n2 = file.preadAll(buf2, n) catch |err|
|
||||
fatal("failed to read {f}: {s}", .{ test_path, @errorName(err) });
|
||||
const n2 = file.readPositionalAll(io, buf2, n) catch |err|
|
||||
fatal("failed to read {f}: {t}", .{ test_path, err });
|
||||
if (n2 != buf2.len) fatal("failed to read {f}: unexpected end of file", .{test_path});
|
||||
|
||||
// This `Io` is only used for a mutex, and we know we aren't doing anything async/concurrent.
|
||||
|
|
|
|||
|
|
@ -636,7 +636,7 @@ fn create(
|
|||
const coff = try arena.create(Coff);
|
||||
const file = try path.root_dir.handle.createFile(io, path.sub_path, .{
|
||||
.read = true,
|
||||
.mode = link.File.determineMode(comp.config.output_mode, comp.config.link_mode),
|
||||
.permissions = link.File.determinePermissions(comp.config.output_mode, comp.config.link_mode),
|
||||
});
|
||||
errdefer file.close(io);
|
||||
coff.* = .{
|
||||
|
|
@ -653,7 +653,7 @@ fn create(
|
|||
.allow_shlib_undefined = false,
|
||||
.stack_size = 0,
|
||||
},
|
||||
.mf = try .init(file, comp.gpa),
|
||||
.mf = try .init(file, comp.gpa, io),
|
||||
.nodes = .empty,
|
||||
.import_table = .{
|
||||
.ni = .none,
|
||||
|
|
|
|||
|
|
@ -52,7 +52,6 @@ pub const UpdateError = error{
|
|||
codegen.GenerateSymbolError ||
|
||||
Io.File.OpenError ||
|
||||
Io.File.LengthError ||
|
||||
Io.File.CopyRangeError ||
|
||||
Io.File.ReadPositionalError ||
|
||||
Io.File.WritePositionalError;
|
||||
|
||||
|
|
|
|||
|
|
@ -320,7 +320,7 @@ pub fn createEmpty(
|
|||
self.base.file = try emit.root_dir.handle.createFile(io, sub_path, .{
|
||||
.truncate = true,
|
||||
.read = true,
|
||||
.mode = link.File.determineMode(output_mode, link_mode),
|
||||
.permissions = link.File.determinePermissions(output_mode, link_mode),
|
||||
});
|
||||
|
||||
const gpa = comp.gpa;
|
||||
|
|
|
|||
|
|
@ -976,7 +976,7 @@ fn create(
|
|||
const elf = try arena.create(Elf);
|
||||
const file = try path.root_dir.handle.createFile(io, path.sub_path, .{
|
||||
.read = true,
|
||||
.mode = link.File.determineMode(comp.config.output_mode, comp.config.link_mode),
|
||||
.permissions = link.File.determinePermissions(comp.config.output_mode, comp.config.link_mode),
|
||||
});
|
||||
errdefer file.close(io);
|
||||
elf.* = .{
|
||||
|
|
@ -994,7 +994,7 @@ fn create(
|
|||
.stack_size = 0,
|
||||
},
|
||||
.options = options,
|
||||
.mf = try .init(file, comp.gpa),
|
||||
.mf = try .init(file, comp.gpa, io),
|
||||
.ni = .{
|
||||
.tls = .none,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -224,7 +224,7 @@ pub fn createEmpty(
|
|||
self.base.file = try emit.root_dir.handle.createFile(io, emit.sub_path, .{
|
||||
.truncate = true,
|
||||
.read = true,
|
||||
.mode = link.File.determineMode(output_mode, link_mode),
|
||||
.permissions = link.File.determinePermissions(output_mode, link_mode),
|
||||
});
|
||||
|
||||
// Append null file
|
||||
|
|
@ -3157,7 +3157,9 @@ fn detectAllocCollision(self: *MachO, start: u64, size: u64) !?u64 {
|
|||
}
|
||||
}
|
||||
|
||||
if (at_end) try self.base.file.?.setEndPos(end);
|
||||
const comp = self.base.comp;
|
||||
const io = comp.io;
|
||||
if (at_end) try self.base.file.?.setLength(io, end);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -3292,7 +3294,7 @@ pub fn reopenDebugInfo(self: *MachO) !void {
|
|||
);
|
||||
defer gpa.free(d_sym_path);
|
||||
|
||||
var d_sym_bundle = try self.base.emit.root_dir.handle.makeOpenPath(d_sym_path, .{});
|
||||
var d_sym_bundle = try self.base.emit.root_dir.handle.makeOpenPath(io, d_sym_path, .{});
|
||||
defer d_sym_bundle.close(io);
|
||||
|
||||
self.d_sym.?.file = try d_sym_bundle.createFile(io, fs.path.basename(self.base.emit.sub_path), .{
|
||||
|
|
@ -3303,6 +3305,10 @@ pub fn reopenDebugInfo(self: *MachO) !void {
|
|||
|
||||
// TODO: move to ZigObject
|
||||
fn initMetadata(self: *MachO, options: InitMetadataOptions) !void {
|
||||
const comp = self.base.comp;
|
||||
const gpa = comp.gpa;
|
||||
const io = comp.io;
|
||||
|
||||
if (!self.base.isRelocatable()) {
|
||||
const base_vmaddr = blk: {
|
||||
const pagezero_size = self.pagezero_size orelse default_pagezero_size;
|
||||
|
|
@ -3357,7 +3363,11 @@ fn initMetadata(self: *MachO, options: InitMetadataOptions) !void {
|
|||
if (options.zo.dwarf) |*dwarf| {
|
||||
// Create dSYM bundle.
|
||||
log.debug("creating {s}.dSYM bundle", .{options.emit.sub_path});
|
||||
self.d_sym = .{ .allocator = self.base.comp.gpa, .file = null };
|
||||
self.d_sym = .{
|
||||
.io = io,
|
||||
.allocator = gpa,
|
||||
.file = null,
|
||||
};
|
||||
try self.reopenDebugInfo();
|
||||
try self.d_sym.?.initMetadata(self);
|
||||
try dwarf.initMetadata();
|
||||
|
|
@ -3477,6 +3487,9 @@ fn growSectionNonRelocatable(self: *MachO, sect_index: u8, needed_size: u64) !vo
|
|||
const seg_id = self.sections.items(.segment_id)[sect_index];
|
||||
const seg = &self.segments.items[seg_id];
|
||||
|
||||
const comp = self.base.comp;
|
||||
const io = comp.io;
|
||||
|
||||
if (!sect.isZerofill()) {
|
||||
const allocated_size = self.allocatedSize(sect.offset);
|
||||
if (needed_size > allocated_size) {
|
||||
|
|
@ -3498,7 +3511,7 @@ fn growSectionNonRelocatable(self: *MachO, sect_index: u8, needed_size: u64) !vo
|
|||
|
||||
sect.offset = @intCast(new_offset);
|
||||
} else if (sect.offset + allocated_size == std.math.maxInt(u64)) {
|
||||
try self.base.file.?.setEndPos(sect.offset + needed_size);
|
||||
try self.base.file.?.setLength(io, sect.offset + needed_size);
|
||||
}
|
||||
seg.filesize = needed_size;
|
||||
}
|
||||
|
|
@ -3520,6 +3533,8 @@ fn growSectionNonRelocatable(self: *MachO, sect_index: u8, needed_size: u64) !vo
|
|||
}
|
||||
|
||||
fn growSectionRelocatable(self: *MachO, sect_index: u8, needed_size: u64) !void {
|
||||
const comp = self.base.comp;
|
||||
const io = comp.io;
|
||||
const sect = &self.sections.items(.header)[sect_index];
|
||||
|
||||
if (!sect.isZerofill()) {
|
||||
|
|
@ -3547,7 +3562,7 @@ fn growSectionRelocatable(self: *MachO, sect_index: u8, needed_size: u64) !void
|
|||
sect.offset = @intCast(new_offset);
|
||||
sect.addr = new_addr;
|
||||
} else if (sect.offset + allocated_size == std.math.maxInt(u64)) {
|
||||
try self.base.file.?.setEndPos(sect.offset + needed_size);
|
||||
try self.base.file.?.setLength(io, sect.offset + needed_size);
|
||||
}
|
||||
}
|
||||
sect.size = needed_size;
|
||||
|
|
@ -5346,12 +5361,12 @@ pub fn pwriteAll(macho_file: *MachO, bytes: []const u8, offset: u64) error{LinkF
|
|||
};
|
||||
}
|
||||
|
||||
pub fn setEndPos(macho_file: *MachO, length: u64) error{LinkFailure}!void {
|
||||
pub fn setLength(macho_file: *MachO, length: u64) error{LinkFailure}!void {
|
||||
const comp = macho_file.base.comp;
|
||||
const io = comp.io;
|
||||
const diags = &comp.link_diags;
|
||||
macho_file.base.file.?.setEndPos(length) catch |err| {
|
||||
return diags.fail("failed to set file end pos: {s}", .{@errorName(err)});
|
||||
};
|
||||
macho_file.base.file.?.setLength(io, length) catch |err|
|
||||
return diags.fail("failed to set file end pos: {t}", .{err});
|
||||
}
|
||||
|
||||
pub fn cast(macho_file: *MachO, comptime T: type, x: anytype) error{LinkFailure}!T {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ const assert = std.debug.assert;
|
|||
const linux = std.os.linux;
|
||||
const windows = std.os.windows;
|
||||
|
||||
io: Io,
|
||||
file: std.Io.File,
|
||||
flags: packed struct {
|
||||
block_size: std.mem.Alignment,
|
||||
|
|
@ -36,8 +37,9 @@ pub const Error = std.posix.MMapError || std.posix.MRemapError || Io.File.Length
|
|||
NoSpaceLeft,
|
||||
};
|
||||
|
||||
pub fn init(file: std.Io.File, gpa: std.mem.Allocator) !MappedFile {
|
||||
pub fn init(file: std.Io.File, gpa: std.mem.Allocator, io: Io) !MappedFile {
|
||||
var mf: MappedFile = .{
|
||||
.io = io,
|
||||
.file = file,
|
||||
.flags = undefined,
|
||||
.section = if (is_windows) windows.INVALID_HANDLE_VALUE else {},
|
||||
|
|
@ -624,13 +626,14 @@ pub fn addNodeAfter(
|
|||
}
|
||||
|
||||
fn resizeNode(mf: *MappedFile, gpa: std.mem.Allocator, ni: Node.Index, requested_size: u64) !void {
|
||||
const io = mf.io;
|
||||
const node = ni.get(mf);
|
||||
const old_offset, const old_size = node.location().resolve(mf);
|
||||
const new_size = node.flags.alignment.forward(@intCast(requested_size));
|
||||
// Resize the entire file
|
||||
if (ni == Node.Index.root) {
|
||||
try mf.ensureCapacityForSetLocation(gpa);
|
||||
try mf.file.setEndPos(new_size);
|
||||
try mf.file.setLength(io, new_size);
|
||||
try mf.ensureTotalCapacity(@intCast(new_size));
|
||||
ni.setLocationAssumeCapacity(mf, old_offset, new_size);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -3002,11 +3002,11 @@ pub fn createEmpty(
|
|||
wasm.base.file = try emit.root_dir.handle.createFile(io, emit.sub_path, .{
|
||||
.truncate = true,
|
||||
.read = true,
|
||||
.mode = if (Io.File.Permissions.has_executable_bit)
|
||||
.permissions = if (Io.File.Permissions.has_executable_bit)
|
||||
if (target.os.tag == .wasi and output_mode == .Exe)
|
||||
Io.File.default_mode | 0b001_000_000
|
||||
.executable_file
|
||||
else
|
||||
Io.File.default_mode
|
||||
.default_file
|
||||
else
|
||||
0,
|
||||
});
|
||||
|
|
|
|||
155
src/main.zig
155
src/main.zig
|
|
@ -335,19 +335,20 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
|
|||
} else if (mem.eql(u8, cmd, "targets")) {
|
||||
dev.check(.targets_command);
|
||||
const host = std.zig.resolveTargetQueryOrFatal(io, .{});
|
||||
var stdout_writer = Io.File.stdout().writer(&stdout_buffer);
|
||||
var stdout_writer = Io.File.stdout().writer(io, &stdout_buffer);
|
||||
try @import("print_targets.zig").cmdTargets(arena, io, cmd_args, &stdout_writer.interface, &host);
|
||||
return stdout_writer.interface.flush();
|
||||
} else if (mem.eql(u8, cmd, "version")) {
|
||||
dev.check(.version_command);
|
||||
try Io.File.stdout().writeAll(build_options.version ++ "\n");
|
||||
try Io.File.stdout().writeStreamingAll(io, build_options.version ++ "\n");
|
||||
return;
|
||||
} else if (mem.eql(u8, cmd, "env")) {
|
||||
dev.check(.env_command);
|
||||
const host = std.zig.resolveTargetQueryOrFatal(io, .{});
|
||||
var stdout_writer = Io.File.stdout().writer(&stdout_buffer);
|
||||
var stdout_writer = Io.File.stdout().writer(io, &stdout_buffer);
|
||||
try @import("print_env.zig").cmdEnv(
|
||||
arena,
|
||||
io,
|
||||
&stdout_writer.interface,
|
||||
args,
|
||||
if (native_os == .wasi) wasi_preopens,
|
||||
|
|
@ -361,10 +362,10 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
|
|||
});
|
||||
} else if (mem.eql(u8, cmd, "zen")) {
|
||||
dev.check(.zen_command);
|
||||
return Io.File.stdout().writeAll(info_zen);
|
||||
return Io.File.stdout().writeStreamingAll(io, info_zen);
|
||||
} else if (mem.eql(u8, cmd, "help") or mem.eql(u8, cmd, "-h") or mem.eql(u8, cmd, "--help")) {
|
||||
dev.check(.help_command);
|
||||
return Io.File.stdout().writeAll(usage);
|
||||
return Io.File.stdout().writeStreamingAll(io, usage);
|
||||
} else if (mem.eql(u8, cmd, "ast-check")) {
|
||||
return cmdAstCheck(arena, io, cmd_args);
|
||||
} else if (mem.eql(u8, cmd, "detect-cpu")) {
|
||||
|
|
@ -374,7 +375,7 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
|
|||
} else if (build_options.enable_debug_extensions and mem.eql(u8, cmd, "dump-zir")) {
|
||||
return cmdDumpZir(arena, io, cmd_args);
|
||||
} else if (build_options.enable_debug_extensions and mem.eql(u8, cmd, "llvm-ints")) {
|
||||
return cmdDumpLlvmInts(gpa, arena, cmd_args);
|
||||
return cmdDumpLlvmInts(gpa, arena, io, cmd_args);
|
||||
} else {
|
||||
std.log.info("{s}", .{usage});
|
||||
fatal("unknown command: {s}", .{args[1]});
|
||||
|
|
@ -701,7 +702,7 @@ const Emit = union(enum) {
|
|||
yes: []const u8,
|
||||
|
||||
const OutputToCacheReason = enum { listen, @"zig run", @"zig test" };
|
||||
fn resolve(io: Io, emit: Emit, default_basename: []const u8, output_to_cache: ?OutputToCacheReason) Compilation.CreateOptions.Emit {
|
||||
fn resolve(emit: Emit, io: Io, default_basename: []const u8, output_to_cache: ?OutputToCacheReason) Compilation.CreateOptions.Emit {
|
||||
return switch (emit) {
|
||||
.no => .no,
|
||||
.yes_default_path => if (output_to_cache != null) .yes_cache else .{ .yes_path = default_basename },
|
||||
|
|
@ -1036,7 +1037,7 @@ fn buildOutputType(
|
|||
fatal("unable to read response file '{s}': {t}", .{ resp_file_path, err });
|
||||
} else if (mem.startsWith(u8, arg, "-")) {
|
||||
if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
|
||||
try Io.File.stdout().writeAll(usage_build_generic);
|
||||
try Io.File.stdout().writeStreamingAll(io, usage_build_generic);
|
||||
return cleanExit();
|
||||
} else if (mem.eql(u8, arg, "--")) {
|
||||
if (arg_mode == .run) {
|
||||
|
|
@ -1858,9 +1859,7 @@ fn buildOutputType(
|
|||
var must_link = false;
|
||||
var file_ext: ?Compilation.FileExt = null;
|
||||
while (it.has_next) {
|
||||
it.next() catch |err| {
|
||||
fatal("unable to parse command line parameters: {s}", .{@errorName(err)});
|
||||
};
|
||||
it.next(io) catch |err| fatal("unable to parse command line parameters: {t}", .{err});
|
||||
switch (it.zig_equivalent) {
|
||||
.target => target_arch_os_abi = it.only_arg, // example: -target riscv64-linux-unknown
|
||||
.o => {
|
||||
|
|
@ -2836,9 +2835,9 @@ fn buildOutputType(
|
|||
} else if (mem.eql(u8, arg, "-V")) {
|
||||
warn("ignoring request for supported emulations: unimplemented", .{});
|
||||
} else if (mem.eql(u8, arg, "-v")) {
|
||||
try Io.File.stdout().writeAll("zig ld " ++ build_options.version ++ "\n");
|
||||
try Io.File.stdout().writeStreamingAll(io, "zig ld " ++ build_options.version ++ "\n");
|
||||
} else if (mem.eql(u8, arg, "--version")) {
|
||||
try Io.File.stdout().writeAll("zig ld " ++ build_options.version ++ "\n");
|
||||
try Io.File.stdout().writeStreamingAll(io, "zig ld " ++ build_options.version ++ "\n");
|
||||
process.exit(0);
|
||||
} else {
|
||||
fatal("unsupported linker arg: {s}", .{arg});
|
||||
|
|
@ -3077,14 +3076,13 @@ fn buildOutputType(
|
|||
|
||||
const self_exe_path = switch (native_os) {
|
||||
.wasi => {},
|
||||
else => fs.selfExePathAlloc(arena) catch |err| {
|
||||
fatal("unable to find zig self exe path: {s}", .{@errorName(err)});
|
||||
},
|
||||
else => process.executablePathAlloc(io, arena) catch |err| fatal("unable to find zig self exe path: {t}", .{err}),
|
||||
};
|
||||
|
||||
// This `init` calls `fatal` on error.
|
||||
var dirs: Compilation.Directories = .init(
|
||||
arena,
|
||||
io,
|
||||
override_lib_dir,
|
||||
override_global_cache_dir,
|
||||
s: {
|
||||
|
|
@ -3097,11 +3095,9 @@ fn buildOutputType(
|
|||
if (native_os == .wasi) wasi_preopens,
|
||||
self_exe_path,
|
||||
);
|
||||
defer dirs.deinit();
|
||||
defer dirs.deinit(io);
|
||||
|
||||
if (linker_optimization) |o| {
|
||||
warn("ignoring deprecated linker optimization setting '{s}'", .{o});
|
||||
}
|
||||
if (linker_optimization) |o| warn("ignoring deprecated linker optimization setting '{s}'", .{o});
|
||||
|
||||
create_module.dirs = dirs;
|
||||
create_module.opts.emit_llvm_ir = emit_llvm_ir != .no;
|
||||
|
|
@ -3324,18 +3320,18 @@ fn buildOutputType(
|
|||
};
|
||||
|
||||
const default_h_basename = try std.fmt.allocPrint(arena, "{s}.h", .{root_name});
|
||||
const emit_h_resolved = emit_h.resolve(default_h_basename, output_to_cache);
|
||||
const emit_h_resolved = emit_h.resolve(io, default_h_basename, output_to_cache);
|
||||
|
||||
const default_asm_basename = try std.fmt.allocPrint(arena, "{s}.s", .{root_name});
|
||||
const emit_asm_resolved = emit_asm.resolve(default_asm_basename, output_to_cache);
|
||||
const emit_asm_resolved = emit_asm.resolve(io, default_asm_basename, output_to_cache);
|
||||
|
||||
const default_llvm_ir_basename = try std.fmt.allocPrint(arena, "{s}.ll", .{root_name});
|
||||
const emit_llvm_ir_resolved = emit_llvm_ir.resolve(default_llvm_ir_basename, output_to_cache);
|
||||
const emit_llvm_ir_resolved = emit_llvm_ir.resolve(io, default_llvm_ir_basename, output_to_cache);
|
||||
|
||||
const default_llvm_bc_basename = try std.fmt.allocPrint(arena, "{s}.bc", .{root_name});
|
||||
const emit_llvm_bc_resolved = emit_llvm_bc.resolve(default_llvm_bc_basename, output_to_cache);
|
||||
const emit_llvm_bc_resolved = emit_llvm_bc.resolve(io, default_llvm_bc_basename, output_to_cache);
|
||||
|
||||
const emit_docs_resolved = emit_docs.resolve("docs", output_to_cache);
|
||||
const emit_docs_resolved = emit_docs.resolve(io, "docs", output_to_cache);
|
||||
|
||||
const is_exe_or_dyn_lib = switch (create_module.resolved_options.output_mode) {
|
||||
.Obj => false,
|
||||
|
|
@ -3356,7 +3352,7 @@ fn buildOutputType(
|
|||
const default_implib_basename = try std.fmt.allocPrint(arena, "{s}.lib", .{root_name});
|
||||
const emit_implib_resolved: Compilation.CreateOptions.Emit = switch (emit_implib) {
|
||||
.no => .no,
|
||||
.yes => emit_implib.resolve(default_implib_basename, output_to_cache),
|
||||
.yes => emit_implib.resolve(io, default_implib_basename, output_to_cache),
|
||||
.yes_default_path => emit: {
|
||||
if (output_to_cache != null) break :emit .yes_cache;
|
||||
const p = try fs.path.join(arena, &.{
|
||||
|
|
@ -3399,7 +3395,7 @@ fn buildOutputType(
|
|||
// for the hashing algorithm here and in the cache are the same.
|
||||
// We are providing our own cache key, because this file has nothing
|
||||
// to do with the cache manifest.
|
||||
var file_writer = f.writer(&.{});
|
||||
var file_writer = f.writer(io, &.{});
|
||||
var buffer: [1000]u8 = undefined;
|
||||
var hasher = file_writer.interface.hashed(Cache.Hasher.init("0123456789abcdef"), &buffer);
|
||||
var stdin_reader = Io.File.stdin().readerStreaming(io, &.{});
|
||||
|
|
@ -3633,13 +3629,13 @@ fn buildOutputType(
|
|||
if (show_builtin) {
|
||||
const builtin_opts = comp.root_mod.getBuiltinOptions(comp.config);
|
||||
const source = try builtin_opts.generate(arena);
|
||||
return Io.File.stdout().writeAll(source);
|
||||
return Io.File.stdout().writeStreamingAll(io, source);
|
||||
}
|
||||
switch (listen) {
|
||||
.none => {},
|
||||
.stdio => {
|
||||
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);
|
||||
try serve(
|
||||
comp,
|
||||
&stdin_reader.interface,
|
||||
|
|
@ -3930,11 +3926,8 @@ fn createModule(
|
|||
}
|
||||
|
||||
if (target.isMinGW()) {
|
||||
const exists = mingw.libExists(arena, target, create_module.dirs.zig_lib, lib_name) catch |err| {
|
||||
fatal("failed to check zig installation for DLL import libs: {s}", .{
|
||||
@errorName(err),
|
||||
});
|
||||
};
|
||||
const exists = mingw.libExists(arena, io, target, create_module.dirs.zig_lib, lib_name) catch |err|
|
||||
fatal("failed to check zig installation for DLL import libs: {t}", .{err});
|
||||
if (exists) {
|
||||
try create_module.windows_libs.put(arena, lib_name, {});
|
||||
continue;
|
||||
|
|
@ -4009,11 +4002,8 @@ fn createModule(
|
|||
}
|
||||
|
||||
if (create_module.libc_paths_file) |paths_file| {
|
||||
create_module.libc_installation = LibCInstallation.parse(arena, paths_file, target) catch |err| {
|
||||
fatal("unable to parse libc paths file at path {s}: {s}", .{
|
||||
paths_file, @errorName(err),
|
||||
});
|
||||
};
|
||||
create_module.libc_installation = LibCInstallation.parse(arena, io, paths_file, target) catch |err|
|
||||
fatal("unable to parse libc paths file at path {s}: {t}", .{ paths_file, err });
|
||||
}
|
||||
|
||||
if (target.os.tag == .windows and (target.abi == .msvc or target.abi == .itanium) and
|
||||
|
|
@ -4024,7 +4014,7 @@ fn createModule(
|
|||
.verbose = true,
|
||||
.target = target,
|
||||
}) catch |err| {
|
||||
fatal("unable to find native libc installation: {s}", .{@errorName(err)});
|
||||
fatal("unable to find native libc installation: {t}", .{err});
|
||||
};
|
||||
}
|
||||
try create_module.lib_directories.ensureUnusedCapacity(arena, 2);
|
||||
|
|
@ -4163,7 +4153,7 @@ fn serve(
|
|||
|
||||
var child_pid: ?std.process.Child.Id = null;
|
||||
|
||||
const main_progress_node = std.Progress.start(.{});
|
||||
const main_progress_node = std.Progress.start(io, .{});
|
||||
const file_system_inputs = comp.file_system_inputs.?;
|
||||
|
||||
const IncrementalDebugServer = if (build_options.enable_debug_extensions and !builtin.single_threaded)
|
||||
|
|
@ -4694,7 +4684,7 @@ fn cmdTranslateC(
|
|||
});
|
||||
};
|
||||
defer zig_file.close(io);
|
||||
var stdout_writer = Io.File.stdout().writer(&stdout_buffer);
|
||||
var stdout_writer = Io.File.stdout().writer(io, &stdout_buffer);
|
||||
var file_reader = zig_file.reader(io, &.{});
|
||||
_ = try stdout_writer.interface.sendFileAll(&file_reader, .unlimited);
|
||||
try stdout_writer.interface.flush();
|
||||
|
|
@ -4744,7 +4734,7 @@ fn cmdInit(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
|
|||
if (mem.eql(u8, arg, "-m") or mem.eql(u8, arg, "--minimal")) {
|
||||
template = .minimal;
|
||||
} else if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
|
||||
try Io.File.stdout().writeAll(usage_init);
|
||||
try Io.File.stdout().writeStreamingAll(io, usage_init);
|
||||
return cleanExit();
|
||||
} else {
|
||||
fatal("unrecognized parameter: '{s}'", .{arg});
|
||||
|
|
@ -4764,7 +4754,7 @@ fn cmdInit(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
|
|||
switch (template) {
|
||||
.example => {
|
||||
var templates = findTemplates(gpa, arena, io);
|
||||
defer templates.deinit();
|
||||
defer templates.deinit(io);
|
||||
|
||||
const s = fs.path.sep_str;
|
||||
const template_paths = [_][]const u8{
|
||||
|
|
@ -4898,7 +4888,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
|
|||
const argv_index_exe = child_argv.items.len;
|
||||
_ = try child_argv.addOne();
|
||||
|
||||
const self_exe_path = try fs.selfExePathAlloc(arena);
|
||||
const self_exe_path = try process.executablePathAlloc(io, arena);
|
||||
try child_argv.append(self_exe_path);
|
||||
|
||||
const argv_index_zig_lib_dir = child_argv.items.len;
|
||||
|
|
@ -5079,7 +5069,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
|
|||
|
||||
const work_around_btrfs_bug = native_os == .linux and
|
||||
EnvVar.ZIG_BTRFS_WORKAROUND.isSet();
|
||||
const root_prog_node = std.Progress.start(.{
|
||||
const root_prog_node = std.Progress.start(io, .{
|
||||
.disable_printing = (color == .off),
|
||||
.root_name = "Compile Build Script",
|
||||
});
|
||||
|
|
@ -5114,7 +5104,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
|
|||
const paths_file = debug_libc_paths_file orelse break :lci null;
|
||||
if (!build_options.enable_debug_extensions) unreachable;
|
||||
const lci = try arena.create(LibCInstallation);
|
||||
lci.* = try .parse(arena, paths_file, &resolved_target.result);
|
||||
lci.* = try .parse(arena, io, paths_file, &resolved_target.result);
|
||||
break :lci lci;
|
||||
};
|
||||
|
||||
|
|
@ -5129,6 +5119,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
|
|||
// This `init` calls `fatal` on error.
|
||||
var dirs: Compilation.Directories = .init(
|
||||
arena,
|
||||
io,
|
||||
override_lib_dir,
|
||||
override_global_cache_dir,
|
||||
.{ .override = path: {
|
||||
|
|
@ -5138,7 +5129,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
|
|||
{},
|
||||
self_exe_path,
|
||||
);
|
||||
defer dirs.deinit();
|
||||
defer dirs.deinit(io);
|
||||
|
||||
child_argv.items[argv_index_zig_lib_dir] = dirs.zig_lib.path orelse cwd_path;
|
||||
child_argv.items[argv_index_build_file] = build_root.directory.path orelse cwd_path;
|
||||
|
|
@ -5421,11 +5412,10 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
|
|||
child.stderr_behavior = .Inherit;
|
||||
|
||||
const term = t: {
|
||||
std.debug.lockStdErr();
|
||||
defer std.debug.unlockStdErr();
|
||||
break :t child.spawnAndWait(io) catch |err| {
|
||||
_ = std.debug.lockStderrWriter(&.{});
|
||||
defer std.debug.unlockStderrWriter();
|
||||
break :t child.spawnAndWait(io) catch |err|
|
||||
fatal("failed to spawn build runner {s}: {t}", .{ child_argv.items[0], err });
|
||||
};
|
||||
};
|
||||
|
||||
switch (term) {
|
||||
|
|
@ -5517,7 +5507,7 @@ fn jitCmd(
|
|||
dev.check(.jit_command);
|
||||
|
||||
const color: Color = .auto;
|
||||
const root_prog_node = if (options.progress_node) |node| node else std.Progress.start(.{
|
||||
const root_prog_node = if (options.progress_node) |node| node else std.Progress.start(io, .{
|
||||
.disable_printing = (color == .off),
|
||||
});
|
||||
|
||||
|
|
@ -5529,9 +5519,8 @@ fn jitCmd(
|
|||
.is_explicit_dynamic_linker = false,
|
||||
};
|
||||
|
||||
const self_exe_path = fs.selfExePathAlloc(arena) catch |err| {
|
||||
fatal("unable to find self exe path: {s}", .{@errorName(err)});
|
||||
};
|
||||
const self_exe_path = process.executablePathAlloc(io, arena) catch |err|
|
||||
fatal("unable to find self exe path: {t}", .{err});
|
||||
|
||||
const optimize_mode: std.builtin.OptimizeMode = if (EnvVar.ZIG_DEBUG_CMD.isSet())
|
||||
.Debug
|
||||
|
|
@ -5544,13 +5533,14 @@ fn jitCmd(
|
|||
// This `init` calls `fatal` on error.
|
||||
var dirs: Compilation.Directories = .init(
|
||||
arena,
|
||||
io,
|
||||
override_lib_dir,
|
||||
override_global_cache_dir,
|
||||
.global,
|
||||
if (native_os == .wasi) wasi_preopens,
|
||||
self_exe_path,
|
||||
);
|
||||
defer dirs.deinit();
|
||||
defer dirs.deinit(io);
|
||||
|
||||
const thread_limit = @min(
|
||||
@max(std.Thread.getCpuCount() catch 1, 1),
|
||||
|
|
@ -5629,7 +5619,7 @@ fn jitCmd(
|
|||
defer comp.destroy();
|
||||
|
||||
if (options.server) {
|
||||
var stdout_writer = Io.File.stdout().writer(&stdout_buffer);
|
||||
var stdout_writer = Io.File.stdout().writer(io, &stdout_buffer);
|
||||
var server: std.zig.Server = .{
|
||||
.out = &stdout_writer.interface,
|
||||
.in = undefined, // won't be receiving messages
|
||||
|
|
@ -5696,7 +5686,7 @@ fn jitCmd(
|
|||
ptr.* = try stdout_reader.interface.allocRemaining(arena, .limited(std.math.maxInt(u32)));
|
||||
}
|
||||
|
||||
const term = try child.wait();
|
||||
const term = try child.wait(io);
|
||||
switch (term) {
|
||||
.Exited => |code| {
|
||||
if (code == 0) {
|
||||
|
|
@ -6160,7 +6150,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void {
|
|||
const arg = args[i];
|
||||
if (mem.startsWith(u8, arg, "-")) {
|
||||
if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
|
||||
try Io.File.stdout().writeAll(usage_ast_check);
|
||||
try Io.File.stdout().writeStreamingAll(io, usage_ast_check);
|
||||
return cleanExit();
|
||||
} else if (mem.eql(u8, arg, "-t")) {
|
||||
want_output_text = true;
|
||||
|
|
@ -6211,7 +6201,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void {
|
|||
|
||||
const tree = try Ast.parse(arena, source, mode);
|
||||
|
||||
var stdout_writer = Io.File.stdout().writerStreaming(&stdout_buffer);
|
||||
var stdout_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer);
|
||||
const stdout_bw = &stdout_writer.interface;
|
||||
switch (mode) {
|
||||
.zig => {
|
||||
|
|
@ -6334,7 +6324,7 @@ fn cmdDetectCpu(io: Io, args: []const []const u8) !void {
|
|||
const arg = args[i];
|
||||
if (mem.startsWith(u8, arg, "-")) {
|
||||
if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
|
||||
try Io.File.stdout().writeAll(detect_cpu_usage);
|
||||
try Io.File.stdout().writeStreamingAll(io, detect_cpu_usage);
|
||||
return cleanExit();
|
||||
} else if (mem.eql(u8, arg, "--llvm")) {
|
||||
use_llvm = true;
|
||||
|
|
@ -6355,10 +6345,10 @@ fn cmdDetectCpu(io: Io, args: []const []const u8) !void {
|
|||
const name = llvm.GetHostCPUName() orelse fatal("LLVM could not figure out the host cpu name", .{});
|
||||
const features = llvm.GetHostCPUFeatures() orelse fatal("LLVM could not figure out the host cpu feature set", .{});
|
||||
const cpu = try detectNativeCpuWithLLVM(builtin.cpu.arch, name, features);
|
||||
try printCpu(cpu);
|
||||
try printCpu(io, cpu);
|
||||
} else {
|
||||
const host_target = std.zig.resolveTargetQueryOrFatal(io, .{});
|
||||
try printCpu(host_target.cpu);
|
||||
try printCpu(io, host_target.cpu);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -6425,8 +6415,8 @@ fn detectNativeCpuWithLLVM(
|
|||
return result;
|
||||
}
|
||||
|
||||
fn printCpu(cpu: std.Target.Cpu) !void {
|
||||
var stdout_writer = Io.File.stdout().writerStreaming(&stdout_buffer);
|
||||
fn printCpu(io: Io, cpu: std.Target.Cpu) !void {
|
||||
var stdout_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer);
|
||||
const stdout_bw = &stdout_writer.interface;
|
||||
|
||||
if (cpu.model.llvm_name) |llvm_name| {
|
||||
|
|
@ -6448,6 +6438,7 @@ fn printCpu(cpu: std.Target.Cpu) !void {
|
|||
fn cmdDumpLlvmInts(
|
||||
gpa: Allocator,
|
||||
arena: Allocator,
|
||||
io: Io,
|
||||
args: []const []const u8,
|
||||
) !void {
|
||||
dev.check(.llvm_ints_command);
|
||||
|
|
@ -6475,7 +6466,7 @@ fn cmdDumpLlvmInts(
|
|||
const dl = tm.createTargetDataLayout();
|
||||
const context = llvm.Context.create();
|
||||
|
||||
var stdout_writer = Io.File.stdout().writerStreaming(&stdout_buffer);
|
||||
var stdout_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer);
|
||||
const stdout_bw = &stdout_writer.interface;
|
||||
for ([_]u16{ 1, 8, 16, 32, 64, 128, 256 }) |bits| {
|
||||
const int_type = context.intType(bits);
|
||||
|
|
@ -6501,7 +6492,7 @@ fn cmdDumpZir(arena: Allocator, io: Io, args: []const []const u8) !void {
|
|||
defer f.close(io);
|
||||
|
||||
const zir = try Zcu.loadZirCache(arena, io, f);
|
||||
var stdout_writer = Io.File.stdout().writerStreaming(&stdout_buffer);
|
||||
var stdout_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer);
|
||||
const stdout_bw = &stdout_writer.interface;
|
||||
{
|
||||
const instruction_bytes = zir.instructions.len *
|
||||
|
|
@ -6585,7 +6576,7 @@ fn cmdChangelist(arena: Allocator, io: Io, args: []const []const u8) !void {
|
|||
var inst_map: std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index) = .empty;
|
||||
try Zcu.mapOldZirToNew(arena, old_zir, new_zir, &inst_map);
|
||||
|
||||
var stdout_writer = Io.File.stdout().writerStreaming(&stdout_buffer);
|
||||
var stdout_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer);
|
||||
const stdout_bw = &stdout_writer.interface;
|
||||
{
|
||||
try stdout_bw.print("Instruction mappings:\n", .{});
|
||||
|
|
@ -6917,7 +6908,7 @@ fn cmdFetch(
|
|||
const arg = args[i];
|
||||
if (mem.startsWith(u8, arg, "-")) {
|
||||
if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
|
||||
try Io.File.stdout().writeAll(usage_fetch);
|
||||
try Io.File.stdout().writeStreamingAll(io, usage_fetch);
|
||||
return cleanExit();
|
||||
} else if (mem.eql(u8, arg, "--global-cache-dir")) {
|
||||
if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg});
|
||||
|
|
@ -6951,7 +6942,7 @@ fn cmdFetch(
|
|||
|
||||
try http_client.initDefaultProxies(arena);
|
||||
|
||||
var root_prog_node = std.Progress.start(.{
|
||||
var root_prog_node = std.Progress.start(io, .{
|
||||
.root_name = "Fetch",
|
||||
});
|
||||
defer root_prog_node.end();
|
||||
|
|
@ -6959,7 +6950,7 @@ fn cmdFetch(
|
|||
var global_cache_directory: Directory = l: {
|
||||
const p = override_global_cache_dir orelse try introspect.resolveGlobalCacheDir(arena);
|
||||
break :l .{
|
||||
.handle = try Io.Dir.cwd().makeOpenPath(p, .{}),
|
||||
.handle = try Io.Dir.cwd().makeOpenPath(io, p, .{}),
|
||||
.path = p,
|
||||
};
|
||||
};
|
||||
|
|
@ -7026,7 +7017,7 @@ fn cmdFetch(
|
|||
|
||||
const name = switch (save) {
|
||||
.no => {
|
||||
var stdout = Io.File.stdout().writerStreaming(&stdout_buffer);
|
||||
var stdout = Io.File.stdout().writerStreaming(io, &stdout_buffer);
|
||||
try stdout.interface.print("{s}\n", .{package_hash_slice});
|
||||
try stdout.interface.flush();
|
||||
return cleanExit();
|
||||
|
|
@ -7044,7 +7035,7 @@ fn cmdFetch(
|
|||
var build_root = try findBuildRoot(arena, io, .{
|
||||
.cwd_path = cwd_path,
|
||||
});
|
||||
defer build_root.deinit();
|
||||
defer build_root.deinit(io);
|
||||
|
||||
// The name to use in case the manifest file needs to be created now.
|
||||
const init_root_name = fs.path.basename(build_root.directory.path orelse cwd_path);
|
||||
|
|
@ -7205,7 +7196,7 @@ fn createDependenciesModule(
|
|||
const rand_int = std.crypto.random.int(u64);
|
||||
const tmp_dir_sub_path = "tmp" ++ fs.path.sep_str ++ std.fmt.hex(rand_int);
|
||||
{
|
||||
var tmp_dir = try dirs.local_cache.handle.makeOpenPath(tmp_dir_sub_path, .{});
|
||||
var tmp_dir = try dirs.local_cache.handle.makeOpenPath(io, tmp_dir_sub_path, .{});
|
||||
defer tmp_dir.close(io);
|
||||
try tmp_dir.writeFile(io, .{ .sub_path = basename, .data = source });
|
||||
}
|
||||
|
|
@ -7446,28 +7437,28 @@ fn writeSimpleTemplateFile(io: Io, file_name: []const u8, comptime fmt: []const
|
|||
const f = try Io.Dir.cwd().createFile(io, file_name, .{ .exclusive = true });
|
||||
defer f.close(io);
|
||||
var buf: [4096]u8 = undefined;
|
||||
var fw = f.writer(&buf);
|
||||
var fw = f.writer(io, &buf);
|
||||
try fw.interface.print(fmt, args);
|
||||
try fw.interface.flush();
|
||||
}
|
||||
|
||||
fn findTemplates(gpa: Allocator, arena: Allocator, io: Io) Templates {
|
||||
const cwd_path = introspect.getResolvedCwd(arena) catch |err| {
|
||||
fatal("unable to get cwd: {s}", .{@errorName(err)});
|
||||
fatal("unable to get cwd: {t}", .{err});
|
||||
};
|
||||
const self_exe_path = fs.selfExePathAlloc(arena) catch |err| {
|
||||
fatal("unable to find self exe path: {s}", .{@errorName(err)});
|
||||
const self_exe_path = process.executablePathAlloc(io, arena) catch |err| {
|
||||
fatal("unable to find self exe path: {t}", .{err});
|
||||
};
|
||||
var zig_lib_directory = introspect.findZigLibDirFromSelfExe(arena, io, cwd_path, self_exe_path) catch |err| {
|
||||
fatal("unable to find zig installation directory '{s}': {s}", .{ self_exe_path, @errorName(err) });
|
||||
fatal("unable to find zig installation directory '{s}': {t}", .{ self_exe_path, err });
|
||||
};
|
||||
|
||||
const s = fs.path.sep_str;
|
||||
const template_sub_path = "init";
|
||||
const template_dir = zig_lib_directory.handle.openDir(io, template_sub_path, .{}) catch |err| {
|
||||
const path = zig_lib_directory.path orelse ".";
|
||||
fatal("unable to open zig project template directory '{s}{s}{s}': {s}", .{
|
||||
path, s, template_sub_path, @errorName(err),
|
||||
fatal("unable to open zig project template directory '{s}{s}{s}': {t}", .{
|
||||
path, s, template_sub_path, err,
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,17 @@
|
|||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const build_options = @import("build_options");
|
||||
const Compilation = @import("Compilation.zig");
|
||||
|
||||
const std = @import("std");
|
||||
const Io = std.Io;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const EnvVar = std.zig.EnvVar;
|
||||
const fatal = std.process.fatal;
|
||||
|
||||
const build_options = @import("build_options");
|
||||
const Compilation = @import("Compilation.zig");
|
||||
|
||||
pub fn cmdEnv(
|
||||
arena: Allocator,
|
||||
io: Io,
|
||||
out: *std.Io.Writer,
|
||||
args: []const []const u8,
|
||||
wasi_preopens: switch (builtin.target.os.tag) {
|
||||
|
|
@ -21,20 +25,21 @@ pub fn cmdEnv(
|
|||
|
||||
const self_exe_path = switch (builtin.target.os.tag) {
|
||||
.wasi => args[0],
|
||||
else => std.fs.selfExePathAlloc(arena) catch |err| {
|
||||
fatal("unable to find zig self exe path: {s}", .{@errorName(err)});
|
||||
else => std.process.executablePathAlloc(io, arena) catch |err| {
|
||||
fatal("unable to find zig self exe path: {t}", .{err});
|
||||
},
|
||||
};
|
||||
|
||||
var dirs: Compilation.Directories = .init(
|
||||
arena,
|
||||
io,
|
||||
override_lib_dir,
|
||||
override_global_cache_dir,
|
||||
.global,
|
||||
if (builtin.target.os.tag == .wasi) wasi_preopens,
|
||||
if (builtin.target.os.tag != .wasi) self_exe_path,
|
||||
);
|
||||
defer dirs.deinit();
|
||||
defer dirs.deinit(io);
|
||||
|
||||
const zig_lib_dir = dirs.zig_lib.path orelse "";
|
||||
const zig_std_dir = try dirs.zig_lib.join(arena, &.{"std"});
|
||||
|
|
|
|||
|
|
@ -1,14 +1,16 @@
|
|||
const std = @import("std");
|
||||
const Io = std.Io;
|
||||
const fs = std.fs;
|
||||
const mem = std.mem;
|
||||
const meta = std.meta;
|
||||
const fatal = std.process.fatal;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const Target = std.Target;
|
||||
const target = @import("target.zig");
|
||||
const assert = std.debug.assert;
|
||||
|
||||
const glibc = @import("libs/glibc.zig");
|
||||
const introspect = @import("introspect.zig");
|
||||
const target = @import("target.zig");
|
||||
|
||||
pub fn cmdTargets(
|
||||
allocator: Allocator,
|
||||
|
|
@ -18,19 +20,19 @@ pub fn cmdTargets(
|
|||
native_target: *const Target,
|
||||
) !void {
|
||||
_ = args;
|
||||
var zig_lib_directory = introspect.findZigLibDir(allocator) catch |err| {
|
||||
fatal("unable to find zig installation directory: {s}\n", .{@errorName(err)});
|
||||
};
|
||||
var zig_lib_directory = introspect.findZigLibDir(allocator, io) catch |err|
|
||||
fatal("unable to find zig installation directory: {t}", .{err});
|
||||
defer zig_lib_directory.handle.close(io);
|
||||
defer allocator.free(zig_lib_directory.path.?);
|
||||
|
||||
const abilists_contents = zig_lib_directory.handle.readFileAlloc(
|
||||
io,
|
||||
glibc.abilists_path,
|
||||
allocator,
|
||||
.limited(glibc.abilists_max_size),
|
||||
) catch |err| switch (err) {
|
||||
error.OutOfMemory => return error.OutOfMemory,
|
||||
else => fatal("unable to read " ++ glibc.abilists_path ++ ": {s}", .{@errorName(err)}),
|
||||
else => fatal("unable to read " ++ glibc.abilists_path ++ ": {t}", .{err}),
|
||||
};
|
||||
defer allocator.free(abilists_contents);
|
||||
|
||||
|
|
@ -49,9 +51,7 @@ pub fn cmdTargets(
|
|||
{
|
||||
var libc_obj = try root_obj.beginTupleField("libc", .{});
|
||||
for (std.zig.target.available_libcs) |libc| {
|
||||
const tmp = try std.fmt.allocPrint(allocator, "{s}-{s}-{s}", .{
|
||||
@tagName(libc.arch), @tagName(libc.os), @tagName(libc.abi),
|
||||
});
|
||||
const tmp = try std.fmt.allocPrint(allocator, "{t}-{t}-{t}", .{ libc.arch, libc.os, libc.abi });
|
||||
defer allocator.free(tmp);
|
||||
try libc_obj.field(tmp, .{});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ pub fn main() !void {
|
|||
defer threaded.deinit();
|
||||
const io = threaded.io();
|
||||
|
||||
const self_path = try std.fs.selfExePathAlloc(gpa);
|
||||
const self_path = try std.process.executablePathAlloc(io, gpa);
|
||||
defer gpa.free(self_path);
|
||||
|
||||
var self_exe = try std.fs.openSelfExe(.{});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue