| author | |
| committer | |
| log | 73cf7b64291ed8b5dcb4cb52df103be08f15a347 |
| tree | bc5d933ec1440850e910b71dfa9166c87fc53d62 |
| parent | 71ff60f1265da83e619b1b6b2488ecb448fdfd36 |
80 files changed, 906 insertions(+), 495 deletions(-)
build.zig+42-30| ... | @@ -23,7 +23,7 @@ pub fn build(b: *Builder) !void { | ... | @@ -23,7 +23,7 @@ pub fn build(b: *Builder) !void { |
| 23 | } | 23 | } |
| 24 | break :t b.standardTargetOptions(.{ .default_target = default_target }); | 24 | break :t b.standardTargetOptions(.{ .default_target = default_target }); |
| 25 | }; | 25 | }; |
| 26 | const mode: std.builtin.Mode = if (release) switch (target.getCpuArch()) { | 26 | const optimize: std.builtin.OptimizeMode = if (release) switch (target.getCpuArch()) { |
| 27 | .wasm32 => .ReleaseSmall, | 27 | .wasm32 => .ReleaseSmall, |
| 28 | else => .ReleaseFast, | 28 | else => .ReleaseFast, |
| 29 | } else .Debug; | 29 | } else .Debug; |
| ... | @@ -33,7 +33,12 @@ pub fn build(b: *Builder) !void { | ... | @@ -33,7 +33,12 @@ pub fn build(b: *Builder) !void { |
| 33 | 33 | ||
| 34 | const test_step = b.step("test", "Run all the tests"); | 34 | const test_step = b.step("test", "Run all the tests"); |
| 35 | 35 | ||
| 36 | const docgen_exe = b.addExecutable("docgen", "doc/docgen.zig"); | 36 | const docgen_exe = b.addExecutable(.{ |
| 37 | .name = "docgen", | ||
| 38 | .root_source_file = .{ .path = "doc/docgen.zig" }, | ||
| 39 | .target = .{}, | ||
| 40 | .optimize = .Debug, | ||
| 41 | }); | ||
| 37 | docgen_exe.single_threaded = single_threaded; | 42 | docgen_exe.single_threaded = single_threaded; |
| 38 | 43 | ||
| 39 | const rel_zig_exe = try fs.path.relative(b.allocator, b.build_root, b.zig_exe); | 44 | const rel_zig_exe = try fs.path.relative(b.allocator, b.build_root, b.zig_exe); |
| ... | @@ -53,10 +58,12 @@ pub fn build(b: *Builder) !void { | ... | @@ -53,10 +58,12 @@ pub fn build(b: *Builder) !void { |
| 53 | const docs_step = b.step("docs", "Build documentation"); | 58 | const docs_step = b.step("docs", "Build documentation"); |
| 54 | docs_step.dependOn(&docgen_cmd.step); | 59 | docs_step.dependOn(&docgen_cmd.step); |
| 55 | 60 | ||
| 56 | const test_cases = b.addTest("src/test.zig"); | 61 | const test_cases = b.addTest(.{ |
| 62 | .root_source_file = .{ .path = "src/test.zig" }, | ||
| 63 | .optimize = optimize, | ||
| 64 | }); | ||
| 57 | test_cases.main_pkg_path = "."; | 65 | test_cases.main_pkg_path = "."; |
| 58 | test_cases.stack_size = stack_size; | 66 | test_cases.stack_size = stack_size; |
| 59 | test_cases.setBuildMode(mode); | ||
| 60 | test_cases.single_threaded = single_threaded; | 67 | test_cases.single_threaded = single_threaded; |
| 61 | 68 | ||
| 62 | const fmt_build_zig = b.addFmt(&[_][]const u8{"build.zig"}); | 69 | const fmt_build_zig = b.addFmt(&[_][]const u8{"build.zig"}); |
| ... | @@ -149,17 +156,15 @@ pub fn build(b: *Builder) !void { | ... | @@ -149,17 +156,15 @@ pub fn build(b: *Builder) !void { |
| 149 | 156 | ||
| 150 | const mem_leak_frames: u32 = b.option(u32, "mem-leak-frames", "How many stack frames to print when a memory leak occurs. Tests get 2x this amount.") orelse blk: { | 157 | const mem_leak_frames: u32 = b.option(u32, "mem-leak-frames", "How many stack frames to print when a memory leak occurs. Tests get 2x this amount.") orelse blk: { |
| 151 | if (strip == true) break :blk @as(u32, 0); | 158 | if (strip == true) break :blk @as(u32, 0); |
| 152 | if (mode != .Debug) break :blk 0; | 159 | if (optimize != .Debug) break :blk 0; |
| 153 | break :blk 4; | 160 | break :blk 4; |
| 154 | }; | 161 | }; |
| 155 | 162 | ||
| 156 | const exe = addCompilerStep(b); | 163 | const exe = addCompilerStep(b, optimize, target); |
| 157 | exe.strip = strip; | 164 | exe.strip = strip; |
| 158 | exe.sanitize_thread = sanitize_thread; | 165 | exe.sanitize_thread = sanitize_thread; |
| 159 | exe.build_id = b.option(bool, "build-id", "Include a build id note") orelse false; | 166 | exe.build_id = b.option(bool, "build-id", "Include a build id note") orelse false; |
| 160 | exe.install(); | 167 | exe.install(); |
| 161 | exe.setBuildMode(mode); | ||
| 162 | exe.setTarget(target); | ||
| 163 | 168 | ||
| 164 | const compile_step = b.step("compile", "Build the self-hosted compiler"); | 169 | const compile_step = b.step("compile", "Build the self-hosted compiler"); |
| 165 | compile_step.dependOn(&exe.step); | 170 | compile_step.dependOn(&exe.step); |
| ... | @@ -195,7 +200,7 @@ pub fn build(b: *Builder) !void { | ... | @@ -195,7 +200,7 @@ pub fn build(b: *Builder) !void { |
| 195 | test_cases.linkLibC(); | 200 | test_cases.linkLibC(); |
| 196 | } | 201 | } |
| 197 | 202 | ||
| 198 | const is_debug = mode == .Debug; | 203 | const is_debug = optimize == .Debug; |
| 199 | const enable_logging = b.option(bool, "log", "Enable debug logging with --debug-log") orelse is_debug; | 204 | const enable_logging = b.option(bool, "log", "Enable debug logging with --debug-log") orelse is_debug; |
| 200 | const enable_link_snapshots = b.option(bool, "link-snapshot", "Whether to enable linker state snapshots") orelse false; | 205 | const enable_link_snapshots = b.option(bool, "link-snapshot", "Whether to enable linker state snapshots") orelse false; |
| 201 | 206 | ||
| ... | @@ -360,25 +365,25 @@ pub fn build(b: *Builder) !void { | ... | @@ -360,25 +365,25 @@ pub fn build(b: *Builder) !void { |
| 360 | test_step.dependOn(test_cases_step); | 365 | test_step.dependOn(test_cases_step); |
| 361 | } | 366 | } |
| 362 | 367 | ||
| 363 | var chosen_modes: [4]builtin.Mode = undefined; | 368 | var chosen_opt_modes_buf: [4]builtin.Mode = undefined; |
| 364 | var chosen_mode_index: usize = 0; | 369 | var chosen_mode_index: usize = 0; |
| 365 | if (!skip_debug) { | 370 | if (!skip_debug) { |
| 366 | chosen_modes[chosen_mode_index] = builtin.Mode.Debug; | 371 | chosen_opt_modes_buf[chosen_mode_index] = builtin.Mode.Debug; |
| 367 | chosen_mode_index += 1; | 372 | chosen_mode_index += 1; |
| 368 | } | 373 | } |
| 369 | if (!skip_release_safe) { | 374 | if (!skip_release_safe) { |
| 370 | chosen_modes[chosen_mode_index] = builtin.Mode.ReleaseSafe; | 375 | chosen_opt_modes_buf[chosen_mode_index] = builtin.Mode.ReleaseSafe; |
| 371 | chosen_mode_index += 1; | 376 | chosen_mode_index += 1; |
| 372 | } | 377 | } |
| 373 | if (!skip_release_fast) { | 378 | if (!skip_release_fast) { |
| 374 | chosen_modes[chosen_mode_index] = builtin.Mode.ReleaseFast; | 379 | chosen_opt_modes_buf[chosen_mode_index] = builtin.Mode.ReleaseFast; |
| 375 | chosen_mode_index += 1; | 380 | chosen_mode_index += 1; |
| 376 | } | 381 | } |
| 377 | if (!skip_release_small) { | 382 | if (!skip_release_small) { |
| 378 | chosen_modes[chosen_mode_index] = builtin.Mode.ReleaseSmall; | 383 | chosen_opt_modes_buf[chosen_mode_index] = builtin.Mode.ReleaseSmall; |
| 379 | chosen_mode_index += 1; | 384 | chosen_mode_index += 1; |
| 380 | } | 385 | } |
| 381 | const modes = chosen_modes[0..chosen_mode_index]; | 386 | const optimization_modes = chosen_opt_modes_buf[0..chosen_mode_index]; |
| 382 | 387 | ||
| 383 | // run stage1 `zig fmt` on this build.zig file just to make sure it works | 388 | // run stage1 `zig fmt` on this build.zig file just to make sure it works |
| 384 | test_step.dependOn(&fmt_build_zig.step); | 389 | test_step.dependOn(&fmt_build_zig.step); |
| ... | @@ -391,7 +396,7 @@ pub fn build(b: *Builder) !void { | ... | @@ -391,7 +396,7 @@ pub fn build(b: *Builder) !void { |
| 391 | "test/behavior.zig", | 396 | "test/behavior.zig", |
| 392 | "behavior", | 397 | "behavior", |
| 393 | "Run the behavior tests", | 398 | "Run the behavior tests", |
| 394 | modes, | 399 | optimization_modes, |
| 395 | skip_single_threaded, | 400 | skip_single_threaded, |
| 396 | skip_non_native, | 401 | skip_non_native, |
| 397 | skip_libc, | 402 | skip_libc, |
| ... | @@ -405,7 +410,7 @@ pub fn build(b: *Builder) !void { | ... | @@ -405,7 +410,7 @@ pub fn build(b: *Builder) !void { |
| 405 | "lib/compiler_rt.zig", | 410 | "lib/compiler_rt.zig", |
| 406 | "compiler-rt", | 411 | "compiler-rt", |
| 407 | "Run the compiler_rt tests", | 412 | "Run the compiler_rt tests", |
| 408 | modes, | 413 | optimization_modes, |
| 409 | true, // skip_single_threaded | 414 | true, // skip_single_threaded |
| 410 | skip_non_native, | 415 | skip_non_native, |
| 411 | true, // skip_libc | 416 | true, // skip_libc |
| ... | @@ -419,7 +424,7 @@ pub fn build(b: *Builder) !void { | ... | @@ -419,7 +424,7 @@ pub fn build(b: *Builder) !void { |
| 419 | "lib/c.zig", | 424 | "lib/c.zig", |
| 420 | "universal-libc", | 425 | "universal-libc", |
| 421 | "Run the universal libc tests", | 426 | "Run the universal libc tests", |
| 422 | modes, | 427 | optimization_modes, |
| 423 | true, // skip_single_threaded | 428 | true, // skip_single_threaded |
| 424 | skip_non_native, | 429 | skip_non_native, |
| 425 | true, // skip_libc | 430 | true, // skip_libc |
| ... | @@ -427,11 +432,11 @@ pub fn build(b: *Builder) !void { | ... | @@ -427,11 +432,11 @@ pub fn build(b: *Builder) !void { |
| 427 | skip_stage2_tests or true, // TODO get these all passing | 432 | skip_stage2_tests or true, // TODO get these all passing |
| 428 | )); | 433 | )); |
| 429 | 434 | ||
| 430 | test_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes)); | 435 | test_step.dependOn(tests.addCompareOutputTests(b, test_filter, optimization_modes)); |
| 431 | test_step.dependOn(tests.addStandaloneTests( | 436 | test_step.dependOn(tests.addStandaloneTests( |
| 432 | b, | 437 | b, |
| 433 | test_filter, | 438 | test_filter, |
| 434 | modes, | 439 | optimization_modes, |
| 435 | skip_non_native, | 440 | skip_non_native, |
| 436 | enable_macos_sdk, | 441 | enable_macos_sdk, |
| 437 | target, | 442 | target, |
| ... | @@ -444,10 +449,10 @@ pub fn build(b: *Builder) !void { | ... | @@ -444,10 +449,10 @@ pub fn build(b: *Builder) !void { |
| 444 | enable_symlinks_windows, | 449 | enable_symlinks_windows, |
| 445 | )); | 450 | )); |
| 446 | test_step.dependOn(tests.addCAbiTests(b, skip_non_native, skip_release)); | 451 | test_step.dependOn(tests.addCAbiTests(b, skip_non_native, skip_release)); |
| 447 | test_step.dependOn(tests.addLinkTests(b, test_filter, modes, enable_macos_sdk, skip_stage2_tests, enable_symlinks_windows)); | 452 | test_step.dependOn(tests.addLinkTests(b, test_filter, optimization_modes, enable_macos_sdk, skip_stage2_tests, enable_symlinks_windows)); |
| 448 | test_step.dependOn(tests.addStackTraceTests(b, test_filter, modes)); | 453 | test_step.dependOn(tests.addStackTraceTests(b, test_filter, optimization_modes)); |
| 449 | test_step.dependOn(tests.addCliTests(b, test_filter, modes)); | 454 | test_step.dependOn(tests.addCliTests(b, test_filter, optimization_modes)); |
| 450 | test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter, modes)); | 455 | test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter, optimization_modes)); |
| 451 | test_step.dependOn(tests.addTranslateCTests(b, test_filter)); | 456 | test_step.dependOn(tests.addTranslateCTests(b, test_filter)); |
| 452 | if (!skip_run_translated_c) { | 457 | if (!skip_run_translated_c) { |
| 453 | test_step.dependOn(tests.addRunTranslatedCTests(b, test_filter, target)); | 458 | test_step.dependOn(tests.addRunTranslatedCTests(b, test_filter, target)); |
| ... | @@ -461,7 +466,7 @@ pub fn build(b: *Builder) !void { | ... | @@ -461,7 +466,7 @@ pub fn build(b: *Builder) !void { |
| 461 | "lib/std/std.zig", | 466 | "lib/std/std.zig", |
| 462 | "std", | 467 | "std", |
| 463 | "Run the standard library tests", | 468 | "Run the standard library tests", |
| 464 | modes, | 469 | optimization_modes, |
| 465 | skip_single_threaded, | 470 | skip_single_threaded, |
| 466 | skip_non_native, | 471 | skip_non_native, |
| 467 | skip_libc, | 472 | skip_libc, |
| ... | @@ -481,9 +486,7 @@ fn addWasiUpdateStep(b: *Builder, version: [:0]const u8) !void { | ... | @@ -481,9 +486,7 @@ fn addWasiUpdateStep(b: *Builder, version: [:0]const u8) !void { |
| 481 | }; | 486 | }; |
| 482 | target.cpu_features_add.addFeature(@enumToInt(std.Target.wasm.Feature.bulk_memory)); | 487 | target.cpu_features_add.addFeature(@enumToInt(std.Target.wasm.Feature.bulk_memory)); |
| 483 | 488 | ||
| 484 | const exe = addCompilerStep(b); | 489 | const exe = addCompilerStep(b, .ReleaseSmall, target); |
| 485 | exe.setBuildMode(.ReleaseSmall); | ||
| 486 | exe.setTarget(target); | ||
| 487 | 490 | ||
| 488 | const exe_options = b.addOptions(); | 491 | const exe_options = b.addOptions(); |
| 489 | exe.addOptions("build_options", exe_options); | 492 | exe.addOptions("build_options", exe_options); |
| ... | @@ -510,8 +513,17 @@ fn addWasiUpdateStep(b: *Builder, version: [:0]const u8) !void { | ... | @@ -510,8 +513,17 @@ fn addWasiUpdateStep(b: *Builder, version: [:0]const u8) !void { |
| 510 | update_zig1_step.dependOn(&run_opt.step); | 513 | update_zig1_step.dependOn(&run_opt.step); |
| 511 | } | 514 | } |
| 512 | 515 | ||
| 513 | fn addCompilerStep(b: *Builder) *std.build.LibExeObjStep { | 516 | fn addCompilerStep( |
| 514 | const exe = b.addExecutable("zig", "src/main.zig"); | 517 | b: *Builder, |
| 518 | optimize: std.builtin.OptimizeMode, | ||
| 519 | target: std.zig.CrossTarget, | ||
| 520 | ) *std.build.LibExeObjStep { | ||
| 521 | const exe = b.addExecutable(.{ | ||
| 522 | .name = "zig", | ||
| 523 | .root_source_file = .{ .path = "src/main.zig" }, | ||
| 524 | .target = target, | ||
| 525 | .optimize = optimize, | ||
| 526 | }); | ||
| 515 | exe.stack_size = stack_size; | 527 | exe.stack_size = stack_size; |
| 516 | return exe; | 528 | return exe; |
| 517 | } | 529 | } |
doc/langref.html.in+29-13| ... | @@ -9531,8 +9531,12 @@ fn foo(comptime T: type, ptr: *T) T { | ... | @@ -9531,8 +9531,12 @@ fn foo(comptime T: type, ptr: *T) T { |
| 9531 | const Builder = @import("std").build.Builder; | 9531 | const Builder = @import("std").build.Builder; |
| 9532 | 9532 | ||
| 9533 | pub fn build(b: *Builder) void { | 9533 | pub fn build(b: *Builder) void { |
| 9534 | const exe = b.addExecutable("example", "example.zig"); | 9534 | const optimize = b.standardOptimizeOption(.{}); |
| 9535 | exe.setBuildMode(b.standardReleaseOptions()); | 9535 | const exe = b.addExecutable(.{ |
| 9536 | .name = "example", | ||
| 9537 | .root_source_file = .{ .path = "example.zig" }, | ||
| 9538 | .optimize = optimize, | ||
| 9539 | }); | ||
| 9536 | b.default_step.dependOn(&exe.step); | 9540 | b.default_step.dependOn(&exe.step); |
| 9537 | } | 9541 | } |
| 9538 | {#code_end#} | 9542 | {#code_end#} |
| ... | @@ -10558,11 +10562,14 @@ pub fn build(b: *Builder) void { | ... | @@ -10558,11 +10562,14 @@ pub fn build(b: *Builder) void { |
| 10558 | 10562 | ||
| 10559 | // Standard release options allow the person running `zig build` to select | 10563 | // Standard release options allow the person running `zig build` to select |
| 10560 | // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. | 10564 | // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. |
| 10561 | const mode = b.standardReleaseOptions(); | 10565 | const optimize = b.standardOptimizeOption(.{}); |
| 10562 | 10566 | ||
| 10563 | const exe = b.addExecutable("example", "src/main.zig"); | 10567 | const exe = b.addExecutable(.{ |
| 10564 | exe.setTarget(target); | 10568 | .name = "example", |
| 10565 | exe.setBuildMode(mode); | 10569 | .root_source_file = .{ .path = "src/main.zig" }, |
| 10570 | .target = target, | ||
| 10571 | .optimize = optimize, | ||
| 10572 | }); | ||
| 10566 | exe.install(); | 10573 | exe.install(); |
| 10567 | 10574 | ||
| 10568 | const run_cmd = exe.run(); | 10575 | const run_cmd = exe.run(); |
| ... | @@ -10584,13 +10591,18 @@ pub fn build(b: *Builder) void { | ... | @@ -10584,13 +10591,18 @@ pub fn build(b: *Builder) void { |
| 10584 | const Builder = @import("std").build.Builder; | 10591 | const Builder = @import("std").build.Builder; |
| 10585 | 10592 | ||
| 10586 | pub fn build(b: *Builder) void { | 10593 | pub fn build(b: *Builder) void { |
| 10587 | const mode = b.standardReleaseOptions(); | 10594 | const optimize = b.standardOptimizeOption(.{}); |
| 10588 | const lib = b.addStaticLibrary("example", "src/main.zig"); | 10595 | const lib = b.addStaticLibrary(.{ |
| 10589 | lib.setBuildMode(mode); | 10596 | .name = "example", |
| 10597 | .root_source_file = .{ .path = "src/main.zig" }, | ||
| 10598 | .optimize = optimize, | ||
| 10599 | }); | ||
| 10590 | lib.install(); | 10600 | lib.install(); |
| 10591 | 10601 | ||
| 10592 | var main_tests = b.addTest("src/main.zig"); | 10602 | const main_tests = b.addTest(.{ |
| 10593 | main_tests.setBuildMode(mode); | 10603 | .root_source_file = .{ .path = "src/main.zig" }, |
| 10604 | .optimize = optimize, | ||
| 10605 | }); | ||
| 10594 | 10606 | ||
| 10595 | const test_step = b.step("test", "Run library tests"); | 10607 | const test_step = b.step("test", "Run library tests"); |
| 10596 | test_step.dependOn(&main_tests.step); | 10608 | test_step.dependOn(&main_tests.step); |
| ... | @@ -10954,7 +10966,9 @@ const Builder = @import("std").build.Builder; | ... | @@ -10954,7 +10966,9 @@ const Builder = @import("std").build.Builder; |
| 10954 | pub fn build(b: *Builder) void { | 10966 | pub fn build(b: *Builder) void { |
| 10955 | const lib = b.addSharedLibrary("mathtest", "mathtest.zig", b.version(1, 0, 0)); | 10967 | const lib = b.addSharedLibrary("mathtest", "mathtest.zig", b.version(1, 0, 0)); |
| 10956 | 10968 | ||
| 10957 | const exe = b.addExecutable("test", null); | 10969 | const exe = b.addExecutable(.{ |
| 10970 | .name = "test", | ||
| 10971 | }); | ||
| 10958 | exe.addCSourceFile("test.c", &[_][]const u8{"-std=c99"}); | 10972 | exe.addCSourceFile("test.c", &[_][]const u8{"-std=c99"}); |
| 10959 | exe.linkLibrary(lib); | 10973 | exe.linkLibrary(lib); |
| 10960 | exe.linkSystemLibrary("c"); | 10974 | exe.linkSystemLibrary("c"); |
| ... | @@ -11016,7 +11030,9 @@ const Builder = @import("std").build.Builder; | ... | @@ -11016,7 +11030,9 @@ const Builder = @import("std").build.Builder; |
| 11016 | pub fn build(b: *Builder) void { | 11030 | pub fn build(b: *Builder) void { |
| 11017 | const obj = b.addObject("base64", "base64.zig"); | 11031 | const obj = b.addObject("base64", "base64.zig"); |
| 11018 | 11032 | ||
| 11019 | const exe = b.addExecutable("test", null); | 11033 | const exe = b.addExecutable(.{ |
| 11034 | .name = "test", | ||
| 11035 | }); | ||
| 11020 | exe.addCSourceFile("test.c", &[_][]const u8{"-std=c99"}); | 11036 | exe.addCSourceFile("test.c", &[_][]const u8{"-std=c99"}); |
| 11021 | exe.addObject(obj); | 11037 | exe.addObject(obj); |
| 11022 | exe.linkSystemLibrary("c"); | 11038 | exe.linkSystemLibrary("c"); |
lib/init-exe/build.zig+42-9| ... | @@ -1,5 +1,8 @@ | ... | @@ -1,5 +1,8 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | 2 | ||
| 3 | // Although this function looks imperative, note that its job is to | ||
| 4 | // declaratively construct a build graph that will be executed by an external | ||
| 5 | // runner. | ||
| 3 | pub fn build(b: *std.build.Builder) void { | 6 | pub fn build(b: *std.build.Builder) void { |
| 4 | // Standard target options allows the person running `zig build` to choose | 7 | // Standard target options allows the person running `zig build` to choose |
| 5 | // what target to build for. Here we do not override the defaults, which | 8 | // what target to build for. Here we do not override the defaults, which |
| ... | @@ -7,28 +10,58 @@ pub fn build(b: *std.build.Builder) void { | ... | @@ -7,28 +10,58 @@ pub fn build(b: *std.build.Builder) void { |
| 7 | // for restricting supported target set are available. | 10 | // for restricting supported target set are available. |
| 8 | const target = b.standardTargetOptions(.{}); | 11 | const target = b.standardTargetOptions(.{}); |
| 9 | 12 | ||
| 10 | // Standard release options allow the person running `zig build` to select | 13 | // Standard optimization options allow the person running `zig build` to select |
| 11 | // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. | 14 | // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not |
| 12 | const mode = b.standardReleaseOptions(); | 15 | // set a preferred release mode, allowing the user to decide how to optimize. |
| 16 | const optimize = b.standardOptimizeOption(); | ||
| 13 | 17 | ||
| 14 | const exe = b.addExecutable("$", "src/main.zig"); | 18 | const exe = b.addExecutable(.{ |
| 15 | exe.setTarget(target); | 19 | .name = "$", |
| 16 | exe.setBuildMode(mode); | 20 | // In this case the main source file is merely a path, however, in more |
| 21 | // complicated build scripts, this could be a generated file. | ||
| 22 | .root_source_file = .{ .path = "src/main.zig" }, | ||
| 23 | .target = target, | ||
| 24 | .optimize = optimize, | ||
| 25 | }); | ||
| 26 | |||
| 27 | // This declares intent for the executable to be installed into the | ||
| 28 | // standard location when the user invokes the "install" step (the default | ||
| 29 | // step when running `zig build`). | ||
| 17 | exe.install(); | 30 | exe.install(); |
| 18 | 31 | ||
| 32 | // This *creates* a RunStep in the build graph, to be executed when another | ||
| 33 | // step is evaluated that depends on it. The next line below will establish | ||
| 34 | // such a dependency. | ||
| 19 | const run_cmd = exe.run(); | 35 | const run_cmd = exe.run(); |
| 36 | |||
| 37 | // By making the run step depend on the install step, it will be run from the | ||
| 38 | // installation directory rather than directly from within the cache directory. | ||
| 39 | // This is not necessary, however, if the application depends on other installed | ||
| 40 | // files, this ensures they will be present and in the expected location. | ||
| 20 | run_cmd.step.dependOn(b.getInstallStep()); | 41 | run_cmd.step.dependOn(b.getInstallStep()); |
| 42 | |||
| 43 | // This allows the user to pass arguments to the application in the build | ||
| 44 | // command itself, like this: `zig build run -- arg1 arg2 etc` | ||
| 21 | if (b.args) |args| { | 45 | if (b.args) |args| { |
| 22 | run_cmd.addArgs(args); | 46 | run_cmd.addArgs(args); |
| 23 | } | 47 | } |
| 24 | 48 | ||
| 49 | // This creates a build step. It will be visible in the `zig build --help` menu, | ||
| 50 | // and can be selected like this: `zig build run` | ||
| 51 | // This will evaluate the `run` step rather than the default, which is "install". | ||
| 25 | const run_step = b.step("run", "Run the app"); | 52 | const run_step = b.step("run", "Run the app"); |
| 26 | run_step.dependOn(&run_cmd.step); | 53 | run_step.dependOn(&run_cmd.step); |
| 27 | 54 | ||
| 28 | const exe_tests = b.addTest("src/main.zig"); | 55 | // Creates a step for unit testing. |
| 29 | exe_tests.setTarget(target); | 56 | const exe_tests = b.addTest(.{ |
| 30 | exe_tests.setBuildMode(mode); | 57 | .root_source_file = .{ .path = "src/main.zig" }, |
| 58 | .target = target, | ||
| 59 | .optimize = optimize, | ||
| 60 | }); | ||
| 31 | 61 | ||
| 62 | // Similar to creating the run step earlier, this exposes a `test` step to | ||
| 63 | // the `zig build --help` menu, providing a way for the user to request | ||
| 64 | // running the unit tests. | ||
| 32 | const test_step = b.step("test", "Run unit tests"); | 65 | const test_step = b.step("test", "Run unit tests"); |
| 33 | test_step.dependOn(&exe_tests.step); | 66 | test_step.dependOn(&exe_tests.step); |
| 34 | } | 67 | } |
lib/init-lib/build.zig+34-7| ... | @@ -1,17 +1,44 @@ | ... | @@ -1,17 +1,44 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | 2 | ||
| 3 | // Although this function looks imperative, note that its job is to | ||
| 4 | // declaratively construct a build graph that will be executed by an external | ||
| 5 | // runner. | ||
| 3 | pub fn build(b: *std.build.Builder) void { | 6 | pub fn build(b: *std.build.Builder) void { |
| 4 | // Standard release options allow the person running `zig build` to select | 7 | // Standard target options allows the person running `zig build` to choose |
| 5 | // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. | 8 | // what target to build for. Here we do not override the defaults, which |
| 6 | const mode = b.standardReleaseOptions(); | 9 | // means any target is allowed, and the default is native. Other options |
| 10 | // for restricting supported target set are available. | ||
| 11 | const target = b.standardTargetOptions(.{}); | ||
| 7 | 12 | ||
| 8 | const lib = b.addStaticLibrary("$", "src/main.zig"); | 13 | // Standard optimization options allow the person running `zig build` to select |
| 9 | lib.setBuildMode(mode); | 14 | // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not |
| 15 | // set a preferred release mode, allowing the user to decide how to optimize. | ||
| 16 | const optimize = b.standardOptimizeOption(); | ||
| 17 | |||
| 18 | const lib = b.addStaticLibrary(.{ | ||
| 19 | .name = "$", | ||
| 20 | // In this case the main source file is merely a path, however, in more | ||
| 21 | // complicated build scripts, this could be a generated file. | ||
| 22 | .root_source_file = .{ .path = "src/main.zig" }, | ||
| 23 | .target = target, | ||
| 24 | .optimize = optimize, | ||
| 25 | }); | ||
| 26 | |||
| 27 | // This declares intent for the library to be installed into the standard | ||
| 28 | // location when the user invokes the "install" step (the default step when | ||
| 29 | // running `zig build`). | ||
| 10 | lib.install(); | 30 | lib.install(); |
| 11 | 31 | ||
| 12 | const main_tests = b.addTest("src/main.zig"); | 32 | // Creates a step for unit testing. |
| 13 | main_tests.setBuildMode(mode); | 33 | const main_tests = b.addTest(.{ |
| 34 | .root_source_file = .{ .path = "src/main.zig" }, | ||
| 35 | .target = target, | ||
| 36 | .optimize = optimize, | ||
| 37 | }); | ||
| 14 | 38 | ||
| 39 | // This creates a build step. It will be visible in the `zig build --help` menu, | ||
| 40 | // and can be selected like this: `zig build test` | ||
| 41 | // This will evaluate the `test` step rather than the default, which is "install". | ||
| 15 | const test_step = b.step("test", "Run library tests"); | 42 | const test_step = b.step("test", "Run library tests"); |
| 16 | test_step.dependOn(&main_tests.step); | 43 | test_step.dependOn(&main_tests.step); |
| 17 | } | 44 | } |
lib/std/build.zig+9-10| ... | @@ -420,10 +420,10 @@ pub const Builder = struct { | ... | @@ -420,10 +420,10 @@ pub const Builder = struct { |
| 420 | 420 | ||
| 421 | pub const ExecutableOptions = struct { | 421 | pub const ExecutableOptions = struct { |
| 422 | name: []const u8, | 422 | name: []const u8, |
| 423 | root_source_file: ?FileSource, | 423 | root_source_file: ?FileSource = null, |
| 424 | version: ?std.builtin.Version = null, | 424 | version: ?std.builtin.Version = null, |
| 425 | target: CrossTarget, | 425 | target: CrossTarget = .{}, |
| 426 | optimize: std.builtin.Mode, | 426 | optimize: std.builtin.Mode = .Debug, |
| 427 | linkage: ?LibExeObjStep.Linkage = null, | 427 | linkage: ?LibExeObjStep.Linkage = null, |
| 428 | }; | 428 | }; |
| 429 | 429 | ||
| ... | @@ -436,13 +436,12 @@ pub const Builder = struct { | ... | @@ -436,13 +436,12 @@ pub const Builder = struct { |
| 436 | .optimize = options.optimize, | 436 | .optimize = options.optimize, |
| 437 | .kind = .exe, | 437 | .kind = .exe, |
| 438 | .linkage = options.linkage, | 438 | .linkage = options.linkage, |
| 439 | .version = options.version, | ||
| 440 | }); | 439 | }); |
| 441 | } | 440 | } |
| 442 | 441 | ||
| 443 | pub const ObjectOptions = struct { | 442 | pub const ObjectOptions = struct { |
| 444 | name: []const u8, | 443 | name: []const u8, |
| 445 | root_source_file: ?FileSource, | 444 | root_source_file: ?FileSource = null, |
| 446 | target: CrossTarget, | 445 | target: CrossTarget, |
| 447 | optimize: std.builtin.Mode, | 446 | optimize: std.builtin.Mode, |
| 448 | }; | 447 | }; |
| ... | @@ -459,7 +458,7 @@ pub const Builder = struct { | ... | @@ -459,7 +458,7 @@ pub const Builder = struct { |
| 459 | 458 | ||
| 460 | pub const SharedLibraryOptions = struct { | 459 | pub const SharedLibraryOptions = struct { |
| 461 | name: []const u8, | 460 | name: []const u8, |
| 462 | root_source_file: ?FileSource, | 461 | root_source_file: ?FileSource = null, |
| 463 | version: ?std.builtin.Version = null, | 462 | version: ?std.builtin.Version = null, |
| 464 | target: CrossTarget, | 463 | target: CrossTarget, |
| 465 | optimize: std.builtin.Mode, | 464 | optimize: std.builtin.Mode, |
| ... | @@ -501,8 +500,8 @@ pub const Builder = struct { | ... | @@ -501,8 +500,8 @@ pub const Builder = struct { |
| 501 | name: []const u8 = "test", | 500 | name: []const u8 = "test", |
| 502 | kind: LibExeObjStep.Kind = .@"test", | 501 | kind: LibExeObjStep.Kind = .@"test", |
| 503 | root_source_file: FileSource, | 502 | root_source_file: FileSource, |
| 504 | target: CrossTarget, | 503 | target: CrossTarget = .{}, |
| 505 | optimize: std.builtin.Mode, | 504 | optimize: std.builtin.Mode = .Debug, |
| 506 | version: ?std.builtin.Version = null, | 505 | version: ?std.builtin.Version = null, |
| 507 | }; | 506 | }; |
| 508 | 507 | ||
| ... | @@ -630,8 +629,8 @@ pub const Builder = struct { | ... | @@ -630,8 +629,8 @@ pub const Builder = struct { |
| 630 | return FmtStep.create(self, paths); | 629 | return FmtStep.create(self, paths); |
| 631 | } | 630 | } |
| 632 | 631 | ||
| 633 | pub fn addTranslateC(self: *Builder, source: FileSource) *TranslateCStep { | 632 | pub fn addTranslateC(self: *Builder, options: TranslateCStep.Options) *TranslateCStep { |
| 634 | return TranslateCStep.create(self, source.dupe(self)); | 633 | return TranslateCStep.create(self, options); |
| 635 | } | 634 | } |
| 636 | 635 | ||
| 637 | pub fn make(self: *Builder, step_names: []const []const u8) !void { | 636 | pub fn make(self: *Builder, step_names: []const []const u8) !void { |
lib/std/build/TranslateCStep.zig+33-7| ... | @@ -19,11 +19,19 @@ include_dirs: std.ArrayList([]const u8), | ... | @@ -19,11 +19,19 @@ include_dirs: std.ArrayList([]const u8), |
| 19 | c_macros: std.ArrayList([]const u8), | 19 | c_macros: std.ArrayList([]const u8), |
| 20 | output_dir: ?[]const u8, | 20 | output_dir: ?[]const u8, |
| 21 | out_basename: []const u8, | 21 | out_basename: []const u8, |
| 22 | target: CrossTarget = CrossTarget{}, | 22 | target: CrossTarget, |
| 23 | optimize: std.builtin.OptimizeMode, | ||
| 23 | output_file: build.GeneratedFile, | 24 | output_file: build.GeneratedFile, |
| 24 | 25 | ||
| 25 | pub fn create(builder: *Builder, source: build.FileSource) *TranslateCStep { | 26 | pub const Options = struct { |
| 27 | source_file: build.FileSource, | ||
| 28 | target: CrossTarget, | ||
| 29 | optimize: std.builtin.OptimizeMode, | ||
| 30 | }; | ||
| 31 | |||
| 32 | pub fn create(builder: *Builder, options: Options) *TranslateCStep { | ||
| 26 | const self = builder.allocator.create(TranslateCStep) catch unreachable; | 33 | const self = builder.allocator.create(TranslateCStep) catch unreachable; |
| 34 | const source = options.source_file.dupe(builder); | ||
| 27 | self.* = TranslateCStep{ | 35 | self.* = TranslateCStep{ |
| 28 | .step = Step.init(.translate_c, "translate-c", builder.allocator, make), | 36 | .step = Step.init(.translate_c, "translate-c", builder.allocator, make), |
| 29 | .builder = builder, | 37 | .builder = builder, |
| ... | @@ -32,19 +40,32 @@ pub fn create(builder: *Builder, source: build.FileSource) *TranslateCStep { | ... | @@ -32,19 +40,32 @@ pub fn create(builder: *Builder, source: build.FileSource) *TranslateCStep { |
| 32 | .c_macros = std.ArrayList([]const u8).init(builder.allocator), | 40 | .c_macros = std.ArrayList([]const u8).init(builder.allocator), |
| 33 | .output_dir = null, | 41 | .output_dir = null, |
| 34 | .out_basename = undefined, | 42 | .out_basename = undefined, |
| 43 | .target = options.target, | ||
| 44 | .optimize = options.optimize, | ||
| 35 | .output_file = build.GeneratedFile{ .step = &self.step }, | 45 | .output_file = build.GeneratedFile{ .step = &self.step }, |
| 36 | }; | 46 | }; |
| 37 | source.addStepDependencies(&self.step); | 47 | source.addStepDependencies(&self.step); |
| 38 | return self; | 48 | return self; |
| 39 | } | 49 | } |
| 40 | 50 | ||
| 41 | pub fn setTarget(self: *TranslateCStep, target: CrossTarget) void { | 51 | pub const AddExecutableOptions = struct { |
| 42 | self.target = target; | 52 | name: ?[]const u8 = null, |
| 43 | } | 53 | version: ?std.builtin.Version = null, |
| 54 | target: ?CrossTarget = null, | ||
| 55 | optimize: ?std.builtin.Mode = null, | ||
| 56 | linkage: ?LibExeObjStep.Linkage = null, | ||
| 57 | }; | ||
| 44 | 58 | ||
| 45 | /// Creates a step to build an executable from the translated source. | 59 | /// Creates a step to build an executable from the translated source. |
| 46 | pub fn addExecutable(self: *TranslateCStep) *LibExeObjStep { | 60 | pub fn addExecutable(self: *TranslateCStep, options: AddExecutableOptions) *LibExeObjStep { |
| 47 | return self.builder.addExecutableSource("translated_c", build.FileSource{ .generated = &self.output_file }); | 61 | return self.builder.addExecutable(.{ |
| 62 | .root_source_file = .{ .generated = &self.output_file }, | ||
| 63 | .name = options.name orelse "translated_c", | ||
| 64 | .version = options.version, | ||
| 65 | .target = options.target orelse self.target, | ||
| 66 | .optimize = options.optimize orelse self.optimize, | ||
| 67 | .linkage = options.linkage, | ||
| 68 | }); | ||
| 48 | } | 69 | } |
| 49 | 70 | ||
| 50 | pub fn addIncludeDir(self: *TranslateCStep, include_dir: []const u8) void { | 71 | pub fn addIncludeDir(self: *TranslateCStep, include_dir: []const u8) void { |
| ... | @@ -82,6 +103,11 @@ fn make(step: *Step) !void { | ... | @@ -82,6 +103,11 @@ fn make(step: *Step) !void { |
| 82 | try argv_list.append(try self.target.zigTriple(self.builder.allocator)); | 103 | try argv_list.append(try self.target.zigTriple(self.builder.allocator)); |
| 83 | } | 104 | } |
| 84 | 105 | ||
| 106 | switch (self.optimize) { | ||
| 107 | .Debug => {}, // Skip since it's the default. | ||
| 108 | else => try argv_list.append(self.builder.fmt("-O{s}", .{@tagName(self.optimize)})), | ||
| 109 | } | ||
| 110 | |||
| 85 | for (self.include_dirs.items) |include_dir| { | 111 | for (self.include_dirs.items) |include_dir| { |
| 86 | try argv_list.append("-I"); | 112 | try argv_list.append("-I"); |
| 87 | try argv_list.append(include_dir); | 113 | try argv_list.append(include_dir); |
lib/std/builtin.zig+4-1| ... | @@ -131,13 +131,16 @@ pub const CodeModel = enum { | ... | @@ -131,13 +131,16 @@ pub const CodeModel = enum { |
| 131 | 131 | ||
| 132 | /// This data structure is used by the Zig language code generation and | 132 | /// This data structure is used by the Zig language code generation and |
| 133 | /// therefore must be kept in sync with the compiler implementation. | 133 | /// therefore must be kept in sync with the compiler implementation. |
| 134 | pub const Mode = enum { | 134 | pub const OptimizeMode = enum { |
| 135 | Debug, | 135 | Debug, |
| 136 | ReleaseSafe, | 136 | ReleaseSafe, |
| 137 | ReleaseFast, | 137 | ReleaseFast, |
| 138 | ReleaseSmall, | 138 | ReleaseSmall, |
| 139 | }; | 139 | }; |
| 140 | 140 | ||
| 141 | /// Deprecated; use OptimizeMode. | ||
| 142 | pub const Mode = OptimizeMode; | ||
| 143 | |||
| 141 | /// This data structure is used by the Zig language code generation and | 144 | /// This data structure is used by the Zig language code generation and |
| 142 | /// therefore must be kept in sync with the compiler implementation. | 145 | /// therefore must be kept in sync with the compiler implementation. |
| 143 | pub const CallingConvention = enum { | 146 | pub const CallingConvention = enum { |
src/link/MachO/zld.zig+7-4| ... | @@ -3596,7 +3596,8 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr | ... | @@ -3596,7 +3596,8 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr |
| 3596 | man.hash.addOptionalBytes(options.sysroot); | 3596 | man.hash.addOptionalBytes(options.sysroot); |
| 3597 | try man.addOptionalFile(options.entitlements); | 3597 | try man.addOptionalFile(options.entitlements); |
| 3598 | 3598 | ||
| 3599 | // We don't actually care whether it's a cache hit or miss; we just need the digest and the lock. | 3599 | // We don't actually care whether it's a cache hit or miss; we just |
| 3600 | // need the digest and the lock. | ||
| 3600 | _ = try man.hit(); | 3601 | _ = try man.hit(); |
| 3601 | digest = man.final(); | 3602 | digest = man.final(); |
| 3602 | 3603 | ||
| ... | @@ -4177,9 +4178,11 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr | ... | @@ -4177,9 +4178,11 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr |
| 4177 | log.debug("failed to save linking hash digest file: {s}", .{@errorName(err)}); | 4178 | log.debug("failed to save linking hash digest file: {s}", .{@errorName(err)}); |
| 4178 | }; | 4179 | }; |
| 4179 | // Again failure here only means an unnecessary cache miss. | 4180 | // Again failure here only means an unnecessary cache miss. |
| 4180 | man.writeManifest() catch |err| { | 4181 | if (man.have_exclusive_lock) { |
| 4181 | log.debug("failed to write cache manifest when linking: {s}", .{@errorName(err)}); | 4182 | man.writeManifest() catch |err| { |
| 4182 | }; | 4183 | log.debug("failed to write cache manifest when linking: {s}", .{@errorName(err)}); |
| 4184 | }; | ||
| 4185 | } | ||
| 4183 | // We hang on to this lock so that the output file path can be used without | 4186 | // We hang on to this lock so that the output file path can be used without |
| 4184 | // other processes clobbering it. | 4187 | // other processes clobbering it. |
| 4185 | macho_file.base.lock = man.toOwnedLock(); | 4188 | macho_file.base.lock = man.toOwnedLock(); |
test/link/bss/build.zig+6-3| ... | @@ -1,12 +1,15 @@ | ... | @@ -1,12 +1,15 @@ |
| 1 | const Builder = @import("std").build.Builder; | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | ||
| 3 | pub fn build(b: *Builder) void { | 3 | pub fn build(b: *Builder) void { |
| 4 | const mode = b.standardReleaseOptions(); | 4 | const optimize = b.standardOptimizeOption(.{}); |
| 5 | const test_step = b.step("test", "Test"); | 5 | const test_step = b.step("test", "Test"); |
| 6 | 6 | ||
| 7 | const exe = b.addExecutable("bss", "main.zig"); | 7 | const exe = b.addExecutable(.{ |
| 8 | .name = "bss", | ||
| 9 | .root_source_file = .{ .path = "main.zig" }, | ||
| 10 | .optimize = optimize, | ||
| 11 | }); | ||
| 8 | b.default_step.dependOn(&exe.step); | 12 | b.default_step.dependOn(&exe.step); |
| 9 | exe.setBuildMode(mode); | ||
| 10 | 13 | ||
| 11 | const run = exe.run(); | 14 | const run = exe.run(); |
| 12 | run.expectStdOutEqual("0, 1, 0\n"); | 15 | run.expectStdOutEqual("0, 1, 0\n"); |
test/link/common_symbols/build.zig+10-5| ... | @@ -1,14 +1,19 @@ | ... | @@ -1,14 +1,19 @@ |
| 1 | const Builder = @import("std").build.Builder; | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | ||
| 3 | pub fn build(b: *Builder) void { | 3 | pub fn build(b: *Builder) void { |
| 4 | const mode = b.standardReleaseOptions(); | 4 | const optimize = b.standardOptimizeOption(.{}); |
| 5 | 5 | ||
| 6 | const lib_a = b.addStaticLibrary("a", null); | 6 | const lib_a = b.addStaticLibrary(.{ |
| 7 | .name = "a", | ||
| 8 | .optimize = optimize, | ||
| 9 | .target = .{}, | ||
| 10 | }); | ||
| 7 | lib_a.addCSourceFiles(&.{ "c.c", "a.c", "b.c" }, &.{"-fcommon"}); | 11 | lib_a.addCSourceFiles(&.{ "c.c", "a.c", "b.c" }, &.{"-fcommon"}); |
| 8 | lib_a.setBuildMode(mode); | ||
| 9 | 12 | ||
| 10 | const test_exe = b.addTest("main.zig"); | 13 | const test_exe = b.addTest(.{ |
| 11 | test_exe.setBuildMode(mode); | 14 | .root_source_file = .{ .path = "main.zig" }, |
| 15 | .optimize = optimize, | ||
| 16 | }); | ||
| 12 | test_exe.linkLibrary(lib_a); | 17 | test_exe.linkLibrary(lib_a); |
| 13 | 18 | ||
| 14 | const test_step = b.step("test", "Test it"); | 19 | const test_step = b.step("test", "Test it"); |
test/link/common_symbols_alignment/build.zig+12-5| ... | @@ -1,14 +1,21 @@ | ... | @@ -1,14 +1,21 @@ |
| 1 | const Builder = @import("std").build.Builder; | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | ||
| 3 | pub fn build(b: *Builder) void { | 3 | pub fn build(b: *Builder) void { |
| 4 | const mode = b.standardReleaseOptions(); | 4 | const optimize = b.standardOptimizeOption(.{}); |
| 5 | const target = b.standardTargetOptions(.{}); | ||
| 5 | 6 | ||
| 6 | const lib_a = b.addStaticLibrary("a", null); | 7 | const lib_a = b.addStaticLibrary(.{ |
| 8 | .name = "a", | ||
| 9 | .optimize = optimize, | ||
| 10 | .target = target, | ||
| 11 | }); | ||
| 7 | lib_a.addCSourceFiles(&.{"a.c"}, &.{"-fcommon"}); | 12 | lib_a.addCSourceFiles(&.{"a.c"}, &.{"-fcommon"}); |
| 8 | lib_a.setBuildMode(mode); | ||
| 9 | 13 | ||
| 10 | const test_exe = b.addTest("main.zig"); | 14 | const test_exe = b.addTest(.{ |
| 11 | test_exe.setBuildMode(mode); | 15 | .root_source_file = .{ .path = "main.zig" }, |
| 16 | .optimize = optimize, | ||
| 17 | .target = target, | ||
| 18 | }); | ||
| 12 | test_exe.linkLibrary(lib_a); | 19 | test_exe.linkLibrary(lib_a); |
| 13 | 20 | ||
| 14 | const test_step = b.step("test", "Test it"); | 21 | const test_step = b.step("test", "Test it"); |
test/link/interdependent_static_c_libs/build.zig+17-7| ... | @@ -1,20 +1,30 @@ | ... | @@ -1,20 +1,30 @@ |
| 1 | const Builder = @import("std").build.Builder; | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | ||
| 3 | pub fn build(b: *Builder) void { | 3 | pub fn build(b: *Builder) void { |
| 4 | const mode = b.standardReleaseOptions(); | 4 | const optimize = b.standardOptimizeOption(.{}); |
| 5 | const target = b.standardTargetOptions(.{}); | ||
| 5 | 6 | ||
| 6 | const lib_a = b.addStaticLibrary("a", null); | 7 | const lib_a = b.addStaticLibrary(.{ |
| 8 | .name = "a", | ||
| 9 | .optimize = optimize, | ||
| 10 | .target = target, | ||
| 11 | }); | ||
| 7 | lib_a.addCSourceFile("a.c", &[_][]const u8{}); | 12 | lib_a.addCSourceFile("a.c", &[_][]const u8{}); |
| 8 | lib_a.setBuildMode(mode); | ||
| 9 | lib_a.addIncludePath("."); | 13 | lib_a.addIncludePath("."); |
| 10 | 14 | ||
| 11 | const lib_b = b.addStaticLibrary("b", null); | 15 | const lib_b = b.addStaticLibrary(.{ |
| 16 | .name = "b", | ||
| 17 | .optimize = optimize, | ||
| 18 | .target = target, | ||
| 19 | }); | ||
| 12 | lib_b.addCSourceFile("b.c", &[_][]const u8{}); | 20 | lib_b.addCSourceFile("b.c", &[_][]const u8{}); |
| 13 | lib_b.setBuildMode(mode); | ||
| 14 | lib_b.addIncludePath("."); | 21 | lib_b.addIncludePath("."); |
| 15 | 22 | ||
| 16 | const test_exe = b.addTest("main.zig"); | 23 | const test_exe = b.addTest(.{ |
| 17 | test_exe.setBuildMode(mode); | 24 | .root_source_file = .{ .path = "main.zig" }, |
| 25 | .optimize = optimize, | ||
| 26 | .target = target, | ||
| 27 | }); | ||
| 18 | test_exe.linkLibrary(lib_a); | 28 | test_exe.linkLibrary(lib_a); |
| 19 | test_exe.linkLibrary(lib_b); | 29 | test_exe.linkLibrary(lib_b); |
| 20 | test_exe.addIncludePath("."); | 30 | test_exe.addIncludePath("."); |
test/link/macho/bugs/13056/build.zig+5-3| ... | @@ -2,7 +2,7 @@ const std = @import("std"); | ... | @@ -2,7 +2,7 @@ const std = @import("std"); |
| 2 | const Builder = std.build.Builder; | 2 | const Builder = std.build.Builder; |
| 3 | 3 | ||
| 4 | pub fn build(b: *Builder) void { | 4 | pub fn build(b: *Builder) void { |
| 5 | const mode = b.standardReleaseOptions(); | 5 | const optimize = b.standardOptimizeOption(.{}); |
| 6 | 6 | ||
| 7 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 7 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; |
| 8 | const target_info = std.zig.system.NativeTargetInfo.detect(target) catch unreachable; | 8 | const target_info = std.zig.system.NativeTargetInfo.detect(target) catch unreachable; |
| ... | @@ -11,7 +11,10 @@ pub fn build(b: *Builder) void { | ... | @@ -11,7 +11,10 @@ pub fn build(b: *Builder) void { |
| 11 | 11 | ||
| 12 | const test_step = b.step("test", "Test the program"); | 12 | const test_step = b.step("test", "Test the program"); |
| 13 | 13 | ||
| 14 | const exe = b.addExecutable("test", null); | 14 | const exe = b.addExecutable(.{ |
| 15 | .name = "test", | ||
| 16 | .optimize = optimize, | ||
| 17 | }); | ||
| 15 | b.default_step.dependOn(&exe.step); | 18 | b.default_step.dependOn(&exe.step); |
| 16 | exe.addIncludePath(std.fs.path.join(b.allocator, &.{ sdk.path, "/usr/include" }) catch unreachable); | 19 | exe.addIncludePath(std.fs.path.join(b.allocator, &.{ sdk.path, "/usr/include" }) catch unreachable); |
| 17 | exe.addIncludePath(std.fs.path.join(b.allocator, &.{ sdk.path, "/usr/include/c++/v1" }) catch unreachable); | 20 | exe.addIncludePath(std.fs.path.join(b.allocator, &.{ sdk.path, "/usr/include/c++/v1" }) catch unreachable); |
| ... | @@ -20,7 +23,6 @@ pub fn build(b: *Builder) void { | ... | @@ -20,7 +23,6 @@ pub fn build(b: *Builder) void { |
| 20 | "-nostdinc++", | 23 | "-nostdinc++", |
| 21 | }); | 24 | }); |
| 22 | exe.addObjectFile(std.fs.path.join(b.allocator, &.{ sdk.path, "/usr/lib/libc++.tbd" }) catch unreachable); | 25 | exe.addObjectFile(std.fs.path.join(b.allocator, &.{ sdk.path, "/usr/lib/libc++.tbd" }) catch unreachable); |
| 23 | exe.setBuildMode(mode); | ||
| 24 | 26 | ||
| 25 | const run_cmd = exe.run(); | 27 | const run_cmd = exe.run(); |
| 26 | run_cmd.expectStdErrEqual("x: 5\n"); | 28 | run_cmd.expectStdErrEqual("x: 5\n"); |
test/link/macho/bugs/13457/build.zig+7-4| ... | @@ -3,14 +3,17 @@ const Builder = std.build.Builder; | ... | @@ -3,14 +3,17 @@ const Builder = std.build.Builder; |
| 3 | const LibExeObjectStep = std.build.LibExeObjStep; | 3 | const LibExeObjectStep = std.build.LibExeObjStep; |
| 4 | 4 | ||
| 5 | pub fn build(b: *Builder) void { | 5 | pub fn build(b: *Builder) void { |
| 6 | const mode = b.standardReleaseOptions(); | 6 | const optimize = b.standardOptimizeOption(.{}); |
| 7 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 7 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; |
| 8 | 8 | ||
| 9 | const test_step = b.step("test", "Test the program"); | 9 | const test_step = b.step("test", "Test the program"); |
| 10 | 10 | ||
| 11 | const exe = b.addExecutable("test", "main.zig"); | 11 | const exe = b.addExecutable(.{ |
| 12 | exe.setBuildMode(mode); | 12 | .name = "test", |
| 13 | exe.setTarget(target); | 13 | .root_source_file = .{ .path = "main.zig" }, |
| 14 | .optimize = optimize, | ||
| 15 | .target = target, | ||
| 16 | }); | ||
| 14 | 17 | ||
| 15 | const run = exe.runEmulatable(); | 18 | const run = exe.runEmulatable(); |
| 16 | test_step.dependOn(&run.step); | 19 | test_step.dependOn(&run.step); |
test/link/macho/dead_strip/build.zig+9-7| ... | @@ -3,7 +3,7 @@ const Builder = std.build.Builder; | ... | @@ -3,7 +3,7 @@ const Builder = std.build.Builder; |
| 3 | const LibExeObjectStep = std.build.LibExeObjStep; | 3 | const LibExeObjectStep = std.build.LibExeObjStep; |
| 4 | 4 | ||
| 5 | pub fn build(b: *Builder) void { | 5 | pub fn build(b: *Builder) void { |
| 6 | const mode = b.standardReleaseOptions(); | 6 | const optimize = b.standardOptimizeOption(.{}); |
| 7 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 7 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; |
| 8 | 8 | ||
| 9 | const test_step = b.step("test", "Test the program"); | 9 | const test_step = b.step("test", "Test the program"); |
| ... | @@ -11,7 +11,7 @@ pub fn build(b: *Builder) void { | ... | @@ -11,7 +11,7 @@ pub fn build(b: *Builder) void { |
| 11 | 11 | ||
| 12 | { | 12 | { |
| 13 | // Without -dead_strip, we expect `iAmUnused` symbol present | 13 | // Without -dead_strip, we expect `iAmUnused` symbol present |
| 14 | const exe = createScenario(b, mode, target); | 14 | const exe = createScenario(b, optimize, target); |
| 15 | 15 | ||
| 16 | const check = exe.checkObject(.macho); | 16 | const check = exe.checkObject(.macho); |
| 17 | check.checkInSymtab(); | 17 | check.checkInSymtab(); |
| ... | @@ -24,7 +24,7 @@ pub fn build(b: *Builder) void { | ... | @@ -24,7 +24,7 @@ pub fn build(b: *Builder) void { |
| 24 | 24 | ||
| 25 | { | 25 | { |
| 26 | // With -dead_strip, no `iAmUnused` symbol should be present | 26 | // With -dead_strip, no `iAmUnused` symbol should be present |
| 27 | const exe = createScenario(b, mode, target); | 27 | const exe = createScenario(b, optimize, target); |
| 28 | exe.link_gc_sections = true; | 28 | exe.link_gc_sections = true; |
| 29 | 29 | ||
| 30 | const check = exe.checkObject(.macho); | 30 | const check = exe.checkObject(.macho); |
| ... | @@ -37,11 +37,13 @@ pub fn build(b: *Builder) void { | ... | @@ -37,11 +37,13 @@ pub fn build(b: *Builder) void { |
| 37 | } | 37 | } |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | fn createScenario(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget) *LibExeObjectStep { | 40 | fn createScenario(b: *Builder, optimize: std.builtin.OptimizeMode, target: std.zig.CrossTarget) *LibExeObjectStep { |
| 41 | const exe = b.addExecutable("test", null); | 41 | const exe = b.addExecutable(.{ |
| 42 | .name = "test", | ||
| 43 | .optimize = optimize, | ||
| 44 | .target = target, | ||
| 45 | }); | ||
| 42 | exe.addCSourceFile("main.c", &[0][]const u8{}); | 46 | exe.addCSourceFile("main.c", &[0][]const u8{}); |
| 43 | exe.setBuildMode(mode); | ||
| 44 | exe.setTarget(target); | ||
| 45 | exe.linkLibC(); | 47 | exe.linkLibC(); |
| 46 | return exe; | 48 | return exe; |
| 47 | } | 49 | } |
test/link/macho/dead_strip_dylibs/build.zig+8-6| ... | @@ -3,14 +3,14 @@ const Builder = std.build.Builder; | ... | @@ -3,14 +3,14 @@ const Builder = std.build.Builder; |
| 3 | const LibExeObjectStep = std.build.LibExeObjStep; | 3 | const LibExeObjectStep = std.build.LibExeObjStep; |
| 4 | 4 | ||
| 5 | pub fn build(b: *Builder) void { | 5 | pub fn build(b: *Builder) void { |
| 6 | const mode = b.standardReleaseOptions(); | 6 | const optimize = b.standardOptimizeOption(.{}); |
| 7 | 7 | ||
| 8 | const test_step = b.step("test", "Test the program"); | 8 | const test_step = b.step("test", "Test the program"); |
| 9 | test_step.dependOn(b.getInstallStep()); | 9 | test_step.dependOn(b.getInstallStep()); |
| 10 | 10 | ||
| 11 | { | 11 | { |
| 12 | // Without -dead_strip_dylibs we expect `-la` to include liba.dylib in the final executable | 12 | // Without -dead_strip_dylibs we expect `-la` to include liba.dylib in the final executable |
| 13 | const exe = createScenario(b, mode); | 13 | const exe = createScenario(b, optimize); |
| 14 | 14 | ||
| 15 | const check = exe.checkObject(.macho); | 15 | const check = exe.checkObject(.macho); |
| 16 | check.checkStart("cmd LOAD_DYLIB"); | 16 | check.checkStart("cmd LOAD_DYLIB"); |
| ... | @@ -27,7 +27,7 @@ pub fn build(b: *Builder) void { | ... | @@ -27,7 +27,7 @@ pub fn build(b: *Builder) void { |
| 27 | 27 | ||
| 28 | { | 28 | { |
| 29 | // With -dead_strip_dylibs, we should include liba.dylib as it's unreachable | 29 | // With -dead_strip_dylibs, we should include liba.dylib as it's unreachable |
| 30 | const exe = createScenario(b, mode); | 30 | const exe = createScenario(b, optimize); |
| 31 | exe.dead_strip_dylibs = true; | 31 | exe.dead_strip_dylibs = true; |
| 32 | 32 | ||
| 33 | const run_cmd = exe.run(); | 33 | const run_cmd = exe.run(); |
| ... | @@ -36,10 +36,12 @@ pub fn build(b: *Builder) void { | ... | @@ -36,10 +36,12 @@ pub fn build(b: *Builder) void { |
| 36 | } | 36 | } |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | fn createScenario(b: *Builder, mode: std.builtin.Mode) *LibExeObjectStep { | 39 | fn createScenario(b: *Builder, optimize: std.builtin.OptimizeMode) *LibExeObjectStep { |
| 40 | const exe = b.addExecutable("test", null); | 40 | const exe = b.addExecutable(.{ |
| 41 | .name = "test", | ||
| 42 | .optimize = optimize, | ||
| 43 | }); | ||
| 41 | exe.addCSourceFile("main.c", &[0][]const u8{}); | 44 | exe.addCSourceFile("main.c", &[0][]const u8{}); |
| 42 | exe.setBuildMode(mode); | ||
| 43 | exe.linkLibC(); | 45 | exe.linkLibC(); |
| 44 | exe.linkFramework("Cocoa"); | 46 | exe.linkFramework("Cocoa"); |
| 45 | return exe; | 47 | return exe; |
test/link/macho/dylib/build.zig+12-7| ... | @@ -2,15 +2,18 @@ const std = @import("std"); | ... | @@ -2,15 +2,18 @@ const std = @import("std"); |
| 2 | const Builder = std.build.Builder; | 2 | const Builder = std.build.Builder; |
| 3 | 3 | ||
| 4 | pub fn build(b: *Builder) void { | 4 | pub fn build(b: *Builder) void { |
| 5 | const mode = b.standardReleaseOptions(); | 5 | const optimize = b.standardOptimizeOption(.{}); |
| 6 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 6 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; |
| 7 | 7 | ||
| 8 | const test_step = b.step("test", "Test"); | 8 | const test_step = b.step("test", "Test"); |
| 9 | test_step.dependOn(b.getInstallStep()); | 9 | test_step.dependOn(b.getInstallStep()); |
| 10 | 10 | ||
| 11 | const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0)); | 11 | const dylib = b.addSharedLibrary(.{ |
| 12 | dylib.setBuildMode(mode); | 12 | .name = "a", |
| 13 | dylib.setTarget(target); | 13 | .version = .{ .major = 1, .minor = 0 }, |
| 14 | .optimize = optimize, | ||
| 15 | .target = target, | ||
| 16 | }); | ||
| 14 | dylib.addCSourceFile("a.c", &.{}); | 17 | dylib.addCSourceFile("a.c", &.{}); |
| 15 | dylib.linkLibC(); | 18 | dylib.linkLibC(); |
| 16 | dylib.install(); | 19 | dylib.install(); |
| ... | @@ -24,9 +27,11 @@ pub fn build(b: *Builder) void { | ... | @@ -24,9 +27,11 @@ pub fn build(b: *Builder) void { |
| 24 | 27 | ||
| 25 | test_step.dependOn(&check_dylib.step); | 28 | test_step.dependOn(&check_dylib.step); |
| 26 | 29 | ||
| 27 | const exe = b.addExecutable("main", null); | 30 | const exe = b.addExecutable(.{ |
| 28 | exe.setTarget(target); | 31 | .name = "main", |
| 29 | exe.setBuildMode(mode); | 32 | .optimize = optimize, |
| 33 | .target = target, | ||
| 34 | }); | ||
| 30 | exe.addCSourceFile("main.c", &.{}); | 35 | exe.addCSourceFile("main.c", &.{}); |
| 31 | exe.linkSystemLibrary("a"); | 36 | exe.linkSystemLibrary("a"); |
| 32 | exe.linkLibC(); | 37 | exe.linkLibC(); |
test/link/macho/empty/build.zig+6-4| ... | @@ -2,17 +2,19 @@ const std = @import("std"); | ... | @@ -2,17 +2,19 @@ const std = @import("std"); |
| 2 | const Builder = std.build.Builder; | 2 | const Builder = std.build.Builder; |
| 3 | 3 | ||
| 4 | pub fn build(b: *Builder) void { | 4 | pub fn build(b: *Builder) void { |
| 5 | const mode = b.standardReleaseOptions(); | 5 | const optimize = b.standardOptimizeOption(.{}); |
| 6 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 6 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; |
| 7 | 7 | ||
| 8 | const test_step = b.step("test", "Test the program"); | 8 | const test_step = b.step("test", "Test the program"); |
| 9 | test_step.dependOn(b.getInstallStep()); | 9 | test_step.dependOn(b.getInstallStep()); |
| 10 | 10 | ||
| 11 | const exe = b.addExecutable("test", null); | 11 | const exe = b.addExecutable(.{ |
| 12 | .name = "test", | ||
| 13 | .optimize = optimize, | ||
| 14 | .target = target, | ||
| 15 | }); | ||
| 12 | exe.addCSourceFile("main.c", &[0][]const u8{}); | 16 | exe.addCSourceFile("main.c", &[0][]const u8{}); |
| 13 | exe.addCSourceFile("empty.c", &[0][]const u8{}); | 17 | exe.addCSourceFile("empty.c", &[0][]const u8{}); |
| 14 | exe.setBuildMode(mode); | ||
| 15 | exe.setTarget(target); | ||
| 16 | exe.linkLibC(); | 18 | exe.linkLibC(); |
| 17 | 19 | ||
| 18 | const run_cmd = std.build.EmulatableRunStep.create(b, "run", exe); | 20 | const run_cmd = std.build.EmulatableRunStep.create(b, "run", exe); |
test/link/macho/entry/build.zig+6-4| ... | @@ -2,14 +2,16 @@ const std = @import("std"); | ... | @@ -2,14 +2,16 @@ const std = @import("std"); |
| 2 | const Builder = std.build.Builder; | 2 | const Builder = std.build.Builder; |
| 3 | 3 | ||
| 4 | pub fn build(b: *Builder) void { | 4 | pub fn build(b: *Builder) void { |
| 5 | const mode = b.standardReleaseOptions(); | 5 | const optimize = b.standardOptimizeOption(.{}); |
| 6 | 6 | ||
| 7 | const test_step = b.step("test", "Test"); | 7 | const test_step = b.step("test", "Test"); |
| 8 | test_step.dependOn(b.getInstallStep()); | 8 | test_step.dependOn(b.getInstallStep()); |
| 9 | 9 | ||
| 10 | const exe = b.addExecutable("main", null); | 10 | const exe = b.addExecutable(.{ |
| 11 | exe.setTarget(.{ .os_tag = .macos }); | 11 | .name = "main", |
| 12 | exe.setBuildMode(mode); | 12 | .optimize = optimize, |
| 13 | .target = .{ .os_tag = .macos }, | ||
| 14 | }); | ||
| 13 | exe.addCSourceFile("main.c", &.{}); | 15 | exe.addCSourceFile("main.c", &.{}); |
| 14 | exe.linkLibC(); | 16 | exe.linkLibC(); |
| 15 | exe.entry_symbol_name = "_non_main"; | 17 | exe.entry_symbol_name = "_non_main"; |
test/link/macho/headerpad/build.zig+10-8| ... | @@ -4,14 +4,14 @@ const Builder = std.build.Builder; | ... | @@ -4,14 +4,14 @@ const Builder = std.build.Builder; |
| 4 | const LibExeObjectStep = std.build.LibExeObjStep; | 4 | const LibExeObjectStep = std.build.LibExeObjStep; |
| 5 | 5 | ||
| 6 | pub fn build(b: *Builder) void { | 6 | pub fn build(b: *Builder) void { |
| 7 | const mode = b.standardReleaseOptions(); | 7 | const optimize = b.standardOptimizeOption(.{}); |
| 8 | 8 | ||
| 9 | const test_step = b.step("test", "Test"); | 9 | const test_step = b.step("test", "Test"); |
| 10 | test_step.dependOn(b.getInstallStep()); | 10 | test_step.dependOn(b.getInstallStep()); |
| 11 | 11 | ||
| 12 | { | 12 | { |
| 13 | // Test -headerpad_max_install_names | 13 | // Test -headerpad_max_install_names |
| 14 | const exe = simpleExe(b, mode); | 14 | const exe = simpleExe(b, optimize); |
| 15 | exe.headerpad_max_install_names = true; | 15 | exe.headerpad_max_install_names = true; |
| 16 | 16 | ||
| 17 | const check = exe.checkObject(.macho); | 17 | const check = exe.checkObject(.macho); |
| ... | @@ -36,7 +36,7 @@ pub fn build(b: *Builder) void { | ... | @@ -36,7 +36,7 @@ pub fn build(b: *Builder) void { |
| 36 | 36 | ||
| 37 | { | 37 | { |
| 38 | // Test -headerpad | 38 | // Test -headerpad |
| 39 | const exe = simpleExe(b, mode); | 39 | const exe = simpleExe(b, optimize); |
| 40 | exe.headerpad_size = 0x10000; | 40 | exe.headerpad_size = 0x10000; |
| 41 | 41 | ||
| 42 | const check = exe.checkObject(.macho); | 42 | const check = exe.checkObject(.macho); |
| ... | @@ -52,7 +52,7 @@ pub fn build(b: *Builder) void { | ... | @@ -52,7 +52,7 @@ pub fn build(b: *Builder) void { |
| 52 | 52 | ||
| 53 | { | 53 | { |
| 54 | // Test both flags with -headerpad overriding -headerpad_max_install_names | 54 | // Test both flags with -headerpad overriding -headerpad_max_install_names |
| 55 | const exe = simpleExe(b, mode); | 55 | const exe = simpleExe(b, optimize); |
| 56 | exe.headerpad_max_install_names = true; | 56 | exe.headerpad_max_install_names = true; |
| 57 | exe.headerpad_size = 0x10000; | 57 | exe.headerpad_size = 0x10000; |
| 58 | 58 | ||
| ... | @@ -69,7 +69,7 @@ pub fn build(b: *Builder) void { | ... | @@ -69,7 +69,7 @@ pub fn build(b: *Builder) void { |
| 69 | 69 | ||
| 70 | { | 70 | { |
| 71 | // Test both flags with -headerpad_max_install_names overriding -headerpad | 71 | // Test both flags with -headerpad_max_install_names overriding -headerpad |
| 72 | const exe = simpleExe(b, mode); | 72 | const exe = simpleExe(b, optimize); |
| 73 | exe.headerpad_size = 0x1000; | 73 | exe.headerpad_size = 0x1000; |
| 74 | exe.headerpad_max_install_names = true; | 74 | exe.headerpad_max_install_names = true; |
| 75 | 75 | ||
| ... | @@ -94,9 +94,11 @@ pub fn build(b: *Builder) void { | ... | @@ -94,9 +94,11 @@ pub fn build(b: *Builder) void { |
| 94 | } | 94 | } |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | fn simpleExe(b: *Builder, mode: std.builtin.Mode) *LibExeObjectStep { | 97 | fn simpleExe(b: *Builder, optimize: std.builtin.OptimizeMode) *LibExeObjectStep { |
| 98 | const exe = b.addExecutable("main", null); | 98 | const exe = b.addExecutable(.{ |
| 99 | exe.setBuildMode(mode); | 99 | .name = "main", |
| 100 | .optimize = optimize, | ||
| 101 | }); | ||
| 100 | exe.addCSourceFile("main.c", &.{}); | 102 | exe.addCSourceFile("main.c", &.{}); |
| 101 | exe.linkLibC(); | 103 | exe.linkLibC(); |
| 102 | exe.linkFramework("CoreFoundation"); | 104 | exe.linkFramework("CoreFoundation"); |
test/link/macho/linksection/build.zig+8-5| ... | @@ -1,15 +1,18 @@ | ... | @@ -1,15 +1,18 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | 2 | ||
| 3 | pub fn build(b: *std.build.Builder) void { | 3 | pub fn build(b: *std.build.Builder) void { |
| 4 | const mode = b.standardReleaseOptions(); | 4 | const optimize = b.standardOptimizeOption(.{}); |
| 5 | const target = std.zig.CrossTarget{ .os_tag = .macos }; | 5 | const target = std.zig.CrossTarget{ .os_tag = .macos }; |
| 6 | 6 | ||
| 7 | const test_step = b.step("test", "Test"); | 7 | const test_step = b.step("test", "Test"); |
| 8 | test_step.dependOn(b.getInstallStep()); | 8 | test_step.dependOn(b.getInstallStep()); |
| 9 | 9 | ||
| 10 | const obj = b.addObject("test", "main.zig"); | 10 | const obj = b.addObject(.{ |
| 11 | obj.setBuildMode(mode); | 11 | .name = "test", |
| 12 | obj.setTarget(target); | 12 | .root_source_file = .{ .path = "main.zig" }, |
| 13 | .optimize = optimize, | ||
| 14 | .target = target, | ||
| 15 | }); | ||
| 13 | 16 | ||
| 14 | const check = obj.checkObject(.macho); | 17 | const check = obj.checkObject(.macho); |
| 15 | 18 | ||
| ... | @@ -19,7 +22,7 @@ pub fn build(b: *std.build.Builder) void { | ... | @@ -19,7 +22,7 @@ pub fn build(b: *std.build.Builder) void { |
| 19 | check.checkInSymtab(); | 22 | check.checkInSymtab(); |
| 20 | check.checkNext("{*} (__TEXT,__TestFn) external _testFn"); | 23 | check.checkNext("{*} (__TEXT,__TestFn) external _testFn"); |
| 21 | 24 | ||
| 22 | if (mode == .Debug) { | 25 | if (optimize == .Debug) { |
| 23 | check.checkInSymtab(); | 26 | check.checkInSymtab(); |
| 24 | check.checkNext("{*} (__TEXT,__TestGenFnA) _main.testGenericFn__anon_{*}"); | 27 | check.checkNext("{*} (__TEXT,__TestGenFnA) _main.testGenericFn__anon_{*}"); |
| 25 | } | 28 | } |
test/link/macho/needed_framework/build.zig+5-3| ... | @@ -3,16 +3,18 @@ const Builder = std.build.Builder; | ... | @@ -3,16 +3,18 @@ const Builder = std.build.Builder; |
| 3 | const LibExeObjectStep = std.build.LibExeObjStep; | 3 | const LibExeObjectStep = std.build.LibExeObjStep; |
| 4 | 4 | ||
| 5 | pub fn build(b: *Builder) void { | 5 | pub fn build(b: *Builder) void { |
| 6 | const mode = b.standardReleaseOptions(); | 6 | const optimize = b.standardOptimizeOption(.{}); |
| 7 | 7 | ||
| 8 | const test_step = b.step("test", "Test the program"); | 8 | const test_step = b.step("test", "Test the program"); |
| 9 | test_step.dependOn(b.getInstallStep()); | 9 | test_step.dependOn(b.getInstallStep()); |
| 10 | 10 | ||
| 11 | // -dead_strip_dylibs | 11 | // -dead_strip_dylibs |
| 12 | // -needed_framework Cocoa | 12 | // -needed_framework Cocoa |
| 13 | const exe = b.addExecutable("test", null); | 13 | const exe = b.addExecutable(.{ |
| 14 | .name = "test", | ||
| 15 | .optimize = optimize, | ||
| 16 | }); | ||
| 14 | exe.addCSourceFile("main.c", &[0][]const u8{}); | 17 | exe.addCSourceFile("main.c", &[0][]const u8{}); |
| 15 | exe.setBuildMode(mode); | ||
| 16 | exe.linkLibC(); | 18 | exe.linkLibC(); |
| 17 | exe.linkFrameworkNeeded("Cocoa"); | 19 | exe.linkFrameworkNeeded("Cocoa"); |
| 18 | exe.dead_strip_dylibs = true; | 20 | exe.dead_strip_dylibs = true; |
test/link/macho/needed_library/build.zig+12-7| ... | @@ -3,25 +3,30 @@ const Builder = std.build.Builder; | ... | @@ -3,25 +3,30 @@ const Builder = std.build.Builder; |
| 3 | const LibExeObjectStep = std.build.LibExeObjStep; | 3 | const LibExeObjectStep = std.build.LibExeObjStep; |
| 4 | 4 | ||
| 5 | pub fn build(b: *Builder) void { | 5 | pub fn build(b: *Builder) void { |
| 6 | const mode = b.standardReleaseOptions(); | 6 | const optimize = b.standardOptimizeOption(.{}); |
| 7 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 7 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; |
| 8 | 8 | ||
| 9 | const test_step = b.step("test", "Test the program"); | 9 | const test_step = b.step("test", "Test the program"); |
| 10 | test_step.dependOn(b.getInstallStep()); | 10 | test_step.dependOn(b.getInstallStep()); |
| 11 | 11 | ||
| 12 | const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0)); | 12 | const dylib = b.addSharedLibrary(.{ |
| 13 | dylib.setTarget(target); | 13 | .name = "a", |
| 14 | dylib.setBuildMode(mode); | 14 | .version = .{ .major = 1, .minor = 0 }, |
| 15 | .optimize = optimize, | ||
| 16 | .target = target, | ||
| 17 | }); | ||
| 15 | dylib.addCSourceFile("a.c", &.{}); | 18 | dylib.addCSourceFile("a.c", &.{}); |
| 16 | dylib.linkLibC(); | 19 | dylib.linkLibC(); |
| 17 | dylib.install(); | 20 | dylib.install(); |
| 18 | 21 | ||
| 19 | // -dead_strip_dylibs | 22 | // -dead_strip_dylibs |
| 20 | // -needed-la | 23 | // -needed-la |
| 21 | const exe = b.addExecutable("test", null); | 24 | const exe = b.addExecutable(.{ |
| 25 | .name = "test", | ||
| 26 | .optimize = optimize, | ||
| 27 | .target = target, | ||
| 28 | }); | ||
| 22 | exe.addCSourceFile("main.c", &[0][]const u8{}); | 29 | exe.addCSourceFile("main.c", &[0][]const u8{}); |
| 23 | exe.setBuildMode(mode); | ||
| 24 | exe.setTarget(target); | ||
| 25 | exe.linkLibC(); | 30 | exe.linkLibC(); |
| 26 | exe.linkSystemLibraryNeeded("a"); | 31 | exe.linkSystemLibraryNeeded("a"); |
| 27 | exe.addLibraryPath(b.pathFromRoot("zig-out/lib")); | 32 | exe.addLibraryPath(b.pathFromRoot("zig-out/lib")); |
test/link/macho/objc/build.zig+5-3| ... | @@ -2,15 +2,17 @@ const std = @import("std"); | ... | @@ -2,15 +2,17 @@ const std = @import("std"); |
| 2 | const Builder = std.build.Builder; | 2 | const Builder = std.build.Builder; |
| 3 | 3 | ||
| 4 | pub fn build(b: *Builder) void { | 4 | pub fn build(b: *Builder) void { |
| 5 | const mode = b.standardReleaseOptions(); | 5 | const optimize = b.standardOptimizeOption(.{}); |
| 6 | 6 | ||
| 7 | const test_step = b.step("test", "Test the program"); | 7 | const test_step = b.step("test", "Test the program"); |
| 8 | 8 | ||
| 9 | const exe = b.addExecutable("test", null); | 9 | const exe = b.addExecutable(.{ |
| 10 | .name = "test", | ||
| 11 | .optimize = optimize, | ||
| 12 | }); | ||
| 10 | exe.addIncludePath("."); | 13 | exe.addIncludePath("."); |
| 11 | exe.addCSourceFile("Foo.m", &[0][]const u8{}); | 14 | exe.addCSourceFile("Foo.m", &[0][]const u8{}); |
| 12 | exe.addCSourceFile("test.m", &[0][]const u8{}); | 15 | exe.addCSourceFile("test.m", &[0][]const u8{}); |
| 13 | exe.setBuildMode(mode); | ||
| 14 | exe.linkLibC(); | 16 | exe.linkLibC(); |
| 15 | // TODO when we figure out how to ship framework stubs for cross-compilation, | 17 | // TODO when we figure out how to ship framework stubs for cross-compilation, |
| 16 | // populate paths to the sysroot here. | 18 | // populate paths to the sysroot here. |
test/link/macho/objcpp/build.zig+5-3| ... | @@ -2,16 +2,18 @@ const std = @import("std"); | ... | @@ -2,16 +2,18 @@ const std = @import("std"); |
| 2 | const Builder = std.build.Builder; | 2 | const Builder = std.build.Builder; |
| 3 | 3 | ||
| 4 | pub fn build(b: *Builder) void { | 4 | pub fn build(b: *Builder) void { |
| 5 | const mode = b.standardReleaseOptions(); | 5 | const optimize = b.standardOptimizeOption(.{}); |
| 6 | 6 | ||
| 7 | const test_step = b.step("test", "Test the program"); | 7 | const test_step = b.step("test", "Test the program"); |
| 8 | 8 | ||
| 9 | const exe = b.addExecutable("test", null); | 9 | const exe = b.addExecutable(.{ |
| 10 | .name = "test", | ||
| 11 | .optimize = optimize, | ||
| 12 | }); | ||
| 10 | b.default_step.dependOn(&exe.step); | 13 | b.default_step.dependOn(&exe.step); |
| 11 | exe.addIncludePath("."); | 14 | exe.addIncludePath("."); |
| 12 | exe.addCSourceFile("Foo.mm", &[0][]const u8{}); | 15 | exe.addCSourceFile("Foo.mm", &[0][]const u8{}); |
| 13 | exe.addCSourceFile("test.mm", &[0][]const u8{}); | 16 | exe.addCSourceFile("test.mm", &[0][]const u8{}); |
| 14 | exe.setBuildMode(mode); | ||
| 15 | exe.linkLibCpp(); | 17 | exe.linkLibCpp(); |
| 16 | // TODO when we figure out how to ship framework stubs for cross-compilation, | 18 | // TODO when we figure out how to ship framework stubs for cross-compilation, |
| 17 | // populate paths to the sysroot here. | 19 | // populate paths to the sysroot here. |
test/link/macho/pagezero/build.zig+11-7| ... | @@ -2,16 +2,18 @@ const std = @import("std"); | ... | @@ -2,16 +2,18 @@ const std = @import("std"); |
| 2 | const Builder = std.build.Builder; | 2 | const Builder = std.build.Builder; |
| 3 | 3 | ||
| 4 | pub fn build(b: *Builder) void { | 4 | pub fn build(b: *Builder) void { |
| 5 | const mode = b.standardReleaseOptions(); | 5 | const optimize = b.standardOptimizeOption(.{}); |
| 6 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 6 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; |
| 7 | 7 | ||
| 8 | const test_step = b.step("test", "Test"); | 8 | const test_step = b.step("test", "Test"); |
| 9 | test_step.dependOn(b.getInstallStep()); | 9 | test_step.dependOn(b.getInstallStep()); |
| 10 | 10 | ||
| 11 | { | 11 | { |
| 12 | const exe = b.addExecutable("pagezero", null); | 12 | const exe = b.addExecutable(.{ |
| 13 | exe.setTarget(target); | 13 | .name = "pagezero", |
| 14 | exe.setBuildMode(mode); | 14 | .optimize = optimize, |
| 15 | .target = target, | ||
| 16 | }); | ||
| 15 | exe.addCSourceFile("main.c", &.{}); | 17 | exe.addCSourceFile("main.c", &.{}); |
| 16 | exe.linkLibC(); | 18 | exe.linkLibC(); |
| 17 | exe.pagezero_size = 0x4000; | 19 | exe.pagezero_size = 0x4000; |
| ... | @@ -29,9 +31,11 @@ pub fn build(b: *Builder) void { | ... | @@ -29,9 +31,11 @@ pub fn build(b: *Builder) void { |
| 29 | } | 31 | } |
| 30 | 32 | ||
| 31 | { | 33 | { |
| 32 | const exe = b.addExecutable("no_pagezero", null); | 34 | const exe = b.addExecutable(.{ |
| 33 | exe.setTarget(target); | 35 | .name = "no_pagezero", |
| 34 | exe.setBuildMode(mode); | 36 | .optimize = optimize, |
| 37 | .target = target, | ||
| 38 | }); | ||
| 35 | exe.addCSourceFile("main.c", &.{}); | 39 | exe.addCSourceFile("main.c", &.{}); |
| 36 | exe.linkLibC(); | 40 | exe.linkLibC(); |
| 37 | exe.pagezero_size = 0; | 41 | exe.pagezero_size = 0; |
test/link/macho/search_strategy/build.zig+20-13| ... | @@ -3,7 +3,7 @@ const Builder = std.build.Builder; | ... | @@ -3,7 +3,7 @@ const Builder = std.build.Builder; |
| 3 | const LibExeObjectStep = std.build.LibExeObjStep; | 3 | const LibExeObjectStep = std.build.LibExeObjStep; |
| 4 | 4 | ||
| 5 | pub fn build(b: *Builder) void { | 5 | pub fn build(b: *Builder) void { |
| 6 | const mode = b.standardReleaseOptions(); | 6 | const optimize = b.standardOptimizeOption(.{}); |
| 7 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 7 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; |
| 8 | 8 | ||
| 9 | const test_step = b.step("test", "Test"); | 9 | const test_step = b.step("test", "Test"); |
| ... | @@ -11,7 +11,7 @@ pub fn build(b: *Builder) void { | ... | @@ -11,7 +11,7 @@ pub fn build(b: *Builder) void { |
| 11 | 11 | ||
| 12 | { | 12 | { |
| 13 | // -search_dylibs_first | 13 | // -search_dylibs_first |
| 14 | const exe = createScenario(b, mode, target); | 14 | const exe = createScenario(b, optimize, target); |
| 15 | exe.search_strategy = .dylibs_first; | 15 | exe.search_strategy = .dylibs_first; |
| 16 | 16 | ||
| 17 | const check = exe.checkObject(.macho); | 17 | const check = exe.checkObject(.macho); |
| ... | @@ -26,7 +26,7 @@ pub fn build(b: *Builder) void { | ... | @@ -26,7 +26,7 @@ pub fn build(b: *Builder) void { |
| 26 | 26 | ||
| 27 | { | 27 | { |
| 28 | // -search_paths_first | 28 | // -search_paths_first |
| 29 | const exe = createScenario(b, mode, target); | 29 | const exe = createScenario(b, optimize, target); |
| 30 | exe.search_strategy = .paths_first; | 30 | exe.search_strategy = .paths_first; |
| 31 | 31 | ||
| 32 | const run = std.build.EmulatableRunStep.create(b, "run", exe); | 32 | const run = std.build.EmulatableRunStep.create(b, "run", exe); |
| ... | @@ -36,10 +36,12 @@ pub fn build(b: *Builder) void { | ... | @@ -36,10 +36,12 @@ pub fn build(b: *Builder) void { |
| 36 | } | 36 | } |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | fn createScenario(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget) *LibExeObjectStep { | 39 | fn createScenario(b: *Builder, optimize: std.builtin.OptimizeMode, target: std.zig.CrossTarget) *LibExeObjectStep { |
| 40 | const static = b.addStaticLibrary("a", null); | 40 | const static = b.addStaticLibrary(.{ |
| 41 | static.setTarget(target); | 41 | .name = "a", |
| 42 | static.setBuildMode(mode); | 42 | .optimize = optimize, |
| 43 | .target = target, | ||
| 44 | }); | ||
| 43 | static.addCSourceFile("a.c", &.{}); | 45 | static.addCSourceFile("a.c", &.{}); |
| 44 | static.linkLibC(); | 46 | static.linkLibC(); |
| 45 | static.override_dest_dir = std.build.InstallDir{ | 47 | static.override_dest_dir = std.build.InstallDir{ |
| ... | @@ -47,9 +49,12 @@ fn createScenario(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarg | ... | @@ -47,9 +49,12 @@ fn createScenario(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarg |
| 47 | }; | 49 | }; |
| 48 | static.install(); | 50 | static.install(); |
| 49 | 51 | ||
| 50 | const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0)); | 52 | const dylib = b.addSharedLibrary(.{ |
| 51 | dylib.setTarget(target); | 53 | .name = "a", |
| 52 | dylib.setBuildMode(mode); | 54 | .version = .{ .major = 1, .minor = 0 }, |
| 55 | .optimize = optimize, | ||
| 56 | .target = target, | ||
| 57 | }); | ||
| 53 | dylib.addCSourceFile("a.c", &.{}); | 58 | dylib.addCSourceFile("a.c", &.{}); |
| 54 | dylib.linkLibC(); | 59 | dylib.linkLibC(); |
| 55 | dylib.override_dest_dir = std.build.InstallDir{ | 60 | dylib.override_dest_dir = std.build.InstallDir{ |
| ... | @@ -57,9 +62,11 @@ fn createScenario(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarg | ... | @@ -57,9 +62,11 @@ fn createScenario(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarg |
| 57 | }; | 62 | }; |
| 58 | dylib.install(); | 63 | dylib.install(); |
| 59 | 64 | ||
| 60 | const exe = b.addExecutable("main", null); | 65 | const exe = b.addExecutable(.{ |
| 61 | exe.setTarget(target); | 66 | .name = "main", |
| 62 | exe.setBuildMode(mode); | 67 | .optimize = optimize, |
| 68 | .target = target, | ||
| 69 | }); | ||
| 63 | exe.addCSourceFile("main.c", &.{}); | 70 | exe.addCSourceFile("main.c", &.{}); |
| 64 | exe.linkSystemLibraryName("a"); | 71 | exe.linkSystemLibraryName("a"); |
| 65 | exe.linkLibC(); | 72 | exe.linkLibC(); |
test/link/macho/stack_size/build.zig+6-4| ... | @@ -2,15 +2,17 @@ const std = @import("std"); | ... | @@ -2,15 +2,17 @@ const std = @import("std"); |
| 2 | const Builder = std.build.Builder; | 2 | const Builder = std.build.Builder; |
| 3 | 3 | ||
| 4 | pub fn build(b: *Builder) void { | 4 | pub fn build(b: *Builder) void { |
| 5 | const mode = b.standardReleaseOptions(); | 5 | const optimize = b.standardOptimizeOption(.{}); |
| 6 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 6 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; |
| 7 | 7 | ||
| 8 | const test_step = b.step("test", "Test"); | 8 | const test_step = b.step("test", "Test"); |
| 9 | test_step.dependOn(b.getInstallStep()); | 9 | test_step.dependOn(b.getInstallStep()); |
| 10 | 10 | ||
| 11 | const exe = b.addExecutable("main", null); | 11 | const exe = b.addExecutable(.{ |
| 12 | exe.setTarget(target); | 12 | .name = "main", |
| 13 | exe.setBuildMode(mode); | 13 | .optimize = optimize, |
| 14 | .target = target, | ||
| 15 | }); | ||
| 14 | exe.addCSourceFile("main.c", &.{}); | 16 | exe.addCSourceFile("main.c", &.{}); |
| 15 | exe.linkLibC(); | 17 | exe.linkLibC(); |
| 16 | exe.stack_size = 0x100000000; | 18 | exe.stack_size = 0x100000000; |
test/link/macho/strict_validation/build.zig+7-4| ... | @@ -4,15 +4,18 @@ const Builder = std.build.Builder; | ... | @@ -4,15 +4,18 @@ const Builder = std.build.Builder; |
| 4 | const LibExeObjectStep = std.build.LibExeObjStep; | 4 | const LibExeObjectStep = std.build.LibExeObjStep; |
| 5 | 5 | ||
| 6 | pub fn build(b: *Builder) void { | 6 | pub fn build(b: *Builder) void { |
| 7 | const mode = b.standardReleaseOptions(); | 7 | const optimize = b.standardOptimizeOption(.{}); |
| 8 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 8 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; |
| 9 | 9 | ||
| 10 | const test_step = b.step("test", "Test"); | 10 | const test_step = b.step("test", "Test"); |
| 11 | test_step.dependOn(b.getInstallStep()); | 11 | test_step.dependOn(b.getInstallStep()); |
| 12 | 12 | ||
| 13 | const exe = b.addExecutable("main", "main.zig"); | 13 | const exe = b.addExecutable(.{ |
| 14 | exe.setBuildMode(mode); | 14 | .name = "main", |
| 15 | exe.setTarget(target); | 15 | .root_source_file = .{ .path = "main.zig" }, |
| 16 | .optimize = optimize, | ||
| 17 | .target = target, | ||
| 18 | }); | ||
| 16 | exe.linkLibC(); | 19 | exe.linkLibC(); |
| 17 | 20 | ||
| 18 | const check_exe = exe.checkObject(.macho); | 21 | const check_exe = exe.checkObject(.macho); |
test/link/macho/tls/build.zig+12-7| ... | @@ -2,18 +2,23 @@ const std = @import("std"); | ... | @@ -2,18 +2,23 @@ const std = @import("std"); |
| 2 | const Builder = std.build.Builder; | 2 | const Builder = std.build.Builder; |
| 3 | 3 | ||
| 4 | pub fn build(b: *Builder) void { | 4 | pub fn build(b: *Builder) void { |
| 5 | const mode = b.standardReleaseOptions(); | 5 | const optimize = b.standardOptimizeOption(.{}); |
| 6 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 6 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; |
| 7 | 7 | ||
| 8 | const lib = b.addSharedLibrary("a", null, b.version(1, 0, 0)); | 8 | const lib = b.addSharedLibrary(.{ |
| 9 | lib.setBuildMode(mode); | 9 | .name = "a", |
| 10 | lib.setTarget(target); | 10 | .version = .{ .major = 1, .minor = 0 }, |
| 11 | .optimize = optimize, | ||
| 12 | .target = target, | ||
| 13 | }); | ||
| 11 | lib.addCSourceFile("a.c", &.{}); | 14 | lib.addCSourceFile("a.c", &.{}); |
| 12 | lib.linkLibC(); | 15 | lib.linkLibC(); |
| 13 | 16 | ||
| 14 | const test_exe = b.addTest("main.zig"); | 17 | const test_exe = b.addTest(.{ |
| 15 | test_exe.setBuildMode(mode); | 18 | .root_source_file = .{ .path = "main.zig" }, |
| 16 | test_exe.setTarget(target); | 19 | .optimize = optimize, |
| 20 | .target = target, | ||
| 21 | }); | ||
| 17 | test_exe.linkLibrary(lib); | 22 | test_exe.linkLibrary(lib); |
| 18 | test_exe.linkLibC(); | 23 | test_exe.linkLibC(); |
| 19 | 24 |
test/link/macho/unwind_info/build.zig+11-9| ... | @@ -4,23 +4,23 @@ const Builder = std.build.Builder; | ... | @@ -4,23 +4,23 @@ const Builder = std.build.Builder; |
| 4 | const LibExeObjectStep = std.build.LibExeObjStep; | 4 | const LibExeObjectStep = std.build.LibExeObjStep; |
| 5 | 5 | ||
| 6 | pub fn build(b: *Builder) void { | 6 | pub fn build(b: *Builder) void { |
| 7 | const mode = b.standardReleaseOptions(); | 7 | const optimize = b.standardOptimizeOption(.{}); |
| 8 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 8 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; |
| 9 | 9 | ||
| 10 | const test_step = b.step("test", "Test the program"); | 10 | const test_step = b.step("test", "Test the program"); |
| 11 | 11 | ||
| 12 | testUnwindInfo(b, test_step, mode, target, false); | 12 | testUnwindInfo(b, test_step, optimize, target, false); |
| 13 | testUnwindInfo(b, test_step, mode, target, true); | 13 | testUnwindInfo(b, test_step, optimize, target, true); |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | fn testUnwindInfo( | 16 | fn testUnwindInfo( |
| 17 | b: *Builder, | 17 | b: *Builder, |
| 18 | test_step: *std.build.Step, | 18 | test_step: *std.build.Step, |
| 19 | mode: std.builtin.Mode, | 19 | optimize: std.builtin.OptimizeMode, |
| 20 | target: std.zig.CrossTarget, | 20 | target: std.zig.CrossTarget, |
| 21 | dead_strip: bool, | 21 | dead_strip: bool, |
| 22 | ) void { | 22 | ) void { |
| 23 | const exe = createScenario(b, mode, target); | 23 | const exe = createScenario(b, optimize, target); |
| 24 | exe.link_gc_sections = dead_strip; | 24 | exe.link_gc_sections = dead_strip; |
| 25 | 25 | ||
| 26 | const check = exe.checkObject(.macho); | 26 | const check = exe.checkObject(.macho); |
| ... | @@ -52,8 +52,12 @@ fn testUnwindInfo( | ... | @@ -52,8 +52,12 @@ fn testUnwindInfo( |
| 52 | test_step.dependOn(&run_cmd.step); | 52 | test_step.dependOn(&run_cmd.step); |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | fn createScenario(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget) *LibExeObjectStep { | 55 | fn createScenario(b: *Builder, optimize: std.builtin.OptimizeMode, target: std.zig.CrossTarget) *LibExeObjectStep { |
| 56 | const exe = b.addExecutable("test", null); | 56 | const exe = b.addExecutable(.{ |
| 57 | .name = "test", | ||
| 58 | .optimize = optimize, | ||
| 59 | .target = target, | ||
| 60 | }); | ||
| 57 | b.default_step.dependOn(&exe.step); | 61 | b.default_step.dependOn(&exe.step); |
| 58 | exe.addIncludePath("."); | 62 | exe.addIncludePath("."); |
| 59 | exe.addCSourceFiles(&[_][]const u8{ | 63 | exe.addCSourceFiles(&[_][]const u8{ |
| ... | @@ -61,8 +65,6 @@ fn createScenario(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarg | ... | @@ -61,8 +65,6 @@ fn createScenario(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarg |
| 61 | "simple_string.cpp", | 65 | "simple_string.cpp", |
| 62 | "simple_string_owner.cpp", | 66 | "simple_string_owner.cpp", |
| 63 | }, &[0][]const u8{}); | 67 | }, &[0][]const u8{}); |
| 64 | exe.setBuildMode(mode); | ||
| 65 | exe.setTarget(target); | ||
| 66 | exe.linkLibCpp(); | 68 | exe.linkLibCpp(); |
| 67 | return exe; | 69 | return exe; |
| 68 | } | 70 | } |
test/link/macho/uuid/build.zig+10-7| ... | @@ -29,21 +29,21 @@ pub fn build(b: *Builder) void { | ... | @@ -29,21 +29,21 @@ pub fn build(b: *Builder) void { |
| 29 | fn testUuid( | 29 | fn testUuid( |
| 30 | b: *Builder, | 30 | b: *Builder, |
| 31 | test_step: *std.build.Step, | 31 | test_step: *std.build.Step, |
| 32 | mode: std.builtin.Mode, | 32 | optimize: std.builtin.OptimizeMode, |
| 33 | target: std.zig.CrossTarget, | 33 | target: std.zig.CrossTarget, |
| 34 | comptime exp: []const u8, | 34 | comptime exp: []const u8, |
| 35 | ) void { | 35 | ) void { |
| 36 | // The calculated UUID value is independent of debug info and so it should | 36 | // The calculated UUID value is independent of debug info and so it should |
| 37 | // stay the same across builds. | 37 | // stay the same across builds. |
| 38 | { | 38 | { |
| 39 | const dylib = simpleDylib(b, mode, target); | 39 | const dylib = simpleDylib(b, optimize, target); |
| 40 | const check_dylib = dylib.checkObject(.macho); | 40 | const check_dylib = dylib.checkObject(.macho); |
| 41 | check_dylib.checkStart("cmd UUID"); | 41 | check_dylib.checkStart("cmd UUID"); |
| 42 | check_dylib.checkNext("uuid " ++ exp); | 42 | check_dylib.checkNext("uuid " ++ exp); |
| 43 | test_step.dependOn(&check_dylib.step); | 43 | test_step.dependOn(&check_dylib.step); |
| 44 | } | 44 | } |
| 45 | { | 45 | { |
| 46 | const dylib = simpleDylib(b, mode, target); | 46 | const dylib = simpleDylib(b, optimize, target); |
| 47 | dylib.strip = true; | 47 | dylib.strip = true; |
| 48 | const check_dylib = dylib.checkObject(.macho); | 48 | const check_dylib = dylib.checkObject(.macho); |
| 49 | check_dylib.checkStart("cmd UUID"); | 49 | check_dylib.checkStart("cmd UUID"); |
| ... | @@ -52,10 +52,13 @@ fn testUuid( | ... | @@ -52,10 +52,13 @@ fn testUuid( |
| 52 | } | 52 | } |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | fn simpleDylib(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget) *LibExeObjectStep { | 55 | fn simpleDylib(b: *Builder, optimize: std.builtin.OptimizeMode, target: std.zig.CrossTarget) *LibExeObjectStep { |
| 56 | const dylib = b.addSharedLibrary("test", null, b.version(1, 0, 0)); | 56 | const dylib = b.addSharedLibrary(.{ |
| 57 | dylib.setTarget(target); | 57 | .name = "test", |
| 58 | dylib.setBuildMode(mode); | 58 | .version = .{ .major = 1, .minor = 0 }, |
| 59 | .optimize = optimize, | ||
| 60 | .target = target, | ||
| 61 | }); | ||
| 59 | dylib.addCSourceFile("test.c", &.{}); | 62 | dylib.addCSourceFile("test.c", &.{}); |
| 60 | dylib.linkLibC(); | 63 | dylib.linkLibC(); |
| 61 | return dylib; | 64 | return dylib; |
test/link/macho/weak_framework/build.zig+5-3| ... | @@ -3,14 +3,16 @@ const Builder = std.build.Builder; | ... | @@ -3,14 +3,16 @@ const Builder = std.build.Builder; |
| 3 | const LibExeObjectStep = std.build.LibExeObjStep; | 3 | const LibExeObjectStep = std.build.LibExeObjStep; |
| 4 | 4 | ||
| 5 | pub fn build(b: *Builder) void { | 5 | pub fn build(b: *Builder) void { |
| 6 | const mode = b.standardReleaseOptions(); | 6 | const optimize = b.standardOptimizeOption(.{}); |
| 7 | 7 | ||
| 8 | const test_step = b.step("test", "Test the program"); | 8 | const test_step = b.step("test", "Test the program"); |
| 9 | test_step.dependOn(b.getInstallStep()); | 9 | test_step.dependOn(b.getInstallStep()); |
| 10 | 10 | ||
| 11 | const exe = b.addExecutable("test", null); | 11 | const exe = b.addExecutable(.{ |
| 12 | .name = "test", | ||
| 13 | .optimize = optimize, | ||
| 14 | }); | ||
| 12 | exe.addCSourceFile("main.c", &[0][]const u8{}); | 15 | exe.addCSourceFile("main.c", &[0][]const u8{}); |
| 13 | exe.setBuildMode(mode); | ||
| 14 | exe.linkLibC(); | 16 | exe.linkLibC(); |
| 15 | exe.linkFrameworkWeak("Cocoa"); | 17 | exe.linkFrameworkWeak("Cocoa"); |
| 16 | 18 |
test/link/macho/weak_library/build.zig+12-7| ... | @@ -3,23 +3,28 @@ const Builder = std.build.Builder; | ... | @@ -3,23 +3,28 @@ const Builder = std.build.Builder; |
| 3 | const LibExeObjectStep = std.build.LibExeObjStep; | 3 | const LibExeObjectStep = std.build.LibExeObjStep; |
| 4 | 4 | ||
| 5 | pub fn build(b: *Builder) void { | 5 | pub fn build(b: *Builder) void { |
| 6 | const mode = b.standardReleaseOptions(); | 6 | const optimize = b.standardOptimizeOption(.{}); |
| 7 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 7 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; |
| 8 | 8 | ||
| 9 | const test_step = b.step("test", "Test the program"); | 9 | const test_step = b.step("test", "Test the program"); |
| 10 | test_step.dependOn(b.getInstallStep()); | 10 | test_step.dependOn(b.getInstallStep()); |
| 11 | 11 | ||
| 12 | const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0)); | 12 | const dylib = b.addSharedLibrary(.{ |
| 13 | dylib.setTarget(target); | 13 | .name = "a", |
| 14 | dylib.setBuildMode(mode); | 14 | .version = .{ .major = 1, .minor = 0, .patch = 0 }, |
| 15 | .target = target, | ||
| 16 | .optimize = optimize, | ||
| 17 | }); | ||
| 15 | dylib.addCSourceFile("a.c", &.{}); | 18 | dylib.addCSourceFile("a.c", &.{}); |
| 16 | dylib.linkLibC(); | 19 | dylib.linkLibC(); |
| 17 | dylib.install(); | 20 | dylib.install(); |
| 18 | 21 | ||
| 19 | const exe = b.addExecutable("test", null); | 22 | const exe = b.addExecutable(.{ |
| 23 | .name = "test", | ||
| 24 | .target = target, | ||
| 25 | .optimize = optimize, | ||
| 26 | }); | ||
| 20 | exe.addCSourceFile("main.c", &[0][]const u8{}); | 27 | exe.addCSourceFile("main.c", &[0][]const u8{}); |
| 21 | exe.setTarget(target); | ||
| 22 | exe.setBuildMode(mode); | ||
| 23 | exe.linkLibC(); | 28 | exe.linkLibC(); |
| 24 | exe.linkSystemLibraryWeak("a"); | 29 | exe.linkSystemLibraryWeak("a"); |
| 25 | exe.addLibraryPath(b.pathFromRoot("zig-out/lib")); | 30 | exe.addLibraryPath(b.pathFromRoot("zig-out/lib")); |
test/link/static_lib_as_system_lib/build.zig+12-5| ... | @@ -2,16 +2,23 @@ const std = @import("std"); | ... | @@ -2,16 +2,23 @@ const std = @import("std"); |
| 2 | const Builder = std.build.Builder; | 2 | const Builder = std.build.Builder; |
| 3 | 3 | ||
| 4 | pub fn build(b: *Builder) void { | 4 | pub fn build(b: *Builder) void { |
| 5 | const mode = b.standardReleaseOptions(); | 5 | const optimize = b.standardOptimizeOption(.{}); |
| 6 | const target = b.standardTargetOptions(.{}); | ||
| 6 | 7 | ||
| 7 | const lib_a = b.addStaticLibrary("a", null); | 8 | const lib_a = b.addStaticLibrary(.{ |
| 9 | .name = "a", | ||
| 10 | .optimize = optimize, | ||
| 11 | .target = target, | ||
| 12 | }); | ||
| 8 | lib_a.addCSourceFile("a.c", &[_][]const u8{}); | 13 | lib_a.addCSourceFile("a.c", &[_][]const u8{}); |
| 9 | lib_a.setBuildMode(mode); | ||
| 10 | lib_a.addIncludePath("."); | 14 | lib_a.addIncludePath("."); |
| 11 | lib_a.install(); | 15 | lib_a.install(); |
| 12 | 16 | ||
| 13 | const test_exe = b.addTest("main.zig"); | 17 | const test_exe = b.addTest(.{ |
| 14 | test_exe.setBuildMode(mode); | 18 | .root_source_file = .{ .path = "main.zig" }, |
| 19 | .optimize = optimize, | ||
| 20 | .target = target, | ||
| 21 | }); | ||
| 15 | test_exe.linkSystemLibrary("a"); // force linking liba.a as -la | 22 | test_exe.linkSystemLibrary("a"); // force linking liba.a as -la |
| 16 | test_exe.addSystemIncludePath("."); | 23 | test_exe.addSystemIncludePath("."); |
| 17 | const search_path = std.fs.path.join(b.allocator, &[_][]const u8{ b.install_path, "lib" }) catch unreachable; | 24 | const search_path = std.fs.path.join(b.allocator, &[_][]const u8{ b.install_path, "lib" }) catch unreachable; |
test/link/wasm/archive/build.zig+6-5| ... | @@ -2,16 +2,17 @@ const std = @import("std"); | ... | @@ -2,16 +2,17 @@ const std = @import("std"); |
| 2 | const Builder = std.build.Builder; | 2 | const Builder = std.build.Builder; |
| 3 | 3 | ||
| 4 | pub fn build(b: *Builder) void { | 4 | pub fn build(b: *Builder) void { |
| 5 | const mode = b.standardReleaseOptions(); | ||
| 6 | |||
| 7 | const test_step = b.step("test", "Test"); | 5 | const test_step = b.step("test", "Test"); |
| 8 | test_step.dependOn(b.getInstallStep()); | 6 | test_step.dependOn(b.getInstallStep()); |
| 9 | 7 | ||
| 10 | // The code in question will pull-in compiler-rt, | 8 | // The code in question will pull-in compiler-rt, |
| 11 | // and therefore link with its archive file. | 9 | // and therefore link with its archive file. |
| 12 | const lib = b.addSharedLibrary("main", "main.zig", .unversioned); | 10 | const lib = b.addSharedLibrary(.{ |
| 13 | lib.setBuildMode(mode); | 11 | .name = "main", |
| 14 | lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }); | 12 | .root_source_file = .{ .path = "main.zig" }, |
| 13 | .optimize = b.standardOptimizeOption(.{}), | ||
| 14 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | ||
| 15 | }); | ||
| 15 | lib.use_llvm = false; | 16 | lib.use_llvm = false; |
| 16 | lib.use_lld = false; | 17 | lib.use_lld = false; |
| 17 | lib.strip = false; | 18 | lib.strip = false; |
test/link/wasm/basic-features/build.zig+11-7| ... | @@ -1,14 +1,18 @@ | ... | @@ -1,14 +1,18 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | 2 | ||
| 3 | pub fn build(b: *std.build.Builder) void { | 3 | pub fn build(b: *std.build.Builder) void { |
| 4 | const mode = b.standardReleaseOptions(); | ||
| 5 | |||
| 6 | // Library with explicitly set cpu features | 4 | // Library with explicitly set cpu features |
| 7 | const lib = b.addSharedLibrary("lib", "main.zig", .unversioned); | 5 | const lib = b.addSharedLibrary(.{ |
| 8 | lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }); | 6 | .name = "lib", |
| 9 | lib.target.cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }; | 7 | .root_source_file = .{ .path = "main.zig" }, |
| 10 | lib.target.cpu_features_add.addFeature(0); // index 0 == atomics (see std.Target.wasm.Features) | 8 | .optimize = b.standardOptimizeOption(.{}), |
| 11 | lib.setBuildMode(mode); | 9 | .target = .{ |
| 10 | .cpu_arch = .wasm32, | ||
| 11 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }, | ||
| 12 | .cpu_features_add = std.Target.wasm.featureSet(&.{.atomics}), | ||
| 13 | .os_tag = .freestanding, | ||
| 14 | }, | ||
| 15 | }); | ||
| 12 | lib.use_llvm = false; | 16 | lib.use_llvm = false; |
| 13 | lib.use_lld = false; | 17 | lib.use_lld = false; |
| 14 | 18 |
test/link/wasm/bss/build.zig+6-5| ... | @@ -2,14 +2,15 @@ const std = @import("std"); | ... | @@ -2,14 +2,15 @@ const std = @import("std"); |
| 2 | const Builder = std.build.Builder; | 2 | const Builder = std.build.Builder; |
| 3 | 3 | ||
| 4 | pub fn build(b: *Builder) void { | 4 | pub fn build(b: *Builder) void { |
| 5 | const mode = b.standardReleaseOptions(); | ||
| 6 | |||
| 7 | const test_step = b.step("test", "Test"); | 5 | const test_step = b.step("test", "Test"); |
| 8 | test_step.dependOn(b.getInstallStep()); | 6 | test_step.dependOn(b.getInstallStep()); |
| 9 | 7 | ||
| 10 | const lib = b.addSharedLibrary("lib", "lib.zig", .unversioned); | 8 | const lib = b.addSharedLibrary(.{ |
| 11 | lib.setBuildMode(mode); | 9 | .name = "lib", |
| 12 | lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }); | 10 | .root_source_file = .{ .path = "lib.zig" }, |
| 11 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | ||
| 12 | .optimize = b.standardOptimizeOption(.{}), | ||
| 13 | }); | ||
| 13 | lib.use_llvm = false; | 14 | lib.use_llvm = false; |
| 14 | lib.use_lld = false; | 15 | lib.use_lld = false; |
| 15 | lib.strip = false; | 16 | lib.strip = false; |
test/link/wasm/export-data/build.zig+6-3| ... | @@ -5,9 +5,12 @@ pub fn build(b: *Builder) void { | ... | @@ -5,9 +5,12 @@ pub fn build(b: *Builder) void { |
| 5 | const test_step = b.step("test", "Test"); | 5 | const test_step = b.step("test", "Test"); |
| 6 | test_step.dependOn(b.getInstallStep()); | 6 | test_step.dependOn(b.getInstallStep()); |
| 7 | 7 | ||
| 8 | const lib = b.addSharedLibrary("lib", "lib.zig", .unversioned); | 8 | const lib = b.addSharedLibrary(.{ |
| 9 | lib.setBuildMode(.ReleaseSafe); // to make the output deterministic in address positions | 9 | .name = "lib", |
| 10 | lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }); | 10 | .root_source_file = .{ .path = "lib.zig" }, |
| 11 | .optimize = .ReleaseSafe, // to make the output deterministic in address positions | ||
| 12 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | ||
| 13 | }); | ||
| 11 | lib.use_lld = false; | 14 | lib.use_lld = false; |
| 12 | lib.export_symbol_names = &.{ "foo", "bar" }; | 15 | lib.export_symbol_names = &.{ "foo", "bar" }; |
| 13 | lib.global_base = 0; // put data section at address 0 to make data symbols easier to parse | 16 | lib.global_base = 0; // put data section at address 0 to make data symbols easier to parse |
test/link/wasm/export/build.zig+20-11| ... | @@ -1,24 +1,33 @@ | ... | @@ -1,24 +1,33 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | 2 | ||
| 3 | pub fn build(b: *std.build.Builder) void { | 3 | pub fn build(b: *std.build.Builder) void { |
| 4 | const mode = b.standardReleaseOptions(); | 4 | const optimize = b.standardOptimizeOption(.{}); |
| 5 | 5 | ||
| 6 | const no_export = b.addSharedLibrary("no-export", "main.zig", .unversioned); | 6 | const no_export = b.addSharedLibrary(.{ |
| 7 | no_export.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }); | 7 | .name = "no-export", |
| 8 | no_export.setBuildMode(mode); | 8 | .root_source_file = .{ .path = "main.zig" }, |
| 9 | .optimize = optimize, | ||
| 10 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | ||
| 11 | }); | ||
| 9 | no_export.use_llvm = false; | 12 | no_export.use_llvm = false; |
| 10 | no_export.use_lld = false; | 13 | no_export.use_lld = false; |
| 11 | 14 | ||
| 12 | const dynamic_export = b.addSharedLibrary("dynamic", "main.zig", .unversioned); | 15 | const dynamic_export = b.addSharedLibrary(.{ |
| 13 | dynamic_export.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }); | 16 | .name = "dynamic", |
| 14 | dynamic_export.setBuildMode(mode); | 17 | .root_source_file = .{ .path = "main.zig" }, |
| 18 | .optimize = optimize, | ||
| 19 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | ||
| 20 | }); | ||
| 15 | dynamic_export.rdynamic = true; | 21 | dynamic_export.rdynamic = true; |
| 16 | dynamic_export.use_llvm = false; | 22 | dynamic_export.use_llvm = false; |
| 17 | dynamic_export.use_lld = false; | 23 | dynamic_export.use_lld = false; |
| 18 | 24 | ||
| 19 | const force_export = b.addSharedLibrary("force", "main.zig", .unversioned); | 25 | const force_export = b.addSharedLibrary(.{ |
| 20 | force_export.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }); | 26 | .name = "force", |
| 21 | force_export.setBuildMode(mode); | 27 | .root_source_file = .{ .path = "main.zig" }, |
| 28 | .optimize = optimize, | ||
| 29 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | ||
| 30 | }); | ||
| 22 | force_export.export_symbol_names = &.{"foo"}; | 31 | force_export.export_symbol_names = &.{"foo"}; |
| 23 | force_export.use_llvm = false; | 32 | force_export.use_llvm = false; |
| 24 | force_export.use_lld = false; | 33 | force_export.use_lld = false; |
test/link/wasm/extern-mangle/build.zig+6-5| ... | @@ -2,14 +2,15 @@ const std = @import("std"); | ... | @@ -2,14 +2,15 @@ const std = @import("std"); |
| 2 | const Builder = std.build.Builder; | 2 | const Builder = std.build.Builder; |
| 3 | 3 | ||
| 4 | pub fn build(b: *Builder) void { | 4 | pub fn build(b: *Builder) void { |
| 5 | const mode = b.standardReleaseOptions(); | ||
| 6 | |||
| 7 | const test_step = b.step("test", "Test"); | 5 | const test_step = b.step("test", "Test"); |
| 8 | test_step.dependOn(b.getInstallStep()); | 6 | test_step.dependOn(b.getInstallStep()); |
| 9 | 7 | ||
| 10 | const lib = b.addSharedLibrary("lib", "lib.zig", .unversioned); | 8 | const lib = b.addSharedLibrary(.{ |
| 11 | lib.setBuildMode(mode); | 9 | .name = "lib", |
| 12 | lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }); | 10 | .root_source_file = .{ .path = "lib.zig" }, |
| 11 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | ||
| 12 | .optimize = b.standardOptimizeOption(.{}), | ||
| 13 | }); | ||
| 13 | lib.import_symbols = true; // import `a` and `b` | 14 | lib.import_symbols = true; // import `a` and `b` |
| 14 | lib.rdynamic = true; // export `foo` | 15 | lib.rdynamic = true; // export `foo` |
| 15 | lib.install(); | 16 | lib.install(); |
test/link/wasm/extern/build.zig+6-4| ... | @@ -1,10 +1,12 @@ | ... | @@ -1,10 +1,12 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | 2 | ||
| 3 | pub fn build(b: *std.build.Builder) void { | 3 | pub fn build(b: *std.build.Builder) void { |
| 4 | const mode = b.standardReleaseOptions(); | 4 | const exe = b.addExecutable(.{ |
| 5 | const exe = b.addExecutable("extern", "main.zig"); | 5 | .name = "extern", |
| 6 | exe.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .wasi }); | 6 | .root_source_file = .{ .path = "main.zig" }, |
| 7 | exe.setBuildMode(mode); | 7 | .optimize = b.standardOptimizeOption(.{}), |
| 8 | .target = .{ .cpu_arch = .wasm32, .os_tag = .wasi }, | ||
| 9 | }); | ||
| 8 | exe.addCSourceFile("foo.c", &.{}); | 10 | exe.addCSourceFile("foo.c", &.{}); |
| 9 | exe.use_llvm = false; | 11 | exe.use_llvm = false; |
| 10 | exe.use_lld = false; | 12 | exe.use_lld = false; |
test/link/wasm/function-table/build.zig+19-10| ... | @@ -2,28 +2,37 @@ const std = @import("std"); | ... | @@ -2,28 +2,37 @@ const std = @import("std"); |
| 2 | const Builder = std.build.Builder; | 2 | const Builder = std.build.Builder; |
| 3 | 3 | ||
| 4 | pub fn build(b: *Builder) void { | 4 | pub fn build(b: *Builder) void { |
| 5 | const mode = b.standardReleaseOptions(); | 5 | const optimize = b.standardOptimizeOption(.{}); |
| 6 | 6 | ||
| 7 | const test_step = b.step("test", "Test"); | 7 | const test_step = b.step("test", "Test"); |
| 8 | test_step.dependOn(b.getInstallStep()); | 8 | test_step.dependOn(b.getInstallStep()); |
| 9 | 9 | ||
| 10 | const import_table = b.addSharedLibrary("lib", "lib.zig", .unversioned); | 10 | const import_table = b.addSharedLibrary(.{ |
| 11 | import_table.setBuildMode(mode); | 11 | .name = "lib", |
| 12 | import_table.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }); | 12 | .root_source_file = .{ .path = "lib.zig" }, |
| 13 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | ||
| 14 | .optimize = optimize, | ||
| 15 | }); | ||
| 13 | import_table.use_llvm = false; | 16 | import_table.use_llvm = false; |
| 14 | import_table.use_lld = false; | 17 | import_table.use_lld = false; |
| 15 | import_table.import_table = true; | 18 | import_table.import_table = true; |
| 16 | 19 | ||
| 17 | const export_table = b.addSharedLibrary("lib", "lib.zig", .unversioned); | 20 | const export_table = b.addSharedLibrary(.{ |
| 18 | export_table.setBuildMode(mode); | 21 | .name = "lib", |
| 19 | export_table.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }); | 22 | .root_source_file = .{ .path = "lib.zig" }, |
| 23 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | ||
| 24 | .optimize = optimize, | ||
| 25 | }); | ||
| 20 | export_table.use_llvm = false; | 26 | export_table.use_llvm = false; |
| 21 | export_table.use_lld = false; | 27 | export_table.use_lld = false; |
| 22 | export_table.export_table = true; | 28 | export_table.export_table = true; |
| 23 | 29 | ||
| 24 | const regular_table = b.addSharedLibrary("lib", "lib.zig", .unversioned); | 30 | const regular_table = b.addSharedLibrary(.{ |
| 25 | regular_table.setBuildMode(mode); | 31 | .name = "lib", |
| 26 | regular_table.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }); | 32 | .root_source_file = .{ .path = "lib.zig" }, |
| 33 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | ||
| 34 | .optimize = optimize, | ||
| 35 | }); | ||
| 27 | regular_table.use_llvm = false; | 36 | regular_table.use_llvm = false; |
| 28 | regular_table.use_lld = false; | 37 | regular_table.use_lld = false; |
| 29 | 38 |
test/link/wasm/infer-features/build.zig+20-9| ... | @@ -1,21 +1,32 @@ | ... | @@ -1,21 +1,32 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | 2 | ||
| 3 | pub fn build(b: *std.build.Builder) void { | 3 | pub fn build(b: *std.build.Builder) void { |
| 4 | const mode = b.standardReleaseOptions(); | 4 | const optimize = b.standardOptimizeOption(.{}); |
| 5 | 5 | ||
| 6 | // Wasm Object file which we will use to infer the features from | 6 | // Wasm Object file which we will use to infer the features from |
| 7 | const c_obj = b.addObject("c_obj", null); | 7 | const c_obj = b.addObject(.{ |
| 8 | c_obj.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }); | 8 | .name = "c_obj", |
| 9 | c_obj.target.cpu_model = .{ .explicit = &std.Target.wasm.cpu.bleeding_edge }; | 9 | .optimize = optimize, |
| 10 | .target = .{ | ||
| 11 | .cpu_arch = .wasm32, | ||
| 12 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.bleeding_edge }, | ||
| 13 | .os_tag = .freestanding, | ||
| 14 | }, | ||
| 15 | }); | ||
| 10 | c_obj.addCSourceFile("foo.c", &.{}); | 16 | c_obj.addCSourceFile("foo.c", &.{}); |
| 11 | c_obj.setBuildMode(mode); | ||
| 12 | 17 | ||
| 13 | // Wasm library that doesn't have any features specified. This will | 18 | // Wasm library that doesn't have any features specified. This will |
| 14 | // infer its featureset from other linked object files. | 19 | // infer its featureset from other linked object files. |
| 15 | const lib = b.addSharedLibrary("lib", "main.zig", .unversioned); | 20 | const lib = b.addSharedLibrary(.{ |
| 16 | lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }); | 21 | .name = "lib", |
| 17 | lib.target.cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }; | 22 | .root_source_file = .{ .path = "main.zig" }, |
| 18 | lib.setBuildMode(mode); | 23 | .optimize = optimize, |
| 24 | .target = .{ | ||
| 25 | .cpu_arch = .wasm32, | ||
| 26 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }, | ||
| 27 | .os_tag = .freestanding, | ||
| 28 | }, | ||
| 29 | }); | ||
| 19 | lib.use_llvm = false; | 30 | lib.use_llvm = false; |
| 20 | lib.use_lld = false; | 31 | lib.use_lld = false; |
| 21 | lib.addObject(c_obj); | 32 | lib.addObject(c_obj); |
test/link/wasm/producers/build.zig+6-5| ... | @@ -3,14 +3,15 @@ const builtin = @import("builtin"); | ... | @@ -3,14 +3,15 @@ const builtin = @import("builtin"); |
| 3 | const Builder = std.build.Builder; | 3 | const Builder = std.build.Builder; |
| 4 | 4 | ||
| 5 | pub fn build(b: *Builder) void { | 5 | pub fn build(b: *Builder) void { |
| 6 | const mode = b.standardReleaseOptions(); | ||
| 7 | |||
| 8 | const test_step = b.step("test", "Test"); | 6 | const test_step = b.step("test", "Test"); |
| 9 | test_step.dependOn(b.getInstallStep()); | 7 | test_step.dependOn(b.getInstallStep()); |
| 10 | 8 | ||
| 11 | const lib = b.addSharedLibrary("lib", "lib.zig", .unversioned); | 9 | const lib = b.addSharedLibrary(.{ |
| 12 | lib.setBuildMode(mode); | 10 | .name = "lib", |
| 13 | lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }); | 11 | .root_source_file = .{ .path = "lib.zig" }, |
| 12 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | ||
| 13 | .optimize = b.standardOptimizeOption(.{}), | ||
| 14 | }); | ||
| 14 | lib.use_llvm = false; | 15 | lib.use_llvm = false; |
| 15 | lib.use_lld = false; | 16 | lib.use_lld = false; |
| 16 | lib.strip = false; | 17 | lib.strip = false; |
test/link/wasm/segments/build.zig+6-5| ... | @@ -2,14 +2,15 @@ const std = @import("std"); | ... | @@ -2,14 +2,15 @@ const std = @import("std"); |
| 2 | const Builder = std.build.Builder; | 2 | const Builder = std.build.Builder; |
| 3 | 3 | ||
| 4 | pub fn build(b: *Builder) void { | 4 | pub fn build(b: *Builder) void { |
| 5 | const mode = b.standardReleaseOptions(); | ||
| 6 | |||
| 7 | const test_step = b.step("test", "Test"); | 5 | const test_step = b.step("test", "Test"); |
| 8 | test_step.dependOn(b.getInstallStep()); | 6 | test_step.dependOn(b.getInstallStep()); |
| 9 | 7 | ||
| 10 | const lib = b.addSharedLibrary("lib", "lib.zig", .unversioned); | 8 | const lib = b.addSharedLibrary(.{ |
| 11 | lib.setBuildMode(mode); | 9 | .name = "lib", |
| 12 | lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }); | 10 | .root_source_file = .{ .path = "lib.zig" }, |
| 11 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | ||
| 12 | .optimize = b.standardOptimizeOption(.{}), | ||
| 13 | }); | ||
| 13 | lib.use_llvm = false; | 14 | lib.use_llvm = false; |
| 14 | lib.use_lld = false; | 15 | lib.use_lld = false; |
| 15 | lib.strip = false; | 16 | lib.strip = false; |
test/link/wasm/stack_pointer/build.zig+6-5| ... | @@ -2,14 +2,15 @@ const std = @import("std"); | ... | @@ -2,14 +2,15 @@ const std = @import("std"); |
| 2 | const Builder = std.build.Builder; | 2 | const Builder = std.build.Builder; |
| 3 | 3 | ||
| 4 | pub fn build(b: *Builder) void { | 4 | pub fn build(b: *Builder) void { |
| 5 | const mode = b.standardReleaseOptions(); | ||
| 6 | |||
| 7 | const test_step = b.step("test", "Test"); | 5 | const test_step = b.step("test", "Test"); |
| 8 | test_step.dependOn(b.getInstallStep()); | 6 | test_step.dependOn(b.getInstallStep()); |
| 9 | 7 | ||
| 10 | const lib = b.addSharedLibrary("lib", "lib.zig", .unversioned); | 8 | const lib = b.addSharedLibrary(.{ |
| 11 | lib.setBuildMode(mode); | 9 | .name = "lib", |
| 12 | lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }); | 10 | .root_source_file = .{ .path = "lib.zig" }, |
| 11 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | ||
| 12 | .optimize = b.standardOptimizeOption(.{}), | ||
| 13 | }); | ||
| 13 | lib.use_llvm = false; | 14 | lib.use_llvm = false; |
| 14 | lib.use_lld = false; | 15 | lib.use_lld = false; |
| 15 | lib.strip = false; | 16 | lib.strip = false; |
test/link/wasm/type/build.zig+6-5| ... | @@ -2,14 +2,15 @@ const std = @import("std"); | ... | @@ -2,14 +2,15 @@ const std = @import("std"); |
| 2 | const Builder = std.build.Builder; | 2 | const Builder = std.build.Builder; |
| 3 | 3 | ||
| 4 | pub fn build(b: *Builder) void { | 4 | pub fn build(b: *Builder) void { |
| 5 | const mode = b.standardReleaseOptions(); | ||
| 6 | |||
| 7 | const test_step = b.step("test", "Test"); | 5 | const test_step = b.step("test", "Test"); |
| 8 | test_step.dependOn(b.getInstallStep()); | 6 | test_step.dependOn(b.getInstallStep()); |
| 9 | 7 | ||
| 10 | const lib = b.addSharedLibrary("lib", "lib.zig", .unversioned); | 8 | const lib = b.addSharedLibrary(.{ |
| 11 | lib.setBuildMode(mode); | 9 | .name = "lib", |
| 12 | lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }); | 10 | .root_source_file = .{ .path = "lib.zig" }, |
| 11 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | ||
| 12 | .optimize = b.standardOptimizeOption(.{}), | ||
| 13 | }); | ||
| 13 | lib.use_llvm = false; | 14 | lib.use_llvm = false; |
| 14 | lib.use_lld = false; | 15 | lib.use_lld = false; |
| 15 | lib.strip = false; | 16 | lib.strip = false; |
test/src/compare_output.zig+23-8| ... | @@ -6,14 +6,14 @@ const ArrayList = std.ArrayList; | ... | @@ -6,14 +6,14 @@ const ArrayList = std.ArrayList; |
| 6 | const fmt = std.fmt; | 6 | const fmt = std.fmt; |
| 7 | const mem = std.mem; | 7 | const mem = std.mem; |
| 8 | const fs = std.fs; | 8 | const fs = std.fs; |
| 9 | const Mode = std.builtin.Mode; | 9 | const OptimizeMode = std.builtin.OptimizeMode; |
| 10 | 10 | ||
| 11 | pub const CompareOutputContext = struct { | 11 | pub const CompareOutputContext = struct { |
| 12 | b: *build.Builder, | 12 | b: *build.Builder, |
| 13 | step: *build.Step, | 13 | step: *build.Step, |
| 14 | test_index: usize, | 14 | test_index: usize, |
| 15 | test_filter: ?[]const u8, | 15 | test_filter: ?[]const u8, |
| 16 | modes: []const Mode, | 16 | optimize_modes: []const OptimizeMode, |
| 17 | 17 | ||
| 18 | const Special = enum { | 18 | const Special = enum { |
| 19 | None, | 19 | None, |
| ... | @@ -102,7 +102,11 @@ pub const CompareOutputContext = struct { | ... | @@ -102,7 +102,11 @@ pub const CompareOutputContext = struct { |
| 102 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; | 102 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | const exe = b.addExecutable("test", null); | 105 | const exe = b.addExecutable(.{ |
| 106 | .name = "test", | ||
| 107 | .target = .{}, | ||
| 108 | .optimize = .Debug, | ||
| 109 | }); | ||
| 106 | exe.addAssemblyFileSource(write_src.getFileSource(case.sources.items[0].filename).?); | 110 | exe.addAssemblyFileSource(write_src.getFileSource(case.sources.items[0].filename).?); |
| 107 | 111 | ||
| 108 | const run = exe.run(); | 112 | const run = exe.run(); |
| ... | @@ -113,19 +117,23 @@ pub const CompareOutputContext = struct { | ... | @@ -113,19 +117,23 @@ pub const CompareOutputContext = struct { |
| 113 | self.step.dependOn(&run.step); | 117 | self.step.dependOn(&run.step); |
| 114 | }, | 118 | }, |
| 115 | Special.None => { | 119 | Special.None => { |
| 116 | for (self.modes) |mode| { | 120 | for (self.optimize_modes) |optimize| { |
| 117 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "{s} {s} ({s})", .{ | 121 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "{s} {s} ({s})", .{ |
| 118 | "compare-output", | 122 | "compare-output", |
| 119 | case.name, | 123 | case.name, |
| 120 | @tagName(mode), | 124 | @tagName(optimize), |
| 121 | }) catch unreachable; | 125 | }) catch unreachable; |
| 122 | if (self.test_filter) |filter| { | 126 | if (self.test_filter) |filter| { |
| 123 | if (mem.indexOf(u8, annotated_case_name, filter) == null) continue; | 127 | if (mem.indexOf(u8, annotated_case_name, filter) == null) continue; |
| 124 | } | 128 | } |
| 125 | 129 | ||
| 126 | const basename = case.sources.items[0].filename; | 130 | const basename = case.sources.items[0].filename; |
| 127 | const exe = b.addExecutableSource("test", write_src.getFileSource(basename).?); | 131 | const exe = b.addExecutable(.{ |
| 128 | exe.setBuildMode(mode); | 132 | .name = "test", |
| 133 | .root_source_file = write_src.getFileSource(basename).?, | ||
| 134 | .optimize = optimize, | ||
| 135 | .target = .{}, | ||
| 136 | }); | ||
| 129 | if (case.link_libc) { | 137 | if (case.link_libc) { |
| 130 | exe.linkSystemLibrary("c"); | 138 | exe.linkSystemLibrary("c"); |
| 131 | } | 139 | } |
| ... | @@ -139,13 +147,20 @@ pub const CompareOutputContext = struct { | ... | @@ -139,13 +147,20 @@ pub const CompareOutputContext = struct { |
| 139 | } | 147 | } |
| 140 | }, | 148 | }, |
| 141 | Special.RuntimeSafety => { | 149 | Special.RuntimeSafety => { |
| 150 | // TODO iterate over self.optimize_modes and test this in both | ||
| 151 | // debug and release safe mode | ||
| 142 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "safety {s}", .{case.name}) catch unreachable; | 152 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "safety {s}", .{case.name}) catch unreachable; |
| 143 | if (self.test_filter) |filter| { | 153 | if (self.test_filter) |filter| { |
| 144 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; | 154 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; |
| 145 | } | 155 | } |
| 146 | 156 | ||
| 147 | const basename = case.sources.items[0].filename; | 157 | const basename = case.sources.items[0].filename; |
| 148 | const exe = b.addExecutableSource("test", write_src.getFileSource(basename).?); | 158 | const exe = b.addExecutable(.{ |
| 159 | .name = "test", | ||
| 160 | .root_source_file = write_src.getFileSource(basename).?, | ||
| 161 | .target = .{}, | ||
| 162 | .optimize = .Debug, | ||
| 163 | }); | ||
| 149 | if (case.link_libc) { | 164 | if (case.link_libc) { |
| 150 | exe.linkSystemLibrary("c"); | 165 | exe.linkSystemLibrary("c"); |
| 151 | } | 166 | } |
test/src/run_translated_c.zig+6-3| ... | @@ -85,11 +85,14 @@ pub const RunTranslatedCContext = struct { | ... | @@ -85,11 +85,14 @@ pub const RunTranslatedCContext = struct { |
| 85 | for (case.sources.items) |src_file| { | 85 | for (case.sources.items) |src_file| { |
| 86 | write_src.add(src_file.filename, src_file.source); | 86 | write_src.add(src_file.filename, src_file.source); |
| 87 | } | 87 | } |
| 88 | const translate_c = b.addTranslateC(write_src.getFileSource(case.sources.items[0].filename).?); | 88 | const translate_c = b.addTranslateC(.{ |
| 89 | .source_file = write_src.getFileSource(case.sources.items[0].filename).?, | ||
| 90 | .target = .{}, | ||
| 91 | .optimize = .Debug, | ||
| 92 | }); | ||
| 89 | 93 | ||
| 90 | translate_c.step.name = b.fmt("{s} translate-c", .{annotated_case_name}); | 94 | translate_c.step.name = b.fmt("{s} translate-c", .{annotated_case_name}); |
| 91 | const exe = translate_c.addExecutable(); | 95 | const exe = translate_c.addExecutable(.{}); |
| 92 | exe.setTarget(self.target); | ||
| 93 | exe.step.name = b.fmt("{s} build-exe", .{annotated_case_name}); | 96 | exe.step.name = b.fmt("{s} build-exe", .{annotated_case_name}); |
| 94 | exe.linkLibC(); | 97 | exe.linkLibC(); |
| 95 | const run = exe.run(); | 98 | const run = exe.run(); |
test/src/translate_c.zig+5-2| ... | @@ -108,10 +108,13 @@ pub const TranslateCContext = struct { | ... | @@ -108,10 +108,13 @@ pub const TranslateCContext = struct { |
| 108 | write_src.add(src_file.filename, src_file.source); | 108 | write_src.add(src_file.filename, src_file.source); |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | const translate_c = b.addTranslateC(write_src.getFileSource(case.sources.items[0].filename).?); | 111 | const translate_c = b.addTranslateC(.{ |
| 112 | .source_file = write_src.getFileSource(case.sources.items[0].filename).?, | ||
| 113 | .target = case.target, | ||
| 114 | .optimize = .Debug, | ||
| 115 | }); | ||
| 112 | 116 | ||
| 113 | translate_c.step.name = annotated_case_name; | 117 | translate_c.step.name = annotated_case_name; |
| 114 | translate_c.setTarget(case.target); | ||
| 115 | 118 | ||
| 116 | const check_file = translate_c.addCheckFile(case.expected_lines.items); | 119 | const check_file = translate_c.addCheckFile(case.expected_lines.items); |
| 117 | 120 |
test/standalone/brace_expansion/build.zig+4-2| ... | @@ -1,8 +1,10 @@ | ... | @@ -1,8 +1,10 @@ |
| 1 | const Builder = @import("std").build.Builder; | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | ||
| 3 | pub fn build(b: *Builder) void { | 3 | pub fn build(b: *Builder) void { |
| 4 | const main = b.addTest("main.zig"); | 4 | const main = b.addTest(.{ |
| 5 | main.setBuildMode(b.standardReleaseOptions()); | 5 | .root_source_file = .{ .path = "main.zig" }, |
| 6 | .optimize = b.standardOptimizeOption(.{}), | ||
| 7 | }); | ||
| 6 | 8 | ||
| 7 | const test_step = b.step("test", "Test it"); | 9 | const test_step = b.step("test", "Test it"); |
| 8 | test_step.dependOn(&main.step); | 10 | test_step.dependOn(&main.step); |
test/standalone/c_compiler/build.zig+11-7| ... | @@ -12,23 +12,27 @@ fn isRunnableTarget(t: CrossTarget) bool { | ... | @@ -12,23 +12,27 @@ fn isRunnableTarget(t: CrossTarget) bool { |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | pub fn build(b: *Builder) void { | 14 | pub fn build(b: *Builder) void { |
| 15 | const mode = b.standardReleaseOptions(); | 15 | const optimize = b.standardOptimizeOption(.{}); |
| 16 | const target = b.standardTargetOptions(.{}); | 16 | const target = b.standardTargetOptions(.{}); |
| 17 | 17 | ||
| 18 | const test_step = b.step("test", "Test the program"); | 18 | const test_step = b.step("test", "Test the program"); |
| 19 | 19 | ||
| 20 | const exe_c = b.addExecutable("test_c", null); | 20 | const exe_c = b.addExecutable(.{ |
| 21 | .name = "test_c", | ||
| 22 | .optimize = optimize, | ||
| 23 | .target = target, | ||
| 24 | }); | ||
| 21 | b.default_step.dependOn(&exe_c.step); | 25 | b.default_step.dependOn(&exe_c.step); |
| 22 | exe_c.addCSourceFile("test.c", &[0][]const u8{}); | 26 | exe_c.addCSourceFile("test.c", &[0][]const u8{}); |
| 23 | exe_c.setBuildMode(mode); | ||
| 24 | exe_c.setTarget(target); | ||
| 25 | exe_c.linkLibC(); | 27 | exe_c.linkLibC(); |
| 26 | 28 | ||
| 27 | const exe_cpp = b.addExecutable("test_cpp", null); | 29 | const exe_cpp = b.addExecutable(.{ |
| 30 | .name = "test_cpp", | ||
| 31 | .optimize = optimize, | ||
| 32 | .target = target, | ||
| 33 | }); | ||
| 28 | b.default_step.dependOn(&exe_cpp.step); | 34 | b.default_step.dependOn(&exe_cpp.step); |
| 29 | exe_cpp.addCSourceFile("test.cpp", &[0][]const u8{}); | 35 | exe_cpp.addCSourceFile("test.cpp", &[0][]const u8{}); |
| 30 | exe_cpp.setBuildMode(mode); | ||
| 31 | exe_cpp.setTarget(target); | ||
| 32 | exe_cpp.linkLibCpp(); | 36 | exe_cpp.linkLibCpp(); |
| 33 | 37 | ||
| 34 | switch (target.getOsTag()) { | 38 | switch (target.getOsTag()) { |
test/standalone/emit_asm_and_bin/build.zig+4-2| ... | @@ -1,8 +1,10 @@ | ... | @@ -1,8 +1,10 @@ |
| 1 | const Builder = @import("std").build.Builder; | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | ||
| 3 | pub fn build(b: *Builder) void { | 3 | pub fn build(b: *Builder) void { |
| 4 | const main = b.addTest("main.zig"); | 4 | const main = b.addTest(.{ |
| 5 | main.setBuildMode(b.standardReleaseOptions()); | 5 | .root_source_file = .{ .path = "main.zig" }, |
| 6 | .optimize = b.standardOptimizeOption(.{}), | ||
| 7 | }); | ||
| 6 | main.emit_asm = .{ .emit_to = b.pathFromRoot("main.s") }; | 8 | main.emit_asm = .{ .emit_to = b.pathFromRoot("main.s") }; |
| 7 | main.emit_bin = .{ .emit_to = b.pathFromRoot("main") }; | 9 | main.emit_bin = .{ .emit_to = b.pathFromRoot("main") }; |
| 8 | 10 |
test/standalone/empty_env/build.zig+5-2| ... | @@ -1,8 +1,11 @@ | ... | @@ -1,8 +1,11 @@ |
| 1 | const Builder = @import("std").build.Builder; | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | ||
| 3 | pub fn build(b: *Builder) void { | 3 | pub fn build(b: *Builder) void { |
| 4 | const main = b.addExecutable("main", "main.zig"); | 4 | const main = b.addExecutable(.{ |
| 5 | main.setBuildMode(b.standardReleaseOptions()); | 5 | .name = "main", |
| 6 | .root_source_file = .{ .path = "main.zig" }, | ||
| 7 | .optimize = b.standardOptimizeOption(.{}), | ||
| 8 | }); | ||
| 6 | 9 | ||
| 7 | const run = main.run(); | 10 | const run = main.run(); |
| 8 | run.clearEnvironment(); | 11 | run.clearEnvironment(); |
test/standalone/global_linkage/build.zig+17-7| ... | @@ -1,16 +1,26 @@ | ... | @@ -1,16 +1,26 @@ |
| 1 | const Builder = @import("std").build.Builder; | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | ||
| 3 | pub fn build(b: *Builder) void { | 3 | pub fn build(b: *Builder) void { |
| 4 | const mode = b.standardReleaseOptions(); | 4 | const optimize = b.standardOptimizeOption(.{}); |
| 5 | 5 | ||
| 6 | const obj1 = b.addStaticLibrary("obj1", "obj1.zig"); | 6 | const obj1 = b.addStaticLibrary(.{ |
| 7 | obj1.setBuildMode(mode); | 7 | .name = "obj1", |
| 8 | .root_source_file = .{ .path = "obj1.zig" }, | ||
| 9 | .optimize = optimize, | ||
| 10 | .target = .{}, | ||
| 11 | }); | ||
| 8 | 12 | ||
| 9 | const obj2 = b.addStaticLibrary("obj2", "obj2.zig"); | 13 | const obj2 = b.addStaticLibrary(.{ |
| 10 | obj2.setBuildMode(mode); | 14 | .name = "obj2", |
| 15 | .root_source_file = .{ .path = "obj2.zig" }, | ||
| 16 | .optimize = optimize, | ||
| 17 | .target = .{}, | ||
| 18 | }); | ||
| 11 | 19 | ||
| 12 | const main = b.addTest("main.zig"); | 20 | const main = b.addTest(.{ |
| 13 | main.setBuildMode(mode); | 21 | .root_source_file = .{ .path = "main.zig" }, |
| 22 | .optimize = optimize, | ||
| 23 | }); | ||
| 14 | main.linkLibrary(obj1); | 24 | main.linkLibrary(obj1); |
| 15 | main.linkLibrary(obj2); | 25 | main.linkLibrary(obj2); |
| 16 | 26 |
test/standalone/install_raw_hex/build.zig+7-4| ... | @@ -10,11 +10,14 @@ pub fn build(b: *std.build.Builder) void { | ... | @@ -10,11 +10,14 @@ pub fn build(b: *std.build.Builder) void { |
| 10 | .abi = .gnueabihf, | 10 | .abi = .gnueabihf, |
| 11 | }; | 11 | }; |
| 12 | 12 | ||
| 13 | const mode = b.standardReleaseOptions(); | 13 | const optimize = b.standardOptimizeOption(.{}); |
| 14 | 14 | ||
| 15 | const elf = b.addExecutable("zig-nrf52-blink.elf", "main.zig"); | 15 | const elf = b.addExecutable(.{ |
| 16 | elf.setTarget(target); | 16 | .name = "zig-nrf52-blink.elf", |
| 17 | elf.setBuildMode(mode); | 17 | .root_source_file = .{ .path = "main.zig" }, |
| 18 | .target = target, | ||
| 19 | .optimize = optimize, | ||
| 20 | }); | ||
| 18 | 21 | ||
| 19 | const test_step = b.step("test", "Test the program"); | 22 | const test_step = b.step("test", "Test the program"); |
| 20 | b.default_step.dependOn(test_step); | 23 | b.default_step.dependOn(test_step); |
test/standalone/issue_11595/build.zig+7-4| ... | @@ -12,11 +12,15 @@ fn isRunnableTarget(t: CrossTarget) bool { | ... | @@ -12,11 +12,15 @@ fn isRunnableTarget(t: CrossTarget) bool { |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | pub fn build(b: *Builder) void { | 14 | pub fn build(b: *Builder) void { |
| 15 | const mode = b.standardReleaseOptions(); | 15 | const optimize = b.standardOptimizeOption(.{}); |
| 16 | const target = b.standardTargetOptions(.{}); | 16 | const target = b.standardTargetOptions(.{}); |
| 17 | 17 | ||
| 18 | const exe = b.addExecutable("zigtest", "main.zig"); | 18 | const exe = b.addExecutable(.{ |
| 19 | exe.setBuildMode(mode); | 19 | .name = "zigtest", |
| 20 | .root_source_file = .{ .path = "main.zig" }, | ||
| 21 | .target = target, | ||
| 22 | .optimize = optimize, | ||
| 23 | }); | ||
| 20 | exe.install(); | 24 | exe.install(); |
| 21 | 25 | ||
| 22 | const c_sources = [_][]const u8{ | 26 | const c_sources = [_][]const u8{ |
| ... | @@ -39,7 +43,6 @@ pub fn build(b: *Builder) void { | ... | @@ -39,7 +43,6 @@ pub fn build(b: *Builder) void { |
| 39 | exe.defineCMacro("QUX", "\"Q\" \"UX\""); | 43 | exe.defineCMacro("QUX", "\"Q\" \"UX\""); |
| 40 | exe.defineCMacro("QUUX", "\"QU\\\"UX\""); | 44 | exe.defineCMacro("QUUX", "\"QU\\\"UX\""); |
| 41 | 45 | ||
| 42 | exe.setTarget(target); | ||
| 43 | b.default_step.dependOn(&exe.step); | 46 | b.default_step.dependOn(&exe.step); |
| 44 | 47 | ||
| 45 | const test_step = b.step("test", "Test the program"); | 48 | const test_step = b.step("test", "Test the program"); |
test/standalone/issue_12588/build.zig+7-4| ... | @@ -2,12 +2,15 @@ const std = @import("std"); | ... | @@ -2,12 +2,15 @@ const std = @import("std"); |
| 2 | const Builder = std.build.Builder; | 2 | const Builder = std.build.Builder; |
| 3 | 3 | ||
| 4 | pub fn build(b: *Builder) void { | 4 | pub fn build(b: *Builder) void { |
| 5 | const mode = b.standardReleaseOptions(); | 5 | const optimize = b.standardOptimizeOption(.{}); |
| 6 | const target = b.standardTargetOptions(.{}); | 6 | const target = b.standardTargetOptions(.{}); |
| 7 | 7 | ||
| 8 | const obj = b.addObject("main", "main.zig"); | 8 | const obj = b.addObject(.{ |
| 9 | obj.setBuildMode(mode); | 9 | .name = "main", |
| 10 | obj.setTarget(target); | 10 | .root_source_file = .{ .path = "main.zig" }, |
| 11 | .optimize = optimize, | ||
| 12 | .target = target, | ||
| 13 | }); | ||
| 11 | obj.emit_llvm_ir = .{ .emit_to = b.pathFromRoot("main.ll") }; | 14 | obj.emit_llvm_ir = .{ .emit_to = b.pathFromRoot("main.ll") }; |
| 12 | obj.emit_llvm_bc = .{ .emit_to = b.pathFromRoot("main.bc") }; | 15 | obj.emit_llvm_bc = .{ .emit_to = b.pathFromRoot("main.bc") }; |
| 13 | obj.emit_bin = .no_emit; | 16 | obj.emit_bin = .no_emit; |
test/standalone/issue_12706/build.zig+7-4| ... | @@ -12,11 +12,15 @@ fn isRunnableTarget(t: CrossTarget) bool { | ... | @@ -12,11 +12,15 @@ fn isRunnableTarget(t: CrossTarget) bool { |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | pub fn build(b: *Builder) void { | 14 | pub fn build(b: *Builder) void { |
| 15 | const mode = b.standardReleaseOptions(); | 15 | const optimize = b.standardOptimizeOption(.{}); |
| 16 | const target = b.standardTargetOptions(.{}); | 16 | const target = b.standardTargetOptions(.{}); |
| 17 | 17 | ||
| 18 | const exe = b.addExecutable("main", "main.zig"); | 18 | const exe = b.addExecutable(.{ |
| 19 | exe.setBuildMode(mode); | 19 | .name = "main", |
| 20 | .root_source_file = .{ .path = "main.zig" }, | ||
| 21 | .optimize = optimize, | ||
| 22 | .target = target, | ||
| 23 | }); | ||
| 20 | exe.install(); | 24 | exe.install(); |
| 21 | 25 | ||
| 22 | const c_sources = [_][]const u8{ | 26 | const c_sources = [_][]const u8{ |
| ... | @@ -26,7 +30,6 @@ pub fn build(b: *Builder) void { | ... | @@ -26,7 +30,6 @@ pub fn build(b: *Builder) void { |
| 26 | exe.addCSourceFiles(&c_sources, &.{}); | 30 | exe.addCSourceFiles(&c_sources, &.{}); |
| 27 | exe.linkLibC(); | 31 | exe.linkLibC(); |
| 28 | 32 | ||
| 29 | exe.setTarget(target); | ||
| 30 | b.default_step.dependOn(&exe.step); | 33 | b.default_step.dependOn(&exe.step); |
| 31 | 34 | ||
| 32 | const test_step = b.step("test", "Test the program"); | 35 | const test_step = b.step("test", "Test the program"); |
test/standalone/issue_13030/build.zig+7-5| ... | @@ -4,13 +4,15 @@ const Builder = std.build.Builder; | ... | @@ -4,13 +4,15 @@ const Builder = std.build.Builder; |
| 4 | const CrossTarget = std.zig.CrossTarget; | 4 | const CrossTarget = std.zig.CrossTarget; |
| 5 | 5 | ||
| 6 | pub fn build(b: *Builder) void { | 6 | pub fn build(b: *Builder) void { |
| 7 | const mode = b.standardReleaseOptions(); | 7 | const optimize = b.standardOptimizeOption(.{}); |
| 8 | const target = b.standardTargetOptions(.{}); | 8 | const target = b.standardTargetOptions(.{}); |
| 9 | 9 | ||
| 10 | const obj = b.addObject("main", "main.zig"); | 10 | const obj = b.addObject(.{ |
| 11 | obj.setBuildMode(mode); | 11 | .name = "main", |
| 12 | 12 | .root_source_file = .{ .path = "main.zig" }, | |
| 13 | obj.setTarget(target); | 13 | .optimize = optimize, |
| 14 | .target = target, | ||
| 15 | }); | ||
| 14 | b.default_step.dependOn(&obj.step); | 16 | b.default_step.dependOn(&obj.step); |
| 15 | 17 | ||
| 16 | const test_step = b.step("test", "Test the program"); | 18 | const test_step = b.step("test", "Test the program"); |
test/standalone/issue_339/build.zig+6-1| ... | @@ -1,7 +1,12 @@ | ... | @@ -1,7 +1,12 @@ |
| 1 | const Builder = @import("std").build.Builder; | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | ||
| 3 | pub fn build(b: *Builder) void { | 3 | pub fn build(b: *Builder) void { |
| 4 | const obj = b.addObject("test", "test.zig"); | 4 | const obj = b.addObject(.{ |
| 5 | .name = "test", | ||
| 6 | .root_source_file = .{ .path = "test.zig" }, | ||
| 7 | .target = b.standardTargetOptions(.{}), | ||
| 8 | .optimize = b.standardOptimizeOption(.{}), | ||
| 9 | }); | ||
| 5 | 10 | ||
| 6 | const test_step = b.step("test", "Test the program"); | 11 | const test_step = b.step("test", "Test the program"); |
| 7 | test_step.dependOn(&obj.step); | 12 | test_step.dependOn(&obj.step); |
test/standalone/issue_5825/build.zig+12-7| ... | @@ -6,17 +6,22 @@ pub fn build(b: *Builder) void { | ... | @@ -6,17 +6,22 @@ pub fn build(b: *Builder) void { |
| 6 | .os_tag = .windows, | 6 | .os_tag = .windows, |
| 7 | .abi = .msvc, | 7 | .abi = .msvc, |
| 8 | }; | 8 | }; |
| 9 | const mode = b.standardReleaseOptions(); | 9 | const optimize = b.standardOptimizeOption(.{}); |
| 10 | const obj = b.addObject("issue_5825", "main.zig"); | 10 | const obj = b.addObject(.{ |
| 11 | obj.setTarget(target); | 11 | .name = "issue_5825", |
| 12 | obj.setBuildMode(mode); | 12 | .root_source_file = .{ .path = "main.zig" }, |
| 13 | .optimize = optimize, | ||
| 14 | .target = target, | ||
| 15 | }); | ||
| 13 | 16 | ||
| 14 | const exe = b.addExecutable("issue_5825", null); | 17 | const exe = b.addExecutable(.{ |
| 18 | .name = "issue_5825", | ||
| 19 | .optimize = optimize, | ||
| 20 | .target = target, | ||
| 21 | }); | ||
| 15 | exe.subsystem = .Console; | 22 | exe.subsystem = .Console; |
| 16 | exe.linkSystemLibrary("kernel32"); | 23 | exe.linkSystemLibrary("kernel32"); |
| 17 | exe.linkSystemLibrary("ntdll"); | 24 | exe.linkSystemLibrary("ntdll"); |
| 18 | exe.setTarget(target); | ||
| 19 | exe.setBuildMode(mode); | ||
| 20 | exe.addObject(obj); | 25 | exe.addObject(obj); |
| 21 | 26 | ||
| 22 | const test_step = b.step("test", "Test the program"); | 27 | const test_step = b.step("test", "Test the program"); |
test/standalone/issue_7030/build.zig+7-4| ... | @@ -1,10 +1,13 @@ | ... | @@ -1,10 +1,13 @@ |
| 1 | const Builder = @import("std").build.Builder; | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | ||
| 3 | pub fn build(b: *Builder) void { | 3 | pub fn build(b: *Builder) void { |
| 4 | const exe = b.addExecutable("issue_7030", "main.zig"); | 4 | const exe = b.addExecutable(.{ |
| 5 | exe.setTarget(.{ | 5 | .name = "issue_7030", |
| 6 | .cpu_arch = .wasm32, | 6 | .root_source_file = .{ .path = "main.zig" }, |
| 7 | .os_tag = .freestanding, | 7 | .target = .{ |
| 8 | .cpu_arch = .wasm32, | ||
| 9 | .os_tag = .freestanding, | ||
| 10 | }, | ||
| 8 | }); | 11 | }); |
| 9 | exe.install(); | 12 | exe.install(); |
| 10 | b.default_step.dependOn(&exe.step); | 13 | b.default_step.dependOn(&exe.step); |
test/standalone/issue_794/build.zig+3-1| ... | @@ -1,7 +1,9 @@ | ... | @@ -1,7 +1,9 @@ |
| 1 | const Builder = @import("std").build.Builder; | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | ||
| 3 | pub fn build(b: *Builder) void { | 3 | pub fn build(b: *Builder) void { |
| 4 | const test_artifact = b.addTest("main.zig"); | 4 | const test_artifact = b.addTest(.{ |
| 5 | .root_source_file = .{ .path = "main.zig" }, | ||
| 6 | }); | ||
| 5 | test_artifact.addIncludePath("a_directory"); | 7 | test_artifact.addIncludePath("a_directory"); |
| 6 | 8 | ||
| 7 | b.default_step.dependOn(&test_artifact.step); | 9 | b.default_step.dependOn(&test_artifact.step); |
test/standalone/issue_8550/build.zig+7-4| ... | @@ -8,12 +8,15 @@ pub fn build(b: *std.build.Builder) !void { | ... | @@ -8,12 +8,15 @@ pub fn build(b: *std.build.Builder) !void { |
| 8 | .explicit = &std.Target.arm.cpu.arm1176jz_s, | 8 | .explicit = &std.Target.arm.cpu.arm1176jz_s, |
| 9 | }, | 9 | }, |
| 10 | }; | 10 | }; |
| 11 | const mode = b.standardReleaseOptions(); | 11 | const optimize = b.standardOptimizeOption(.{}); |
| 12 | const kernel = b.addExecutable("kernel", "./main.zig"); | 12 | const kernel = b.addExecutable(.{ |
| 13 | .name = "kernel", | ||
| 14 | .root_source_file = .{ .path = "./main.zig" }, | ||
| 15 | .optimize = optimize, | ||
| 16 | .target = target, | ||
| 17 | }); | ||
| 13 | kernel.addObjectFile("./boot.S"); | 18 | kernel.addObjectFile("./boot.S"); |
| 14 | kernel.setLinkerScriptPath(.{ .path = "./linker.ld" }); | 19 | kernel.setLinkerScriptPath(.{ .path = "./linker.ld" }); |
| 15 | kernel.setBuildMode(mode); | ||
| 16 | kernel.setTarget(target); | ||
| 17 | kernel.install(); | 20 | kernel.install(); |
| 18 | 21 | ||
| 19 | const test_step = b.step("test", "Test it"); | 22 | const test_step = b.step("test", "Test it"); |
test/standalone/issue_9812/build.zig+5-3| ... | @@ -1,9 +1,11 @@ | ... | @@ -1,9 +1,11 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | 2 | ||
| 3 | pub fn build(b: *std.build.Builder) !void { | 3 | pub fn build(b: *std.build.Builder) !void { |
| 4 | const mode = b.standardReleaseOptions(); | 4 | const optimize = b.standardOptimizeOption(.{}); |
| 5 | const zip_add = b.addTest("main.zig"); | 5 | const zip_add = b.addTest(.{ |
| 6 | zip_add.setBuildMode(mode); | 6 | .root_source_file = .{ .path = "main.zig" }, |
| 7 | .optimize = optimize, | ||
| 8 | }); | ||
| 7 | zip_add.addCSourceFile("vendor/kuba-zip/zip.c", &[_][]const u8{ | 9 | zip_add.addCSourceFile("vendor/kuba-zip/zip.c", &[_][]const u8{ |
| 8 | "-std=c99", | 10 | "-std=c99", |
| 9 | "-fno-sanitize=undefined", | 11 | "-fno-sanitize=undefined", |
test/standalone/load_dynamic_library/build.zig+15-5| ... | @@ -1,13 +1,23 @@ | ... | @@ -1,13 +1,23 @@ |
| 1 | const Builder = @import("std").build.Builder; | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | ||
| 3 | pub fn build(b: *Builder) void { | 3 | pub fn build(b: *Builder) void { |
| 4 | const opts = b.standardReleaseOptions(); | 4 | const target = b.standardTargetOptions(.{}); |
| 5 | const optimize = b.standardOptimizeOption(.{}); | ||
| 5 | 6 | ||
| 6 | const lib = b.addSharedLibrary("add", "add.zig", b.version(1, 0, 0)); | 7 | const lib = b.addSharedLibrary(.{ |
| 7 | lib.setBuildMode(opts); | 8 | .name = "add", |
| 9 | .root_source_file = .{ .path = "add.zig" }, | ||
| 10 | .version = .{ .major = 1, .minor = 0 }, | ||
| 11 | .optimize = optimize, | ||
| 12 | .target = target, | ||
| 13 | }); | ||
| 8 | 14 | ||
| 9 | const main = b.addExecutable("main", "main.zig"); | 15 | const main = b.addExecutable(.{ |
| 10 | main.setBuildMode(opts); | 16 | .name = "main", |
| 17 | .root_source_file = .{ .path = "main.zig" }, | ||
| 18 | .optimize = optimize, | ||
| 19 | .target = target, | ||
| 20 | }); | ||
| 11 | 21 | ||
| 12 | const run = main.run(); | 22 | const run = main.run(); |
| 13 | run.addArtifactArg(lib); | 23 | run.addArtifactArg(lib); |
test/standalone/main_pkg_path/build.zig+3-1| ... | @@ -1,7 +1,9 @@ | ... | @@ -1,7 +1,9 @@ |
| 1 | const Builder = @import("std").build.Builder; | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | ||
| 3 | pub fn build(b: *Builder) void { | 3 | pub fn build(b: *Builder) void { |
| 4 | const test_exe = b.addTest("a/test.zig"); | 4 | const test_exe = b.addTest(.{ |
| 5 | .root_source_file = .{ .path = "a/test.zig" }, | ||
| 6 | }); | ||
| 5 | test_exe.setMainPkgPath("."); | 7 | test_exe.setMainPkgPath("."); |
| 6 | 8 | ||
| 7 | const test_step = b.step("test", "Test the program"); | 9 | const test_step = b.step("test", "Test the program"); |
test/standalone/mix_c_files/build.zig+7-4| ... | @@ -12,14 +12,17 @@ fn isRunnableTarget(t: CrossTarget) bool { | ... | @@ -12,14 +12,17 @@ fn isRunnableTarget(t: CrossTarget) bool { |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | pub fn build(b: *Builder) void { | 14 | pub fn build(b: *Builder) void { |
| 15 | const mode = b.standardReleaseOptions(); | 15 | const optimize = b.standardOptimizeOption(.{}); |
| 16 | const target = b.standardTargetOptions(.{}); | 16 | const target = b.standardTargetOptions(.{}); |
| 17 | 17 | ||
| 18 | const exe = b.addExecutable("test", "main.zig"); | 18 | const exe = b.addExecutable(.{ |
| 19 | .name = "test", | ||
| 20 | .root_source_file = .{ .path = "main.zig" }, | ||
| 21 | .optimize = optimize, | ||
| 22 | .target = target, | ||
| 23 | }); | ||
| 19 | exe.addCSourceFile("test.c", &[_][]const u8{"-std=c11"}); | 24 | exe.addCSourceFile("test.c", &[_][]const u8{"-std=c11"}); |
| 20 | exe.setBuildMode(mode); | ||
| 21 | exe.linkLibC(); | 25 | exe.linkLibC(); |
| 22 | exe.setTarget(target); | ||
| 23 | b.default_step.dependOn(&exe.step); | 26 | b.default_step.dependOn(&exe.step); |
| 24 | 27 | ||
| 25 | const test_step = b.step("test", "Test the program"); | 28 | const test_step = b.step("test", "Test the program"); |
test/standalone/mix_o_files/build.zig+12-2| ... | @@ -1,9 +1,19 @@ | ... | @@ -1,9 +1,19 @@ |
| 1 | const Builder = @import("std").build.Builder; | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | ||
| 3 | pub fn build(b: *Builder) void { | 3 | pub fn build(b: *Builder) void { |
| 4 | const obj = b.addObject("base64", "base64.zig"); | 4 | const optimize = b.standardOptimizeOption(.{}); |
| 5 | 5 | ||
| 6 | const exe = b.addExecutable("test", null); | 6 | const obj = b.addObject(.{ |
| 7 | .name = "base64", | ||
| 8 | .root_source_file = .{ .path = "base64.zig" }, | ||
| 9 | .optimize = optimize, | ||
| 10 | .target = .{}, | ||
| 11 | }); | ||
| 12 | |||
| 13 | const exe = b.addExecutable(.{ | ||
| 14 | .name = "test", | ||
| 15 | .optimize = optimize, | ||
| 16 | }); | ||
| 7 | exe.addCSourceFile("test.c", &[_][]const u8{"-std=c99"}); | 17 | exe.addCSourceFile("test.c", &[_][]const u8{"-std=c99"}); |
| 8 | exe.addObject(obj); | 18 | exe.addObject(obj); |
| 9 | exe.linkSystemLibrary("c"); | 19 | exe.linkSystemLibrary("c"); |
test/standalone/options/build.zig+6-4| ... | @@ -2,11 +2,13 @@ const std = @import("std"); | ... | @@ -2,11 +2,13 @@ const std = @import("std"); |
| 2 | 2 | ||
| 3 | pub fn build(b: *std.build.Builder) void { | 3 | pub fn build(b: *std.build.Builder) void { |
| 4 | const target = b.standardTargetOptions(.{}); | 4 | const target = b.standardTargetOptions(.{}); |
| 5 | const mode = b.standardReleaseOptions(); | 5 | const optimize = b.standardOptimizeOption(.{}); |
| 6 | 6 | ||
| 7 | const main = b.addTest("src/main.zig"); | 7 | const main = b.addTest(.{ |
| 8 | main.setTarget(target); | 8 | .root_source_file = .{ .path = "src/main.zig" }, |
| 9 | main.setBuildMode(mode); | 9 | .target = target, |
| 10 | .optimize = optimize, | ||
| 11 | }); | ||
| 10 | 12 | ||
| 11 | const options = b.addOptions(); | 13 | const options = b.addOptions(); |
| 12 | main.addOptions("build_options", options); | 14 | main.addOptions("build_options", options); |
test/standalone/pie/build.zig+4-2| ... | @@ -1,8 +1,10 @@ | ... | @@ -1,8 +1,10 @@ |
| 1 | const Builder = @import("std").build.Builder; | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | ||
| 3 | pub fn build(b: *Builder) void { | 3 | pub fn build(b: *Builder) void { |
| 4 | const main = b.addTest("main.zig"); | 4 | const main = b.addTest(.{ |
| 5 | main.setBuildMode(b.standardReleaseOptions()); | 5 | .root_source_file = .{ .path = "main.zig" }, |
| 6 | .optimize = b.standardOptimizeOption(.{}), | ||
| 7 | }); | ||
| 6 | main.pie = true; | 8 | main.pie = true; |
| 7 | 9 | ||
| 8 | const test_step = b.step("test", "Test the program"); | 10 | const test_step = b.step("test", "Test the program"); |
test/standalone/pkg_import/build.zig+7-6| ... | @@ -1,13 +1,14 @@ | ... | @@ -1,13 +1,14 @@ |
| 1 | const Builder = @import("std").build.Builder; | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | ||
| 3 | pub fn build(b: *Builder) void { | 3 | pub fn build(b: *Builder) void { |
| 4 | const exe = b.addExecutable("test", "test.zig"); | 4 | const optimize = b.standardOptimizeOption(.{}); |
| 5 | exe.addPackagePath("my_pkg", "pkg.zig"); | ||
| 6 | 5 | ||
| 7 | // This is duplicated to test that you are allowed to call | 6 | const exe = b.addExecutable(.{ |
| 8 | // b.standardReleaseOptions() twice. | 7 | .name = "test", |
| 9 | exe.setBuildMode(b.standardReleaseOptions()); | 8 | .root_source_file = .{ .path = "test.zig" }, |
| 10 | exe.setBuildMode(b.standardReleaseOptions()); | 9 | .optimize = optimize, |
| 10 | }); | ||
| 11 | exe.addPackagePath("my_pkg", "pkg.zig"); | ||
| 11 | 12 | ||
| 12 | const run = exe.run(); | 13 | const run = exe.run(); |
| 13 | 14 |
test/standalone/shared_library/build.zig+13-4| ... | @@ -1,12 +1,21 @@ | ... | @@ -1,12 +1,21 @@ |
| 1 | const Builder = @import("std").build.Builder; | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | ||
| 3 | pub fn build(b: *Builder) void { | 3 | pub fn build(b: *Builder) void { |
| 4 | const optimize = b.standardOptimizeOption(.{}); | ||
| 4 | const target = b.standardTargetOptions(.{}); | 5 | const target = b.standardTargetOptions(.{}); |
| 5 | const lib = b.addSharedLibrary("mathtest", "mathtest.zig", b.version(1, 0, 0)); | 6 | const lib = b.addSharedLibrary(.{ |
| 6 | lib.setTarget(target); | 7 | .name = "mathtest", |
| 8 | .root_source_file = .{ .path = "mathtest.zig" }, | ||
| 9 | .version = .{ .major = 1, .minor = 0 }, | ||
| 10 | .target = target, | ||
| 11 | .optimize = optimize, | ||
| 12 | }); | ||
| 7 | 13 | ||
| 8 | const exe = b.addExecutable("test", null); | 14 | const exe = b.addExecutable(.{ |
| 9 | exe.setTarget(target); | 15 | .name = "test", |
| 16 | .target = target, | ||
| 17 | .optimize = optimize, | ||
| 18 | }); | ||
| 10 | exe.addCSourceFile("test.c", &[_][]const u8{"-std=c99"}); | 19 | exe.addCSourceFile("test.c", &[_][]const u8{"-std=c99"}); |
| 11 | exe.linkLibrary(lib); | 20 | exe.linkLibrary(lib); |
| 12 | exe.linkSystemLibrary("c"); | 21 | exe.linkSystemLibrary("c"); |
test/standalone/static_c_lib/build.zig+10-5| ... | @@ -1,15 +1,20 @@ | ... | @@ -1,15 +1,20 @@ |
| 1 | const Builder = @import("std").build.Builder; | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | ||
| 3 | pub fn build(b: *Builder) void { | 3 | pub fn build(b: *Builder) void { |
| 4 | const mode = b.standardReleaseOptions(); | 4 | const optimize = b.standardOptimizeOption(.{}); |
| 5 | 5 | ||
| 6 | const foo = b.addStaticLibrary("foo", null); | 6 | const foo = b.addStaticLibrary(.{ |
| 7 | .name = "foo", | ||
| 8 | .optimize = optimize, | ||
| 9 | .target = .{}, | ||
| 10 | }); | ||
| 7 | foo.addCSourceFile("foo.c", &[_][]const u8{}); | 11 | foo.addCSourceFile("foo.c", &[_][]const u8{}); |
| 8 | foo.setBuildMode(mode); | ||
| 9 | foo.addIncludePath("."); | 12 | foo.addIncludePath("."); |
| 10 | 13 | ||
| 11 | const test_exe = b.addTest("foo.zig"); | 14 | const test_exe = b.addTest(.{ |
| 12 | test_exe.setBuildMode(mode); | 15 | .root_source_file = .{ .path = "foo.zig" }, |
| 16 | .optimize = optimize, | ||
| 17 | }); | ||
| 13 | test_exe.linkLibrary(foo); | 18 | test_exe.linkLibrary(foo); |
| 14 | test_exe.addIncludePath("."); | 19 | test_exe.addIncludePath("."); |
| 15 | 20 |
test/standalone/test_runner_path/build.zig+4-1| ... | @@ -1,7 +1,10 @@ | ... | @@ -1,7 +1,10 @@ |
| 1 | const Builder = @import("std").build.Builder; | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | ||
| 3 | pub fn build(b: *Builder) void { | 3 | pub fn build(b: *Builder) void { |
| 4 | const test_exe = b.addTestExe("test", "test.zig"); | 4 | const test_exe = b.addTest(.{ |
| 5 | .root_source_file = .{ .path = "test.zig" }, | ||
| 6 | .kind = .test_exe, | ||
| 7 | }); | ||
| 5 | test_exe.test_runner = "test_runner.zig"; | 8 | test_exe.test_runner = "test_runner.zig"; |
| 6 | 9 | ||
| 7 | const test_run = test_exe.run(); | 10 | const test_run = test_exe.run(); |
test/standalone/use_alias/build.zig+4-2| ... | @@ -1,8 +1,10 @@ | ... | @@ -1,8 +1,10 @@ |
| 1 | const Builder = @import("std").build.Builder; | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | ||
| 3 | pub fn build(b: *Builder) void { | 3 | pub fn build(b: *Builder) void { |
| 4 | const main = b.addTest("main.zig"); | 4 | const main = b.addTest(.{ |
| 5 | main.setBuildMode(b.standardReleaseOptions()); | 5 | .root_source_file = .{ .path = "main.zig" }, |
| 6 | .optimize = b.standardOptimizeOption(.{}), | ||
| 7 | }); | ||
| 6 | main.addIncludePath("."); | 8 | main.addIncludePath("."); |
| 7 | 9 | ||
| 8 | const test_step = b.step("test", "Test it"); | 10 | const test_step = b.step("test", "Test it"); |
test/standalone/windows_spawn/build.zig+12-5| ... | @@ -1,13 +1,20 @@ | ... | @@ -1,13 +1,20 @@ |
| 1 | const Builder = @import("std").build.Builder; | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | ||
| 3 | pub fn build(b: *Builder) void { | 3 | pub fn build(b: *Builder) void { |
| 4 | const mode = b.standardReleaseOptions(); | 4 | const optimize = b.standardOptimizeOption(.{}); |
| 5 | 5 | ||
| 6 | const hello = b.addExecutable("hello", "hello.zig"); | 6 | const hello = b.addExecutable(.{ |
| 7 | hello.setBuildMode(mode); | 7 | .name = "hello", |
| 8 | .root_source_file = .{ .path = "hello.zig" }, | ||
| 9 | .optimize = optimize, | ||
| 10 | }); | ||
| 11 | |||
| 12 | const main = b.addExecutable(.{ | ||
| 13 | .name = "main", | ||
| 14 | .root_source_file = .{ .path = "main.zig" }, | ||
| 15 | .optimize = optimize, | ||
| 16 | }); | ||
| 8 | 17 | ||
| 9 | const main = b.addExecutable("main", "main.zig"); | ||
| 10 | main.setBuildMode(mode); | ||
| 11 | const run = main.run(); | 18 | const run = main.run(); |
| 12 | run.addArtifactArg(hello); | 19 | run.addArtifactArg(hello); |
| 13 | 20 |
test/tests.zig+86-70| ... | @@ -8,7 +8,7 @@ const fs = std.fs; | ... | @@ -8,7 +8,7 @@ const fs = std.fs; |
| 8 | const mem = std.mem; | 8 | const mem = std.mem; |
| 9 | const fmt = std.fmt; | 9 | const fmt = std.fmt; |
| 10 | const ArrayList = std.ArrayList; | 10 | const ArrayList = std.ArrayList; |
| 11 | const Mode = std.builtin.Mode; | 11 | const OptimizeMode = std.builtin.OptimizeMode; |
| 12 | const LibExeObjStep = build.LibExeObjStep; | 12 | const LibExeObjStep = build.LibExeObjStep; |
| 13 | const Allocator = mem.Allocator; | 13 | const Allocator = mem.Allocator; |
| 14 | const ExecError = build.Builder.ExecError; | 14 | const ExecError = build.Builder.ExecError; |
| ... | @@ -30,7 +30,7 @@ pub const CompareOutputContext = @import("src/compare_output.zig").CompareOutput | ... | @@ -30,7 +30,7 @@ pub const CompareOutputContext = @import("src/compare_output.zig").CompareOutput |
| 30 | 30 | ||
| 31 | const TestTarget = struct { | 31 | const TestTarget = struct { |
| 32 | target: CrossTarget = @as(CrossTarget, .{}), | 32 | target: CrossTarget = @as(CrossTarget, .{}), |
| 33 | mode: std.builtin.Mode = .Debug, | 33 | optimize_mode: std.builtin.OptimizeMode = .Debug, |
| 34 | link_libc: bool = false, | 34 | link_libc: bool = false, |
| 35 | single_threaded: bool = false, | 35 | single_threaded: bool = false, |
| 36 | disable_native: bool = false, | 36 | disable_native: bool = false, |
| ... | @@ -423,38 +423,38 @@ const test_targets = blk: { | ... | @@ -423,38 +423,38 @@ const test_targets = blk: { |
| 423 | 423 | ||
| 424 | // Do the release tests last because they take a long time | 424 | // Do the release tests last because they take a long time |
| 425 | .{ | 425 | .{ |
| 426 | .mode = .ReleaseFast, | 426 | .optimize_mode = .ReleaseFast, |
| 427 | }, | 427 | }, |
| 428 | .{ | 428 | .{ |
| 429 | .link_libc = true, | 429 | .link_libc = true, |
| 430 | .mode = .ReleaseFast, | 430 | .optimize_mode = .ReleaseFast, |
| 431 | }, | 431 | }, |
| 432 | .{ | 432 | .{ |
| 433 | .mode = .ReleaseFast, | 433 | .optimize_mode = .ReleaseFast, |
| 434 | .single_threaded = true, | 434 | .single_threaded = true, |
| 435 | }, | 435 | }, |
| 436 | 436 | ||
| 437 | .{ | 437 | .{ |
| 438 | .mode = .ReleaseSafe, | 438 | .optimize_mode = .ReleaseSafe, |
| 439 | }, | 439 | }, |
| 440 | .{ | 440 | .{ |
| 441 | .link_libc = true, | 441 | .link_libc = true, |
| 442 | .mode = .ReleaseSafe, | 442 | .optimize_mode = .ReleaseSafe, |
| 443 | }, | 443 | }, |
| 444 | .{ | 444 | .{ |
| 445 | .mode = .ReleaseSafe, | 445 | .optimize_mode = .ReleaseSafe, |
| 446 | .single_threaded = true, | 446 | .single_threaded = true, |
| 447 | }, | 447 | }, |
| 448 | 448 | ||
| 449 | .{ | 449 | .{ |
| 450 | .mode = .ReleaseSmall, | 450 | .optimize_mode = .ReleaseSmall, |
| 451 | }, | 451 | }, |
| 452 | .{ | 452 | .{ |
| 453 | .link_libc = true, | 453 | .link_libc = true, |
| 454 | .mode = .ReleaseSmall, | 454 | .optimize_mode = .ReleaseSmall, |
| 455 | }, | 455 | }, |
| 456 | .{ | 456 | .{ |
| 457 | .mode = .ReleaseSmall, | 457 | .optimize_mode = .ReleaseSmall, |
| 458 | .single_threaded = true, | 458 | .single_threaded = true, |
| 459 | }, | 459 | }, |
| 460 | }; | 460 | }; |
| ... | @@ -462,14 +462,14 @@ const test_targets = blk: { | ... | @@ -462,14 +462,14 @@ const test_targets = blk: { |
| 462 | 462 | ||
| 463 | const max_stdout_size = 1 * 1024 * 1024; // 1 MB | 463 | const max_stdout_size = 1 * 1024 * 1024; // 1 MB |
| 464 | 464 | ||
| 465 | pub fn addCompareOutputTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step { | 465 | pub fn addCompareOutputTests(b: *build.Builder, test_filter: ?[]const u8, optimize_modes: []const OptimizeMode) *build.Step { |
| 466 | const cases = b.allocator.create(CompareOutputContext) catch unreachable; | 466 | const cases = b.allocator.create(CompareOutputContext) catch unreachable; |
| 467 | cases.* = CompareOutputContext{ | 467 | cases.* = CompareOutputContext{ |
| 468 | .b = b, | 468 | .b = b, |
| 469 | .step = b.step("test-compare-output", "Run the compare output tests"), | 469 | .step = b.step("test-compare-output", "Run the compare output tests"), |
| 470 | .test_index = 0, | 470 | .test_index = 0, |
| 471 | .test_filter = test_filter, | 471 | .test_filter = test_filter, |
| 472 | .modes = modes, | 472 | .optimize_modes = optimize_modes, |
| 473 | }; | 473 | }; |
| 474 | 474 | ||
| 475 | compare_output.addCases(cases); | 475 | compare_output.addCases(cases); |
| ... | @@ -477,14 +477,14 @@ pub fn addCompareOutputTests(b: *build.Builder, test_filter: ?[]const u8, modes: | ... | @@ -477,14 +477,14 @@ pub fn addCompareOutputTests(b: *build.Builder, test_filter: ?[]const u8, modes: |
| 477 | return cases.step; | 477 | return cases.step; |
| 478 | } | 478 | } |
| 479 | 479 | ||
| 480 | pub fn addStackTraceTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step { | 480 | pub fn addStackTraceTests(b: *build.Builder, test_filter: ?[]const u8, optimize_modes: []const OptimizeMode) *build.Step { |
| 481 | const cases = b.allocator.create(StackTracesContext) catch unreachable; | 481 | const cases = b.allocator.create(StackTracesContext) catch unreachable; |
| 482 | cases.* = StackTracesContext{ | 482 | cases.* = StackTracesContext{ |
| 483 | .b = b, | 483 | .b = b, |
| 484 | .step = b.step("test-stack-traces", "Run the stack trace tests"), | 484 | .step = b.step("test-stack-traces", "Run the stack trace tests"), |
| 485 | .test_index = 0, | 485 | .test_index = 0, |
| 486 | .test_filter = test_filter, | 486 | .test_filter = test_filter, |
| 487 | .modes = modes, | 487 | .optimize_modes = optimize_modes, |
| 488 | }; | 488 | }; |
| 489 | 489 | ||
| 490 | stack_traces.addCases(cases); | 490 | stack_traces.addCases(cases); |
| ... | @@ -495,7 +495,7 @@ pub fn addStackTraceTests(b: *build.Builder, test_filter: ?[]const u8, modes: [] | ... | @@ -495,7 +495,7 @@ pub fn addStackTraceTests(b: *build.Builder, test_filter: ?[]const u8, modes: [] |
| 495 | pub fn addStandaloneTests( | 495 | pub fn addStandaloneTests( |
| 496 | b: *build.Builder, | 496 | b: *build.Builder, |
| 497 | test_filter: ?[]const u8, | 497 | test_filter: ?[]const u8, |
| 498 | modes: []const Mode, | 498 | optimize_modes: []const OptimizeMode, |
| 499 | skip_non_native: bool, | 499 | skip_non_native: bool, |
| 500 | enable_macos_sdk: bool, | 500 | enable_macos_sdk: bool, |
| 501 | target: std.zig.CrossTarget, | 501 | target: std.zig.CrossTarget, |
| ... | @@ -513,7 +513,7 @@ pub fn addStandaloneTests( | ... | @@ -513,7 +513,7 @@ pub fn addStandaloneTests( |
| 513 | .step = b.step("test-standalone", "Run the standalone tests"), | 513 | .step = b.step("test-standalone", "Run the standalone tests"), |
| 514 | .test_index = 0, | 514 | .test_index = 0, |
| 515 | .test_filter = test_filter, | 515 | .test_filter = test_filter, |
| 516 | .modes = modes, | 516 | .optimize_modes = optimize_modes, |
| 517 | .skip_non_native = skip_non_native, | 517 | .skip_non_native = skip_non_native, |
| 518 | .enable_macos_sdk = enable_macos_sdk, | 518 | .enable_macos_sdk = enable_macos_sdk, |
| 519 | .target = target, | 519 | .target = target, |
| ... | @@ -534,7 +534,7 @@ pub fn addStandaloneTests( | ... | @@ -534,7 +534,7 @@ pub fn addStandaloneTests( |
| 534 | pub fn addLinkTests( | 534 | pub fn addLinkTests( |
| 535 | b: *build.Builder, | 535 | b: *build.Builder, |
| 536 | test_filter: ?[]const u8, | 536 | test_filter: ?[]const u8, |
| 537 | modes: []const Mode, | 537 | optimize_modes: []const OptimizeMode, |
| 538 | enable_macos_sdk: bool, | 538 | enable_macos_sdk: bool, |
| 539 | omit_stage2: bool, | 539 | omit_stage2: bool, |
| 540 | enable_symlinks_windows: bool, | 540 | enable_symlinks_windows: bool, |
| ... | @@ -545,7 +545,7 @@ pub fn addLinkTests( | ... | @@ -545,7 +545,7 @@ pub fn addLinkTests( |
| 545 | .step = b.step("test-link", "Run the linker tests"), | 545 | .step = b.step("test-link", "Run the linker tests"), |
| 546 | .test_index = 0, | 546 | .test_index = 0, |
| 547 | .test_filter = test_filter, | 547 | .test_filter = test_filter, |
| 548 | .modes = modes, | 548 | .optimize_modes = optimize_modes, |
| 549 | .skip_non_native = true, | 549 | .skip_non_native = true, |
| 550 | .enable_macos_sdk = enable_macos_sdk, | 550 | .enable_macos_sdk = enable_macos_sdk, |
| 551 | .target = .{}, | 551 | .target = .{}, |
| ... | @@ -556,12 +556,17 @@ pub fn addLinkTests( | ... | @@ -556,12 +556,17 @@ pub fn addLinkTests( |
| 556 | return cases.step; | 556 | return cases.step; |
| 557 | } | 557 | } |
| 558 | 558 | ||
| 559 | pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step { | 559 | pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, optimize_modes: []const OptimizeMode) *build.Step { |
| 560 | _ = test_filter; | 560 | _ = test_filter; |
| 561 | _ = modes; | 561 | _ = optimize_modes; |
| 562 | const step = b.step("test-cli", "Test the command line interface"); | 562 | const step = b.step("test-cli", "Test the command line interface"); |
| 563 | 563 | ||
| 564 | const exe = b.addExecutable("test-cli", "test/cli.zig"); | 564 | const exe = b.addExecutable(.{ |
| 565 | .name = "test-cli", | ||
| 566 | .root_source_file = .{ .path = "test/cli.zig" }, | ||
| 567 | .target = .{}, | ||
| 568 | .optimize = .Debug, | ||
| 569 | }); | ||
| 565 | const run_cmd = exe.run(); | 570 | const run_cmd = exe.run(); |
| 566 | run_cmd.addArgs(&[_][]const u8{ | 571 | run_cmd.addArgs(&[_][]const u8{ |
| 567 | fs.realpathAlloc(b.allocator, b.zig_exe) catch unreachable, | 572 | fs.realpathAlloc(b.allocator, b.zig_exe) catch unreachable, |
| ... | @@ -572,14 +577,14 @@ pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const M | ... | @@ -572,14 +577,14 @@ pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const M |
| 572 | return step; | 577 | return step; |
| 573 | } | 578 | } |
| 574 | 579 | ||
| 575 | pub fn addAssembleAndLinkTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step { | 580 | pub fn addAssembleAndLinkTests(b: *build.Builder, test_filter: ?[]const u8, optimize_modes: []const OptimizeMode) *build.Step { |
| 576 | const cases = b.allocator.create(CompareOutputContext) catch unreachable; | 581 | const cases = b.allocator.create(CompareOutputContext) catch unreachable; |
| 577 | cases.* = CompareOutputContext{ | 582 | cases.* = CompareOutputContext{ |
| 578 | .b = b, | 583 | .b = b, |
| 579 | .step = b.step("test-asm-link", "Run the assemble and link tests"), | 584 | .step = b.step("test-asm-link", "Run the assemble and link tests"), |
| 580 | .test_index = 0, | 585 | .test_index = 0, |
| 581 | .test_filter = test_filter, | 586 | .test_filter = test_filter, |
| 582 | .modes = modes, | 587 | .optimize_modes = optimize_modes, |
| 583 | }; | 588 | }; |
| 584 | 589 | ||
| 585 | assemble_and_link.addCases(cases); | 590 | assemble_and_link.addCases(cases); |
| ... | @@ -640,7 +645,7 @@ pub fn addPkgTests( | ... | @@ -640,7 +645,7 @@ pub fn addPkgTests( |
| 640 | root_src: []const u8, | 645 | root_src: []const u8, |
| 641 | name: []const u8, | 646 | name: []const u8, |
| 642 | desc: []const u8, | 647 | desc: []const u8, |
| 643 | modes: []const Mode, | 648 | optimize_modes: []const OptimizeMode, |
| 644 | skip_single_threaded: bool, | 649 | skip_single_threaded: bool, |
| 645 | skip_non_native: bool, | 650 | skip_non_native: bool, |
| 646 | skip_libc: bool, | 651 | skip_libc: bool, |
| ... | @@ -677,8 +682,8 @@ pub fn addPkgTests( | ... | @@ -677,8 +682,8 @@ pub fn addPkgTests( |
| 677 | else => if (skip_stage2) continue, | 682 | else => if (skip_stage2) continue, |
| 678 | }; | 683 | }; |
| 679 | 684 | ||
| 680 | const want_this_mode = for (modes) |m| { | 685 | const want_this_mode = for (optimize_modes) |m| { |
| 681 | if (m == test_target.mode) break true; | 686 | if (m == test_target.optimize_mode) break true; |
| 682 | } else false; | 687 | } else false; |
| 683 | if (!want_this_mode) continue; | 688 | if (!want_this_mode) continue; |
| 684 | 689 | ||
| ... | @@ -691,21 +696,23 @@ pub fn addPkgTests( | ... | @@ -691,21 +696,23 @@ pub fn addPkgTests( |
| 691 | 696 | ||
| 692 | const triple_prefix = test_target.target.zigTriple(b.allocator) catch unreachable; | 697 | const triple_prefix = test_target.target.zigTriple(b.allocator) catch unreachable; |
| 693 | 698 | ||
| 694 | const these_tests = b.addTest(root_src); | 699 | const these_tests = b.addTest(.{ |
| 700 | .root_source_file = .{ .path = root_src }, | ||
| 701 | .optimize = test_target.optimize_mode, | ||
| 702 | .target = test_target.target, | ||
| 703 | }); | ||
| 695 | const single_threaded_txt = if (test_target.single_threaded) "single" else "multi"; | 704 | const single_threaded_txt = if (test_target.single_threaded) "single" else "multi"; |
| 696 | const backend_txt = if (test_target.backend) |backend| @tagName(backend) else "default"; | 705 | const backend_txt = if (test_target.backend) |backend| @tagName(backend) else "default"; |
| 697 | these_tests.setNamePrefix(b.fmt("{s}-{s}-{s}-{s}-{s}-{s} ", .{ | 706 | these_tests.setNamePrefix(b.fmt("{s}-{s}-{s}-{s}-{s}-{s} ", .{ |
| 698 | name, | 707 | name, |
| 699 | triple_prefix, | 708 | triple_prefix, |
| 700 | @tagName(test_target.mode), | 709 | @tagName(test_target.optimize_mode), |
| 701 | libc_prefix, | 710 | libc_prefix, |
| 702 | single_threaded_txt, | 711 | single_threaded_txt, |
| 703 | backend_txt, | 712 | backend_txt, |
| 704 | })); | 713 | })); |
| 705 | these_tests.single_threaded = test_target.single_threaded; | 714 | these_tests.single_threaded = test_target.single_threaded; |
| 706 | these_tests.setFilter(test_filter); | 715 | these_tests.setFilter(test_filter); |
| 707 | these_tests.setBuildMode(test_target.mode); | ||
| 708 | these_tests.setTarget(test_target.target); | ||
| 709 | if (test_target.link_libc) { | 716 | if (test_target.link_libc) { |
| 710 | these_tests.linkSystemLibrary("c"); | 717 | these_tests.linkSystemLibrary("c"); |
| 711 | } | 718 | } |
| ... | @@ -739,9 +746,9 @@ pub const StackTracesContext = struct { | ... | @@ -739,9 +746,9 @@ pub const StackTracesContext = struct { |
| 739 | step: *build.Step, | 746 | step: *build.Step, |
| 740 | test_index: usize, | 747 | test_index: usize, |
| 741 | test_filter: ?[]const u8, | 748 | test_filter: ?[]const u8, |
| 742 | modes: []const Mode, | 749 | optimize_modes: []const OptimizeMode, |
| 743 | 750 | ||
| 744 | const Expect = [@typeInfo(Mode).Enum.fields.len][]const u8; | 751 | const Expect = [@typeInfo(OptimizeMode).Enum.fields.len][]const u8; |
| 745 | 752 | ||
| 746 | pub fn addCase(self: *StackTracesContext, config: anytype) void { | 753 | pub fn addCase(self: *StackTracesContext, config: anytype) void { |
| 747 | if (@hasField(@TypeOf(config), "exclude")) { | 754 | if (@hasField(@TypeOf(config), "exclude")) { |
| ... | @@ -755,26 +762,26 @@ pub const StackTracesContext = struct { | ... | @@ -755,26 +762,26 @@ pub const StackTracesContext = struct { |
| 755 | const exclude_os: []const std.Target.Os.Tag = &config.exclude_os; | 762 | const exclude_os: []const std.Target.Os.Tag = &config.exclude_os; |
| 756 | for (exclude_os) |os| if (os == builtin.os.tag) return; | 763 | for (exclude_os) |os| if (os == builtin.os.tag) return; |
| 757 | } | 764 | } |
| 758 | for (self.modes) |mode| { | 765 | for (self.optimize_modes) |optimize_mode| { |
| 759 | switch (mode) { | 766 | switch (optimize_mode) { |
| 760 | .Debug => { | 767 | .Debug => { |
| 761 | if (@hasField(@TypeOf(config), "Debug")) { | 768 | if (@hasField(@TypeOf(config), "Debug")) { |
| 762 | self.addExpect(config.name, config.source, mode, config.Debug); | 769 | self.addExpect(config.name, config.source, optimize_mode, config.Debug); |
| 763 | } | 770 | } |
| 764 | }, | 771 | }, |
| 765 | .ReleaseSafe => { | 772 | .ReleaseSafe => { |
| 766 | if (@hasField(@TypeOf(config), "ReleaseSafe")) { | 773 | if (@hasField(@TypeOf(config), "ReleaseSafe")) { |
| 767 | self.addExpect(config.name, config.source, mode, config.ReleaseSafe); | 774 | self.addExpect(config.name, config.source, optimize_mode, config.ReleaseSafe); |
| 768 | } | 775 | } |
| 769 | }, | 776 | }, |
| 770 | .ReleaseFast => { | 777 | .ReleaseFast => { |
| 771 | if (@hasField(@TypeOf(config), "ReleaseFast")) { | 778 | if (@hasField(@TypeOf(config), "ReleaseFast")) { |
| 772 | self.addExpect(config.name, config.source, mode, config.ReleaseFast); | 779 | self.addExpect(config.name, config.source, optimize_mode, config.ReleaseFast); |
| 773 | } | 780 | } |
| 774 | }, | 781 | }, |
| 775 | .ReleaseSmall => { | 782 | .ReleaseSmall => { |
| 776 | if (@hasField(@TypeOf(config), "ReleaseSmall")) { | 783 | if (@hasField(@TypeOf(config), "ReleaseSmall")) { |
| 777 | self.addExpect(config.name, config.source, mode, config.ReleaseSmall); | 784 | self.addExpect(config.name, config.source, optimize_mode, config.ReleaseSmall); |
| 778 | } | 785 | } |
| 779 | }, | 786 | }, |
| 780 | } | 787 | } |
| ... | @@ -785,7 +792,7 @@ pub const StackTracesContext = struct { | ... | @@ -785,7 +792,7 @@ pub const StackTracesContext = struct { |
| 785 | self: *StackTracesContext, | 792 | self: *StackTracesContext, |
| 786 | name: []const u8, | 793 | name: []const u8, |
| 787 | source: []const u8, | 794 | source: []const u8, |
| 788 | mode: Mode, | 795 | optimize_mode: OptimizeMode, |
| 789 | mode_config: anytype, | 796 | mode_config: anytype, |
| 790 | ) void { | 797 | ) void { |
| 791 | if (@hasField(@TypeOf(mode_config), "exclude")) { | 798 | if (@hasField(@TypeOf(mode_config), "exclude")) { |
| ... | @@ -803,7 +810,7 @@ pub const StackTracesContext = struct { | ... | @@ -803,7 +810,7 @@ pub const StackTracesContext = struct { |
| 803 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "{s} {s} ({s})", .{ | 810 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "{s} {s} ({s})", .{ |
| 804 | "stack-trace", | 811 | "stack-trace", |
| 805 | name, | 812 | name, |
| 806 | @tagName(mode), | 813 | @tagName(optimize_mode), |
| 807 | }) catch unreachable; | 814 | }) catch unreachable; |
| 808 | if (self.test_filter) |filter| { | 815 | if (self.test_filter) |filter| { |
| 809 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; | 816 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; |
| ... | @@ -812,14 +819,18 @@ pub const StackTracesContext = struct { | ... | @@ -812,14 +819,18 @@ pub const StackTracesContext = struct { |
| 812 | const b = self.b; | 819 | const b = self.b; |
| 813 | const src_basename = "source.zig"; | 820 | const src_basename = "source.zig"; |
| 814 | const write_src = b.addWriteFile(src_basename, source); | 821 | const write_src = b.addWriteFile(src_basename, source); |
| 815 | const exe = b.addExecutableSource("test", write_src.getFileSource(src_basename).?); | 822 | const exe = b.addExecutable(.{ |
| 816 | exe.setBuildMode(mode); | 823 | .name = "test", |
| 824 | .root_source_file = write_src.getFileSource(src_basename).?, | ||
| 825 | .optimize = optimize_mode, | ||
| 826 | .target = .{}, | ||
| 827 | }); | ||
| 817 | 828 | ||
| 818 | const run_and_compare = RunAndCompareStep.create( | 829 | const run_and_compare = RunAndCompareStep.create( |
| 819 | self, | 830 | self, |
| 820 | exe, | 831 | exe, |
| 821 | annotated_case_name, | 832 | annotated_case_name, |
| 822 | mode, | 833 | optimize_mode, |
| 823 | mode_config.expect, | 834 | mode_config.expect, |
| 824 | ); | 835 | ); |
| 825 | 836 | ||
| ... | @@ -833,7 +844,7 @@ pub const StackTracesContext = struct { | ... | @@ -833,7 +844,7 @@ pub const StackTracesContext = struct { |
| 833 | context: *StackTracesContext, | 844 | context: *StackTracesContext, |
| 834 | exe: *LibExeObjStep, | 845 | exe: *LibExeObjStep, |
| 835 | name: []const u8, | 846 | name: []const u8, |
| 836 | mode: Mode, | 847 | optimize_mode: OptimizeMode, |
| 837 | expect_output: []const u8, | 848 | expect_output: []const u8, |
| 838 | test_index: usize, | 849 | test_index: usize, |
| 839 | 850 | ||
| ... | @@ -841,7 +852,7 @@ pub const StackTracesContext = struct { | ... | @@ -841,7 +852,7 @@ pub const StackTracesContext = struct { |
| 841 | context: *StackTracesContext, | 852 | context: *StackTracesContext, |
| 842 | exe: *LibExeObjStep, | 853 | exe: *LibExeObjStep, |
| 843 | name: []const u8, | 854 | name: []const u8, |
| 844 | mode: Mode, | 855 | optimize_mode: OptimizeMode, |
| 845 | expect_output: []const u8, | 856 | expect_output: []const u8, |
| 846 | ) *RunAndCompareStep { | 857 | ) *RunAndCompareStep { |
| 847 | const allocator = context.b.allocator; | 858 | const allocator = context.b.allocator; |
| ... | @@ -851,7 +862,7 @@ pub const StackTracesContext = struct { | ... | @@ -851,7 +862,7 @@ pub const StackTracesContext = struct { |
| 851 | .context = context, | 862 | .context = context, |
| 852 | .exe = exe, | 863 | .exe = exe, |
| 853 | .name = name, | 864 | .name = name, |
| 854 | .mode = mode, | 865 | .optimize_mode = optimize_mode, |
| 855 | .expect_output = expect_output, | 866 | .expect_output = expect_output, |
| 856 | .test_index = context.test_index, | 867 | .test_index = context.test_index, |
| 857 | }; | 868 | }; |
| ... | @@ -932,7 +943,7 @@ pub const StackTracesContext = struct { | ... | @@ -932,7 +943,7 @@ pub const StackTracesContext = struct { |
| 932 | // process result | 943 | // process result |
| 933 | // - keep only basename of source file path | 944 | // - keep only basename of source file path |
| 934 | // - replace address with symbolic string | 945 | // - replace address with symbolic string |
| 935 | // - replace function name with symbolic string when mode != .Debug | 946 | // - replace function name with symbolic string when optimize_mode != .Debug |
| 936 | // - skip empty lines | 947 | // - skip empty lines |
| 937 | const got: []const u8 = got_result: { | 948 | const got: []const u8 = got_result: { |
| 938 | var buf = ArrayList(u8).init(b.allocator); | 949 | var buf = ArrayList(u8).init(b.allocator); |
| ... | @@ -968,7 +979,7 @@ pub const StackTracesContext = struct { | ... | @@ -968,7 +979,7 @@ pub const StackTracesContext = struct { |
| 968 | // emit substituted line | 979 | // emit substituted line |
| 969 | try buf.appendSlice(line[pos + 1 .. marks[2] + delims[2].len]); | 980 | try buf.appendSlice(line[pos + 1 .. marks[2] + delims[2].len]); |
| 970 | try buf.appendSlice(" [address]"); | 981 | try buf.appendSlice(" [address]"); |
| 971 | if (self.mode == .Debug) { | 982 | if (self.optimize_mode == .Debug) { |
| 972 | // On certain platforms (windows) or possibly depending on how we choose to link main | 983 | // On certain platforms (windows) or possibly depending on how we choose to link main |
| 973 | // the object file extension may be present so we simply strip any extension. | 984 | // the object file extension may be present so we simply strip any extension. |
| 974 | if (mem.indexOfScalar(u8, line[marks[4]..marks[5]], '.')) |idot| { | 985 | if (mem.indexOfScalar(u8, line[marks[4]..marks[5]], '.')) |idot| { |
| ... | @@ -1007,7 +1018,7 @@ pub const StandaloneContext = struct { | ... | @@ -1007,7 +1018,7 @@ pub const StandaloneContext = struct { |
| 1007 | step: *build.Step, | 1018 | step: *build.Step, |
| 1008 | test_index: usize, | 1019 | test_index: usize, |
| 1009 | test_filter: ?[]const u8, | 1020 | test_filter: ?[]const u8, |
| 1010 | modes: []const Mode, | 1021 | optimize_modes: []const OptimizeMode, |
| 1011 | skip_non_native: bool, | 1022 | skip_non_native: bool, |
| 1012 | enable_macos_sdk: bool, | 1023 | enable_macos_sdk: bool, |
| 1013 | target: std.zig.CrossTarget, | 1024 | target: std.zig.CrossTarget, |
| ... | @@ -1087,13 +1098,13 @@ pub const StandaloneContext = struct { | ... | @@ -1087,13 +1098,13 @@ pub const StandaloneContext = struct { |
| 1087 | } | 1098 | } |
| 1088 | } | 1099 | } |
| 1089 | 1100 | ||
| 1090 | const modes = if (features.build_modes) self.modes else &[1]Mode{.Debug}; | 1101 | const optimize_modes = if (features.build_modes) self.optimize_modes else &[1]OptimizeMode{.Debug}; |
| 1091 | for (modes) |mode| { | 1102 | for (optimize_modes) |optimize_mode| { |
| 1092 | const arg = switch (mode) { | 1103 | const arg = switch (optimize_mode) { |
| 1093 | .Debug => "", | 1104 | .Debug => "", |
| 1094 | .ReleaseFast => "-Drelease-fast", | 1105 | .ReleaseFast => "-Doptimize=ReleaseFast", |
| 1095 | .ReleaseSafe => "-Drelease-safe", | 1106 | .ReleaseSafe => "-Doptimize=ReleaseSafe", |
| 1096 | .ReleaseSmall => "-Drelease-small", | 1107 | .ReleaseSmall => "-Doptimize=ReleaseSmall", |
| 1097 | }; | 1108 | }; |
| 1098 | const zig_args_base_len = zig_args.items.len; | 1109 | const zig_args_base_len = zig_args.items.len; |
| 1099 | if (arg.len > 0) | 1110 | if (arg.len > 0) |
| ... | @@ -1101,7 +1112,7 @@ pub const StandaloneContext = struct { | ... | @@ -1101,7 +1112,7 @@ pub const StandaloneContext = struct { |
| 1101 | defer zig_args.resize(zig_args_base_len) catch unreachable; | 1112 | defer zig_args.resize(zig_args_base_len) catch unreachable; |
| 1102 | 1113 | ||
| 1103 | const run_cmd = b.addSystemCommand(zig_args.items); | 1114 | const run_cmd = b.addSystemCommand(zig_args.items); |
| 1104 | const log_step = b.addLog("PASS {s} ({s})", .{ annotated_case_name, @tagName(mode) }); | 1115 | const log_step = b.addLog("PASS {s} ({s})", .{ annotated_case_name, @tagName(optimize_mode) }); |
| 1105 | log_step.step.dependOn(&run_cmd.step); | 1116 | log_step.step.dependOn(&run_cmd.step); |
| 1106 | 1117 | ||
| 1107 | self.step.dependOn(&log_step.step); | 1118 | self.step.dependOn(&log_step.step); |
| ... | @@ -1111,17 +1122,21 @@ pub const StandaloneContext = struct { | ... | @@ -1111,17 +1122,21 @@ pub const StandaloneContext = struct { |
| 1111 | pub fn addAllArgs(self: *StandaloneContext, root_src: []const u8, link_libc: bool) void { | 1122 | pub fn addAllArgs(self: *StandaloneContext, root_src: []const u8, link_libc: bool) void { |
| 1112 | const b = self.b; | 1123 | const b = self.b; |
| 1113 | 1124 | ||
| 1114 | for (self.modes) |mode| { | 1125 | for (self.optimize_modes) |optimize| { |
| 1115 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "build {s} ({s})", .{ | 1126 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "build {s} ({s})", .{ |
| 1116 | root_src, | 1127 | root_src, |
| 1117 | @tagName(mode), | 1128 | @tagName(optimize), |
| 1118 | }) catch unreachable; | 1129 | }) catch unreachable; |
| 1119 | if (self.test_filter) |filter| { | 1130 | if (self.test_filter) |filter| { |
| 1120 | if (mem.indexOf(u8, annotated_case_name, filter) == null) continue; | 1131 | if (mem.indexOf(u8, annotated_case_name, filter) == null) continue; |
| 1121 | } | 1132 | } |
| 1122 | 1133 | ||
| 1123 | const exe = b.addExecutable("test", root_src); | 1134 | const exe = b.addExecutable(.{ |
| 1124 | exe.setBuildMode(mode); | 1135 | .name = "test", |
| 1136 | .root_source_file = .{ .path = root_src }, | ||
| 1137 | .optimize = optimize, | ||
| 1138 | .target = .{}, | ||
| 1139 | }); | ||
| 1125 | if (link_libc) { | 1140 | if (link_libc) { |
| 1126 | exe.linkSystemLibrary("c"); | 1141 | exe.linkSystemLibrary("c"); |
| 1127 | } | 1142 | } |
| ... | @@ -1247,8 +1262,8 @@ pub const GenHContext = struct { | ... | @@ -1247,8 +1262,8 @@ pub const GenHContext = struct { |
| 1247 | pub fn addCase(self: *GenHContext, case: *const TestCase) void { | 1262 | pub fn addCase(self: *GenHContext, case: *const TestCase) void { |
| 1248 | const b = self.b; | 1263 | const b = self.b; |
| 1249 | 1264 | ||
| 1250 | const mode = std.builtin.Mode.Debug; | 1265 | const optimize_mode = std.builtin.OptimizeMode.Debug; |
| 1251 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "gen-h {s} ({s})", .{ case.name, @tagName(mode) }) catch unreachable; | 1266 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "gen-h {s} ({s})", .{ case.name, @tagName(optimize_mode) }) catch unreachable; |
| 1252 | if (self.test_filter) |filter| { | 1267 | if (self.test_filter) |filter| { |
| 1253 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; | 1268 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; |
| 1254 | } | 1269 | } |
| ... | @@ -1259,7 +1274,7 @@ pub const GenHContext = struct { | ... | @@ -1259,7 +1274,7 @@ pub const GenHContext = struct { |
| 1259 | } | 1274 | } |
| 1260 | 1275 | ||
| 1261 | const obj = b.addObjectFromWriteFileStep("test", write_src, case.sources.items[0].filename); | 1276 | const obj = b.addObjectFromWriteFileStep("test", write_src, case.sources.items[0].filename); |
| 1262 | obj.setBuildMode(mode); | 1277 | obj.setBuildMode(optimize_mode); |
| 1263 | 1278 | ||
| 1264 | const cmp_h = GenHCmpOutputStep.create(self, obj, annotated_case_name, case); | 1279 | const cmp_h = GenHCmpOutputStep.create(self, obj, annotated_case_name, case); |
| 1265 | 1280 | ||
| ... | @@ -1336,14 +1351,16 @@ const c_abi_targets = [_]CrossTarget{ | ... | @@ -1336,14 +1351,16 @@ const c_abi_targets = [_]CrossTarget{ |
| 1336 | pub fn addCAbiTests(b: *build.Builder, skip_non_native: bool, skip_release: bool) *build.Step { | 1351 | pub fn addCAbiTests(b: *build.Builder, skip_non_native: bool, skip_release: bool) *build.Step { |
| 1337 | const step = b.step("test-c-abi", "Run the C ABI tests"); | 1352 | const step = b.step("test-c-abi", "Run the C ABI tests"); |
| 1338 | 1353 | ||
| 1339 | const modes: [2]Mode = .{ .Debug, .ReleaseFast }; | 1354 | const optimize_modes: [2]OptimizeMode = .{ .Debug, .ReleaseFast }; |
| 1340 | 1355 | ||
| 1341 | for (modes[0 .. @as(u8, 1) + @boolToInt(!skip_release)]) |mode| for (c_abi_targets) |c_abi_target| { | 1356 | for (optimize_modes[0 .. @as(u8, 1) + @boolToInt(!skip_release)]) |optimize_mode| for (c_abi_targets) |c_abi_target| { |
| 1342 | if (skip_non_native and !c_abi_target.isNative()) | 1357 | if (skip_non_native and !c_abi_target.isNative()) |
| 1343 | continue; | 1358 | continue; |
| 1344 | 1359 | ||
| 1345 | const test_step = b.addTest("test/c_abi/main.zig"); | 1360 | const test_step = b.addTest(.{ |
| 1346 | test_step.setTarget(c_abi_target); | 1361 | .root_source_file = .{ .path = "test/c_abi/main.zig" }, |
| 1362 | .optimize = optimize_mode, | ||
| 1363 | }); | ||
| 1347 | if (c_abi_target.abi != null and c_abi_target.abi.?.isMusl()) { | 1364 | if (c_abi_target.abi != null and c_abi_target.abi.?.isMusl()) { |
| 1348 | // TODO NativeTargetInfo insists on dynamically linking musl | 1365 | // TODO NativeTargetInfo insists on dynamically linking musl |
| 1349 | // for some reason? | 1366 | // for some reason? |
| ... | @@ -1351,7 +1368,6 @@ pub fn addCAbiTests(b: *build.Builder, skip_non_native: bool, skip_release: bool | ... | @@ -1351,7 +1368,6 @@ pub fn addCAbiTests(b: *build.Builder, skip_non_native: bool, skip_release: bool |
| 1351 | } | 1368 | } |
| 1352 | test_step.linkLibC(); | 1369 | test_step.linkLibC(); |
| 1353 | test_step.addCSourceFile("test/c_abi/cfuncs.c", &.{"-std=c99"}); | 1370 | test_step.addCSourceFile("test/c_abi/cfuncs.c", &.{"-std=c99"}); |
| 1354 | test_step.setBuildMode(mode); | ||
| 1355 | 1371 | ||
| 1356 | if (c_abi_target.isWindows() and (c_abi_target.getCpuArch() == .x86 or builtin.target.os.tag == .linux)) { | 1372 | if (c_abi_target.isWindows() and (c_abi_target.getCpuArch() == .x86 or builtin.target.os.tag == .linux)) { |
| 1357 | // LTO currently incorrectly strips stdcall name-mangled functions | 1373 | // LTO currently incorrectly strips stdcall name-mangled functions |
| ... | @@ -1363,7 +1379,7 @@ pub fn addCAbiTests(b: *build.Builder, skip_non_native: bool, skip_release: bool | ... | @@ -1363,7 +1379,7 @@ pub fn addCAbiTests(b: *build.Builder, skip_non_native: bool, skip_release: bool |
| 1363 | test_step.setNamePrefix(b.fmt("{s}-{s}-{s} ", .{ | 1379 | test_step.setNamePrefix(b.fmt("{s}-{s}-{s} ", .{ |
| 1364 | "test-c-abi", | 1380 | "test-c-abi", |
| 1365 | triple_prefix, | 1381 | triple_prefix, |
| 1366 | @tagName(mode), | 1382 | @tagName(optimize_mode), |
| 1367 | })); | 1383 | })); |
| 1368 | 1384 | ||
| 1369 | step.dependOn(&test_step.step); | 1385 | step.dependOn(&test_step.step); |