authorgravatar for dbandstra@protonmail.comdbandstra <dbandstra@protonmail.com> 2023-08-06 14:55:57-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-20 04:50:29-04:00
log6822a7a1237d0274ac68b9e713db11c45a737998
tree75e2b6dea1de70028f851b4561a1afbf2753cd0d
parent3c22cecee20d0c01d6c007c4fb8a8903498c66db

langref: bring build.zig examples up to date

Update to match current outputs of init-exe and init-lib.

1 files changed, 18 insertions(+), 0 deletions(-)

doc/langref.html.in+18
......@@ -10836,12 +10836,25 @@ pub fn build(b: *std.Build) void {
1083610836 {#code_begin|syntax|build_library#}
1083710837const std = @import("std");
1083810838
10839// Although this function looks imperative, note that its job is to
10840// declaratively construct a build graph that will be executed by an external
10841// runner.
1083910842pub fn build(b: *std.Build) void {
10843 // Standard target options allows the person running `zig build` to choose
10844 // what target to build for. Here we do not override the defaults, which
10845 // means any target is allowed, and the default is native. Other options
10846 // for restricting supported target set are available.
1084010847 const target = b.standardTargetOptions(.{});
10848
10849 // Standard optimization options allow the person running `zig build` to select
10850 // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
10851 // set a preferred release mode, allowing the user to decide how to optimize.
1084110852 const optimize = b.standardOptimizeOption(.{});
1084210853
1084310854 const lib = b.addStaticLibrary(.{
1084410855 .name = "example",
10856 // In this case the main source file is merely a path, however, in more
10857 // complicated build scripts, this could be a generated file.
1084510858 .root_source_file = .{ .path = "src/main.zig" },
1084610859 .target = target,
1084710860 .optimize = optimize,
......@@ -10852,6 +10865,8 @@ pub fn build(b: *std.Build) void {
1085210865 // running `zig build`).
1085310866 b.installArtifact(lib);
1085410867
10868 // Creates a step for unit testing. This only builds the test executable
10869 // but does not run it.
1085510870 const main_tests = b.addTest(.{
1085610871 .root_source_file = .{ .path = "src/main.zig" },
1085710872 .target = target,
......@@ -10860,6 +10875,9 @@ pub fn build(b: *std.Build) void {
1086010875
1086110876 const run_main_tests = b.addRunArtifact(main_tests);
1086210877
10878 // This creates a build step. It will be visible in the `zig build --help` menu,
10879 // and can be selected like this: `zig build test`
10880 // This will evaluate the `test` step rather than the default, which is "install".
1086310881 const test_step = b.step("test", "Run library tests");
1086410882 test_step.dependOn(&run_main_tests.step);
1086510883}