aboutsummaryrefslogtreecommitdiff
path: root/lib/std/child_process.zig
AgeCommit message (Collapse)Author
2022-09-11Compilation: handle system C compiler not foundAndrew Kelley
When linking libc and compiling natively, Zig tries to integrate with the system C compiler. However, this caused Zig to fail when no system C compiler is installed, despite the fact that Zig is perfectly capable of compiling & linking libc without one. This commit makes Zig fall back to using its own ability to provide libc in the case that no C compiler is installed. For glibc, it means sometimes getting the warning "zig cannot build new glibc version abc, providing instead xyz". Ideally, Zig would do some more validation about the system libraries being linked against, and report an error in case it could not provide the exact correct libc version of the system libraries (or that the system libraries themselves conflict with each other), however, I think it is fair to call that a separate enhancement.
2022-05-27math: make `cast` return optional instead of an errorAli Chraghi
2022-05-26std.testing: remove tight coupling with executing zig as child processAndrew Kelley
This tight coupling causes problems for various targets, requires hacky "get args" functionality, and bungles relative file system paths, making invalid assumptions about the zig-cache directory. In short, these are not unit tests; these should be standalone tests instead. Reverts e5d4a694ea7dd251e10d6434c9321b5e0a548d4b Reverts d976456ef665bf0aba3a83a8e7fccb4a92b2d3b2 Reverts dbbda0f41a7c5e214801925f8447a15193c3c731 Closes #11542
2022-05-11remove extra storage from EnvMap on windowsJonathan Marler
2022-05-11Update usages of `process.getEnvMap` and change BufMap -> EnvMap where ↵Jonathan Marler
applicable # Conflicts: # lib/std/build/RunStep.zig
2022-04-29std: Do not allocate the result for ChildProcess.initJimmi Holst Christensen
Instead, just return ChildProcess directly. This structure does not require a stable address, so we can put it on the stack just fine. If someone wants it on the heap they should do. const proc = try allocator.create(ChildProcess); proc.* = ChildProcess.init(args, allocator);
2022-04-28Revert "std.testing: add writeZigFile for TmpDir"Andrew Kelley
This reverts commit 7f13f5cd5f5a518638b15d7225eae2d88ec1efb5. I'd like to review this one before it goes in. This is an awfully specific API that I don't think belongs in std.testing. Also I don't want any code snippets in doc strings. We have doctests for that.
2022-04-28std.testing: add writeZigFile for TmpDirmatu3ba
* remove need for manual string concatenation for building binaries in test blocks * include small program snippet to show how to get binary path with subslicing
2022-04-21ran zig fmt on changesRabin Gaire
2022-04-21update test message and using unreachable keyword for unintended test code pathRabin Gaire
2022-04-20add test case for child_process spawn logicRabin Gaire
tests creating a child process with stdin/stdout behavior set to StdIo.Pipe.
2022-04-20fix child process spawn on macos hangs issueRabin Gaire
When a child process with stdin, stdout behavior set to pipe is ran on macos it used to hang which has been fixed. Issue existed because we forgot to call `posix_spawn_file_actions_addclose` syscall on user exposed file descriptor which resulted on file descriptor not closing properly.
2022-03-27std.testing: add methods tmpDirPath, getTestArgs, buildExematu3ba
continuation of #11093 to simplify testing IPC * use cases - get path to temporary directory - get the test arguments inside test block for reusage - build executables from text within test blocks, ie to test IPC * missing conventions - how to name and debug test cases - where do simple+repititve build commands for testing belong
2022-03-16std: introduce posix_spawn as an alt to fork-execJakub Konka
Currently, the new API will only be available on macOS with the intention of adding more POSIX systems to it incrementally (such as Linux, etc.). Changes: * add `posix_spawn` wrappers in a separate container in `os/posix_spawn.zig` * rewrite `ChildProcess.spawnPosix` using `posix_spawn` targeting macOS as `ChildProcess.spawnMacos` * introduce a `posix_spawn` specific `std.c.waitpid` wrapper which does return an error in case the child process failed to exec - this is required for any process that was spawned using `posix_spawn` mechanism as, by definition, the errors returned by `posix_spawn` routine cover only the `fork`-equivalent; `pre-exec()` and `exec()` steps are covered by a catch-all error `ECHILD` returned by `waitpid` on unsuccessful execution, e.g., no such file error, etc.
2022-03-12std: add test for child_processmatu3ba
- Cli operations should be refactored, since the standard test runner has an expected argument structure. This would also ensure that the test cli is usable as tested library with checks for subprocess error or success instead of "hacky shell script interfaces". - Default paths generation based on tmpDir would also be useful. - Anonymous pipes on windows are generated from named pipes - Async IO does not work on anonymous pipes - Remove finished TODO
2022-03-03stdlib: Add emulated CWD to std.os for WASI targetsCody Tapscott
This adds a special CWD file descriptor, AT.FDCWD (-2), to refer to the current working directory. The `*at(...)` functions look for this and resolve relative paths against the stored CWD. Absolute paths are dynamically matched against the stored Preopens. "os.initPreopensWasi()" must be called before std.os functions will resolve relative or absolute paths correctly. This is asserted at runtime. Support has been added for: `open`, `rename`, `mkdir`, `rmdir`, `chdir`, `fchdir`, `link`, `symlink`, `unlink`, `readlink`, `fstatat`, `access`, and `faccessat`. This also includes limited support for `getcwd()` and `realpath()`. These return an error if the CWD does not correspond to a Preopen with an absolute path. They also do not currently expand symlinks.
2022-02-07Merge pull request #10813 from marler8997/windowsChildHangAndrew Kelley
child_process: collectOutputWindows handle broken_pipe from ReadFile
2022-02-07fix bug when ReadFile returns synchronously in collectOutputWindowsJonathan Marler
2022-02-06Avoid depending on child process execution when not supported by host OSCody Tapscott
In accordance with the requesting issue (#10750): - `zig test` skips any tests that it cannot spawn, returning success - `zig run` and `zig build` exit with failure, reporting the command the cannot be run - `zig clang`, `zig ar`, etc. already punt directly to the appropriate clang/lld main(), even before this change - Native `libc` Detection is not supported Additionally, `exec()` and related Builder functions error at run-time, reporting the command that cannot be run
2022-02-06rework to allow ReadFile to complete synchronouslyJonathan Marler
2022-02-06fix bug I think I found while manually reviewingJonathan Marler
2022-02-06child_process: collectOutputWindows handle broken_pipe from ReadFileJonathan Marler
This was found on a user's machine when calling "git" as a child process from msys. Instead of getting BROKEN_PIPE on GetOverlappedREsult, it would occur on ReadFile which would then cause the function to hang because the async operation was never started.
2021-12-19stage1, stage2: rename c_void to anyopaque (#10316)Isaac Freund
zig fmt now replaces c_void with anyopaque to make updating code easy.
2021-11-30allocgate: renamed getAllocator function to allocatorLee Cannon
2021-11-30allocgate: std Allocator interface refactorLee Cannon
2021-11-30std lib API deprecations for the upcoming 0.9.0 releaseAndrew Kelley
See #3811
2021-10-17actually fix child process deadlock on windowsJonathan Marler
Looks like I forgot to remove windows from this workaround condition when I finished implementing the child process output collection on windows.
2021-10-04migrate from `std.Target.current` to `@import("builtin").target`Andrew Kelley
closes #9388 closes #9321
2021-09-19Improve ensureTotalCapacity call in ChildProcess.collectOutputWindowsRyan Liptak
Take current len and max_output_bytes into account instead of unconditionally using bump_amt
2021-09-19Update all ensureCapacity calls to the relevant non-deprecated versionRyan Liptak
2021-09-06stdlib: fix ChildProcess.killPosixTakeshi Yoneda
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-09-01std.os: more reorganization effortsAndrew Kelley
* std lib tests are passing on x86_64-linux with and without -lc * stage2 is building from source on x86_64-linux * down to 38 remaining uses of `usingnamespace`
2021-08-24remove redundant license headers from zig standard libraryAndrew Kelley
We already have a LICENSE file that covers the Zig Standard Library. We no longer need to remind everyone that the license is MIT in every single file. Previously this was introduced to clarify the situation for a fork of Zig that made Zig's LICENSE file harder to find, and replaced it with their own license that required annual payments to their company. However that fork now appears to be dead. So there is no need to reinforce the copyright notice in every single file.
2021-08-06Update all usages of mem.split/mem.tokenize for generic versionRyan Liptak
2021-06-18finish ChildProcess collectOutputWindowsJonathan Marler
This finishes LemonBoy's Draft PR ziglang#6750. It updates ChildProcess to collect the output from stdout/stderr asynchronously using Overlapped IO and named pipes.
2021-06-17std: Uniform polling logic for Windows and UnixLemonBoy
Keep polling until there are enough open handles, if the child process terminates closing the handles or explicitly closes them we just quit polling and wait for the process handle to signal the termination condition.
2021-06-17std: Avoid deadlocking in ChildProcess.execLemonBoy
Reading stdin&stderr at different times may lead to nasty deadlocks (eg. when stdout is read before stderr and the child process doesn't write anything onto stdout). Implement a polling mechanism to make sure this won't happen: we read data from stderr/stdout as it becomes ready and then it's copied into an ArrayList provided by the user, avoiding any kind of blocking read.
2021-06-12Make std.ChildProcess exit code u8 to match std.process.exitGarrett Squire
This patch adjusts the exit code for a child process to be a u8. Since the WEXITSTATUS macro returns the lower eight bits, it's safe to assume that we can truncate the returned u32.
2021-06-05std: Better handing of POLLHUP in ChildProcess (#8988)LemonBoy
* std: Better handing of POLLHUP in ChildProcess Upon hitting the EOF condition there are two main differences between how Linux and the *BSD-derived systems behave: the former sets POLLHUP and POLLIN and, after reading any residual data, only POLLHUP remains set. The latter signal the EOF condition by setting both flags thus requiring some extra checks to determine if the stream is "done". DragonFly workaround/hack for POLLHUP is no longer required. Closes #8969
2021-06-03Breaking hash map changes for 0.8.0Martin Wickham
- hash/eql functions moved into a Context object - *Context functions pass an explicit context - *Adapted functions pass specialized keys and contexts - new getPtr() function returns a pointer to value - remove functions renamed to fetchRemove - new remove functions return bool - removeAssertDiscard deleted, use assert(remove(...)) instead - Keys and values are stored in separate arrays - Entry is now {*K, *V}, the new KV is {K, V} - BufSet/BufMap functions renamed to match other set/map types - fixed iterating-while-modifying bug in src/link/C.zig
2021-05-23overhaul elf csu (c-runtime startup) logicMichael Dusan
- more support for linux, android, freebsd, netbsd, openbsd, dragonfly - centralize musl utils; musl logic is no longer intertwined with csu - fix musl compilation to build crti/crtn for full archs list - fix openbsd to support `zig build-lib -dynamic` - initial dragonfly linking success (with a warning) ancillary: - fix emutls (openbsd) tests to use `try`
2021-05-08Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgenAndrew Kelley
Conflicts: * doc/langref.html.in * lib/std/enums.zig * lib/std/fmt.zig * lib/std/hash/auto_hash.zig * lib/std/math.zig * lib/std/mem.zig * lib/std/meta.zig * test/behavior/alignof.zig * test/behavior/bitcast.zig * test/behavior/bugs/1421.zig * test/behavior/cast.zig * test/behavior/ptrcast.zig * test/behavior/type_info.zig * test/behavior/vector.zig Master branch added `try` to a bunch of testing function calls, and some lines also had changed how to refer to the native architecture and other `@import("builtin")` stuff.
2021-05-08std: update usage of std.testingVeikka Tuominen
2021-04-28Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgenAndrew Kelley
In particular I wanted to take advantage of the new hex float parsing code.
2021-04-23support output collection for haikuAl Hoang
2021-04-15std: change `@import("builtin")` to `std.builtin`Andrew Kelley
2021-01-07Reduce use of deprecated IO typesJay Petacat
Related: #4917
2020-12-31Year++Frank Denis
2020-12-29std.ChildProcess: fix max_output_bytes handlingAndrew Kelley
The previous logic had a false positive of returning an error when in fact the maximum number of output bytes had not been exceeded.
2020-12-29std.ChildProcess: improvements to collectOutputPosixAndrew Kelley
* read directly into the ArrayList buffers. * respect max_output_bytes * std.ArrayList: - make `allocatedSlice` public. - add `unusedCapacitySlice`. I removed the Windows implementation of this stuff; I am doing a partial merge of LemonBoy's patch with the understanding that a later patch can add the Windows implementation after it is vetted.