aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
authorMotiejus Jakštys <motiejus@uber.com>2023-01-23 21:59:03 +0200
committerAndrew Kelley <andrew@ziglang.org>2023-05-16 16:40:58 -0700
commit2e692312f104e1e5533c9f389d73488ea4a1ef68 (patch)
tree41c075be8388dc374bfd2f01973a6f8dfb612939 /src/Compilation.zig
parentb754068fbc7492962953068d31386d4c04e37ae5 (diff)
downloadzig-2e692312f104e1e5533c9f389d73488ea4a1ef68.tar.gz
zig-2e692312f104e1e5533c9f389d73488ea4a1ef68.zip
zig cc: support reading from non-files
echo 'some C program' | $CC -x c - Is a common pattern to test for compiler or linker features. This patch adds support for reading from non-regular files. This will make at least one more Go test to pass.
Diffstat (limited to 'src/Compilation.zig')
-rw-r--r--src/Compilation.zig20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 1b6d805bb3..3ae43773e3 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -3981,7 +3981,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
// 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);
+ const out_obj_path = try comp.local_cache_directory.tmpFilePath(arena, o_basename);
var zig_cache_tmp_dir = try comp.local_cache_directory.handle.makeOpenPath("tmp", .{});
defer zig_cache_tmp_dir.close();
@@ -4129,16 +4129,6 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
};
}
-pub fn tmpFilePath(comp: *Compilation, ally: Allocator, suffix: []const u8) error{OutOfMemory}![]const u8 {
- const s = std.fs.path.sep_str;
- const rand_int = std.crypto.random.int(u64);
- if (comp.local_cache_directory.path) |p| {
- return std.fmt.allocPrint(ally, "{s}" ++ s ++ "tmp" ++ s ++ "{x}-{s}", .{ p, rand_int, suffix });
- } else {
- return std.fmt.allocPrint(ally, "tmp" ++ s ++ "{x}-{s}", .{ rand_int, suffix });
- }
-}
-
pub fn addTranslateCCArgs(
comp: *Compilation,
arena: Allocator,
@@ -4597,6 +4587,14 @@ pub const FileExt = enum {
=> false,
};
}
+
+ // maximum length of @tagName(ext: FileExt)
+ pub const max_len = blk: {
+ var max: u16 = 0;
+ inline for (std.meta.tags(FileExt)) |ext|
+ max = std.math.max(@tagName(ext).len, max);
+ break :blk max;
+ };
};
pub fn hasObjectExt(filename: []const u8) bool {