| author | |
| committer | |
| log | 19aab5302c71edccae7959065062fd1695a396aa |
| tree | 942792e93fde35bbb7c0db611578b690f29e3b6a |
| parent | 43da1029200f8f8fead6bfe3995d4fb9549293fc |
Additionally ensure that the Zig cache incorporates any extra cflags when
using translate-c.
Fixes the issue identified in #86623 files changed, 29 insertions(+), 22 deletions(-)
src/Cache.zig+20-1| ... | ... | @@ -11,6 +11,7 @@ const testing = std.testing; |
| 11 | 11 | const mem = std.mem; |
| 12 | 12 | const fmt = std.fmt; |
| 13 | 13 | const Allocator = std.mem.Allocator; |
| 14 | const Compilation = @import("Compilation.zig"); | |
| 14 | 15 | |
| 15 | 16 | /// Be sure to call `Manifest.deinit` after successful initialization. |
| 16 | 17 | pub fn obtain(cache: *const Cache) Manifest { |
| ... | ... | @@ -61,7 +62,7 @@ pub const File = struct { |
| 61 | 62 | pub const HashHelper = struct { |
| 62 | 63 | hasher: Hasher = hasher_init, |
| 63 | 64 | |
| 64 | const EmitLoc = @import("Compilation.zig").EmitLoc; | |
| 65 | const EmitLoc = Compilation.EmitLoc; | |
| 65 | 66 | |
| 66 | 67 | /// Record a slice of bytes as an dependency of the process being cached |
| 67 | 68 | pub fn addBytes(hh: *HashHelper, bytes: []const u8) void { |
| ... | ... | @@ -220,6 +221,24 @@ pub const Manifest = struct { |
| 220 | 221 | return idx; |
| 221 | 222 | } |
| 222 | 223 | |
| 224 | pub fn hashCSource(self: *Manifest, c_source: Compilation.CSourceFile) !void { | |
| 225 | _ = try self.addFile(c_source.src_path, null); | |
| 226 | // Hash the extra flags, with special care to call addFile for file parameters. | |
| 227 | // TODO this logic can likely be improved by utilizing clang_options_data.zig. | |
| 228 | const file_args = [_][]const u8{"-include"}; | |
| 229 | var arg_i: usize = 0; | |
| 230 | while (arg_i < c_source.extra_flags.len) : (arg_i += 1) { | |
| 231 | const arg = c_source.extra_flags[arg_i]; | |
| 232 | self.hash.addBytes(arg); | |
| 233 | for (file_args) |file_arg| { | |
| 234 | if (mem.eql(u8, file_arg, arg) and arg_i + 1 < c_source.extra_flags.len) { | |
| 235 | arg_i += 1; | |
| 236 | _ = try self.addFile(c_source.extra_flags[arg_i], null); | |
| 237 | } | |
| 238 | } | |
| 239 | } | |
| 240 | } | |
| 241 | ||
| 223 | 242 | pub fn addOptionalFile(self: *Manifest, optional_file_path: ?[]const u8) !void { |
| 224 | 243 | self.hash.add(optional_file_path != null); |
| 225 | 244 | const file_path = optional_file_path orelse return; |
src/Compilation.zig+1-17| ... | ... | @@ -2260,23 +2260,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_comp_progress_node: * |
| 2260 | 2260 | |
| 2261 | 2261 | man.hash.add(comp.clang_preprocessor_mode); |
| 2262 | 2262 | |
| 2263 | _ = try man.addFile(c_object.src.src_path, null); | |
| 2264 | { | |
| 2265 | // Hash the extra flags, with special care to call addFile for file parameters. | |
| 2266 | // TODO this logic can likely be improved by utilizing clang_options_data.zig. | |
| 2267 | const file_args = [_][]const u8{"-include"}; | |
| 2268 | var arg_i: usize = 0; | |
| 2269 | while (arg_i < c_object.src.extra_flags.len) : (arg_i += 1) { | |
| 2270 | const arg = c_object.src.extra_flags[arg_i]; | |
| 2271 | man.hash.addBytes(arg); | |
| 2272 | for (file_args) |file_arg| { | |
| 2273 | if (mem.eql(u8, file_arg, arg) and arg_i + 1 < c_object.src.extra_flags.len) { | |
| 2274 | arg_i += 1; | |
| 2275 | _ = try man.addFile(c_object.src.extra_flags[arg_i], null); | |
| 2276 | } | |
| 2277 | } | |
| 2278 | } | |
| 2279 | } | |
| 2263 | try man.hashCSource(c_object.src); | |
| 2280 | 2264 | |
| 2281 | 2265 | { |
| 2282 | 2266 | const is_collision = blk: { |
src/main.zig+8-4| ... | ... | @@ -2172,7 +2172,7 @@ fn cmdTranslateC(comp: *Compilation, arena: *Allocator, enable_cache: bool) !voi |
| 2172 | 2172 | defer if (enable_cache) man.deinit(); |
| 2173 | 2173 | |
| 2174 | 2174 | man.hash.add(@as(u16, 0xb945)); // Random number to distinguish translate-c from compiling C objects |
| 2175 | _ = man.addFile(c_source_file.src_path, null) catch |err| { | |
| 2175 | man.hashCSource(c_source_file) catch |err| { | |
| 2176 | 2176 | fatal("unable to process '{s}': {s}", .{ c_source_file.src_path, @errorName(err) }); |
| 2177 | 2177 | }; |
| 2178 | 2178 | |
| ... | ... | @@ -2202,12 +2202,16 @@ fn cmdTranslateC(comp: *Compilation, arena: *Allocator, enable_cache: bool) !voi |
| 2202 | 2202 | } |
| 2203 | 2203 | |
| 2204 | 2204 | // Convert to null terminated args. |
| 2205 | const new_argv_with_sentinel = try arena.alloc(?[*:0]const u8, argv.items.len + 1); | |
| 2206 | new_argv_with_sentinel[argv.items.len] = null; | |
| 2207 | const new_argv = new_argv_with_sentinel[0..argv.items.len :null]; | |
| 2205 | const clang_args_len = argv.items.len + c_source_file.extra_flags.len; | |
| 2206 | const new_argv_with_sentinel = try arena.alloc(?[*:0]const u8, clang_args_len + 1); | |
| 2207 | new_argv_with_sentinel[clang_args_len] = null; | |
| 2208 | const new_argv = new_argv_with_sentinel[0..clang_args_len :null]; | |
| 2208 | 2209 | for (argv.items) |arg, i| { |
| 2209 | 2210 | new_argv[i] = try arena.dupeZ(u8, arg); |
| 2210 | 2211 | } |
| 2212 | for (c_source_file.extra_flags) |arg, i| { | |
| 2213 | new_argv[argv.items.len + i] = try arena.dupeZ(u8, arg); | |
| 2214 | } | |
| 2211 | 2215 | |
| 2212 | 2216 | const c_headers_dir_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{"include"}); |
| 2213 | 2217 | const c_headers_dir_path_z = try arena.dupeZ(u8, c_headers_dir_path); |