Skip to content

Commit 38800e2

Browse files
motiejusandrewrk
authored andcommitted
migrate to Zig Build v2
1 parent 84f20b5 commit 38800e2

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
@@ -3055,50 +3055,18 @@ fn buildOutputType(
30553055
temp_files_for_comp.deinit();
30563056
}
30573057

3058-
// if a c_source_file is not a regular file, dump it to a tempdir
3059-
// and replace the src_name with the newly created file.
3060-
// translate-c works fine with streams; other actions don't.
3058+
// if a c_source_file is "-", dump it to a tempdir and replace the src_name
3059+
// with the newly created file. translate-c works fine with streams; other
3060+
// actions don't.
30613061
if (arg_mode != .translate_c) {
3062-
c_src_loop: for (c_source_files.items) |*src| {
3063-
// optimization: if the file extension is known, assume it is
3064-
// a regular file and keep going. This is in the hot path.
3065-
// If we remove this check, all input files will get an extra
3066-
// syscall or two of overhead.
3067-
if (Compilation.classifyFileExt(src.src_path) != .unknown)
3068-
continue;
3062+
for (c_source_files.items) |*src| {
3063+
if (!mem.eql(u8, src.src_path, "-")) continue;
30693064

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

3074-
var close_fd = true;
3075-
const fd = blk: {
3076-
if (mem.eql(u8, src.src_path, "-")) {
3077-
close_fd = false;
3078-
break :blk io.getStdIn().handle;
3079-
}
3080-
3081-
// all things in a windows filesystem are files or directories.
3082-
// Therefore, if it is not stdin, it is a file.
3083-
if (builtin.os.tag == .windows)
3084-
continue :c_src_loop;
3085-
3086-
// On POSIX or wasm need to determine if a given path is a
3087-
// stream. 2 choices:
3088-
// 1. open + lseek. If lseek fails, it is a stream. Always 2
3089-
// syscalls.
3090-
// 2. fstat + optional open. If fstat says it's a file, return
3091-
// use it as such. If it is not a file, open and return the
3092-
// file descriptor. 1,5 syscall. Use this.
3093-
var stat_info = try std.os.fstatat(fs.cwd().fd, src.src_path, 0);
3094-
if (stat_info.mode & std.os.S.IFMT == std.os.S.IFREG)
3095-
continue :c_src_loop;
3096-
3097-
break :blk try std.os.open(src.src_path, std.os.O.RDONLY, 0);
3098-
};
3099-
defer if (close_fd) std.os.close(fd);
3100-
3101-
const new_file = try copyToFile(arena, fd, local_cache_directory);
3068+
// "-" is stdin. Dump it to a real file.
3069+
const new_file = try copyToFile(arena, io.getStdIn().handle, local_cache_directory);
31023070
try temp_files_for_comp.append(new_file);
31033071
src.src_path = new_file;
31043072
}

test/cli.zig

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

0 commit comments

Comments
 (0)