Commit graph

219 commits

Author SHA1 Message Date
Jacob Young
a28d57292f IoUring: update to new Io APIs 2026-02-09 10:47:21 -05:00
Jacob Young
b5bd494606 std.Threaded: replace more kernel32 functions with ntdll 2026-02-07 00:02:50 -05:00
Andrew Kelley
d45f9aca14 std.Thread: delete Mutex.Recursive
Replaced by the lockStderr functions of std.Io. Trying to make
`std.process.stderr_thread_mutex` be a bridge across different Io
implementations didn't work in practice.
2026-02-03 20:46:25 -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
Tom Winter
83abd73801 Windows: Support directory handle for cwd instead of string for Child.process
This implementation is a bit of a hacky workaround, as we use a ntdll
API to grab the full path of the directory handle. As far as I can tell
this might be the only solution to the problem, as
kernel32.CreateProcessW takes a directory path as a string only.

I might be wrong though as haven't researched the problem thoroughly.
2026-02-02 01:21:11 -08:00
Andrew Kelley
a520355e4c std.process: simplify RunError set 2026-01-30 22:03:14 -08:00
Andrew Kelley
687123a85e std.process.run: use Io.File.MultiReader
and delete the special-cased function
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
642f329ac9 std.Io: exploring a different batch API proposal 2026-01-30 22:03:14 -08:00
Andrew Kelley
e2a266e744 Revert "std.process.Child: rewrite using concurrent"
This reverts commit 76e1ba8f490812c6e2ebf6f6becd89a71275d21e.
2026-01-30 22:03:13 -08:00
Andrew Kelley
87408f8add std.process.Child: rewrite using concurrent
I plan to immediately revert this, but here's a commit for posterity
2026-01-30 22:03:13 -08:00
Andrew Kelley
05064e1281 std.Io: simplify operate function
- no timeout
- no n_wait
- infallible
2026-01-30 22:03:13 -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
36eb8dec98 std.posix: goodbye to some functions
- fstat
- inotify_init1
- inotify_add_watch, inotify_add_watchZ
- inotify_rm_watch
- sysctlbynameZ
2026-01-30 01:58:49 -08: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
Andrew Kelley
18c6abc0ba std: finish moving os.windows.ReadLink logic to Io.Threaded
- remove error.SharingViolation from all error sets since it has the
  same meaning as FileBusy
- add error.FileBusy to CreateFileAtomicError and ReadLinkError
- update dirReadLinkWindows to use NtCreateFile and NtFsControlFile and
  integrate with cancelation properly.
- move windows CTL_CODE constants to the proper namespace
- delete os.windows.ReadLink
2026-01-28 17:02:17 -08:00
llogick
11c3b4bd41 Fix std.process.run leaking memory if child.wait returned an error 2026-01-28 03:12:00 +01:00
Ryan Liptak
29b7214027 Disentangle from error.CurrentWorkingDirectoryUnlinked
This error is actually only ever directly returned from `std.posix.getcwd` (and only on POSIX systems, so never on Windows). Its inclusion in almost all of the error sets its currently found in is a leftover from when `std.fs.path.resolve` called `std.process.getCwdAlloc` (https://github.com/ziglang/zig/issues/13613).
2026-01-27 20:48:25 +01:00
Michael Dusan
f186809caf
std: impl process.totalSystemMemory for netbsd 2026-01-25 13:03:22 -05:00
Andrew Kelley
7b21fd7244 std.Io.Threaded: fix memory mapping on windows
- set protection flags properly
- handle when mapping fails after unmapping
2026-01-15 14:18:21 -08:00
Andrew Kelley
5a7dc4b0fa std.Io: introduce File.MemoryMap
by defining the pointer contents to only be synchronized after explicit
sync points, makes it legal to have a fallback implementation based on
file operations while still supporting a handful of use cases for memory
mapping.

furthermore, it makes it legal for evented I/O implementations to use
evented file I/O for the sync points rather than memory mapping.

not yet done:
- implement checking the length when options.len is null
- some windows impl work
- some wasi impl work
- unit tests
- integration with compiler
2026-01-15 14:18:20 -08:00
Alex Rønne Petersen
e8a6e58f9d
std.process: fix some page size assumptions in lockMemory/protectMemory tests
Makes the tests work on hexagon and loongarch.
2026-01-11 03:07:45 +01:00
Alex Rønne Petersen
9acfd167fa
std.process: add PermissionDenied to ProtectMemoryError (for OpenBSD)
See EPERM notes on https://man.openbsd.org/mprotect.2.
2026-01-10 21:04:20 +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
Andrew Kelley
6a5bb3ede3 std: find a better home for the "preopens" concept 2026-01-08 05:06:31 +01:00
Andrew Kelley
ff67f70cf9 start: tweak default allocator choices
On wasm targets, when libc is linked, we have to go through libc.
2026-01-04 00:27:09 -08:00
Andrew Kelley
dd7be75f7c std.process: add missing error.OperationUnsupported 2026-01-04 00:27:09 -08:00
Andrew Kelley
baa49e5929 std.Io.Threaded: implement processReplace 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
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
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
Andrew Kelley
fa79d34674 std: add changing cur dir back
There's a good argument to not have this in the std lib but it's more
work to remove it than to leave it in, and this branch is already
20,000+ lines changed.
2025-12-23 22:15:12 -08:00
Andrew Kelley
3e624e17a4 std: fix compilation errors on FreeBSD 2025-12-23 22:15:11 -08:00
Andrew Kelley
405db921dc std: fix compilation targeting WASI 2025-12-23 22:15:11 -08:00
Ryan Liptak
406950f756 std.process: Fix executableDirPath functions 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
aa57793b68 std: rework locking stderr 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
e68ae8d7a1 update uses of std.debug.lockStdErr 2025-12-23 22:15:09 -08:00
Andrew Kelley
ffcbd48a12 std: rework TTY detection and printing
This commit sketches an idea for how to deal with detection of file
streams as being terminals.

When a File stream is a terminal, writes through the stream should have
their escapes stripped unless the programmer explicitly enables terminal
escapes. Furthermore, the programmer needs a convenient API for
intentionally outputting escapes into the stream. In particular it
should be possible to set colors that are silently discarded when the
stream is not a terminal.

This commit makes `Io.File.Writer` track the terminal mode in the
already-existing `mode` field, making it the appropriate place to
implement escape stripping.

`Io.lockStderrWriter` returns a `*Io.File.Writer` with terminal
detection already done by default. This is a higher-level application
layer stream for writing to stderr.

Meanwhile, `std.debug.lockStderrWriter` also returns a `*Io.File.Writer`
but a lower-level one that is hard-coded to use a static single-threaded
`std.Io.Threaded` instance. This is the same instance that is used for
collecting debug information and iterating the unwind info.
2025-12-23 22:15:09 -08:00
Andrew Kelley
9ccd68de0b std: move abort and exit from posix into process
and delete the unit tests that called fork()

no forking allowed in the std lib, including unit tests, except to implement child process spawning.
2025-12-23 22:15:08 -08:00
Andrew Kelley
9169983159 std.fs: migrate most of the API elsewhere 2025-12-23 22:15:08 -08:00
Andrew Kelley
877032ec6a std: reorganize realpath and process executable APIs 2025-12-23 22:15:08 -08:00
Andrew Kelley
aafddc2ea1 update all occurrences of close() to close(io) 2025-12-23 22:15:07 -08:00
Adrià Arrufat
02c5f05e2f std: replace usages of std.mem.indexOf with std.mem.find 2025-12-05 14:31:27 +01:00
Zihad
cb115cf73a std.process.ArgIteratorWasi: fix no-args deinit 2025-12-03 08:35:24 +01:00
Ryan Liptak
53e615b920
Merge pull request #25993 from squeek502/windows-paths
Teach `std.fs.path` about the wonderful world of Windows paths
2025-11-24 15:27:24 -08:00
rpkak
6b4f45f782 system specific errno 2025-11-20 15:03:23 -08:00