aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-12-08 17:21:52 -0800
committerAndrew Kelley <andrew@ziglang.org>2025-12-23 22:15:08 -0800
commit4218344dd3178f2fd3d9d00e9ff6895ee344df6d (patch)
tree38a1378b45349bcd182f6bdb721dadb275c1d02e /lib/std
parent950d18ef695bb7a28397e080dc3c201559ec4ee2 (diff)
downloadzig-4218344dd3178f2fd3d9d00e9ff6895ee344df6d.tar.gz
zig-4218344dd3178f2fd3d9d00e9ff6895ee344df6d.zip
std.Build.Cache: remove readSmallFile and writeSmallFile
These were to support optimizations involving detecting when to avoid calling into LLD, which are no longer implemented.
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/Build/Cache.zig36
-rw-r--r--lib/std/Build/Step/ConfigHeader.zig2
-rw-r--r--lib/std/Build/Step/Run.zig2
-rw-r--r--lib/std/Build/Step/UpdateSourceFiles.zig2
-rw-r--r--lib/std/Build/Step/WriteFile.zig2
-rw-r--r--lib/std/Build/WebServer.zig2
-rw-r--r--lib/std/debug.zig4
-rw-r--r--lib/std/fs/test.zig48
-rw-r--r--lib/std/posix/test.zig2
9 files changed, 42 insertions, 58 deletions
diff --git a/lib/std/Build/Cache.zig b/lib/std/Build/Cache.zig
index dab1926f53..f7c4d729bc 100644
--- a/lib/std/Build/Cache.zig
+++ b/lib/std/Build/Cache.zig
@@ -1276,30 +1276,6 @@ pub const Manifest = struct {
}
};
-/// On operating systems that support symlinks, does a readlink. On other operating systems,
-/// uses the file contents. Windows supports symlinks but only with elevated privileges, so
-/// it is treated as not supporting symlinks.
-pub fn readSmallFile(dir: Io.Dir, sub_path: []const u8, buffer: []u8) ![]u8 {
- if (builtin.os.tag == .windows) {
- return dir.readFile(sub_path, buffer);
- } else {
- return dir.readLink(sub_path, buffer);
- }
-}
-
-/// On operating systems that support symlinks, does a symlink. On other operating systems,
-/// uses the file contents. Windows supports symlinks but only with elevated privileges, so
-/// it is treated as not supporting symlinks.
-/// `data` must be a valid UTF-8 encoded file path and 255 bytes or fewer.
-pub fn writeSmallFile(dir: Io.Dir, sub_path: []const u8, data: []const u8) !void {
- assert(data.len <= 255);
- if (builtin.os.tag == .windows) {
- return dir.writeFile(.{ .sub_path = sub_path, .data = data });
- } else {
- return dir.symLink(data, sub_path, .{});
- }
-}
-
fn hashFile(io: Io, file: Io.File, bin_digest: *[Hasher.mac_length]u8) Io.File.ReadPositionalError!void {
var buffer: [2048]u8 = undefined;
var hasher = hasher_init;
@@ -1338,7 +1314,7 @@ test "cache file and then recall it" {
const temp_file = "test.txt";
const temp_manifest_dir = "temp_manifest_dir";
- try tmp.dir.writeFile(.{ .sub_path = temp_file, .data = "Hello, world!\n" });
+ try tmp.dir.writeFile(io, .{ .sub_path = temp_file, .data = "Hello, world!\n" });
// Wait for file timestamps to tick
const initial_time = try testGetCurrentFileTimestamp(io, tmp.dir);
@@ -1404,7 +1380,7 @@ test "check that changing a file makes cache fail" {
const original_temp_file_contents = "Hello, world!\n";
const updated_temp_file_contents = "Hello, world; but updated!\n";
- try tmp.dir.writeFile(.{ .sub_path = temp_file, .data = original_temp_file_contents });
+ try tmp.dir.writeFile(io, .{ .sub_path = temp_file, .data = original_temp_file_contents });
// Wait for file timestamps to tick
const initial_time = try testGetCurrentFileTimestamp(tmp.dir);
@@ -1441,7 +1417,7 @@ test "check that changing a file makes cache fail" {
try ch.writeManifest();
}
- try tmp.dir.writeFile(.{ .sub_path = temp_file, .data = updated_temp_file_contents });
+ try tmp.dir.writeFile(io, .{ .sub_path = temp_file, .data = updated_temp_file_contents });
{
var ch = cache.obtain();
@@ -1521,8 +1497,8 @@ test "Manifest with files added after initial hash work" {
const temp_file2 = "cache_hash_post_file_test2.txt";
const temp_manifest_dir = "cache_hash_post_file_manifest_dir";
- try tmp.dir.writeFile(.{ .sub_path = temp_file1, .data = "Hello, world!\n" });
- try tmp.dir.writeFile(.{ .sub_path = temp_file2, .data = "Hello world the second!\n" });
+ try tmp.dir.writeFile(io, .{ .sub_path = temp_file1, .data = "Hello, world!\n" });
+ try tmp.dir.writeFile(io, .{ .sub_path = temp_file2, .data = "Hello world the second!\n" });
// Wait for file timestamps to tick
const initial_time = try testGetCurrentFileTimestamp(tmp.dir);
@@ -1573,7 +1549,7 @@ test "Manifest with files added after initial hash work" {
try testing.expect(mem.eql(u8, &digest1, &digest2));
// Modify the file added after initial hash
- try tmp.dir.writeFile(.{ .sub_path = temp_file2, .data = "Hello world the second, updated\n" });
+ try tmp.dir.writeFile(io, .{ .sub_path = temp_file2, .data = "Hello world the second, updated\n" });
// Wait for file timestamps to tick
const initial_time2 = try testGetCurrentFileTimestamp(tmp.dir);
diff --git a/lib/std/Build/Step/ConfigHeader.zig b/lib/std/Build/Step/ConfigHeader.zig
index f377959610..589110d4c4 100644
--- a/lib/std/Build/Step/ConfigHeader.zig
+++ b/lib/std/Build/Step/ConfigHeader.zig
@@ -264,7 +264,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
});
};
- b.cache_root.handle.writeFile(.{ .sub_path = sub_path, .data = output }) catch |err| {
+ b.cache_root.handle.writeFile(io, .{ .sub_path = sub_path, .data = output }) catch |err| {
return step.fail("unable to write file '{f}{s}': {s}", .{
b.cache_root, sub_path, @errorName(err),
});
diff --git a/lib/std/Build/Step/Run.zig b/lib/std/Build/Step/Run.zig
index f6b29635c1..a1618beb02 100644
--- a/lib/std/Build/Step/Run.zig
+++ b/lib/std/Build/Step/Run.zig
@@ -1482,7 +1482,7 @@ fn runCommand(
.leading => mem.trimStart(u8, stream.bytes.?, &std.ascii.whitespace),
.trailing => mem.trimEnd(u8, stream.bytes.?, &std.ascii.whitespace),
};
- b.cache_root.handle.writeFile(.{ .sub_path = sub_path, .data = data }) catch |err| {
+ b.cache_root.handle.writeFile(io, .{ .sub_path = sub_path, .data = data }) catch |err| {
return step.fail("unable to write file '{f}{s}': {s}", .{
b.cache_root, sub_path, @errorName(err),
});
diff --git a/lib/std/Build/Step/UpdateSourceFiles.zig b/lib/std/Build/Step/UpdateSourceFiles.zig
index 44c6ae1ed4..eb8a6a85dd 100644
--- a/lib/std/Build/Step/UpdateSourceFiles.zig
+++ b/lib/std/Build/Step/UpdateSourceFiles.zig
@@ -84,7 +84,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
}
switch (output_source_file.contents) {
.bytes => |bytes| {
- b.build_root.handle.writeFile(.{ .sub_path = output_source_file.sub_path, .data = bytes }) catch |err| {
+ b.build_root.handle.writeFile(io, .{ .sub_path = output_source_file.sub_path, .data = bytes }) catch |err| {
return step.fail("unable to write file '{f}{s}': {t}", .{
b.build_root, output_source_file.sub_path, err,
});
diff --git a/lib/std/Build/Step/WriteFile.zig b/lib/std/Build/Step/WriteFile.zig
index 94b04b4212..3d712fa1d4 100644
--- a/lib/std/Build/Step/WriteFile.zig
+++ b/lib/std/Build/Step/WriteFile.zig
@@ -273,7 +273,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
}
switch (file.contents) {
.bytes => |bytes| {
- cache_dir.writeFile(.{ .sub_path = file.sub_path, .data = bytes }) catch |err| {
+ cache_dir.writeFile(io, .{ .sub_path = file.sub_path, .data = bytes }) catch |err| {
return step.fail("unable to write file '{f}{s}{c}{s}': {t}", .{
b.cache_root, cache_path, fs.path.sep, file.sub_path, err,
});
diff --git a/lib/std/Build/WebServer.zig b/lib/std/Build/WebServer.zig
index 162d17f070..ed07d04d57 100644
--- a/lib/std/Build/WebServer.zig
+++ b/lib/std/Build/WebServer.zig
@@ -523,7 +523,7 @@ pub fn serveTarFile(ws: *WebServer, request: *http.Server.Request, paths: []cons
if (cached_cwd_path == null) cached_cwd_path = try std.process.getCwdAlloc(gpa);
break :cwd cached_cwd_path.?;
};
- try archiver.writeFile(path.sub_path, &file_reader, @intCast(stat.mtime.toSeconds()));
+ try archiver.writeFile(io, path.sub_path, &file_reader, @intCast(stat.mtime.toSeconds()));
}
// intentionally not calling `archiver.finishPedantically`
diff --git a/lib/std/debug.zig b/lib/std/debug.zig
index 39207f938d..cb79bb7855 100644
--- a/lib/std/debug.zig
+++ b/lib/std/debug.zig
@@ -1243,7 +1243,7 @@ test printLineFromFile {
{
const path = try join(gpa, &.{ test_dir_path, "one_line.zig" });
defer gpa.free(path);
- try test_dir.dir.writeFile(.{ .sub_path = "one_line.zig", .data = "no new lines in this file, but one is printed anyway" });
+ try test_dir.dir.writeFile(io, .{ .sub_path = "one_line.zig", .data = "no new lines in this file, but one is printed anyway" });
try expectError(error.EndOfFile, printLineFromFile(io, output_stream, .{ .file_name = path, .line = 2, .column = 0 }));
@@ -1254,7 +1254,7 @@ test printLineFromFile {
{
const path = try fs.path.join(gpa, &.{ test_dir_path, "three_lines.zig" });
defer gpa.free(path);
- try test_dir.dir.writeFile(.{
+ try test_dir.dir.writeFile(io, .{
.sub_path = "three_lines.zig",
.data =
\\1
diff --git a/lib/std/fs/test.zig b/lib/std/fs/test.zig
index 59bacff2d0..59e0990eb0 100644
--- a/lib/std/fs/test.zig
+++ b/lib/std/fs/test.zig
@@ -184,7 +184,7 @@ test "Dir.readLink" {
fn impl(ctx: *TestContext) !void {
// Create some targets
const file_target_path = try ctx.transformPath("file.txt");
- try ctx.dir.writeFile(.{ .sub_path = file_target_path, .data = "nonsense" });
+ try ctx.dir.writeFile(io, .{ .sub_path = file_target_path, .data = "nonsense" });
const dir_target_path = try ctx.transformPath("subdir");
try ctx.dir.makeDir(dir_target_path);
@@ -487,11 +487,13 @@ test "readLinkAbsolute" {
if (native_os == .wasi) return error.SkipZigTest;
if (native_os == .openbsd) return error.SkipZigTest;
+ const io = testing.io;
+
var tmp = tmpDir(.{});
defer tmp.cleanup();
// Create some targets
- try tmp.dir.writeFile(.{ .sub_path = "file.txt", .data = "nonsense" });
+ try tmp.dir.writeFile(io, .{ .sub_path = "file.txt", .data = "nonsense" });
try tmp.dir.makeDir("subdir");
// Get base abs path
@@ -708,6 +710,7 @@ test "Dir.realpath smoke test" {
try testWithAllSupportedPathTypes(struct {
fn impl(ctx: *TestContext) !void {
+ const io = ctx.io;
const allocator = ctx.arena.allocator();
const test_file_path = try ctx.transformPath("test_file");
const test_dir_path = try ctx.transformPath("test_dir");
@@ -720,7 +723,7 @@ test "Dir.realpath smoke test" {
try testing.expectError(error.FileNotFound, ctx.dir.realpath(test_dir_path, &buf));
// Now create the file and dir
- try ctx.dir.writeFile(.{ .sub_path = test_file_path, .data = "" });
+ try ctx.dir.writeFile(io, .{ .sub_path = test_file_path, .data = "" });
try ctx.dir.makeDir(test_dir_path);
const base_path = try ctx.transformPath(".");
@@ -803,11 +806,12 @@ test "readFileAlloc" {
test "Dir.statFile" {
try testWithAllSupportedPathTypes(struct {
fn impl(ctx: *TestContext) !void {
+ const io = ctx.io;
const test_file_name = try ctx.transformPath("test_file");
try testing.expectError(error.FileNotFound, ctx.dir.statFile(test_file_name));
- try ctx.dir.writeFile(.{ .sub_path = test_file_name, .data = "" });
+ try ctx.dir.writeFile(io, .{ .sub_path = test_file_name, .data = "" });
const stat = try ctx.dir.statFile(test_file_name);
try testing.expectEqual(File.Kind.file, stat.kind);
@@ -925,6 +929,7 @@ test "makeOpenPath parent dirs do not exist" {
test "deleteDir" {
try testWithAllSupportedPathTypes(struct {
fn impl(ctx: *TestContext) !void {
+ const io = ctx.io;
const test_dir_path = try ctx.transformPath("test_dir");
const test_file_path = try ctx.transformPath("test_dir" ++ fs.path.sep_str ++ "test_file");
@@ -933,7 +938,7 @@ test "deleteDir" {
// deleting a non-empty directory
try ctx.dir.makeDir(test_dir_path);
- try ctx.dir.writeFile(.{ .sub_path = test_file_path, .data = "" });
+ try ctx.dir.writeFile(io, .{ .sub_path = test_file_path, .data = "" });
try testing.expectError(error.DirNotEmpty, ctx.dir.deleteDir(test_dir_path));
// deleting an empty directory
@@ -1217,7 +1222,7 @@ test "deleteTree on a symlink" {
defer tmp.cleanup();
// Symlink to a file
- try tmp.dir.writeFile(.{ .sub_path = "file", .data = "" });
+ try tmp.dir.writeFile(io, .{ .sub_path = "file", .data = "" });
try setupSymlink(tmp.dir, "file", "filelink", .{});
try tmp.dir.deleteTree("filelink");
@@ -1241,11 +1246,11 @@ test "makePath, put some files in it, deleteTree" {
const dir_path = try ctx.transformPath("os_test_tmp");
try ctx.dir.makePath(io, try fs.path.join(allocator, &.{ "os_test_tmp", "b", "c" }));
- try ctx.dir.writeFile(.{
+ try ctx.dir.writeFile(io, .{
.sub_path = try fs.path.join(allocator, &.{ "os_test_tmp", "b", "c", "file.txt" }),
.data = "nonsense",
});
- try ctx.dir.writeFile(.{
+ try ctx.dir.writeFile(io, .{
.sub_path = try fs.path.join(allocator, &.{ "os_test_tmp", "b", "file2.txt" }),
.data = "blah",
});
@@ -1264,11 +1269,11 @@ test "makePath, put some files in it, deleteTreeMinStackSize" {
const dir_path = try ctx.transformPath("os_test_tmp");
try ctx.dir.makePath(io, try fs.path.join(allocator, &.{ "os_test_tmp", "b", "c" }));
- try ctx.dir.writeFile(.{
+ try ctx.dir.writeFile(io, .{
.sub_path = try fs.path.join(allocator, &.{ "os_test_tmp", "b", "c", "file.txt" }),
.data = "nonsense",
});
- try ctx.dir.writeFile(.{
+ try ctx.dir.writeFile(io, .{
.sub_path = try fs.path.join(allocator, &.{ "os_test_tmp", "b", "file2.txt" }),
.data = "blah",
});
@@ -1298,7 +1303,7 @@ test "makePath but sub_path contains pre-existing file" {
defer tmp.cleanup();
try tmp.dir.makeDir("foo");
- try tmp.dir.writeFile(.{ .sub_path = "foo/bar", .data = "" });
+ try tmp.dir.writeFile(io, .{ .sub_path = "foo/bar", .data = "" });
try testing.expectError(error.NotDir, tmp.dir.makePath(io, "foo/bar/baz"));
}
@@ -1400,7 +1405,7 @@ fn testFilenameLimits(io: Io, iterable_dir: Dir, maxed_filename: []const u8) !vo
var maxed_dir = try iterable_dir.makeOpenPath(maxed_filename, .{});
defer maxed_dir.close(io);
- try maxed_dir.writeFile(.{ .sub_path = maxed_filename, .data = "" });
+ try maxed_dir.writeFile(io, .{ .sub_path = maxed_filename, .data = "" });
var walker = try iterable_dir.walk(testing.allocator);
defer walker.deinit();
@@ -1513,7 +1518,7 @@ test "setEndPos" {
defer tmp.cleanup();
const file_name = "afile.txt";
- try tmp.dir.writeFile(.{ .sub_path = file_name, .data = "ninebytes" });
+ try tmp.dir.writeFile(io, .{ .sub_path = file_name, .data = "ninebytes" });
const f = try tmp.dir.openFile(io, file_name, .{ .mode = .read_write });
defer f.close(io);
@@ -1563,7 +1568,7 @@ test "access file" {
try ctx.dir.makePath(io, dir_path);
try testing.expectError(error.FileNotFound, ctx.dir.access(io, file_path, .{}));
- try ctx.dir.writeFile(.{ .sub_path = file_path, .data = "" });
+ try ctx.dir.writeFile(io, .{ .sub_path = file_path, .data = "" });
try ctx.dir.access(io, file_path, .{});
try ctx.dir.deleteTree(dir_path);
}
@@ -1659,12 +1664,13 @@ test "sendfile with buffered data" {
test "copyFile" {
try testWithAllSupportedPathTypes(struct {
fn impl(ctx: *TestContext) !void {
+ const io = ctx.io;
const data = "u6wj+JmdF3qHsFPE BUlH2g4gJCmEz0PP";
const src_file = try ctx.transformPath("tmp_test_copy_file.txt");
const dest_file = try ctx.transformPath("tmp_test_copy_file2.txt");
const dest_file2 = try ctx.transformPath("tmp_test_copy_file3.txt");
- try ctx.dir.writeFile(.{ .sub_path = src_file, .data = data });
+ try ctx.dir.writeFile(io, .{ .sub_path = src_file, .data = data });
defer ctx.dir.deleteFile(src_file) catch {};
try ctx.dir.copyFile(src_file, ctx.dir, dest_file, .{});
@@ -2050,7 +2056,7 @@ test "'.' and '..' in Io.Dir functions" {
renamed_file.close(io);
try ctx.dir.deleteFile(rename_path);
- try ctx.dir.writeFile(.{ .sub_path = update_path, .data = "something" });
+ try ctx.dir.writeFile(io, .{ .sub_path = update_path, .data = "something" });
var dir = ctx.dir;
const prev_status = try dir.updateFile(io, file_path, dir, update_path, .{});
try testing.expectEqual(Io.Dir.PrevStatus.stale, prev_status);
@@ -2187,7 +2193,7 @@ test "invalid UTF-8/WTF-8 paths" {
try testing.expectError(expected_err, ctx.dir.deleteTree(invalid_path));
try testing.expectError(expected_err, ctx.dir.deleteTreeMinStackSize(invalid_path));
- try testing.expectError(expected_err, ctx.dir.writeFile(.{ .sub_path = invalid_path, .data = "" }));
+ try testing.expectError(expected_err, ctx.dir.writeFile(io, .{ .sub_path = invalid_path, .data = "" }));
try testing.expectError(expected_err, ctx.dir.access(invalid_path, .{}));
@@ -2304,7 +2310,7 @@ test "seekBy" {
var tmp_dir = testing.tmpDir(.{});
defer tmp_dir.cleanup();
- try tmp_dir.dir.writeFile(.{ .sub_path = "blah.txt", .data = "let's test seekBy" });
+ try tmp_dir.dir.writeFile(io, .{ .sub_path = "blah.txt", .data = "let's test seekBy" });
const f = try tmp_dir.dir.openFile(io, "blah.txt", .{ .mode = .read_only });
defer f.close(io);
var reader = f.readerStreaming(io, &.{});
@@ -2350,7 +2356,7 @@ test "File.Writer sendfile with buffered contents" {
defer tmp_dir.cleanup();
{
- try tmp_dir.dir.writeFile(.{ .sub_path = "a", .data = "bcd" });
+ try tmp_dir.dir.writeFile(io, .{ .sub_path = "a", .data = "bcd" });
const in = try tmp_dir.dir.openFile(io, "a", .{});
defer in.close(io);
const out = try tmp_dir.dir.createFile(io, "b", .{});
@@ -2391,11 +2397,13 @@ fn testReadlink(target_path: []const u8, symlink_path: []const u8) !void {
}
test "readlinkat" {
+ const io = testing.io;
+
var tmp = tmpDir(.{});
defer tmp.cleanup();
// create file
- try tmp.dir.writeFile(.{ .sub_path = "file.txt", .data = "nonsense" });
+ try tmp.dir.writeFile(io, .{ .sub_path = "file.txt", .data = "nonsense" });
// create a symbolic link
if (native_os == .windows) {
diff --git a/lib/std/posix/test.zig b/lib/std/posix/test.zig
index af17f1f9ff..bacfdacf83 100644
--- a/lib/std/posix/test.zig
+++ b/lib/std/posix/test.zig
@@ -145,7 +145,7 @@ test "linkat with different directories" {
const subdir = try tmp.dir.makeOpenPath("subdir", .{});
defer tmp.dir.deleteFile(target_name) catch {};
- try tmp.dir.writeFile(.{ .sub_path = target_name, .data = "example" });
+ try tmp.dir.writeFile(io, .{ .sub_path = target_name, .data = "example" });
// Test 1: link from file in subdir back up to target in parent directory
try posix.linkat(tmp.dir.handle, target_name, subdir.handle, link_name, 0);