29 Commits

Author SHA1 Message Date
John Benediktsson
37ecaae639
std.fmt: migrate bufPrintZ to bufPrintSentinel (#25260) 2025-09-19 05:02:22 +00:00
Andrew Kelley
ef14c73245 Compilation: remove last instance of deprecatedReader
This also makes initStreaming preemptively disable file size checking.
2025-08-16 14:46:20 -07:00
Andrew Kelley
749f10af49 std.ArrayList: make unmanaged the default 2025-08-11 15:52:49 -07:00
lumanetic
afa66f6111 std.process.Child: fix double path normalization in spawnWindows
besides simply being redundant work, the now removed normalize call would cause
spawn to errantly fail (BadPath) when passing a relative path which traversed
'above' the current working directory. This case is already handled by leaving
normalization to the windows.wToPrefixedFileW call in
windowsCreateProcessPathExt
2025-07-26 01:34:19 -04:00
Andrew Kelley
b8955a2e0a std.Io.poll: update to new I/O API 2025-07-23 21:25:34 -07:00
Andrew Kelley
0e37ff0d59 std.fmt: breaking API changes
added adapter to AnyWriter and GenericWriter to help bridge the gap
between old and new API

make std.testing.expectFmt work at compile-time

std.fmt no longer has a dependency on std.unicode. Formatted printing
was never properly unicode-aware. Now it no longer pretends to be.

Breakage/deprecations:
* std.fs.File.reader -> std.fs.File.deprecatedReader
* std.fs.File.writer -> std.fs.File.deprecatedWriter
* std.io.GenericReader -> std.io.Reader
* std.io.GenericWriter -> std.io.Writer
* std.io.AnyReader -> std.io.Reader
* std.io.AnyWriter -> std.io.Writer
* std.fmt.format -> std.fmt.deprecatedFormat
* std.fmt.fmtSliceEscapeLower -> std.ascii.hexEscape
* std.fmt.fmtSliceEscapeUpper -> std.ascii.hexEscape
* std.fmt.fmtSliceHexLower -> {x}
* std.fmt.fmtSliceHexUpper -> {X}
* std.fmt.fmtIntSizeDec -> {B}
* std.fmt.fmtIntSizeBin -> {Bi}
* std.fmt.fmtDuration -> {D}
* std.fmt.fmtDurationSigned -> {D}
* {} -> {f} when there is a format method
* format method signature
  - anytype -> *std.io.Writer
  - inferred error set -> error{WriteFailed}
  - options -> (deleted)
* std.fmt.Formatted
  - now takes context type explicitly
  - no fmt string
2025-07-07 22:43:51 -07:00
Jonathan Marler
1408288b95 support more process creation options on Windows
Adds a CreateProcessFlags packed struct for all the possible flags to
CreateProcessW on windows.  In addition, propagates the existing
`start_suspended` option in std.process.Child which was previously only
used on Darwin.  Also adds a `create_no_window` option to std.process.Child
which is a commonly used flag for launching console executables on
windows without causing a new console window to "pop up".
2025-03-25 23:48:27 +01:00
Pat Tullmann
f304d8e50a windows: Use AccessDenied for ACCESS_DENIED on Windows
Windows defines an `ACCESS_DENIED` error code.  There is no
PERMISSION_DENIED (or its equivalent) which seems to only exist on POSIX
systems.  Fix a couple Windows calls code to return `error.AccessDenied`
for `ACCESS_DENIED` and to stop mapping AccessDenied into
PermissionDenied.
2025-03-24 16:20:45 +01:00
Ryan Liptak
b46f9945a8 process.Child.collectOutput: Switch to Allocator/ArrayListUnmanaged
Removes an inadvisable comparison of Allocator.ptr fields
2025-02-03 17:07:27 -08:00
Alex Kladov
4de2b1ea65 std: don't leak a process in Child.run in case of an error
Closes: #22433
2025-01-31 17:57:39 +01:00
mlugg
048e85f27e
std.process.Child: add waitForSpawn
`std.Build.Step.Run` makes the very reasonable assumption that
`error.InvalidExe` will be reported on `spawn` if it will happen.
However, this property does not currently hold on POSIX targets. This
is, through a slightly convoluted series of events, partially
responsible for the sporadic `BrokenPipe` errors we've been seeing more
and more in CI runs.

Making `spawn` wait for the child to exec in the POSIX path introduces
a block of up to 400us. So, instead of doing that, we add a new API for
this particular case: `waitForSpawn`. This function is a nop on Windows,
but on POSIX it blocks until the child successfully (or otherwise) calls
`execvpe`, and reports the error if necessary. `std.Build.Step.Run`
calls this function, so that it can get `error.InvalidExe` when it wants
it.

I'm not convinced that this API is optimal. However, I think this entire
API needs to be either heavily refactored or straight-up redesigned
(related: #22504), so I'm not too worried about hitting the perfect API:
I'd rather just fix this bug for now, and figure out the long-term goal
a bit later.
2025-01-20 00:27:19 +00:00
Justin Braben
d16a9b0acb
std.os.windows: Map PIPE_NOT_AVAILABLE from OpenFile() to error.NoDevice (#21938) 2024-11-27 22:33:29 +01:00
Andrew Kelley
aa5341bf85 std.process.Child: explicit error set for wait 2024-11-25 14:18:55 -08:00
Alex Kladov
ffd071f558 fix IB in fifoToOwnedArrayList
memcpy requires non-overlapping arguments.

fifo.realign() handles this case correctly and tries to provide an
optimized implementation.

This probably wasn't hit in practice, as, in a typical usage, fifo's
head is not advanced.
2024-09-24 13:19:06 -07:00
Linus Groh
8588964972 Replace deprecated default initializations with decl literals 2024-09-12 16:01:23 +01:00
mlugg
0fe3fd01dd
std: update std.builtin.Type fields to follow naming conventions
The compiler actually doesn't need any functional changes for this: Sema
does reification based on the tag indices of `std.builtin.Type` already!
So, no zig1.wasm update is necessary.

This change is necessary to disallow name clashes between fields and
decls on a type, which is a prerequisite of #9938.
2024-08-28 08:39:59 +01:00
Nguyễn Gia Phong
759ab41d72
Allow setting PGID in std.process.Child.spawn 2024-07-22 11:50:00 +09:00
Lucas Santos
89942ebd03
Better implementation of GetLastError. (#20623)
Instead of calling the dynamically loaded kernel32.GetLastError, we can extract it from the TEB.
As shown by [Wine](34b1606019/include/winternl.h (L439)), the last error lives at offset 0x34 of the TEB in 32-bit Windows and at offset 0x68 in 64-bit Windows.
2024-07-15 10:49:51 -07:00
Alex Rønne Petersen
9be9b8ca90 std.Build.findProgram(): Try with and without the Windows executable extensions.
I renamed std.process.Child.CreateProcessSupportedExtension to WindowsExtension
and made it public to avoid duplicating the list of extensions.

While here, I also improved it to not misreport OOM from std.fs.realpathAlloc()
as a generic failure to find the program, but instead panic like the rest of the
build system does for OOM.

Closes #20314.
2024-06-21 15:41:03 -04:00
Andrew Kelley
42658de762 std.process.Child: run fn accepts std.Progress.Node
There was not a way to pass a progress node to this function until now.
2024-06-16 19:28:13 -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
e2e61f3296 std.process.Child: comptime assert to protect prog_fileno
documenting my assumptions via comptime assertion
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
c01cfde688 std.process.Child: fix ZIG_PROGRESS env var handling
and properly dup2 the file descriptor to make it handle the case when
other files are already open
2024-05-27 20:56:48 -07:00
Andrew Kelley
df46f5af69 std.Progress: include subtrees from child processes 2024-05-27 20:56:48 -07:00
Andrew Kelley
f07116404a std.Progress: child process sends updates via IPC 2024-05-27 20:56:48 -07:00
Matthew Lugg
389181f6be std.process.Child: prevent racing children from inheriting one another's pipes
The added comment explains the issue here relatively well. The new
progress API made this bug obvious because it became visibly clear that
certain Compile steps were seemingly "hanging" until other steps
completed. As it turned out, these child processes had raced to spawn,
and hence one had inherited the other's stdio pipes, meaning the `poll`
call in `std.Build.Step.evalZigProcess` was not identifying the child
stdout as closed until an unrelated process terminated.
2024-05-26 16:44:14 -04:00
Ryan Liptak
aa463adc91 std.process.Child: Improve doc comments of Windows argv -> command line functions 2024-05-26 09:37:14 -07:00
Andrew Kelley
f47824f24d std: restructure child process namespace 2024-05-26 09:31:55 -07:00