| ... | @@ -10,6 +10,7 @@ const Io = std.Io; | ... | @@ -10,6 +10,7 @@ const Io = std.Io; |
| 10 | const Sha256 = std.crypto.hash.sha2.Sha256; | 10 | const Sha256 = std.crypto.hash.sha2.Sha256; |
| 11 | const assert = std.debug.assert; | 11 | const assert = std.debug.assert; |
| 12 | const mem = std.mem; | 12 | const mem = std.mem; |
| | 13 | const allocPrint = std.fmt.allocPrint; |
| 13 | | 14 | |
| 14 | const Step = @import("../Step.zig"); | 15 | const Step = @import("../Step.zig"); |
| 15 | const Maker = @import("../../Maker.zig"); | 16 | const Maker = @import("../../Maker.zig"); |
| ... | @@ -17,6 +18,8 @@ const Maker = @import("../../Maker.zig"); | ... | @@ -17,6 +18,8 @@ const Maker = @import("../../Maker.zig"); |
| 17 | /// Populated during the make phase when there is a long-lived compiler process. | 18 | /// Populated during the make phase when there is a long-lived compiler process. |
| 18 | /// Managed by the build runner, not user build script. | 19 | /// Managed by the build runner, not user build script. |
| 19 | zig_process: ?*Step.ZigProcess = null, | 20 | zig_process: ?*Step.ZigProcess = null, |
| | 21 | /// Persisted to reuse memory on subsequent make. |
| | 22 | zig_args: std.ArrayList([]const u8) = .empty, |
| 20 | | 23 | |
| 21 | pub fn make( | 24 | pub fn make( |
| 22 | compile: *Compile, | 25 | compile: *Compile, |
| ... | @@ -24,14 +27,15 @@ pub fn make( | ... | @@ -24,14 +27,15 @@ pub fn make( |
| 24 | maker: *Maker, | 27 | maker: *Maker, |
| 25 | progress_node: std.Progress.Node, | 28 | progress_node: std.Progress.Node, |
| 26 | ) Step.ExtendedMakeError!void { | 29 | ) Step.ExtendedMakeError!void { |
| 27 | if (true) @panic("TODO implement compile.make()"); | | |
| 28 | const graph = maker.graph; | 30 | const graph = maker.graph; |
| 29 | const step = maker.stepByIndex(step_index); | 31 | const step = maker.stepByIndex(step_index); |
| 30 | const zig_args = try getZigArgs(compile, maker, false); | 32 | compile.zig_args.clearRetainingCapacity(); |
| | 33 | if (true) @panic("TODO implement compile.make()"); |
| | 34 | try lowerZigArgs(compile, step_index, maker, &compile.zig_args, false); |
| 31 | const process_arena = graph.arena; // TODO don't leak into the process_arena | 35 | const process_arena = graph.arena; // TODO don't leak into the process_arena |
| 32 | | 36 | |
| 33 | const maybe_output_dir = step.evalZigProcess( | 37 | const maybe_output_dir = step.evalZigProcess( |
| 34 | zig_args, | 38 | compile.zig_args.items, |
| 35 | progress_node, | 39 | progress_node, |
| 36 | (graph.incremental == true) and (maker.watch or maker.web_server != null), | 40 | (graph.incremental == true) and (maker.watch or maker.web_server != null), |
| 37 | maker, | 41 | maker, |
| ... | @@ -47,7 +51,7 @@ pub fn make( | ... | @@ -47,7 +51,7 @@ pub fn make( |
| 47 | // Update generated files | 51 | // Update generated files |
| 48 | if (maybe_output_dir) |output_dir| { | 52 | if (maybe_output_dir) |output_dir| { |
| 49 | if (compile.emit_directory) |lp| { | 53 | if (compile.emit_directory) |lp| { |
| 50 | lp.path = try std.fmt.allocPrint(process_arena, "{f}", .{output_dir}); | 54 | lp.path = try allocPrint(process_arena, "{f}", .{output_dir}); |
| 51 | } | 55 | } |
| 52 | | 56 | |
| 53 | // zig fmt: off | 57 | // zig fmt: off |
| ... | @@ -70,23 +74,26 @@ pub fn make( | ... | @@ -70,23 +74,26 @@ pub fn make( |
| 70 | { | 74 | { |
| 71 | try doAtomicSymLinks( | 75 | try doAtomicSymLinks( |
| 72 | step, | 76 | step, |
| 73 | compile.getEmittedBin().getPath2(step.owner, step), | 77 | compile.getEmittedBin().getPath2(step), |
| 74 | compile.major_only_filename.?, | 78 | compile.major_only_filename.?, |
| 75 | compile.name_only_filename.?, | 79 | compile.name_only_filename.?, |
| 76 | ); | 80 | ); |
| 77 | } | 81 | } |
| 78 | } | 82 | } |
| 79 | | 83 | |
| 80 | fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { | 84 | fn lowerZigArgs( |
| 81 | const step = &compile.step; | 85 | compile: *Compile, |
| 82 | const b = step.owner; | 86 | step_index: Configuration.Step.Index, |
| | 87 | maker: *Maker, |
| | 88 | zig_args: *std.ArrayList([]const u8), |
| | 89 | fuzz: bool, |
| | 90 | ) Allocator.Error!void { |
| | 91 | const step = maker.stepByIndex(step_index); |
| 83 | const graph = maker.graph; | 92 | const graph = maker.graph; |
| 84 | const arena = graph.arena; // TODO don't leak into the process arena | 93 | const arena = graph.arena; // TODO don't leak into the process arena |
| | 94 | const gpa = maker.gpa; |
| 85 | | 95 | |
| 86 | var zig_args = std.array_list.Managed([]const u8).init(arena); | 96 | try zig_args.append(gpa, graph.zig_exe); |
| 87 | defer zig_args.deinit(); | | |
| 88 | | | |
| 89 | try zig_args.append(graph.zig_exe); | | |
| 90 | | 97 | |
| 91 | const cmd = switch (compile.kind) { | 98 | const cmd = switch (compile.kind) { |
| 92 | .lib => "build-lib", | 99 | .lib => "build-lib", |
| ... | @@ -95,10 +102,10 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { | ... | @@ -95,10 +102,10 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 95 | .@"test" => "test", | 102 | .@"test" => "test", |
| 96 | .test_obj => "test-obj", | 103 | .test_obj => "test-obj", |
| 97 | }; | 104 | }; |
| 98 | try zig_args.append(cmd); | 105 | try zig_args.append(gpa, cmd); |
| 99 | | 106 | |
| 100 | if (b.reference_trace) |some| { | 107 | if (graph.reference_trace) |some| { |
| 101 | try zig_args.append(try std.fmt.allocPrint(arena, "-freference-trace={d}", .{some})); | 108 | try zig_args.append(gpa, try allocPrint(arena, "-freference-trace={d}", .{some})); |
| 102 | } | 109 | } |
| 103 | try addFlag(&zig_args, "allow-so-scripts", compile.allow_so_scripts orelse graph.allow_so_scripts); | 110 | try addFlag(&zig_args, "allow-so-scripts", compile.allow_so_scripts orelse graph.allow_so_scripts); |
| 104 | | 111 | |
| ... | @@ -107,33 +114,31 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { | ... | @@ -107,33 +114,31 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 107 | try addFlag(&zig_args, "new-linker", compile.use_new_linker); | 114 | try addFlag(&zig_args, "new-linker", compile.use_new_linker); |
| 108 | | 115 | |
| 109 | if (compile.root_module.resolved_target.?.query.ofmt) |ofmt| { | 116 | if (compile.root_module.resolved_target.?.query.ofmt) |ofmt| { |
| 110 | try zig_args.append(try std.fmt.allocPrint(arena, "-ofmt={s}", .{@tagName(ofmt)})); | 117 | try zig_args.append(gpa, try allocPrint(arena, "-ofmt={t}", .{ofmt})); |
| 111 | } | 118 | } |
| 112 | | 119 | |
| 113 | switch (compile.entry) { | 120 | switch (compile.entry) { |
| 114 | .default => {}, | 121 | .default => {}, |
| 115 | .disabled => try zig_args.append("-fno-entry"), | 122 | .disabled => try zig_args.append(gpa, "-fno-entry"), |
| 116 | .enabled => try zig_args.append("-fentry"), | 123 | .enabled => try zig_args.append(gpa, "-fentry"), |
| 117 | .symbol_name => |entry_name| { | 124 | .symbol_name => |entry_name| { |
| 118 | try zig_args.append(try std.fmt.allocPrint(arena, "-fentry={s}", .{entry_name})); | 125 | try zig_args.append(gpa, try allocPrint(arena, "-fentry={s}", .{entry_name})); |
| 119 | }, | 126 | }, |
| 120 | } | 127 | } |
| 121 | | 128 | |
| 122 | { | 129 | { |
| 123 | for (compile.force_undefined_symbols.keys()) |symbol_name| { | 130 | for (compile.force_undefined_symbols.keys()) |symbol_name| { |
| 124 | try zig_args.append("--force_undefined"); | 131 | try zig_args.append(gpa, "--force_undefined"); |
| 125 | try zig_args.append(symbol_name.*); | 132 | try zig_args.append(gpa, symbol_name.*); |
| 126 | } | 133 | } |
| 127 | } | 134 | } |
| 128 | | 135 | |
| 129 | if (compile.stack_size) |stack_size| { | 136 | if (compile.stack_size) |stack_size| { |
| 130 | try zig_args.append("--stack"); | 137 | try zig_args.append(gpa, "--stack"); |
| 131 | try zig_args.append(try std.fmt.allocPrint(arena, "{}", .{stack_size})); | 138 | try zig_args.append(gpa, try allocPrint(arena, "{}", .{stack_size})); |
| 132 | } | 139 | } |
| 133 | | 140 | |
| 134 | if (fuzz) { | 141 | try addBool(gpa, zig_args, fuzz, "-ffuzz"); |
| 135 | try zig_args.append("-ffuzz"); | | |
| 136 | } | | |
| 137 | | 142 | |
| 138 | { | 143 | { |
| 139 | // Stores system libraries that have already been seen for at least one | 144 | // Stores system libraries that have already been seen for at least one |
| ... | @@ -183,14 +188,14 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { | ... | @@ -183,14 +188,14 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 183 | switch (link_object) { | 188 | switch (link_object) { |
| 184 | .static_path => |static_path| { | 189 | .static_path => |static_path| { |
| 185 | if (my_responsibility) { | 190 | if (my_responsibility) { |
| 186 | try zig_args.append(static_path.getPath2(mod.owner, step)); | 191 | try zig_args.append(gpa, static_path.getPath2(step)); |
| 187 | total_linker_objects += 1; | 192 | total_linker_objects += 1; |
| 188 | } | 193 | } |
| 189 | }, | 194 | }, |
| 190 | .system_lib => |system_lib| { | 195 | .system_lib => |system_lib| { |
| 191 | const system_lib_gop = try seen_system_libs.getOrPut(arena, system_lib.name); | 196 | const system_lib_gop = try seen_system_libs.getOrPut(arena, system_lib.name); |
| 192 | if (system_lib_gop.found_existing) { | 197 | if (system_lib_gop.found_existing) { |
| 193 | try zig_args.appendSlice(system_lib_gop.value_ptr.*); | 198 | try zig_args.appendSlice(gpa, system_lib_gop.value_ptr.*); |
| 194 | continue; | 199 | continue; |
| 195 | } else { | 200 | } else { |
| 196 | system_lib_gop.value_ptr.* = &.{}; | 201 | system_lib_gop.value_ptr.* = &.{}; |
| ... | @@ -205,16 +210,16 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { | ... | @@ -205,16 +210,16 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 205 | { | 210 | { |
| 206 | switch (system_lib.search_strategy) { | 211 | switch (system_lib.search_strategy) { |
| 207 | .no_fallback => switch (system_lib.preferred_link_mode) { | 212 | .no_fallback => switch (system_lib.preferred_link_mode) { |
| 208 | .dynamic => try zig_args.append("-search_dylibs_only"), | 213 | .dynamic => try zig_args.append(gpa, "-search_dylibs_only"), |
| 209 | .static => try zig_args.append("-search_static_only"), | 214 | .static => try zig_args.append(gpa, "-search_static_only"), |
| 210 | }, | 215 | }, |
| 211 | .paths_first => switch (system_lib.preferred_link_mode) { | 216 | .paths_first => switch (system_lib.preferred_link_mode) { |
| 212 | .dynamic => try zig_args.append("-search_paths_first"), | 217 | .dynamic => try zig_args.append(gpa, "-search_paths_first"), |
| 213 | .static => try zig_args.append("-search_paths_first_static"), | 218 | .static => try zig_args.append(gpa, "-search_paths_first_static"), |
| 214 | }, | 219 | }, |
| 215 | .mode_first => switch (system_lib.preferred_link_mode) { | 220 | .mode_first => switch (system_lib.preferred_link_mode) { |
| 216 | .dynamic => try zig_args.append("-search_dylibs_first"), | 221 | .dynamic => try zig_args.append(gpa, "-search_dylibs_first"), |
| 217 | .static => try zig_args.append("-search_static_first"), | 222 | .static => try zig_args.append(gpa, "-search_static_first"), |
| 218 | }, | 223 | }, |
| 219 | } | 224 | } |
| 220 | prev_search_strategy = system_lib.search_strategy; | 225 | prev_search_strategy = system_lib.search_strategy; |
| ... | @@ -227,11 +232,11 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { | ... | @@ -227,11 +232,11 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 227 | break :prefix "-l"; | 232 | break :prefix "-l"; |
| 228 | }; | 233 | }; |
| 229 | switch (system_lib.use_pkg_config) { | 234 | switch (system_lib.use_pkg_config) { |
| 230 | .no => try zig_args.append(b.fmt("{s}{s}", .{ prefix, system_lib.name })), | 235 | .no => try zig_args.append(gpa, try allocPrint(arena, "{s}{s}", .{ prefix, system_lib.name })), |
| 231 | .yes, .force => { | 236 | .yes, .force => { |
| 232 | if (compile.runPkgConfig(maker, system_lib.name)) |result| { | 237 | if (compile.runPkgConfig(maker, system_lib.name)) |result| { |
| 233 | try zig_args.appendSlice(result.cflags); | 238 | try zig_args.appendSlice(gpa, result.cflags); |
| 234 | try zig_args.appendSlice(result.libs); | 239 | try zig_args.appendSlice(gpa, result.libs); |
| 235 | try seen_system_libs.put(arena, system_lib.name, result.cflags); | 240 | try seen_system_libs.put(arena, system_lib.name, result.cflags); |
| 236 | } else |err| switch (err) { | 241 | } else |err| switch (err) { |
| 237 | error.PkgConfigInvalidOutput, | 242 | error.PkgConfigInvalidOutput, |
| ... | @@ -243,7 +248,7 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { | ... | @@ -243,7 +248,7 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 243 | .yes => { | 248 | .yes => { |
| 244 | // pkg-config failed, so fall back to linking the library | 249 | // pkg-config failed, so fall back to linking the library |
| 245 | // by name directly. | 250 | // by name directly. |
| 246 | try zig_args.append(b.fmt("{s}{s}", .{ | 251 | try zig_args.append(gpa, try allocPrint(arena, "{s}{s}", .{ |
| 247 | prefix, | 252 | prefix, |
| 248 | system_lib.name, | 253 | system_lib.name, |
| 249 | })); | 254 | })); |
| ... | @@ -267,7 +272,7 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { | ... | @@ -267,7 +272,7 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 267 | const included_in_lib_or_obj = !my_responsibility and | 272 | const included_in_lib_or_obj = !my_responsibility and |
| 268 | (dep_compile.kind == .lib or dep_compile.kind == .obj or dep_compile.kind == .test_obj); | 273 | (dep_compile.kind == .lib or dep_compile.kind == .obj or dep_compile.kind == .test_obj); |
| 269 | if (!already_linked and !included_in_lib_or_obj) { | 274 | if (!already_linked and !included_in_lib_or_obj) { |
| 270 | try zig_args.append(other.getEmittedBin().getPath2(b, step)); | 275 | try zig_args.append(gpa, other.getEmittedBin().getPath2(step)); |
| 271 | total_linker_objects += 1; | 276 | total_linker_objects += 1; |
| 272 | } | 277 | } |
| 273 | }, | 278 | }, |
| ... | @@ -288,15 +293,15 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { | ... | @@ -288,15 +293,15 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 288 | else | 293 | else |
| 289 | try other.getGeneratedFilePath("generated_bin", &compile.step); | 294 | try other.getGeneratedFilePath("generated_bin", &compile.step); |
| 290 | | 295 | |
| 291 | try zig_args.append(full_path_lib); | 296 | try zig_args.append(gpa, full_path_lib); |
| 292 | total_linker_objects += 1; | 297 | total_linker_objects += 1; |
| 293 | | 298 | |
| 294 | if (other.linkage == .dynamic and | 299 | if (other.linkage == .dynamic and |
| 295 | compile.rootModuleTarget().os.tag != .windows) | 300 | compile.rootModuleTarget().os.tag != .windows) |
| 296 | { | 301 | { |
| 297 | if (Dir.path.dirname(full_path_lib)) |dirname| { | 302 | if (Dir.path.dirname(full_path_lib)) |dirname| { |
| 298 | try zig_args.append("-rpath"); | 303 | try zig_args.append(gpa, "-rpath"); |
| 299 | try zig_args.append(dirname); | 304 | try zig_args.append(gpa, dirname); |
| 300 | } | 305 | } |
| 301 | } | 306 | } |
| 302 | }, | 307 | }, |
| ... | @@ -306,11 +311,11 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { | ... | @@ -306,11 +311,11 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 306 | if (!my_responsibility) break :l; | 311 | if (!my_responsibility) break :l; |
| 307 | | 312 | |
| 308 | if (prev_has_cflags) { | 313 | if (prev_has_cflags) { |
| 309 | try zig_args.append("-cflags"); | 314 | try zig_args.append(gpa, "-cflags"); |
| 310 | try zig_args.append("--"); | 315 | try zig_args.append(gpa, "--"); |
| 311 | prev_has_cflags = false; | 316 | prev_has_cflags = false; |
| 312 | } | 317 | } |
| 313 | try zig_args.append(asm_file.getPath2(mod.owner, step)); | 318 | try zig_args.append(gpa, asm_file.getPath2(mod.owner, step)); |
| 314 | total_linker_objects += 1; | 319 | total_linker_objects += 1; |
| 315 | }, | 320 | }, |
| 316 | | 321 | |
| ... | @@ -318,24 +323,24 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { | ... | @@ -318,24 +323,24 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 318 | if (!my_responsibility) break :l; | 323 | if (!my_responsibility) break :l; |
| 319 | | 324 | |
| 320 | if (prev_has_cflags or c_source_file.flags.len != 0) { | 325 | if (prev_has_cflags or c_source_file.flags.len != 0) { |
| 321 | try zig_args.append("-cflags"); | 326 | try zig_args.append(gpa, "-cflags"); |
| 322 | for (c_source_file.flags) |arg| { | 327 | for (c_source_file.flags) |arg| { |
| 323 | try zig_args.append(arg); | 328 | try zig_args.append(gpa, arg); |
| 324 | } | 329 | } |
| 325 | try zig_args.append("--"); | 330 | try zig_args.append(gpa, "--"); |
| 326 | } | 331 | } |
| 327 | prev_has_cflags = (c_source_file.flags.len != 0); | 332 | prev_has_cflags = (c_source_file.flags.len != 0); |
| 328 | | 333 | |
| 329 | if (c_source_file.language) |lang| { | 334 | if (c_source_file.language) |lang| { |
| 330 | try zig_args.append("-x"); | 335 | try zig_args.append(gpa, "-x"); |
| 331 | try zig_args.append(lang.internalIdentifier()); | 336 | try zig_args.append(gpa, lang.internalIdentifier()); |
| 332 | } | 337 | } |
| 333 | | 338 | |
| 334 | try zig_args.append(c_source_file.file.getPath2(mod.owner, step)); | 339 | try zig_args.append(gpa, c_source_file.file.getPath2(mod.owner, step)); |
| 335 | | 340 | |
| 336 | if (c_source_file.language != null) { | 341 | if (c_source_file.language != null) { |
| 337 | try zig_args.append("-x"); | 342 | try zig_args.append(gpa, "-x"); |
| 338 | try zig_args.append("none"); | 343 | try zig_args.append(gpa, "none"); |
| 339 | } | 344 | } |
| 340 | total_linker_objects += 1; | 345 | total_linker_objects += 1; |
| 341 | }, | 346 | }, |
| ... | @@ -344,27 +349,27 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { | ... | @@ -344,27 +349,27 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 344 | if (!my_responsibility) break :l; | 349 | if (!my_responsibility) break :l; |
| 345 | | 350 | |
| 346 | if (prev_has_cflags or c_source_files.flags.len != 0) { | 351 | if (prev_has_cflags or c_source_files.flags.len != 0) { |
| 347 | try zig_args.append("-cflags"); | 352 | try zig_args.append(gpa, "-cflags"); |
| 348 | for (c_source_files.flags) |arg| { | 353 | for (c_source_files.flags) |arg| { |
| 349 | try zig_args.append(arg); | 354 | try zig_args.append(gpa, arg); |
| 350 | } | 355 | } |
| 351 | try zig_args.append("--"); | 356 | try zig_args.append(gpa, "--"); |
| 352 | } | 357 | } |
| 353 | prev_has_cflags = (c_source_files.flags.len != 0); | 358 | prev_has_cflags = (c_source_files.flags.len != 0); |
| 354 | | 359 | |
| 355 | if (c_source_files.language) |lang| { | 360 | if (c_source_files.language) |lang| { |
| 356 | try zig_args.append("-x"); | 361 | try zig_args.append(gpa, "-x"); |
| 357 | try zig_args.append(lang.internalIdentifier()); | 362 | try zig_args.append(gpa, lang.internalIdentifier()); |
| 358 | } | 363 | } |
| 359 | | 364 | |
| 360 | const root_path = c_source_files.root.getPath2(mod.owner, step); | 365 | const root_path = c_source_files.root.getPath2(mod.owner, step); |
| 361 | for (c_source_files.files) |file| { | 366 | for (c_source_files.files) |file| { |
| 362 | try zig_args.append(b.pathJoin(&.{ root_path, file })); | 367 | try zig_args.append(gpa, try Dir.path.join(arena, &.{ root_path, file })); |
| 363 | } | 368 | } |
| 364 | | 369 | |
| 365 | if (c_source_files.language != null) { | 370 | if (c_source_files.language != null) { |
| 366 | try zig_args.append("-x"); | 371 | try zig_args.append(gpa, "-x"); |
| 367 | try zig_args.append("none"); | 372 | try zig_args.append(gpa, "none"); |
| 368 | } | 373 | } |
| 369 | | 374 | |
| 370 | total_linker_objects += c_source_files.files.len; | 375 | total_linker_objects += c_source_files.files.len; |
| ... | @@ -375,23 +380,23 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { | ... | @@ -375,23 +380,23 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 375 | | 380 | |
| 376 | if (rc_source_file.flags.len == 0 and rc_source_file.include_paths.len == 0) { | 381 | if (rc_source_file.flags.len == 0 and rc_source_file.include_paths.len == 0) { |
| 377 | if (prev_has_rcflags) { | 382 | if (prev_has_rcflags) { |
| 378 | try zig_args.append("-rcflags"); | 383 | try zig_args.append(gpa, "-rcflags"); |
| 379 | try zig_args.append("--"); | 384 | try zig_args.append(gpa, "--"); |
| 380 | prev_has_rcflags = false; | 385 | prev_has_rcflags = false; |
| 381 | } | 386 | } |
| 382 | } else { | 387 | } else { |
| 383 | try zig_args.append("-rcflags"); | 388 | try zig_args.append(gpa, "-rcflags"); |
| 384 | for (rc_source_file.flags) |arg| { | 389 | for (rc_source_file.flags) |arg| { |
| 385 | try zig_args.append(arg); | 390 | try zig_args.append(gpa, arg); |
| 386 | } | 391 | } |
| 387 | for (rc_source_file.include_paths) |include_path| { | 392 | for (rc_source_file.include_paths) |include_path| { |
| 388 | try zig_args.append("/I"); | 393 | try zig_args.append(gpa, "/I"); |
| 389 | try zig_args.append(include_path.getPath2(mod.owner, step)); | 394 | try zig_args.append(gpa, include_path.getPath2(mod.owner, step)); |
| 390 | } | 395 | } |
| 391 | try zig_args.append("--"); | 396 | try zig_args.append(gpa, "--"); |
| 392 | prev_has_rcflags = true; | 397 | prev_has_rcflags = true; |
| 393 | } | 398 | } |
| 394 | try zig_args.append(rc_source_file.file.getPath2(mod.owner, step)); | 399 | try zig_args.append(gpa, rc_source_file.file.getPath2(mod.owner, step)); |
| 395 | total_linker_objects += 1; | 400 | total_linker_objects += 1; |
| 396 | }, | 401 | }, |
| 397 | } | 402 | } |
| ... | @@ -414,7 +419,7 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { | ... | @@ -414,7 +419,7 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 414 | if (std.mem.eql(u8, import_cli_name, name)) { | 419 | if (std.mem.eql(u8, import_cli_name, name)) { |
| 415 | zig_args.appendAssumeCapacity(import_cli_name); | 420 | zig_args.appendAssumeCapacity(import_cli_name); |
| 416 | } else { | 421 | } else { |
| 417 | zig_args.appendAssumeCapacity(b.fmt("{s}={s}", .{ name, import_cli_name })); | 422 | zig_args.appendAssumeCapacity(try allocPrint(arena, "{s}={s}", .{ name, import_cli_name })); |
| 418 | } | 423 | } |
| 419 | } | 424 | } |
| 420 | | 425 | |
| ... | @@ -427,9 +432,9 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { | ... | @@ -427,9 +432,9 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 427 | // files must have a module parent. | 432 | // files must have a module parent. |
| 428 | if (mod.root_source_file) |lp| { | 433 | if (mod.root_source_file) |lp| { |
| 429 | const src = lp.getPath2(mod.owner, step); | 434 | const src = lp.getPath2(mod.owner, step); |
| 430 | try zig_args.append(b.fmt("-M{s}={s}", .{ module_cli_name, src })); | 435 | try zig_args.append(gpa, try allocPrint(arena, "-M{s}={s}", .{ module_cli_name, src })); |
| 431 | } else if (moduleNeedsCliArg(mod)) { | 436 | } else if (moduleNeedsCliArg(mod)) { |
| 432 | try zig_args.append(b.fmt("-M{s}", .{module_cli_name})); | 437 | try zig_args.append(gpa, try allocPrint(arena, "-M{s}", .{module_cli_name})); |
| 433 | } | 438 | } |
| 434 | } | 439 | } |
| 435 | } | 440 | } |
| ... | @@ -441,275 +446,248 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { | ... | @@ -441,275 +446,248 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 441 | | 446 | |
| 442 | for (frameworks.keys(), frameworks.values()) |name, info| { | 447 | for (frameworks.keys(), frameworks.values()) |name, info| { |
| 443 | if (info.needed) { | 448 | if (info.needed) { |
| 444 | try zig_args.append("-needed_framework"); | 449 | try zig_args.append(gpa, "-needed_framework"); |
| 445 | } else if (info.weak) { | 450 | } else if (info.weak) { |
| 446 | try zig_args.append("-weak_framework"); | 451 | try zig_args.append(gpa, "-weak_framework"); |
| 447 | } else { | 452 | } else { |
| 448 | try zig_args.append("-framework"); | 453 | try zig_args.append(gpa, "-framework"); |
| 449 | } | 454 | } |
| 450 | try zig_args.append(name); | 455 | try zig_args.append(gpa, name); |
| 451 | } | 456 | } |
| 452 | | 457 | |
| 453 | if (compile.is_linking_libcpp) { | 458 | if (compile.is_linking_libcpp) { |
| 454 | try zig_args.append("-lc++"); | 459 | try zig_args.append(gpa, "-lc++"); |
| 455 | } | 460 | } |
| 456 | | 461 | |
| 457 | if (compile.is_linking_libc) { | 462 | if (compile.is_linking_libc) { |
| 458 | try zig_args.append("-lc"); | 463 | try zig_args.append(gpa, "-lc"); |
| 459 | } | 464 | } |
| 460 | } | 465 | } |
| 461 | | 466 | |
| 462 | if (compile.win32_manifest) |manifest_file| { | 467 | if (compile.win32_manifest) |manifest_file| { |
| 463 | try zig_args.append(manifest_file.getPath2(b, step)); | 468 | try zig_args.append(gpa, manifest_file.getPath2(step)); |
| 464 | } | 469 | } |
| 465 | | 470 | |
| 466 | if (compile.win32_module_definition) |module_file| { | 471 | if (compile.win32_module_definition) |module_file| { |
| 467 | try zig_args.append(module_file.getPath2(b, step)); | 472 | try zig_args.append(gpa, module_file.getPath2(step)); |
| 468 | } | 473 | } |
| 469 | | 474 | |
| 470 | if (compile.image_base) |image_base| { | 475 | if (compile.image_base) |image_base| { |
| 471 | try zig_args.append("--image-base"); | 476 | try zig_args.appendSlice(gpa, &.{ |
| 472 | try zig_args.append(b.fmt("0x{x}", .{image_base})); | 477 | "--image-base", try allocPrint(arena, "0x{x}", .{image_base}), |
| | 478 | }); |
| 473 | } | 479 | } |
| 474 | | 480 | |
| 475 | for (compile.filters) |filter| { | 481 | for (compile.filters) |filter| { |
| 476 | try zig_args.append("--test-filter"); | 482 | try zig_args.appendSlice(gpa, &.{ "--test-filter", filter }); |
| 477 | try zig_args.append(filter); | | |
| 478 | } | 483 | } |
| 479 | | 484 | |
| 480 | if (compile.test_runner) |test_runner| { | 485 | if (compile.test_runner) |test_runner| { |
| 481 | try zig_args.append("--test-runner"); | 486 | try zig_args.appendSlice(gpa, &.{ "--test-runner", test_runner.path.getPath2(step) }); |
| 482 | try zig_args.append(test_runner.path.getPath2(b, step)); | | |
| 483 | } | 487 | } |
| 484 | | 488 | |
| 485 | for (b.debug_log_scopes) |log_scope| { | 489 | for (graph.debug_log_scopes) |log_scope| { |
| 486 | try zig_args.append("--debug-log"); | 490 | try zig_args.appendSlice(gpa, &.{ "--debug-log", log_scope }); |
| 487 | try zig_args.append(log_scope); | | |
| 488 | } | 491 | } |
| 489 | | 492 | |
| 490 | if (b.debug_compile_errors) { | 493 | try addBool(gpa, zig_args, graph.debug_compile_errors, "--debug-compile-errors"); |
| 491 | try zig_args.append("--debug-compile-errors"); | 494 | try addBool(gpa, zig_args, graph.debug_incremental, "--debug-incremental"); |
| 492 | } | 495 | try addBool(gpa, zig_args, graph.verbose_air, "--verbose-air"); |
| | 496 | try addBool(gpa, zig_args, graph.verbose_llvm_ir, "--verbose-llvm-ir"); |
| | 497 | try addBool(gpa, zig_args, graph.verbose_link or compile.verbose_link, "--verbose-link"); |
| | 498 | try addBool(gpa, zig_args, graph.verbose_cc or compile.verbose_cc, "--verbose-cc"); |
| | 499 | try addBool(gpa, zig_args, graph.verbose_llvm_cpu_features, "--verbose-llvm-cpu-features"); |
| | 500 | try addBool(gpa, zig_args, graph.time_report, "--time-report"); |
| 493 | | 501 | |
| 494 | if (b.debug_incremental) { | 502 | if (compile.generated_asm != null) try zig_args.append(gpa, "-femit-asm"); |
| 495 | try zig_args.append("--debug-incremental"); | 503 | if (compile.generated_bin == null) try zig_args.append(gpa, "-fno-emit-bin"); |
| 496 | } | 504 | if (compile.generated_docs != null) try zig_args.append(gpa, "-femit-docs"); |
| 497 | | 505 | if (compile.generated_implib != null) try zig_args.append(gpa, "-femit-implib"); |
| 498 | if (b.verbose_air) try zig_args.append("--verbose-air"); | 506 | if (compile.generated_llvm_bc != null) try zig_args.append(gpa, "-femit-llvm-bc"); |
| 499 | if (b.verbose_llvm_ir) |path| try zig_args.append(b.fmt("--verbose-llvm-ir={s}", .{path})); | 507 | if (compile.generated_llvm_ir != null) try zig_args.append(gpa, "-femit-llvm-ir"); |
| 500 | if (b.verbose_llvm_bc) |path| try zig_args.append(b.fmt("--verbose-llvm-bc={s}", .{path})); | 508 | if (compile.generated_h != null) try zig_args.append(gpa, "-femit-h"); |
| 501 | if (b.verbose_link or compile.verbose_link) try zig_args.append("--verbose-link"); | | |
| 502 | if (b.verbose_cc or compile.verbose_cc) try zig_args.append("--verbose-cc"); | | |
| 503 | if (b.verbose_llvm_cpu_features) try zig_args.append("--verbose-llvm-cpu-features"); | | |
| 504 | if (graph.time_report) try zig_args.append("--time-report"); | | |
| 505 | | | |
| 506 | if (compile.generated_asm != null) try zig_args.append("-femit-asm"); | | |
| 507 | if (compile.generated_bin == null) try zig_args.append("-fno-emit-bin"); | | |
| 508 | if (compile.generated_docs != null) try zig_args.append("-femit-docs"); | | |
| 509 | if (compile.generated_implib != null) try zig_args.append("-femit-implib"); | | |
| 510 | if (compile.generated_llvm_bc != null) try zig_args.append("-femit-llvm-bc"); | | |
| 511 | if (compile.generated_llvm_ir != null) try zig_args.append("-femit-llvm-ir"); | | |
| 512 | if (compile.generated_h != null) try zig_args.append("-femit-h"); | | |
| 513 | | 509 | |
| 514 | try addFlag(&zig_args, "formatted-panics", compile.formatted_panics); | 510 | try addFlag(&zig_args, "formatted-panics", compile.formatted_panics); |
| 515 | | 511 | |
| 516 | switch (compile.compress_debug_sections) { | 512 | switch (compile.compress_debug_sections) { |
| 517 | .none => {}, | 513 | .none => {}, |
| 518 | .zlib => try zig_args.append("--compress-debug-sections=zlib"), | 514 | .zlib => try zig_args.append(gpa, "--compress-debug-sections=zlib"), |
| 519 | .zstd => try zig_args.append("--compress-debug-sections=zstd"), | 515 | .zstd => try zig_args.append(gpa, "--compress-debug-sections=zstd"), |
| 520 | } | 516 | } |
| 521 | | 517 | |
| 522 | if (compile.link_eh_frame_hdr) { | 518 | if (compile.link_eh_frame_hdr) { |
| 523 | try zig_args.append("--eh-frame-hdr"); | 519 | try zig_args.append(gpa, "--eh-frame-hdr"); |
| 524 | } | 520 | } |
| 525 | if (compile.link_emit_relocs) { | 521 | if (compile.link_emit_relocs) { |
| 526 | try zig_args.append("--emit-relocs"); | 522 | try zig_args.append(gpa, "--emit-relocs"); |
| 527 | } | 523 | } |
| 528 | if (compile.link_function_sections) { | 524 | if (compile.link_function_sections) { |
| 529 | try zig_args.append("-ffunction-sections"); | 525 | try zig_args.append(gpa, "-ffunction-sections"); |
| 530 | } | 526 | } |
| 531 | if (compile.link_data_sections) { | 527 | if (compile.link_data_sections) { |
| 532 | try zig_args.append("-fdata-sections"); | 528 | try zig_args.append(gpa, "-fdata-sections"); |
| 533 | } | 529 | } |
| 534 | if (compile.link_gc_sections) |x| { | 530 | if (compile.link_gc_sections) |x| { |
| 535 | try zig_args.append(if (x) "--gc-sections" else "--no-gc-sections"); | 531 | try zig_args.append(gpa, if (x) "--gc-sections" else "--no-gc-sections"); |
| 536 | } | 532 | } |
| 537 | if (!compile.linker_dynamicbase) { | 533 | if (!compile.linker_dynamicbase) { |
| 538 | try zig_args.append("--no-dynamicbase"); | 534 | try zig_args.append(gpa, "--no-dynamicbase"); |
| 539 | } | 535 | } |
| 540 | if (compile.linker_allow_shlib_undefined) |x| { | 536 | if (compile.linker_allow_shlib_undefined) |x| { |
| 541 | try zig_args.append(if (x) "-fallow-shlib-undefined" else "-fno-allow-shlib-undefined"); | 537 | try zig_args.append(gpa, if (x) "-fallow-shlib-undefined" else "-fno-allow-shlib-undefined"); |
| 542 | } | 538 | } |
| 543 | if (compile.link_z_notext) { | 539 | if (compile.link_z_notext) try zig_args.appendSlice(gpa, &.{ "-z", "notext" }); |
| 544 | try zig_args.append("-z"); | 540 | if (!compile.link_z_relro) try zig_args.appendSlice(gpa, &.{ "-z", "norelro" }); |
| 545 | try zig_args.append("notext"); | 541 | if (compile.link_z_lazy) try zig_args.appendSlice(gpa, &.{ "-z", "lazy" }); |
| 546 | } | 542 | if (compile.link_z_common_page_size) |size| try zig_args.appendSlice(gpa, &.{ |
| 547 | if (!compile.link_z_relro) { | 543 | "-z", |
| 548 | try zig_args.append("-z"); | 544 | try allocPrint(arena, "common-page-size={d}", .{size}), |
| 549 | try zig_args.append("norelro"); | 545 | }); |
| 550 | } | 546 | if (compile.link_z_max_page_size) |size| try zig_args.appendSlice(gpa, &.{ |
| 551 | if (compile.link_z_lazy) { | 547 | "-z", |
| 552 | try zig_args.append("-z"); | 548 | try allocPrint(arena, "max-page-size={d}", .{size}), |
| 553 | try zig_args.append("lazy"); | 549 | }); |
| 554 | } | 550 | if (compile.link_z_defs) try zig_args.appendSlice(gpa, &.{ "-z", "defs" }); |
| 555 | if (compile.link_z_common_page_size) |size| { | | |
| 556 | try zig_args.append("-z"); | | |
| 557 | try zig_args.append(b.fmt("common-page-size={d}", .{size})); | | |
| 558 | } | | |
| 559 | if (compile.link_z_max_page_size) |size| { | | |
| 560 | try zig_args.append("-z"); | | |
| 561 | try zig_args.append(b.fmt("max-page-size={d}", .{size})); | | |
| 562 | } | | |
| 563 | if (compile.link_z_defs) { | | |
| 564 | try zig_args.append("-z"); | | |
| 565 | try zig_args.append("defs"); | | |
| 566 | } | | |
| 567 | | 551 | |
| 568 | if (compile.libc_file) |libc_file| { | 552 | if (compile.libc_file) |libc_file| { |
| 569 | try zig_args.append("--libc"); | 553 | try zig_args.appendSlice(gpa, &.{ "--libc", libc_file.getPath2(step) }); |
| 570 | try zig_args.append(libc_file.getPath2(b, step)); | 554 | } else if (graph.libc_file) |libc_file| { |
| 571 | } else if (b.libc_file) |libc_file| { | 555 | try zig_args.appendSlice(gpa, &.{ "--libc", libc_file }); |
| 572 | try zig_args.append("--libc"); | | |
| 573 | try zig_args.append(libc_file); | | |
| 574 | } | 556 | } |
| 575 | | 557 | |
| 576 | try zig_args.append("--cache-dir"); | 558 | try zig_args.append(gpa, "--cache-dir"); |
| 577 | try zig_args.append(b.cache_root.path orelse "."); | 559 | try zig_args.append(gpa, graph.cache_root.path orelse "."); |
| 578 | | 560 | |
| 579 | try zig_args.append("--global-cache-dir"); | 561 | try zig_args.append(gpa, "--global-cache-dir"); |
| 580 | try zig_args.append(graph.global_cache_root.path orelse "."); | 562 | try zig_args.append(gpa, graph.global_cache_root.path orelse "."); |
| 581 | | 563 | |
| 582 | if (graph.debug_compiler_runtime_libs) |mode| | 564 | if (graph.debug_compiler_runtime_libs) |mode| |
| 583 | try zig_args.append(b.fmt("--debug-rt={t}", .{mode})); | 565 | try zig_args.append(gpa, try allocPrint(arena, "--debug-rt={t}", .{mode})); |
| 584 | | 566 | |
| 585 | try zig_args.append("--name"); | 567 | try zig_args.append(gpa, "--name"); |
| 586 | try zig_args.append(compile.name); | 568 | try zig_args.append(gpa, compile.name); |
| 587 | | 569 | |
| 588 | if (compile.linkage) |some| switch (some) { | 570 | if (compile.linkage) |some| switch (some) { |
| 589 | .dynamic => try zig_args.append("-dynamic"), | 571 | .dynamic => try zig_args.append(gpa, "-dynamic"), |
| 590 | .static => try zig_args.append("-static"), | 572 | .static => try zig_args.append(gpa, "-static"), |
| 591 | }; | 573 | }; |
| 592 | if (compile.kind == .lib and compile.linkage != null and compile.linkage.? == .dynamic) { | 574 | if (compile.kind == .lib and compile.linkage != null and compile.linkage.? == .dynamic) { |
| 593 | if (compile.version) |version| { | 575 | if (compile.version) |version| { |
| 594 | try zig_args.append("--version"); | 576 | try zig_args.append(gpa, "--version"); |
| 595 | try zig_args.append(b.fmt("{f}", .{version})); | 577 | try zig_args.append(gpa, try allocPrint(arena, "{f}", .{version})); |
| 596 | } | 578 | } |
| 597 | | 579 | |
| 598 | if (compile.rootModuleTarget().os.tag.isDarwin()) { | 580 | if (compile.rootModuleTarget().os.tag.isDarwin()) { |
| 599 | const install_name = compile.install_name orelse b.fmt("@rpath/{s}{s}{s}", .{ | 581 | const install_name = compile.install_name orelse try allocPrint(arena, "@rpath/{s}{s}{s}", .{ |
| 600 | compile.rootModuleTarget().libPrefix(), | 582 | compile.rootModuleTarget().libPrefix(), |
| 601 | compile.name, | 583 | compile.name, |
| 602 | compile.rootModuleTarget().dynamicLibSuffix(), | 584 | compile.rootModuleTarget().dynamicLibSuffix(), |
| 603 | }); | 585 | }); |
| 604 | try zig_args.append("-install_name"); | 586 | try zig_args.append(gpa, "-install_name"); |
| 605 | try zig_args.append(install_name); | 587 | try zig_args.append(gpa, install_name); |
| 606 | } | 588 | } |
| 607 | } | 589 | } |
| 608 | | 590 | |
| 609 | if (compile.entitlements) |entitlements| { | 591 | if (compile.entitlements) |entitlements| { |
| 610 | try zig_args.appendSlice(&[_][]const u8{ "--entitlements", entitlements }); | 592 | try zig_args.appendSlice(gpa, &[_][]const u8{ "--entitlements", entitlements }); |
| 611 | } | 593 | } |
| 612 | if (compile.pagezero_size) |pagezero_size| { | 594 | if (compile.pagezero_size) |pagezero_size| { |
| 613 | const size = try std.fmt.allocPrint(arena, "{x}", .{pagezero_size}); | 595 | const size = try allocPrint(arena, "{x}", .{pagezero_size}); |
| 614 | try zig_args.appendSlice(&[_][]const u8{ "-pagezero_size", size }); | 596 | try zig_args.appendSlice(gpa, &[_][]const u8{ "-pagezero_size", size }); |
| 615 | } | 597 | } |
| 616 | if (compile.headerpad_size) |headerpad_size| { | 598 | if (compile.headerpad_size) |headerpad_size| { |
| 617 | const size = try std.fmt.allocPrint(arena, "{x}", .{headerpad_size}); | 599 | const size = try allocPrint(arena, "{x}", .{headerpad_size}); |
| 618 | try zig_args.appendSlice(&[_][]const u8{ "-headerpad", size }); | 600 | try zig_args.appendSlice(gpa, &[_][]const u8{ "-headerpad", size }); |
| 619 | } | 601 | } |
| 620 | if (compile.headerpad_max_install_names) { | 602 | if (compile.headerpad_max_install_names) { |
| 621 | try zig_args.append("-headerpad_max_install_names"); | 603 | try zig_args.append(gpa, "-headerpad_max_install_names"); |
| 622 | } | 604 | } |
| 623 | if (compile.dead_strip_dylibs) { | 605 | if (compile.dead_strip_dylibs) { |
| 624 | try zig_args.append("-dead_strip_dylibs"); | 606 | try zig_args.append(gpa, "-dead_strip_dylibs"); |
| 625 | } | 607 | } |
| 626 | if (compile.force_load_objc) { | 608 | if (compile.force_load_objc) { |
| 627 | try zig_args.append("-ObjC"); | 609 | try zig_args.append(gpa, "-ObjC"); |
| 628 | } | 610 | } |
| 629 | if (compile.discard_local_symbols) { | 611 | if (compile.discard_local_symbols) { |
| 630 | try zig_args.append("--discard-all"); | 612 | try zig_args.append(gpa, "--discard-all"); |
| 631 | } | 613 | } |
| 632 | | 614 | |
| 633 | try addFlag(&zig_args, "compiler-rt", compile.bundle_compiler_rt); | 615 | try addFlag(&zig_args, "compiler-rt", compile.bundle_compiler_rt); |
| 634 | try addFlag(&zig_args, "ubsan-rt", compile.bundle_ubsan_rt); | 616 | try addFlag(&zig_args, "ubsan-rt", compile.bundle_ubsan_rt); |
| 635 | try addFlag(&zig_args, "dll-export-fns", compile.dll_export_fns); | 617 | try addFlag(&zig_args, "dll-export-fns", compile.dll_export_fns); |
| 636 | if (compile.rdynamic) { | 618 | if (compile.rdynamic) { |
| 637 | try zig_args.append("-rdynamic"); | 619 | try zig_args.append(gpa, "-rdynamic"); |
| 638 | } | 620 | } |
| 639 | if (compile.import_memory) { | 621 | if (compile.import_memory) { |
| 640 | try zig_args.append("--import-memory"); | 622 | try zig_args.append(gpa, "--import-memory"); |
| 641 | } | 623 | } |
| 642 | if (compile.export_memory) { | 624 | if (compile.export_memory) { |
| 643 | try zig_args.append("--export-memory"); | 625 | try zig_args.append(gpa, "--export-memory"); |
| 644 | } | 626 | } |
| 645 | if (compile.import_symbols) { | 627 | if (compile.import_symbols) { |
| 646 | try zig_args.append("--import-symbols"); | 628 | try zig_args.append(gpa, "--import-symbols"); |
| 647 | } | 629 | } |
| 648 | if (compile.import_table) { | 630 | if (compile.import_table) { |
| 649 | try zig_args.append("--import-table"); | 631 | try zig_args.append(gpa, "--import-table"); |
| 650 | } | 632 | } |
| 651 | if (compile.export_table) { | 633 | if (compile.export_table) { |
| 652 | try zig_args.append("--export-table"); | 634 | try zig_args.append(gpa, "--export-table"); |
| 653 | } | 635 | } |
| 654 | if (compile.initial_memory) |initial_memory| { | 636 | if (compile.initial_memory) |initial_memory| { |
| 655 | try zig_args.append(b.fmt("--initial-memory={d}", .{initial_memory})); | 637 | try zig_args.append(gpa, try allocPrint(arena, "--initial-memory={d}", .{initial_memory})); |
| 656 | } | 638 | } |
| 657 | if (compile.max_memory) |max_memory| { | 639 | if (compile.max_memory) |max_memory| { |
| 658 | try zig_args.append(b.fmt("--max-memory={d}", .{max_memory})); | 640 | try zig_args.append(gpa, try allocPrint(arena, "--max-memory={d}", .{max_memory})); |
| 659 | } | 641 | } |
| 660 | if (compile.shared_memory) { | 642 | if (compile.shared_memory) { |
| 661 | try zig_args.append("--shared-memory"); | 643 | try zig_args.append(gpa, "--shared-memory"); |
| 662 | } | 644 | } |
| 663 | if (compile.global_base) |global_base| { | 645 | if (compile.global_base) |global_base| { |
| 664 | try zig_args.append(b.fmt("--global-base={d}", .{global_base})); | 646 | try zig_args.append(gpa, try allocPrint(arena, "--global-base={d}", .{global_base})); |
| 665 | } | 647 | } |
| 666 | | 648 | |
| 667 | if (compile.wasi_exec_model) |model| { | 649 | if (compile.wasi_exec_model) |model| { |
| 668 | try zig_args.append(b.fmt("-mexec-model={s}", .{@tagName(model)})); | 650 | try zig_args.append(gpa, try allocPrint(arena, "-mexec-model={t}", .{model})); |
| 669 | } | 651 | } |
| 670 | if (compile.linker_script) |linker_script| { | 652 | if (compile.linker_script) |linker_script| { |
| 671 | try zig_args.append("--script"); | 653 | try zig_args.append(gpa, "--script"); |
| 672 | try zig_args.append(linker_script.getPath2(b, step)); | 654 | try zig_args.append(gpa, linker_script.getPath2(step)); |
| 673 | } | 655 | } |
| 674 | | 656 | |
| 675 | if (compile.version_script) |version_script| { | 657 | if (compile.version_script) |version_script| { |
| 676 | try zig_args.append("--version-script"); | 658 | try zig_args.append(gpa, "--version-script"); |
| 677 | try zig_args.append(version_script.getPath2(b, step)); | 659 | try zig_args.append(gpa, version_script.getPath2(step)); |
| 678 | } | 660 | } |
| 679 | if (compile.linker_allow_undefined_version) |x| { | 661 | if (compile.linker_allow_undefined_version) |x| { |
| 680 | try zig_args.append(if (x) "--undefined-version" else "--no-undefined-version"); | 662 | try zig_args.append(gpa, if (x) "--undefined-version" else "--no-undefined-version"); |
| 681 | } | 663 | } |
| 682 | | 664 | |
| 683 | if (compile.linker_enable_new_dtags) |enabled| { | 665 | if (compile.linker_enable_new_dtags) |enabled| { |
| 684 | try zig_args.append(if (enabled) "--enable-new-dtags" else "--disable-new-dtags"); | 666 | try zig_args.append(gpa, if (enabled) "--enable-new-dtags" else "--disable-new-dtags"); |
| 685 | } | 667 | } |
| 686 | | 668 | |
| 687 | if (compile.kind == .@"test") { | 669 | if (compile.kind == .@"test") { |
| 688 | if (compile.exec_cmd_args) |exec_cmd_args| { | 670 | if (compile.exec_cmd_args) |exec_cmd_args| { |
| 689 | for (exec_cmd_args) |cmd_arg| { | 671 | for (exec_cmd_args) |cmd_arg| { |
| 690 | if (cmd_arg) |arg| { | 672 | if (cmd_arg) |arg| { |
| 691 | try zig_args.append("--test-cmd"); | 673 | try zig_args.append(gpa, "--test-cmd"); |
| 692 | try zig_args.append(arg); | 674 | try zig_args.append(gpa, arg); |
| 693 | } else { | 675 | } else { |
| 694 | try zig_args.append("--test-cmd-bin"); | 676 | try zig_args.append(gpa, "--test-cmd-bin"); |
| 695 | } | 677 | } |
| 696 | } | 678 | } |
| 697 | } | 679 | } |
| 698 | } | 680 | } |
| 699 | | 681 | |
| 700 | if (b.sysroot) |sysroot| { | 682 | if (graph.sysroot) |sysroot| try zig_args.appendSlice(gpa, &.{ "--sysroot", sysroot }); |
| 701 | try zig_args.appendSlice(&[_][]const u8{ "--sysroot", sysroot }); | | |
| 702 | } | | |
| 703 | | 683 | |
| 704 | // -I and -L arguments that appear after the last --mod argument apply to all modules. | 684 | // -I and -L arguments that appear after the last --mod argument apply to all modules. |
| 705 | const cwd: Io.Dir = .cwd(); | 685 | const cwd: Io.Dir = .cwd(); |
| 706 | const io = graph.io; | 686 | const io = graph.io; |
| 707 | | 687 | |
| 708 | for (b.search_prefixes.items) |search_prefix| { | 688 | for (graph.search_prefixes.items) |search_prefix| { |
| 709 | var prefix_dir = cwd.openDir(io, search_prefix, .{}) catch |err| { | 689 | var prefix_dir = cwd.openDir(io, search_prefix, .{}) catch |err| { |
| 710 | return step.fail("unable to open prefix directory '{s}': {s}", .{ | 690 | return step.fail("unable to open prefix directory '{s}': {t}", .{ search_prefix, err }); |
| 711 | search_prefix, @errorName(err), | | |
| 712 | }); | | |
| 713 | }; | 691 | }; |
| 714 | defer prefix_dir.close(io); | 692 | defer prefix_dir.close(io); |
| 715 | | 693 | |
| ... | @@ -718,58 +696,53 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { | ... | @@ -718,58 +696,53 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 718 | // CLI parsing code, when the linker sees an -L directory that does not exist. | 696 | // CLI parsing code, when the linker sees an -L directory that does not exist. |
| 719 | | 697 | |
| 720 | if (prefix_dir.access(io, "lib", .{})) |_| { | 698 | if (prefix_dir.access(io, "lib", .{})) |_| { |
| 721 | try zig_args.appendSlice(&.{ | 699 | try zig_args.appendSlice(gpa, &.{ |
| 722 | "-L", b.pathJoin(&.{ search_prefix, "lib" }), | 700 | "-L", try Dir.path.join(arena, &.{ search_prefix, "lib" }), |
| 723 | }); | 701 | }); |
| 724 | } else |err| switch (err) { | 702 | } else |err| switch (err) { |
| 725 | error.FileNotFound => {}, | 703 | error.FileNotFound => {}, |
| 726 | else => |e| return step.fail("unable to access '{s}/lib' directory: {s}", .{ | 704 | else => |e| return step.fail("unable to access '{s}/lib' directory: {t}", .{ search_prefix, e }), |
| 727 | search_prefix, @errorName(e), | | |
| 728 | }), | | |
| 729 | } | 705 | } |
| 730 | | 706 | |
| 731 | if (prefix_dir.access(io, "include", .{})) |_| { | 707 | if (prefix_dir.access(io, "include", .{})) |_| { |
| 732 | try zig_args.appendSlice(&.{ | 708 | try zig_args.appendSlice(gpa, &.{ |
| 733 | "-I", b.pathJoin(&.{ search_prefix, "include" }), | 709 | "-I", try Dir.path.join(arena, &.{ search_prefix, "include" }), |
| 734 | }); | 710 | }); |
| 735 | } else |err| switch (err) { | 711 | } else |err| switch (err) { |
| 736 | error.FileNotFound => {}, | 712 | error.FileNotFound => {}, |
| 737 | else => |e| return step.fail("unable to access '{s}/include' directory: {s}", .{ | 713 | else => |e| return step.fail("unable to access '{s}/include' directory: {t}", .{ search_prefix, e }), |
| 738 | search_prefix, @errorName(e), | | |
| 739 | }), | | |
| 740 | } | 714 | } |
| 741 | } | 715 | } |
| 742 | | 716 | |
| 743 | if (compile.rc_includes != .any) { | 717 | if (compile.rc_includes != .any) { |
| 744 | try zig_args.append("-rcincludes"); | 718 | try zig_args.appendSlice(gpa, &.{ "-rcincludes", @tagName(compile.rc_includes) }); |
| 745 | try zig_args.append(@tagName(compile.rc_includes)); | | |
| 746 | } | 719 | } |
| 747 | | 720 | |
| 748 | try addFlag(&zig_args, "each-lib-rpath", compile.each_lib_rpath); | 721 | try addFlag(&zig_args, "each-lib-rpath", compile.each_lib_rpath); |
| 749 | | 722 | |
| 750 | if (compile.build_id orelse b.build_id) |build_id| { | 723 | if (compile.build_id orelse graph.build_id) |build_id| { |
| 751 | try zig_args.append(switch (build_id) { | 724 | try zig_args.append(gpa, switch (build_id) { |
| 752 | .hexstring => |hs| b.fmt("--build-id=0x{x}", .{hs.toSlice()}), | 725 | .hexstring => |hs| try allocPrint(arena, "--build-id=0x{x}", .{hs.toSlice()}), |
| 753 | .none, .fast, .uuid, .sha1, .md5 => b.fmt("--build-id={s}", .{@tagName(build_id)}), | 726 | .none, .fast, .uuid, .sha1, .md5 => try allocPrint(arena, "--build-id={t}", .{build_id}), |
| 754 | }); | 727 | }); |
| 755 | } | 728 | } |
| 756 | | 729 | |
| 757 | const opt_zig_lib_dir = if (compile.zig_lib_dir) |dir| | 730 | const opt_zig_lib_dir = if (compile.zig_lib_dir) |dir| |
| 758 | dir.getPath2(b, step) | 731 | dir.getPath2(step) |
| 759 | else if (graph.zig_lib_directory.path) |_| | 732 | else if (graph.zig_lib_directory.path) |_| |
| 760 | b.fmt("{f}", .{graph.zig_lib_directory}) | 733 | try allocPrint(arena, "{f}", .{graph.zig_lib_directory}) |
| 761 | else | 734 | else |
| 762 | null; | 735 | null; |
| 763 | | 736 | |
| 764 | if (opt_zig_lib_dir) |zig_lib_dir| { | 737 | if (opt_zig_lib_dir) |zig_lib_dir| { |
| 765 | try zig_args.append("--zig-lib-dir"); | 738 | try zig_args.append(gpa, "--zig-lib-dir"); |
| 766 | try zig_args.append(zig_lib_dir); | 739 | try zig_args.append(gpa, zig_lib_dir); |
| 767 | } | 740 | } |
| 768 | | 741 | |
| 769 | try addFlag(&zig_args, "PIE", compile.pie); | 742 | try addFlag(&zig_args, "PIE", compile.pie); |
| 770 | | 743 | |
| 771 | if (compile.lto) |lto| { | 744 | if (compile.lto) |lto| { |
| 772 | try zig_args.append(switch (lto) { | 745 | try zig_args.append(gpa, switch (lto) { |
| 773 | .full => "-flto=full", | 746 | .full => "-flto=full", |
| 774 | .thin => "-flto=thin", | 747 | .thin => "-flto=thin", |
| 775 | .none => "-fno-lto", | 748 | .none => "-fno-lto", |
| ... | @@ -779,21 +752,20 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { | ... | @@ -779,21 +752,20 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 779 | try addFlag(&zig_args, "sanitize-coverage-trace-pc-guard", compile.sanitize_coverage_trace_pc_guard); | 752 | try addFlag(&zig_args, "sanitize-coverage-trace-pc-guard", compile.sanitize_coverage_trace_pc_guard); |
| 780 | | 753 | |
| 781 | if (compile.subsystem) |subsystem| { | 754 | if (compile.subsystem) |subsystem| { |
| 782 | try zig_args.append("--subsystem"); | 755 | try zig_args.appendSlice(gpa, &.{ "--subsystem", @tagName(subsystem) }); |
| 783 | try zig_args.append(@tagName(subsystem)); | | |
| 784 | } | 756 | } |
| 785 | | 757 | |
| 786 | if (compile.mingw_unicode_entry_point) { | 758 | if (compile.mingw_unicode_entry_point) { |
| 787 | try zig_args.append("-municode"); | 759 | try zig_args.append(gpa, "-municode"); |
| 788 | } | 760 | } |
| 789 | | 761 | |
| 790 | if (compile.error_limit) |err_limit| try zig_args.appendSlice(&.{ | 762 | if (compile.error_limit) |err_limit| try zig_args.appendSlice(gpa, &.{ |
| 791 | "--error-limit", b.fmt("{d}", .{err_limit}), | 763 | "--error-limit", try allocPrint(arena, "{d}", .{err_limit}), |
| 792 | }); | 764 | }); |
| 793 | | 765 | |
| 794 | try addFlag(&zig_args, "incremental", graph.incremental); | 766 | try addFlag(&zig_args, "incremental", graph.incremental); |
| 795 | | 767 | |
| 796 | try zig_args.append("--listen=-"); | 768 | try zig_args.append(gpa, "--listen=-"); |
| 797 | | 769 | |
| 798 | // Windows has an argument length limit of 32,766 characters, macOS 262,144 and Linux | 770 | // Windows has an argument length limit of 32,766 characters, macOS 262,144 and Linux |
| 799 | // 2,097,152. If our args exceed 30 KiB, we instead write them to a "response file" and | 771 | // 2,097,152. If our args exceed 30 KiB, we instead write them to a "response file" and |
| ... | @@ -804,7 +776,7 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { | ... | @@ -804,7 +776,7 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 804 | args_length += arg.len + 1; // +1 to account for null terminator | 776 | args_length += arg.len + 1; // +1 to account for null terminator |
| 805 | } | 777 | } |
| 806 | if (args_length >= 30 * 1024) { | 778 | if (args_length >= 30 * 1024) { |
| 807 | try b.cache_root.handle.createDirPath(io, "args"); | 779 | try graph.cache_root.handle.createDirPath(io, "args"); |
| 808 | | 780 | |
| 809 | const args_to_escape = zig_args.items[2..]; | 781 | const args_to_escape = zig_args.items[2..]; |
| 810 | var escaped_args = try std.array_list.Managed([]const u8).initCapacity(arena, args_to_escape.len); | 782 | var escaped_args = try std.array_list.Managed([]const u8).initCapacity(arena, args_to_escape.len); |
| ... | @@ -837,21 +809,21 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { | ... | @@ -837,21 +809,21 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 837 | _ = try std.fmt.bufPrint(&args_hex_hash, "{x}", .{&args_hash}); | 809 | _ = try std.fmt.bufPrint(&args_hex_hash, "{x}", .{&args_hash}); |
| 838 | | 810 | |
| 839 | const args_file = "args" ++ Dir.path.sep_str ++ args_hex_hash; | 811 | const args_file = "args" ++ Dir.path.sep_str ++ args_hex_hash; |
| 840 | if (b.cache_root.handle.access(io, args_file, .{})) |_| { | 812 | if (graph.cache_root.handle.access(io, args_file, .{})) |_| { |
| 841 | // The args file is already present from a previous run. | 813 | // The args file is already present from a previous run. |
| 842 | } else |err| switch (err) { | 814 | } else |err| switch (err) { |
| 843 | error.FileNotFound => { | 815 | error.FileNotFound => { |
| 844 | var af = b.cache_root.handle.createFileAtomic(io, args_file, .{ | 816 | var af = graph.cache_root.handle.createFileAtomic(io, args_file, .{ |
| 845 | .replace = false, | 817 | .replace = false, |
| 846 | .make_path = true, | 818 | .make_path = true, |
| 847 | }) catch |e| return step.fail("failed creating tmp args file {f}{s}: {t}", .{ | 819 | }) catch |e| return step.fail("failed creating tmp args file {f}{s}: {t}", .{ |
| 848 | b.cache_root, args_file, e, | 820 | graph.cache_root, args_file, e, |
| 849 | }); | 821 | }); |
| 850 | defer af.deinit(io); | 822 | defer af.deinit(io); |
| 851 | | 823 | |
| 852 | af.file.writeStreamingAll(io, args) catch |e| { | 824 | af.file.writeStreamingAll(io, args) catch |e| { |
| 853 | return step.fail("failed writing args data to tmp file {f}{s}: {t}", .{ | 825 | return step.fail("failed writing args data to tmp file {f}{s}: {t}", .{ |
| 854 | b.cache_root, args_file, e, | 826 | graph.cache_root, args_file, e, |
| 855 | }); | 827 | }); |
| 856 | }; | 828 | }; |
| 857 | // Note we can't clean up this file, not even after build | 829 | // Note we can't clean up this file, not even after build |
| ... | @@ -862,7 +834,7 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { | ... | @@ -862,7 +834,7 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 862 | // The args file was created by another concurrent build process. | 834 | // The args file was created by another concurrent build process. |
| 863 | }, | 835 | }, |
| 864 | else => |other_err| return step.fail("failed linking tmp file {f}{s}: {t}", .{ | 836 | else => |other_err| return step.fail("failed linking tmp file {f}{s}: {t}", .{ |
| 865 | b.cache_root, args_file, other_err, | 837 | graph.cache_root, args_file, other_err, |
| 866 | }), | 838 | }), |
| 867 | }; | 839 | }; |
| 868 | }, | 840 | }, |
| ... | @@ -871,32 +843,34 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { | ... | @@ -871,32 +843,34 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 871 | | 843 | |
| 872 | const resolved_args_file = try mem.concat(arena, u8, &.{ | 844 | const resolved_args_file = try mem.concat(arena, u8, &.{ |
| 873 | "@", | 845 | "@", |
| 874 | try b.cache_root.join(arena, &.{args_file}), | 846 | try graph.cache_root.join(arena, &.{args_file}), |
| 875 | }); | 847 | }); |
| 876 | | 848 | |
| 877 | zig_args.shrinkRetainingCapacity(2); | 849 | zig_args.shrinkRetainingCapacity(2); |
| 878 | try zig_args.append(resolved_args_file); | 850 | try zig_args.append(gpa, resolved_args_file); |
| 879 | } | 851 | } |
| 880 | | 852 | |
| 881 | return try zig_args.toOwnedSlice(); | 853 | return try zig_args.toOwnedSlice(); |
| 882 | } | 854 | } |
| 883 | | 855 | |
| 884 | pub fn rebuildInFuzzMode(c: *Compile, maker: *Maker, progress_node: std.Progress.Node) !Path { | 856 | pub fn rebuildInFuzzMode(compile: *Compile, maker: *Maker, progress_node: std.Progress.Node) !Path { |
| 885 | const gpa = maker.graph.gpa; | 857 | const gpa = maker.graph.gpa; |
| 886 | | 858 | |
| 887 | c.step.result_error_msgs.clearRetainingCapacity(); | 859 | compile.step.result_error_msgs.clearRetainingCapacity(); |
| 888 | c.step.result_stderr = ""; | 860 | compile.step.result_stderr = ""; |
| 889 | | 861 | |
| 890 | c.step.result_error_bundle.deinit(gpa); | 862 | compile.step.result_error_bundle.deinit(gpa); |
| 891 | c.step.result_error_bundle = std.zig.ErrorBundle.empty; | 863 | compile.step.result_error_bundle = std.zig.ErrorBundle.empty; |
| 892 | | 864 | |
| 893 | if (c.step.result_failed_command) |cmd| { | 865 | if (compile.step.result_failed_command) |cmd| { |
| 894 | gpa.free(cmd); | 866 | gpa.free(cmd); |
| 895 | c.step.result_failed_command = null; | 867 | compile.step.result_failed_command = null; |
| 896 | } | 868 | } |
| 897 | | 869 | |
| 898 | const zig_args = try getZigArgs(c, maker, true); | 870 | const zig_args = &compile.zig_args; |
| 899 | const maybe_output_bin_path = try c.step.evalZigProcess(zig_args, progress_node, false, null, gpa); | 871 | zig_args.clearRetainingCapacity(); |
| | 872 | try lowerZigArgs(compile, maker, zig_args, true); |
| | 873 | const maybe_output_bin_path = try compile.step.evalZigProcess(zig_args.items, progress_node, false, maker); |
| 900 | return maybe_output_bin_path.?; | 874 | return maybe_output_bin_path.?; |
| 901 | } | 875 | } |
| 902 | | 876 | |
| ... | @@ -907,24 +881,24 @@ pub fn doAtomicSymLinks( | ... | @@ -907,24 +881,24 @@ pub fn doAtomicSymLinks( |
| 907 | filename_major_only: []const u8, | 881 | filename_major_only: []const u8, |
| 908 | filename_name_only: []const u8, | 882 | filename_name_only: []const u8, |
| 909 | ) !void { | 883 | ) !void { |
| 910 | const b = step.owner; | | |
| 911 | const graph = maker.graph; | 884 | const graph = maker.graph; |
| | 885 | const arena = graph.arena; // TODO don't leak into process arena |
| 912 | const io = graph.io; | 886 | const io = graph.io; |
| 913 | const out_dir = Dir.path.dirname(output_path) orelse "."; | 887 | const out_dir = Dir.path.dirname(output_path) orelse "."; |
| 914 | const out_basename = Dir.path.basename(output_path); | 888 | const out_basename = Dir.path.basename(output_path); |
| 915 | // sym link for libfoo.so.1 to libfoo.so.1.2.3 | 889 | // sym link for libfoo.so.1 to libfoo.so.1.2.3 |
| 916 | const major_only_path = b.pathJoin(&.{ out_dir, filename_major_only }); | 890 | const major_only_path = try Dir.path.join(arena, &.{ out_dir, filename_major_only }); |
| 917 | const cwd: Io.Dir = .cwd(); | 891 | const cwd: Io.Dir = .cwd(); |
| 918 | cwd.symLinkAtomic(io, out_basename, major_only_path, .{}) catch |err| { | 892 | cwd.symLinkAtomic(io, out_basename, major_only_path, .{}) catch |err| { |
| 919 | return step.fail("unable to symlink {s} -> {s}: {s}", .{ | 893 | return step.fail("unable to symlink {s} -> {s}: {t}", .{ |
| 920 | major_only_path, out_basename, @errorName(err), | 894 | major_only_path, out_basename, err, |
| 921 | }); | 895 | }); |
| 922 | }; | 896 | }; |
| 923 | // sym link for libfoo.so to libfoo.so.1 | 897 | // sym link for libfoo.so to libfoo.so.1 |
| 924 | const name_only_path = b.pathJoin(&.{ out_dir, filename_name_only }); | 898 | const name_only_path = try Dir.path.join(arena, &.{ out_dir, filename_name_only }); |
| 925 | cwd.symLinkAtomic(io, filename_major_only, name_only_path, .{}) catch |err| { | 899 | cwd.symLinkAtomic(io, filename_major_only, name_only_path, .{}) catch |err| { |
| 926 | return step.fail("Unable to symlink {s} -> {s}: {s}", .{ | 900 | return step.fail("unable to symlink {s} -> {s}: {t}", .{ |
| 927 | name_only_path, filename_major_only, @errorName(err), | 901 | name_only_path, filename_major_only, err, |
| 928 | }); | 902 | }); |
| 929 | }; | 903 | }; |
| 930 | } | 904 | } |
| ... | @@ -983,14 +957,13 @@ fn getPkgConfigList(b: *std.Build) ![]const PkgConfigPkg { | ... | @@ -983,14 +957,13 @@ fn getPkgConfigList(b: *std.Build) ![]const PkgConfigPkg { |
| 983 | } | 957 | } |
| 984 | } | 958 | } |
| 985 | | 959 | |
| 986 | fn addFlag(args: *std.array_list.Managed([]const u8), comptime name: []const u8, opt: ?bool) !void { | 960 | fn addBool(gpa: Allocator, args: *std.ArrayList([]const u8), arg: []const u8, opt: bool) !void { |
| | 961 | if (opt) try args.append(gpa, arg); |
| | 962 | } |
| | 963 | |
| | 964 | fn addFlag(gpa: Allocator, args: *std.ArrayList([]const u8), comptime name: []const u8, opt: ?bool) !void { |
| 987 | const cond = opt orelse return; | 965 | const cond = opt orelse return; |
| 988 | try args.ensureUnusedCapacity(1); | 966 | try args.append(gpa, if (cond) "-f" ++ name else "-fno-" ++ name); |
| 989 | if (cond) { | | |
| 990 | args.appendAssumeCapacity("-f" ++ name); | | |
| 991 | } else { | | |
| 992 | args.appendAssumeCapacity("-fno-" ++ name); | | |
| 993 | } | | |
| 994 | } | 967 | } |
| 995 | | 968 | |
| 996 | const PkgConfigResult = struct { | 969 | const PkgConfigResult = struct { |
| ... | @@ -1267,7 +1240,7 @@ const CliNamedModules = struct { | ... | @@ -1267,7 +1240,7 @@ const CliNamedModules = struct { |
| 1267 | try compile.modules.putNoClobber(arena, mod, {}); | 1240 | try compile.modules.putNoClobber(arena, mod, {}); |
| 1268 | break; | 1241 | break; |
| 1269 | } | 1242 | } |
| 1270 | name = try std.fmt.allocPrint(arena, "{s}{d}", .{ orig_name, n }); | 1243 | name = try allocPrint(arena, "{s}{d}", .{ orig_name, n }); |
| 1271 | n += 1; | 1244 | n += 1; |
| 1272 | } | 1245 | } |
| 1273 | } | 1246 | } |