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