| ... | @@ -3110,6 +3110,21 @@ fn buildOutputType( | ... | @@ -3110,6 +3110,21 @@ fn buildOutputType( |
| 3110 | else => false, | 3110 | else => false, |
| 3111 | }; | 3111 | }; |
| 3112 | | 3112 | |
| | 3113 | const disable_lld_caching = !output_to_cache; |
| | 3114 | |
| | 3115 | const cache_mode: Compilation.CacheMode = b: { |
| | 3116 | if (disable_lld_caching) break :b .incremental; |
| | 3117 | if (!create_module.resolved_options.have_zcu) break :b .whole; |
| | 3118 | |
| | 3119 | // TODO: once we support incremental compilation for the LLVM backend |
| | 3120 | // via saving the LLVM module into a bitcode file and restoring it, |
| | 3121 | // along with compiler state, this clause can be removed so that |
| | 3122 | // incremental cache mode is used for LLVM backend too. |
| | 3123 | if (create_module.resolved_options.use_llvm) break :b .whole; |
| | 3124 | |
| | 3125 | break :b .incremental; |
| | 3126 | }; |
| | 3127 | |
| 3113 | gimmeMoreOfThoseSweetSweetFileDescriptors(); | 3128 | gimmeMoreOfThoseSweetSweetFileDescriptors(); |
| 3114 | | 3129 | |
| 3115 | const comp = Compilation.create(gpa, .{ | 3130 | const comp = Compilation.create(gpa, .{ |
| ... | @@ -3211,7 +3226,8 @@ fn buildOutputType( | ... | @@ -3211,7 +3226,8 @@ fn buildOutputType( |
| 3211 | .test_filter = test_filter, | 3226 | .test_filter = test_filter, |
| 3212 | .test_name_prefix = test_name_prefix, | 3227 | .test_name_prefix = test_name_prefix, |
| 3213 | .test_runner_path = test_runner_path, | 3228 | .test_runner_path = test_runner_path, |
| 3214 | .disable_lld_caching = !output_to_cache, | 3229 | .disable_lld_caching = disable_lld_caching, |
| | 3230 | .cache_mode = cache_mode, |
| 3215 | .subsystem = subsystem, | 3231 | .subsystem = subsystem, |
| 3216 | .debug_compile_errors = debug_compile_errors, | 3232 | .debug_compile_errors = debug_compile_errors, |
| 3217 | .enable_link_snapshots = enable_link_snapshots, | 3233 | .enable_link_snapshots = enable_link_snapshots, |
| ... | @@ -3942,7 +3958,7 @@ fn serve( | ... | @@ -3942,7 +3958,7 @@ fn serve( |
| 3942 | const hdr = try server.receiveMessage(); | 3958 | const hdr = try server.receiveMessage(); |
| 3943 | | 3959 | |
| 3944 | switch (hdr.tag) { | 3960 | switch (hdr.tag) { |
| 3945 | .exit => return, | 3961 | .exit => return cleanExit(), |
| 3946 | .update => { | 3962 | .update => { |
| 3947 | assert(main_progress_node.recently_updated_child == null); | 3963 | assert(main_progress_node.recently_updated_child == null); |
| 3948 | tracy.frameMark(); | 3964 | tracy.frameMark(); |
| ... | @@ -4104,25 +4120,63 @@ fn serveUpdateResults(s: *Server, comp: *Compilation) !void { | ... | @@ -4104,25 +4120,63 @@ fn serveUpdateResults(s: *Server, comp: *Compilation) !void { |
| 4104 | try s.serveErrorBundle(error_bundle); | 4120 | try s.serveErrorBundle(error_bundle); |
| 4105 | return; | 4121 | return; |
| 4106 | } | 4122 | } |
| 4107 | // This logic is a bit counter-intuitive because the protocol implies that | 4123 | |
| 4108 | // each emitted artifact could possibly be in a different location, when in | 4124 | // This logic is counter-intuitive because the protocol accounts for each |
| 4109 | // reality, there is only one artifact output directory, and the build | 4125 | // emitted artifact possibly being in a different location, which correctly |
| 4110 | // system depends on that fact. So, until the protocol is changed to | 4126 | // matches the behavior of the compiler, however, the build system |
| 4111 | // reflect this, this logic only needs to ensure that emit_bin_path is | 4127 | // currently always passes flags that makes all build artifacts output to |
| 4112 | // emitted for at least one thing, if there are any artifacts. | 4128 | // the same local cache directory, and relies on them all being in the same |
| 4113 | if (comp.bin_file) |lf| { | 4129 | // directory. |
| 4114 | const emit = lf.emit; | 4130 | // |
| | 4131 | // So, until the build system and protocol are changed to reflect this, |
| | 4132 | // this logic must ensure that emit_bin_path is emitted for at least one |
| | 4133 | // thing, if there are any artifacts. |
| | 4134 | |
| | 4135 | switch (comp.cache_use) { |
| | 4136 | .incremental => if (comp.bin_file) |lf| { |
| | 4137 | const full_path = try lf.emit.directory.join(gpa, &.{lf.emit.sub_path}); |
| | 4138 | defer gpa.free(full_path); |
| | 4139 | try s.serveEmitBinPath(full_path, .{ |
| | 4140 | .flags = .{ .cache_hit = comp.last_update_was_cache_hit }, |
| | 4141 | }); |
| | 4142 | return; |
| | 4143 | }, |
| | 4144 | .whole => |whole| if (whole.bin_sub_path) |sub_path| { |
| | 4145 | const full_path = try comp.local_cache_directory.join(gpa, &.{sub_path}); |
| | 4146 | defer gpa.free(full_path); |
| | 4147 | try s.serveEmitBinPath(full_path, .{ |
| | 4148 | .flags = .{ .cache_hit = comp.last_update_was_cache_hit }, |
| | 4149 | }); |
| | 4150 | return; |
| | 4151 | }, |
| | 4152 | } |
| | 4153 | |
| | 4154 | for ([_]?Compilation.Emit{ |
| | 4155 | comp.docs_emit, |
| | 4156 | comp.implib_emit, |
| | 4157 | }) |opt_emit| { |
| | 4158 | const emit = opt_emit orelse continue; |
| 4115 | const full_path = try emit.directory.join(gpa, &.{emit.sub_path}); | 4159 | const full_path = try emit.directory.join(gpa, &.{emit.sub_path}); |
| 4116 | defer gpa.free(full_path); | 4160 | defer gpa.free(full_path); |
| 4117 | try s.serveEmitBinPath(full_path, .{ | 4161 | try s.serveEmitBinPath(full_path, .{ |
| 4118 | .flags = .{ .cache_hit = comp.last_update_was_cache_hit }, | 4162 | .flags = .{ .cache_hit = comp.last_update_was_cache_hit }, |
| 4119 | }); | 4163 | }); |
| 4120 | } else if (comp.docs_emit) |emit| { | 4164 | return; |
| 4121 | const full_path = try emit.directory.join(gpa, &.{emit.sub_path}); | 4165 | } |
| | 4166 | |
| | 4167 | for ([_]?Compilation.EmitLoc{ |
| | 4168 | comp.emit_asm, |
| | 4169 | comp.emit_llvm_ir, |
| | 4170 | comp.emit_llvm_bc, |
| | 4171 | }) |opt_emit_loc| { |
| | 4172 | const emit_loc = opt_emit_loc orelse continue; |
| | 4173 | const directory = emit_loc.directory orelse continue; |
| | 4174 | const full_path = try directory.join(gpa, &.{emit_loc.basename}); |
| 4122 | defer gpa.free(full_path); | 4175 | defer gpa.free(full_path); |
| 4123 | try s.serveEmitBinPath(full_path, .{ | 4176 | try s.serveEmitBinPath(full_path, .{ |
| 4124 | .flags = .{ .cache_hit = comp.last_update_was_cache_hit }, | 4177 | .flags = .{ .cache_hit = comp.last_update_was_cache_hit }, |
| 4125 | }); | 4178 | }); |
| | 4179 | return; |
| 4126 | } | 4180 | } |
| 4127 | } | 4181 | } |
| 4128 | | 4182 | |