authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-30 21:39:43-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-31 15:09:35-07:00
log73cf7b64291ed8b5dcb4cb52df103be08f15a347
treebc5d933ec1440850e910b71dfa9166c87fc53d62
parent71ff60f1265da83e619b1b6b2488ecb448fdfd36

update build.zig API usage


80 files changed, 906 insertions(+), 495 deletions(-)

build.zig+42-30
......@@ -23,7 +23,7 @@ pub fn build(b: *Builder) !void {
2323 }
2424 break :t b.standardTargetOptions(.{ .default_target = default_target });
2525 };
26 const mode: std.builtin.Mode = if (release) switch (target.getCpuArch()) {
26 const optimize: std.builtin.OptimizeMode = if (release) switch (target.getCpuArch()) {
2727 .wasm32 => .ReleaseSmall,
2828 else => .ReleaseFast,
2929 } else .Debug;
......@@ -33,7 +33,12 @@ pub fn build(b: *Builder) !void {
3333
3434 const test_step = b.step("test", "Run all the tests");
3535
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 });
3742 docgen_exe.single_threaded = single_threaded;
3843
3944 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 {
5358 const docs_step = b.step("docs", "Build documentation");
5459 docs_step.dependOn(&docgen_cmd.step);
5560
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 });
5765 test_cases.main_pkg_path = ".";
5866 test_cases.stack_size = stack_size;
59 test_cases.setBuildMode(mode);
6067 test_cases.single_threaded = single_threaded;
6168
6269 const fmt_build_zig = b.addFmt(&[_][]const u8{"build.zig"});
......@@ -149,17 +156,15 @@ pub fn build(b: *Builder) !void {
149156
150157 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: {
151158 if (strip == true) break :blk @as(u32, 0);
152 if (mode != .Debug) break :blk 0;
159 if (optimize != .Debug) break :blk 0;
153160 break :blk 4;
154161 };
155162
156 const exe = addCompilerStep(b);
163 const exe = addCompilerStep(b, optimize, target);
157164 exe.strip = strip;
158165 exe.sanitize_thread = sanitize_thread;
159166 exe.build_id = b.option(bool, "build-id", "Include a build id note") orelse false;
160167 exe.install();
161 exe.setBuildMode(mode);
162 exe.setTarget(target);
163168
164169 const compile_step = b.step("compile", "Build the self-hosted compiler");
165170 compile_step.dependOn(&exe.step);
......@@ -195,7 +200,7 @@ pub fn build(b: *Builder) !void {
195200 test_cases.linkLibC();
196201 }
197202
198 const is_debug = mode == .Debug;
203 const is_debug = optimize == .Debug;
199204 const enable_logging = b.option(bool, "log", "Enable debug logging with --debug-log") orelse is_debug;
200205 const enable_link_snapshots = b.option(bool, "link-snapshot", "Whether to enable linker state snapshots") orelse false;
201206
......@@ -360,25 +365,25 @@ pub fn build(b: *Builder) !void {
360365 test_step.dependOn(test_cases_step);
361366 }
362367
363 var chosen_modes: [4]builtin.Mode = undefined;
368 var chosen_opt_modes_buf: [4]builtin.Mode = undefined;
364369 var chosen_mode_index: usize = 0;
365370 if (!skip_debug) {
366 chosen_modes[chosen_mode_index] = builtin.Mode.Debug;
371 chosen_opt_modes_buf[chosen_mode_index] = builtin.Mode.Debug;
367372 chosen_mode_index += 1;
368373 }
369374 if (!skip_release_safe) {
370 chosen_modes[chosen_mode_index] = builtin.Mode.ReleaseSafe;
375 chosen_opt_modes_buf[chosen_mode_index] = builtin.Mode.ReleaseSafe;
371376 chosen_mode_index += 1;
372377 }
373378 if (!skip_release_fast) {
374 chosen_modes[chosen_mode_index] = builtin.Mode.ReleaseFast;
379 chosen_opt_modes_buf[chosen_mode_index] = builtin.Mode.ReleaseFast;
375380 chosen_mode_index += 1;
376381 }
377382 if (!skip_release_small) {
378 chosen_modes[chosen_mode_index] = builtin.Mode.ReleaseSmall;
383 chosen_opt_modes_buf[chosen_mode_index] = builtin.Mode.ReleaseSmall;
379384 chosen_mode_index += 1;
380385 }
381 const modes = chosen_modes[0..chosen_mode_index];
386 const optimization_modes = chosen_opt_modes_buf[0..chosen_mode_index];
382387
383388 // run stage1 `zig fmt` on this build.zig file just to make sure it works
384389 test_step.dependOn(&fmt_build_zig.step);
......@@ -391,7 +396,7 @@ pub fn build(b: *Builder) !void {
391396 "test/behavior.zig",
392397 "behavior",
393398 "Run the behavior tests",
394 modes,
399 optimization_modes,
395400 skip_single_threaded,
396401 skip_non_native,
397402 skip_libc,
......@@ -405,7 +410,7 @@ pub fn build(b: *Builder) !void {
405410 "lib/compiler_rt.zig",
406411 "compiler-rt",
407412 "Run the compiler_rt tests",
408 modes,
413 optimization_modes,
409414 true, // skip_single_threaded
410415 skip_non_native,
411416 true, // skip_libc
......@@ -419,7 +424,7 @@ pub fn build(b: *Builder) !void {
419424 "lib/c.zig",
420425 "universal-libc",
421426 "Run the universal libc tests",
422 modes,
427 optimization_modes,
423428 true, // skip_single_threaded
424429 skip_non_native,
425430 true, // skip_libc
......@@ -427,11 +432,11 @@ pub fn build(b: *Builder) !void {
427432 skip_stage2_tests or true, // TODO get these all passing
428433 ));
429434
430 test_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes));
435 test_step.dependOn(tests.addCompareOutputTests(b, test_filter, optimization_modes));
431436 test_step.dependOn(tests.addStandaloneTests(
432437 b,
433438 test_filter,
434 modes,
439 optimization_modes,
435440 skip_non_native,
436441 enable_macos_sdk,
437442 target,
......@@ -444,10 +449,10 @@ pub fn build(b: *Builder) !void {
444449 enable_symlinks_windows,
445450 ));
446451 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));
448 test_step.dependOn(tests.addStackTraceTests(b, test_filter, modes));
449 test_step.dependOn(tests.addCliTests(b, test_filter, modes));
450 test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter, modes));
452 test_step.dependOn(tests.addLinkTests(b, test_filter, optimization_modes, enable_macos_sdk, skip_stage2_tests, enable_symlinks_windows));
453 test_step.dependOn(tests.addStackTraceTests(b, test_filter, optimization_modes));
454 test_step.dependOn(tests.addCliTests(b, test_filter, optimization_modes));
455 test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter, optimization_modes));
451456 test_step.dependOn(tests.addTranslateCTests(b, test_filter));
452457 if (!skip_run_translated_c) {
453458 test_step.dependOn(tests.addRunTranslatedCTests(b, test_filter, target));
......@@ -461,7 +466,7 @@ pub fn build(b: *Builder) !void {
461466 "lib/std/std.zig",
462467 "std",
463468 "Run the standard library tests",
464 modes,
469 optimization_modes,
465470 skip_single_threaded,
466471 skip_non_native,
467472 skip_libc,
......@@ -481,9 +486,7 @@ fn addWasiUpdateStep(b: *Builder, version: [:0]const u8) !void {
481486 };
482487 target.cpu_features_add.addFeature(@enumToInt(std.Target.wasm.Feature.bulk_memory));
483488
484 const exe = addCompilerStep(b);
485 exe.setBuildMode(.ReleaseSmall);
486 exe.setTarget(target);
489 const exe = addCompilerStep(b, .ReleaseSmall, target);
487490
488491 const exe_options = b.addOptions();
489492 exe.addOptions("build_options", exe_options);
......@@ -510,8 +513,17 @@ fn addWasiUpdateStep(b: *Builder, version: [:0]const u8) !void {
510513 update_zig1_step.dependOn(&run_opt.step);
511514}
512515
513fn addCompilerStep(b: *Builder) *std.build.LibExeObjStep {
514 const exe = b.addExecutable("zig", "src/main.zig");
516fn addCompilerStep(
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 });
515527 exe.stack_size = stack_size;
516528 return exe;
517529}
doc/langref.html.in+29-13
......@@ -9531,8 +9531,12 @@ fn foo(comptime T: type, ptr: *T) T {
95319531const Builder = @import("std").build.Builder;
95329532
95339533pub fn build(b: *Builder) void {
9534 const exe = b.addExecutable("example", "example.zig");
9535 exe.setBuildMode(b.standardReleaseOptions());
9534 const optimize = b.standardOptimizeOption(.{});
9535 const exe = b.addExecutable(.{
9536 .name = "example",
9537 .root_source_file = .{ .path = "example.zig" },
9538 .optimize = optimize,
9539 });
95369540 b.default_step.dependOn(&exe.step);
95379541}
95389542 {#code_end#}
......@@ -10558,11 +10562,14 @@ pub fn build(b: *Builder) void {
1055810562
1055910563 // Standard release options allow the person running `zig build` to select
1056010564 // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
10561 const mode = b.standardReleaseOptions();
10565 const optimize = b.standardOptimizeOption(.{});
1056210566
10563 const exe = b.addExecutable("example", "src/main.zig");
10564 exe.setTarget(target);
10565 exe.setBuildMode(mode);
10567 const exe = b.addExecutable(.{
10568 .name = "example",
10569 .root_source_file = .{ .path = "src/main.zig" },
10570 .target = target,
10571 .optimize = optimize,
10572 });
1056610573 exe.install();
1056710574
1056810575 const run_cmd = exe.run();
......@@ -10584,13 +10591,18 @@ pub fn build(b: *Builder) void {
1058410591const Builder = @import("std").build.Builder;
1058510592
1058610593pub fn build(b: *Builder) void {
10587 const mode = b.standardReleaseOptions();
10588 const lib = b.addStaticLibrary("example", "src/main.zig");
10589 lib.setBuildMode(mode);
10594 const optimize = b.standardOptimizeOption(.{});
10595 const lib = b.addStaticLibrary(.{
10596 .name = "example",
10597 .root_source_file = .{ .path = "src/main.zig" },
10598 .optimize = optimize,
10599 });
1059010600 lib.install();
1059110601
10592 var main_tests = b.addTest("src/main.zig");
10593 main_tests.setBuildMode(mode);
10602 const main_tests = b.addTest(.{
10603 .root_source_file = .{ .path = "src/main.zig" },
10604 .optimize = optimize,
10605 });
1059410606
1059510607 const test_step = b.step("test", "Run library tests");
1059610608 test_step.dependOn(&main_tests.step);
......@@ -10954,7 +10966,9 @@ const Builder = @import("std").build.Builder;
1095410966pub fn build(b: *Builder) void {
1095510967 const lib = b.addSharedLibrary("mathtest", "mathtest.zig", b.version(1, 0, 0));
1095610968
10957 const exe = b.addExecutable("test", null);
10969 const exe = b.addExecutable(.{
10970 .name = "test",
10971 });
1095810972 exe.addCSourceFile("test.c", &[_][]const u8{"-std=c99"});
1095910973 exe.linkLibrary(lib);
1096010974 exe.linkSystemLibrary("c");
......@@ -11016,7 +11030,9 @@ const Builder = @import("std").build.Builder;
1101611030pub fn build(b: *Builder) void {
1101711031 const obj = b.addObject("base64", "base64.zig");
1101811032
11019 const exe = b.addExecutable("test", null);
11033 const exe = b.addExecutable(.{
11034 .name = "test",
11035 });
1102011036 exe.addCSourceFile("test.c", &[_][]const u8{"-std=c99"});
1102111037 exe.addObject(obj);
1102211038 exe.linkSystemLibrary("c");
lib/init-exe/build.zig+42-9
......@@ -1,5 +1,8 @@
11const std = @import("std");
22
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.
36pub fn build(b: *std.build.Builder) void {
47 // Standard target options allows the person running `zig build` to choose
58 // 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 {
710 // for restricting supported target set are available.
811 const target = b.standardTargetOptions(.{});
912
10 // Standard release options allow the person running `zig build` to select
11 // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
12 const mode = b.standardReleaseOptions();
13 // Standard optimization options allow the person running `zig build` to select
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();
1317
14 const exe = b.addExecutable("$", "src/main.zig");
15 exe.setTarget(target);
16 exe.setBuildMode(mode);
18 const exe = b.addExecutable(.{
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 executable to be installed into the
28 // standard location when the user invokes the "install" step (the default
29 // step when running `zig build`).
1730 exe.install();
1831
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.
1935 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.
2041 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`
2145 if (b.args) |args| {
2246 run_cmd.addArgs(args);
2347 }
2448
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".
2552 const run_step = b.step("run", "Run the app");
2653 run_step.dependOn(&run_cmd.step);
2754
28 const exe_tests = b.addTest("src/main.zig");
29 exe_tests.setTarget(target);
30 exe_tests.setBuildMode(mode);
55 // Creates a step for unit testing.
56 const exe_tests = b.addTest(.{
57 .root_source_file = .{ .path = "src/main.zig" },
58 .target = target,
59 .optimize = optimize,
60 });
3161
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.
3265 const test_step = b.step("test", "Run unit tests");
3366 test_step.dependOn(&exe_tests.step);
3467}
lib/init-lib/build.zig+34-7
......@@ -1,17 +1,44 @@
11const std = @import("std");
22
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.
36pub fn build(b: *std.build.Builder) void {
4 // Standard release options allow the person running `zig build` to select
5 // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
6 const mode = b.standardReleaseOptions();
7 // Standard target options allows the person running `zig build` to choose
8 // what target to build for. Here we do not override the defaults, which
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(.{});
712
8 const lib = b.addStaticLibrary("$", "src/main.zig");
9 lib.setBuildMode(mode);
13 // Standard optimization options allow the person running `zig build` to select
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`).
1030 lib.install();
1131
12 const main_tests = b.addTest("src/main.zig");
13 main_tests.setBuildMode(mode);
32 // Creates a step for unit testing.
33 const main_tests = b.addTest(.{
34 .root_source_file = .{ .path = "src/main.zig" },
35 .target = target,
36 .optimize = optimize,
37 });
1438
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".
1542 const test_step = b.step("test", "Run library tests");
1643 test_step.dependOn(&main_tests.step);
1744}
lib/std/build.zig+9-10
......@@ -420,10 +420,10 @@ pub const Builder = struct {
420420
421421 pub const ExecutableOptions = struct {
422422 name: []const u8,
423 root_source_file: ?FileSource,
423 root_source_file: ?FileSource = null,
424424 version: ?std.builtin.Version = null,
425 target: CrossTarget,
426 optimize: std.builtin.Mode,
425 target: CrossTarget = .{},
426 optimize: std.builtin.Mode = .Debug,
427427 linkage: ?LibExeObjStep.Linkage = null,
428428 };
429429
......@@ -436,13 +436,12 @@ pub const Builder = struct {
436436 .optimize = options.optimize,
437437 .kind = .exe,
438438 .linkage = options.linkage,
439 .version = options.version,
440439 });
441440 }
442441
443442 pub const ObjectOptions = struct {
444443 name: []const u8,
445 root_source_file: ?FileSource,
444 root_source_file: ?FileSource = null,
446445 target: CrossTarget,
447446 optimize: std.builtin.Mode,
448447 };
......@@ -459,7 +458,7 @@ pub const Builder = struct {
459458
460459 pub const SharedLibraryOptions = struct {
461460 name: []const u8,
462 root_source_file: ?FileSource,
461 root_source_file: ?FileSource = null,
463462 version: ?std.builtin.Version = null,
464463 target: CrossTarget,
465464 optimize: std.builtin.Mode,
......@@ -501,8 +500,8 @@ pub const Builder = struct {
501500 name: []const u8 = "test",
502501 kind: LibExeObjStep.Kind = .@"test",
503502 root_source_file: FileSource,
504 target: CrossTarget,
505 optimize: std.builtin.Mode,
503 target: CrossTarget = .{},
504 optimize: std.builtin.Mode = .Debug,
506505 version: ?std.builtin.Version = null,
507506 };
508507
......@@ -630,8 +629,8 @@ pub const Builder = struct {
630629 return FmtStep.create(self, paths);
631630 }
632631
633 pub fn addTranslateC(self: *Builder, source: FileSource) *TranslateCStep {
634 return TranslateCStep.create(self, source.dupe(self));
632 pub fn addTranslateC(self: *Builder, options: TranslateCStep.Options) *TranslateCStep {
633 return TranslateCStep.create(self, options);
635634 }
636635
637636 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),
1919c_macros: std.ArrayList([]const u8),
2020output_dir: ?[]const u8,
2121out_basename: []const u8,
22target: CrossTarget = CrossTarget{},
22target: CrossTarget,
23optimize: std.builtin.OptimizeMode,
2324output_file: build.GeneratedFile,
2425
25pub fn create(builder: *Builder, source: build.FileSource) *TranslateCStep {
26pub const Options = struct {
27 source_file: build.FileSource,
28 target: CrossTarget,
29 optimize: std.builtin.OptimizeMode,
30};
31
32pub fn create(builder: *Builder, options: Options) *TranslateCStep {
2633 const self = builder.allocator.create(TranslateCStep) catch unreachable;
34 const source = options.source_file.dupe(builder);
2735 self.* = TranslateCStep{
2836 .step = Step.init(.translate_c, "translate-c", builder.allocator, make),
2937 .builder = builder,
......@@ -32,19 +40,32 @@ pub fn create(builder: *Builder, source: build.FileSource) *TranslateCStep {
3240 .c_macros = std.ArrayList([]const u8).init(builder.allocator),
3341 .output_dir = null,
3442 .out_basename = undefined,
43 .target = options.target,
44 .optimize = options.optimize,
3545 .output_file = build.GeneratedFile{ .step = &self.step },
3646 };
3747 source.addStepDependencies(&self.step);
3848 return self;
3949}
4050
41pub fn setTarget(self: *TranslateCStep, target: CrossTarget) void {
42 self.target = target;
43}
51pub const AddExecutableOptions = struct {
52 name: ?[]const u8 = null,
53 version: ?std.builtin.Version = null,
54 target: ?CrossTarget = null,
55 optimize: ?std.builtin.Mode = null,
56 linkage: ?LibExeObjStep.Linkage = null,
57};
4458
4559/// Creates a step to build an executable from the translated source.
46pub fn addExecutable(self: *TranslateCStep) *LibExeObjStep {
47 return self.builder.addExecutableSource("translated_c", build.FileSource{ .generated = &self.output_file });
60pub fn addExecutable(self: *TranslateCStep, options: AddExecutableOptions) *LibExeObjStep {
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 });
4869}
4970
5071pub fn addIncludeDir(self: *TranslateCStep, include_dir: []const u8) void {
......@@ -82,6 +103,11 @@ fn make(step: *Step) !void {
82103 try argv_list.append(try self.target.zigTriple(self.builder.allocator));
83104 }
84105
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
85111 for (self.include_dirs.items) |include_dir| {
86112 try argv_list.append("-I");
87113 try argv_list.append(include_dir);
lib/std/builtin.zig+4-1
......@@ -131,13 +131,16 @@ pub const CodeModel = enum {
131131
132132/// This data structure is used by the Zig language code generation and
133133/// therefore must be kept in sync with the compiler implementation.
134pub const Mode = enum {
134pub const OptimizeMode = enum {
135135 Debug,
136136 ReleaseSafe,
137137 ReleaseFast,
138138 ReleaseSmall,
139139};
140140
141/// Deprecated; use OptimizeMode.
142pub const Mode = OptimizeMode;
143
141144/// This data structure is used by the Zig language code generation and
142145/// therefore must be kept in sync with the compiler implementation.
143146pub 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
35963596 man.hash.addOptionalBytes(options.sysroot);
35973597 try man.addOptionalFile(options.entitlements);
35983598
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.
36003601 _ = try man.hit();
36013602 digest = man.final();
36023603
......@@ -4177,9 +4178,11 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr
41774178 log.debug("failed to save linking hash digest file: {s}", .{@errorName(err)});
41784179 };
41794180 // Again failure here only means an unnecessary cache miss.
4180 man.writeManifest() catch |err| {
4181 log.debug("failed to write cache manifest when linking: {s}", .{@errorName(err)});
4182 };
4181 if (man.have_exclusive_lock) {
4182 man.writeManifest() catch |err| {
4183 log.debug("failed to write cache manifest when linking: {s}", .{@errorName(err)});
4184 };
4185 }
41834186 // We hang on to this lock so that the output file path can be used without
41844187 // other processes clobbering it.
41854188 macho_file.base.lock = man.toOwnedLock();
test/link/bss/build.zig+6-3
......@@ -1,12 +1,15 @@
11const Builder = @import("std").build.Builder;
22
33pub fn build(b: *Builder) void {
4 const mode = b.standardReleaseOptions();
4 const optimize = b.standardOptimizeOption(.{});
55 const test_step = b.step("test", "Test");
66
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 });
812 b.default_step.dependOn(&exe.step);
9 exe.setBuildMode(mode);
1013
1114 const run = exe.run();
1215 run.expectStdOutEqual("0, 1, 0\n");
test/link/common_symbols/build.zig+10-5
......@@ -1,14 +1,19 @@
11const Builder = @import("std").build.Builder;
22
33pub fn build(b: *Builder) void {
4 const mode = b.standardReleaseOptions();
4 const optimize = b.standardOptimizeOption(.{});
55
6 const lib_a = b.addStaticLibrary("a", null);
6 const lib_a = b.addStaticLibrary(.{
7 .name = "a",
8 .optimize = optimize,
9 .target = .{},
10 });
711 lib_a.addCSourceFiles(&.{ "c.c", "a.c", "b.c" }, &.{"-fcommon"});
8 lib_a.setBuildMode(mode);
912
10 const test_exe = b.addTest("main.zig");
11 test_exe.setBuildMode(mode);
13 const test_exe = b.addTest(.{
14 .root_source_file = .{ .path = "main.zig" },
15 .optimize = optimize,
16 });
1217 test_exe.linkLibrary(lib_a);
1318
1419 const test_step = b.step("test", "Test it");
test/link/common_symbols_alignment/build.zig+12-5
......@@ -1,14 +1,21 @@
11const Builder = @import("std").build.Builder;
22
33pub fn build(b: *Builder) void {
4 const mode = b.standardReleaseOptions();
4 const optimize = b.standardOptimizeOption(.{});
5 const target = b.standardTargetOptions(.{});
56
6 const lib_a = b.addStaticLibrary("a", null);
7 const lib_a = b.addStaticLibrary(.{
8 .name = "a",
9 .optimize = optimize,
10 .target = target,
11 });
712 lib_a.addCSourceFiles(&.{"a.c"}, &.{"-fcommon"});
8 lib_a.setBuildMode(mode);
913
10 const test_exe = b.addTest("main.zig");
11 test_exe.setBuildMode(mode);
14 const test_exe = b.addTest(.{
15 .root_source_file = .{ .path = "main.zig" },
16 .optimize = optimize,
17 .target = target,
18 });
1219 test_exe.linkLibrary(lib_a);
1320
1421 const test_step = b.step("test", "Test it");
test/link/interdependent_static_c_libs/build.zig+17-7
......@@ -1,20 +1,30 @@
11const Builder = @import("std").build.Builder;
22
33pub fn build(b: *Builder) void {
4 const mode = b.standardReleaseOptions();
4 const optimize = b.standardOptimizeOption(.{});
5 const target = b.standardTargetOptions(.{});
56
6 const lib_a = b.addStaticLibrary("a", null);
7 const lib_a = b.addStaticLibrary(.{
8 .name = "a",
9 .optimize = optimize,
10 .target = target,
11 });
712 lib_a.addCSourceFile("a.c", &[_][]const u8{});
8 lib_a.setBuildMode(mode);
913 lib_a.addIncludePath(".");
1014
11 const lib_b = b.addStaticLibrary("b", null);
15 const lib_b = b.addStaticLibrary(.{
16 .name = "b",
17 .optimize = optimize,
18 .target = target,
19 });
1220 lib_b.addCSourceFile("b.c", &[_][]const u8{});
13 lib_b.setBuildMode(mode);
1421 lib_b.addIncludePath(".");
1522
16 const test_exe = b.addTest("main.zig");
17 test_exe.setBuildMode(mode);
23 const test_exe = b.addTest(.{
24 .root_source_file = .{ .path = "main.zig" },
25 .optimize = optimize,
26 .target = target,
27 });
1828 test_exe.linkLibrary(lib_a);
1929 test_exe.linkLibrary(lib_b);
2030 test_exe.addIncludePath(".");
test/link/macho/bugs/13056/build.zig+5-3
......@@ -2,7 +2,7 @@ const std = @import("std");
22const Builder = std.build.Builder;
33
44pub fn build(b: *Builder) void {
5 const mode = b.standardReleaseOptions();
5 const optimize = b.standardOptimizeOption(.{});
66
77 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
88 const target_info = std.zig.system.NativeTargetInfo.detect(target) catch unreachable;
......@@ -11,7 +11,10 @@ pub fn build(b: *Builder) void {
1111
1212 const test_step = b.step("test", "Test the program");
1313
14 const exe = b.addExecutable("test", null);
14 const exe = b.addExecutable(.{
15 .name = "test",
16 .optimize = optimize,
17 });
1518 b.default_step.dependOn(&exe.step);
1619 exe.addIncludePath(std.fs.path.join(b.allocator, &.{ sdk.path, "/usr/include" }) catch unreachable);
1720 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 {
2023 "-nostdinc++",
2124 });
2225 exe.addObjectFile(std.fs.path.join(b.allocator, &.{ sdk.path, "/usr/lib/libc++.tbd" }) catch unreachable);
23 exe.setBuildMode(mode);
2426
2527 const run_cmd = exe.run();
2628 run_cmd.expectStdErrEqual("x: 5\n");
test/link/macho/bugs/13457/build.zig+7-4
......@@ -3,14 +3,17 @@ const Builder = std.build.Builder;
33const LibExeObjectStep = std.build.LibExeObjStep;
44
55pub fn build(b: *Builder) void {
6 const mode = b.standardReleaseOptions();
6 const optimize = b.standardOptimizeOption(.{});
77 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
88
99 const test_step = b.step("test", "Test the program");
1010
11 const exe = b.addExecutable("test", "main.zig");
12 exe.setBuildMode(mode);
13 exe.setTarget(target);
11 const exe = b.addExecutable(.{
12 .name = "test",
13 .root_source_file = .{ .path = "main.zig" },
14 .optimize = optimize,
15 .target = target,
16 });
1417
1518 const run = exe.runEmulatable();
1619 test_step.dependOn(&run.step);
test/link/macho/dead_strip/build.zig+9-7
......@@ -3,7 +3,7 @@ const Builder = std.build.Builder;
33const LibExeObjectStep = std.build.LibExeObjStep;
44
55pub fn build(b: *Builder) void {
6 const mode = b.standardReleaseOptions();
6 const optimize = b.standardOptimizeOption(.{});
77 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
88
99 const test_step = b.step("test", "Test the program");
......@@ -11,7 +11,7 @@ pub fn build(b: *Builder) void {
1111
1212 {
1313 // Without -dead_strip, we expect `iAmUnused` symbol present
14 const exe = createScenario(b, mode, target);
14 const exe = createScenario(b, optimize, target);
1515
1616 const check = exe.checkObject(.macho);
1717 check.checkInSymtab();
......@@ -24,7 +24,7 @@ pub fn build(b: *Builder) void {
2424
2525 {
2626 // With -dead_strip, no `iAmUnused` symbol should be present
27 const exe = createScenario(b, mode, target);
27 const exe = createScenario(b, optimize, target);
2828 exe.link_gc_sections = true;
2929
3030 const check = exe.checkObject(.macho);
......@@ -37,11 +37,13 @@ pub fn build(b: *Builder) void {
3737 }
3838}
3939
40fn createScenario(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget) *LibExeObjectStep {
41 const exe = b.addExecutable("test", null);
40fn createScenario(b: *Builder, optimize: std.builtin.OptimizeMode, target: std.zig.CrossTarget) *LibExeObjectStep {
41 const exe = b.addExecutable(.{
42 .name = "test",
43 .optimize = optimize,
44 .target = target,
45 });
4246 exe.addCSourceFile("main.c", &[0][]const u8{});
43 exe.setBuildMode(mode);
44 exe.setTarget(target);
4547 exe.linkLibC();
4648 return exe;
4749}
test/link/macho/dead_strip_dylibs/build.zig+8-6
......@@ -3,14 +3,14 @@ const Builder = std.build.Builder;
33const LibExeObjectStep = std.build.LibExeObjStep;
44
55pub fn build(b: *Builder) void {
6 const mode = b.standardReleaseOptions();
6 const optimize = b.standardOptimizeOption(.{});
77
88 const test_step = b.step("test", "Test the program");
99 test_step.dependOn(b.getInstallStep());
1010
1111 {
1212 // 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);
1414
1515 const check = exe.checkObject(.macho);
1616 check.checkStart("cmd LOAD_DYLIB");
......@@ -27,7 +27,7 @@ pub fn build(b: *Builder) void {
2727
2828 {
2929 // 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);
3131 exe.dead_strip_dylibs = true;
3232
3333 const run_cmd = exe.run();
......@@ -36,10 +36,12 @@ pub fn build(b: *Builder) void {
3636 }
3737}
3838
39fn createScenario(b: *Builder, mode: std.builtin.Mode) *LibExeObjectStep {
40 const exe = b.addExecutable("test", null);
39fn createScenario(b: *Builder, optimize: std.builtin.OptimizeMode) *LibExeObjectStep {
40 const exe = b.addExecutable(.{
41 .name = "test",
42 .optimize = optimize,
43 });
4144 exe.addCSourceFile("main.c", &[0][]const u8{});
42 exe.setBuildMode(mode);
4345 exe.linkLibC();
4446 exe.linkFramework("Cocoa");
4547 return exe;
test/link/macho/dylib/build.zig+12-7
......@@ -2,15 +2,18 @@ const std = @import("std");
22const Builder = std.build.Builder;
33
44pub fn build(b: *Builder) void {
5 const mode = b.standardReleaseOptions();
5 const optimize = b.standardOptimizeOption(.{});
66 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
77
88 const test_step = b.step("test", "Test");
99 test_step.dependOn(b.getInstallStep());
1010
11 const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0));
12 dylib.setBuildMode(mode);
13 dylib.setTarget(target);
11 const dylib = b.addSharedLibrary(.{
12 .name = "a",
13 .version = .{ .major = 1, .minor = 0 },
14 .optimize = optimize,
15 .target = target,
16 });
1417 dylib.addCSourceFile("a.c", &.{});
1518 dylib.linkLibC();
1619 dylib.install();
......@@ -24,9 +27,11 @@ pub fn build(b: *Builder) void {
2427
2528 test_step.dependOn(&check_dylib.step);
2629
27 const exe = b.addExecutable("main", null);
28 exe.setTarget(target);
29 exe.setBuildMode(mode);
30 const exe = b.addExecutable(.{
31 .name = "main",
32 .optimize = optimize,
33 .target = target,
34 });
3035 exe.addCSourceFile("main.c", &.{});
3136 exe.linkSystemLibrary("a");
3237 exe.linkLibC();
test/link/macho/empty/build.zig+6-4
......@@ -2,17 +2,19 @@ const std = @import("std");
22const Builder = std.build.Builder;
33
44pub fn build(b: *Builder) void {
5 const mode = b.standardReleaseOptions();
5 const optimize = b.standardOptimizeOption(.{});
66 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
77
88 const test_step = b.step("test", "Test the program");
99 test_step.dependOn(b.getInstallStep());
1010
11 const exe = b.addExecutable("test", null);
11 const exe = b.addExecutable(.{
12 .name = "test",
13 .optimize = optimize,
14 .target = target,
15 });
1216 exe.addCSourceFile("main.c", &[0][]const u8{});
1317 exe.addCSourceFile("empty.c", &[0][]const u8{});
14 exe.setBuildMode(mode);
15 exe.setTarget(target);
1618 exe.linkLibC();
1719
1820 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");
22const Builder = std.build.Builder;
33
44pub fn build(b: *Builder) void {
5 const mode = b.standardReleaseOptions();
5 const optimize = b.standardOptimizeOption(.{});
66
77 const test_step = b.step("test", "Test");
88 test_step.dependOn(b.getInstallStep());
99
10 const exe = b.addExecutable("main", null);
11 exe.setTarget(.{ .os_tag = .macos });
12 exe.setBuildMode(mode);
10 const exe = b.addExecutable(.{
11 .name = "main",
12 .optimize = optimize,
13 .target = .{ .os_tag = .macos },
14 });
1315 exe.addCSourceFile("main.c", &.{});
1416 exe.linkLibC();
1517 exe.entry_symbol_name = "_non_main";
test/link/macho/headerpad/build.zig+10-8
......@@ -4,14 +4,14 @@ const Builder = std.build.Builder;
44const LibExeObjectStep = std.build.LibExeObjStep;
55
66pub fn build(b: *Builder) void {
7 const mode = b.standardReleaseOptions();
7 const optimize = b.standardOptimizeOption(.{});
88
99 const test_step = b.step("test", "Test");
1010 test_step.dependOn(b.getInstallStep());
1111
1212 {
1313 // Test -headerpad_max_install_names
14 const exe = simpleExe(b, mode);
14 const exe = simpleExe(b, optimize);
1515 exe.headerpad_max_install_names = true;
1616
1717 const check = exe.checkObject(.macho);
......@@ -36,7 +36,7 @@ pub fn build(b: *Builder) void {
3636
3737 {
3838 // Test -headerpad
39 const exe = simpleExe(b, mode);
39 const exe = simpleExe(b, optimize);
4040 exe.headerpad_size = 0x10000;
4141
4242 const check = exe.checkObject(.macho);
......@@ -52,7 +52,7 @@ pub fn build(b: *Builder) void {
5252
5353 {
5454 // Test both flags with -headerpad overriding -headerpad_max_install_names
55 const exe = simpleExe(b, mode);
55 const exe = simpleExe(b, optimize);
5656 exe.headerpad_max_install_names = true;
5757 exe.headerpad_size = 0x10000;
5858
......@@ -69,7 +69,7 @@ pub fn build(b: *Builder) void {
6969
7070 {
7171 // Test both flags with -headerpad_max_install_names overriding -headerpad
72 const exe = simpleExe(b, mode);
72 const exe = simpleExe(b, optimize);
7373 exe.headerpad_size = 0x1000;
7474 exe.headerpad_max_install_names = true;
7575
......@@ -94,9 +94,11 @@ pub fn build(b: *Builder) void {
9494 }
9595}
9696
97fn simpleExe(b: *Builder, mode: std.builtin.Mode) *LibExeObjectStep {
98 const exe = b.addExecutable("main", null);
99 exe.setBuildMode(mode);
97fn simpleExe(b: *Builder, optimize: std.builtin.OptimizeMode) *LibExeObjectStep {
98 const exe = b.addExecutable(.{
99 .name = "main",
100 .optimize = optimize,
101 });
100102 exe.addCSourceFile("main.c", &.{});
101103 exe.linkLibC();
102104 exe.linkFramework("CoreFoundation");
test/link/macho/linksection/build.zig+8-5
......@@ -1,15 +1,18 @@
11const std = @import("std");
22
33pub fn build(b: *std.build.Builder) void {
4 const mode = b.standardReleaseOptions();
4 const optimize = b.standardOptimizeOption(.{});
55 const target = std.zig.CrossTarget{ .os_tag = .macos };
66
77 const test_step = b.step("test", "Test");
88 test_step.dependOn(b.getInstallStep());
99
10 const obj = b.addObject("test", "main.zig");
11 obj.setBuildMode(mode);
12 obj.setTarget(target);
10 const obj = b.addObject(.{
11 .name = "test",
12 .root_source_file = .{ .path = "main.zig" },
13 .optimize = optimize,
14 .target = target,
15 });
1316
1417 const check = obj.checkObject(.macho);
1518
......@@ -19,7 +22,7 @@ pub fn build(b: *std.build.Builder) void {
1922 check.checkInSymtab();
2023 check.checkNext("{*} (__TEXT,__TestFn) external _testFn");
2124
22 if (mode == .Debug) {
25 if (optimize == .Debug) {
2326 check.checkInSymtab();
2427 check.checkNext("{*} (__TEXT,__TestGenFnA) _main.testGenericFn__anon_{*}");
2528 }
test/link/macho/needed_framework/build.zig+5-3
......@@ -3,16 +3,18 @@ const Builder = std.build.Builder;
33const LibExeObjectStep = std.build.LibExeObjStep;
44
55pub fn build(b: *Builder) void {
6 const mode = b.standardReleaseOptions();
6 const optimize = b.standardOptimizeOption(.{});
77
88 const test_step = b.step("test", "Test the program");
99 test_step.dependOn(b.getInstallStep());
1010
1111 // -dead_strip_dylibs
1212 // -needed_framework Cocoa
13 const exe = b.addExecutable("test", null);
13 const exe = b.addExecutable(.{
14 .name = "test",
15 .optimize = optimize,
16 });
1417 exe.addCSourceFile("main.c", &[0][]const u8{});
15 exe.setBuildMode(mode);
1618 exe.linkLibC();
1719 exe.linkFrameworkNeeded("Cocoa");
1820 exe.dead_strip_dylibs = true;
test/link/macho/needed_library/build.zig+12-7
......@@ -3,25 +3,30 @@ const Builder = std.build.Builder;
33const LibExeObjectStep = std.build.LibExeObjStep;
44
55pub fn build(b: *Builder) void {
6 const mode = b.standardReleaseOptions();
6 const optimize = b.standardOptimizeOption(.{});
77 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
88
99 const test_step = b.step("test", "Test the program");
1010 test_step.dependOn(b.getInstallStep());
1111
12 const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0));
13 dylib.setTarget(target);
14 dylib.setBuildMode(mode);
12 const dylib = b.addSharedLibrary(.{
13 .name = "a",
14 .version = .{ .major = 1, .minor = 0 },
15 .optimize = optimize,
16 .target = target,
17 });
1518 dylib.addCSourceFile("a.c", &.{});
1619 dylib.linkLibC();
1720 dylib.install();
1821
1922 // -dead_strip_dylibs
2023 // -needed-la
21 const exe = b.addExecutable("test", null);
24 const exe = b.addExecutable(.{
25 .name = "test",
26 .optimize = optimize,
27 .target = target,
28 });
2229 exe.addCSourceFile("main.c", &[0][]const u8{});
23 exe.setBuildMode(mode);
24 exe.setTarget(target);
2530 exe.linkLibC();
2631 exe.linkSystemLibraryNeeded("a");
2732 exe.addLibraryPath(b.pathFromRoot("zig-out/lib"));
test/link/macho/objc/build.zig+5-3
......@@ -2,15 +2,17 @@ const std = @import("std");
22const Builder = std.build.Builder;
33
44pub fn build(b: *Builder) void {
5 const mode = b.standardReleaseOptions();
5 const optimize = b.standardOptimizeOption(.{});
66
77 const test_step = b.step("test", "Test the program");
88
9 const exe = b.addExecutable("test", null);
9 const exe = b.addExecutable(.{
10 .name = "test",
11 .optimize = optimize,
12 });
1013 exe.addIncludePath(".");
1114 exe.addCSourceFile("Foo.m", &[0][]const u8{});
1215 exe.addCSourceFile("test.m", &[0][]const u8{});
13 exe.setBuildMode(mode);
1416 exe.linkLibC();
1517 // TODO when we figure out how to ship framework stubs for cross-compilation,
1618 // populate paths to the sysroot here.
test/link/macho/objcpp/build.zig+5-3
......@@ -2,16 +2,18 @@ const std = @import("std");
22const Builder = std.build.Builder;
33
44pub fn build(b: *Builder) void {
5 const mode = b.standardReleaseOptions();
5 const optimize = b.standardOptimizeOption(.{});
66
77 const test_step = b.step("test", "Test the program");
88
9 const exe = b.addExecutable("test", null);
9 const exe = b.addExecutable(.{
10 .name = "test",
11 .optimize = optimize,
12 });
1013 b.default_step.dependOn(&exe.step);
1114 exe.addIncludePath(".");
1215 exe.addCSourceFile("Foo.mm", &[0][]const u8{});
1316 exe.addCSourceFile("test.mm", &[0][]const u8{});
14 exe.setBuildMode(mode);
1517 exe.linkLibCpp();
1618 // TODO when we figure out how to ship framework stubs for cross-compilation,
1719 // populate paths to the sysroot here.
test/link/macho/pagezero/build.zig+11-7
......@@ -2,16 +2,18 @@ const std = @import("std");
22const Builder = std.build.Builder;
33
44pub fn build(b: *Builder) void {
5 const mode = b.standardReleaseOptions();
5 const optimize = b.standardOptimizeOption(.{});
66 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
77
88 const test_step = b.step("test", "Test");
99 test_step.dependOn(b.getInstallStep());
1010
1111 {
12 const exe = b.addExecutable("pagezero", null);
13 exe.setTarget(target);
14 exe.setBuildMode(mode);
12 const exe = b.addExecutable(.{
13 .name = "pagezero",
14 .optimize = optimize,
15 .target = target,
16 });
1517 exe.addCSourceFile("main.c", &.{});
1618 exe.linkLibC();
1719 exe.pagezero_size = 0x4000;
......@@ -29,9 +31,11 @@ pub fn build(b: *Builder) void {
2931 }
3032
3133 {
32 const exe = b.addExecutable("no_pagezero", null);
33 exe.setTarget(target);
34 exe.setBuildMode(mode);
34 const exe = b.addExecutable(.{
35 .name = "no_pagezero",
36 .optimize = optimize,
37 .target = target,
38 });
3539 exe.addCSourceFile("main.c", &.{});
3640 exe.linkLibC();
3741 exe.pagezero_size = 0;
test/link/macho/search_strategy/build.zig+20-13
......@@ -3,7 +3,7 @@ const Builder = std.build.Builder;
33const LibExeObjectStep = std.build.LibExeObjStep;
44
55pub fn build(b: *Builder) void {
6 const mode = b.standardReleaseOptions();
6 const optimize = b.standardOptimizeOption(.{});
77 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
88
99 const test_step = b.step("test", "Test");
......@@ -11,7 +11,7 @@ pub fn build(b: *Builder) void {
1111
1212 {
1313 // -search_dylibs_first
14 const exe = createScenario(b, mode, target);
14 const exe = createScenario(b, optimize, target);
1515 exe.search_strategy = .dylibs_first;
1616
1717 const check = exe.checkObject(.macho);
......@@ -26,7 +26,7 @@ pub fn build(b: *Builder) void {
2626
2727 {
2828 // -search_paths_first
29 const exe = createScenario(b, mode, target);
29 const exe = createScenario(b, optimize, target);
3030 exe.search_strategy = .paths_first;
3131
3232 const run = std.build.EmulatableRunStep.create(b, "run", exe);
......@@ -36,10 +36,12 @@ pub fn build(b: *Builder) void {
3636 }
3737}
3838
39fn createScenario(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget) *LibExeObjectStep {
40 const static = b.addStaticLibrary("a", null);
41 static.setTarget(target);
42 static.setBuildMode(mode);
39fn createScenario(b: *Builder, optimize: std.builtin.OptimizeMode, target: std.zig.CrossTarget) *LibExeObjectStep {
40 const static = b.addStaticLibrary(.{
41 .name = "a",
42 .optimize = optimize,
43 .target = target,
44 });
4345 static.addCSourceFile("a.c", &.{});
4446 static.linkLibC();
4547 static.override_dest_dir = std.build.InstallDir{
......@@ -47,9 +49,12 @@ fn createScenario(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarg
4749 };
4850 static.install();
4951
50 const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0));
51 dylib.setTarget(target);
52 dylib.setBuildMode(mode);
52 const dylib = b.addSharedLibrary(.{
53 .name = "a",
54 .version = .{ .major = 1, .minor = 0 },
55 .optimize = optimize,
56 .target = target,
57 });
5358 dylib.addCSourceFile("a.c", &.{});
5459 dylib.linkLibC();
5560 dylib.override_dest_dir = std.build.InstallDir{
......@@ -57,9 +62,11 @@ fn createScenario(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarg
5762 };
5863 dylib.install();
5964
60 const exe = b.addExecutable("main", null);
61 exe.setTarget(target);
62 exe.setBuildMode(mode);
65 const exe = b.addExecutable(.{
66 .name = "main",
67 .optimize = optimize,
68 .target = target,
69 });
6370 exe.addCSourceFile("main.c", &.{});
6471 exe.linkSystemLibraryName("a");
6572 exe.linkLibC();
test/link/macho/stack_size/build.zig+6-4
......@@ -2,15 +2,17 @@ const std = @import("std");
22const Builder = std.build.Builder;
33
44pub fn build(b: *Builder) void {
5 const mode = b.standardReleaseOptions();
5 const optimize = b.standardOptimizeOption(.{});
66 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
77
88 const test_step = b.step("test", "Test");
99 test_step.dependOn(b.getInstallStep());
1010
11 const exe = b.addExecutable("main", null);
12 exe.setTarget(target);
13 exe.setBuildMode(mode);
11 const exe = b.addExecutable(.{
12 .name = "main",
13 .optimize = optimize,
14 .target = target,
15 });
1416 exe.addCSourceFile("main.c", &.{});
1517 exe.linkLibC();
1618 exe.stack_size = 0x100000000;
test/link/macho/strict_validation/build.zig+7-4
......@@ -4,15 +4,18 @@ const Builder = std.build.Builder;
44const LibExeObjectStep = std.build.LibExeObjStep;
55
66pub fn build(b: *Builder) void {
7 const mode = b.standardReleaseOptions();
7 const optimize = b.standardOptimizeOption(.{});
88 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
99
1010 const test_step = b.step("test", "Test");
1111 test_step.dependOn(b.getInstallStep());
1212
13 const exe = b.addExecutable("main", "main.zig");
14 exe.setBuildMode(mode);
15 exe.setTarget(target);
13 const exe = b.addExecutable(.{
14 .name = "main",
15 .root_source_file = .{ .path = "main.zig" },
16 .optimize = optimize,
17 .target = target,
18 });
1619 exe.linkLibC();
1720
1821 const check_exe = exe.checkObject(.macho);
test/link/macho/tls/build.zig+12-7
......@@ -2,18 +2,23 @@ const std = @import("std");
22const Builder = std.build.Builder;
33
44pub fn build(b: *Builder) void {
5 const mode = b.standardReleaseOptions();
5 const optimize = b.standardOptimizeOption(.{});
66 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
77
8 const lib = b.addSharedLibrary("a", null, b.version(1, 0, 0));
9 lib.setBuildMode(mode);
10 lib.setTarget(target);
8 const lib = b.addSharedLibrary(.{
9 .name = "a",
10 .version = .{ .major = 1, .minor = 0 },
11 .optimize = optimize,
12 .target = target,
13 });
1114 lib.addCSourceFile("a.c", &.{});
1215 lib.linkLibC();
1316
14 const test_exe = b.addTest("main.zig");
15 test_exe.setBuildMode(mode);
16 test_exe.setTarget(target);
17 const test_exe = b.addTest(.{
18 .root_source_file = .{ .path = "main.zig" },
19 .optimize = optimize,
20 .target = target,
21 });
1722 test_exe.linkLibrary(lib);
1823 test_exe.linkLibC();
1924
test/link/macho/unwind_info/build.zig+11-9
......@@ -4,23 +4,23 @@ const Builder = std.build.Builder;
44const LibExeObjectStep = std.build.LibExeObjStep;
55
66pub fn build(b: *Builder) void {
7 const mode = b.standardReleaseOptions();
7 const optimize = b.standardOptimizeOption(.{});
88 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
99
1010 const test_step = b.step("test", "Test the program");
1111
12 testUnwindInfo(b, test_step, mode, target, false);
13 testUnwindInfo(b, test_step, mode, target, true);
12 testUnwindInfo(b, test_step, optimize, target, false);
13 testUnwindInfo(b, test_step, optimize, target, true);
1414}
1515
1616fn testUnwindInfo(
1717 b: *Builder,
1818 test_step: *std.build.Step,
19 mode: std.builtin.Mode,
19 optimize: std.builtin.OptimizeMode,
2020 target: std.zig.CrossTarget,
2121 dead_strip: bool,
2222) void {
23 const exe = createScenario(b, mode, target);
23 const exe = createScenario(b, optimize, target);
2424 exe.link_gc_sections = dead_strip;
2525
2626 const check = exe.checkObject(.macho);
......@@ -52,8 +52,12 @@ fn testUnwindInfo(
5252 test_step.dependOn(&run_cmd.step);
5353}
5454
55fn createScenario(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget) *LibExeObjectStep {
56 const exe = b.addExecutable("test", null);
55fn createScenario(b: *Builder, optimize: std.builtin.OptimizeMode, target: std.zig.CrossTarget) *LibExeObjectStep {
56 const exe = b.addExecutable(.{
57 .name = "test",
58 .optimize = optimize,
59 .target = target,
60 });
5761 b.default_step.dependOn(&exe.step);
5862 exe.addIncludePath(".");
5963 exe.addCSourceFiles(&[_][]const u8{
......@@ -61,8 +65,6 @@ fn createScenario(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarg
6165 "simple_string.cpp",
6266 "simple_string_owner.cpp",
6367 }, &[0][]const u8{});
64 exe.setBuildMode(mode);
65 exe.setTarget(target);
6668 exe.linkLibCpp();
6769 return exe;
6870}
test/link/macho/uuid/build.zig+10-7
......@@ -29,21 +29,21 @@ pub fn build(b: *Builder) void {
2929fn testUuid(
3030 b: *Builder,
3131 test_step: *std.build.Step,
32 mode: std.builtin.Mode,
32 optimize: std.builtin.OptimizeMode,
3333 target: std.zig.CrossTarget,
3434 comptime exp: []const u8,
3535) void {
3636 // The calculated UUID value is independent of debug info and so it should
3737 // stay the same across builds.
3838 {
39 const dylib = simpleDylib(b, mode, target);
39 const dylib = simpleDylib(b, optimize, target);
4040 const check_dylib = dylib.checkObject(.macho);
4141 check_dylib.checkStart("cmd UUID");
4242 check_dylib.checkNext("uuid " ++ exp);
4343 test_step.dependOn(&check_dylib.step);
4444 }
4545 {
46 const dylib = simpleDylib(b, mode, target);
46 const dylib = simpleDylib(b, optimize, target);
4747 dylib.strip = true;
4848 const check_dylib = dylib.checkObject(.macho);
4949 check_dylib.checkStart("cmd UUID");
......@@ -52,10 +52,13 @@ fn testUuid(
5252 }
5353}
5454
55fn simpleDylib(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget) *LibExeObjectStep {
56 const dylib = b.addSharedLibrary("test", null, b.version(1, 0, 0));
57 dylib.setTarget(target);
58 dylib.setBuildMode(mode);
55fn simpleDylib(b: *Builder, optimize: std.builtin.OptimizeMode, target: std.zig.CrossTarget) *LibExeObjectStep {
56 const dylib = b.addSharedLibrary(.{
57 .name = "test",
58 .version = .{ .major = 1, .minor = 0 },
59 .optimize = optimize,
60 .target = target,
61 });
5962 dylib.addCSourceFile("test.c", &.{});
6063 dylib.linkLibC();
6164 return dylib;
test/link/macho/weak_framework/build.zig+5-3
......@@ -3,14 +3,16 @@ const Builder = std.build.Builder;
33const LibExeObjectStep = std.build.LibExeObjStep;
44
55pub fn build(b: *Builder) void {
6 const mode = b.standardReleaseOptions();
6 const optimize = b.standardOptimizeOption(.{});
77
88 const test_step = b.step("test", "Test the program");
99 test_step.dependOn(b.getInstallStep());
1010
11 const exe = b.addExecutable("test", null);
11 const exe = b.addExecutable(.{
12 .name = "test",
13 .optimize = optimize,
14 });
1215 exe.addCSourceFile("main.c", &[0][]const u8{});
13 exe.setBuildMode(mode);
1416 exe.linkLibC();
1517 exe.linkFrameworkWeak("Cocoa");
1618
test/link/macho/weak_library/build.zig+12-7
......@@ -3,23 +3,28 @@ const Builder = std.build.Builder;
33const LibExeObjectStep = std.build.LibExeObjStep;
44
55pub fn build(b: *Builder) void {
6 const mode = b.standardReleaseOptions();
6 const optimize = b.standardOptimizeOption(.{});
77 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
88
99 const test_step = b.step("test", "Test the program");
1010 test_step.dependOn(b.getInstallStep());
1111
12 const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0));
13 dylib.setTarget(target);
14 dylib.setBuildMode(mode);
12 const dylib = b.addSharedLibrary(.{
13 .name = "a",
14 .version = .{ .major = 1, .minor = 0, .patch = 0 },
15 .target = target,
16 .optimize = optimize,
17 });
1518 dylib.addCSourceFile("a.c", &.{});
1619 dylib.linkLibC();
1720 dylib.install();
1821
19 const exe = b.addExecutable("test", null);
22 const exe = b.addExecutable(.{
23 .name = "test",
24 .target = target,
25 .optimize = optimize,
26 });
2027 exe.addCSourceFile("main.c", &[0][]const u8{});
21 exe.setTarget(target);
22 exe.setBuildMode(mode);
2328 exe.linkLibC();
2429 exe.linkSystemLibraryWeak("a");
2530 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");
22const Builder = std.build.Builder;
33
44pub fn build(b: *Builder) void {
5 const mode = b.standardReleaseOptions();
5 const optimize = b.standardOptimizeOption(.{});
6 const target = b.standardTargetOptions(.{});
67
7 const lib_a = b.addStaticLibrary("a", null);
8 const lib_a = b.addStaticLibrary(.{
9 .name = "a",
10 .optimize = optimize,
11 .target = target,
12 });
813 lib_a.addCSourceFile("a.c", &[_][]const u8{});
9 lib_a.setBuildMode(mode);
1014 lib_a.addIncludePath(".");
1115 lib_a.install();
1216
13 const test_exe = b.addTest("main.zig");
14 test_exe.setBuildMode(mode);
17 const test_exe = b.addTest(.{
18 .root_source_file = .{ .path = "main.zig" },
19 .optimize = optimize,
20 .target = target,
21 });
1522 test_exe.linkSystemLibrary("a"); // force linking liba.a as -la
1623 test_exe.addSystemIncludePath(".");
1724 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");
22const Builder = std.build.Builder;
33
44pub fn build(b: *Builder) void {
5 const mode = b.standardReleaseOptions();
6
75 const test_step = b.step("test", "Test");
86 test_step.dependOn(b.getInstallStep());
97
108 // The code in question will pull-in compiler-rt,
119 // and therefore link with its archive file.
12 const lib = b.addSharedLibrary("main", "main.zig", .unversioned);
13 lib.setBuildMode(mode);
14 lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
10 const lib = b.addSharedLibrary(.{
11 .name = "main",
12 .root_source_file = .{ .path = "main.zig" },
13 .optimize = b.standardOptimizeOption(.{}),
14 .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
15 });
1516 lib.use_llvm = false;
1617 lib.use_lld = false;
1718 lib.strip = false;
test/link/wasm/basic-features/build.zig+11-7
......@@ -1,14 +1,18 @@
11const std = @import("std");
22
33pub fn build(b: *std.build.Builder) void {
4 const mode = b.standardReleaseOptions();
5
64 // Library with explicitly set cpu features
7 const lib = b.addSharedLibrary("lib", "main.zig", .unversioned);
8 lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
9 lib.target.cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp };
10 lib.target.cpu_features_add.addFeature(0); // index 0 == atomics (see std.Target.wasm.Features)
11 lib.setBuildMode(mode);
5 const lib = b.addSharedLibrary(.{
6 .name = "lib",
7 .root_source_file = .{ .path = "main.zig" },
8 .optimize = b.standardOptimizeOption(.{}),
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 });
1216 lib.use_llvm = false;
1317 lib.use_lld = false;
1418
test/link/wasm/bss/build.zig+6-5
......@@ -2,14 +2,15 @@ const std = @import("std");
22const Builder = std.build.Builder;
33
44pub fn build(b: *Builder) void {
5 const mode = b.standardReleaseOptions();
6
75 const test_step = b.step("test", "Test");
86 test_step.dependOn(b.getInstallStep());
97
10 const lib = b.addSharedLibrary("lib", "lib.zig", .unversioned);
11 lib.setBuildMode(mode);
12 lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
8 const lib = b.addSharedLibrary(.{
9 .name = "lib",
10 .root_source_file = .{ .path = "lib.zig" },
11 .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
12 .optimize = b.standardOptimizeOption(.{}),
13 });
1314 lib.use_llvm = false;
1415 lib.use_lld = false;
1516 lib.strip = false;
test/link/wasm/export-data/build.zig+6-3
......@@ -5,9 +5,12 @@ pub fn build(b: *Builder) void {
55 const test_step = b.step("test", "Test");
66 test_step.dependOn(b.getInstallStep());
77
8 const lib = b.addSharedLibrary("lib", "lib.zig", .unversioned);
9 lib.setBuildMode(.ReleaseSafe); // to make the output deterministic in address positions
10 lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
8 const lib = b.addSharedLibrary(.{
9 .name = "lib",
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 });
1114 lib.use_lld = false;
1215 lib.export_symbol_names = &.{ "foo", "bar" };
1316 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 @@
11const std = @import("std");
22
33pub fn build(b: *std.build.Builder) void {
4 const mode = b.standardReleaseOptions();
5
6 const no_export = b.addSharedLibrary("no-export", "main.zig", .unversioned);
7 no_export.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
8 no_export.setBuildMode(mode);
4 const optimize = b.standardOptimizeOption(.{});
5
6 const no_export = b.addSharedLibrary(.{
7 .name = "no-export",
8 .root_source_file = .{ .path = "main.zig" },
9 .optimize = optimize,
10 .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
11 });
912 no_export.use_llvm = false;
1013 no_export.use_lld = false;
1114
12 const dynamic_export = b.addSharedLibrary("dynamic", "main.zig", .unversioned);
13 dynamic_export.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
14 dynamic_export.setBuildMode(mode);
15 const dynamic_export = b.addSharedLibrary(.{
16 .name = "dynamic",
17 .root_source_file = .{ .path = "main.zig" },
18 .optimize = optimize,
19 .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
20 });
1521 dynamic_export.rdynamic = true;
1622 dynamic_export.use_llvm = false;
1723 dynamic_export.use_lld = false;
1824
19 const force_export = b.addSharedLibrary("force", "main.zig", .unversioned);
20 force_export.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
21 force_export.setBuildMode(mode);
25 const force_export = b.addSharedLibrary(.{
26 .name = "force",
27 .root_source_file = .{ .path = "main.zig" },
28 .optimize = optimize,
29 .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
30 });
2231 force_export.export_symbol_names = &.{"foo"};
2332 force_export.use_llvm = false;
2433 force_export.use_lld = false;
test/link/wasm/extern-mangle/build.zig+6-5
......@@ -2,14 +2,15 @@ const std = @import("std");
22const Builder = std.build.Builder;
33
44pub fn build(b: *Builder) void {
5 const mode = b.standardReleaseOptions();
6
75 const test_step = b.step("test", "Test");
86 test_step.dependOn(b.getInstallStep());
97
10 const lib = b.addSharedLibrary("lib", "lib.zig", .unversioned);
11 lib.setBuildMode(mode);
12 lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
8 const lib = b.addSharedLibrary(.{
9 .name = "lib",
10 .root_source_file = .{ .path = "lib.zig" },
11 .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
12 .optimize = b.standardOptimizeOption(.{}),
13 });
1314 lib.import_symbols = true; // import `a` and `b`
1415 lib.rdynamic = true; // export `foo`
1516 lib.install();
test/link/wasm/extern/build.zig+6-4
......@@ -1,10 +1,12 @@
11const std = @import("std");
22
33pub fn build(b: *std.build.Builder) void {
4 const mode = b.standardReleaseOptions();
5 const exe = b.addExecutable("extern", "main.zig");
6 exe.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .wasi });
7 exe.setBuildMode(mode);
4 const exe = b.addExecutable(.{
5 .name = "extern",
6 .root_source_file = .{ .path = "main.zig" },
7 .optimize = b.standardOptimizeOption(.{}),
8 .target = .{ .cpu_arch = .wasm32, .os_tag = .wasi },
9 });
810 exe.addCSourceFile("foo.c", &.{});
911 exe.use_llvm = false;
1012 exe.use_lld = false;
test/link/wasm/function-table/build.zig+19-10
......@@ -2,28 +2,37 @@ const std = @import("std");
22const Builder = std.build.Builder;
33
44pub fn build(b: *Builder) void {
5 const mode = b.standardReleaseOptions();
5 const optimize = b.standardOptimizeOption(.{});
66
77 const test_step = b.step("test", "Test");
88 test_step.dependOn(b.getInstallStep());
99
10 const import_table = b.addSharedLibrary("lib", "lib.zig", .unversioned);
11 import_table.setBuildMode(mode);
12 import_table.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
10 const import_table = b.addSharedLibrary(.{
11 .name = "lib",
12 .root_source_file = .{ .path = "lib.zig" },
13 .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
14 .optimize = optimize,
15 });
1316 import_table.use_llvm = false;
1417 import_table.use_lld = false;
1518 import_table.import_table = true;
1619
17 const export_table = b.addSharedLibrary("lib", "lib.zig", .unversioned);
18 export_table.setBuildMode(mode);
19 export_table.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
20 const export_table = b.addSharedLibrary(.{
21 .name = "lib",
22 .root_source_file = .{ .path = "lib.zig" },
23 .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
24 .optimize = optimize,
25 });
2026 export_table.use_llvm = false;
2127 export_table.use_lld = false;
2228 export_table.export_table = true;
2329
24 const regular_table = b.addSharedLibrary("lib", "lib.zig", .unversioned);
25 regular_table.setBuildMode(mode);
26 regular_table.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
30 const regular_table = b.addSharedLibrary(.{
31 .name = "lib",
32 .root_source_file = .{ .path = "lib.zig" },
33 .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
34 .optimize = optimize,
35 });
2736 regular_table.use_llvm = false;
2837 regular_table.use_lld = false;
2938
test/link/wasm/infer-features/build.zig+20-9
......@@ -1,21 +1,32 @@
11const std = @import("std");
22
33pub fn build(b: *std.build.Builder) void {
4 const mode = b.standardReleaseOptions();
4 const optimize = b.standardOptimizeOption(.{});
55
66 // Wasm Object file which we will use to infer the features from
7 const c_obj = b.addObject("c_obj", null);
8 c_obj.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
9 c_obj.target.cpu_model = .{ .explicit = &std.Target.wasm.cpu.bleeding_edge };
7 const c_obj = b.addObject(.{
8 .name = "c_obj",
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 });
1016 c_obj.addCSourceFile("foo.c", &.{});
11 c_obj.setBuildMode(mode);
1217
1318 // Wasm library that doesn't have any features specified. This will
1419 // infer its featureset from other linked object files.
15 const lib = b.addSharedLibrary("lib", "main.zig", .unversioned);
16 lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
17 lib.target.cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp };
18 lib.setBuildMode(mode);
20 const lib = b.addSharedLibrary(.{
21 .name = "lib",
22 .root_source_file = .{ .path = "main.zig" },
23 .optimize = optimize,
24 .target = .{
25 .cpu_arch = .wasm32,
26 .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp },
27 .os_tag = .freestanding,
28 },
29 });
1930 lib.use_llvm = false;
2031 lib.use_lld = false;
2132 lib.addObject(c_obj);
test/link/wasm/producers/build.zig+6-5
......@@ -3,14 +3,15 @@ const builtin = @import("builtin");
33const Builder = std.build.Builder;
44
55pub fn build(b: *Builder) void {
6 const mode = b.standardReleaseOptions();
7
86 const test_step = b.step("test", "Test");
97 test_step.dependOn(b.getInstallStep());
108
11 const lib = b.addSharedLibrary("lib", "lib.zig", .unversioned);
12 lib.setBuildMode(mode);
13 lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
9 const lib = b.addSharedLibrary(.{
10 .name = "lib",
11 .root_source_file = .{ .path = "lib.zig" },
12 .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
13 .optimize = b.standardOptimizeOption(.{}),
14 });
1415 lib.use_llvm = false;
1516 lib.use_lld = false;
1617 lib.strip = false;
test/link/wasm/segments/build.zig+6-5
......@@ -2,14 +2,15 @@ const std = @import("std");
22const Builder = std.build.Builder;
33
44pub fn build(b: *Builder) void {
5 const mode = b.standardReleaseOptions();
6
75 const test_step = b.step("test", "Test");
86 test_step.dependOn(b.getInstallStep());
97
10 const lib = b.addSharedLibrary("lib", "lib.zig", .unversioned);
11 lib.setBuildMode(mode);
12 lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
8 const lib = b.addSharedLibrary(.{
9 .name = "lib",
10 .root_source_file = .{ .path = "lib.zig" },
11 .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
12 .optimize = b.standardOptimizeOption(.{}),
13 });
1314 lib.use_llvm = false;
1415 lib.use_lld = false;
1516 lib.strip = false;
test/link/wasm/stack_pointer/build.zig+6-5
......@@ -2,14 +2,15 @@ const std = @import("std");
22const Builder = std.build.Builder;
33
44pub fn build(b: *Builder) void {
5 const mode = b.standardReleaseOptions();
6
75 const test_step = b.step("test", "Test");
86 test_step.dependOn(b.getInstallStep());
97
10 const lib = b.addSharedLibrary("lib", "lib.zig", .unversioned);
11 lib.setBuildMode(mode);
12 lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
8 const lib = b.addSharedLibrary(.{
9 .name = "lib",
10 .root_source_file = .{ .path = "lib.zig" },
11 .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
12 .optimize = b.standardOptimizeOption(.{}),
13 });
1314 lib.use_llvm = false;
1415 lib.use_lld = false;
1516 lib.strip = false;
test/link/wasm/type/build.zig+6-5
......@@ -2,14 +2,15 @@ const std = @import("std");
22const Builder = std.build.Builder;
33
44pub fn build(b: *Builder) void {
5 const mode = b.standardReleaseOptions();
6
75 const test_step = b.step("test", "Test");
86 test_step.dependOn(b.getInstallStep());
97
10 const lib = b.addSharedLibrary("lib", "lib.zig", .unversioned);
11 lib.setBuildMode(mode);
12 lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
8 const lib = b.addSharedLibrary(.{
9 .name = "lib",
10 .root_source_file = .{ .path = "lib.zig" },
11 .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
12 .optimize = b.standardOptimizeOption(.{}),
13 });
1314 lib.use_llvm = false;
1415 lib.use_lld = false;
1516 lib.strip = false;
test/src/compare_output.zig+23-8
......@@ -6,14 +6,14 @@ const ArrayList = std.ArrayList;
66const fmt = std.fmt;
77const mem = std.mem;
88const fs = std.fs;
9const Mode = std.builtin.Mode;
9const OptimizeMode = std.builtin.OptimizeMode;
1010
1111pub const CompareOutputContext = struct {
1212 b: *build.Builder,
1313 step: *build.Step,
1414 test_index: usize,
1515 test_filter: ?[]const u8,
16 modes: []const Mode,
16 optimize_modes: []const OptimizeMode,
1717
1818 const Special = enum {
1919 None,
......@@ -102,7 +102,11 @@ pub const CompareOutputContext = struct {
102102 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
103103 }
104104
105 const exe = b.addExecutable("test", null);
105 const exe = b.addExecutable(.{
106 .name = "test",
107 .target = .{},
108 .optimize = .Debug,
109 });
106110 exe.addAssemblyFileSource(write_src.getFileSource(case.sources.items[0].filename).?);
107111
108112 const run = exe.run();
......@@ -113,19 +117,23 @@ pub const CompareOutputContext = struct {
113117 self.step.dependOn(&run.step);
114118 },
115119 Special.None => {
116 for (self.modes) |mode| {
120 for (self.optimize_modes) |optimize| {
117121 const annotated_case_name = fmt.allocPrint(self.b.allocator, "{s} {s} ({s})", .{
118122 "compare-output",
119123 case.name,
120 @tagName(mode),
124 @tagName(optimize),
121125 }) catch unreachable;
122126 if (self.test_filter) |filter| {
123127 if (mem.indexOf(u8, annotated_case_name, filter) == null) continue;
124128 }
125129
126130 const basename = case.sources.items[0].filename;
127 const exe = b.addExecutableSource("test", write_src.getFileSource(basename).?);
128 exe.setBuildMode(mode);
131 const exe = b.addExecutable(.{
132 .name = "test",
133 .root_source_file = write_src.getFileSource(basename).?,
134 .optimize = optimize,
135 .target = .{},
136 });
129137 if (case.link_libc) {
130138 exe.linkSystemLibrary("c");
131139 }
......@@ -139,13 +147,20 @@ pub const CompareOutputContext = struct {
139147 }
140148 },
141149 Special.RuntimeSafety => {
150 // TODO iterate over self.optimize_modes and test this in both
151 // debug and release safe mode
142152 const annotated_case_name = fmt.allocPrint(self.b.allocator, "safety {s}", .{case.name}) catch unreachable;
143153 if (self.test_filter) |filter| {
144154 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
145155 }
146156
147157 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 });
149164 if (case.link_libc) {
150165 exe.linkSystemLibrary("c");
151166 }
test/src/run_translated_c.zig+6-3
......@@ -85,11 +85,14 @@ pub const RunTranslatedCContext = struct {
8585 for (case.sources.items) |src_file| {
8686 write_src.add(src_file.filename, src_file.source);
8787 }
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 });
8993
9094 translate_c.step.name = b.fmt("{s} translate-c", .{annotated_case_name});
91 const exe = translate_c.addExecutable();
92 exe.setTarget(self.target);
95 const exe = translate_c.addExecutable(.{});
9396 exe.step.name = b.fmt("{s} build-exe", .{annotated_case_name});
9497 exe.linkLibC();
9598 const run = exe.run();
test/src/translate_c.zig+5-2
......@@ -108,10 +108,13 @@ pub const TranslateCContext = struct {
108108 write_src.add(src_file.filename, src_file.source);
109109 }
110110
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 });
112116
113117 translate_c.step.name = annotated_case_name;
114 translate_c.setTarget(case.target);
115118
116119 const check_file = translate_c.addCheckFile(case.expected_lines.items);
117120
test/standalone/brace_expansion/build.zig+4-2
......@@ -1,8 +1,10 @@
11const Builder = @import("std").build.Builder;
22
33pub fn build(b: *Builder) void {
4 const main = b.addTest("main.zig");
5 main.setBuildMode(b.standardReleaseOptions());
4 const main = b.addTest(.{
5 .root_source_file = .{ .path = "main.zig" },
6 .optimize = b.standardOptimizeOption(.{}),
7 });
68
79 const test_step = b.step("test", "Test it");
810 test_step.dependOn(&main.step);
test/standalone/c_compiler/build.zig+11-7
......@@ -12,23 +12,27 @@ fn isRunnableTarget(t: CrossTarget) bool {
1212}
1313
1414pub fn build(b: *Builder) void {
15 const mode = b.standardReleaseOptions();
15 const optimize = b.standardOptimizeOption(.{});
1616 const target = b.standardTargetOptions(.{});
1717
1818 const test_step = b.step("test", "Test the program");
1919
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 });
2125 b.default_step.dependOn(&exe_c.step);
2226 exe_c.addCSourceFile("test.c", &[0][]const u8{});
23 exe_c.setBuildMode(mode);
24 exe_c.setTarget(target);
2527 exe_c.linkLibC();
2628
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 });
2834 b.default_step.dependOn(&exe_cpp.step);
2935 exe_cpp.addCSourceFile("test.cpp", &[0][]const u8{});
30 exe_cpp.setBuildMode(mode);
31 exe_cpp.setTarget(target);
3236 exe_cpp.linkLibCpp();
3337
3438 switch (target.getOsTag()) {
test/standalone/emit_asm_and_bin/build.zig+4-2
......@@ -1,8 +1,10 @@
11const Builder = @import("std").build.Builder;
22
33pub fn build(b: *Builder) void {
4 const main = b.addTest("main.zig");
5 main.setBuildMode(b.standardReleaseOptions());
4 const main = b.addTest(.{
5 .root_source_file = .{ .path = "main.zig" },
6 .optimize = b.standardOptimizeOption(.{}),
7 });
68 main.emit_asm = .{ .emit_to = b.pathFromRoot("main.s") };
79 main.emit_bin = .{ .emit_to = b.pathFromRoot("main") };
810
test/standalone/empty_env/build.zig+5-2
......@@ -1,8 +1,11 @@
11const Builder = @import("std").build.Builder;
22
33pub fn build(b: *Builder) void {
4 const main = b.addExecutable("main", "main.zig");
5 main.setBuildMode(b.standardReleaseOptions());
4 const main = b.addExecutable(.{
5 .name = "main",
6 .root_source_file = .{ .path = "main.zig" },
7 .optimize = b.standardOptimizeOption(.{}),
8 });
69
710 const run = main.run();
811 run.clearEnvironment();
test/standalone/global_linkage/build.zig+17-7
......@@ -1,16 +1,26 @@
11const Builder = @import("std").build.Builder;
22
33pub fn build(b: *Builder) void {
4 const mode = b.standardReleaseOptions();
4 const optimize = b.standardOptimizeOption(.{});
55
6 const obj1 = b.addStaticLibrary("obj1", "obj1.zig");
7 obj1.setBuildMode(mode);
6 const obj1 = b.addStaticLibrary(.{
7 .name = "obj1",
8 .root_source_file = .{ .path = "obj1.zig" },
9 .optimize = optimize,
10 .target = .{},
11 });
812
9 const obj2 = b.addStaticLibrary("obj2", "obj2.zig");
10 obj2.setBuildMode(mode);
13 const obj2 = b.addStaticLibrary(.{
14 .name = "obj2",
15 .root_source_file = .{ .path = "obj2.zig" },
16 .optimize = optimize,
17 .target = .{},
18 });
1119
12 const main = b.addTest("main.zig");
13 main.setBuildMode(mode);
20 const main = b.addTest(.{
21 .root_source_file = .{ .path = "main.zig" },
22 .optimize = optimize,
23 });
1424 main.linkLibrary(obj1);
1525 main.linkLibrary(obj2);
1626
test/standalone/install_raw_hex/build.zig+7-4
......@@ -10,11 +10,14 @@ pub fn build(b: *std.build.Builder) void {
1010 .abi = .gnueabihf,
1111 };
1212
13 const mode = b.standardReleaseOptions();
13 const optimize = b.standardOptimizeOption(.{});
1414
15 const elf = b.addExecutable("zig-nrf52-blink.elf", "main.zig");
16 elf.setTarget(target);
17 elf.setBuildMode(mode);
15 const elf = b.addExecutable(.{
16 .name = "zig-nrf52-blink.elf",
17 .root_source_file = .{ .path = "main.zig" },
18 .target = target,
19 .optimize = optimize,
20 });
1821
1922 const test_step = b.step("test", "Test the program");
2023 b.default_step.dependOn(test_step);
test/standalone/issue_11595/build.zig+7-4
......@@ -12,11 +12,15 @@ fn isRunnableTarget(t: CrossTarget) bool {
1212}
1313
1414pub fn build(b: *Builder) void {
15 const mode = b.standardReleaseOptions();
15 const optimize = b.standardOptimizeOption(.{});
1616 const target = b.standardTargetOptions(.{});
1717
18 const exe = b.addExecutable("zigtest", "main.zig");
19 exe.setBuildMode(mode);
18 const exe = b.addExecutable(.{
19 .name = "zigtest",
20 .root_source_file = .{ .path = "main.zig" },
21 .target = target,
22 .optimize = optimize,
23 });
2024 exe.install();
2125
2226 const c_sources = [_][]const u8{
......@@ -39,7 +43,6 @@ pub fn build(b: *Builder) void {
3943 exe.defineCMacro("QUX", "\"Q\" \"UX\"");
4044 exe.defineCMacro("QUUX", "\"QU\\\"UX\"");
4145
42 exe.setTarget(target);
4346 b.default_step.dependOn(&exe.step);
4447
4548 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");
22const Builder = std.build.Builder;
33
44pub fn build(b: *Builder) void {
5 const mode = b.standardReleaseOptions();
5 const optimize = b.standardOptimizeOption(.{});
66 const target = b.standardTargetOptions(.{});
77
8 const obj = b.addObject("main", "main.zig");
9 obj.setBuildMode(mode);
10 obj.setTarget(target);
8 const obj = b.addObject(.{
9 .name = "main",
10 .root_source_file = .{ .path = "main.zig" },
11 .optimize = optimize,
12 .target = target,
13 });
1114 obj.emit_llvm_ir = .{ .emit_to = b.pathFromRoot("main.ll") };
1215 obj.emit_llvm_bc = .{ .emit_to = b.pathFromRoot("main.bc") };
1316 obj.emit_bin = .no_emit;
test/standalone/issue_12706/build.zig+7-4
......@@ -12,11 +12,15 @@ fn isRunnableTarget(t: CrossTarget) bool {
1212}
1313
1414pub fn build(b: *Builder) void {
15 const mode = b.standardReleaseOptions();
15 const optimize = b.standardOptimizeOption(.{});
1616 const target = b.standardTargetOptions(.{});
1717
18 const exe = b.addExecutable("main", "main.zig");
19 exe.setBuildMode(mode);
18 const exe = b.addExecutable(.{
19 .name = "main",
20 .root_source_file = .{ .path = "main.zig" },
21 .optimize = optimize,
22 .target = target,
23 });
2024 exe.install();
2125
2226 const c_sources = [_][]const u8{
......@@ -26,7 +30,6 @@ pub fn build(b: *Builder) void {
2630 exe.addCSourceFiles(&c_sources, &.{});
2731 exe.linkLibC();
2832
29 exe.setTarget(target);
3033 b.default_step.dependOn(&exe.step);
3134
3235 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;
44const CrossTarget = std.zig.CrossTarget;
55
66pub fn build(b: *Builder) void {
7 const mode = b.standardReleaseOptions();
7 const optimize = b.standardOptimizeOption(.{});
88 const target = b.standardTargetOptions(.{});
99
10 const obj = b.addObject("main", "main.zig");
11 obj.setBuildMode(mode);
12
13 obj.setTarget(target);
10 const obj = b.addObject(.{
11 .name = "main",
12 .root_source_file = .{ .path = "main.zig" },
13 .optimize = optimize,
14 .target = target,
15 });
1416 b.default_step.dependOn(&obj.step);
1517
1618 const test_step = b.step("test", "Test the program");
test/standalone/issue_339/build.zig+6-1
......@@ -1,7 +1,12 @@
11const Builder = @import("std").build.Builder;
22
33pub 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 });
510
611 const test_step = b.step("test", "Test the program");
712 test_step.dependOn(&obj.step);
test/standalone/issue_5825/build.zig+12-7
......@@ -6,17 +6,22 @@ pub fn build(b: *Builder) void {
66 .os_tag = .windows,
77 .abi = .msvc,
88 };
9 const mode = b.standardReleaseOptions();
10 const obj = b.addObject("issue_5825", "main.zig");
11 obj.setTarget(target);
12 obj.setBuildMode(mode);
9 const optimize = b.standardOptimizeOption(.{});
10 const obj = b.addObject(.{
11 .name = "issue_5825",
12 .root_source_file = .{ .path = "main.zig" },
13 .optimize = optimize,
14 .target = target,
15 });
1316
14 const exe = b.addExecutable("issue_5825", null);
17 const exe = b.addExecutable(.{
18 .name = "issue_5825",
19 .optimize = optimize,
20 .target = target,
21 });
1522 exe.subsystem = .Console;
1623 exe.linkSystemLibrary("kernel32");
1724 exe.linkSystemLibrary("ntdll");
18 exe.setTarget(target);
19 exe.setBuildMode(mode);
2025 exe.addObject(obj);
2126
2227 const test_step = b.step("test", "Test the program");
test/standalone/issue_7030/build.zig+7-4
......@@ -1,10 +1,13 @@
11const Builder = @import("std").build.Builder;
22
33pub fn build(b: *Builder) void {
4 const exe = b.addExecutable("issue_7030", "main.zig");
5 exe.setTarget(.{
6 .cpu_arch = .wasm32,
7 .os_tag = .freestanding,
4 const exe = b.addExecutable(.{
5 .name = "issue_7030",
6 .root_source_file = .{ .path = "main.zig" },
7 .target = .{
8 .cpu_arch = .wasm32,
9 .os_tag = .freestanding,
10 },
811 });
912 exe.install();
1013 b.default_step.dependOn(&exe.step);
test/standalone/issue_794/build.zig+3-1
......@@ -1,7 +1,9 @@
11const Builder = @import("std").build.Builder;
22
33pub 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 });
57 test_artifact.addIncludePath("a_directory");
68
79 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 {
88 .explicit = &std.Target.arm.cpu.arm1176jz_s,
99 },
1010 };
11 const mode = b.standardReleaseOptions();
12 const kernel = b.addExecutable("kernel", "./main.zig");
11 const optimize = b.standardOptimizeOption(.{});
12 const kernel = b.addExecutable(.{
13 .name = "kernel",
14 .root_source_file = .{ .path = "./main.zig" },
15 .optimize = optimize,
16 .target = target,
17 });
1318 kernel.addObjectFile("./boot.S");
1419 kernel.setLinkerScriptPath(.{ .path = "./linker.ld" });
15 kernel.setBuildMode(mode);
16 kernel.setTarget(target);
1720 kernel.install();
1821
1922 const test_step = b.step("test", "Test it");
test/standalone/issue_9812/build.zig+5-3
......@@ -1,9 +1,11 @@
11const std = @import("std");
22
33pub fn build(b: *std.build.Builder) !void {
4 const mode = b.standardReleaseOptions();
5 const zip_add = b.addTest("main.zig");
6 zip_add.setBuildMode(mode);
4 const optimize = b.standardOptimizeOption(.{});
5 const zip_add = b.addTest(.{
6 .root_source_file = .{ .path = "main.zig" },
7 .optimize = optimize,
8 });
79 zip_add.addCSourceFile("vendor/kuba-zip/zip.c", &[_][]const u8{
810 "-std=c99",
911 "-fno-sanitize=undefined",
test/standalone/load_dynamic_library/build.zig+15-5
......@@ -1,13 +1,23 @@
11const Builder = @import("std").build.Builder;
22
33pub fn build(b: *Builder) void {
4 const opts = b.standardReleaseOptions();
4 const target = b.standardTargetOptions(.{});
5 const optimize = b.standardOptimizeOption(.{});
56
6 const lib = b.addSharedLibrary("add", "add.zig", b.version(1, 0, 0));
7 lib.setBuildMode(opts);
7 const lib = b.addSharedLibrary(.{
8 .name = "add",
9 .root_source_file = .{ .path = "add.zig" },
10 .version = .{ .major = 1, .minor = 0 },
11 .optimize = optimize,
12 .target = target,
13 });
814
9 const main = b.addExecutable("main", "main.zig");
10 main.setBuildMode(opts);
15 const main = b.addExecutable(.{
16 .name = "main",
17 .root_source_file = .{ .path = "main.zig" },
18 .optimize = optimize,
19 .target = target,
20 });
1121
1222 const run = main.run();
1323 run.addArtifactArg(lib);
test/standalone/main_pkg_path/build.zig+3-1
......@@ -1,7 +1,9 @@
11const Builder = @import("std").build.Builder;
22
33pub 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 });
57 test_exe.setMainPkgPath(".");
68
79 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 {
1212}
1313
1414pub fn build(b: *Builder) void {
15 const mode = b.standardReleaseOptions();
15 const optimize = b.standardOptimizeOption(.{});
1616 const target = b.standardTargetOptions(.{});
1717
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 });
1924 exe.addCSourceFile("test.c", &[_][]const u8{"-std=c11"});
20 exe.setBuildMode(mode);
2125 exe.linkLibC();
22 exe.setTarget(target);
2326 b.default_step.dependOn(&exe.step);
2427
2528 const test_step = b.step("test", "Test the program");
test/standalone/mix_o_files/build.zig+12-2
......@@ -1,9 +1,19 @@
11const Builder = @import("std").build.Builder;
22
33pub fn build(b: *Builder) void {
4 const obj = b.addObject("base64", "base64.zig");
4 const optimize = b.standardOptimizeOption(.{});
55
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 });
717 exe.addCSourceFile("test.c", &[_][]const u8{"-std=c99"});
818 exe.addObject(obj);
919 exe.linkSystemLibrary("c");
test/standalone/options/build.zig+6-4
......@@ -2,11 +2,13 @@ const std = @import("std");
22
33pub fn build(b: *std.build.Builder) void {
44 const target = b.standardTargetOptions(.{});
5 const mode = b.standardReleaseOptions();
5 const optimize = b.standardOptimizeOption(.{});
66
7 const main = b.addTest("src/main.zig");
8 main.setTarget(target);
9 main.setBuildMode(mode);
7 const main = b.addTest(.{
8 .root_source_file = .{ .path = "src/main.zig" },
9 .target = target,
10 .optimize = optimize,
11 });
1012
1113 const options = b.addOptions();
1214 main.addOptions("build_options", options);
test/standalone/pie/build.zig+4-2
......@@ -1,8 +1,10 @@
11const Builder = @import("std").build.Builder;
22
33pub fn build(b: *Builder) void {
4 const main = b.addTest("main.zig");
5 main.setBuildMode(b.standardReleaseOptions());
4 const main = b.addTest(.{
5 .root_source_file = .{ .path = "main.zig" },
6 .optimize = b.standardOptimizeOption(.{}),
7 });
68 main.pie = true;
79
810 const test_step = b.step("test", "Test the program");
test/standalone/pkg_import/build.zig+7-6
......@@ -1,13 +1,14 @@
11const Builder = @import("std").build.Builder;
22
33pub fn build(b: *Builder) void {
4 const exe = b.addExecutable("test", "test.zig");
5 exe.addPackagePath("my_pkg", "pkg.zig");
4 const optimize = b.standardOptimizeOption(.{});
65
7 // This is duplicated to test that you are allowed to call
8 // b.standardReleaseOptions() twice.
9 exe.setBuildMode(b.standardReleaseOptions());
10 exe.setBuildMode(b.standardReleaseOptions());
6 const exe = b.addExecutable(.{
7 .name = "test",
8 .root_source_file = .{ .path = "test.zig" },
9 .optimize = optimize,
10 });
11 exe.addPackagePath("my_pkg", "pkg.zig");
1112
1213 const run = exe.run();
1314
test/standalone/shared_library/build.zig+13-4
......@@ -1,12 +1,21 @@
11const Builder = @import("std").build.Builder;
22
33pub fn build(b: *Builder) void {
4 const optimize = b.standardOptimizeOption(.{});
45 const target = b.standardTargetOptions(.{});
5 const lib = b.addSharedLibrary("mathtest", "mathtest.zig", b.version(1, 0, 0));
6 lib.setTarget(target);
6 const lib = b.addSharedLibrary(.{
7 .name = "mathtest",
8 .root_source_file = .{ .path = "mathtest.zig" },
9 .version = .{ .major = 1, .minor = 0 },
10 .target = target,
11 .optimize = optimize,
12 });
713
8 const exe = b.addExecutable("test", null);
9 exe.setTarget(target);
14 const exe = b.addExecutable(.{
15 .name = "test",
16 .target = target,
17 .optimize = optimize,
18 });
1019 exe.addCSourceFile("test.c", &[_][]const u8{"-std=c99"});
1120 exe.linkLibrary(lib);
1221 exe.linkSystemLibrary("c");
test/standalone/static_c_lib/build.zig+10-5
......@@ -1,15 +1,20 @@
11const Builder = @import("std").build.Builder;
22
33pub fn build(b: *Builder) void {
4 const mode = b.standardReleaseOptions();
4 const optimize = b.standardOptimizeOption(.{});
55
6 const foo = b.addStaticLibrary("foo", null);
6 const foo = b.addStaticLibrary(.{
7 .name = "foo",
8 .optimize = optimize,
9 .target = .{},
10 });
711 foo.addCSourceFile("foo.c", &[_][]const u8{});
8 foo.setBuildMode(mode);
912 foo.addIncludePath(".");
1013
11 const test_exe = b.addTest("foo.zig");
12 test_exe.setBuildMode(mode);
14 const test_exe = b.addTest(.{
15 .root_source_file = .{ .path = "foo.zig" },
16 .optimize = optimize,
17 });
1318 test_exe.linkLibrary(foo);
1419 test_exe.addIncludePath(".");
1520
test/standalone/test_runner_path/build.zig+4-1
......@@ -1,7 +1,10 @@
11const Builder = @import("std").build.Builder;
22
33pub 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 });
58 test_exe.test_runner = "test_runner.zig";
69
710 const test_run = test_exe.run();
test/standalone/use_alias/build.zig+4-2
......@@ -1,8 +1,10 @@
11const Builder = @import("std").build.Builder;
22
33pub fn build(b: *Builder) void {
4 const main = b.addTest("main.zig");
5 main.setBuildMode(b.standardReleaseOptions());
4 const main = b.addTest(.{
5 .root_source_file = .{ .path = "main.zig" },
6 .optimize = b.standardOptimizeOption(.{}),
7 });
68 main.addIncludePath(".");
79
810 const test_step = b.step("test", "Test it");
test/standalone/windows_spawn/build.zig+12-5
......@@ -1,13 +1,20 @@
11const Builder = @import("std").build.Builder;
22
33pub fn build(b: *Builder) void {
4 const mode = b.standardReleaseOptions();
4 const optimize = b.standardOptimizeOption(.{});
55
6 const hello = b.addExecutable("hello", "hello.zig");
7 hello.setBuildMode(mode);
6 const hello = b.addExecutable(.{
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 });
817
9 const main = b.addExecutable("main", "main.zig");
10 main.setBuildMode(mode);
1118 const run = main.run();
1219 run.addArtifactArg(hello);
1320
test/tests.zig+86-70
......@@ -8,7 +8,7 @@ const fs = std.fs;
88const mem = std.mem;
99const fmt = std.fmt;
1010const ArrayList = std.ArrayList;
11const Mode = std.builtin.Mode;
11const OptimizeMode = std.builtin.OptimizeMode;
1212const LibExeObjStep = build.LibExeObjStep;
1313const Allocator = mem.Allocator;
1414const ExecError = build.Builder.ExecError;
......@@ -30,7 +30,7 @@ pub const CompareOutputContext = @import("src/compare_output.zig").CompareOutput
3030
3131const TestTarget = struct {
3232 target: CrossTarget = @as(CrossTarget, .{}),
33 mode: std.builtin.Mode = .Debug,
33 optimize_mode: std.builtin.OptimizeMode = .Debug,
3434 link_libc: bool = false,
3535 single_threaded: bool = false,
3636 disable_native: bool = false,
......@@ -423,38 +423,38 @@ const test_targets = blk: {
423423
424424 // Do the release tests last because they take a long time
425425 .{
426 .mode = .ReleaseFast,
426 .optimize_mode = .ReleaseFast,
427427 },
428428 .{
429429 .link_libc = true,
430 .mode = .ReleaseFast,
430 .optimize_mode = .ReleaseFast,
431431 },
432432 .{
433 .mode = .ReleaseFast,
433 .optimize_mode = .ReleaseFast,
434434 .single_threaded = true,
435435 },
436436
437437 .{
438 .mode = .ReleaseSafe,
438 .optimize_mode = .ReleaseSafe,
439439 },
440440 .{
441441 .link_libc = true,
442 .mode = .ReleaseSafe,
442 .optimize_mode = .ReleaseSafe,
443443 },
444444 .{
445 .mode = .ReleaseSafe,
445 .optimize_mode = .ReleaseSafe,
446446 .single_threaded = true,
447447 },
448448
449449 .{
450 .mode = .ReleaseSmall,
450 .optimize_mode = .ReleaseSmall,
451451 },
452452 .{
453453 .link_libc = true,
454 .mode = .ReleaseSmall,
454 .optimize_mode = .ReleaseSmall,
455455 },
456456 .{
457 .mode = .ReleaseSmall,
457 .optimize_mode = .ReleaseSmall,
458458 .single_threaded = true,
459459 },
460460 };
......@@ -462,14 +462,14 @@ const test_targets = blk: {
462462
463463const max_stdout_size = 1 * 1024 * 1024; // 1 MB
464464
465pub fn addCompareOutputTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step {
465pub fn addCompareOutputTests(b: *build.Builder, test_filter: ?[]const u8, optimize_modes: []const OptimizeMode) *build.Step {
466466 const cases = b.allocator.create(CompareOutputContext) catch unreachable;
467467 cases.* = CompareOutputContext{
468468 .b = b,
469469 .step = b.step("test-compare-output", "Run the compare output tests"),
470470 .test_index = 0,
471471 .test_filter = test_filter,
472 .modes = modes,
472 .optimize_modes = optimize_modes,
473473 };
474474
475475 compare_output.addCases(cases);
......@@ -477,14 +477,14 @@ pub fn addCompareOutputTests(b: *build.Builder, test_filter: ?[]const u8, modes:
477477 return cases.step;
478478}
479479
480pub fn addStackTraceTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step {
480pub fn addStackTraceTests(b: *build.Builder, test_filter: ?[]const u8, optimize_modes: []const OptimizeMode) *build.Step {
481481 const cases = b.allocator.create(StackTracesContext) catch unreachable;
482482 cases.* = StackTracesContext{
483483 .b = b,
484484 .step = b.step("test-stack-traces", "Run the stack trace tests"),
485485 .test_index = 0,
486486 .test_filter = test_filter,
487 .modes = modes,
487 .optimize_modes = optimize_modes,
488488 };
489489
490490 stack_traces.addCases(cases);
......@@ -495,7 +495,7 @@ pub fn addStackTraceTests(b: *build.Builder, test_filter: ?[]const u8, modes: []
495495pub fn addStandaloneTests(
496496 b: *build.Builder,
497497 test_filter: ?[]const u8,
498 modes: []const Mode,
498 optimize_modes: []const OptimizeMode,
499499 skip_non_native: bool,
500500 enable_macos_sdk: bool,
501501 target: std.zig.CrossTarget,
......@@ -513,7 +513,7 @@ pub fn addStandaloneTests(
513513 .step = b.step("test-standalone", "Run the standalone tests"),
514514 .test_index = 0,
515515 .test_filter = test_filter,
516 .modes = modes,
516 .optimize_modes = optimize_modes,
517517 .skip_non_native = skip_non_native,
518518 .enable_macos_sdk = enable_macos_sdk,
519519 .target = target,
......@@ -534,7 +534,7 @@ pub fn addStandaloneTests(
534534pub fn addLinkTests(
535535 b: *build.Builder,
536536 test_filter: ?[]const u8,
537 modes: []const Mode,
537 optimize_modes: []const OptimizeMode,
538538 enable_macos_sdk: bool,
539539 omit_stage2: bool,
540540 enable_symlinks_windows: bool,
......@@ -545,7 +545,7 @@ pub fn addLinkTests(
545545 .step = b.step("test-link", "Run the linker tests"),
546546 .test_index = 0,
547547 .test_filter = test_filter,
548 .modes = modes,
548 .optimize_modes = optimize_modes,
549549 .skip_non_native = true,
550550 .enable_macos_sdk = enable_macos_sdk,
551551 .target = .{},
......@@ -556,12 +556,17 @@ pub fn addLinkTests(
556556 return cases.step;
557557}
558558
559pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step {
559pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, optimize_modes: []const OptimizeMode) *build.Step {
560560 _ = test_filter;
561 _ = modes;
561 _ = optimize_modes;
562562 const step = b.step("test-cli", "Test the command line interface");
563563
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 });
565570 const run_cmd = exe.run();
566571 run_cmd.addArgs(&[_][]const u8{
567572 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
572577 return step;
573578}
574579
575pub fn addAssembleAndLinkTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step {
580pub fn addAssembleAndLinkTests(b: *build.Builder, test_filter: ?[]const u8, optimize_modes: []const OptimizeMode) *build.Step {
576581 const cases = b.allocator.create(CompareOutputContext) catch unreachable;
577582 cases.* = CompareOutputContext{
578583 .b = b,
579584 .step = b.step("test-asm-link", "Run the assemble and link tests"),
580585 .test_index = 0,
581586 .test_filter = test_filter,
582 .modes = modes,
587 .optimize_modes = optimize_modes,
583588 };
584589
585590 assemble_and_link.addCases(cases);
......@@ -640,7 +645,7 @@ pub fn addPkgTests(
640645 root_src: []const u8,
641646 name: []const u8,
642647 desc: []const u8,
643 modes: []const Mode,
648 optimize_modes: []const OptimizeMode,
644649 skip_single_threaded: bool,
645650 skip_non_native: bool,
646651 skip_libc: bool,
......@@ -677,8 +682,8 @@ pub fn addPkgTests(
677682 else => if (skip_stage2) continue,
678683 };
679684
680 const want_this_mode = for (modes) |m| {
681 if (m == test_target.mode) break true;
685 const want_this_mode = for (optimize_modes) |m| {
686 if (m == test_target.optimize_mode) break true;
682687 } else false;
683688 if (!want_this_mode) continue;
684689
......@@ -691,21 +696,23 @@ pub fn addPkgTests(
691696
692697 const triple_prefix = test_target.target.zigTriple(b.allocator) catch unreachable;
693698
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 });
695704 const single_threaded_txt = if (test_target.single_threaded) "single" else "multi";
696705 const backend_txt = if (test_target.backend) |backend| @tagName(backend) else "default";
697706 these_tests.setNamePrefix(b.fmt("{s}-{s}-{s}-{s}-{s}-{s} ", .{
698707 name,
699708 triple_prefix,
700 @tagName(test_target.mode),
709 @tagName(test_target.optimize_mode),
701710 libc_prefix,
702711 single_threaded_txt,
703712 backend_txt,
704713 }));
705714 these_tests.single_threaded = test_target.single_threaded;
706715 these_tests.setFilter(test_filter);
707 these_tests.setBuildMode(test_target.mode);
708 these_tests.setTarget(test_target.target);
709716 if (test_target.link_libc) {
710717 these_tests.linkSystemLibrary("c");
711718 }
......@@ -739,9 +746,9 @@ pub const StackTracesContext = struct {
739746 step: *build.Step,
740747 test_index: usize,
741748 test_filter: ?[]const u8,
742 modes: []const Mode,
749 optimize_modes: []const OptimizeMode,
743750
744 const Expect = [@typeInfo(Mode).Enum.fields.len][]const u8;
751 const Expect = [@typeInfo(OptimizeMode).Enum.fields.len][]const u8;
745752
746753 pub fn addCase(self: *StackTracesContext, config: anytype) void {
747754 if (@hasField(@TypeOf(config), "exclude")) {
......@@ -755,26 +762,26 @@ pub const StackTracesContext = struct {
755762 const exclude_os: []const std.Target.Os.Tag = &config.exclude_os;
756763 for (exclude_os) |os| if (os == builtin.os.tag) return;
757764 }
758 for (self.modes) |mode| {
759 switch (mode) {
765 for (self.optimize_modes) |optimize_mode| {
766 switch (optimize_mode) {
760767 .Debug => {
761768 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);
763770 }
764771 },
765772 .ReleaseSafe => {
766773 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);
768775 }
769776 },
770777 .ReleaseFast => {
771778 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);
773780 }
774781 },
775782 .ReleaseSmall => {
776783 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);
778785 }
779786 },
780787 }
......@@ -785,7 +792,7 @@ pub const StackTracesContext = struct {
785792 self: *StackTracesContext,
786793 name: []const u8,
787794 source: []const u8,
788 mode: Mode,
795 optimize_mode: OptimizeMode,
789796 mode_config: anytype,
790797 ) void {
791798 if (@hasField(@TypeOf(mode_config), "exclude")) {
......@@ -803,7 +810,7 @@ pub const StackTracesContext = struct {
803810 const annotated_case_name = fmt.allocPrint(self.b.allocator, "{s} {s} ({s})", .{
804811 "stack-trace",
805812 name,
806 @tagName(mode),
813 @tagName(optimize_mode),
807814 }) catch unreachable;
808815 if (self.test_filter) |filter| {
809816 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
......@@ -812,14 +819,18 @@ pub const StackTracesContext = struct {
812819 const b = self.b;
813820 const src_basename = "source.zig";
814821 const write_src = b.addWriteFile(src_basename, source);
815 const exe = b.addExecutableSource("test", write_src.getFileSource(src_basename).?);
816 exe.setBuildMode(mode);
822 const exe = b.addExecutable(.{
823 .name = "test",
824 .root_source_file = write_src.getFileSource(src_basename).?,
825 .optimize = optimize_mode,
826 .target = .{},
827 });
817828
818829 const run_and_compare = RunAndCompareStep.create(
819830 self,
820831 exe,
821832 annotated_case_name,
822 mode,
833 optimize_mode,
823834 mode_config.expect,
824835 );
825836
......@@ -833,7 +844,7 @@ pub const StackTracesContext = struct {
833844 context: *StackTracesContext,
834845 exe: *LibExeObjStep,
835846 name: []const u8,
836 mode: Mode,
847 optimize_mode: OptimizeMode,
837848 expect_output: []const u8,
838849 test_index: usize,
839850
......@@ -841,7 +852,7 @@ pub const StackTracesContext = struct {
841852 context: *StackTracesContext,
842853 exe: *LibExeObjStep,
843854 name: []const u8,
844 mode: Mode,
855 optimize_mode: OptimizeMode,
845856 expect_output: []const u8,
846857 ) *RunAndCompareStep {
847858 const allocator = context.b.allocator;
......@@ -851,7 +862,7 @@ pub const StackTracesContext = struct {
851862 .context = context,
852863 .exe = exe,
853864 .name = name,
854 .mode = mode,
865 .optimize_mode = optimize_mode,
855866 .expect_output = expect_output,
856867 .test_index = context.test_index,
857868 };
......@@ -932,7 +943,7 @@ pub const StackTracesContext = struct {
932943 // process result
933944 // - keep only basename of source file path
934945 // - 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
936947 // - skip empty lines
937948 const got: []const u8 = got_result: {
938949 var buf = ArrayList(u8).init(b.allocator);
......@@ -968,7 +979,7 @@ pub const StackTracesContext = struct {
968979 // emit substituted line
969980 try buf.appendSlice(line[pos + 1 .. marks[2] + delims[2].len]);
970981 try buf.appendSlice(" [address]");
971 if (self.mode == .Debug) {
982 if (self.optimize_mode == .Debug) {
972983 // On certain platforms (windows) or possibly depending on how we choose to link main
973984 // the object file extension may be present so we simply strip any extension.
974985 if (mem.indexOfScalar(u8, line[marks[4]..marks[5]], '.')) |idot| {
......@@ -1007,7 +1018,7 @@ pub const StandaloneContext = struct {
10071018 step: *build.Step,
10081019 test_index: usize,
10091020 test_filter: ?[]const u8,
1010 modes: []const Mode,
1021 optimize_modes: []const OptimizeMode,
10111022 skip_non_native: bool,
10121023 enable_macos_sdk: bool,
10131024 target: std.zig.CrossTarget,
......@@ -1087,13 +1098,13 @@ pub const StandaloneContext = struct {
10871098 }
10881099 }
10891100
1090 const modes = if (features.build_modes) self.modes else &[1]Mode{.Debug};
1091 for (modes) |mode| {
1092 const arg = switch (mode) {
1101 const optimize_modes = if (features.build_modes) self.optimize_modes else &[1]OptimizeMode{.Debug};
1102 for (optimize_modes) |optimize_mode| {
1103 const arg = switch (optimize_mode) {
10931104 .Debug => "",
1094 .ReleaseFast => "-Drelease-fast",
1095 .ReleaseSafe => "-Drelease-safe",
1096 .ReleaseSmall => "-Drelease-small",
1105 .ReleaseFast => "-Doptimize=ReleaseFast",
1106 .ReleaseSafe => "-Doptimize=ReleaseSafe",
1107 .ReleaseSmall => "-Doptimize=ReleaseSmall",
10971108 };
10981109 const zig_args_base_len = zig_args.items.len;
10991110 if (arg.len > 0)
......@@ -1101,7 +1112,7 @@ pub const StandaloneContext = struct {
11011112 defer zig_args.resize(zig_args_base_len) catch unreachable;
11021113
11031114 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) });
11051116 log_step.step.dependOn(&run_cmd.step);
11061117
11071118 self.step.dependOn(&log_step.step);
......@@ -1111,17 +1122,21 @@ pub const StandaloneContext = struct {
11111122 pub fn addAllArgs(self: *StandaloneContext, root_src: []const u8, link_libc: bool) void {
11121123 const b = self.b;
11131124
1114 for (self.modes) |mode| {
1125 for (self.optimize_modes) |optimize| {
11151126 const annotated_case_name = fmt.allocPrint(self.b.allocator, "build {s} ({s})", .{
11161127 root_src,
1117 @tagName(mode),
1128 @tagName(optimize),
11181129 }) catch unreachable;
11191130 if (self.test_filter) |filter| {
11201131 if (mem.indexOf(u8, annotated_case_name, filter) == null) continue;
11211132 }
11221133
1123 const exe = b.addExecutable("test", root_src);
1124 exe.setBuildMode(mode);
1134 const exe = b.addExecutable(.{
1135 .name = "test",
1136 .root_source_file = .{ .path = root_src },
1137 .optimize = optimize,
1138 .target = .{},
1139 });
11251140 if (link_libc) {
11261141 exe.linkSystemLibrary("c");
11271142 }
......@@ -1247,8 +1262,8 @@ pub const GenHContext = struct {
12471262 pub fn addCase(self: *GenHContext, case: *const TestCase) void {
12481263 const b = self.b;
12491264
1250 const mode = std.builtin.Mode.Debug;
1251 const annotated_case_name = fmt.allocPrint(self.b.allocator, "gen-h {s} ({s})", .{ case.name, @tagName(mode) }) catch unreachable;
1265 const optimize_mode = std.builtin.OptimizeMode.Debug;
1266 const annotated_case_name = fmt.allocPrint(self.b.allocator, "gen-h {s} ({s})", .{ case.name, @tagName(optimize_mode) }) catch unreachable;
12521267 if (self.test_filter) |filter| {
12531268 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
12541269 }
......@@ -1259,7 +1274,7 @@ pub const GenHContext = struct {
12591274 }
12601275
12611276 const obj = b.addObjectFromWriteFileStep("test", write_src, case.sources.items[0].filename);
1262 obj.setBuildMode(mode);
1277 obj.setBuildMode(optimize_mode);
12631278
12641279 const cmp_h = GenHCmpOutputStep.create(self, obj, annotated_case_name, case);
12651280
......@@ -1336,14 +1351,16 @@ const c_abi_targets = [_]CrossTarget{
13361351pub fn addCAbiTests(b: *build.Builder, skip_non_native: bool, skip_release: bool) *build.Step {
13371352 const step = b.step("test-c-abi", "Run the C ABI tests");
13381353
1339 const modes: [2]Mode = .{ .Debug, .ReleaseFast };
1354 const optimize_modes: [2]OptimizeMode = .{ .Debug, .ReleaseFast };
13401355
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| {
13421357 if (skip_non_native and !c_abi_target.isNative())
13431358 continue;
13441359
1345 const test_step = b.addTest("test/c_abi/main.zig");
1346 test_step.setTarget(c_abi_target);
1360 const test_step = b.addTest(.{
1361 .root_source_file = .{ .path = "test/c_abi/main.zig" },
1362 .optimize = optimize_mode,
1363 });
13471364 if (c_abi_target.abi != null and c_abi_target.abi.?.isMusl()) {
13481365 // TODO NativeTargetInfo insists on dynamically linking musl
13491366 // for some reason?
......@@ -1351,7 +1368,6 @@ pub fn addCAbiTests(b: *build.Builder, skip_non_native: bool, skip_release: bool
13511368 }
13521369 test_step.linkLibC();
13531370 test_step.addCSourceFile("test/c_abi/cfuncs.c", &.{"-std=c99"});
1354 test_step.setBuildMode(mode);
13551371
13561372 if (c_abi_target.isWindows() and (c_abi_target.getCpuArch() == .x86 or builtin.target.os.tag == .linux)) {
13571373 // 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
13631379 test_step.setNamePrefix(b.fmt("{s}-{s}-{s} ", .{
13641380 "test-c-abi",
13651381 triple_prefix,
1366 @tagName(mode),
1382 @tagName(optimize_mode),
13671383 }));
13681384
13691385 step.dependOn(&test_step.step);