| ... | @@ -427,6 +427,13 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | ... | @@ -427,6 +427,13 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 427 | // modified between incremental updates. | 427 | // modified between incremental updates. |
| 428 | var hash = cache.hash; | 428 | var hash = cache.hash; |
| 429 | | 429 | |
| | 430 | // Here we put the root source file path name, but *not* with addFile. We want the |
| | 431 | // hash to be the same regardless of the contents of the source file, because |
| | 432 | // incremental compilation will handle it, but we do want to namespace different |
| | 433 | // source file names because they are likely different compilations and therefore this |
| | 434 | // would be likely to cause cache hits. |
| | 435 | hash.addBytes(root_pkg.root_src_path); |
| | 436 | hash.addOptionalBytes(root_pkg.root_src_directory.path); |
| 430 | hash.add(valgrind); | 437 | hash.add(valgrind); |
| 431 | hash.add(single_threaded); | 438 | hash.add(single_threaded); |
| 432 | switch (options.target.os.getVersionRange()) { | 439 | switch (options.target.os.getVersionRange()) { |
| ... | @@ -512,7 +519,17 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | ... | @@ -512,7 +519,17 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 512 | const bin_directory = emit_bin.directory orelse blk: { | 519 | const bin_directory = emit_bin.directory orelse blk: { |
| 513 | if (module) |zm| break :blk zm.zig_cache_artifact_directory; | 520 | if (module) |zm| break :blk zm.zig_cache_artifact_directory; |
| 514 | | 521 | |
| 515 | const digest = cache.hash.peek(); | 522 | // We could use the cache hash as is no problem, however, we increase |
| | 523 | // the likelihood of cache hits by adding the first C source file |
| | 524 | // path name (not contents) to the hash. This way if the user is compiling |
| | 525 | // foo.c and bar.c as separate compilations, they get different cache |
| | 526 | // directories. |
| | 527 | var hash = cache.hash; |
| | 528 | if (options.c_source_files.len >= 1) { |
| | 529 | hash.addBytes(options.c_source_files[0].src_path); |
| | 530 | } |
| | 531 | |
| | 532 | const digest = hash.final(); |
| 516 | const artifact_sub_dir = try std.fs.path.join(arena, &[_][]const u8{ "o", &digest }); | 533 | const artifact_sub_dir = try std.fs.path.join(arena, &[_][]const u8{ "o", &digest }); |
| 517 | var artifact_dir = try options.zig_cache_directory.handle.makeOpenPath(artifact_sub_dir, .{}); | 534 | var artifact_dir = try options.zig_cache_directory.handle.makeOpenPath(artifact_sub_dir, .{}); |
| 518 | owned_link_dir = artifact_dir; | 535 | owned_link_dir = artifact_dir; |