From 0d4db8828a9efc05b5c3622098a8337de0b62d1e Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 25 Feb 2019 14:03:36 -0500 Subject: `@cImport` works with `--cache on` We pass -MD -MF args to clang when doing `@cImport`, which gives us a complete list of files that the C code read from. Then we add these to the cache. So even when using `@cImport` Zig's caching system remains perfect. This is a proof of concept for the mechanism that the self-hosted compiler will use to watch and rebuild files. --- src/os.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/os.cpp') diff --git a/src/os.cpp b/src/os.cpp index 95febca9bc..f52325af00 100644 --- a/src/os.cpp +++ b/src/os.cpp @@ -1232,6 +1232,18 @@ static Error os_buf_to_tmp_file_posix(Buf *contents, Buf *suffix, Buf *out_tmp_p } #endif +Buf *os_tmp_filename(Buf *prefix, Buf *suffix) { + Buf *result = buf_create_from_buf(prefix); + + const char base64[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"; + assert(array_length(base64) == 64 + 1); + for (size_t i = 0; i < 12; i += 1) { + buf_append_char(result, base64[rand() % 64]); + } + buf_append_buf(result, suffix); + return result; +} + #if defined(ZIG_OS_WINDOWS) static Error os_buf_to_tmp_file_windows(Buf *contents, Buf *suffix, Buf *out_tmp_path) { char tmp_dir[MAX_PATH + 1]; -- cgit v1.2.3