Commit Graph

29397 Commits

Author SHA1 Message Date
Linus Groh
b5e99b5295 std.Build.step.Compile: Fix lib{c,cpp} mixup in dependsOnSystemLibrary() 2024-05-28 20:39:42 -04:00
Andrew Kelley
963ffe9d57
Merge pull request #20059 from ziglang/progress
rework std.Progress
2024-05-28 19:27:14 -04:00
Andrew Kelley
3a3d2187f9 std.Progress: better Windows support
* Merge a bunch of related state together into TerminalMode. Windows
  sometimes follows the same path as posix via ansi_escape_codes,
  sometimes not.
* Use a different thread entry point for Windows API but share the same
  entry point on Windows when the terminal is in ansi_escape_codes mode.
* Only clear the terminal when the stderr lock is held.
* Don't try to clear the terminal when nothing has been written yet.
* Don't try to clear the terminal in IPC mode.
* Fix size detection logic bug under error conditions.
2024-05-28 12:31:10 -07:00
Ryan Liptak
40afac40b8 std.Progress: Use Windows console API calls when ANSI escape codes are not supported 2024-05-28 10:41:07 -07:00
Andrew Kelley
65a0e14e4f std.Progress: relax some of the atomic orderings
Generates better machine code, particularly on ARM
2024-05-27 20:56:49 -07:00
Andrew Kelley
5bdfe22092 CLI: actually fix translate-c creating root progress node twice
7281cc1d839da6e84bb76fadb2c1eafc22a82df7 did not solve the problem
because even when Node.index is none, it still counts as initializing
the global Progress object. Just use a normal zig optional, and all is
good.
2024-05-27 20:56:49 -07:00
Andrew Kelley
947a3a1be9 std.process.Child: fix spawning child proc with new cwd fd
Before this fix, the dup2 of the progress pipe was clobbering the cwd
fd, causing the fchdir to return ENOTDIR in between fork() and exec().
2024-05-27 20:56:49 -07:00
Andrew Kelley
b7889f262a zig build: respect --color argument
`--color off` now disables the CLI progress bar both in the parent
process and the build runner process.
2024-05-27 20:56:49 -07:00
Andrew Kelley
aca7feb8fa std.Progress: fix race condition with setIpcFd
The update thread was sometimes reading the special state and then
incorrectly getting 0 for the file descriptor, making it hang since it
tried to read from stdin.
2024-05-27 20:56:49 -07:00
Andrew Kelley
bb1f4d2bda translate-c tests: skip_foreign_checks=true 2024-05-27 20:56:49 -07:00
Andrew Kelley
44389253c2 fix zig translate-c creating root progress node twice 2024-05-27 20:56:49 -07:00
Andrew Kelley
2367a1ff84 std.Progress: handle short writes 2024-05-27 20:56:49 -07:00
Andrew Kelley
dcf9cae256 std.Progress: handle big-endian targets
We cannot rely on host endianness because the parent or child process
may be executing inside QEMU.
2024-05-27 20:56:49 -07:00
Andrew Kelley
eea7e5e554 std.Progress: adjust the timings a little bit
Slightly slower refresh rate. It's still updating very quickly.

Lower the initial delay so that CLI applications feel more responsive.
Even though the application is doing work for the full 500ms until
something is displayed on the screen, it feels nicer to get the progress
earlier.
2024-05-27 20:56:49 -07:00
Andrew Kelley
a5e4fe5487 std.Build.Step.Run: account for new environment variable
Introduces `disable_zig_progress` which prevents the build runner from
assigning the child process a progress node.

This is needed for the empty_env test which requires the environment to
be completely empty.
2024-05-27 20:56:49 -07:00
Andrew Kelley
0937992a14 resinator: update to new progress API 2024-05-27 20:56:49 -07:00
Andrew Kelley
03073d6c7b build runner: use "configure" for the progress name 2024-05-27 20:56:49 -07:00
Andrew Kelley
45b505c930 std.process.cleanExit: lock stderr before exiting
This makes it so that any other threads which are writing to stderr have
a chance to finish before the process terminates. It also clears the
terminal in case any progress has been written to stderr, while still
accomplishing the goal of not waiting until the update thread exits.
2024-05-27 20:56:49 -07:00
Andrew Kelley
c9587d3e40 CLI: add missing call to root progress node end()
cleans up unwanted "LLVM Emit Object" being left on the screen
2024-05-27 20:56:49 -07:00
Andrew Kelley
64c6a5092c std.Progress: elide root node if empty
when the root progress node has a zero length name, the sub-tree is
flattened one layer, reducing visual noise, as well as bytes written to
the terminal.
2024-05-27 20:56:48 -07:00
Andrew Kelley
dc3a192ae8 std.Progress: count newlines more accurately
Split newline_count into written_newline_count and
accumulated_newline_count. This handle the case when the tryLock() fails
to obtain the lock, because in such case there would not be any newlines
written to the terminal but the system would incorrectly think there
were. Now, written_newline_count is only adjusted when the write() call
succeeds.

Furthermore, write() call failure is handled by exiting the update
thread.
2024-05-27 20:56:48 -07:00
Andrew Kelley
6145819c0b std.Progress: handle when terminal write buffer too small 2024-05-27 20:56:48 -07:00
Andrew Kelley
52ffdec74b std.Progress: keep cursor on newline
Don't truncate trailing newline. This better handles stray writes to
stderr that are not std.Progress-aware, such as from non-zig child
processes.

This commit also makes `Node.start` and `Node.end` bail out early with a
comptime branch when it is known the target will not be spawning an
update thread.
2024-05-27 20:56:48 -07:00
Andrew Kelley
849693f07c zig build: give a root progress name
Now it's more clear when zig is building the build script vs building
the actual project.
2024-05-27 20:56:48 -07:00
Andrew Kelley
0ca2b4e0f1 std.Progress: use std.log.debug rather than warn
when the errors could possibly be spammed many times
2024-05-27 20:56:48 -07:00
Andrew Kelley
ea7d8ec147 std.Progress: smaller type for parents and robustify
Switch Node.Parent, Node.Index, and Node.OptionalIndex to be backed by
u8 rather than u16. This works fine since we use 200 as the preallocated
node buffer. This has the nice property that scanning the entire parents
array for allocated nodes fits in 4 cache lines, even if we bumped the
200 up to 254 (leaving room for the two special states).

The thread that reads progress updates from the pipe now handles short
reads by ignoring messages that are sent in multiple reads.

When checking the terminal size, if there is a failure, fall back to a
conservative guess of 80x25 rather than panicking. A debug message is
also emitted which would be displayed only in a debug build.
2024-05-27 20:56:48 -07:00
Andrew Kelley
11f894702b std.Progress: avoid scrolling the PS1 off the terminal 2024-05-27 20:56:48 -07:00
Andrew Kelley
52ed54d1e7 std.Progress: truncate IPC data exceeding preallocated buffers
This accomplishes 2 things simultaneously:

1. Don't trust child process data; if the data is outside the expected
   range, ignore the data.
2. If there is too much data to fit in the preallocated buffers, drop
   the data.
2024-05-27 20:56:48 -07:00
Andrew Kelley
807b613f71 std.Progress: move more global preallocations to thread memory
Same idea as previous commit
2024-05-27 20:56:48 -07:00
Andrew Kelley
7fe72d560d std.Progress: move global preallocations to thread memory
Instead of making static buffers configurable, let's pick strong
defaults and then use the update thread's stack memory to store the
preallocations. The thread uses a fairly shallow stack so this memory is
otherwise unused. This also makes the data section of the executable
smaller since it runtime allocates the memory when a `std.Progress`
instance is allocated, and in the case that the process is not connected
to a terminal, it never allocates the memory.
2024-05-27 20:56:48 -07:00
Andrew Kelley
d3b03ed64b frontend: fix use of undefined progress node
This was causing a crash when running `zig test`.
2024-05-27 20:56:48 -07:00
Andrew Kelley
eb718ceffa std.process: fix compilation on 32-bit targets 2024-05-27 20:56:48 -07:00
Andrew Kelley
e820173467 Compilation: fix sub-compilations given wrong progress node 2024-05-27 20:56:48 -07:00
Andrew Kelley
e2e61f3296 std.process.Child: comptime assert to protect prog_fileno
documenting my assumptions via comptime assertion
2024-05-27 20:56:48 -07:00
Andrew Kelley
e8907f9e9c std.Progress: correct the top level doc comments 2024-05-27 20:56:48 -07:00
Jacob Young
d77f5e7aaa Progress: fix compile errors on windows
Works for `zig build-exe`, IPC still not implemented yet.
2024-05-27 20:56:48 -07:00
mlugg
d403d8cb7a Module: fix and improve progress reporting
* correctly report time spent analyzing function bodies
* print fully qualified decl names
* also have a progress node for codegen

The downside of these changes is that it's a bit flickerey, but the
upside is that it's accurate; you can see what the compiler's doing!
2024-05-27 20:56:48 -07:00
mlugg
acdf988c24 std.process.Child: prevent racing children from inheriting progress pipes
This fix is already in master branch for stdin, stdout, and stderr; this
commit solves the same problem but for the progress pipe.

Both fixes were originally included in one commit on this branch,
however it was split it into two so that master branch could receive the
fix before the progress branch is merged.
2024-05-27 20:56:48 -07:00
Andrew Kelley
9331da8fe3 std.Build.Step.Run: don't create empty progress node 2024-05-27 20:56:48 -07:00
Andrew Kelley
ca03c9c512 std.Progress: fix race condition with IPC nodes
It stored some metadata into the canonical node storage data but that is
a race condition because another thread recycles those nodes.

Also, keep the parent name for empty child root node names.
2024-05-27 20:56:48 -07:00
Andrew Kelley
516366f78f std.Progress: skip printing root node when it is empty 2024-05-27 20:56:48 -07:00
Andrew Kelley
2759173452 zig build: lock stderr while executing the build runner 2024-05-27 20:56:48 -07:00
Andrew Kelley
352dc2c06a compiler: show decl name in progress node 2024-05-27 20:56:48 -07:00
Andrew Kelley
70e39c1a20 std.Progress: fixes
* bump default statically allocated resources
* debug help when multiple instances of std.Progress are initialized
* only handle sigwinch on supported operating systems
* handle when reading from the pipe returns 0 bytes
* avoid printing more lines than rows
2024-05-27 20:56:48 -07:00
Andrew Kelley
2233d95b0f main: avoid creating multiple std.Progress instances 2024-05-27 20:56:48 -07:00
Andrew Kelley
b27fdf92fb Compilation: only create progress nodes for work actually being done 2024-05-27 20:56:48 -07:00
Andrew Kelley
1cf1cb6ae0 std.debug.Trace: follow the struct default field guidance 2024-05-27 20:56:48 -07:00
Andrew Kelley
a486392ee4 std.Build.Step: don't create an empty progress node 2024-05-27 20:56:48 -07:00
Andrew Kelley
795c5791a9 test runner: update to new std.Progress API 2024-05-27 20:56:48 -07:00
Andrew Kelley
f97c2f28fd update the codebase for the new std.Progress API 2024-05-27 20:56:48 -07:00