authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-02-19 18:40:34-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-25 18:54:34-07:00
log9baf02de5f17157c0e79e765b26588ec551f971c
treec45d3fc315c2f716da45cac0c80fd9fb835e5afe
parent612560d0198ab9a6b471e36770eb3718ccc5b57f

Maker: move ScannedConfig to separate file


2 files changed, 208 insertions(+), 202 deletions(-)

lib/compiler/Maker.zig+1-202
...@@ -21,6 +21,7 @@ const Graph = @import("Maker/Graph.zig");...@@ -21,6 +21,7 @@ const Graph = @import("Maker/Graph.zig");
21const Step = @import("Maker/Step.zig");21const Step = @import("Maker/Step.zig");
22const Watch = @import("Maker/Watch.zig");22const Watch = @import("Maker/Watch.zig");
23const WebServer = @import("Maker/WebServer.zig");23const WebServer = @import("Maker/WebServer.zig");
24const ScannedConfig = @import("Maker/ScannedConfig.zig");
2425
25pub const std_options: std.Options = .{26pub const std_options: std.Options = .{
26 .side_channels_mitigations = .none,27 .side_channels_mitigations = .none,
...@@ -1667,205 +1668,3 @@ fn initStdoutWriter(io: Io) *Writer {...@@ -1667,205 +1668,3 @@ fn initStdoutWriter(io: Io) *Writer {
1667 stdout_writer_allocation = Io.File.stdout().writerStreaming(io, &stdio_buffer_allocation);1668 stdout_writer_allocation = Io.File.stdout().writerStreaming(io, &stdio_buffer_allocation);
1668 return &stdout_writer_allocation.interface;1669 return &stdout_writer_allocation.interface;
1669}1670}
1670
1671const ScannedConfig = struct {
1672 configuration: Configuration,
1673 top_level_steps: std.StringArrayHashMapUnmanaged(Configuration.Step.Index),
1674
1675 fn print(sc: *const ScannedConfig, w: *Writer) Writer.Error!void {
1676 const c = &sc.configuration;
1677 var serializer: std.zon.Serializer = .{ .writer = w };
1678 var s = try serializer.beginStruct(.{});
1679
1680 try s.field("default_step", @intFromEnum(c.default_step), .{});
1681 {
1682 var ss = try s.beginStructField("top_level_steps", .{});
1683 for (sc.top_level_steps.keys(), sc.top_level_steps.values()) |name, step| {
1684 try ss.field(name, @intFromEnum(step), .{});
1685 }
1686 try ss.end();
1687 }
1688
1689 try s.end();
1690 }
1691
1692 fn printSteps(sc: *const ScannedConfig, graph: *Graph, w: *Writer) !void {
1693 const arena = graph.arena;
1694 const c = &sc.configuration;
1695 for (sc.top_level_steps.keys(), sc.top_level_steps.values()) |name, step_index| {
1696 const step = step_index.ptr(c);
1697 const decorated_name = if (step_index == c.default_step)
1698 try fmt.allocPrint(arena, "{s} (default)", .{name})
1699 else
1700 name;
1701 const top_level = c.extraData(Configuration.Step.TopLevel, step.extra_index);
1702 const description = top_level.description.slice(c);
1703 try w.print(" {s:<28} {s}\n", .{ decorated_name, description });
1704 }
1705 }
1706
1707 fn printUsage(sc: *const ScannedConfig, graph: *Graph, w: *Writer) !void {
1708 const arena = graph.arena;
1709
1710 try w.print(
1711 \\Usage: {s} build [steps] [options]
1712 \\
1713 \\Steps:
1714 \\
1715 , .{graph.zig_exe});
1716 try printSteps(sc, graph, w);
1717 try w.writeAll(
1718 \\
1719 \\Project-Specific Options:
1720 \\
1721 );
1722
1723 const available_options = sc.configuration.available_options;
1724 if (available_options.len == 0) {
1725 try w.print(" (none)\n", .{});
1726 } else {
1727 for (available_options) |option| {
1728 const name = option.name.slice(&sc.configuration);
1729 const description = option.description.slice(&sc.configuration);
1730 const help = try fmt.allocPrint(arena, " -D{s}=[{t}]", .{ name, option.type });
1731 try w.print("{s:<30} {s}\n", .{ help, description });
1732 if (option.enum_options.slice(&sc.configuration)) |enum_options| {
1733 const padding: [33]u8 = @splat(' ');
1734 try w.writeAll(padding ++ "Supported Values:\n");
1735 for (enum_options) |enum_option_index| {
1736 const enum_option = enum_option_index.slice(&sc.configuration);
1737 try w.print(padding ++ " {s}\n", .{enum_option});
1738 }
1739 }
1740 }
1741 }
1742
1743 try w.writeAll(
1744 \\
1745 \\System Integration Options:
1746 \\ --search-prefix [path] Add a path to look for binaries, libraries, headers
1747 \\ --sysroot [path] Set the system root directory (usually /)
1748 \\ --libc [file] Provide a file which specifies libc paths
1749 \\
1750 \\ --system [pkgdir] Disable package fetching; enable all integrations
1751 \\ -fsys=[name] Enable a system integration
1752 \\ -fno-sys=[name] Disable a system integration
1753 \\
1754 \\ -fdarling, -fno-darling Integration with system-installed Darling to
1755 \\ execute macOS programs on Linux hosts
1756 \\ (default: no)
1757 \\ -fqemu, -fno-qemu Integration with system-installed QEMU to execute
1758 \\ foreign-architecture programs on Linux hosts
1759 \\ (default: no)
1760 \\ --libc-runtimes [path] Enhances QEMU integration by providing dynamic libc
1761 \\ (e.g. glibc or musl) built for multiple foreign
1762 \\ architectures, allowing execution of non-native
1763 \\ programs that link with libc.
1764 \\ -frosetta, -fno-rosetta Rely on Rosetta to execute x86_64 programs on
1765 \\ ARM64 macOS hosts. (default: no)
1766 \\ -fwasmtime, -fno-wasmtime Integration with system-installed wasmtime to
1767 \\ execute WASI binaries. (default: no)
1768 \\ -fwine, -fno-wine Integration with system-installed Wine to execute
1769 \\ Windows programs on Linux hosts. (default: no)
1770 \\
1771 \\ Available System Integrations: Enabled:
1772 \\
1773 );
1774 if (sc.configuration.system_integrations.len == 0) {
1775 try w.writeAll(" (none) -\n");
1776 } else {
1777 for (sc.configuration.system_integrations) |system_integration| {
1778 const name = system_integration.name.slice(&sc.configuration);
1779 const status = switch (system_integration.status) {
1780 .disabled => "no",
1781 .enabled => "yes",
1782 };
1783 try w.print(" {s:<43} {s}\n", .{ name, status });
1784 }
1785 }
1786
1787 try w.writeAll(
1788 \\
1789 \\General Options:
1790 \\ -h, --help Print this help to stdout and exit
1791 \\ -l, --list-steps Print available steps to stdout and exit
1792 \\
1793 \\ -p, --prefix [path] Where to install files (default: zig-out)
1794 \\ --prefix-lib-dir [path] Where to install libraries
1795 \\ --prefix-exe-dir [path] Where to install executables
1796 \\ --prefix-include-dir [path] Where to install C header files
1797 \\ --release[=mode] Request release mode, optionally specifying a
1798 \\ preferred optimization mode: fast, safe, small
1799 \\
1800 \\ --verbose Print commands before executing them
1801 \\ --color [auto|off|on] Enable or disable colored error messages
1802 \\ --error-style [style] Control how build errors are printed
1803 \\ verbose (Default) Report errors with full context
1804 \\ minimal Report errors after summary, excluding context like command lines
1805 \\ verbose_clear Like 'verbose', but clear the terminal at the start of each update
1806 \\ minimal_clear Like 'minimal', but clear the terminal at the start of each update
1807 \\ --multiline-errors [style] Control how multi-line error messages are printed
1808 \\ indent (Default) Indent non-initial lines to align with initial line
1809 \\ newline Include a leading newline so that the error message is on its own lines
1810 \\ none Print as usual so the first line is misaligned
1811 \\ --summary [mode] Control the printing of the build summary
1812 \\ all Print the build summary in its entirety
1813 \\ new Omit cached steps
1814 \\ failures (Default if short-lived) Only print failed steps
1815 \\ line (Default if long-lived) Only print the single-line summary
1816 \\ none Do not print the build summary
1817 \\ -j<N> Limit concurrent jobs (default is to use all CPU cores)
1818 \\ --maxrss <bytes> Limit memory usage (default is to use available memory)
1819 \\ --skip-oom-steps Instead of failing, skip steps that would exceed --maxrss
1820 \\ --test-timeout <timeout> Limit execution time of unit tests, terminating if exceeded.
1821 \\ The timeout must include a unit: ns, us, ms, s, m, h
1822 \\ --watch Continuously rebuild when source files are modified
1823 \\ --debounce <ms> Delay before rebuilding after changed file detected
1824 \\ --webui[=ip] Enable the web interface on the given IP address
1825 \\ --fuzz[=limit] Continuously search for unit test failures with an optional
1826 \\ limit to the max number of iterations. The argument supports
1827 \\ an optional 'K', 'M', or 'G' suffix (e.g. '10K'). Implies
1828 \\ '--webui' when no limit is specified.
1829 \\ --time-report Force full rebuild and provide detailed information on
1830 \\ compilation time of Zig source code (implies '--webui')
1831 \\ -fincremental Enable incremental compilation
1832 \\ -fno-incremental Disable incremental compilation
1833 \\
1834 \\Package Management Options:
1835 \\ --fetch[=mode] Fetch dependency tree (optionally choose laziness) and exit
1836 \\ needed (Default) Lazy dependencies are fetched as needed
1837 \\ all Lazy dependencies are always fetched
1838 \\ --fork=[path] Override one or more projects from dependency tree
1839 \\
1840 \\Advanced Options:
1841 \\ -freference-trace[=num] How many lines of reference trace should be shown per compile error
1842 \\ -fno-reference-trace Disable reference trace
1843 \\ -fallow-so-scripts Allows .so files to be GNU ld scripts
1844 \\ -fno-allow-so-scripts (default) .so files must be ELF files
1845 \\ --error-limit [num] Set the maximum amount of distinct error values
1846 \\ --build-file [file] Override path to build.zig
1847 \\ --cache-dir [path] Override path to local Zig cache directory
1848 \\ --global-cache-dir [path] Override path to global Zig cache directory
1849 \\ --zig-lib-dir [arg] Override path to Zig lib directory
1850 \\ --build-runner [file] Override path to build runner
1851 \\ --seed [integer] For shuffling dependency traversal order (default: random)
1852 \\ --build-id[=style] At a minor link-time expense, embeds a build ID in binaries
1853 \\ fast 8-byte non-cryptographic hash (COFF, ELF, WASM)
1854 \\ sha1, tree 20-byte cryptographic hash (ELF, WASM)
1855 \\ md5 16-byte cryptographic hash (ELF)
1856 \\ uuid 16-byte random UUID (ELF, WASM)
1857 \\ 0x[hexstring] Constant ID, maximum 32 bytes (ELF, WASM)
1858 \\ none (default) No build ID
1859 \\ --debug-log [scope] Enable debugging the compiler
1860 \\ --debug-pkg-config Fail if unknown pkg-config flags encountered
1861 \\ --debug-rt Debug compiler runtime libraries
1862 \\ --verbose-link Enable compiler debug output for linking
1863 \\ --verbose-air Enable compiler debug output for Zig AIR
1864 \\ --verbose-llvm-ir Enable compiler debug output for LLVM IR
1865 \\ --verbose-cimport Enable compiler debug output for C imports
1866 \\ --verbose-cc Enable compiler debug output for C compilation
1867 \\ --verbose-llvm-cpu-features Enable compiler debug output for LLVM CPU features
1868 \\
1869 );
1870 }
1871};
lib/compiler/Maker/ScannedConfig.zig created+207
...@@ -0,0 +1,207 @@
1const ScannedConfig = @This();
2
3const std = @import("std");
4const Configuration = std.Build.Configuration;
5const Writer = std.Io.Writer;
6
7const Graph = @import("Graph.zig");
8
9configuration: Configuration,
10top_level_steps: std.StringArrayHashMapUnmanaged(Configuration.Step.Index),
11
12pub fn print(sc: *const ScannedConfig, w: *Writer) Writer.Error!void {
13 const c = &sc.configuration;
14 var serializer: std.zon.Serializer = .{ .writer = w };
15 var s = try serializer.beginStruct(.{});
16
17 try s.field("default_step", @intFromEnum(c.default_step), .{});
18 {
19 var ss = try s.beginStructField("top_level_steps", .{});
20 for (sc.top_level_steps.keys(), sc.top_level_steps.values()) |name, step| {
21 try ss.field(name, @intFromEnum(step), .{});
22 }
23 try ss.end();
24 }
25
26 try s.end();
27}
28
29pub fn printSteps(sc: *const ScannedConfig, graph: *Graph, w: *Writer) !void {
30 const arena = graph.arena;
31 const c = &sc.configuration;
32 for (sc.top_level_steps.keys(), sc.top_level_steps.values()) |name, step_index| {
33 const step = step_index.ptr(c);
34 const decorated_name = if (step_index == c.default_step)
35 try std.fmt.allocPrint(arena, "{s} (default)", .{name})
36 else
37 name;
38 const top_level = c.extraData(Configuration.Step.TopLevel, step.extra_index);
39 const description = top_level.description.slice(c);
40 try w.print(" {s:<28} {s}\n", .{ decorated_name, description });
41 }
42}
43
44pub fn printUsage(sc: *const ScannedConfig, graph: *Graph, w: *Writer) !void {
45 const arena = graph.arena;
46
47 try w.print(
48 \\Usage: {s} build [steps] [options]
49 \\
50 \\Steps:
51 \\
52 , .{graph.zig_exe});
53 try printSteps(sc, graph, w);
54 try w.writeAll(
55 \\
56 \\Project-Specific Options:
57 \\
58 );
59
60 const available_options = sc.configuration.available_options;
61 if (available_options.len == 0) {
62 try w.print(" (none)\n", .{});
63 } else {
64 for (available_options) |option| {
65 const name = option.name.slice(&sc.configuration);
66 const description = option.description.slice(&sc.configuration);
67 const help = try std.fmt.allocPrint(arena, " -D{s}=[{t}]", .{ name, option.type });
68 try w.print("{s:<30} {s}\n", .{ help, description });
69 if (option.enum_options.slice(&sc.configuration)) |enum_options| {
70 const padding: [33]u8 = @splat(' ');
71 try w.writeAll(padding ++ "Supported Values:\n");
72 for (enum_options) |enum_option_index| {
73 const enum_option = enum_option_index.slice(&sc.configuration);
74 try w.print(padding ++ " {s}\n", .{enum_option});
75 }
76 }
77 }
78 }
79
80 try w.writeAll(
81 \\
82 \\System Integration Options:
83 \\ --search-prefix [path] Add a path to look for binaries, libraries, headers
84 \\ --sysroot [path] Set the system root directory (usually /)
85 \\ --libc [file] Provide a file which specifies libc paths
86 \\
87 \\ --system [pkgdir] Disable package fetching; enable all integrations
88 \\ -fsys=[name] Enable a system integration
89 \\ -fno-sys=[name] Disable a system integration
90 \\
91 \\ -fdarling, -fno-darling Integration with system-installed Darling to
92 \\ execute macOS programs on Linux hosts
93 \\ (default: no)
94 \\ -fqemu, -fno-qemu Integration with system-installed QEMU to execute
95 \\ foreign-architecture programs on Linux hosts
96 \\ (default: no)
97 \\ --libc-runtimes [path] Enhances QEMU integration by providing dynamic libc
98 \\ (e.g. glibc or musl) built for multiple foreign
99 \\ architectures, allowing execution of non-native
100 \\ programs that link with libc.
101 \\ -frosetta, -fno-rosetta Rely on Rosetta to execute x86_64 programs on
102 \\ ARM64 macOS hosts. (default: no)
103 \\ -fwasmtime, -fno-wasmtime Integration with system-installed wasmtime to
104 \\ execute WASI binaries. (default: no)
105 \\ -fwine, -fno-wine Integration with system-installed Wine to execute
106 \\ Windows programs on Linux hosts. (default: no)
107 \\
108 \\ Available System Integrations: Enabled:
109 \\
110 );
111 if (sc.configuration.system_integrations.len == 0) {
112 try w.writeAll(" (none) -\n");
113 } else {
114 for (sc.configuration.system_integrations) |system_integration| {
115 const name = system_integration.name.slice(&sc.configuration);
116 const status = switch (system_integration.status) {
117 .disabled => "no",
118 .enabled => "yes",
119 };
120 try w.print(" {s:<43} {s}\n", .{ name, status });
121 }
122 }
123
124 try w.writeAll(
125 \\
126 \\General Options:
127 \\ -h, --help Print this help to stdout and exit
128 \\ -l, --list-steps Print available steps to stdout and exit
129 \\
130 \\ -p, --prefix [path] Where to install files (default: zig-out)
131 \\ --prefix-lib-dir [path] Where to install libraries
132 \\ --prefix-exe-dir [path] Where to install executables
133 \\ --prefix-include-dir [path] Where to install C header files
134 \\ --release[=mode] Request release mode, optionally specifying a
135 \\ preferred optimization mode: fast, safe, small
136 \\
137 \\ --verbose Print commands before executing them
138 \\ --color [auto|off|on] Enable or disable colored error messages
139 \\ --error-style [style] Control how build errors are printed
140 \\ verbose (Default) Report errors with full context
141 \\ minimal Report errors after summary, excluding context like command lines
142 \\ verbose_clear Like 'verbose', but clear the terminal at the start of each update
143 \\ minimal_clear Like 'minimal', but clear the terminal at the start of each update
144 \\ --multiline-errors [style] Control how multi-line error messages are printed
145 \\ indent (Default) Indent non-initial lines to align with initial line
146 \\ newline Include a leading newline so that the error message is on its own lines
147 \\ none Print as usual so the first line is misaligned
148 \\ --summary [mode] Control the printing of the build summary
149 \\ all Print the build summary in its entirety
150 \\ new Omit cached steps
151 \\ failures (Default if short-lived) Only print failed steps
152 \\ line (Default if long-lived) Only print the single-line summary
153 \\ none Do not print the build summary
154 \\ -j<N> Limit concurrent jobs (default is to use all CPU cores)
155 \\ --maxrss <bytes> Limit memory usage (default is to use available memory)
156 \\ --skip-oom-steps Instead of failing, skip steps that would exceed --maxrss
157 \\ --test-timeout <timeout> Limit execution time of unit tests, terminating if exceeded.
158 \\ The timeout must include a unit: ns, us, ms, s, m, h
159 \\ --watch Continuously rebuild when source files are modified
160 \\ --debounce <ms> Delay before rebuilding after changed file detected
161 \\ --webui[=ip] Enable the web interface on the given IP address
162 \\ --fuzz[=limit] Continuously search for unit test failures with an optional
163 \\ limit to the max number of iterations. The argument supports
164 \\ an optional 'K', 'M', or 'G' suffix (e.g. '10K'). Implies
165 \\ '--webui' when no limit is specified.
166 \\ --time-report Force full rebuild and provide detailed information on
167 \\ compilation time of Zig source code (implies '--webui')
168 \\ -fincremental Enable incremental compilation
169 \\ -fno-incremental Disable incremental compilation
170 \\
171 \\Package Management Options:
172 \\ --fetch[=mode] Fetch dependency tree (optionally choose laziness) and exit
173 \\ needed (Default) Lazy dependencies are fetched as needed
174 \\ all Lazy dependencies are always fetched
175 \\ --fork=[path] Override one or more projects from dependency tree
176 \\
177 \\Advanced Options:
178 \\ -freference-trace[=num] How many lines of reference trace should be shown per compile error
179 \\ -fno-reference-trace Disable reference trace
180 \\ -fallow-so-scripts Allows .so files to be GNU ld scripts
181 \\ -fno-allow-so-scripts (default) .so files must be ELF files
182 \\ --error-limit [num] Set the maximum amount of distinct error values
183 \\ --build-file [file] Override path to build.zig
184 \\ --cache-dir [path] Override path to local Zig cache directory
185 \\ --global-cache-dir [path] Override path to global Zig cache directory
186 \\ --zig-lib-dir [arg] Override path to Zig lib directory
187 \\ --build-runner [file] Override path to build runner
188 \\ --seed [integer] For shuffling dependency traversal order (default: random)
189 \\ --build-id[=style] At a minor link-time expense, embeds a build ID in binaries
190 \\ fast 8-byte non-cryptographic hash (COFF, ELF, WASM)
191 \\ sha1, tree 20-byte cryptographic hash (ELF, WASM)
192 \\ md5 16-byte cryptographic hash (ELF)
193 \\ uuid 16-byte random UUID (ELF, WASM)
194 \\ 0x[hexstring] Constant ID, maximum 32 bytes (ELF, WASM)
195 \\ none (default) No build ID
196 \\ --debug-log [scope] Enable debugging the compiler
197 \\ --debug-pkg-config Fail if unknown pkg-config flags encountered
198 \\ --debug-rt Debug compiler runtime libraries
199 \\ --verbose-link Enable compiler debug output for linking
200 \\ --verbose-air Enable compiler debug output for Zig AIR
201 \\ --verbose-llvm-ir Enable compiler debug output for LLVM IR
202 \\ --verbose-cimport Enable compiler debug output for C imports
203 \\ --verbose-cc Enable compiler debug output for C compilation
204 \\ --verbose-llvm-cpu-features Enable compiler debug output for LLVM CPU features
205 \\
206 );
207}