aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
AgeCommit message (Collapse)Author
6 hoursopenbsd: initialize Io.Threaded.argv0Michael Dusan
5 daysCLI: lock stderr while running jit cmdAndrew Kelley
5 dayscompiler: add missing end() for root std.Progress nodesAndrew Kelley
otherwise the progress task prevents main() from returning
5 daysstd.Io.Threaded: accept argv and environ on initAndrew Kelley
This is needed unfortunately for OpenBSD and Haiku for process executable path. I made it so that you can omit the options usually, but you get a compile error if you omit the options on those targets.
5 daysUpdate a few more callsites for std.Io changesRyan Liptak
5 daysstd: rename other Dir "make" functions to "create"Andrew Kelley
5 dayscompiler: fix build from source on macOSAndrew Kelley
5 daysfix more fallout from locking stderrAndrew Kelley
5 dayscompiler: fix most compilation errors from std.fs changesAndrew Kelley
5 dayslink.MappedFile: update statx usageAndrew Kelley
5 daysupdate lockStderrWriter sitesAndrew Kelley
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.
5 daysstd.process.cleanExit: take an Io parameterAndrew Kelley
In case exit(0) will be called, this provides the opportunity for the application's Io instance to be the one to clear the terminal in case std.Progress or similar was used.
5 daysupdate uses of std.debug.lockStdErrAndrew Kelley
5 dayslink: update to new file system APIsAndrew Kelley
5 dayscompiler: update various code to new fs APIAndrew Kelley
5 daysstd: rework TTY detection and printingAndrew Kelley
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.
5 daysstd.heap.DebugAllocator: never detect TTY configAndrew Kelley
instead, allow the user to set it as a field. this fixes a bug where leak printing and error printing would run tty config detection for stderr, and then emit a log, which is not necessary going to print to stderr. however, the nice defaults are gone; the user must explicitly assign the tty_config field during initialization or else the logging will not have color. related: https://github.com/ziglang/zig/issues/24510
5 daysfix a handful of compilation errors related to std.fs migrationAndrew Kelley
5 daysupdate makeDir() sites to specify permissionsAndrew Kelley
5 daysupdate std.process.Child.run occurences to use ioAndrew Kelley
5 daysupdate all readFileAlloc() to accept Io instanceAndrew Kelley
5 daysupdate all rename() to rename(io)Andrew Kelley
5 daysstd.Build.Cache: remove readSmallFile and writeSmallFileAndrew Kelley
These were to support optimizations involving detecting when to avoid calling into LLD, which are no longer implemented.
5 daysupdate all access() to access(io)Andrew Kelley
5 daysstd: move abort and exit from posix into processAndrew Kelley
and delete the unit tests that called fork() no forking allowed in the std lib, including unit tests, except to implement child process spawning.
5 daysupdate all openDir() sites to accept io instanceAndrew Kelley
5 daysupdate all std.fs.cwd() to std.Io.Dir.cwd()Andrew Kelley
5 daysupdate all occurrences of openFile to receive an io instanceAndrew Kelley
5 daysupdate all occurrences of close() to close(io)Andrew Kelley
7 dayscompiler: replace thread pool with `std.Io`Matthew Lugg
Eliminate the `std.Thread.Pool` used in the compiler for concurrency and asynchrony, in favour of the new `std.Io.async` and `std.Io.concurrent` primitives. This removes the last usage of `std.Thread.Pool` in the Zig repository.
2025-12-06Merge pull request 'link: support `--dependency-file` linker option' ↵Alex Rønne Petersen
(#30073) from alexrp/zig:elf-depfile into master Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30073 Reviewed-by: mlugg <mlugg@noreply.codeberg.org>
2025-12-06std.heap: rework `c_allocator`Matthew Lugg
The main goal here was to avoid allocating padding and header space if `malloc` already guarantees the alignment we need via `max_align_t`. Previously, the compiler was using `std.heap.raw_c_allocator` as its GPA in some cases depending on `std.c.max_align_t`, but that's pretty fragile (it meant we had to encode our alignment requirements into `src/main.zig`!). Perhaps more importantly, that solution is unnecessarily restrictive: since Zig's `Allocator` API passes the `Alignment` not only to `alloc`, but also to `free` etc, we are able to use a different strategy depending on its value. So `c_allocator` can simply compare the requested align to `Alignment.of(std.c.max_align_t)`, and use a raw `malloc` call (no header needed!) if it will guarantee a suitable alignment (which, in practice, will be true the vast majority of the time). So in short, this makes `std.heap.c_allocator` more memory efficient, and probably removes any incentive to use `std.heap.raw_c_allocator`. I also refactored the `c_allocator` implementation while doing this, just to neaten things up a little.
2025-12-05compiler: handle -Xlinker args similarly to -Wl argsAlex Rønne Petersen
2025-12-05compiler: support --dependency-file linker optionAlex Rønne Petersen
closes https://github.com/ziglang/zig/issues/22213
2025-11-25fetch: update from std.Thread.Pool to std.IoAndrew Kelley
2025-11-24Merge pull request #25993 from squeek502/windows-pathsRyan Liptak
Teach `std.fs.path` about the wonderful world of Windows paths
2025-11-22all: replace all `@Type` usagesAli Cheraghi
Co-authored-by: Matthew Lugg <mlugg@mlugg.co.uk>
2025-11-21Teach fs.path about the wonderful world of Windows pathsRyan Liptak
Previously, fs.path handled a few of the Windows path types, but not all of them, and only a few of them correctly/consistently. This commit aims to make `std.fs.path` correct and consistent in handling all possible Win32 path types. This commit also slightly nudges the codebase towards a separation of Win32 paths and NT paths, as NT paths are not actually distinguishable from Win32 paths from looking at their contents alone (i.e. `\Device\Foo` could be an NT path or a Win32 rooted path, no way to tell without external context). This commit formalizes `std.fs.path` being fully concerned with Win32 paths, and having no special detection/handling of NT paths. Resources on Windows path types, and Win32 vs NT paths: - https://googleprojectzero.blogspot.com/2016/02/the-definitive-guide-on-win32-to-nt.html - https://chrisdenton.github.io/omnipath/Overview.html - https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file API additions/changes/deprecations - `std.os.windows.getWin32PathType` was added (it is analogous to `RtlDetermineDosPathNameType_U`), while `std.os.windows.getNamespacePrefix` and `std.os.windows.getUnprefixedPathType` were deleted. `getWin32PathType` forms the basis on which the updated `std.fs.path` functions operate. - `std.fs.path.parsePath`, `std.fs.path.parsePathPosix`, and `std.fs.path.parsePathWindows` were added, while `std.fs.path.windowsParsePath` was deprecated. The new `parsePath` functions provide the "root" and the "kind" of a path, which is platform-specific. The now-deprecated `windowsParsePath` did not handle all possible path types, while the new `parsePathWindows` does. - `std.fs.path.diskDesignator` has been deprecated in favor of `std.fs.path.parsePath`, and same deal with `diskDesignatorWindows` -> `parsePathWindows` - `relativeWindows` is now a compile error when *not* targeting Windows, while `relativePosix` is now a compile error when targeting Windows. This is because those functions read/use the CWD path which will behave improperly when used from a system with different path semantics (e.g. calling `relativePosix` from a Windows system with a CWD like `C:\foo\bar` will give you a bogus result since that'd be treated as a single relative component when using POSIX semantics). This also allows `relativeWindows` to use Windows-specific APIs for getting the CWD and environment variables to cut down on allocations. - `componentIterator`/`ComponentIterator.init` have been made infallible. These functions used to be able to error on UNC paths with an empty server component, and on paths that were assumed to be NT paths, but now: + We follow the lead of `RtlDetermineDosPathNameType_U`/`RtlGetFullPathName_U` in how it treats a UNC path with an empty server name (e.g. `\\\share`) and allow it, even if it'll be invalid at the time of usage + Now that `std.fs.path` assumes paths are Win32 paths and not NT paths, we don't have to worry about NT paths Behavior changes - `std.fs.path` generally: any combinations of mixed path separators for UNC paths are universally supported, e.g. `\/server/share`, `/\server\share`, `/\server/\\//share` are all seen as equivalent UNC paths - `resolveWindows` handles all path types more appropriately/consistently. + `//` and `//foo` used to be treated as a relative path, but are now seen as UNC paths + If a rooted/drive-relative path cannot be resolved against anything more definite, the result will remain a rooted/drive-relative path. + I've created [a script to generate the results of a huge number of permutations of different path types](https://gist.github.com/squeek502/9eba7f19cad0d0d970ccafbc30f463bf) (the result of running the script is also included for anyone that'd like to vet the behavior). - `dirnameWindows` now treats the drive-relative root as the dirname of a drive-relative path with a component, e.g. `dirname("C:foo")` is now `C:`, whereas before it would return null. `dirnameWindows` also handles local device paths appropriately now. - `basenameWindows` now handles all path types more appropriately. The most notable change here is `//a` being treated as a partial UNC path now and therefore `basename` will return `""` for it, whereas before it would return `"a"` - `relativeWindows` will now do its best to resolve against the most appropriate CWD for each path, e.g. relative for `D:foo` will look at the CWD to check if the drive letter matches, and if not, look at the special environment variable `=D:` to get the shell-defined CWD for that drive, and if that doesn't exist, then it'll resolve against `D:\`. Implementation details - `resolveWindows` previously looped through the paths twice to build up the relevant info before doing the actual resolution. Now, `resolveWindows` iterates backwards once and keeps track of which paths are actually relevant using a bit set, which also allows it to break from the loop when it's no longer possible for earlier paths to matter. - A standalone test was added to test parts of `relativeWindows` since the CWD resolution logic depends on CWD information from the PEB and environment variables Edge cases worth noting - A strange piece of trivia that I found out while working on this is that it's technically possible to have a drive letter that it outside the intended A-Z range, or even outside the ASCII range entirely. Since we deal with both WTF-8 and WTF-16 paths, `path[0]`/`path[1]`/`path[2]` will not always refer to the same bits of information, so to get consistent behavior, some decision about how to deal with this edge case had to be made. I've made the choice to conform with how `RtlDetermineDosPathNameType_U` works, i.e. treat the first WTF-16 code unit as the drive letter. This means that when working with WTF-8, checking for drive-relative/drive-absolute paths is a bit more complicated. For more details, see the lengthy comment in `std.os.windows.getWin32PathType` - `relativeWindows` will now almost always be able to return either a fully-qualified absolute path or a relative path, but there's one scenario where it may return a rooted path: when the CWD gotten from the PEB is not a drive-absolute or UNC path (if that's actually feasible/possible?). An alternative approach to this scenario might be to resolve against the `HOMEDRIVE` env var if available, and/or default to `C:\` as a last resort in order to guarantee the result of `relative` is never a rooted path. - Partial UNC paths (e.g. `\\server` instead of `\\server\share`) are a bit awkward to handle, generally. Not entirely sure how best to handle them, so there may need to be another pass in the future to iron out any issues that arise. As of now the behavior is: + For `relative`, any part of a UNC disk designator is treated as the "root" and therefore isn't applicable for relative paths, e.g. calling `relative` with `\\server` and `\\server\share` will result in `\\server\share` rather than just `share` and if `relative` is called with `\\server\foo` and `\\server\bar` the result will be `\\server\bar` rather than `..\bar` + For `resolve`, any part of a UNC disk designator is also treated as the "root", but relative and rooted paths are still elligable for filling in missing portions of the disk designator, e.g. `resolve` with `\\server` and `foo` or `\foo` will result in `\\server\foo` Fixes #25703 Closes #25702
2025-11-20update deprecated ArrayListUnmanaged usage (#25958)Benjamin Jurk
2025-11-14represent Mac Catalyst as aarch64-maccatalyst-none rather than ↵Alex Rønne Petersen
aarch64-ios-macabi Apple's own headers and tbd files prefer to think of Mac Catalyst as a distinct OS target. Earlier, when DriverKit support was added to LLVM, it was represented a distinct OS. So why Apple decided to only represent Mac Catalyst as an ABI in the target triple is beyond me. But this isn't the first time they've ignored established target triple norms (see: armv7k and aarch64_32) and it probably won't be the last. While doing this, I also audited all Darwin OS prongs throughout the codebase and made sure they cover all the tags.
2025-11-10compiler: warn when using -fincremental with LLVM backendMatthew Lugg
This configuration hasn't had much work put into it yet, so is all but guaranteed to miscompile or crash. Since users are starting to try out `-fincremental`, and LLVM is still the default backend in many cases, it's worth having this warning to avoid bug reports like https://github.com/ziglang/zig/issues/25873.
2025-11-10compiler: update logFn to use colorMatthew Lugg
To match the new default implementation. In fact, I implemented this by simply dispatching *to* the default implementation after the debug log guard; no need to complicate things!
2025-11-07Move/coalesce RcIncludes enum to `std.zig.RcIncludes`Ryan Liptak
2025-11-07Move/coalesce CompressDebugSections enum to `std.zig.CompressDebugSections`Ryan Liptak
2025-11-05Move `std.Target.SubSystem` to `std.zig.Subsystem`Carl Åstholm
Also updates the field names to conform with the rest of std.
2025-10-30Merge pull request #25558 from jacobly0/elfv2-load-objJacob Young
Elf2: start implementing input object loading
2025-10-30std.debug.lockStderrWriter: also return ttyconfMatthew Lugg
`std.Io.tty.Config.detect` may be an expensive check (e.g. involving syscalls), and doing it every time we need to print isn't really necessary; under normal usage, we can compute the value once and cache it for the whole program's execution. Since anyone outputting to stderr may reasonably want this information (in fact they are very likely to), it makes sense to cache it and return it from `lockStderrWriter`. Call sites who do not need it will experience no significant overhead, and can just ignore the TTY config with a `const w, _` destructure.
2025-10-29Elf2: start implementing dynamic linkingJacob Young
2025-10-29std: move DNS record enum to a better namespaceAndrew Kelley
2025-10-29compiler: update for introduction of std.IoAndrew Kelley
only thing remaining is using libc dns resolution when linking libc