| ... | ... | @@ -10,6 +10,7 @@ const Io = std.Io; |
| 10 | 10 | const Sha256 = std.crypto.hash.sha2.Sha256; |
| 11 | 11 | const assert = std.debug.assert; |
| 12 | 12 | const mem = std.mem; |
| 13 | const allocPrint = std.fmt.allocPrint; |
| 13 | 14 | |
| 14 | 15 | const Step = @import("../Step.zig"); |
| 15 | 16 | const Maker = @import("../../Maker.zig"); |
| ... | ... | @@ -17,6 +18,8 @@ const Maker = @import("../../Maker.zig"); |
| 17 | 18 | /// Populated during the make phase when there is a long-lived compiler process. |
| 18 | 19 | /// Managed by the build runner, not user build script. |
| 19 | 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 | 24 | pub fn make( |
| 22 | 25 | compile: *Compile, |
| ... | ... | @@ -24,14 +27,15 @@ pub fn make( |
| 24 | 27 | maker: *Maker, |
| 25 | 28 | progress_node: std.Progress.Node, |
| 26 | 29 | ) Step.ExtendedMakeError!void { |
| 27 | | if (true) @panic("TODO implement compile.make()"); |
| 28 | 30 | const graph = maker.graph; |
| 29 | 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 | 35 | const process_arena = graph.arena; // TODO don't leak into the process_arena |
| 32 | 36 | |
| 33 | 37 | const maybe_output_dir = step.evalZigProcess( |
| 34 | | zig_args, |
| 38 | compile.zig_args.items, |
| 35 | 39 | progress_node, |
| 36 | 40 | (graph.incremental == true) and (maker.watch or maker.web_server != null), |
| 37 | 41 | maker, |
| ... | ... | @@ -47,7 +51,7 @@ pub fn make( |
| 47 | 51 | // Update generated files |
| 48 | 52 | if (maybe_output_dir) |output_dir| { |
| 49 | 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 | 57 | // zig fmt: off |
| ... | ... | @@ -70,23 +74,26 @@ pub fn make( |
| 70 | 74 | { |
| 71 | 75 | try doAtomicSymLinks( |
| 72 | 76 | step, |
| 73 | | compile.getEmittedBin().getPath2(step.owner, step), |
| 77 | compile.getEmittedBin().getPath2(step), |
| 74 | 78 | compile.major_only_filename.?, |
| 75 | 79 | compile.name_only_filename.?, |
| 76 | 80 | ); |
| 77 | 81 | } |
| 78 | 82 | } |
| 79 | 83 | |
| 80 | | fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 81 | | const step = &compile.step; |
| 82 | | const b = step.owner; |
| 84 | fn lowerZigArgs( |
| 85 | compile: *Compile, |
| 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 | 92 | const graph = maker.graph; |
| 84 | 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); |
| 87 | | defer zig_args.deinit(); |
| 88 | | |
| 89 | | try zig_args.append(graph.zig_exe); |
| 96 | try zig_args.append(gpa, graph.zig_exe); |
| 90 | 97 | |
| 91 | 98 | const cmd = switch (compile.kind) { |
| 92 | 99 | .lib => "build-lib", |
| ... | ... | @@ -95,10 +102,10 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 95 | 102 | .@"test" => "test", |
| 96 | 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| { |
| 101 | | try zig_args.append(try std.fmt.allocPrint(arena, "-freference-trace={d}", .{some})); |
| 107 | if (graph.reference_trace) |some| { |
| 108 | try zig_args.append(gpa, try allocPrint(arena, "-freference-trace={d}", .{some})); |
| 102 | 109 | } |
| 103 | 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 | 114 | try addFlag(&zig_args, "new-linker", compile.use_new_linker); |
| 108 | 115 | |
| 109 | 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 | 120 | switch (compile.entry) { |
| 114 | 121 | .default => {}, |
| 115 | | .disabled => try zig_args.append("-fno-entry"), |
| 116 | | .enabled => try zig_args.append("-fentry"), |
| 122 | .disabled => try zig_args.append(gpa, "-fno-entry"), |
| 123 | .enabled => try zig_args.append(gpa, "-fentry"), |
| 117 | 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 | 130 | for (compile.force_undefined_symbols.keys()) |symbol_name| { |
| 124 | | try zig_args.append("--force_undefined"); |
| 125 | | try zig_args.append(symbol_name.*); |
| 131 | try zig_args.append(gpa, "--force_undefined"); |
| 132 | try zig_args.append(gpa, symbol_name.*); |
| 126 | 133 | } |
| 127 | 134 | } |
| 128 | 135 | |
| 129 | 136 | if (compile.stack_size) |stack_size| { |
| 130 | | try zig_args.append("--stack"); |
| 131 | | try zig_args.append(try std.fmt.allocPrint(arena, "{}", .{stack_size})); |
| 137 | try zig_args.append(gpa, "--stack"); |
| 138 | try zig_args.append(gpa, try allocPrint(arena, "{}", .{stack_size})); |
| 132 | 139 | } |
| 133 | 140 | |
| 134 | | if (fuzz) { |
| 135 | | try zig_args.append("-ffuzz"); |
| 136 | | } |
| 141 | try addBool(gpa, zig_args, fuzz, "-ffuzz"); |
| 137 | 142 | |
| 138 | 143 | { |
| 139 | 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 | 188 | switch (link_object) { |
| 184 | 189 | .static_path => |static_path| { |
| 185 | 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 | 192 | total_linker_objects += 1; |
| 188 | 193 | } |
| 189 | 194 | }, |
| 190 | 195 | .system_lib => |system_lib| { |
| 191 | 196 | const system_lib_gop = try seen_system_libs.getOrPut(arena, system_lib.name); |
| 192 | 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 | 199 | continue; |
| 195 | 200 | } else { |
| 196 | 201 | system_lib_gop.value_ptr.* = &.{}; |
| ... | ... | @@ -205,16 +210,16 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 205 | 210 | { |
| 206 | 211 | switch (system_lib.search_strategy) { |
| 207 | 212 | .no_fallback => switch (system_lib.preferred_link_mode) { |
| 208 | | .dynamic => try zig_args.append("-search_dylibs_only"), |
| 209 | | .static => try zig_args.append("-search_static_only"), |
| 213 | .dynamic => try zig_args.append(gpa, "-search_dylibs_only"), |
| 214 | .static => try zig_args.append(gpa, "-search_static_only"), |
| 210 | 215 | }, |
| 211 | 216 | .paths_first => switch (system_lib.preferred_link_mode) { |
| 212 | | .dynamic => try zig_args.append("-search_paths_first"), |
| 213 | | .static => try zig_args.append("-search_paths_first_static"), |
| 217 | .dynamic => try zig_args.append(gpa, "-search_paths_first"), |
| 218 | .static => try zig_args.append(gpa, "-search_paths_first_static"), |
| 214 | 219 | }, |
| 215 | 220 | .mode_first => switch (system_lib.preferred_link_mode) { |
| 216 | | .dynamic => try zig_args.append("-search_dylibs_first"), |
| 217 | | .static => try zig_args.append("-search_static_first"), |
| 221 | .dynamic => try zig_args.append(gpa, "-search_dylibs_first"), |
| 222 | .static => try zig_args.append(gpa, "-search_static_first"), |
| 218 | 223 | }, |
| 219 | 224 | } |
| 220 | 225 | prev_search_strategy = system_lib.search_strategy; |
| ... | ... | @@ -227,11 +232,11 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 227 | 232 | break :prefix "-l"; |
| 228 | 233 | }; |
| 229 | 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 | 236 | .yes, .force => { |
| 232 | 237 | if (compile.runPkgConfig(maker, system_lib.name)) |result| { |
| 233 | | try zig_args.appendSlice(result.cflags); |
| 234 | | try zig_args.appendSlice(result.libs); |
| 238 | try zig_args.appendSlice(gpa, result.cflags); |
| 239 | try zig_args.appendSlice(gpa, result.libs); |
| 235 | 240 | try seen_system_libs.put(arena, system_lib.name, result.cflags); |
| 236 | 241 | } else |err| switch (err) { |
| 237 | 242 | error.PkgConfigInvalidOutput, |
| ... | ... | @@ -243,7 +248,7 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 243 | 248 | .yes => { |
| 244 | 249 | // pkg-config failed, so fall back to linking the library |
| 245 | 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 | 252 | prefix, |
| 248 | 253 | system_lib.name, |
| 249 | 254 | })); |
| ... | ... | @@ -267,7 +272,7 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 267 | 272 | const included_in_lib_or_obj = !my_responsibility and |
| 268 | 273 | (dep_compile.kind == .lib or dep_compile.kind == .obj or dep_compile.kind == .test_obj); |
| 269 | 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 | 276 | total_linker_objects += 1; |
| 272 | 277 | } |
| 273 | 278 | }, |
| ... | ... | @@ -288,15 +293,15 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 288 | 293 | else |
| 289 | 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 | 297 | total_linker_objects += 1; |
| 293 | 298 | |
| 294 | 299 | if (other.linkage == .dynamic and |
| 295 | 300 | compile.rootModuleTarget().os.tag != .windows) |
| 296 | 301 | { |
| 297 | 302 | if (Dir.path.dirname(full_path_lib)) |dirname| { |
| 298 | | try zig_args.append("-rpath"); |
| 299 | | try zig_args.append(dirname); |
| 303 | try zig_args.append(gpa, "-rpath"); |
| 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 | 311 | if (!my_responsibility) break :l; |
| 307 | 312 | |
| 308 | 313 | if (prev_has_cflags) { |
| 309 | | try zig_args.append("-cflags"); |
| 310 | | try zig_args.append("--"); |
| 314 | try zig_args.append(gpa, "-cflags"); |
| 315 | try zig_args.append(gpa, "--"); |
| 311 | 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 | 319 | total_linker_objects += 1; |
| 315 | 320 | }, |
| 316 | 321 | |
| ... | ... | @@ -318,24 +323,24 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 318 | 323 | if (!my_responsibility) break :l; |
| 319 | 324 | |
| 320 | 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 | 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 | 332 | prev_has_cflags = (c_source_file.flags.len != 0); |
| 328 | 333 | |
| 329 | 334 | if (c_source_file.language) |lang| { |
| 330 | | try zig_args.append("-x"); |
| 331 | | try zig_args.append(lang.internalIdentifier()); |
| 335 | try zig_args.append(gpa, "-x"); |
| 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 | 341 | if (c_source_file.language != null) { |
| 337 | | try zig_args.append("-x"); |
| 338 | | try zig_args.append("none"); |
| 342 | try zig_args.append(gpa, "-x"); |
| 343 | try zig_args.append(gpa, "none"); |
| 339 | 344 | } |
| 340 | 345 | total_linker_objects += 1; |
| 341 | 346 | }, |
| ... | ... | @@ -344,27 +349,27 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 344 | 349 | if (!my_responsibility) break :l; |
| 345 | 350 | |
| 346 | 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 | 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 | 358 | prev_has_cflags = (c_source_files.flags.len != 0); |
| 354 | 359 | |
| 355 | 360 | if (c_source_files.language) |lang| { |
| 356 | | try zig_args.append("-x"); |
| 357 | | try zig_args.append(lang.internalIdentifier()); |
| 361 | try zig_args.append(gpa, "-x"); |
| 362 | try zig_args.append(gpa, lang.internalIdentifier()); |
| 358 | 363 | } |
| 359 | 364 | |
| 360 | 365 | const root_path = c_source_files.root.getPath2(mod.owner, step); |
| 361 | 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 | 370 | if (c_source_files.language != null) { |
| 366 | | try zig_args.append("-x"); |
| 367 | | try zig_args.append("none"); |
| 371 | try zig_args.append(gpa, "-x"); |
| 372 | try zig_args.append(gpa, "none"); |
| 368 | 373 | } |
| 369 | 374 | |
| 370 | 375 | total_linker_objects += c_source_files.files.len; |
| ... | ... | @@ -375,23 +380,23 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 375 | 380 | |
| 376 | 381 | if (rc_source_file.flags.len == 0 and rc_source_file.include_paths.len == 0) { |
| 377 | 382 | if (prev_has_rcflags) { |
| 378 | | try zig_args.append("-rcflags"); |
| 379 | | try zig_args.append("--"); |
| 383 | try zig_args.append(gpa, "-rcflags"); |
| 384 | try zig_args.append(gpa, "--"); |
| 380 | 385 | prev_has_rcflags = false; |
| 381 | 386 | } |
| 382 | 387 | } else { |
| 383 | | try zig_args.append("-rcflags"); |
| 388 | try zig_args.append(gpa, "-rcflags"); |
| 384 | 389 | for (rc_source_file.flags) |arg| { |
| 385 | | try zig_args.append(arg); |
| 390 | try zig_args.append(gpa, arg); |
| 386 | 391 | } |
| 387 | 392 | for (rc_source_file.include_paths) |include_path| { |
| 388 | | try zig_args.append("/I"); |
| 389 | | try zig_args.append(include_path.getPath2(mod.owner, step)); |
| 393 | try zig_args.append(gpa, "/I"); |
| 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 | 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 | 400 | total_linker_objects += 1; |
| 396 | 401 | }, |
| 397 | 402 | } |
| ... | ... | @@ -414,7 +419,7 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 414 | 419 | if (std.mem.eql(u8, import_cli_name, name)) { |
| 415 | 420 | zig_args.appendAssumeCapacity(import_cli_name); |
| 416 | 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 | 432 | // files must have a module parent. |
| 428 | 433 | if (mod.root_source_file) |lp| { |
| 429 | 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 | 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 | 446 | |
| 442 | 447 | for (frameworks.keys(), frameworks.values()) |name, info| { |
| 443 | 448 | if (info.needed) { |
| 444 | | try zig_args.append("-needed_framework"); |
| 449 | try zig_args.append(gpa, "-needed_framework"); |
| 445 | 450 | } else if (info.weak) { |
| 446 | | try zig_args.append("-weak_framework"); |
| 451 | try zig_args.append(gpa, "-weak_framework"); |
| 447 | 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 | 458 | if (compile.is_linking_libcpp) { |
| 454 | | try zig_args.append("-lc++"); |
| 459 | try zig_args.append(gpa, "-lc++"); |
| 455 | 460 | } |
| 456 | 461 | |
| 457 | 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 | 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 | 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 | 475 | if (compile.image_base) |image_base| { |
| 471 | | try zig_args.append("--image-base"); |
| 472 | | try zig_args.append(b.fmt("0x{x}", .{image_base})); |
| 476 | try zig_args.appendSlice(gpa, &.{ |
| 477 | "--image-base", try allocPrint(arena, "0x{x}", .{image_base}), |
| 478 | }); |
| 473 | 479 | } |
| 474 | 480 | |
| 475 | 481 | for (compile.filters) |filter| { |
| 476 | | try zig_args.append("--test-filter"); |
| 477 | | try zig_args.append(filter); |
| 482 | try zig_args.appendSlice(gpa, &.{ "--test-filter", filter }); |
| 478 | 483 | } |
| 479 | 484 | |
| 480 | 485 | if (compile.test_runner) |test_runner| { |
| 481 | | try zig_args.append("--test-runner"); |
| 482 | | try zig_args.append(test_runner.path.getPath2(b, step)); |
| 486 | try zig_args.appendSlice(gpa, &.{ "--test-runner", test_runner.path.getPath2(step) }); |
| 483 | 487 | } |
| 484 | 488 | |
| 485 | | for (b.debug_log_scopes) |log_scope| { |
| 486 | | try zig_args.append("--debug-log"); |
| 487 | | try zig_args.append(log_scope); |
| 489 | for (graph.debug_log_scopes) |log_scope| { |
| 490 | try zig_args.appendSlice(gpa, &.{ "--debug-log", log_scope }); |
| 488 | 491 | } |
| 489 | 492 | |
| 490 | | if (b.debug_compile_errors) { |
| 491 | | try zig_args.append("--debug-compile-errors"); |
| 492 | | } |
| 493 | try addBool(gpa, zig_args, graph.debug_compile_errors, "--debug-compile-errors"); |
| 494 | try addBool(gpa, zig_args, graph.debug_incremental, "--debug-incremental"); |
| 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) { |
| 495 | | try zig_args.append("--debug-incremental"); |
| 496 | | } |
| 497 | | |
| 498 | | if (b.verbose_air) try zig_args.append("--verbose-air"); |
| 499 | | if (b.verbose_llvm_ir) |path| try zig_args.append(b.fmt("--verbose-llvm-ir={s}", .{path})); |
| 500 | | if (b.verbose_llvm_bc) |path| try zig_args.append(b.fmt("--verbose-llvm-bc={s}", .{path})); |
| 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"); |
| 502 | if (compile.generated_asm != null) try zig_args.append(gpa, "-femit-asm"); |
| 503 | if (compile.generated_bin == null) try zig_args.append(gpa, "-fno-emit-bin"); |
| 504 | if (compile.generated_docs != null) try zig_args.append(gpa, "-femit-docs"); |
| 505 | if (compile.generated_implib != null) try zig_args.append(gpa, "-femit-implib"); |
| 506 | if (compile.generated_llvm_bc != null) try zig_args.append(gpa, "-femit-llvm-bc"); |
| 507 | if (compile.generated_llvm_ir != null) try zig_args.append(gpa, "-femit-llvm-ir"); |
| 508 | if (compile.generated_h != null) try zig_args.append(gpa, "-femit-h"); |
| 513 | 509 | |
| 514 | 510 | try addFlag(&zig_args, "formatted-panics", compile.formatted_panics); |
| 515 | 511 | |
| 516 | 512 | switch (compile.compress_debug_sections) { |
| 517 | 513 | .none => {}, |
| 518 | | .zlib => try zig_args.append("--compress-debug-sections=zlib"), |
| 519 | | .zstd => try zig_args.append("--compress-debug-sections=zstd"), |
| 514 | .zlib => try zig_args.append(gpa, "--compress-debug-sections=zlib"), |
| 515 | .zstd => try zig_args.append(gpa, "--compress-debug-sections=zstd"), |
| 520 | 516 | } |
| 521 | 517 | |
| 522 | 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 | 521 | if (compile.link_emit_relocs) { |
| 526 | | try zig_args.append("--emit-relocs"); |
| 522 | try zig_args.append(gpa, "--emit-relocs"); |
| 527 | 523 | } |
| 528 | 524 | if (compile.link_function_sections) { |
| 529 | | try zig_args.append("-ffunction-sections"); |
| 525 | try zig_args.append(gpa, "-ffunction-sections"); |
| 530 | 526 | } |
| 531 | 527 | if (compile.link_data_sections) { |
| 532 | | try zig_args.append("-fdata-sections"); |
| 528 | try zig_args.append(gpa, "-fdata-sections"); |
| 533 | 529 | } |
| 534 | 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 | 533 | if (!compile.linker_dynamicbase) { |
| 538 | | try zig_args.append("--no-dynamicbase"); |
| 534 | try zig_args.append(gpa, "--no-dynamicbase"); |
| 539 | 535 | } |
| 540 | 536 | if (compile.linker_allow_shlib_undefined) |x| { |
| 541 | | try zig_args.append(if (x) "-fallow-shlib-undefined" else "-fno-allow-shlib-undefined"); |
| 542 | | } |
| 543 | | if (compile.link_z_notext) { |
| 544 | | try zig_args.append("-z"); |
| 545 | | try zig_args.append("notext"); |
| 546 | | } |
| 547 | | if (!compile.link_z_relro) { |
| 548 | | try zig_args.append("-z"); |
| 549 | | try zig_args.append("norelro"); |
| 550 | | } |
| 551 | | if (compile.link_z_lazy) { |
| 552 | | try zig_args.append("-z"); |
| 553 | | try zig_args.append("lazy"); |
| 554 | | } |
| 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 | | } |
| 537 | try zig_args.append(gpa, if (x) "-fallow-shlib-undefined" else "-fno-allow-shlib-undefined"); |
| 538 | } |
| 539 | if (compile.link_z_notext) try zig_args.appendSlice(gpa, &.{ "-z", "notext" }); |
| 540 | if (!compile.link_z_relro) try zig_args.appendSlice(gpa, &.{ "-z", "norelro" }); |
| 541 | if (compile.link_z_lazy) try zig_args.appendSlice(gpa, &.{ "-z", "lazy" }); |
| 542 | if (compile.link_z_common_page_size) |size| try zig_args.appendSlice(gpa, &.{ |
| 543 | "-z", |
| 544 | try allocPrint(arena, "common-page-size={d}", .{size}), |
| 545 | }); |
| 546 | if (compile.link_z_max_page_size) |size| try zig_args.appendSlice(gpa, &.{ |
| 547 | "-z", |
| 548 | try allocPrint(arena, "max-page-size={d}", .{size}), |
| 549 | }); |
| 550 | if (compile.link_z_defs) try zig_args.appendSlice(gpa, &.{ "-z", "defs" }); |
| 567 | 551 | |
| 568 | 552 | if (compile.libc_file) |libc_file| { |
| 569 | | try zig_args.append("--libc"); |
| 570 | | try zig_args.append(libc_file.getPath2(b, step)); |
| 571 | | } else if (b.libc_file) |libc_file| { |
| 572 | | try zig_args.append("--libc"); |
| 573 | | try zig_args.append(libc_file); |
| 553 | try zig_args.appendSlice(gpa, &.{ "--libc", libc_file.getPath2(step) }); |
| 554 | } else if (graph.libc_file) |libc_file| { |
| 555 | try zig_args.appendSlice(gpa, &.{ "--libc", libc_file }); |
| 574 | 556 | } |
| 575 | 557 | |
| 576 | | try zig_args.append("--cache-dir"); |
| 577 | | try zig_args.append(b.cache_root.path orelse "."); |
| 558 | try zig_args.append(gpa, "--cache-dir"); |
| 559 | try zig_args.append(gpa, graph.cache_root.path orelse "."); |
| 578 | 560 | |
| 579 | | try zig_args.append("--global-cache-dir"); |
| 580 | | try zig_args.append(graph.global_cache_root.path orelse "."); |
| 561 | try zig_args.append(gpa, "--global-cache-dir"); |
| 562 | try zig_args.append(gpa, graph.global_cache_root.path orelse "."); |
| 581 | 563 | |
| 582 | 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"); |
| 586 | | try zig_args.append(compile.name); |
| 567 | try zig_args.append(gpa, "--name"); |
| 568 | try zig_args.append(gpa, compile.name); |
| 587 | 569 | |
| 588 | 570 | if (compile.linkage) |some| switch (some) { |
| 589 | | .dynamic => try zig_args.append("-dynamic"), |
| 590 | | .static => try zig_args.append("-static"), |
| 571 | .dynamic => try zig_args.append(gpa, "-dynamic"), |
| 572 | .static => try zig_args.append(gpa, "-static"), |
| 591 | 573 | }; |
| 592 | 574 | if (compile.kind == .lib and compile.linkage != null and compile.linkage.? == .dynamic) { |
| 593 | 575 | if (compile.version) |version| { |
| 594 | | try zig_args.append("--version"); |
| 595 | | try zig_args.append(b.fmt("{f}", .{version})); |
| 576 | try zig_args.append(gpa, "--version"); |
| 577 | try zig_args.append(gpa, try allocPrint(arena, "{f}", .{version})); |
| 596 | 578 | } |
| 597 | 579 | |
| 598 | 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 | 582 | compile.rootModuleTarget().libPrefix(), |
| 601 | 583 | compile.name, |
| 602 | 584 | compile.rootModuleTarget().dynamicLibSuffix(), |
| 603 | 585 | }); |
| 604 | | try zig_args.append("-install_name"); |
| 605 | | try zig_args.append(install_name); |
| 586 | try zig_args.append(gpa, "-install_name"); |
| 587 | try zig_args.append(gpa, install_name); |
| 606 | 588 | } |
| 607 | 589 | } |
| 608 | 590 | |
| 609 | 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 | 594 | if (compile.pagezero_size) |pagezero_size| { |
| 613 | | const size = try std.fmt.allocPrint(arena, "{x}", .{pagezero_size}); |
| 614 | | try zig_args.appendSlice(&[_][]const u8{ "-pagezero_size", size }); |
| 595 | const size = try allocPrint(arena, "{x}", .{pagezero_size}); |
| 596 | try zig_args.appendSlice(gpa, &[_][]const u8{ "-pagezero_size", size }); |
| 615 | 597 | } |
| 616 | 598 | if (compile.headerpad_size) |headerpad_size| { |
| 617 | | const size = try std.fmt.allocPrint(arena, "{x}", .{headerpad_size}); |
| 618 | | try zig_args.appendSlice(&[_][]const u8{ "-headerpad", size }); |
| 599 | const size = try allocPrint(arena, "{x}", .{headerpad_size}); |
| 600 | try zig_args.appendSlice(gpa, &[_][]const u8{ "-headerpad", size }); |
| 619 | 601 | } |
| 620 | 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 | 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 | 608 | if (compile.force_load_objc) { |
| 627 | | try zig_args.append("-ObjC"); |
| 609 | try zig_args.append(gpa, "-ObjC"); |
| 628 | 610 | } |
| 629 | 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 | 615 | try addFlag(&zig_args, "compiler-rt", compile.bundle_compiler_rt); |
| 634 | 616 | try addFlag(&zig_args, "ubsan-rt", compile.bundle_ubsan_rt); |
| 635 | 617 | try addFlag(&zig_args, "dll-export-fns", compile.dll_export_fns); |
| 636 | 618 | if (compile.rdynamic) { |
| 637 | | try zig_args.append("-rdynamic"); |
| 619 | try zig_args.append(gpa, "-rdynamic"); |
| 638 | 620 | } |
| 639 | 621 | if (compile.import_memory) { |
| 640 | | try zig_args.append("--import-memory"); |
| 622 | try zig_args.append(gpa, "--import-memory"); |
| 641 | 623 | } |
| 642 | 624 | if (compile.export_memory) { |
| 643 | | try zig_args.append("--export-memory"); |
| 625 | try zig_args.append(gpa, "--export-memory"); |
| 644 | 626 | } |
| 645 | 627 | if (compile.import_symbols) { |
| 646 | | try zig_args.append("--import-symbols"); |
| 628 | try zig_args.append(gpa, "--import-symbols"); |
| 647 | 629 | } |
| 648 | 630 | if (compile.import_table) { |
| 649 | | try zig_args.append("--import-table"); |
| 631 | try zig_args.append(gpa, "--import-table"); |
| 650 | 632 | } |
| 651 | 633 | if (compile.export_table) { |
| 652 | | try zig_args.append("--export-table"); |
| 634 | try zig_args.append(gpa, "--export-table"); |
| 653 | 635 | } |
| 654 | 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 | 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 | 642 | if (compile.shared_memory) { |
| 661 | | try zig_args.append("--shared-memory"); |
| 643 | try zig_args.append(gpa, "--shared-memory"); |
| 662 | 644 | } |
| 663 | 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 | 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 | 652 | if (compile.linker_script) |linker_script| { |
| 671 | | try zig_args.append("--script"); |
| 672 | | try zig_args.append(linker_script.getPath2(b, step)); |
| 653 | try zig_args.append(gpa, "--script"); |
| 654 | try zig_args.append(gpa, linker_script.getPath2(step)); |
| 673 | 655 | } |
| 674 | 656 | |
| 675 | 657 | if (compile.version_script) |version_script| { |
| 676 | | try zig_args.append("--version-script"); |
| 677 | | try zig_args.append(version_script.getPath2(b, step)); |
| 658 | try zig_args.append(gpa, "--version-script"); |
| 659 | try zig_args.append(gpa, version_script.getPath2(step)); |
| 678 | 660 | } |
| 679 | 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 | 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 | 669 | if (compile.kind == .@"test") { |
| 688 | 670 | if (compile.exec_cmd_args) |exec_cmd_args| { |
| 689 | 671 | for (exec_cmd_args) |cmd_arg| { |
| 690 | 672 | if (cmd_arg) |arg| { |
| 691 | | try zig_args.append("--test-cmd"); |
| 692 | | try zig_args.append(arg); |
| 673 | try zig_args.append(gpa, "--test-cmd"); |
| 674 | try zig_args.append(gpa, arg); |
| 693 | 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| { |
| 701 | | try zig_args.appendSlice(&[_][]const u8{ "--sysroot", sysroot }); |
| 702 | | } |
| 682 | if (graph.sysroot) |sysroot| try zig_args.appendSlice(gpa, &.{ "--sysroot", sysroot }); |
| 703 | 683 | |
| 704 | 684 | // -I and -L arguments that appear after the last --mod argument apply to all modules. |
| 705 | 685 | const cwd: Io.Dir = .cwd(); |
| 706 | 686 | const io = graph.io; |
| 707 | 687 | |
| 708 | | for (b.search_prefixes.items) |search_prefix| { |
| 688 | for (graph.search_prefixes.items) |search_prefix| { |
| 709 | 689 | var prefix_dir = cwd.openDir(io, search_prefix, .{}) catch |err| { |
| 710 | | return step.fail("unable to open prefix directory '{s}': {s}", .{ |
| 711 | | search_prefix, @errorName(err), |
| 712 | | }); |
| 690 | return step.fail("unable to open prefix directory '{s}': {t}", .{ search_prefix, err }); |
| 713 | 691 | }; |
| 714 | 692 | defer prefix_dir.close(io); |
| 715 | 693 | |
| ... | ... | @@ -718,58 +696,53 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 718 | 696 | // CLI parsing code, when the linker sees an -L directory that does not exist. |
| 719 | 697 | |
| 720 | 698 | if (prefix_dir.access(io, "lib", .{})) |_| { |
| 721 | | try zig_args.appendSlice(&.{ |
| 722 | | "-L", b.pathJoin(&.{ search_prefix, "lib" }), |
| 699 | try zig_args.appendSlice(gpa, &.{ |
| 700 | "-L", try Dir.path.join(arena, &.{ search_prefix, "lib" }), |
| 723 | 701 | }); |
| 724 | 702 | } else |err| switch (err) { |
| 725 | 703 | error.FileNotFound => {}, |
| 726 | | else => |e| return step.fail("unable to access '{s}/lib' directory: {s}", .{ |
| 727 | | search_prefix, @errorName(e), |
| 728 | | }), |
| 704 | else => |e| return step.fail("unable to access '{s}/lib' directory: {t}", .{ search_prefix, e }), |
| 729 | 705 | } |
| 730 | 706 | |
| 731 | 707 | if (prefix_dir.access(io, "include", .{})) |_| { |
| 732 | | try zig_args.appendSlice(&.{ |
| 733 | | "-I", b.pathJoin(&.{ search_prefix, "include" }), |
| 708 | try zig_args.appendSlice(gpa, &.{ |
| 709 | "-I", try Dir.path.join(arena, &.{ search_prefix, "include" }), |
| 734 | 710 | }); |
| 735 | 711 | } else |err| switch (err) { |
| 736 | 712 | error.FileNotFound => {}, |
| 737 | | else => |e| return step.fail("unable to access '{s}/include' directory: {s}", .{ |
| 738 | | search_prefix, @errorName(e), |
| 739 | | }), |
| 713 | else => |e| return step.fail("unable to access '{s}/include' directory: {t}", .{ search_prefix, e }), |
| 740 | 714 | } |
| 741 | 715 | } |
| 742 | 716 | |
| 743 | 717 | if (compile.rc_includes != .any) { |
| 744 | | try zig_args.append("-rcincludes"); |
| 745 | | try zig_args.append(@tagName(compile.rc_includes)); |
| 718 | try zig_args.appendSlice(gpa, &.{ "-rcincludes", @tagName(compile.rc_includes) }); |
| 746 | 719 | } |
| 747 | 720 | |
| 748 | 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| { |
| 751 | | try zig_args.append(switch (build_id) { |
| 752 | | .hexstring => |hs| b.fmt("--build-id=0x{x}", .{hs.toSlice()}), |
| 753 | | .none, .fast, .uuid, .sha1, .md5 => b.fmt("--build-id={s}", .{@tagName(build_id)}), |
| 723 | if (compile.build_id orelse graph.build_id) |build_id| { |
| 724 | try zig_args.append(gpa, switch (build_id) { |
| 725 | .hexstring => |hs| try allocPrint(arena, "--build-id=0x{x}", .{hs.toSlice()}), |
| 726 | .none, .fast, .uuid, .sha1, .md5 => try allocPrint(arena, "--build-id={t}", .{build_id}), |
| 754 | 727 | }); |
| 755 | 728 | } |
| 756 | 729 | |
| 757 | 730 | const opt_zig_lib_dir = if (compile.zig_lib_dir) |dir| |
| 758 | | dir.getPath2(b, step) |
| 731 | dir.getPath2(step) |
| 759 | 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 | 734 | else |
| 762 | 735 | null; |
| 763 | 736 | |
| 764 | 737 | if (opt_zig_lib_dir) |zig_lib_dir| { |
| 765 | | try zig_args.append("--zig-lib-dir"); |
| 766 | | try zig_args.append(zig_lib_dir); |
| 738 | try zig_args.append(gpa, "--zig-lib-dir"); |
| 739 | try zig_args.append(gpa, zig_lib_dir); |
| 767 | 740 | } |
| 768 | 741 | |
| 769 | 742 | try addFlag(&zig_args, "PIE", compile.pie); |
| 770 | 743 | |
| 771 | 744 | if (compile.lto) |lto| { |
| 772 | | try zig_args.append(switch (lto) { |
| 745 | try zig_args.append(gpa, switch (lto) { |
| 773 | 746 | .full => "-flto=full", |
| 774 | 747 | .thin => "-flto=thin", |
| 775 | 748 | .none => "-fno-lto", |
| ... | ... | @@ -779,21 +752,20 @@ fn getZigArgs(compile: *Compile, maker: *Maker, fuzz: bool) ![][]const u8 { |
| 779 | 752 | try addFlag(&zig_args, "sanitize-coverage-trace-pc-guard", compile.sanitize_coverage_trace_pc_guard); |
| 780 | 753 | |
| 781 | 754 | if (compile.subsystem) |subsystem| { |
| 782 | | try zig_args.append("--subsystem"); |
| 783 | | try zig_args.append(@tagName(subsystem)); |
| 755 | try zig_args.appendSlice(gpa, &.{ "--subsystem", @tagName(subsystem) }); |
| 784 | 756 | } |
| 785 | 757 | |
| 786 | 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(&.{ |
| 791 | | "--error-limit", b.fmt("{d}", .{err_limit}), |
| 762 | if (compile.error_limit) |err_limit| try zig_args.appendSlice(gpa, &.{ |
| 763 | "--error-limit", try allocPrint(arena, "{d}", .{err_limit}), |
| 792 | 764 | }); |
| 793 | 765 | |
| 794 | 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 | 770 | // Windows has an argument length limit of 32,766 characters, macOS 262,144 and Linux |
| 799 | 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 | 776 | args_length += arg.len + 1; // +1 to account for null terminator |
| 805 | 777 | } |
| 806 | 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 | 781 | const args_to_escape = zig_args.items[2..]; |
| 810 | 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 | 809 | _ = try std.fmt.bufPrint(&args_hex_hash, "{x}", .{&args_hash}); |
| 838 | 810 | |
| 839 | 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 | 813 | // The args file is already present from a previous run. |
| 842 | 814 | } else |err| switch (err) { |
| 843 | 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 | 817 | .replace = false, |
| 846 | 818 | .make_path = true, |
| 847 | 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 | 822 | defer af.deinit(io); |
| 851 | 823 | |
| 852 | 824 | af.file.writeStreamingAll(io, args) catch |e| { |
| 853 | 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 | 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 | 834 | // The args file was created by another concurrent build process. |
| 863 | 835 | }, |
| 864 | 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 | 843 | |
| 872 | 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 | 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 | 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 | 857 | const gpa = maker.graph.gpa; |
| 886 | 858 | |
| 887 | | c.step.result_error_msgs.clearRetainingCapacity(); |
| 888 | | c.step.result_stderr = ""; |
| 859 | compile.step.result_error_msgs.clearRetainingCapacity(); |
| 860 | compile.step.result_stderr = ""; |
| 889 | 861 | |
| 890 | | c.step.result_error_bundle.deinit(gpa); |
| 891 | | c.step.result_error_bundle = std.zig.ErrorBundle.empty; |
| 862 | compile.step.result_error_bundle.deinit(gpa); |
| 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 | 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); |
| 899 | | const maybe_output_bin_path = try c.step.evalZigProcess(zig_args, progress_node, false, null, gpa); |
| 870 | const zig_args = &compile.zig_args; |
| 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 | 874 | return maybe_output_bin_path.?; |
| 901 | 875 | } |
| 902 | 876 | |
| ... | ... | @@ -907,24 +881,24 @@ pub fn doAtomicSymLinks( |
| 907 | 881 | filename_major_only: []const u8, |
| 908 | 882 | filename_name_only: []const u8, |
| 909 | 883 | ) !void { |
| 910 | | const b = step.owner; |
| 911 | 884 | const graph = maker.graph; |
| 885 | const arena = graph.arena; // TODO don't leak into process arena |
| 912 | 886 | const io = graph.io; |
| 913 | 887 | const out_dir = Dir.path.dirname(output_path) orelse "."; |
| 914 | 888 | const out_basename = Dir.path.basename(output_path); |
| 915 | 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 | 891 | const cwd: Io.Dir = .cwd(); |
| 918 | 892 | cwd.symLinkAtomic(io, out_basename, major_only_path, .{}) catch |err| { |
| 919 | | return step.fail("unable to symlink {s} -> {s}: {s}", .{ |
| 920 | | major_only_path, out_basename, @errorName(err), |
| 893 | return step.fail("unable to symlink {s} -> {s}: {t}", .{ |
| 894 | major_only_path, out_basename, err, |
| 921 | 895 | }); |
| 922 | 896 | }; |
| 923 | 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 | 899 | cwd.symLinkAtomic(io, filename_major_only, name_only_path, .{}) catch |err| { |
| 926 | | return step.fail("Unable to symlink {s} -> {s}: {s}", .{ |
| 927 | | name_only_path, filename_major_only, @errorName(err), |
| 900 | return step.fail("unable to symlink {s} -> {s}: {t}", .{ |
| 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 | 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 | 965 | const cond = opt orelse return; |
| 988 | | try args.ensureUnusedCapacity(1); |
| 989 | | if (cond) { |
| 990 | | args.appendAssumeCapacity("-f" ++ name); |
| 991 | | } else { |
| 992 | | args.appendAssumeCapacity("-fno-" ++ name); |
| 993 | | } |
| 966 | try args.append(gpa, if (cond) "-f" ++ name else "-fno-" ++ name); |
| 994 | 967 | } |
| 995 | 968 | |
| 996 | 969 | const PkgConfigResult = struct { |
| ... | ... | @@ -1267,7 +1240,7 @@ const CliNamedModules = struct { |
| 1267 | 1240 | try compile.modules.putNoClobber(arena, mod, {}); |
| 1268 | 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 | 1244 | n += 1; |
| 1272 | 1245 | } |
| 1273 | 1246 | } |