diff --git a/src/main.zig b/src/main.zig index 0ab7a5c..f426d3f 100644 --- a/src/main.zig +++ b/src/main.zig @@ -577,14 +577,19 @@ fn compileWithTimer(allocator: std.mem.Allocator, io: std.Io, input_path: []cons const obj_path = try std.fmt.allocPrintSentinel(allocator, "{s}/main.o", .{tmp_dir}, 0); - // Cache: compute key and check for cached binary/.o + // Cache: compute key and check for cached binary/.o. + // Disabled for programs with top-level #run (same guard as the JIT + // path): the #run interp runs during codegen, and skipping codegen + // loses its effects — build config (link flags, frameworks, output + // path, bundling) and print side effects alike. + const use_cache = enable_cache and !hasTopLevelRun(root); const key = computeCacheKey(source, &comp.import_sources, target_config); const cache_obj = try cachePath(allocator, key, "o"); const cache_bin = try cachePath(allocator, key, "bin"); // Level 1: Try cached binary (skip everything — no codegen, no link). // Skipped under --emit-obj, which needs the freshly-emitted object kept. - if (enable_cache and !target_config.emit_obj) bin_cache: { + if (use_cache and !target_config.emit_obj) bin_cache: { std.Io.Dir.copyFile(.cwd(), cache_bin, .cwd(), output_path, io, .{}) catch break :bin_cache; timer.record("cache"); return; @@ -592,7 +597,7 @@ fn compileWithTimer(allocator: std.mem.Allocator, io: std.Io, input_path: []cons // Level 2: Try cached .o (skip codegen+emit, still need link) const used_obj_cache = blk: { - if (!enable_cache) break :blk false; + if (!use_cache) break :blk false; std.Io.Dir.copyFile(.cwd(), cache_obj, .cwd(), obj_path, io, .{}) catch break :blk false; break :blk true; }; @@ -614,7 +619,7 @@ fn compileWithTimer(allocator: std.mem.Allocator, io: std.Io, input_path: []cons timer.record("emit"); // Save .o to cache - if (enable_cache) { + if (use_cache) { std.Io.Dir.copyFile(.cwd(), obj_path, .cwd(), cache_obj, io, .{ .make_path = true }) catch {}; } } @@ -783,7 +788,7 @@ fn compileWithTimer(allocator: std.mem.Allocator, io: std.Io, input_path: []cons } // Save linked binary to cache - if (enable_cache) { + if (use_cache) { std.Io.Dir.copyFile(.cwd(), output_path, .cwd(), cache_bin, io, .{ .make_path = true }) catch {}; }