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 {...@@ -10836,12 +10836,25 @@ pub fn build(b: *std.Build) void {
10836 {#code_begin|syntax|build_library#}10836 {#code_begin|syntax|build_library#}
10837const std = @import("std");10837const 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.
10839pub fn build(b: *std.Build) void {10842pub 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.
10840 const target = b.standardTargetOptions(.{});10847 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.
10841 const optimize = b.standardOptimizeOption(.{});10852 const optimize = b.standardOptimizeOption(.{});
1084210853
10843 const lib = b.addStaticLibrary(.{10854 const lib = b.addStaticLibrary(.{
10844 .name = "example",10855 .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.
10845 .root_source_file = .{ .path = "src/main.zig" },10858 .root_source_file = .{ .path = "src/main.zig" },
10846 .target = target,10859 .target = target,
10847 .optimize = optimize,10860 .optimize = optimize,
...@@ -10852,6 +10865,8 @@ pub fn build(b: *std.Build) void {...@@ -10852,6 +10865,8 @@ pub fn build(b: *std.Build) void {
10852 // running `zig build`).10865 // running `zig build`).
10853 b.installArtifact(lib);10866 b.installArtifact(lib);
1085410867
10868 // Creates a step for unit testing. This only builds the test executable
10869 // but does not run it.
10855 const main_tests = b.addTest(.{10870 const main_tests = b.addTest(.{
10856 .root_source_file = .{ .path = "src/main.zig" },10871 .root_source_file = .{ .path = "src/main.zig" },
10857 .target = target,10872 .target = target,
...@@ -10860,6 +10875,9 @@ pub fn build(b: *std.Build) void {...@@ -10860,6 +10875,9 @@ pub fn build(b: *std.Build) void {
1086010875
10861 const run_main_tests = b.addRunArtifact(main_tests);10876 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".
10863 const test_step = b.step("test", "Run library tests");10881 const test_step = b.step("test", "Run library tests");
10864 test_step.dependOn(&run_main_tests.step);10882 test_step.dependOn(&run_main_tests.step);
10865}10883}