| ... | @@ -103,6 +103,8 @@ self_exe_path: ?[]const u8, | ... | @@ -103,6 +103,8 @@ self_exe_path: ?[]const u8, |
| 103 | /// of exactly the correct size for "o/[digest]/[basename]". | 103 | /// of exactly the correct size for "o/[digest]/[basename]". |
| 104 | /// The basename is of the outputted binary file in case we don't know the directory yet. | 104 | /// The basename is of the outputted binary file in case we don't know the directory yet. |
| 105 | whole_bin_sub_path: ?[]u8, | 105 | whole_bin_sub_path: ?[]u8, |
| | 106 | /// Same as `whole_bin_sub_path` but for implibs. |
| | 107 | whole_implib_sub_path: ?[]u8, |
| 106 | zig_lib_directory: Directory, | 108 | zig_lib_directory: Directory, |
| 107 | local_cache_directory: Directory, | 109 | local_cache_directory: Directory, |
| 108 | global_cache_directory: Directory, | 110 | global_cache_directory: Directory, |
| ... | @@ -1477,6 +1479,12 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { | ... | @@ -1477,6 +1479,12 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1477 | }; | 1479 | }; |
| 1478 | } | 1480 | } |
| 1479 | | 1481 | |
| | 1482 | // This is here for the same reason as in `bin_file_emit` above. |
| | 1483 | switch (cache_mode) { |
| | 1484 | .whole => break :blk null, |
| | 1485 | .incremental => {}, |
| | 1486 | } |
| | 1487 | |
| 1480 | // Use the same directory as the bin. The CLI already emits an | 1488 | // Use the same directory as the bin. The CLI already emits an |
| 1481 | // error if -fno-emit-bin is combined with -femit-implib. | 1489 | // error if -fno-emit-bin is combined with -femit-implib. |
| 1482 | break :blk link.Emit{ | 1490 | break :blk link.Emit{ |
| ... | @@ -1491,14 +1499,9 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { | ... | @@ -1491,14 +1499,9 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1491 | // for `CacheMode.whole`. | 1499 | // for `CacheMode.whole`. |
| 1492 | // This memory will be overwritten with the real digest in update() but | 1500 | // This memory will be overwritten with the real digest in update() but |
| 1493 | // the basename will be preserved. | 1501 | // the basename will be preserved. |
| 1494 | const whole_bin_sub_path: ?[]u8 = if (options.emit_bin) |x| | 1502 | const whole_bin_sub_path: ?[]u8 = try prepareWholeEmitSubPath(arena, options.emit_bin); |
| 1495 | if (x.directory == null) | 1503 | // Same thing but for implibs. |
| 1496 | try std.fmt.allocPrint(arena, "o" ++ std.fs.path.sep_str ++ | 1504 | const whole_implib_sub_path: ?[]u8 = try prepareWholeEmitSubPath(arena, options.emit_implib); |
| 1497 | ("x" ** Cache.hex_digest_len) ++ std.fs.path.sep_str ++ "{s}", .{x.basename}) | | |
| 1498 | else | | |
| 1499 | null | | |
| 1500 | else | | |
| 1501 | null; | | |
| 1502 | | 1505 | |
| 1503 | var system_libs: std.StringArrayHashMapUnmanaged(SystemLib) = .{}; | 1506 | var system_libs: std.StringArrayHashMapUnmanaged(SystemLib) = .{}; |
| 1504 | errdefer system_libs.deinit(gpa); | 1507 | errdefer system_libs.deinit(gpa); |
| ... | @@ -1606,6 +1609,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { | ... | @@ -1606,6 +1609,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1606 | .global_cache_directory = options.global_cache_directory, | 1609 | .global_cache_directory = options.global_cache_directory, |
| 1607 | .bin_file = bin_file, | 1610 | .bin_file = bin_file, |
| 1608 | .whole_bin_sub_path = whole_bin_sub_path, | 1611 | .whole_bin_sub_path = whole_bin_sub_path, |
| | 1612 | .whole_implib_sub_path = whole_implib_sub_path, |
| 1609 | .emit_asm = options.emit_asm, | 1613 | .emit_asm = options.emit_asm, |
| 1610 | .emit_llvm_ir = options.emit_llvm_ir, | 1614 | .emit_llvm_ir = options.emit_llvm_ir, |
| 1611 | .emit_llvm_bc = options.emit_llvm_bc, | 1615 | .emit_llvm_bc = options.emit_llvm_bc, |
| ... | @@ -1988,6 +1992,12 @@ pub fn update(comp: *Compilation) !void { | ... | @@ -1988,6 +1992,12 @@ pub fn update(comp: *Compilation) !void { |
| 1988 | .sub_path = std.fs.path.basename(sub_path), | 1992 | .sub_path = std.fs.path.basename(sub_path), |
| 1989 | }; | 1993 | }; |
| 1990 | } | 1994 | } |
| | 1995 | if (comp.whole_implib_sub_path) |sub_path| { |
| | 1996 | options.implib_emit = .{ |
| | 1997 | .directory = tmp_artifact_directory.?, |
| | 1998 | .sub_path = std.fs.path.basename(sub_path), |
| | 1999 | }; |
| | 2000 | } |
| 1991 | comp.bin_file.destroy(); | 2001 | comp.bin_file.destroy(); |
| 1992 | comp.bin_file = try link.File.openPath(comp.gpa, options); | 2002 | comp.bin_file = try link.File.openPath(comp.gpa, options); |
| 1993 | } | 2003 | } |
| ... | @@ -2149,14 +2159,33 @@ pub fn update(comp: *Compilation) !void { | ... | @@ -2149,14 +2159,33 @@ pub fn update(comp: *Compilation) !void { |
| 2149 | | 2159 | |
| 2150 | /// Communicate the output binary location to parent Compilations. | 2160 | /// Communicate the output binary location to parent Compilations. |
| 2151 | fn wholeCacheModeSetBinFilePath(comp: *Compilation, digest: *const [Cache.hex_digest_len]u8) void { | 2161 | fn wholeCacheModeSetBinFilePath(comp: *Compilation, digest: *const [Cache.hex_digest_len]u8) void { |
| 2152 | const sub_path = comp.whole_bin_sub_path orelse return; | | |
| 2153 | const digest_start = 2; // "o/[digest]/[basename]" | 2162 | const digest_start = 2; // "o/[digest]/[basename]" |
| 2154 | mem.copy(u8, sub_path[digest_start..], digest); | | |
| 2155 | | 2163 | |
| 2156 | comp.bin_file.options.emit = .{ | 2164 | if (comp.whole_bin_sub_path) |sub_path| { |
| 2157 | .directory = comp.local_cache_directory, | 2165 | mem.copy(u8, sub_path[digest_start..], digest); |
| 2158 | .sub_path = sub_path, | 2166 | |
| 2159 | }; | 2167 | comp.bin_file.options.emit = .{ |
| | 2168 | .directory = comp.local_cache_directory, |
| | 2169 | .sub_path = sub_path, |
| | 2170 | }; |
| | 2171 | } |
| | 2172 | |
| | 2173 | if (comp.whole_implib_sub_path) |sub_path| { |
| | 2174 | mem.copy(u8, sub_path[digest_start..], digest); |
| | 2175 | |
| | 2176 | comp.bin_file.options.implib_emit = .{ |
| | 2177 | .directory = comp.local_cache_directory, |
| | 2178 | .sub_path = sub_path, |
| | 2179 | }; |
| | 2180 | } |
| | 2181 | } |
| | 2182 | |
| | 2183 | fn prepareWholeEmitSubPath(arena: Allocator, opt_emit: ?EmitLoc) error{OutOfMemory}!?[]u8 { |
| | 2184 | const emit = opt_emit orelse return null; |
| | 2185 | if (emit.directory != null) return null; |
| | 2186 | const s = std.fs.path.sep_str; |
| | 2187 | const format = "o" ++ s ++ ("x" ** Cache.hex_digest_len) ++ s ++ "{s}"; |
| | 2188 | return try std.fmt.allocPrint(arena, format, .{emit.basename}); |
| 2160 | } | 2189 | } |
| 2161 | | 2190 | |
| 2162 | /// This is only observed at compile-time and used to emit a compile error | 2191 | /// This is only observed at compile-time and used to emit a compile error |