Commit graph

767 commits

Author SHA1 Message Date
Jacob Young
2fa1a78491 Io.Dispatch: introduce grand central dispatch io impl 2026-02-13 12:29:40 -05:00
Andrew Kelley
b600b6e5e0 std.posix: remove close function 2026-02-11 23:37:31 +01:00
antme0
fb18f2096a Allow build.zig scripts to define module definition files (.def) when building win32 dlls. 2026-02-09 07:58:13 +01:00
Jacob Young
b5bd494606 std.Threaded: replace more kernel32 functions with ntdll 2026-02-07 00:02:50 -05:00
Andrew Kelley
2a193a3987 std: move GetFinalPathNameByHandle to Io.Threaded
unfortunately this function calls NtCreateFile so it has to participate
in cancelation
2026-02-04 16:27:13 -08:00
Jacob Young
71156aff80 std.Progress: implement ipc resource cleanup 2026-02-04 15:20:10 -05:00
Jacob Young
ffc6da29e3 std.Io.Threaded: implement and cleanup windows codepaths 2026-02-04 14:15:41 -05:00
Andrew Kelley
922ab8b8bc std: finish moving time to Io interface
Importantly, adds ability to get Clock resolution, which may be zero.
This allows error.Unexpected and error.ClockUnsupported to be removed
from timeout and clock reading error sets.
2026-02-02 23:02:31 -08:00
Ryan Liptak
05346e123b Add process.Child.Cwd, use it for cwd and remove cwd_dir field
The user must now explicitly choose between inheriting the current CWD, passing a path for the CWD, or passing a Dir for the CWD.
2026-02-02 01:41:35 -08:00
Andrew Kelley
a41ee5994d std.Build.Step: evalZigProcess handles EndOfStream
and a happy little info log when the process needs to be restarted
2026-01-30 22:03:14 -08:00
Matthew Lugg
f8828e543a std.Build: fully upgrade Step.Run to std.Io timing (and fix a typo) 2026-01-30 22:03:14 -08:00
Andrew Kelley
6a1fd3c69d std.Io.File.MultiReader: make checkAnyError exclude EndOfStream 2026-01-30 22:03:14 -08:00
Andrew Kelley
efa502a1cd std.Build.Step.Run: gracefully handle test runner misbehavior
specifically if it misbehaves after sending a message header but not the
body
2026-01-30 22:03:14 -08:00
Andrew Kelley
523aa213c9 std.Io.Threaded: batchWait and batchCancel for Windows 2026-01-30 22:03:14 -08:00
Andrew Kelley
372e8e54d3 compiler: update for std.Io.File.MultiReader API 2026-01-30 22:03:14 -08:00
Andrew Kelley
e56563ce3f std.Io.File.MultiReader: implementation fixes 2026-01-30 22:03:14 -08:00
Andrew Kelley
12cfc96e1b std: update rest of build runner to new File.MultiReader API 2026-01-30 22:03:14 -08:00
Andrew Kelley
20cadd60aa std.Io.File: introduce MultiReader
Concurrently read from multiple file streams, eliminating risk of
deadlocking.
2026-01-30 22:03:14 -08:00
Andrew Kelley
78a1476475 Build.WebServer: update concurrency API usage 2026-01-30 22:03:14 -08:00
Andrew Kelley
0a0ecc4fb1 std.Io: proof-of-concept "operations" API
This commit shows a proof-of-concept direction for std.Io.VTable to go,
which is to have general support for batching, timeouts, and
non-blocking.

I'm not sure if this is a good idea or not so I'm putting it up for
scrutiny.

This commit introduces `std.Io.operate`, `std.Io.Operation`, and
implements it experimentally for `FileReadStreaming`.

In `std.Io.Threaded`, the implementation is based on poll().

This commit shows how it can be used in `std.process.run` to collect
both stdout and stderr in a single-threaded program using
`std.Threaded.Io`.

It also demonstrates how to upgrade code that was previously using
`std.Io.poll` (*not* integrated with the interface!) using concurrency.
This may not be ideal since it makes the build runner no longer support
single-threaded mode. There is still a needed abstraction for
conveniently reading multiple File streams concurrently without
io.concurrent, but this commit demonstrates that such an API can be
built on top of the new `std.Io.operate` functionality.
2026-01-30 22:03:13 -08:00
Andrew Kelley
377bb8f237 Merge pull request 'std: migrate getcwd to Io' (#31047) from getcwd into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31047
2026-01-30 06:38:08 +01:00
Pablo Alessandro Santos Hugen
ad0458f582 std.Build: Fix wrong error enum
Signed-off-by: Pablo Alessandro Santos Hugen <phugen@redhat.com>
2026-01-30 06:19:49 +01:00
Andrew Kelley
b1d1806fef std.process: currentDir -> currentPath
In Zig standard library, Dir means an open directory handle. path
represents a file system identifier string. This function is better
named after "current path" than "current dir". "get" and "working" are
superfluous.
2026-01-29 18:47:58 -08:00
Andrew Kelley
649aaf4814 std: migrate getcwd to Io
progress towards #30150
2026-01-29 18:40:55 -08:00
Alex Rønne Petersen
5652288e5d
zig fmt
oops
2026-01-27 07:05:14 +01:00
Alex Rønne Petersen
d4d210fb37
std.Build.WebServer: use Io futex operations instead of std.Thread.Futex 2026-01-27 05:37:01 +01:00
Pablo Alessandro Santos Hugen
951ab1b18b std.Build.Step.Compile: pass target by pointer to isLibC*LibName 2026-01-27 05:29:04 +01:00
InKryption
305fd06756 Build: check if dynamic lib installed for symlinks
If the library isn't actually installed, `generated_bin` will be null,
causing this to panic about a missing dependency for itself; checking
for this state avoids this.
2026-01-22 22:28:28 +01:00
Andrew Kelley
4d6d2922b8 std: move memory locking and memory protection to process
and introduce type safety for posix.PROT (mmap, mprotect)

progress towards #6600
2026-01-09 13:52:00 -08:00
Matthew Lugg
aebd84b525 build runner: refactor step evaluation logic
The previous logic was made really messy by the fact that upon entry to
the step eval worker, the step may not be ready to run, we may be racing
with other workers doing the same check, and we had already acquired our
RSS requirement even though we might not run. It also required iterating
all dependencies each time we were called to check whether we were even
ready to run yet.

A much better strategy is for each step to have an atomic counter
representing how many of its dependencies are yet to complete. When a
step completes (successfully or otherwise), it decrements this value for
all of its dependants, and if it drops any to 0, it schedules that step
to run. This means each step is scheduled exactly once, and only when
all of its dependencies have finished, reducing redundant checks and
hence contention. If the step being scheduled needs to claim RSS which
isn't available, then it is instead added to `memory_blocked_steps`,
which is iterated by the step worker after a step with an RSS claim
finishes.

This logic is more concise than before, simpler to understand, generally
more efficient, and fixes a bug in the RSS tracking. Also, as a nice
side effect, it should also play a little bit nicer with `Io.Threaded`'s
scheduling strategy, because we no longer spawn extremely short-lived
tasks all the time as we previously did.

Resolves: https://codeberg.org/ziglang/zig/issues/30742
2026-01-09 03:16:39 +01:00
Andrew Kelley
3961fe3de9 std: move posix.kevent to Io.Kqueue 2026-01-07 17:33:07 -08:00
Andrew Kelley
2c6304efc7 std: move posix.kqueue to Io.Kqueue.createFileDescriptor 2026-01-07 17:33:07 -08:00
Andrew Kelley
81a35a86ea std.Io: introduce random and randomSecure
and use a thread-local CSPRNG for the former.
2026-01-07 11:03:36 -08:00
Andrew Kelley
e3e9c7c33c std.Build.Step.Compile: take advantage of std lib atomic files 2026-01-07 11:03:36 -08:00
Andrew Kelley
42ca9e5d8e std.Build: remove no longer needed workaround
now that definitions of networking addresses are arch-independent
2026-01-07 11:03:36 -08:00
Andrew Kelley
3bc22dbd94 std.Build.Step.Options: exploit Io.File.Atomic 2026-01-07 11:03:36 -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
2fee64ceb0 update init template for new main API 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
e149c0e2aa std.Build.Step.Run: fix wrong environment passed 2026-01-04 00:27:08 -08:00
Andrew Kelley
af164b3f3c std.Build.Step.Run: no need to sort the environment
since we now use ArrayHashMap, the order is deterministic, and in fact,
observable by applications.
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
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
69d07472a1 std lib tests passing on linux 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
Matthew Lugg
d024d9f005
std.Build: crashes in the test runner are fatal errors 2026-01-03 14:52:11 +00: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