Add process.Child.Cwd, use it for cwd and remove cwd_dir field #31090

Merged
andrewrk merged 2 commits from squeek502/zig:unify-child-cwd into master 2026-02-02 19:56:43 +01:00
Member

Builds on the changes in #30112 (this branch contains a rebased version of that PR) and extends it, intending to close https://github.com/ziglang/zig/issues/5190.

Instead of deprecating/removing the []const u8 version of providing the CWD of a child process, the CWD option is now a tagged union with the fields inherit (inherit the CWD of the parent process), dir (provide CWD as an Io.Dir), or path (provide CWD as a []const u8). The reasoning for this is laid out here: #30112 (comment). The simple version is:

  • Windows must provide a path when specifying the CWD when spawning a process, so the path of an Io.Dir must be resolved before actually spawning
  • A directory handle may have multiple paths associated with it, so providing the CWD as a string retains a legitimate use case in cases where the precise path matters
Builds on the changes in https://codeberg.org/ziglang/zig/pulls/30112 (this branch contains a rebased version of that PR) and extends it, intending to close https://github.com/ziglang/zig/issues/5190. Instead of deprecating/removing the `[]const u8` version of providing the CWD of a child process, the CWD option is now a tagged union with the fields `inherit` (inherit the CWD of the parent process), `dir` (provide CWD as an `Io.Dir`), or `path` (provide CWD as a `[]const u8`). The reasoning for this is laid out here: https://codeberg.org/ziglang/zig/pulls/30112#issuecomment-8711850. The simple version is: - Windows must provide a path when specifying the CWD when spawning a process, so the path of an `Io.Dir` must be resolved before actually spawning - A directory handle may have multiple paths associated with it, so providing the CWD as a string retains a legitimate use case in cases where the precise path matters
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.
Add process.Child.Cwd, use it for cwd and remove cwd_dir field
All checks were successful
ci / x86_64-freebsd-release (pull_request) Successful in 40m20s
ci / x86_64-freebsd-debug (pull_request) Successful in 49m19s
ci / aarch64-macos-release (pull_request) Successful in 51m41s
ci / x86_64-openbsd-release (pull_request) Successful in 1h1m32s
ci / x86_64-windows-debug (pull_request) Successful in 47m38s
ci / x86_64-openbsd-debug (pull_request) Successful in 1h6m36s
ci / aarch64-macos-debug (pull_request) Successful in 1h7m48s
ci / x86_64-linux-debug (pull_request) Successful in 1h18m3s
ci / x86_64-windows-release (pull_request) Successful in 48m27s
ci / aarch64-linux-release (pull_request) Successful in 1h30m50s
ci / powerpc64le-linux-release (pull_request) Successful in 1h40m33s
ci / aarch64-linux-debug (pull_request) Successful in 2h15m21s
ci / x86_64-linux-debug-llvm (pull_request) Successful in 2h32m12s
ci / x86_64-linux-release (pull_request) Successful in 2h47m39s
ci / s390x-linux-release (pull_request) Successful in 1h40m38s
ci / s390x-linux-debug (pull_request) Successful in 2h19m29s
ci / powerpc64le-linux-debug (pull_request) Successful in 3h30m28s
ci / loongarch64-linux-release (pull_request) Successful in 2h13m2s
ci / loongarch64-linux-debug (pull_request) Successful in 3h12m10s
ci / riscv64-linux-debug (pull_request) Has been skipped
ci / riscv64-linux-release (pull_request) Has been skipped
05346e123b
The user must now explicitly choose between inheriting the current CWD, passing a path for the CWD, or passing a Dir for the CWD.
andrewrk approved these changes 2026-02-02 19:56:25 +01:00
andrewrk left a comment

Nice, thank you

Nice, thank you
andrewrk merged commit b71e593df4 into master 2026-02-02 19:56:43 +01:00
First-time contributor

Thank you for doing this! 🙏

Thank you for doing this! 🙏
squeek502 referenced this pull request from a commit 2026-03-08 10:38:41 +01:00
andrewrk referenced this pull request from a commit 2026-03-09 03:19:16 +01:00
GasInfinity referenced this pull request from a commit 2026-03-09 12:46:14 +01:00
gero3 referenced this pull request from a commit 2026-03-09 17:50:44 +01:00
invlpg referenced this pull request from a commit 2026-03-21 12:50:33 +01:00
ARandomOSDever referenced this pull request from a commit 2026-06-06 11:45:17 +02:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ziglang/zig!31090
No description provided.