zig/lib/std
mlugg dcc3e6e1dd build system: replace fuzzing UI with build UI, add time report
This commit replaces the "fuzzer" UI, previously accessed with the
`--fuzz` and `--port` flags, with a more interesting web UI which allows
more interactions with the Zig build system. Most notably, it allows
accessing the data emitted by a new "time report" system, which allows
users to see which parts of Zig programs take the longest to compile.

The option to expose the web UI is `--webui`. By default, it will listen
on `[::1]` on a random port, but any IPv6 or IPv4 address can be
specified with e.g. `--webui=[::1]:8000` or `--webui=127.0.0.1:8000`.
The options `--fuzz` and `--time-report` both imply `--webui` if not
given. Currently, `--webui` is incompatible with `--watch`; specifying
both will cause `zig build` to exit with a fatal error.

When the web UI is enabled, the build runner spawns the web server as
soon as the configure phase completes. The frontend code consists of one
HTML file, one JavaScript file, two CSS files, and a few Zig source
files which are built into a WASM blob on-demand -- this is all very
similar to the old fuzzer UI. Also inherited from the fuzzer UI is that
the build system communicates with web clients over a WebSocket
connection.

When the build finishes, if `--webui` was passed (i.e. if the web server
is running), the build runner does not terminate; it continues running
to serve web requests, allowing interactive control of the build system.

In the web interface is an overall "status" indicating whether a build
is currently running, and also a list of all steps in this build. There
are visual indicators (colors and spinners) for in-progress, succeeded,
and failed steps. There is a "Rebuild" button which will cause the build
system to reset the state of every step (note that this does not affect
caching) and evaluate the step graph again.

If `--time-report` is passed to `zig build`, a new section of the
interface becomes visible, which associates every build step with a
"time report". For most steps, this is just a simple "time taken" value.
However, for `Compile` steps, the compiler communicates with the build
system to provide it with much more interesting information: time taken
for various pipeline phases, with a per-declaration and per-file
breakdown, sorted by slowest declarations/files first. This feature is
still in its early stages: the data can be a little tricky to
understand, and there is no way to, for instance, sort by different
properties, or filter to certain files. However, it has already given us
some interesting statistics, and can be useful for spotting, for
instance, particularly complex and slow compile-time logic.
Additionally, if a compilation uses LLVM, its time report includes the
"LLVM pass timing" information, which was previously accessible with the
(now removed) `-ftime-report` compiler flag.

To make time reports more useful, ZIR and compilation caches are ignored
by the Zig compiler when they are enabled -- in other words, `Compile`
steps *always* run, even if their result should be cached. This means
that the flag can be used to analyze a project's compile time without
having to repeatedly clear cache directory, for instance. However, when
using `-fincremental`, updates other than the first will only show you
the statistics for what changed on that particular update. Notably, this
gives us a fairly nice way to see exactly which declarations were
re-analyzed by an incremental update.

If `--fuzz` is passed to `zig build`, another section of the web
interface becomes visible, this time exposing the fuzzer. This is quite
similar to the fuzzer UI this commit replaces, with only a few cosmetic
tweaks. The interface is closer than before to supporting multiple fuzz
steps at a time (in line with the overall strategy for this build UI,
the goal will be for all of the fuzz steps to be accessible in the same
interface), but still doesn't actually support it. The fuzzer UI looks
quite different under the hood: as a result, various bugs are fixed,
although other bugs remain. For instance, viewing the source code of any
file other than the root of the main module is completely broken (as on
master) due to some bogus file-to-module assignment logic in the fuzzer
UI.

Implementation notes:

* The `lib/build-web/` directory holds the client side of the web UI.

* The general server logic is in `std.Build.WebServer`.

* Fuzzing-specific logic is in `std.Build.Fuzz`.

* `std.Build.abi` is the new home of `std.Build.Fuzz.abi`, since it now
  relates to the build system web UI in general.

* The build runner now has an **actual** general-purpose allocator,
  because thanks to `--watch` and `--webui`, the process can be
  arbitrarily long-lived. The gpa is `std.heap.DebugAllocator`, but the
  arena remains backed by `std.heap.page_allocator` for efficiency. I
  fixed several crashes caused by conflation of `gpa` and `arena` in the
  build runner and `std.Build`, but there may still be some I have
  missed.

* The I/O logic in `std.Build.WebServer` is pretty gnarly; there are a
  *lot* of threads involved. I anticipate this situation improving
  significantly once the `std.Io` interface (with concurrency support)
  is introduced.
2025-08-01 23:48:21 +01:00
..
Build build system: replace fuzzing UI with build UI, add time report 2025-08-01 23:48:21 +01:00
builtin add lr register to mips 2025-07-16 10:27:40 -07:00
c enable pwd.h functions for other OSes 2025-08-01 04:34:45 +02:00
compress std.Io.Reader: introduce readVec back into the VTable 2025-07-30 09:26:34 -07:00
crypto std.tar: update to new I/O API 2025-07-22 09:41:44 -07:00
debug zig fmt 2025-07-16 10:27:39 -07:00
dwarf Dwarf: remove redundant debug info 2024-12-19 17:10:03 -05:00
fmt std.fmt: breaking API changes 2025-07-07 22:43:51 -07:00
fs std.Io.Reader: introduce readVec back into the VTable 2025-07-30 09:26:34 -07:00
hash std.hash.RapidHash: remove 2025-07-19 11:49:33 -07:00
heap Merge pull request #24387 from ziglang/std.log.default_level 2025-07-10 14:56:33 +02:00
http build system: replace fuzzing UI with build UI, add time report 2025-08-01 23:48:21 +01:00
Io std.Io.Reader: fix readVec at end 2025-07-31 19:26:12 -07:00
json std.json: update to new I/O API 2025-07-19 16:05:01 -07:00
math std: stop relying on precision-losing coercions 2025-07-31 10:57:04 +01:00
mem std: refactor to use Alignment.of 2025-07-09 23:07:18 -07:00
meta std: eradicate u29 and embrace std.mem.Alignment 2025-04-13 02:20:32 -04:00
net std.net: update to new I/O API 2025-07-14 00:16:49 -07:00
os aarch64: add new from scratch self-hosted backend 2025-07-22 19:43:47 -07:00
posix std.posix: skip flaky test 2025-07-14 18:38:50 -07:00
process std.Io.poll: update to new I/O API 2025-07-23 21:25:34 -07:00
Random std.fmt: breaking API changes 2025-07-07 22:43:51 -07:00
sort compiler,lib,test,langref: migrate @setCold to @branchHint 2024-08-27 00:44:35 +01:00
tar std.tar: delete function redundant with std.mem 2025-07-22 17:40:12 -07:00
Target std.fmt: breaking API changes 2025-07-07 22:43:51 -07:00
testing FailingAllocator: remove outdated doc comments, move doc comment example to decltest 2025-04-23 19:28:28 -04:00
Thread Remove numerous things deprecated during the 0.14 release cycle 2025-07-11 08:17:43 +02:00
time std.time.epoch: change getDaysInMonth to accept the year as an argument 2025-03-08 14:25:28 -05:00
tz Support legacy TZ format, expose header struct to a potential writer 2022-01-01 12:47:08 +00:00
unicode std.fmt: breaking API changes 2025-07-07 22:43:51 -07:00
valgrind Remove numerous things deprecated during the 0.14 release cycle 2025-07-11 08:17:43 +02:00
zig build system: replace fuzzing UI with build UI, add time report 2025-08-01 23:48:21 +01:00
zip std.fmt: breaking API changes 2025-07-07 22:43:51 -07:00
zon std: stop relying on precision-losing coercions 2025-07-31 10:57:04 +01:00
array_hash_map.zig Legalize: implement scalarization of @shuffle 2025-06-01 08:24:01 +01:00
array_list.zig std.io.Writer.Allocating: rename interface to writer 2025-07-07 22:43:52 -07:00
ascii.zig Remove numerous things deprecated during the 0.14 release cycle 2025-07-11 08:17:43 +02:00
atomic.zig Remove numerous things deprecated during the 0.14 release cycle 2025-07-11 08:17:43 +02:00
base64.zig std.io: deprecated Reader/Writer; introduce new API 2025-07-07 22:43:51 -07:00
bit_set.zig std.bit_set: Disable IntegerBitSet decltest on RISC-V with vector support 2025-07-01 23:03:15 +02:00
BitStack.zig std: fix typos (#20560) 2024-07-09 14:25:42 -07:00
bounded_array.zig std.io: deprecated Reader/Writer; introduce new API 2025-07-07 22:43:51 -07:00
buf_map.zig lib: correct unnecessary uses of 'var' 2023-11-19 09:55:07 +00:00
buf_set.zig Change many test blocks to doctests/decltests 2024-02-26 15:18:31 -08:00
Build.zig build system: replace fuzzing UI with build UI, add time report 2025-08-01 23:48:21 +01:00
builtin.zig aarch64: workaround some optional/union issues 2025-07-28 09:03:17 -07:00
c.zig enable pwd.h functions for other OSes 2025-08-01 04:34:45 +02:00
coff.zig std.{coff,elf}: Remove the {MachineType,EM}.toTargetCpuArch() functions. 2024-08-23 19:56:24 +02:00
compress.zig std: rework zstd for new I/O API 2025-07-25 14:15:33 -07:00
crypto.zig std.crypto: fix Sha1 namespace 2025-07-14 00:14:21 -07:00
debug.zig std.debug: add assertAligned 2025-07-19 19:57:37 -07:00
DoublyLinkedList.zig std.DoublyLinkedList: remove length tracking 2025-04-03 15:57:35 -07:00
dwarf.zig Dwarf: cleanup emitted debug info 2024-08-22 08:44:08 +02:00
dynamic_library.zig x86_64: add support for pie executables 2025-06-06 23:42:14 -07:00
elf.zig aarch64: add new from scratch self-hosted backend 2025-07-22 19:43:47 -07:00
enums.zig std.enums: fix EnumIndexer branch quota 2025-07-31 22:10:22 +01:00
fifo.zig std.io: deprecated Reader/Writer; introduce new API 2025-07-07 22:43:51 -07:00
fmt.zig disable more failing tests 2025-07-29 22:44:01 +01:00
fs.zig Remove numerous things deprecated during the 0.14 release cycle 2025-07-11 08:17:43 +02:00
gpu.zig spirv: error when execution mode is set more than once 2025-05-21 13:01:21 +03:30
hash.zig std.hash.RapidHash: remove 2025-07-19 11:49:33 -07:00
hash_map.zig std: eradicate u29 and embrace std.mem.Alignment 2025-04-13 02:20:32 -04:00
heap.zig std: Add serenity to more OS checks 2025-07-30 23:28:58 +01:00
http.zig std.fmt: fully remove format string from format methods 2025-07-07 22:43:53 -07:00
Io.zig DeprecatedReader.Adapted: fix EndOfStream handling 2025-07-28 21:41:19 -07:00
json.zig std.json: delete dead API 2025-07-21 12:32:37 -07:00
leb128.zig Remove numerous things deprecated during the 0.14 release cycle 2025-07-11 08:17:43 +02:00
log.zig std.log.defaultLog: provide a small buffer 2025-07-10 16:52:29 -07:00
macho.zig remove hard tabs from source code 2024-07-31 16:57:42 -07:00
math.zig std: stop relying on precision-losing coercions 2025-07-31 10:57:04 +01:00
mem.zig aarch64: add new from scratch self-hosted backend 2025-07-22 19:43:47 -07:00
meta.zig Remove numerous things deprecated during the 0.14 release cycle 2025-07-11 08:17:43 +02:00
multi_array_list.zig std.fmt: breaking API changes 2025-07-07 22:43:51 -07:00
net.zig build system: replace fuzzing UI with build UI, add time report 2025-08-01 23:48:21 +01:00
once.zig compiler,lib,test,langref: migrate @setCold to @branchHint 2024-08-27 00:44:35 +01:00
os.zig std.fmt: breaking API changes 2025-07-07 22:43:51 -07:00
pdb.zig std.pdb: obey naming conventions 2024-08-29 23:43:52 +01:00
pie.zig zig fmt 2025-07-16 10:27:39 -07:00
posix.zig std: Add serenity to more OS checks 2025-07-30 23:28:58 +01:00
priority_dequeue.zig add std.testing.random_seed 2024-07-23 11:43:12 -07:00
priority_queue.zig std.priority_queue: add useful functions from ArrayList API 2025-02-01 19:02:39 +01:00
process.zig std.fmt: breaking API changes 2025-07-07 22:43:51 -07:00
Progress.zig std: Add serenity to more OS checks 2025-07-30 23:28:58 +01:00
Random.zig Allocator/Random: document that comparing ptr may result in illegal behavior 2025-02-03 17:07:28 -08:00
RingBuffer.zig std.RingBuffer: use sliceAt/sliceFirst in read*AssumeLength 2024-03-10 18:17:23 +11:00
segmented_list.zig std: update std.builtin.Type fields to follow naming conventions 2024-08-28 08:39:59 +01:00
SemanticVersion.zig std.fmt: fully remove format string from format methods 2025-07-07 22:43:53 -07:00
simd.zig std.simd: Increase branch quota in suggestVectorLengthForCpu() 2025-06-30 08:01:27 +02:00
SinglyLinkedList.zig de-genericify SinglyLinkedList 2025-04-03 14:55:04 -07:00
sort.zig std.equalRange: Compute lower and upper bounds simultaneously 2024-09-23 13:03:06 -07:00
start.zig std: Add serenity to more OS checks 2025-07-30 23:28:58 +01:00
static_string_map.zig std.static_string_map: Cast length of input for runtime initialization 2024-06-20 23:22:39 +00:00
std.zig std: rename io to Io in preparation 2025-07-11 01:16:27 +02:00
tar.zig std.tar: update to new I/O API 2025-07-22 09:41:44 -07:00
Target.zig better default min versions for freebsd and netbsd 2025-07-15 15:32:18 +02:00
testing.zig aarch64: add new from scratch self-hosted backend 2025-07-22 19:43:47 -07:00
Thread.zig std.Thread: don't spin 2025-07-21 05:37:51 +02:00
time.zig std.os.uefi.tables: ziggify boot and runtime services (#23441) 2025-07-12 17:18:53 +00:00
treap.zig Condense and extend std.Treap's traversal functionalities. (#20002) 2024-07-28 19:47:55 -07:00
tz.zig std.builtin.Endian: make the tags lower case 2023-10-31 21:37:35 -04:00
unicode.zig Remove numerous things deprecated during the 0.14 release cycle 2025-07-11 08:17:43 +02:00
Uri.zig std.io.Writer.printValue: rework logic 2025-07-07 22:43:53 -07:00
valgrind.zig remove condition codes 2025-07-16 10:27:39 -07:00
wasm.zig wasm linker: implement @tagName for sparse enums 2025-01-15 15:11:36 -08:00
zig.zig std.zig: fmtId returns a FormatId 2025-07-26 21:53:23 -07:00
zip.zig std.zip: work around deprecated API 2025-07-07 22:43:53 -07:00
zon.zig std.zon: better namespace for Serializer 2025-07-19 18:27:09 -07:00