Commit graph

678 commits

Author SHA1 Message Date
IOKG04
e23af9d31d Build.Step.Options: add comptime_float support
It seems to me this was simply forgotten.
Or there is some reason I don't know why this code doesn't work for `comptime_float`.

For a more comprehensive fix, https://github.com/ziglang/zig/pull/24057 is the place to look.
2025-11-26 09:57:49 +01:00
Andrew Kelley
5816646aa0
Merge pull request #26037 from ziglang/build-runner-std.Io
build runner: update from std.Thread.Pool to std.Io
2025-11-25 02:49:37 -08: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
Andrew Kelley
3f34f5e433 build runner: update Mutex and Condition usage to std.Io 2025-11-24 14:34:18 -08:00
Andrew Kelley
a242292644 build runner: update from std.Thread.Pool to std.Io 2025-11-24 14:34:18 -08:00
Ryan Liptak
59b8bed222 Teach fs.path about the wonderful world of Windows paths
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-21 00:03:44 -08:00
Benjamin Jurk
4b5351bc0d
update deprecated ArrayListUnmanaged usage (#25958) 2025-11-20 14:46:23 -08:00
Matthew Lugg
bc524a2b1a
std.Build: fix crashes running fuzz tests 2025-11-20 10:42:21 +00:00
Matthew Lugg
010dcd6a9b
fuzzer: account for runtime address slide
This is relevant to PIEs, which are notably enabled by default on macOS.
The build system needs to only see virtual addresses, that is, those
which do not have the slide applied; but the fuzzer itself naturally
sees relocated addresses (i.e. with the slide applied). We just need to
subtract the slide when we communicate addresses to the build system.
2025-11-20 10:42:20 +00:00
Matthew Lugg
0a330d4f94
std.debug.Info: basic Mach-O support 2025-11-20 10:42:20 +00:00
Matthew Lugg
0caca625eb
std.debug: split up Mach-O debug info handling
Like ELF, we now have `std.debug.MachOFile` for the host-independent
parts, and `std.debug.SelfInfo.MachO` for logic requiring the file to
correspond to the running program.
2025-11-20 10:42:20 +00:00
Harold
2f240d0819 std.Build.Step.Compile: add support for '-z defs' flag 2025-11-19 20:13:54 +01:00
Alex Rønne Petersen
acfb88e9a5
std.Build.Step.CheckObject: make ELF reading endianness-aware 2025-11-19 01:42:45 +01:00
Alex Rønne Petersen
e09ba67161
std.Build.Step.Run: read/write messages as little endian 2025-11-19 01:42:45 +01:00
Matthew Lugg
0922990367
std.Build.Step: send messages to compiler as little-endian
Little-endian is what `std.zig.Server` expects, but the old logic just
send the raw bytes of the struct, so sent in native endian (causing a
crash on big-endian targets).
2025-11-19 01:42:45 +01:00
Matthew Lugg
c6b5945356 std.Build: don't force all children to inherit color option
The build runner was previously forcing child processes to have their
stderr colorization match the build runner by setting `CLICOLOR_FORCE`
or `NO_COLOR`. This is a nice idea in some cases---for instance a simple
`Run` step which we just expect to exit with code 0 and whose stderr is
not being programmatically inspected---but is a bad idea in others, for
instance if there is a check on stderr or if stderr is captured, in
which case forcing color on the child could cause checks to fail.

Instead, this commit adds a field to `std.Build.Step.Run` which
specifies a behavior for the build runner to employ in terms of
assigning the `CLICOLOR_FORCE` and `NO_COLOR` environment variables. The
default behavior is to set `CLICOLOR_FORCE` if the build runner's output
is colorized and the step's stderr is not captured, and to set
`NO_COLOR` otherwise. Alternatively, colors can be always enabled,
always disabled, always match the build runner, or the environment
variables can be left untouched so they can be manually controlled
through `env_map`.

Notably, this fixes a failure when running `zig build test-cli` in a
TTY (or with colors explicitly enabled). GitHub CI hadn't caught this
because it does not request color, but Codeberg CI now does, and we were
seeing a failure in the `zig init` test because the actual output had
color escape codes in it due to 6d280dc.
2025-11-14 21:50:24 +01:00
Alex Rønne Petersen
9ab7eec23e represent Mac Catalyst as aarch64-maccatalyst-none rather than 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-14 11:33:35 +01:00
Ryan Liptak
da77d306b6 Move/coalesce RcIncludes enum to std.zig.RcIncludes 2025-11-07 19:16:52 -08:00
Ryan Liptak
f587209e04 Move/coalesce CompressDebugSections enum to std.zig.CompressDebugSections 2025-11-07 19:15:55 -08:00
Ryan Liptak
74d2536715
Merge pull request #25158 from castholm/subsystem
Misc. Windows subsystem refactorings
2025-11-07 18:56:52 -08:00
Ryan Liptak
e0898f4e05 Step.Run: Fix for convertPathArg when cwd and path args are on different drives
Fixes #25805
2025-11-06 03:40:33 -08:00
Carl Åstholm
54f2a7c833 Move std.Target.SubSystem to std.zig.Subsystem
Also updates the field names to conform with the rest of std.
2025-11-05 01:31:26 +01:00
Jacob Young
5b060ef9d4
Merge pull request #25558 from jacobly0/elfv2-load-obj
Elf2: start implementing input object loading
2025-10-30 12:09:13 -04:00
Matthew Lugg
0dde70ef76
std.Build: fix '--webui' crash
Using '--webui' without '--time-report' when there are Run steps in the
graph was regressed by https://github.com/ziglang/zig/pull/25029.
2025-10-30 09:31:30 +00:00
Matthew Lugg
74931fe25c
std.debug.lockStderrWriter: also return ttyconf
`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-30 09:31:28 +00:00
John Benediktsson
74c23a237e
Merge pull request #25763 from mrjbq7/cancelled
rename Cancelled to Canceled
2025-10-30 04:40:13 +00:00
Jacob Young
0834e696f7 Elf2: start implementing dynamic linking 2025-10-29 18:15:09 -04:00
Andrew Kelley
aadd8d4a3e std: back out the StackTrace byval changes
Let's keep passing this thing by pointer
2025-10-29 06:20:50 -07:00
Andrew Kelley
10b1eef2d3 std: fix compilation errors on Windows 2025-10-29 06:20:50 -07:00
Andrew Kelley
2d7d98da0c std.fs: use BadPathName rather than InvalidWtf8 on Windows 2025-10-29 06:20:50 -07:00
Andrew Kelley
43c2ba375d std: accessZ -> access 2025-10-29 06:20:50 -07:00
Andrew Kelley
8a1e6c8c39 std.Io: implement dirStatPath 2025-10-29 06:20:49 -07:00
Andrew Kelley
ebcc6f166c std.Io: bring back Timestamp but also keep Clock.Timestamp
this feels better
2025-10-29 06:20:49 -07:00
Andrew Kelley
47aa5a70a5 std: updating to std.Io interface
got the build runner compiling
2025-10-29 06:20:48 -07:00
Andrew Kelley
066864a0bf std.zig.system: upgrade to std.Io.Reader 2025-10-29 06:20:48 -07:00
Andrew Kelley
774df26835 WIP: hack at std.Io on a plane 2025-10-29 06:20:48 -07:00
Andrew Kelley
00f26cb0a4 WIP land the std.Io interface
fix std lib compilation errors caused by introducing std.Io
2025-10-29 06:20:48 -07:00
Matthew Lugg
50056a5b3a
compiler: rename --test-timeout-ms to --test-timeout
The unit can now be specified in the argument.
2025-10-18 09:28:43 +01:00
mlugg
a7251e4191
ci: bump unit test timeouts 2025-10-18 09:28:43 +01:00
mlugg
75adbf40ca
build runner: remove --prominent-compile-errors, introduce --error-style
The new `--error-style` option decides how build failures are printed.
The default mode "verbose" prints all context including the step graph
fragment and the failed command (if any). The alternative mode "minimal"
prints only the failed step itself, and does not print the failed
command. There are also "verbose_clear" and "minimal_clear" modes, which
have the distinction that the output is cleared (through ANSI escape
codes) between updates, preventing different updates from being confused
in the output. If `--error-style` is not specified, the environment
variable `ZIG_BUILD_ERROR_STYLE` is checked before falling back to the
default of "verbose"; this means the value can effectively be chosen
system-wide since it is generally a personal preference.

Also introduced is a `--multiline-errors` option which decides how to
print errors which span multiple lines. By default, non-initial lines
are indented to align with the first. Alternatively, a leading newline
can be printed to align everyting on the first column, or no special
treatment can be applied, resulting in misaligned output. Again, there
is an environment variable (`ZIG_BUILD_MULTILINE_ERRORS`) to specify a
preferred default if the option is not explicitly provided.

Resolves: #23472
2025-10-18 09:28:42 +01:00
mlugg
a388a8e5a7
std.Build: separate errors from failed commands
Recording the command in a separate field will give the build runner
more freedom to choose how and when the command should be printed.
2025-10-18 09:28:42 +01:00
mlugg
e4456d03f3
std.Build.Step.Run: many enhancements
This is a major refactor to `Step.Run` which adds new functionality,
primarily to the execution of Zig tests.

* All tests are run, even if a test crashes. This happens through the
  same mechanism as timeouts where the test processes is repeatedly
  respawned as needed.
* The build status output is more precise. For each unit test, it
  differentiates pass, skip, fail, crash, and timeout. Memory leaks are
  reported separately, as they do not indicate a test's "status", but
  are rather an additional property (a test with leaks may still pass!).
* The number of memory leaks is tracked and reported, both per-test and
  for a whole `Run` step.
* Reporting is made clearer when a step is failed solely due to error
  logs (`std.log.err`) where every unit test passed.
2025-10-18 09:28:41 +01:00
mlugg
7e7d7875b9
std.Build: implement unit test timeouts
For now, there is a flag to `zig build` called `--test-timeout-ms` which
accepts a value in milliseconds. If the execution time of any individual
unit test exceeds that number of milliseconds, the test is terminated
and marked as timed out.

In the future, we may want to increase the granularity of this feature
by allowing timeouts to be specified per-step or even per-test. However,
a global option is actually very useful. In particular, it can be used
in CI scripts to ensure that no individual unit test exceeds some
reasonable limit (e.g. 60 seconds) without having to assign limits to
every individual test step in the build script.

Also, individual unit test durations are now shown in the time report
web interface -- this was fairly trivial to add since we're timing tests
(to check for timeouts) anyway.

This commit makes progress on #19821, but does not close it, because
that proposal includes a more sophisticated mechanism for setting
timeouts.

Co-Authored-By: David Rubin <david@vortan.dev>
2025-10-18 09:28:39 +01:00
kcbanner
8b6cdc3d82 - Rework common translate-c and cImport logic into Compilation.translateC
- Add std.zig.Server.allocErrorBundle, replace duplicates
2025-10-09 01:06:09 -04:00
mlugg
202aeacc05
std: fixes 2025-09-30 13:44:51 +01:00
mlugg
c2ada49354
replace usages of old std.debug APIs
src/crash_handler.zig is still TODO though, i am planning bigger changes there
2025-09-30 13:44:51 +01:00
mlugg
89d862180f
yet more 2025-09-30 13:44:49 +01:00
Andrew Kelley
e0dc2e4e3f
Merge pull request #25342 from ziglang/fuzz-limit
fuzzing: implement limited fuzzing
2025-09-26 05:28:46 -07:00
Andrew Kelley
52a13f6a7f web ui: fix not sending initial context sometimes
This would cause the web ui to crash in js or wasm.
2025-09-25 17:16:41 -07:00
Loris Cro
9bb0b43ea3 implement review suggestions 2025-09-25 18:20:19 +02:00