Skip to content

Commit 8280d0e

Browse files
committed
migrate to Zig Build v2
1 parent 433adc5 commit 8280d0e

File tree

4 files changed

+105
-285
lines changed

4 files changed

+105
-285
lines changed

lib/std/Build/Cache.zig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ pub const Directory = struct {
3131
}
3232
}
3333

34+
pub fn tmpFilePath(self: *const Directory, ally: Allocator, suffix: []const u8) error{OutOfMemory}![]const u8 {
35+
const s = std.fs.path.sep_str;
36+
const rand_int = std.crypto.random.int(u64);
37+
if (self.path) |p| {
38+
return std.fmt.allocPrint(ally, "{s}" ++ s ++ "tmp" ++ s ++ "{x}-{s}", .{ p, rand_int, suffix });
39+
} else {
40+
return std.fmt.allocPrint(ally, "tmp" ++ s ++ "{x}-{s}", .{ rand_int, suffix });
41+
}
42+
}
43+
3444
/// Whether or not the handle should be closed, or the path should be freed
3545
/// is determined by usage, however this function is provided for convenience
3646
/// if it happens to be what the caller needs.

src/main.zig

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3147,50 +3147,18 @@ fn buildOutputType(
31473147
temp_files_for_comp.deinit();
31483148
}
31493149

3150-
// if a c_source_file is not a regular file, dump it to a tempdir
3151-
// and replace the src_name with the newly created file.
3152-
// translate-c works fine with streams; other actions don't.
3150+
// if a c_source_file is "-", dump it to a tempdir and replace the src_name
3151+
// with the newly created file. translate-c works fine with streams; other
3152+
// actions don't.
31533153
if (arg_mode != .translate_c) {
3154-
c_src_loop: for (c_source_files.items) |*src| {
3155-
// optimization: if the file extension is known, assume it is
3156-
// a regular file and keep going. This is in the hot path.
3157-
// If we remove this check, all input files will get an extra
3158-
// syscall or two of overhead.
3159-
if (Compilation.classifyFileExt(src.src_path) != .unknown)
3160-
continue;
3154+
for (c_source_files.items) |*src| {
3155+
if (!mem.eql(u8, src.src_path, "-")) continue;
31613156

3162-
// if the extension was not supplied or recognized, bail.
31633157
if (src.ext == null)
31643158
fatal("-E or -x is required when reading from a non-regular file", .{});
31653159

3166-
var close_fd = true;
3167-
const fd = blk: {
3168-
if (mem.eql(u8, src.src_path, "-")) {
3169-
close_fd = false;
3170-
break :blk io.getStdIn().handle;
3171-
}
3172-
3173-
// all things in a windows filesystem are files or directories.
3174-
// Therefore, if it is not stdin, it is a file.
3175-
if (builtin.os.tag == .windows)
3176-
continue :c_src_loop;
3177-
3178-
// On POSIX or wasm need to determine if a given path is a
3179-
// stream. 2 choices:
3180-
// 1. open + lseek. If lseek fails, it is a stream. Always 2
3181-
// syscalls.
3182-
// 2. fstat + optional open. If fstat says it's a file, return
3183-
// use it as such. If it is not a file, open and return the
3184-
// file descriptor. 1,5 syscall. Use this.
3185-
var stat_info = try std.os.fstatat(fs.cwd().fd, src.src_path, 0);
3186-
if (stat_info.mode & std.os.S.IFMT == std.os.S.IFREG)
3187-
continue :c_src_loop;
3188-
3189-
break :blk try std.os.open(src.src_path, std.os.O.RDONLY, 0);
3190-
};
3191-
defer if (close_fd) std.os.close(fd);
3192-
3193-
const new_file = try copyToFile(arena, fd, local_cache_directory);
3160+
// "-" is stdin. Dump it to a real file.
3161+
const new_file = try copyToFile(arena, io.getStdIn().handle, local_cache_directory);
31943162
try temp_files_for_comp.append(new_file);
31953163
src.src_path = new_file;
31963164
}

test/cli.zig

Lines changed: 0 additions & 246 deletions
This file was deleted.

0 commit comments

Comments
 (0)