| ... | @@ -19,8 +19,6 @@ const PkgConfig = @import("../PkgConfig.zig"); | ... | @@ -19,8 +19,6 @@ const PkgConfig = @import("../PkgConfig.zig"); |
| 19 | /// Populated when there is compiler process that lives across multiple calls | 19 | /// Populated when there is compiler process that lives across multiple calls |
| 20 | /// to `make`. | 20 | /// to `make`. |
| 21 | zig_process: ?*Step.ZigProcess = null, | 21 | zig_process: ?*Step.ZigProcess = null, |
| 22 | /// Persisted to reuse memory on subsequent calls to `make`. | | |
| 23 | zig_args: std.ArrayList([]const u8) = .empty, | | |
| 24 | /// Populated by InstallArtifact. | 22 | /// Populated by InstallArtifact. |
| 25 | installed_path: ?Path = null, | 23 | installed_path: ?Path = null, |
| 26 | /// Populated by `make`, used by `Run`. | 24 | /// Populated by `make`, used by `Run`. |
| ... | @@ -33,25 +31,29 @@ pub fn make( | ... | @@ -33,25 +31,29 @@ pub fn make( |
| 33 | progress_node: std.Progress.Node, | 31 | progress_node: std.Progress.Node, |
| 34 | ) Step.ExtendedMakeError!void { | 32 | ) Step.ExtendedMakeError!void { |
| 35 | const graph = maker.graph; | 33 | const graph = maker.graph; |
| 36 | const arena = graph.arena; // TODO don't leak into process arena | 34 | const gpa = maker.gpa; |
| 37 | const conf = &maker.scanned_config.configuration; | 35 | const conf = &maker.scanned_config.configuration; |
| 38 | const conf_step = compile_index.ptr(conf); | 36 | const conf_step = compile_index.ptr(conf); |
| 39 | const conf_comp = conf_step.extended.get(conf.extra).compile; | 37 | const conf_comp = conf_step.extended.get(conf.extra).compile; |
| 40 | | 38 | |
| 41 | // Reset / repopulate persistent state. | 39 | var arena_allocator: std.heap.ArenaAllocator = .init(gpa); |
| 42 | compile.zig_args.clearRetainingCapacity(); | 40 | defer arena_allocator.deinit(); |
| | 41 | const arena = arena_allocator.allocator(); |
| | 42 | |
| | 43 | var argv: std.ArrayList([]const u8) = .empty; |
| | 44 | defer argv.deinit(gpa); |
| 43 | | 45 | |
| 44 | try lowerZigArgs(compile, compile_index, maker, progress_node, &compile.zig_args, false); | 46 | try lowerZigArgs(arena, compile, compile_index, maker, progress_node, &argv, false); |
| 45 | | 47 | |
| 46 | const maybe_output_dir = Step.evalZigProcess( | 48 | const maybe_output_dir = Step.evalZigProcess( |
| 47 | compile_index, | 49 | compile_index, |
| 48 | maker, | 50 | maker, |
| 49 | compile.zig_args.items, | 51 | argv.items, |
| 50 | progress_node, | 52 | progress_node, |
| 51 | (graph.incremental == true) and (maker.watch or maker.web_server != null), | 53 | (graph.incremental == true) and (maker.watch or maker.web_server != null), |
| 52 | ) catch |err| switch (err) { | 54 | ) catch |err| switch (err) { |
| 53 | error.NeedCompileErrorCheck => { | 55 | error.NeedCompileErrorCheck => { |
| 54 | try checkCompileErrors(maker, compile_index); | 56 | try checkCompileErrors(arena, maker, compile_index); |
| 55 | return; | 57 | return; |
| 56 | }, | 58 | }, |
| 57 | else => |e| return e, | 59 | else => |e| return e, |
| ... | @@ -63,14 +65,14 @@ pub fn make( | ... | @@ -63,14 +65,14 @@ pub fn make( |
| 63 | // Update generated files | 65 | // Update generated files |
| 64 | if (maybe_output_dir) |output_dir| { | 66 | if (maybe_output_dir) |output_dir| { |
| 65 | if (conf_comp.emit_directory.value) |gf| maker.generatedPath(gf).* = output_dir; | 67 | if (conf_comp.emit_directory.value) |gf| maker.generatedPath(gf).* = output_dir; |
| 66 | try updateGeneratedFile(&conf_comp, maker, output_dir, &target, conf_comp.generated_bin.value, .bin); | 68 | try updateGeneratedFile(maker, arena, &conf_comp, output_dir, &target, conf_comp.generated_bin.value, .bin); |
| 67 | try updateGeneratedFile(&conf_comp, maker, output_dir, &target, conf_comp.generated_pdb.value, .pdb); | 69 | try updateGeneratedFile(maker, arena, &conf_comp, output_dir, &target, conf_comp.generated_pdb.value, .pdb); |
| 68 | try updateGeneratedFile(&conf_comp, maker, output_dir, &target, conf_comp.generated_implib.value, .implib); | 70 | try updateGeneratedFile(maker, arena, &conf_comp, output_dir, &target, conf_comp.generated_implib.value, .implib); |
| 69 | try updateGeneratedFile(&conf_comp, maker, output_dir, &target, conf_comp.generated_h.value, .h); | 71 | try updateGeneratedFile(maker, arena, &conf_comp, output_dir, &target, conf_comp.generated_h.value, .h); |
| 70 | try updateGeneratedFile(&conf_comp, maker, output_dir, &target, conf_comp.generated_docs.value, .docs); | 72 | try updateGeneratedFile(maker, arena, &conf_comp, output_dir, &target, conf_comp.generated_docs.value, .docs); |
| 71 | try updateGeneratedFile(&conf_comp, maker, output_dir, &target, conf_comp.generated_asm.value, .@"asm"); | 73 | try updateGeneratedFile(maker, arena, &conf_comp, output_dir, &target, conf_comp.generated_asm.value, .@"asm"); |
| 72 | try updateGeneratedFile(&conf_comp, maker, output_dir, &target, conf_comp.generated_llvm_ir.value, .llvm_ir); | 74 | try updateGeneratedFile(maker, arena, &conf_comp, output_dir, &target, conf_comp.generated_llvm_ir.value, .llvm_ir); |
| 73 | try updateGeneratedFile(&conf_comp, maker, output_dir, &target, conf_comp.generated_llvm_bc.value, .llvm_bc); | 75 | try updateGeneratedFile(maker, arena, &conf_comp, output_dir, &target, conf_comp.generated_llvm_bc.value, .llvm_bc); |
| 74 | } | 76 | } |
| 75 | | 77 | |
| 76 | if (conf_comp.flags3.kind == .lib and conf_comp.flags2.linkage == .dynamic and | 78 | if (conf_comp.flags3.kind == .lib and conf_comp.flags2.linkage == .dynamic and |
| ... | @@ -84,8 +86,9 @@ pub fn make( | ... | @@ -84,8 +86,9 @@ pub fn make( |
| 84 | } | 86 | } |
| 85 | | 87 | |
| 86 | fn updateGeneratedFile( | 88 | fn updateGeneratedFile( |
| 87 | conf_comp: *const Configuration.Step.Compile, | | |
| 88 | maker: *Maker, | 89 | maker: *Maker, |
| | 90 | arena: Allocator, |
| | 91 | conf_comp: *const Configuration.Step.Compile, |
| 89 | out_path: std.Build.Cache.Path, | 92 | out_path: std.Build.Cache.Path, |
| 90 | target: *const Configuration.TargetQuery, | 93 | target: *const Configuration.TargetQuery, |
| 91 | opt_gf: ?Configuration.GeneratedFileIndex, | 94 | opt_gf: ?Configuration.GeneratedFileIndex, |
| ... | @@ -94,7 +97,6 @@ fn updateGeneratedFile( | ... | @@ -94,7 +97,6 @@ fn updateGeneratedFile( |
| 94 | const gf = opt_gf orelse return; | 97 | const gf = opt_gf orelse return; |
| 95 | const graph = maker.graph; | 98 | const graph = maker.graph; |
| 96 | const conf = &maker.scanned_config.configuration; | 99 | const conf = &maker.scanned_config.configuration; |
| 97 | const arena = graph.arena; // TODO don't leak into process arena | | |
| 98 | const name = try ea.cacheName(arena, .{ | 100 | const name = try ea.cacheName(arena, .{ |
| 99 | .root_name = conf_comp.root_name.slice(conf), | 101 | .root_name = conf_comp.root_name.slice(conf), |
| 100 | .cpu_arch = target.flags.cpu_arch.unwrap().?, | 102 | .cpu_arch = target.flags.cpu_arch.unwrap().?, |
| ... | @@ -112,7 +114,7 @@ fn updateGeneratedFile( | ... | @@ -112,7 +114,7 @@ fn updateGeneratedFile( |
| 112 | else | 114 | else |
| 113 | null, | 115 | null, |
| 114 | }); | 116 | }); |
| 115 | maker.generatedPath(gf).* = try out_path.join(arena, name); | 117 | maker.generatedPath(gf).* = try out_path.join(graph.arena, name); |
| 116 | } | 118 | } |
| 117 | | 119 | |
| 118 | /// List of importable modules in a compilation's module graph, including | 120 | /// List of importable modules in a compilation's module graph, including |
| ... | @@ -147,6 +149,7 @@ const ModuleListContext = struct { | ... | @@ -147,6 +149,7 @@ const ModuleListContext = struct { |
| 147 | }; | 149 | }; |
| 148 | | 150 | |
| 149 | fn lowerZigArgs( | 151 | fn lowerZigArgs( |
| | 152 | arena: Allocator, |
| 150 | compile: *Compile, | 153 | compile: *Compile, |
| 151 | compile_index: Configuration.Step.Index, | 154 | compile_index: Configuration.Step.Index, |
| 152 | maker: *Maker, | 155 | maker: *Maker, |
| ... | @@ -156,7 +159,6 @@ fn lowerZigArgs( | ... | @@ -156,7 +159,6 @@ fn lowerZigArgs( |
| 156 | ) Step.ExtendedMakeError!void { | 159 | ) Step.ExtendedMakeError!void { |
| 157 | const step = maker.stepByIndex(compile_index); | 160 | const step = maker.stepByIndex(compile_index); |
| 158 | const graph = maker.graph; | 161 | const graph = maker.graph; |
| 159 | const arena = graph.arena; // TODO don't leak into the process arena | | |
| 160 | const gpa = maker.gpa; | 162 | const gpa = maker.gpa; |
| 161 | const conf = &maker.scanned_config.configuration; | 163 | const conf = &maker.scanned_config.configuration; |
| 162 | const conf_step = compile_index.ptr(conf); | 164 | const conf_step = compile_index.ptr(conf); |
| ... | @@ -508,7 +510,7 @@ fn lowerZigArgs( | ... | @@ -508,7 +510,7 @@ fn lowerZigArgs( |
| 508 | if (cli_named_modules.modules.getIndex(mod_index)) |module_cli_index| { | 510 | if (cli_named_modules.modules.getIndex(mod_index)) |module_cli_index| { |
| 509 | const module_cli_name = cli_named_modules.names.keys()[module_cli_index]; | 511 | const module_cli_name = cli_named_modules.names.keys()[module_cli_index]; |
| 510 | const module_index = cli_named_modules.modules.keys()[module_cli_index]; | 512 | const module_index = cli_named_modules.modules.keys()[module_cli_index]; |
| 511 | try appendModuleFlags(module_index, zig_args, compile_index, maker); | 513 | try appendModuleFlags(arena, module_index, zig_args, compile_index, maker); |
| 512 | | 514 | |
| 513 | const imports = mod.import_table.get(conf).imports.mal; | 515 | const imports = mod.import_table.get(conf).imports.mal; |
| 514 | | 516 | |
| ... | @@ -953,21 +955,23 @@ pub fn rebuildInFuzzMode( | ... | @@ -953,21 +955,23 @@ pub fn rebuildInFuzzMode( |
| 953 | const gpa = maker.gpa; | 955 | const gpa = maker.gpa; |
| 954 | const step = maker.stepByIndex(compile_index); | 956 | const step = maker.stepByIndex(compile_index); |
| 955 | | 957 | |
| | 958 | var arena_allocator: std.heap.ArenaAllocator = .init(gpa); |
| | 959 | defer arena_allocator.deinit(); |
| | 960 | const arena = arena_allocator.allocator(); |
| | 961 | |
| 956 | step.result_error_msgs.clearRetainingCapacity(); | 962 | step.result_error_msgs.clearRetainingCapacity(); |
| 957 | step.result_stderr = ""; | 963 | step.result_stderr = ""; |
| 958 | | 964 | |
| 959 | step.result_error_bundle.deinit(gpa); | 965 | step.result_error_bundle.deinit(gpa); |
| 960 | step.result_error_bundle = std.zig.ErrorBundle.empty; | 966 | step.result_error_bundle = std.zig.ErrorBundle.empty; |
| 961 | | 967 | |
| 962 | if (step.result_failed_command) |cmd| { | 968 | step.clearFailedCommand(gpa); |
| 963 | gpa.free(cmd); | 969 | |
| 964 | step.result_failed_command = null; | 970 | var argv: std.ArrayList([]const u8) = .empty; |
| 965 | } | 971 | defer argv.deinit(gpa); |
| 966 | | 972 | |
| 967 | const zig_args = &compile.zig_args; | 973 | try lowerZigArgs(arena, compile, compile_index, maker, progress_node, &argv, true); |
| 968 | zig_args.clearRetainingCapacity(); | 974 | const maybe_output_bin_path = try Step.evalZigProcess(compile_index, maker, argv.items, progress_node, false); |
| 969 | try lowerZigArgs(compile, compile_index, maker, progress_node, zig_args, true); | | |
| 970 | const maybe_output_bin_path = try Step.evalZigProcess(compile_index, maker, zig_args.items, progress_node, false); | | |
| 971 | return maybe_output_bin_path.?; | 975 | return maybe_output_bin_path.?; |
| 972 | } | 976 | } |
| 973 | | 977 | |
| ... | @@ -980,10 +984,8 @@ fn addFlag(gpa: Allocator, args: *std.ArrayList([]const u8), comptime name: []co | ... | @@ -980,10 +984,8 @@ fn addFlag(gpa: Allocator, args: *std.ArrayList([]const u8), comptime name: []co |
| 980 | try args.append(gpa, if (cond) "-f" ++ name else "-fno-" ++ name); | 984 | try args.append(gpa, if (cond) "-f" ++ name else "-fno-" ++ name); |
| 981 | } | 985 | } |
| 982 | | 986 | |
| 983 | fn checkCompileErrors(maker: *Maker, step_index: Configuration.Step.Index) Step.ExtendedMakeError!void { | 987 | fn checkCompileErrors(arena: Allocator, maker: *Maker, step_index: Configuration.Step.Index) Step.ExtendedMakeError!void { |
| 984 | const step = maker.stepByIndex(step_index); | 988 | const step = maker.stepByIndex(step_index); |
| 985 | const graph = maker.graph; | | |
| 986 | const arena = graph.arena; // TODO don't leak into the process arena | | |
| 987 | const conf = &maker.scanned_config.configuration; | 989 | const conf = &maker.scanned_config.configuration; |
| 988 | const conf_step = step_index.ptr(conf); | 990 | const conf_step = step_index.ptr(conf); |
| 989 | const conf_comp = conf_step.extended.get(conf.extra).compile; | 991 | const conf_comp = conf_step.extended.get(conf.extra).compile; |
| ... | @@ -1226,14 +1228,13 @@ fn getModuleList( | ... | @@ -1226,14 +1228,13 @@ fn getModuleList( |
| 1226 | } | 1228 | } |
| 1227 | | 1229 | |
| 1228 | fn appendModuleFlags( | 1230 | fn appendModuleFlags( |
| | 1231 | arena: Allocator, |
| 1229 | module_index: Configuration.Module.Index, | 1232 | module_index: Configuration.Module.Index, |
| 1230 | zig_args: *std.ArrayList([]const u8), | 1233 | zig_args: *std.ArrayList([]const u8), |
| 1231 | asking_step: Configuration.Step.Index, | 1234 | asking_step: Configuration.Step.Index, |
| 1232 | maker: *const Maker, | 1235 | maker: *const Maker, |
| 1233 | ) !void { | 1236 | ) !void { |
| 1234 | const gpa = maker.gpa; | 1237 | const gpa = maker.gpa; |
| 1235 | const graph = maker.graph; | | |
| 1236 | const arena = graph.arena; // TODO don't leak into the process arena | | |
| 1237 | const conf = &maker.scanned_config.configuration; | 1238 | const conf = &maker.scanned_config.configuration; |
| 1238 | const m = module_index.get(conf); | 1239 | const m = module_index.get(conf); |
| 1239 | | 1240 | |
| ... | @@ -1317,7 +1318,7 @@ fn appendModuleFlags( | ... | @@ -1317,7 +1318,7 @@ fn appendModuleFlags( |
| 1317 | | 1318 | |
| 1318 | try zig_args.ensureUnusedCapacity(gpa, 2 * m.include_dirs.len); | 1319 | try zig_args.ensureUnusedCapacity(gpa, 2 * m.include_dirs.len); |
| 1319 | for (0..m.include_dirs.len) |i| | 1320 | for (0..m.include_dirs.len) |i| |
| 1320 | try appendIncludeDirFlags(m.include_dirs.get(conf.extra, i), zig_args, asking_step, maker); | 1321 | try appendIncludeDirFlags(arena, m.include_dirs.get(conf.extra, i), zig_args, asking_step, maker); |
| 1321 | | 1322 | |
| 1322 | try zig_args.ensureUnusedCapacity(gpa, m.c_macros.slice.len); | 1323 | try zig_args.ensureUnusedCapacity(gpa, m.c_macros.slice.len); |
| 1323 | for (m.c_macros.slice) |c_macro| | 1324 | for (m.c_macros.slice) |c_macro| |
| ... | @@ -1344,13 +1345,12 @@ fn appendModuleFlags( | ... | @@ -1344,13 +1345,12 @@ fn appendModuleFlags( |
| 1344 | | 1345 | |
| 1345 | /// Assumes unused capacity for at least 2 items. | 1346 | /// Assumes unused capacity for at least 2 items. |
| 1346 | pub fn appendIncludeDirFlags( | 1347 | pub fn appendIncludeDirFlags( |
| | 1348 | arena: Allocator, |
| 1347 | include_dir: Configuration.Module.IncludeDir, | 1349 | include_dir: Configuration.Module.IncludeDir, |
| 1348 | zig_args: *std.ArrayList([]const u8), | 1350 | zig_args: *std.ArrayList([]const u8), |
| 1349 | asking_step: Configuration.Step.Index, | 1351 | asking_step: Configuration.Step.Index, |
| 1350 | maker: *const Maker, | 1352 | maker: *const Maker, |
| 1351 | ) !void { | 1353 | ) !void { |
| 1352 | const graph = maker.graph; | | |
| 1353 | const arena = graph.arena; // TODO don't leak into the process arena | | |
| 1354 | const conf = &maker.scanned_config.configuration; | 1354 | const conf = &maker.scanned_config.configuration; |
| 1355 | | 1355 | |
| 1356 | switch (include_dir) { | 1356 | switch (include_dir) { |