Commit graph

484 commits

Author SHA1 Message Date
Andrew Kelley
1f1381a866 update API usage of std.crypto.random to io.random 2026-01-07 11:03:36 -08:00
Andrew Kelley
816565dd07 std: move entropy to Io 2026-01-07 11:03:36 -08:00
Andrew Kelley
c8ecfad41a build runner: clean up tmp dirs 2026-01-04 17:46:44 -08:00
Andrew Kelley
b4dbe483a7 std.Build: adjust temp files API
Remove the RemoveDir step with no replacement. This step had no valid
purpose. Mutating source files? That should be done with
UpdateSourceFiles step. Deleting temporary directories? That required
creating the tmp directories in the configure phase which is broken.
Deleting cached artifacts? That's going to cause problems.

Similarly, remove the `Build.makeTempPath` function. This was used to
create a temporary path in the configure place which, again, is the
wrong place to do it.

Instead, the WriteFile step has been updated with more functionality:

tmp mode: In this mode, the directory will be placed inside "tmp" rather
than "o", and caching will be skipped. During the `make` phase, the step
will always do all the file system operations, and on successful build
completion, the dir will be deleted along with all other tmp
directories. The directory is therefore eligible to be used for
mutations by other steps. `Build.addTempFiles` is introduced to
initialize a WriteFile step with this mode.

mutate mode: The operations will not be performed against a freshly
created directory, but instead act against a temporary directory.
`Build.addMutateFiles` is introduced to initialize a WriteFile step with
this mode.

`Build.tmpPath` is introduced, which is a shortcut for
`Build.addTempFiles` followed by `WriteFile.getDirectory`.

* give Cache a gpa rather than arena because that's what it asks for
2026-01-04 17:23:45 -08:00
Andrew Kelley
e2c04a4651 fix some windows compilation errors 2026-01-04 00:27:09 -08:00
Andrew Kelley
b32a38ad27 build: fix file system watching compilation on macOS 2026-01-04 00:27:09 -08:00
Andrew Kelley
1070c2a71a rename env_map to environ_map
For naming consistency with `std.process.Environ.Map`.
2026-01-04 00:27:09 -08:00
Andrew Kelley
4afed3e9ef test-standalone: update the rest of the cases to new API 2026-01-04 00:27:08 -08:00
Andrew Kelley
bf74827ddb test-standalone: update more cases to new main API 2026-01-04 00:27:08 -08:00
Andrew Kelley
1b56686012 test-standalone: update cases to new main API 2026-01-04 00:27:08 -08:00
Andrew Kelley
f28802a9c6 zig libc: fix subcommand
This branch regressed the child process "run" mechanism because it
didn't pass the correct stdin, stdout, stderr values to process.spawn

Fixed now.
2026-01-04 00:27:08 -08:00
Andrew Kelley
960c512efd compiler: update std lib API usage 2026-01-04 00:27:08 -08:00
Andrew Kelley
08447ca47e std.fs.path: make relative a pure function
Instead of querying the operating system for current working directory
and environment variables, this function now accepts those things as
inputs.
2026-01-04 00:27:08 -08:00
Andrew Kelley
9009ab2495 std.Io.Threaded: make environ init non-optional
and argv0 on systems that need it too.

fixes surprising behavior for applications that forget to initialize the
environment field.
2026-01-04 00:27:08 -08:00
Andrew Kelley
3e6d6150d9 std.process.Environ: fix compile errors on POSIX 2026-01-04 00:27:08 -08:00
Andrew Kelley
32af0f6154 std: move child process APIs to std.Io
this gets the build runner compiling again on linux

this work is incomplete; it only moves code around so that environment
variables can be wrangled properly. a future commit will need to audit
the cancelation and error handling of this moved logic.
2026-01-04 00:27:08 -08:00
Andrew Kelley
d6a1e73142 std: start wrangling environment variables and process args
this commit is unfinished. It marks a spot where I wanted to start
moving child process stuff below the std.Io.VTable
2026-01-04 00:27:07 -08:00
Matthew Lugg
f306a9f84a
std: rebase fixups and cancelation changes
This commit includes some API changes which I agreed with Andrew as a
follow-up to the recent `Io.Group` changes:

* `Io.Group.await` *does* propagate cancelation to group tasks; it then
  waits for them to complete, and *also* returns `error.Canceled`. The
  assertion that group tasks handle `error.Canceled` "correctly" means
  this behavior is loosely analagous to how awaiting a future works. The
  important thing is that the semantics of `Group.await` and
  `Future.await` are similar, and `error.Canceled` will always be
  visible to the caller (assuming correct API usage).

* `Io.Group.awaitUncancelable` is removed.

* `Future.await` calls `recancel` only if the "child" task (the future
  being awaited) did not acknowledge cancelation. If it did, then it is
  assumed that the future will propagate `error.Canceled` through
  `await` as needed.
2026-01-03 15:45:11 +00:00
PeterMcKinnis
96ba0ab930 fix lockStderr API calls in test_runner fuzz code 2025-12-30 15:09:17 -05:00
Andrew Kelley
1eb8fe7c61 Merge pull request 'bsd-futex' (#30626) from mikdusan/zig:bsd-futex into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30626
Reviewed-by: Andrew Kelley <andrewrk@noreply.codeberg.org>
2025-12-30 20:24:00 +01:00
Andrew Kelley
2adfd4d107 std.Io: fix and improve Group API
Rename `wait` to `await` to be consistent with Future API. The
convention here is that this set of functionality goes together:
* async/concurrent
* await/cancel

Also rename Select `wait` to `await` for the same reason.

`Group.await` now can return `error.Canceled`. Furthermore,
`Group.await` does not auto-propagate cancelation. Instead, users should
follow the pattern of `defer group.cancel(io);` after initialization,
and doing `try group.await(io);` at the end of the success path.
Advanced logic can choose to do something other than this pattern in the
event of cancelation.

Additionally, fixes a bug in `std.Io.Threaded` future await, in which it
swallowed an `error.Canceled`. Now if a task is canceled while awaiting
a future, after propagating the cancel request, it also recancels,
meaning that the awaiting task will properly detect its own cancelation
at the next cancelation point.

Furthermore, fixes a bug in the compiler where `error.Canceled` was
being swallowed in `dispatchPrelinkWork`.

Finally, fixes std.crypto code that inappropriately used
`catch unreachable` in response to cancelation without even so much as a
comment explaining why it was believed to be unreachable. Now, those
functions have `error.Canceled` in the error set and propagate
cancelation properly.

With this way of doing things, `Group.await` has a nice property: even if
all tasks in the group are CPU bound and without cancelation points, the
`Group.await` can still be canceled. In such case, the task that was
waiting for `await` wakes up with a chance to do some more resource
cleanup tasks, such as canceling more things, before entering the
deferred `Group.cancel` call at which point it has to suspend until the
canceled but uninterruptible CPU bound tasks complete.

closes #30601
2025-12-29 22:47:34 -08:00
Michael Dusan
1ea2d5692d
openbsd: init Io.Threaded.argv0 for tests
Some tests (eg. std.process.openExecutable) require argv0 for OpenBSD,
otherwise error.OperationUnsupported is encountered.
2025-12-29 21:06:08 -05:00
Andrew Kelley
744e22b18a build_runner: re-order the help menu
closes #30615
2025-12-28 19:53:42 -08:00
Ryan Liptak
4f8aa8213d Fix for compile error in resinator 2025-12-26 19:58:56 -08:00
Andrew Kelley
b0691df5ba test_runner: fix simple runner compilation 2025-12-26 19:58:56 -08:00
Andrew Kelley
0870f17501 fix aro and resinator compilation errors 2025-12-23 22:15:12 -08:00
Andrew Kelley
c05e2720a1 tools: fix compilation errors 2025-12-23 22:15:12 -08:00
Andrew Kelley
691afee786 langref: fix build failure 2025-12-23 22:15:12 -08:00
Andrew Kelley
33e302d67a update remaining calls to std.Io.Threaded.init 2025-12-23 22:15:12 -08:00
Andrew Kelley
9aee45be97 fix "zig std" compilation errors 2025-12-23 22:15:12 -08:00
Andrew Kelley
3c2f5adf41 std: integrate Io.Threaded with environment variables
* std.option allows overriding the debug Io instance
* if the default is used, start code initializes environ and argv0

also fix some places that needed recancel(), thanks mlugg!

See #30562
2025-12-23 22:15:12 -08:00
Andrew Kelley
a29d79313a std.Io.Threaded: accept argv and environ on init
This is needed unfortunately for OpenBSD and Haiku for process
executable path.

I made it so that you can omit the options usually, but you get a
compile error if you omit the options on those targets.
2025-12-23 22:15:12 -08:00
Ryan Liptak
51a6f3a525 Update a few more callsites for std.Io changes 2025-12-23 22:15:11 -08:00
Andrew Kelley
77d2ad8c92 std: consolidate all instances of std.Io.Threaded into a singleton
It's better to avoid references to this global variable, but, in the
cases where it's needed, such as in std.debug.print and collecting stack
traces, better to share the same instance.
2025-12-23 22:15:11 -08:00
Andrew Kelley
a8088306f6 std: rename other Dir "make" functions to "create" 2025-12-23 22:15:11 -08:00
Andrew Kelley
54865e0483 compiler: fix compilation when linking libc 2025-12-23 22:15:10 -08:00
Andrew Kelley
a5b719e9eb compiler: fix build failures from std.Io-fs 2025-12-23 22:15:10 -08:00
Andrew Kelley
608145c2f0 fix more fallout from locking stderr 2025-12-23 22:15:10 -08:00
Andrew Kelley
16bd2e137e compiler: fix most compilation errors from std.fs changes 2025-12-23 22:15:09 -08:00
Andrew Kelley
1925e0319f update lockStderrWriter sites
use the application's Io implementation where possible. This correctly
makes writing to stderr cancelable, fallible, and participate in the
application's event loop. It also removes one more hard-coded
dependency on a secondary Io implementation.
2025-12-23 22:15:09 -08:00
Andrew Kelley
ec56696503 std.process.cleanExit: take an Io parameter
In case exit(0) will be called, this provides the opportunity for the
application's Io instance to be the one to clear the terminal in case
std.Progress or similar was used.
2025-12-23 22:15:09 -08:00
Andrew Kelley
e68ae8d7a1 update uses of std.debug.lockStdErr 2025-12-23 22:15:09 -08:00
Andrew Kelley
6484101f78 update occurences of std.fs.openDirAbsolute 2025-12-23 22:15:09 -08:00
Andrew Kelley
1ed845e1f6 update occurences of setEndPos to setLength 2025-12-23 22:15:09 -08:00
Andrew Kelley
16f8af1b9a compiler: update various code to new fs API 2025-12-23 22:15:09 -08:00
Andrew Kelley
68621afd2e std.tar: update fs API calls to take io argument 2025-12-23 22:15:09 -08:00
Andrew Kelley
b042e93522 std: update tty config references in the build system 2025-12-23 22:15:09 -08:00
Andrew Kelley
03526c59d4 std.debug: fix printLineFromFile 2025-12-23 22:15:09 -08:00
Andrew Kelley
bee8005fe6 std.heap.DebugAllocator: never detect TTY config
instead, allow the user to set it as a field.

this fixes a bug where leak printing and error printing would run tty
config detection for stderr, and then emit a log, which is not necessary
going to print to stderr.

however, the nice defaults are gone; the user must explicitly assign the
tty_config field during initialization or else the logging will not have
color.

related: https://github.com/ziglang/zig/issues/24510
2025-12-23 22:15:08 -08:00
Andrew Kelley
4a53e5b0b4 fix a handful of compilation errors related to std.fs migration 2025-12-23 22:15:08 -08:00