Compare commits

...

3111 Commits

Author SHA1 Message Date
Andrew Kelley
738d2be9d6 README: migrated to codeberg 2025-11-26 17:42:52 -08:00
Alex Rønne Petersen
51bb2b3d2d
remove zig-cache from .gitignore
It's been a while since this was renamed to .zig-cache.
2025-11-26 23:36:11 +01:00
Alex Rønne Petersen
9b752cb989
adjust issue templates for Codeberg 2025-11-26 23:36:11 +01:00
Alex Rønne Petersen
4d58fafaf2
ci: remove GitHub Actions 2025-11-26 23:36:11 +01:00
Alex Rønne Petersen
43b4368b94
ci: bump riscv64-linux-debug timeout by 1 hour
A very recent change seems to have made this slower.
2025-11-26 19:29:36 +01:00
Alex Rønne Petersen
c969ef7cbe
ci: make the workflow file a bit more readable 2025-11-26 19:29:06 +01:00
Andrew Kelley
fc8a51ece3 README: enhance plain text readability
this file is first and foremost plain text, and rendered markdown
second.
2025-11-26 09:55:00 -08:00
Alex Rønne Petersen
2e328beaa5
Merge pull request #26005 from jedisct1/kt128r
Add std.crypto.hash.sha3.{KT128,KT256} - RFC 9861. (#25593)
2025-11-26 17:24:13 +01:00
Jay Petacat
b6e1a100b8 std.Progress: Terminate progress escape codes with ST not BEL
`ST` is the "string terminator" and what is actually prescribed in the
standard for escape codes. Use of `BEL` as a terminator is apparently a
historical oddity that persists for compatibility. Unfortunately, not
all terminals support using `BEL`, including Ubuntu's new default
terminal, Ptyxis. Using `ST` should make it work in more terminals.

Further reading:

- https://en.wikipedia.org/wiki/ANSI_escape_code#Operating_System_Command_sequences
- https://ecma-international.org/wp-content/uploads/ECMA-48_5th_edition_june_1991.pdf
2025-11-26 14:16:08 +01:00
Giuseppe Cesarano
0b5b35c696 std.elf implemented DynamicSectionBufferIterator 2025-11-26 11:30:03 +01:00
Frank Denis
5f73c01368
crypto.blake3: sequentially process larger small tree layers (#26046)
Improves performance by spawning less threads.
2025-11-26 10:16:20 +01:00
Frank Denis
846082fdf2 std.crypto.kt128: add support for threads
Allow KT128 and KT256 to use multiple threads to quickly process
very large inputs.
2025-11-26 10:08:09 +01:00
Frank Denis
9ede8ee135 Add std.crypto.hash.sha3.{KT128,KT256} - RFC 9861. (#25593)
KangarooTwelve is a family of two fast and secure extendable-output
functions (XOFs): KT128 and KT256. These functions generalize
traditional hash functions by allowing arbitrary output lengths.

KangarooTwelve was designed by SHA-3 authors. It aims to deliver
higher performance than the SHA-3 and SHAKE functions defined in
FIPS 202, while preserving their flexibility and core security
principles.

On high-end platforms, it can take advantage of parallelism,
whether through multiple CPU cores or SIMD instructions.

As modern SHA-3 constructions, KT128 and KT256 can serve as
general-purpose hash functions and can be used, for example, in
key-derivation, and with arbitrarily large inputs.

RFC9861: https://datatracker.ietf.org/doc/rfc9861/
2025-11-26 10:08:09 +01:00
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
Mateusz Poliwczak
f3270ceca4 std.zig.AstGen: rename token_bytes parameter to ident_name_raw
This method is called on an identifier token, so let's rename the parameter to make this clear.
This is also how it's named on most of the caller's sides.
2025-11-26 09:49:50 +01:00
Eamon Burns
5cb72fce91 docs: fix up some README links
- https://github.com/ziglang/zig-bootstrap -> https://codeberg.org/ziglang/zig-bootstrap
- https://github.com/ziglang/qemu-static -> https://codeberg.org/ziglang/qemu-static
- Add <...> around bare URLs
- Link to tips inside README.md, rather than in CONTRIBUTING.md
2025-11-26 09:36:58 +01:00
Jacob Young
6ef3af4c1c
ci: remove hardcoded paths in aarch64-macos scripts 2025-11-25 22:24:19 +01:00
Alex Rønne Petersen
f50b0d7136
ci: add aarch64-macos to Forgejo Actions 2025-11-25 22:21:25 +01:00
Andrew Kelley
0f1a6ae943 fetch: update from std.Thread.Pool to std.Io 2025-11-25 09:40:27 -08:00
Mateusz Poliwczak
d0ba6642b5 std.Zig.AstGen: handle properly .inferred_ptr and .destructure in enum_literal handling
rl.resultType() returns null for inferred_ptr and destructure, so move
that to the unreachable block.
2025-11-25 05:58:30 -08:00
Nir Lahad
14ba3bd9a1
std.testing: Fix expectEqualDeep formatted enum (#25960) 2025-11-25 05:39:07 -08:00
Zihad
e4be00f949 std.Io.Threaded: fix QueryPerformanceCounter usage
Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2025-11-25 03:46:24 -08: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
84353183c7 build runner: fix recursive locking of max_rss_mutex 2025-11-24 14:34:18 -08:00
Andrew Kelley
ece62a0223 frontend: introduce error.Canceled 2025-11-24 14:34:18 -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
Andrew Kelley
32dc46aae5 std.Io: add Group.concurrent
A function that participates in a group but guarantees allocation of one
unit of concurrency, or returns an error.
2025-11-24 14:33:16 -08:00
Giuseppe Cesarano
476d7d939c std.Io.File.readPositional fixed buffer type 2025-11-24 21:32:18 +01:00
Frank Denis
3c647ca6bb
crypto.ml_kem: avoid redundant assignment & fix K-PKE.KeyGen (#26031)
FIPS-203 algorithm 13 for deterministic key generation uses
(𝜌, 𝜎) ← G(𝑑 ‖ 𝑘) , not (𝜌, 𝜎) ← G(k ‖ d)
2025-11-24 18:45:48 +00:00
Ryan Liptak
289f2f0d34
Merge pull request #17541 from moosichu/fix/wine-get-final-path-name-by-handle
Windows: Deal with NT namespaced paths in GetFinalPathNameByHandle
2025-11-24 07:17:30 -08:00
Andrew Kelley
66fe584ead README: update some links 2025-11-24 06:39:28 -08:00
Ryan Liptak
ccc5e581a8
Merge pull request #26030 from squeek502/windows-cleanup
Cleanup some Windows stuff, delete unused functions and kernel32 bindings
2025-11-24 06:14:21 -08:00
Ryan Liptak
bf25816067 Move Windows rename implementation from std.posix to windows.RenameFile
This also unifies the rename implementations, since previously `posix.renameW` used `MoveFileEx` while `posix.renameatW` used `NtOpenFile`/`NtSetInformationFile`. This, in turn, allows the `MoveFileEx` bindings to be deleted as `posix.renameW` was the only usage.
2025-11-23 23:38:01 -08:00
Ryan Liptak
17ecc77fc4 os.windows: Delete unused functions and kernel32 bindings 2025-11-23 23:38:01 -08:00
Alex Rønne Petersen
b31173179b
ci: bump riscv64-linux-release timeout to 8 hours on Forgejo Actions 2025-11-24 06:29:53 +01:00
Ryan Liptak
d48faf1a32 windows.GetFinalPathNameByHandle: add links to bugs tracking the Wine workaround 2025-11-23 19:10:23 -08:00
fkobi
9082b004b6 README: use HTTPS for releases.llvm.org 2025-11-23 20:54:20 +01:00
meowjesty
755a3d957c
langref: convert to unmanaged ArrayList in example 2025-11-23 18:32:05 +00:00
Justus Klausecker
e5c2df9f17 std.math.big.int: fix format functions 2025-11-23 09:52:43 -08:00
Alex Rønne Petersen
16fc083f2b
std.Target: remove Abi.code16
This functionality -- if it's actually needed -- can be reintroduced through
some other mechanism. An ABI is clearly not the right way to represent it.

closes #25918
2025-11-23 10:22:03 +01:00
Matthew Lugg
6d543bcf94
Merge pull request #23733 from alichraghi/bp
replace @Type with individual type-creating builtins
2025-11-23 07:50:29 +00:00
Alex Rønne Petersen
0a9f666ea6
cbe: translate sparc ccr/icc/xcc registers to icc
C compilers do not distinguish between these.
2025-11-23 07:27:50 +01:00
Alex Rønne Petersen
1231aa9719
Revert "std.os.linux.sparc64: use icc instead of xcc in asm clobbers"
This reverts commit b34a13da38f60737477e62dd0acd1a7a6b6be0a0.

This is not the right fix; rather, the C backend needs to translate all of ccr,
icc, and xcc to just icc.
2025-11-23 07:27:45 +01:00
Kendall Condon
8284da2f3d flate.Compress: simplify huffman node comparisons
Instead of comparing each field, nodes are now compared as 32-bit
values where `freq` is in the most significant bits.
2025-11-22 22:11:33 -08:00
Alex Rønne Petersen
d6931b0ff5
test: disable coff_dwarf on FreeBSD
https://github.com/ziglang/zig/issues/25471

This is not the only test that aborts like this, nor does it happen only on
FreeBSD, but it happens to be disproportionally disruptive on FreeBSD in
particular.
2025-11-23 07:10:35 +01:00
Frank Denis
0e3b5e6d8f blake3: remove unnecessary comptime, digest_length instead of key_length 2025-11-22 22:09:51 -08:00
Andrew Kelley
9473011052 README: add some content from the wiki
also update the issue templates
2025-11-22 16:01:02 -08:00
Ali Cheraghi
dec1163fbb
all: replace all @Type usages
Co-authored-by: Matthew Lugg <mlugg@mlugg.co.uk>
2025-11-22 22:42:38 +00:00
Matthew Lugg
ce0df033cf
stage1: update zig1.wasm
Signed-off-by: Matthew Lugg <mlugg@mlugg.co.uk>
2025-11-22 22:42:37 +00:00
Matthew Lugg
c5383173a0
compiler: replace @Type with individual type-creating builtins
The new builtins are:
* `@EnumLiteral`
* `@Int`
* `@Fn`
* `@Pointer`
* `@Tuple`
* `@Enum`
* `@Union`
* `@Struct`

Their usage is documented in the language reference.

There is no `@Array` because arrays can be created like this:

    if (sentinel) |s| [n:s]T else [n]T

There is also no `@Float`. Instead, `std.meta.Float` can serve this use
case if necessary.

There is no `@ErrorSet` and intentionally no way to achieve this.
Likewise, there is intentionally no way to reify tuples with comptime
fields, or function types with comptime parameters. These decisions
simplify the Zig language specification, and moreover make Zig code more
readable by discouraging overly complex metaprogramming.

Co-authored-by: Ali Cheraghi <alichraghi@proton.me>
Resolves: #10710
2025-11-22 22:42:37 +00:00
Andrew Kelley
3f2cf1c002 CI: skip test-incremental on Windows
Tracked by #22510
2025-11-22 08:09:25 -08:00
Andrew Kelley
c9a788c851 Revert "disable flaky test/incremental/add_decl"
This reverts commit d54fbc01234688b37a48b29fee499529a500ccf5.

Since all incremental tests are flaky on Windows, this is reinstated and
all test-incremental tests will be skipped on Windows until the
flakiness is resolved.

Closes #26003
2025-11-22 08:09:12 -08:00
Alex Rønne Petersen
48b0eef3e9
mark resinator and translate-c as vendored in .gitattributes 2025-11-22 13:45:20 +01:00
Ryan Liptak
21f9f378f1 Reader.defaultDiscard: Fix for use with an indirect reader
If a Reader implementation implements `stream` by ignoring the Writer, writing directly to its internal buffer, and returning 0, then `defaultDiscard` would not update `seek` and also return 0, which is incorrect and can cause `discardShort` to violate the contract of `VTable.discard` by calling into `vtable.discard` with a non-empty buffer.

This commit fixes the problem by advancing seek up to the limit after the stream call. This logic could likely be somewhat simplified in the future depending on how #25170 is resolved.
2025-11-21 22:34:55 -08:00
Ryan Liptak
822f412424 fs.path: Fix on big-endian architectures, make PathType.isSep assume WTF-16 is LE
This commit flips usage of PathType.isSep from requiring the caller to convert to native to assuming the input is LE encoded, which is a breaking change. This makes usage a bit nicer, though, and moves the endian conversion work from runtime to comptime.
2025-11-21 22:26:58 -08:00
Andrew Kelley
2ea55d7153
Merge pull request #25998 from ziglang/std.Io.Threaded-async-guarantee
std.Io: guarantee when async() returns, task is already completed or has been successfully assigned a unit of concurrency
2025-11-21 20:56:29 -08:00
Andrew Kelley
d828115dab
Merge pull request #25903 from aznashwan/minor-docs-fixes
docs: minor fixes to main language reference page.
2025-11-21 19:56:15 -08:00
Andrew Kelley
7096e66ca9 std.Thread: update doc comments 2025-11-21 19:54:41 -08:00
Andrew Kelley
eb038ffbc1 std.Io.Threaded: forward cancellation requests to awaited tasks 2025-11-21 19:54:41 -08:00
Andrew Kelley
b052afd24b std.Io.Threaded: import std.mem.Alignment 2025-11-21 19:54:41 -08:00
Andrew Kelley
cf744aa182 std.Io.Threaded: slightly different semantics
while still preserving the guarantee about async() being assigned a unit
of concurrency (or immediately running the task), this change:
* retains the error from calling getCpuCount()
* spawns all threads in detached mode, using WaitGroup to join them
* treats all workers the same regardless of whether they are processing
  concurrent or async tasks. one thread pool does all the work, while
  respecting async and concurrent limits.
2025-11-21 19:54:41 -08:00
Andrew Kelley
13b537d77c std.Io.Threaded: remove dead code 2025-11-21 19:54:41 -08:00
Andrew Kelley
aae85a4130 std.Io.Threaded: allow calling init in single-threaded mode 2025-11-21 19:54:41 -08:00
Andrew Kelley
b4ec78906c std.Io: update async documentation to reflect the guarantee 2025-11-21 19:54:41 -08:00
Loris Cro
69f9395b38 fix logic bug in groupAsync 2025-11-21 19:54:41 -08:00
Loris Cro
ff883dd6ce fix single-threaded builds 2025-11-21 19:54:41 -08:00
Loris Cro
8eaebf5939 Io.Threaded PoC reimplementation
This is a reimplementation of Io.Threaded that fixes the issues
highlighted in the recent Zulip discussion. It's poorly tested but it
does successfully run to completion the litmust test example that I
offered in the discussion.

This implementation has the following key design decisions:

- `t.cpu_count` is used as the threadpool size.
- `t.concurrency_limit` is used as the maximum number of
  "burst, one-shot" threads that can be spawned by `io.concurrent` past
  `t.cpu_count`.
- `t.available_thread_count` is the number of threads in the pool that
  is not currently busy with work (the bookkeeping happens in the worker
  function).
- `t.one_shot_thread_count` is the number of active threads that were
  spawned by `io.concurrent` past `t.cpu_count`.

In this implementation:

- `io.async` first tries to decrement `t.available_thread_count`. If
  there are no threads available, it tries to spawn a new one if possible,
  otherwise it runs the task immediately.
- `io.concurrent` first tries to use a thread in the pool same as
  `io.async`, but on failure (no available threads and pool size limit
  reached) it tries to spawn a new one-shot thread. One shot threads
  run a different main function that just executes one task, decrements
  the number of active one shot threads, and then exits.

A relevant future improvement is to have one-shot threads stay on for a
few seconds (and potentially pick up a new task) to amortize spawning
costs.
2025-11-21 19:54:41 -08:00
Andrew Kelley
d54fbc0123 disable flaky test/incremental/add_decl
tracked by https://github.com/ziglang/zig/issues/26003
2025-11-21 19:53:33 -08:00
Andrew Kelley
bb3b5d09cc Revert std.crypto kangarootwelve addition
I would like a chance to review this before it lands, please. Feel free
to submit the work again without changes and I will make review
comments.

In the meantime, these reverts avoid intermittent CI failures, and
remove bad patterns from occurring in the standard library that other
users might copy.

Revert "std.crypto: improve KT documentation, use key_length for B3 key length (#25807)"

This reverts commit 4b593a6c24797484e68a668818736b0f6a8d81a2.

Revert "crypto - threaded K12: separate context computation from thread spawning (#25793)"

This reverts commit ee4df4ad3edad160fb737a1935cd86bc2f9cfbbe.

Revert "crypto.kt128: when using incremental hashing, use SIMD when possible (#25783)"

This reverts commit bf9082518c32ce7d53d011777bf8d8056472cbf9.

Revert "Add std.crypto.hash.sha3.{KT128,KT256} - RFC 9861. (#25593)"

This reverts commit 95c76b1b4aa7302966281c6b9b7f6cadea3cf7a6.
2025-11-21 19:43:01 -08:00
Alex Rønne Petersen
a892e09435
Revert "ci: allow riscv64-linux on Forgejo Actions to run on PRs for now"
This reverts commit 2cdafe91065c5d477563361a8fe1f637898ca285.
2025-11-22 03:08:49 +01:00
Nashwan Azhari
af7dec94c6
docs: use custom error set in values.zig sample.
Signed-off-by: Nashwan Azhari <aznashwan@icloud.com>
2025-11-22 02:56:40 +02:00
Nashwan Azhari
153521279f
docs: remove normal-doc comment interleaving bug note.
Signed-off-by: Nashwan Azhari <aznashwan@icloud.com>
2025-11-22 02:51:16 +02:00
Alex Rønne Petersen
d3e20e71be
std.zig.system.linux: implement s390x native CPU detection 2025-11-21 12:15:15 +01:00
Alex Rønne Petersen
1cd913a0ec
std.zig.system: disable vector support on s390x for now
https://github.com/llvm/llvm-project/issues/168992
2025-11-21 12:15:15 +01:00
Alex Rønne Petersen
7e54ee06d8
test: disable big simd vector C ABI test on s390x 2025-11-21 12:15:15 +01:00
Alex Rønne Petersen
3333bcc4f2
std.crypto.ml_kem: disable some tests on s390x with vector support 2025-11-21 12:15:15 +01:00
Alex Rønne Petersen
47df2f9abe
std.zig.system.linux: don't arbitrarily limit sparc CPU detection to 64-bit 2025-11-21 12:15:15 +01:00
Tom Read Cutting
689032d571 Deal with NT paths in GetFinalPathNameByHandle
When calling QueryObjectName, NT namespaced paths can be returned. This
change appropriately strips the prefix to turn it into an absolute path.

(The above behaviour was observed at least in Wine so far)

Co-authored-by: Ryan Liptak <squeek502@hotmail.com>
2025-11-21 01:52:50 -08:00
Alex Rønne Petersen
534370c4de
ci: bump loongarch64-linux-debug timeout to 4 hours on Forgejo Actions 2025-11-21 09:44:22 +01: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
Alex Rønne Petersen
f3eef35c05
aro: unbreak s390x
https://github.com/ziglang/zig/pull/25780#discussion_r2548496117
2025-11-21 06:28:19 +01:00
rpkak
6b4f45f782 system specific errno 2025-11-20 15:03:23 -08:00
Benjamin Jurk
4b5351bc0d
update deprecated ArrayListUnmanaged usage (#25958) 2025-11-20 14:46:23 -08:00
Andrew Kelley
db622f14c4
Merge pull request #25780 from Vexu/translate-c
Update Aro and translate-c to latest
2025-11-20 10:24:31 -08:00
Matthew Lugg
8a73fc8d8e
Merge pull request #25981 from mlugg/macos-fuzz-2
make the fuzzer vaguely work on macOS
2025-11-20 17:48:35 +00:00
Andrew Kelley
a9568ed296
Merge pull request #25898 from jacobly0/elfv2-progress
Elf2: more progress
2025-11-20 04:33:04 -08:00
Veikka Tuominen
df50f9e28e update resinator to Aro changes 2025-11-20 13:12:53 +02:00
Veikka Tuominen
21f3ff2a8d update Aro and translate-c to latest 2025-11-20 13:12:53 +02:00
Matthew Lugg
a87b533231
std.Io.Writer: fix some bugs 2025-11-20 10:42:21 +00:00
Matthew Lugg
b05fefb9c9
std.http: stop assuming previous chunk state
The full file may not be written, either due to a previous chunk being
in-progress when `sendFile` was called, or due to `limit`.
2025-11-20 10:42:21 +00:00
Matthew Lugg
bc524a2b1a
std.Build: fix crashes running fuzz tests 2025-11-20 10:42:21 +00:00
Matthew Lugg
0f06b5b583
std.debug.MachOFile: handle 'path/to/archive.a(entry.o)' form 2025-11-20 10:42:21 +00:00
Matthew Lugg
e1fa4011fb
fuzz: hack around unknown module structure 2025-11-20 10:42:20 +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
Jacob Young
7b325e08c9 Elf2: revert incorrect endian fix 2025-11-19 22:19:57 -05:00
Alex Rønne Petersen
f06adc70b0
ci: bump timeout for s390x-linux-debug to 5 hours on Forgejo Actions 2025-11-20 03:34:42 +01:00
Alex Rønne Petersen
c9afa901f3
ci: bump timeout for s390x-linux-release to 4 hours on Forgejo Actions 2025-11-19 23:47:58 +01:00
Alex Rønne Petersen
5078acf3a3
std.Io.net: disable listen on a unix socket, send bytes, receive bytes on Windows
https://github.com/ziglang/zig/issues/25983
2025-11-19 21:51:57 +01:00
Alex Rønne Petersen
4ed5bb0bac
ci: bump aarch64-linux-debug timeout to 3 hours on Forgejo Actions 2025-11-19 20:45:36 +01:00
Harold
2f240d0819 std.Build.Step.Compile: add support for '-z defs' flag 2025-11-19 20:13:54 +01:00
Jan200101
bd832ed39a std.Io.Threaded: add missing statx masks
statx does not guarantee that the values requested by the mask be
present and those not requested be absent which is why this worked.
2025-11-19 20:13:25 +01:00
Alex Rønne Petersen
43371cf388
Merge pull request #25965 from alexrp/s390x
`s390x-linux` and general big-endian stuff
2025-11-19 19:52:18 +01:00
Ryan Liptak
26afcdb7fe std.process: Actually use explicit GetCwdError/GetCwdAllocError sets
Also fix GetCwdAllocError to include only the set of possible errors.
2025-11-19 04:10:11 -08:00
Matthew Lugg
806470b492
compiler: fix crash if file contents change during update
When reporting a compile error, we would load the new file, but assume
we could apply old AST/token indices (etc) to it, potentially causing
crashes. Instead, if the file stat has changed since it was loaded, just
emit an error that the file was modified mid-update.
2025-11-19 09:44:22 +00:00
Alex Rønne Petersen
abd05b3819
ci: enable s390x-linux jobs on Forgejo Actions 2025-11-19 09:41:58 +01:00
Alex Rønne Petersen
830831dcba
ci: add s390x-linux scripts 2025-11-19 09:41:55 +01:00
Ryan Liptak
fb1bd78908 process.getenvW: Document that returned memory points to the PEB 2025-11-18 20:07:39 -08:00
Alex Rønne Petersen
e11901c1a1
test: enable C ABI tests on s390x-linux 2025-11-19 01:42:45 +01:00
Alex Rønne Petersen
692c798303
test: disable a bunch of failing C ABI tests on s390x 2025-11-19 01:42:45 +01:00
Alex Rønne Petersen
ae0cc8c065
test: disable C ABI tests using i128 on s390x due to an LLVM crash
https://github.com/llvm/llvm-project/issues/168460
2025-11-19 01:42:45 +01:00
Alex Rønne Petersen
a8e77b7a05
test: disable test-link on big-endian hosts
https://github.com/ziglang/zig/issues/25961
2025-11-19 01:42:45 +01:00
Alex Rønne Petersen
a0e6d41331
test: remove complex arithmetic testing from c_compiler standalone test
This has no business being here. Tests for our compiler-rt routines should be in
compiler-rt, and tests for our C ABI compliance should be in `test-c-abi`.
2025-11-19 01:42:45 +01:00
Alex Rønne Petersen
41f7f3d4d5
test: disable an error trace test on optimized s390x-linux 2025-11-19 01:42:45 +01:00
Alex Rønne Petersen
0d104a645a
test: fix glibc_compat test for s390x which does not have local atexit 2025-11-19 01:42:45 +01:00
Alex Rønne Petersen
508f676bb4
std.os.linux.IoUring: disable bind/listen/connect on s390x
https://github.com/ziglang/zig/issues/25956
2025-11-19 01:42:45 +01:00
Alex Rønne Petersen
e179335bee
std.zon.parse: disable zon vector on s390x
https://github.com/ziglang/zig/issues/25957
2025-11-19 01:42:45 +01:00
Alex Rønne Petersen
c82884542f
langref: work around s390x LLVM compilation crash in test_defining_variadic_function
https://github.com/ziglang/zig/issues/21350#issuecomment-3543006475
2025-11-19 01:42:45 +01:00
Alex Rønne Petersen
4dd05b5a64
langref: work around s390x LLVM miscompilation in runtime_shrExact_overflow
https://github.com/ziglang/zig/issues/24304
2025-11-19 01:42:45 +01:00
Alex Rønne Petersen
04853f4052
std-docs: read/write messages as little endian 2025-11-19 01:42:45 +01:00
Alex Rønne Petersen
8817fc8958
incr-check: read/write messages as little endian 2025-11-19 01:42:45 +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
cd7d8dff26
std.zig.Server: read error bundle as little-endian
Again, `std.zig.Server` expects little-endian. This is easy; we just use
a `Reader.fixed` instead of directly `@ptrCast`ing data out of the
buffer.
2025-11-19 01:42:45 +01:00
Alex Rønne Petersen
989e05d93b
stage1: update zig1.wasm
Signed-off-by: Alex Rønne Petersen <alex@alexrp.com>
2025-11-19 01:42:45 +01:00
Alex Rønne Petersen
4b99e3718b
compiler: don't use self-hosted backends on big-endian hosts
https://github.com/ziglang/zig/issues/25961
2025-11-19 01:42:45 +01:00
Alex Rønne Petersen
959a3612c2
aro: define arch macros for s390x 2025-11-19 01:42:45 +01:00
Matthew Lugg
a319211eee
llvm: fix lowering of packed struct constants
The big-endian logic here was simply incorrect. Luckily, it was also
overcomplicated; after calling `Value.writeToPackedMemory`, there is a
method on `std.math.big.int.Mutable` which just does the correct
endianness load for us.
2025-11-19 01:42:37 +01:00
Frank Denis
4ea4728084
Align ML-KEM code with ML-DSA (#25964)
This will facilitate maintainance and code sharing between primitives.
2025-11-18 15:39:58 +00:00
Matthew Lugg
891f187032
cbe: fix big-endian unnatural integer bitcast
Integers with padding bits on big-endian targets cannot quite be bitcast
with a trivial memcpy, because the padding bits (which are zext or sext)
are the most-significant, so are at the *lowest* addresses. So to
bitcast to something which doesn't have padding bits, we need to offset
past the padding.

The logic I've added here definitely doesn't handle all possibilities
correctly; I think that would actually be quite complicated. However, it
handles a common case, and so prevents the Zig compiler itself from
being miscompiled on big-endian targets (hence fixing a bootstrapping
problem on big-endian).
2025-11-18 11:10:52 +01:00
Lukas Lalinsky
73f863a6fb Fix AI/NI flag definitions for BSD systems
Add missing AI flags for NetBSD and OpenBSD:
- NetBSD: Add AI.SRV flag at bit 11 (0x00000800)
- OpenBSD: Add AI.EXT flag at bit 3 and AI.FQDN flag at bit 5

Add missing NI (getnameinfo) flag definitions for all BSDs and Darwin:
- FreeBSD/Haiku: NOFQDN, NUMERICHOST, NAMEREQD, NUMERICSERV, DGRAM, NUMERICSCOPE
- DragonFly/NetBSD: Same flags with NUMERICSCOPE at bit 6 (deprecated WITHSCOPEID at bit 5 is skipped)
- OpenBSD: NUMERICHOST, NUMERICSERV, NOFQDN, NAMEREQD, DGRAM (no NUMERICSCOPE)
- macOS/Darwin: NOFQDN, NUMERICHOST, NAMEREQD, NUMERICSERV, DGRAM, NUMERICSCOPE at bit 8 (deprecated WITHSCOPEID at bit 5 is skipped)

References:
- NetBSD: https://github.com/NetBSD/src/blob/trunk/include/netdb.h
- OpenBSD: https://github.com/openbsd/src/blob/master/include/netdb.h
- FreeBSD: https://github.com/freebsd/freebsd-src/blob/master/include/netdb.h
- DragonFly BSD: https://github.com/DragonFlyBSD/DragonFlyBSD/blob/master/include/netdb.h
- Haiku: https://github.com/haiku/haiku/blob/master/headers/posix/netdb.h
- macOS/Darwin: https://github.com/apple-oss-distributions/Libinfo/blob/main/lookup.subproj/netdb.h
2025-11-17 19:01:39 +01:00
Tobias Simetsreiter
f0a3df98d3 replace @panic with b.addFail in standalone test build.zig 2025-11-17 17:02:53 +01:00
xdBronch
d2b1aa48ab sema: fix UAF in type mismatch error 2025-11-17 10:37:22 +02:00
xdBronch
29a1d0c06f sema: improve codegen of for loop safety checks 2025-11-16 22:59:51 +00:00
Alex Rønne Petersen
35d87c4406
Merge pull request #25929 from alexrp/maccatalyst
`std.zig.target`: support `aarch64-maccatalyst` and `x86_64-maccatalyst` cross libc
2025-11-16 23:16:33 +01:00
Prokop Randáček
94e98bfe80
Dedupe types when printing error messages 2025-11-16 16:20:45 +02:00
Ryan Liptak
adf74ba4fb windows.eqlIgnoreCaseWTF16 -> eqlIgnoreCaseWtf16
Consistent with naming of other, similar functions
2025-11-16 04:03:52 -08:00
Ryan Liptak
aa4332fb0e
Merge pull request #25539 from squeek502/windows-readlinkw
windows: Make readLinkW APIs output WTF-16, reduce stack usage of callers
2025-11-15 23:36:34 -08:00
xdBronch
f6fecfdc00 improve assembly error test coverage 2025-11-16 06:30:51 +00:00
Meghan Denny
d07360f999 std.c: implement rusage for freebsd
Reference: e0c41af925/sys/sys/resource.h (L70)
2025-11-16 06:15:54 +01:00
Ryan Liptak
6aa3570cb0 windows: Make readLinkW APIs output WTF-16, reduce stack usage of callers
- Affects the following functions:
  + `std.fs.Dir.readLinkW`
  + `std.os.windows.ReadLink`
  + `std.os.windows.ntToWin32Namespace`
  + `std.posix.readlinkW`
  + `std.posix.readlinkatW`

Each of these functions (except `ntToWin32Namespace`) took WTF-16 as input and would output WTF-8, which makes optimal buffer re-use difficult at callsites and could force unnecessary WTF-16 <-> WTF-8 conversion during an intermediate step.

The functions have been updated to output WTF-16, and also allow for the path and the output to re-use the same buffer (i.e. in-place modification), which can reduce the stack usage at callsites. For example, all of `std.fs.Dir.readLink`/`readLinkZ`/`std.posix.readlink`/`readlinkZ`/`readlinkat`/`readlinkatZ` have had their stack usage reduced by one PathSpace struct (64 KiB) when targeting Windows.

The new `ntToWin32Namespace` takes an output buffer and returns a slice from that instead of returning a PathSpace, which is necessary to make the above possible.
2025-11-15 18:16:03 -08:00
Ryan Liptak
06a7597ea8 windows.ReadLink: Use OpenFile now that .filter = .any exists
The reasoning in the comment deleted by this commit no longer applies, since that same benefit can be obtained by using OpenFile with `.filter = .any`.

Also removes a stray debug.print
2025-11-15 18:07:25 -08:00
Andrew Kelley
6ecf497714
Merge pull request #25936 from Traxar/master
Add some missing features to `std.Io.Timestamp` and `spirv/CodeGen.zig`
2025-11-15 17:14:12 -08:00
Alex Rønne Petersen
83d9a5968f
std.Thread: disable thread local storage test on 32-bit targets
https://github.com/ziglang/zig/issues/25498
2025-11-16 00:08:20 +01:00
Matthew Lugg
bc589c271a
Merge pull request #25924 from mlugg/legalize-soft-float
Legalize: implement soft-float legalizations
2025-11-15 16:18:40 +00:00
Alex Rønne Petersen
96dfffb7f5
test: enable module tests for maccatalyst targets 2025-11-15 14:23:36 +01:00
Alex Rønne Petersen
bbdf8eaf75
build: change -Dskip-macos to -Dskip-darwin and make it cover all darwin OSs 2025-11-15 14:23:34 +01:00
Sam Bossley
1ebbdf8eef fix: add specific error set for SelectiveWalker iterator function 2025-11-15 05:00:14 -08:00
Matthew Lugg
cd8fdd252d
build.zig: use Step.UpdateSourceFiles for zig1.wasm
We were already using this for `stage1/zig.h`, but `stage1/zig1.wasm`
was being modified directly by the `wasm-opt` command. That's a bad idea
because it forces the build system to assume that `wasm-opt` has side
effects, so it is re-run every time you run `zig build update-zig1`,
i.e. it does not interact with the cache system correctly. It is much
better to create non-side-effecting `Run` steps (using `addOutput*Arg`)
where possible so that the build system has a more correct understanding
of the step graph.
2025-11-15 09:49:02 +00:00
Matthew Lugg
bc78d8efdb
Legalize: implement soft-float legalizations
A new `Legalize.Feature` tag is introduced for each float bit width
(16/32/64/80/128). When e.g. `soft_f16` is enabled, all arithmetic and
comparison operations on `f16` are converted to calls to the appropriate
compiler_rt function using the new AIR tag `.legalize_compiler_rt_call`.
This includes casts where the source *or* target type is `f16`, or
integer<=>float conversions to or from `f16`. Occasionally, operations
are legalized to blocks because there is extra code required; for
instance, legalizing `@floatFromInt` where the integer type is larger
than 64 bits requires calling an arbitrary-width integer conversion
function which accepts a pointer to the integer, so we need to use
`alloc` to create such a pointer, and store the integer there (after
possibly zero-extending or sign-extending it).

No backend currently uses these new legalizations (and as such, no
backend currently needs to implement `.legalize_compiler_rt_call`).
However, for testing purposes, I tried modifying the self-hosted x86_64
backend to enable all of the soft-float features (and implement the AIR
instruction). This modified backend was able to pass all of the behavior
tests (except for one `@mod` test where the LLVM backend has a bug
resulting in incorrect compiler-rt behavior!), including the tests
specific to the self-hosted x86_64 backend.

`f16` and `f80` legalizations are likely of particular interest to
backend developers, because most architectures do not have instructions
to operate on these types. However, enabling *all* of these legalization
passes can be useful when developing a new backend to hit the ground
running and pass a good amount of tests more easily.
2025-11-15 09:49:01 +00:00
Matthew Lugg
9c45a87490
compiler_rt: fix and simplify additional Windows exports
Simplifies the logic, clarifies the comment, and fixes a minor bug,
which is that we exported the Windows ABI name *instead* of the standard
compiler-rt name, but it's meant to be exported *in addition* to the
standard name (this is LLVM's behavior and it is more useful).
2025-11-15 09:49:01 +00:00
Justus Klausecker
4187d0e8fe MemoryPool: add unmanaged variants and make them the default 2025-11-15 09:30:57 +00:00
traxar
868413007f src/codegen/spirv/CodeGen.zig: add missing unary Ops 2025-11-15 16:39:39 +09:00
traxar
19c9062840 std/Io.zig Timestamp: add toMilliseconds() 2025-11-15 16:38:33 +09:00
Alex Rønne Petersen
250803661c
Merge pull request #25927 from lalinsky/netbsd-madv
Fix madvice/msync flags for BSDs
2025-11-15 01:28:05 +01:00
Justus Klausecker
06d08dabab Sema: fix illegal multi level pointer coercions
Moves a premature check that allowed pointers to mutable pointers to coerce
to any other pointer to a mutable pointer.
2025-11-14 23:25:54 +00:00
Alex Rønne Petersen
3649aeb426
std.zig.target: support aarch64-maccatalyst and x86_64-maccatalyst cross libc 2025-11-14 22:14:50 +01:00
Alex Rønne Petersen
3633dd8d41
std.zig.target: libmx is a libSystem library for maccatalyst too 2025-11-14 22:14:50 +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
2125c94abe
link.MachO.Dylib: allow maccatalyst output to link macos libraries in TBDs
This is the logic that LLD uses. It is pretty silly, but it is what it is.
2025-11-14 19:19:00 +01:00
Alex Rønne Petersen
ca7523742f
libc: rename any-macos-any to any-darwin-any 2025-11-14 19:19:00 +01:00
Lukas Lalinsky
6bdea35ce5 Fix std.c.MSF.SYNC for freebsd, openbsd, dragonfly 2025-11-14 18:02:53 +01:00
Lukas Lalinsky
6fc5923a54 Define std.c.MADV for openbsd 2025-11-14 18:01:57 +01:00
Lukas Lalinsky
3a08d2f162 Define std.c.MADV for NetBSD
The `.netbsd` branch was completely missing. Validated against the
actual system headers.
2025-11-14 17:48:19 +01:00
Alex Rønne Petersen
b38fb4bff3
Merge pull request #25917 from alexrp/target-features
`std.Target`: add CPU features and models for alpha and hppa
2025-11-14 12:23:09 +01:00
Alex Rønne Petersen
94538d8dd2 std.pie: add missing clobbers on alpha and sparc
Also format all the assembly code in the file.
2025-11-14 12:19:38 +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
0x4a61636f62
2e6f7d36b9 std.Io.net: fix off-by-one in HostName.expand
`HostName.expand` was including the null terminator in the slice passed to `HostName.init`, which caused `HostName.validate` to fail.
2025-11-13 21:04:21 -08:00
Andrew Kelley
813e8614bc
Merge pull request #25817 from castholm/windows-fetch
Fix TLS, `io.async()` and package fetching on Windows
2025-11-13 19:20:13 -08:00
Alex Rønne Petersen
375d873e1e libcxx: use compiler's _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION when set
closes #25911
2025-11-14 02:02:59 +01:00
Alex Rønne Petersen
18a131f3da
ci: enable Forgejo Actions on master pushes 2025-11-13 23:04:40 +01:00
Alex Rønne Petersen
cca2da16bd
ci: only cancel previous PR runs on Forgejo Actions 2025-11-13 23:00:40 +01:00
Alex Rønne Petersen
65b0a2342b
std.Target.x86: refresh from update_cpu_features.zig
Just to get rid of this ordering diff.
2025-11-13 22:29:28 +01:00
Alex Rønne Petersen
39e91deb77
std.Target: add CPU features and models for hppa 2025-11-13 22:29:12 +01:00
Alex Rønne Petersen
2b23f98d2c
std.Target: add CPU features and models for alpha 2025-11-13 22:28:50 +01:00
xdBronch
071453d5b9 fix 'redundant comptime keyword' error source location and add tests 2025-11-13 19:47:36 +00:00
Matthew Lugg
181b25ce4f
Merge pull request #25772 from mlugg/kill-dead-code
compiler: rewrite some legalizations, and remove a bunch of dead code
2025-11-12 23:14:02 +00:00
Alex Rønne Petersen
dfd7b7f233 std.Target: remove Abi.cygnus
There is approximately zero chance of the Zig team ever spending any effort on
supporting Cygwin; the MSVC and MinGW-w64 ABIs are superior in every way that
matters, and not least because they lead to binaries that just run natively on
Windows without needing a POSIX emulation environment installed.
2025-11-12 22:39:04 +01:00
Matthew Lugg
92bc619c49 std.debug: allow fp unwind from context
It's easy to do FP unwinding from a CPU context: you just report the
captured ip/pc value first, and then unwind from the captured fp value.
All this really needed was a couple of new functions on the
`std.debug.cpu_context` implementations so that we don't need to rely on
`std.debug.Dwarf` to access the captured registers.

Resolves: #25576
2025-11-12 21:02:38 +00:00
So1aric
49e19fc94f
Sema: fix inline fn compiler crash (#25586)
Resolves: https://github.com/ziglang/zig/issues/25581
2025-11-12 19:21:28 +00:00
Alex Rønne Petersen
be2a902784
cmake: update ZIG_LLVM_REQUIRED_TARGETS to contain LoongArch and SPIRV 2025-11-12 20:16:58 +01:00
Matthew Lugg
532aa3c575
cbe: work around some miscompilations
The changes to `codegen.c` are blatant hacks, but the problem they work
around isn't a regression: it's an existing miscompilation. This branch
happened to *expose* that miscompilation in more cases by changing how
an incorrect result is *used*.
2025-11-12 16:00:16 +00:00
Matthew Lugg
5df5e2ed26
zig.h: drop dependency on deleted compiler_rt functions
It turns out we did use these in the C backend. However, it's really
just as easy, if not easier, to replicate the logic directly in C.

Synchronizes stage1/zig.h to make sure the bootstrap doesn't depend on
these functions either. The actual zig1 tarball is unmodified because
regenerating it is unnecessary in this instance.
2025-11-12 16:00:16 +00:00
Matthew Lugg
69f39868b4
Air.Legalize: revert to loops for scalarizations
I had tried unrolling the loops to avoid requiring the
`vector_store_elem` instruction, but it's arguably a problem to generate
O(N) code for an operation on `@Vector(N, T)`. In addition, that
lowering emitted a lot of `.aggregate_init` instructions, which is
itself a quite difficult operation to codegen.

This requires reintroducing runtime vector indexing internally. However,
I've put it in a couple of instructions which are intended only for use
by `Air.Legalize`, named `legalize_vec_elem_val` (like `array_elem_val`,
but for indexing a vector with a runtime-known index) and
`legalize_vec_store_elem` (like the old `vector_store_elem`
instruction). These are explicitly documented as *not* being emitted by
Sema, so need only be implemented by backends if they actually use an
`Air.Legalize.Feature` which emits them (otherwise they can be marked as
`unreachable`).
2025-11-12 16:00:16 +00:00
Matthew Lugg
99a7884308
behavior: disable test on cbe
This isn't so much a regression as it is foreshadowing of accepted
proposal https://github.com/ziglang/zig/issues/24657.
2025-11-12 16:00:16 +00:00
Matthew Lugg
6576c3b898
x86_64: spill eflags when initializing bool vector 2025-11-12 16:00:16 +00:00
Matthew Lugg
20bd5e8018
compiler-rt: remove dead code
`__addosi4`, `__addodi4`, `__addoti4`, `__subosi4`, `__subodi4`, and
`__suboti4` were all functions which we invented for no apparent reason.
Neither LLVM, nor GCC, nor the Zig compiler use these functions. It
appears the functions were created in a kind of misunderstanding of an
old language proposal; see https://github.com/ziglang/zig/pull/10824.

There is no benefit to these functions existing; if a Zig compiler
backend needs this operation, it is trivial to implement, and *far*
simpler than calling a compiler-rt routine. Therefore, this commit
deletes them. A small amount of that code was used by other parts of
compiler-rt; the logic is trivial so has just been inlined where needed.
I also chose to quickly implement `__addvdi3` (a standard function)
because it is trivial and we already implement the `sub` parallel.
2025-11-12 16:00:16 +00:00
Matthew Lugg
c091e27aac
compiler: spring cleaning
I started this diff trying to remove a little dead code from the C
backend, but ended up finding a bunch of dead code sprinkled all over
the place:

* `packed` handling in the C backend which was made dead by `Legalize`
* Representation of pointers to runtime-known vector indices
* Handling for the `vector_store_elem` AIR instruction (now removed)
* Old tuple handling from when they used the InternPool repr of structs
* Straightforward unused functions
* TODOs in the LLVM backend for features which Zig just does not support
2025-11-12 16:00:15 +00:00
Matthew Lugg
9a7d28fe58
Legalize: rewrite several legalizations
The main goal of this change was to avoid emitting the
`vector_store_elem` AIR tag, because this represents an operation which
Zig no longer supports (and hence Sema no longer emits) as of 010d9a6
(because runtime vector indices are now forbidden). Backends should not
need to lower this operation, so I rewrote the legalizations which
emitted it (scalarizations of vector operations) to instead unroll the
loop and hence emit comptime-known vector indices.

In doing this, I actually reworked those legalizations to use a
different strategy; instead of using an `alloc` and storing to
individual vector elements, the vector is constructed by-val, for
instance by performing the scalar operation on all elements and passing
them to an `aggregate_init`. This is vastly simpler to implement in
Legalize, conceptually simpler, and doesn't severely pessimise memory
usage, because a non-optimizing backend will store the full vector on
the stack either way.

Given the above rationale, I also ended up reworking several other
legalizations to use simpler lowerings. The legalizations in question
were bitcast scalarization, `struct_field_val` of `packed struct`s
(where we just bitcast to an integer and perform the appropriate
shift/trunc sequence), and `aggregate_init` of a `packed struct` (also
implemented in terms of integer bitwise operations with bitcasts to and
from the actual types). This hugely simplified some parts of `Legalize`.

So, `Legalize` is now much simpler, and the `vector_store_elem`
instruction is no longer emitted by any part of the compiler so can be
removed in a future commit.
2025-11-12 16:00:15 +00:00
Alex Rønne Petersen
ee0a0f119c
cmake: add a - missed in 0f71a9291a7400844d95d7ae6aabeaa6b9191527 2025-11-12 11:29:36 +01:00
Alex Rønne Petersen
0f71a9291a
cmake: improve host system detection in some more cases 2025-11-12 10:04:30 +01:00
Jacob Young
61a1cefeb3 Elf2: implement PLT 2025-11-11 14:11:32 -05:00
Jacob Young
79a9f3a418 Elf2: fix relocations against untyped symbols 2025-11-11 01:47:27 -05:00
Jacob Young
8647e4d311 aarch64: cleanup register lock 2025-11-11 01:47:27 -05:00
Techatrix
8887346b53 std.Io: fix calls on functions that return an array type 2025-11-11 01:11:51 +01:00
Carl Åstholm
cca2d09950 io: Correctly align async closure contexts
This fixes package fetching on Windows.

Previously, `Async/GroupClosure` allocations were only aligned for the
closure struct type, which resulted in panics when `context_alignment`
(or `result_alignment` for that matter) had a greater alignment.
2025-11-11 01:11:45 +01:00
Carl Åstholm
5f1392247d io: Redefine Clock.real to return timestamps relative to the POSIX/Unix epoch
`Clock.real` being defined to return timestamps relative to an
implementation-specific epoch means that there's currently no way for
the user to translate returned timestamps to actual calendar dates
without digging into implementation details of any particular `Io`
implementation. Redefining it to return timestamps relative to
1970-01-01T00:00:00Z fixes this problem.

There are other ways to solve this, such as adding a new vtable function
for returning the implementation-specific epoch, but in terms of
complexity this redefinition is by far the simplest solution and only
amounts to a simple 96-bit integer addition's worth of overhead on OSes
like Windows that use non-POSIX/Unix epochs.
2025-11-10 22:12:40 +01:00
Carl Åstholm
ed7f2588e4 io: Translate Windows Clock.real timestamps to the POSIX/Unix epoch
This fixes `std.http.Client` TLS certificate validation on Windows.
2025-11-10 22:12:39 +01:00
Matthew Lugg
cbfa87cbea
Merge pull request #25889 from mlugg/incremental-llvm-warn
compiler: warn when using -fincremental with LLVM backend
2025-11-10 21:10:31 +00:00
Alex Rønne Petersen
ca34abbcde
ci: remove TERM=dumb workaround on Forgejo Actions
https://codeberg.org/forgejo/forgejo/issues/9244
2025-11-10 17:02:27 +01:00
Alex Rønne Petersen
d182c7e3bc
Merge pull request #25886 from alexrp/kvx
beginnings of KVX target support (via CBE)
2025-11-10 16:38:23 +01:00
Matthew Lugg
966809862f
Merge pull request #25839 from Rexicon226/socket-bind-fix
Io.net: fix compile error in `receive` and `receiveTimeout`
2025-11-10 14:38:54 +00:00
xdBronch
fb914a9a10 sema: print @panic message at comptime 2025-11-10 14:21:26 +00:00
Mateusz Poliwczak
d942f693c5 std.zig.AstGen: properly handle grouped_expression
This fixes an endless loop in the compiler.
2025-11-10 14:02:37 +00:00
Frank Denis
ce355e0ba5
Add ML-DSA post-quantum signatures (#25862)
ML-DSA is a post-quantum signature scheme that was recently
standardized by NIST.

Keys and signatures are pretty large, not making it a drop-in
replacement for classical signature schemes.

But if you are shipping keys that may still be used in 10 years
or whenever large quantum computers able to break ECC arrive,
it that ever happens, and you don't have the ability to replace
these keys, ML-DSA is for you.

Performance is great, verification is faster than Ed25519 / ECDSA.

I tried manual vectorization, but it wasn't worth it, the compiler
does at good job at auto-vectorization already.
2025-11-10 14:11:30 +01:00
Matthew Lugg
13993c4f62
compiler: warn when using -fincremental with LLVM backend
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-10 12:56:35 +00:00
Matthew Lugg
6d280dc1b0
compiler: update logFn to use color
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-10 12:55:39 +00:00
Alex Rønne Petersen
cde865e06a
llvm: set sub-arch for spirv 1.6 2025-11-10 12:54:04 +01:00
Alex Rønne Petersen
f34b5ce288
std.Target.DynamicLinker: define standard paths for alpha, microblaze, sh on netbsd and openbsd 2025-11-10 09:40:44 +01:00
Alex Rønne Petersen
255fc44036
std.Target: fix toElfMachine() for arc/arceb 2025-11-10 09:40:44 +01:00
Alex Rønne Petersen
a382b7bfc5
std.simd: suggest 1024-bit vectors for kvx 2025-11-10 09:40:44 +01:00
Alex Rønne Petersen
39b5c8ee8a
std.debug.Dwarf: add kvx ip/fp/sp register mappings 2025-11-10 09:40:44 +01:00
Alex Rønne Petersen
94b6c7ce5f
std.debug.cpu_context: add kvx context implementation 2025-11-10 09:40:44 +01:00
Alex Rønne Petersen
80e567b6bd
std.pie: add kvx support 2025-11-10 09:40:44 +01:00
Alex Rønne Petersen
8fae6630c4
std.start: add kvx support 2025-11-10 09:40:44 +01:00
Alex Rønne Petersen
f5d31cff71
zig.h: add kvx support 2025-11-10 09:40:44 +01:00
Alex Rønne Petersen
4ff6e290dd
cbe: kvx uses $-prefixed registers 2025-11-10 09:40:44 +01:00
Alex Rønne Petersen
350eaa5bac
std.builtin.assembly: add Clobbers for kvx 2025-11-10 09:40:42 +01:00
Alex Rønne Petersen
1e2c216156
compiler: kvx requires 8-byte aligned functions 2025-11-10 08:20:24 +01:00
Alex Rønne Petersen
378eec95b8
std.Target: kvx requires 32-byte aligned stacks 2025-11-10 08:20:24 +01:00
Alex Rønne Petersen
2c470d24b3
std.Target: add Arch tag and info for kvx 2025-11-10 08:20:21 +01:00
Ryan Liptak
c58687225b
Merge pull request #25875 from Zirunis/patch-2
Update Style Guide to suggest TitleCase for Type aliases as is the reality in the standard library
2025-11-09 22:40:24 -08:00
Jacob Young
f3309a96a7
Merge pull request #25819 from jacobly0/elfv2-emit-obj 2025-11-10 00:10:17 -05:00
Zirunis
e1f12124fd
Remove StringAlias because it implies the existence of a String type and is a redundant example anyway
Co-authored-by: Ryan Liptak <squeek502@hotmail.com>
2025-11-09 14:05:09 +01:00
Mateusz Poliwczak
bdbfc7de3f std.zig.Zir: remove ref_start_index from enum fields of Index and OptionalIndex
This change removes the ref_start_index from the possible enum values of
Index and OptionalIndex. It is not really a index, but a constant that
tells the offset of static Refs, so lets move it where such constant
belongs i.e. to the Ref.
2025-11-09 10:45:14 +00:00
Jacob Young
57889cae80 posix: reduce the number of assumptions made by dl_iterate_phdr
Not yet fully compatible with the new linker, but still progress.

Closes #25786
2025-11-09 03:31:26 -05:00
Jacob Young
d33c00cad0 MappedFile: avoid allocating file space with inconsistent state 2025-11-09 03:31:26 -05:00
Jacob Young
02a241f472 Elf2: incrementally update object relocs 2025-11-09 03:31:26 -05:00
Jacob Young
b1d46339b5 Elf2: implement object relocs 2025-11-09 03:31:26 -05:00
Jacob Young
80c961159b Elf2: elide unused nodes when emitting objects 2025-11-09 03:31:26 -05:00
Jacob Young
7bcefe5a22 Elf2: emit object files that are slightly more object-like 2025-11-09 03:31:26 -05:00
Ryan Liptak
5358af7ba4
incr-check: Kill child process on error
Since the child process is spawned with the tmp directory as its CWD, the child process opens it without DELETE access. On error, the child process would still be alive while the tmp directory is attempting to be deleted, so it would fail with `.SHARING_VIOLATION => return error.FileBusy`.

Fixes arguably the least important part of #22510, since it's only the directory itself that would fail to get deleted, all the files inside would get deleted just fine.
2025-11-09 07:45:31 +00:00
Zirunis
4dcc8a80a9
Simplified and unified sentence structure of the naming convention logic 2025-11-09 04:44:05 +01:00
Zirunis
07f50c0351
Update Style Guide to suggest TitleCase for Type aliases 2025-11-09 04:35:01 +01:00
Ryan Liptak
b31a03f134 Let CRT take care of the entry point for wWinMain if libc is linked
Fixes #7852

Before, the modified test would fail with:

```
error: lld-link: undefined symbol: wWinMain
    note: referenced by C:\Users\Ryan\Programming\Zig\zig-x86_64-windows-0.15.1\lib\libc\mingw\crt\crtexewin.c:66
    note:               libmingw32.lib(ucrtexewin.obj):(wmain)
```
2025-11-08 17:11:12 -08:00
Ryan Liptak
be4eaed7c4
Merge pull request #25860 from squeek502/coalesce-to-std-zig
Move/coalesce `CompressDebugSections` and `RcIncludes` enums to `std.zig`
2025-11-08 02:34:44 -08:00
Carl Åstholm
43eb9b52cc link.Elf: Ensure archive header fields are not left blank
ld.lld fails with "truncated or malformed archive" errors when reading
archive header field values that are not valid numbers.
2025-11-08 02:11:52 -08:00
Petr Pučil
38d44404a5 Fix param name in doc comment for std.Io.Reader.peek()
The old doc comment mentioned a parameter `len` three times, but the
function does not accept such a parameter - it is actually called `n`.
2025-11-08 00:34:41 -08: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
Alex Rønne Petersen
bf15c791fa
Merge pull request #25820 from GiuseppeCesarano/process
Child.start_suspended ported to posix
2025-11-07 23:17:55 +01:00
Lukas Lalinsky
852a1f718a Fix kqueue definitions on NetBSD
EVFILT_USER and NOTE_TRIGGER were wrong.

Added missing ones along the way.
2025-11-07 22:23:46 +01:00
xdBronch
92f64899c1 sema: disallow slices of opaque types 2025-11-07 12:12:32 +00:00
Alex Rønne Petersen
19af9fa488
Merge pull request #25848 from Rexicon226/llvm-valgrind-clobber
llvm: fix up clobbers for valgrind requests
2025-11-07 11:55:09 +01:00
Giuseppe Cesarano
f4159eff92
std.Child: start_suspended ported to posix 2025-11-07 08:53:43 +01:00
Giuseppe Cesarano
5c0309a9e5
std.posix: implemented getpid and getppid 2025-11-07 08:52:35 +01:00
Frank Denis
4b593a6c24
std.crypto: improve KT documentation, use key_length for B3 key length (#25807)
It was not obvious that the KT128/KT256 customization string can be
used to set a key, or what it was designed to be used for at all.

Also properly use key_length and not digest_length for the BLAKE3
key length (no practical changes as they are both 32, but that was
confusing).

Remove unneeded simd_degree copies by the way, and that doesn't need
to be in the public interface.
2025-11-07 08:20:04 +01:00
marximimus
2e8f8afc83
Base64DecoderWithIgnore.calcSizeUpperBound cannot return an error (#25834)
* std: Base64DecoderWithIgnore.calcSizeUpperBound cannot return an error

* std: update doc comment of Base64DecoderWithIgnore.calcSizeUpperBound
2025-11-07 08:16:34 +01:00
David Rubin
483f9bd367
llvm: add extra clobbers to valgrind requests
This seems to work around a very puzzling miscompilation first
present in LLVM 21.x. We already unconditionally add these
clobbers to inline assembly that came from the source, the
valgrind requests should also contain them.
2025-11-06 20:27:38 -08:00
David Rubin
09e4035e79
llvm: clobber rdx instead of edx for x86-64 valgrind request 2025-11-06 20:12:35 -08:00
David Rubin
71988d6719
Io.net: set receive{,Timeout} message to init
If we use `undefined`, then `netReceive` can `@intCast` the
control slice len to msghdr controllen, which is sometimes `u32`,
even on 64-bit platforms.

`init` just avoids this entirely by setting `control` to an empty
slice rather than undefined.
2025-11-06 17:44:28 -08:00
David Rubin
654a5b20d7
Io: fix compile error in receive and receiveTimeout
Correctly uses the `netReceive` API. If an error was
returned, we propagate that error, otherwise assert
we only received one message.
2025-11-06 17:42:19 -08:00
Mateusz Poliwczak
40132af3ad std.zig.AstRlAnnotate: remove pointless switch
This switch has the same cases as the outer one.
2025-11-06 23:57:16 +00:00
Ryan Liptak
4937aeff84
Merge pull request #25714 from snoire/enum-literal-format-support
std.Io.Writer.print: support .enum_literal in 't' format specifier
2025-11-06 14:40:34 -08:00
Mateusz Poliwczak
b2895f356f std.ArrayList: actaully memset to undefined in shrinkRetainingCapacity and clearRetainingCapacity
See #25810
2025-11-06 05:30:41 -08:00
Alex Rønne Petersen
e639602569 ci: update to Wasmtime 38.0.3 2025-11-06 14:08:16 +01: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
snoire
b4b54b597d test: add test case for enum-literal with '{t}' format
Co-authored-by: Ryan Liptak <squeek502@hotmail.com>
2025-11-06 13:45:21 +08:00
snoire
ffb0050d81 std.Io.Writer.print: support .enum_literal in 't' format specifier 2025-11-06 13:45:21 +08:00
Mateusz Poliwczak
416bf1de47 std.ArrayList: memset to undefined in shrinkRetainingCapacity and clearRetainingCapacity
Fixes #25796
2025-11-05 19:31:19 -08:00
skewb1k
26db54d69b zig fmt: fix extra whitespace in StructInit with multiline strings
68d2f68ed introduced special handling for StructInit fields
containing multiline strings to prevent inserting whitespace after =.
However, this logic didn't handle cases without a trailing comma,
which resulted in unwanted trailing whitespace.
2025-11-05 14:07:30 +02:00
Jacob Young
a6d444c271 x86_64: implement split vector stores
Closes #25809
2025-11-04 22:45:54 -05: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
Carl Åstholm
075d300342 Remove std.builtin.subsystem
The subsystem detection was flaky and often incorrect and was not
actually needed by the compiler or standard library. The actual
subsystem won't be known until at link time, so it doesn't make
sense to try to determine it at compile time.
2025-11-05 01:29:00 +01:00
Alex Rønne Petersen
74900e938a
Merge pull request #25813 from linusg/bump-macos-libc
libc: Update macOS headers to SDK 26.1
2025-11-04 23:05:14 +01:00
Linus Groh
f55eb18abb libc: Add mach-o/getsect.h and mach/exception.h macOS headers
Closes #18257.
2025-11-04 21:51:48 +00:00
Linus Groh
e2fb103ce1 libc: Add all macOS CommonCrypto headers
Closes #23795.
2025-11-04 21:48:06 +00:00
Linus Groh
abca5bd588 libc: Update macOS headers to SDK 26.1 2025-11-04 21:40:21 +00:00
Jacob Young
459f3b7ede codegen: fix tuple padding
Closes #25797
2025-11-04 06:04:30 -05:00
Jacob Young
ea76946d2a Io.Queue: fix empty and full states being indistinguishable. 2025-11-04 04:24:32 -05:00
kbz_8
c603d27f90
Fixing SPIR-V header generator magic + Adding Zig compiler version to SPIR-V OpSource (#25435)
* fixing Zig generator magic in SPIR-V header; adding zig compiler version to SPIR-V OpSource

* Update src/codegen/spirv/Module.zig

Co-authored-by: rpkak <67059904+rpkak@users.noreply.github.com>

---------

Co-authored-by: rpkak <67059904+rpkak@users.noreply.github.com>
2025-11-04 04:40:29 +00:00
Frank Denis
ee4df4ad3e
crypto - threaded K12: separate context computation from thread spawning (#25793)
* threaded K12: separate context computation from thread spawning

Compute all contexts and store them in a pre-allocated array,
then spawn threads using the pre-computed contexts.

This ensures each context is fully materialized in memory with the
correct values before any thread tries to access it.

* kt128: unroll the permutation rounds only twice

This appears to deliver the best performance thanks to improved cache
utilization, and it’s consistent with what we already do for SHA3.
2025-11-03 17:09:00 +01:00
Linus Groh
afdd04356c std: serenity has preadv now
2a9154e77c
2025-11-02 14:45:32 -08:00
Frank Denis
bf9082518c
crypto.kt128: when using incremental hashing, use SIMD when possible (#25783)
Also add plain kt128 (without threading) to the benchmarks
2025-11-02 11:31:00 +01:00
Alex Rønne Petersen
2f4bca41ea
ci: bump riscv64-linux-debug timeout to 9 hours on Forgejo Actions 2025-11-01 17:18:24 +01:00
Jacob Young
143ea88017 Revert "std.http: disable failing test on 32-bit arm"
This reverts commit 16185f66f1e500d61d43550e7c847a36ad1032df.

Which was fixed by d000574380baba7b63fdcde713b51f8318509474.

Closes #25762
2025-11-01 11:21:28 -04:00
Alex Rønne Petersen
5db9eaa851
std.Io.Threaded: use ResetEventPosix on illumos
Like NetBSD, illumos has no futexes.

ref #25760
2025-11-01 16:18:56 +01:00
Bingwu Zhang
a8fea09cd5 cbe: fix more MIPS register names in inline assembly 2025-11-01 15:11:35 +01:00
Frank Denis
95c76b1b4a
Add std.crypto.hash.sha3.{KT128,KT256} - RFC 9861. (#25593)
KT128 and KT256 are fast, secure cryptographic hash functions based on Keccak (SHA-3).

They can be seen as the modern version of SHA-3, and evolution of SHAKE, with better performance.

After the SHA-3 competition, the Keccak team proposed these variants in 2016, and the constructions underwent 8 years of public scrutiny before being standardized in October 2025 as RFC 9861.

They uses a tree-hashing mode on top of TurboSHAKE, providing both high security and excellent performance, especially on large inputs.

They support arbitrary-length output and optional customization strings.

Hashing of very large inputs can be done using multiple threads, for high throughput.

KT128 provides 128-bit security strength, equivalent to AES-128 and SHAKE128, which is sufficient for virtually all applications.

KT256 provides 256-bit security strength, equivalent to SHA-512. For virtually all applications, KT128 is enough (equivalent to SHA-256 or BLAKE3).

For small inputs, TurboSHAKE128 and TurboSHAKE256 (which KT128 and KT256 are based on) can be used instead as they have less overhead.
2025-11-01 14:03:43 +00:00
Alex Rønne Petersen
4e943fc847
std.c: add missing MINSIGSTKSZ for some FreeBSD targets 2025-11-01 09:58:05 +01:00
Frank Denis
d5585bc650
Implement threaded BLAKE3 (#25587)
Allows BLAKE3 to be computed using multiple threads.
2025-11-01 07:40:03 +01:00
Jay Petacat
5a38dd28dc std: Skip element comparisons if mem.order args point to same memory
This optimization is used in `mem.eql`, but was missing from `order`,
`orderZ`, and `ascii.orderIgnoreCase`.
2025-10-31 18:34:33 -07:00
Alex Rønne Petersen
8468549726
std.Target: bump vulkan max version to 1.4.331 2025-10-31 15:46:44 +01:00
Alex Rønne Petersen
d677086bcd
std.Target: bump opencl/nvcl max version to 3.0.19 2025-10-31 15:46:29 +01:00
Alex Rønne Petersen
adbf46aef3
std.Target: bump cuda max version to 13.0.2 2025-10-31 15:46:08 +01:00
Alex Rønne Petersen
802ee515d8
std.Target: bump amdhsa max version to 7.1.0 2025-10-31 15:45:57 +01:00
Alex Rønne Petersen
27c949689e
std.Target: bump wasi max version to 0.3.0 2025-10-31 15:45:43 +01:00
Alex Rønne Petersen
3801e6366f
std.Target: bump dragonfly max version to 6.4.2 2025-10-31 15:45:26 +01:00
Alex Rønne Petersen
a9c648c060
std.Target: bump linux max version to 6.17 2025-10-31 15:45:13 +01:00
Alex Rønne Petersen
0116d98093
std.Target: bump fuchsia max version to 28.0.0 2025-10-31 15:45:01 +01:00
Alex Rønne Petersen
38413446b0
std.Target: bump contiki max version to 5.1.0 2025-10-31 15:44:47 +01:00
Alex Rønne Petersen
a46c3a1582
test: remove some unsupported x86_64 darwin targets from llvm_targets 2025-10-31 15:36:17 +01:00
qilme
8347791ce3
std.os.windows: eliminate forwarder function in kernel32 (#25766)
#1840

kernel32.AddVectoredExceptionHandler -> ntdll.RtlAddVectoredExceptionHandler
kernel32.RemoveVectoredExceptionHandler -> ntdll.RtlRemoveVectoredExceptionHandler
kernel32.ExitProcess -> ntdll.RtlExitUserProcess
kernel32.InitializeCriticalSection -> ntdll.RtlInitializeCriticalSection
kernel32.EnterCriticalSection -> ntdll.RtlEnterCriticalSection
kernel32.LeaveCriticalSection -> ntdll.RtlLeaveCriticalSection
kernel32.DeleteCriticalSection -> ntdll.RtlDeleteCriticalSection
kernel32.TryAcquireSRWLockExclusive -> ntdll.RtlTryAcquireSRWLockExclusive
kernel32.AcquireSRWLockExclusive -> ntdll.RtlAcquireSRWLockExclusive
kernel32.ReleaseSRWLockExclusive -> ntdll.RtlReleaseSRWLockExclusive
kernel32.WakeConditionVariable -> ntdll.RtlWakeConditionVariable
kernel32.WakeAllConditionVariable -> ntdll.RtlWakeAllConditionVariable
kernel32.HeapReAlloc -> ntdll.RtlReAllocateHeap
kernel32.HeapAlloc -> ntdll.RtlAllocateHeap
2025-10-31 13:54:50 +00:00
TibboddiT
62de7a2efd
fix typo in std.debug.ElfFile.loadSeparateDebugFile
closes #25667
2025-10-31 09:44:47 +01:00
Alex Rønne Petersen
389368392e
Revert "ci: stop building FreeBSD module tests on x86_64-linux"
This reverts commit 16c18b835e16bae7a0f85caa29457f4ae4b7b417.

There must be one CI script that doesn't skip anything.
2025-10-30 23:17:33 +01:00
Jacob Young
d000574380 Io: fix some horrible data races and UAFs caused by Condition misuse 2025-10-30 16:53:05 -04:00
Alex Rønne Petersen
0ca4df540f
std.debug.cpu_context: fix signal_ucontext_t for arm-linux 2025-10-30 20:28:31 +01:00
Alex Rønne Petersen
8126e22756
build: bump libc-test max_rss from 1758181785 to 2253598720 2025-10-30 17:52:50 +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
4174ab9c2c
Merge pull request #25726 from mlugg/std-log-colors
Cache stderr ttyconf, colorize `std.log`, and fix `--webui`
2025-10-30 15:24:47 +00:00
Jacob Young
32779a7c73
aarch64: fix macho external references 2025-10-30 09:31:30 +00:00
Jacob Young
402c14f86a
aarch64: implement optional comparisons 2025-10-30 09:31:30 +00: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
9215121688
std.log: colorize output in default implementation
Also remove the example implementation from the file doc comment; it's
better to just link to `defaultLog` as an example, since this avoids
writing the example implementation twice and prevents the example from
bitrotting.
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
1d80c9540a Threaded: fix safety crashes 2025-10-29 21:01:47 -04:00
Alex Rønne Petersen
767f28d7a6
Merge pull request #25733 from GasInfinity-Forks/x86_16-cpu_context
* fix: add `i86` cpu in `update_cpu_features`
* feat: add `x86_16` debug `cpu_context`
2025-10-30 01:41:32 +01:00
Jacob Young
09aa4add2a x86_64: add lret encoding
Closes #25608
2025-10-29 19:31:44 -04:00
Jacob Young
52a029e503 x86_64: continue hacking around unimplemented linker logic
Closes #25666
2025-10-29 19:31:44 -04:00
Jacob Young
ada9035af5 x86_64: fix encoding for out with an immediate port
Closes #25547
2025-10-29 18:41:31 -04:00
Jacob Young
6e8b07ca15 Elf: fix alignment of merge subsections
Closes #25565
2025-10-29 18:41:05 -04:00
Jacob Young
0834e696f7 Elf2: start implementing dynamic linking 2025-10-29 18:15:09 -04:00
Jacob Young
40901440a6 Elf2: simplify archive loading 2025-10-29 18:14:16 -04:00
Jacob Young
c4478e078b Elf2: load archives 2025-10-29 18:07:12 -04:00
Jacob Young
7542c3260f Elf2: load relocations from input objects 2025-10-29 18:06:17 -04:00
Jacob Young
6f0476e41d Elf2: start implementing input object loading 2025-10-29 18:05:49 -04:00
Andrew Kelley
a072d821be
Merge pull request #25592 from ziglang/init-std.Io
std: Introduce `Io` Interface
2025-10-29 13:51:37 -07:00
Andrew Kelley
16185f66f1 std.http: disable failing test on 32-bit arm
tracked by https://github.com/ziglang/zig/issues/25762
2025-10-29 13:50:04 -07:00
Alex Rønne Petersen
b2bc44e0d5
std.os.linux: fix restore for powerpc/powerpc64
sigreturn and rt_sigreturn are distinct syscalls on PowerPC.
2025-10-29 20:44:43 +01:00
GasInfinity
ef4f6e6c05
feat: add x86_16 debug cpu_context 2025-10-29 14:35:33 +01:00
GasInfinity
fca748ffba
fix: add i86 cpu in update_cpu_features 2025-10-29 14:34:58 +01:00
Andrew Kelley
0205ce4736 std.os.linux.IoUring: disable failing test
tracked by https://github.com/ziglang/zig/issues/25734
2025-10-29 06:26:05 -07:00
Andrew Kelley
e8e1e2793a std.Io: make select unit test not depend on cancellation 2025-10-29 06:26:05 -07:00
Alex Rønne Petersen
a7119d4269 remove all IBM AIX and z/OS support
As with Solaris (dba1bf935390ddb0184a4dc72245454de6c06fd2), we have no way to
actually audit contributions for these OSs. IBM also makes it even harder than
Oracle to actually obtain these OSs.

closes #23695
closes #23694
closes #3655
closes #23693
2025-10-29 14:25:51 +01:00
Andrew Kelley
b1d270d38e std.os.linux.s390x: fix restore function 2025-10-29 06:20:52 -07:00
Andrew Kelley
05b28409e7 std.Io.Threaded: install and cleanup signal handlers
rather than in start code. delete std.options.keep_sig_io and
std.options.keep_sig_pipe
2025-10-29 06:20:52 -07:00
Andrew Kelley
b863f2548b std.Io.Threaded: handle -fsingle-threaded in unit tests 2025-10-29 06:20:52 -07:00
Andrew Kelley
1c0a8b8fe4 std.hash_map: tune slow unit tests
These are the only two unit tests that take longer than 1s on my
computer.
2025-10-29 06:20:52 -07:00
Andrew Kelley
a45cafb7f0 std.Io: add unit test for select 2025-10-29 06:20:52 -07:00
Andrew Kelley
c40204a3e5 std.Io: add unit tests for Group and concurrent 2025-10-29 06:20:52 -07:00
Andrew Kelley
03fd132b1c std.Io: fix Group.wait unsoundness
Previously if a Group.wait was canceled, then a subsequent call to
wait() or cancel() would trip an assertion in the synchronization code.
2025-10-29 06:20:52 -07:00
Andrew Kelley
6c794ce7bc std.Io.Threaded.dirOpenFileWtf16: SHARING_VIOLATION
is the error code that needs the kernel bug workaround, not
ACCESS_DENIED.
2025-10-29 06:20:52 -07:00
Andrew Kelley
9f986419bd CI: link ws2_32.lib on Windows 2025-10-29 06:20:52 -07:00
Andrew Kelley
6f64c8b693 std.debug.SelfInfo.Windows: less invasive change
restores code closer to master branch in hopes of avoiding a regression
that was introduced when this was based on openSelfExe rather than
GetModuleFileNameExW.
2025-10-29 06:20:52 -07:00
Andrew Kelley
1553c8eae7 std.os.linux.x86: fix signal restore function
After handling any signal on x86, it would previously segfault.
2025-10-29 06:20:52 -07:00
Andrew Kelley
030b630829 std.Io.Threaded: fix EBADF error code on wasm32-wasi -lc when reading 2025-10-29 06:20:52 -07:00
Andrew Kelley
c4dc7d7c3d std.Io.Threaded: implement Unix sockets for Windows 2025-10-29 06:20:52 -07:00
Andrew Kelley
b39f3d294d std.Io.Threaded: implement dirMakeOpenPath for WASI
and fix error code when file operation occurs on director handle
2025-10-29 06:20:52 -07:00
Andrew Kelley
4114392369 std: fix definition of ws2_32.GetAddrInfoExW
There was a missing parameter.
2025-10-29 06:20:52 -07:00
Andrew Kelley
f5870b267e std.Io.Threaded: fix typo in panic message 2025-10-29 06:20:52 -07:00
Andrew Kelley
94b9874981 std.Io.Threaded: stub out netbsd mutex and condition 2025-10-29 06:20:52 -07:00
Andrew Kelley
c0c2010535 std.c: fix msghdr struct on big endian targets 2025-10-29 06:20:52 -07:00
Andrew Kelley
a28d3059e6 std.Io.Threaded: implement ResetEvent in terms of pthreads
needed for NetBSD
2025-10-29 06:20:52 -07:00
Andrew Kelley
30448d92af std.Io.Threaded: fix netLookup for Windows
* respect address family option
* fix port number using wrong buffer
2025-10-29 06:20:52 -07:00
Andrew Kelley
030ddc7952 update standalone tests for ws2_32 dependency 2025-10-29 06:20:51 -07:00
Andrew Kelley
135ec79f50 std.Io.File: fix stat for Windows 2025-10-29 06:20:51 -07:00
Andrew Kelley
6b8972dd22 resinator: update for Io API 2025-10-29 06:20:51 -07:00
Andrew Kelley
cc4931b325 std.Io.Threaded: fix 32-bit overflow in lookupDns
be a little more careful with nanoseconds
2025-10-29 06:20:51 -07:00
Andrew Kelley
c8739d6953 std.Io.Group: fix leak when wait is canceled
Only when the operation succeeds should the token field be set to null.
2025-10-29 06:20:51 -07:00
Andrew Kelley
3de1b6c9a9 std.Io.Threaded: better clock lowering for BSDs 2025-10-29 06:20:51 -07:00
Andrew Kelley
80a341b411 std: remove awareness of POLL signal
this signal seems to be deprecated and/or useless on every target
2025-10-29 06:20:51 -07:00
Andrew Kelley
8b269f7e18 std: make signal numbers into an enum
fixes start logic for checking whether IO/POLL exist
2025-10-29 06:20:51 -07:00
Andrew Kelley
cc751c01f1 std.Io.Threaded: correct clockToPosix for FreeBSD 2025-10-29 06:20:51 -07:00
Andrew Kelley
ef55dcae67 start: fix logic for signal hanlding when SIG.POLL does not exist
fixes a compilation failure on FreeBSD
2025-10-29 06:20:51 -07:00
Andrew Kelley
bbc1c07538 std.zig.system: fix error set of abiAndDynamicLinkerFromFile 2025-10-29 06:20:51 -07:00
Andrew Kelley
4e95c2eb1b std.Io.Threaded: implement futexes for freebsd 2025-10-29 06:20:51 -07:00
Andrew Kelley
a87fd37bf5 std.Io: make Evented equal void when unimplemented
This allows conditional compilation checks.
2025-10-29 06:20:51 -07:00
Andrew Kelley
0caf286a1a std.Io.Threaded: don't skip executing canceled group closures 2025-10-29 06:20:51 -07:00
Andrew Kelley
df4c30ca16 link: move the windows kernel bug workaround to Io implementation 2025-10-29 06:20:51 -07:00
Andrew Kelley
02119362d7 wasm linking: handle unreachable call_indirect
The compiler crashed when we tried to call a function pointer for which
the type signature does not match any function body or function import
in the entire wasm executable, because there is no way to create a
reference to a function without it being in the function table or import
table. Solution is to make this instruction lower to unreachable.
2025-10-29 06:20:51 -07:00
Andrew Kelley
6ccb53bff1 std.Io.Threaded: fix openSelfExe for Windows
missing a call to wToPrefixedFileW
2025-10-29 06:20:51 -07:00
Andrew Kelley
441d0c4272 std.Io.net.HostName: fix missing group cancel 2025-10-29 06:20:51 -07:00
Andrew Kelley
f9de83c90e std.Io.net: skip testing netInterfaceNameResolve on Windows
let's handle this in a follow-up change. implementation needs to use
ConvertInterfaceNameToLuidW and the additional dependency on
Iphlpapi.dll poses some challenges.
2025-10-29 06:20:51 -07:00
Andrew Kelley
f6c5525c84 std.Io.Threaded: fix compilation on pthreads linux 2025-10-29 06:20:51 -07:00
Andrew Kelley
fd7475c8b2 std.Io.Threaded: implement netWrite for Windows 2025-10-29 06:20:51 -07:00
Andrew Kelley
6cff32c7ee std.Io.Threaded: implement netRead for Windows 2025-10-29 06:20:51 -07:00
Andrew Kelley
a8f95e5176 std.Io.Threaded: implement cancellation for pthreads
not to be confused with pthread_cancel, which is a useless API.
2025-10-29 06:20:51 -07:00
Andrew Kelley
85e159e652 std.Io.Threaded: closures must always be run even when canceled 2025-10-29 06:20:51 -07:00
Andrew Kelley
ed7067a690 std.Io: more convenient sleep 2025-10-29 06:20:51 -07:00
Andrew Kelley
e6b4e1a5d0 disable self-hosted wasm test-cases
Tracked by #25684
2025-10-29 06:20:51 -07:00
Andrew Kelley
ae86c0f529 std.Io: adjust concurrent error set
Now std.Io.Threaded can return error.ConcurrencyUnavailable rather than
asserting. This is handy for logic that wants to try a concurrent
implementation but then fall back to a synchronous one.
2025-10-29 06:20:51 -07:00
Andrew Kelley
ecdc00466c std.Io.net: make it easier to use netReceiveMany correctly 2025-10-29 06:20:51 -07:00
Andrew Kelley
c87fbd5878 std.os.linux.IoUring: use linux msghdr
it disagrees with posix msghdr
2025-10-29 06:20:51 -07:00
Andrew Kelley
46f7e3ea9f std.Io.Threaded: add ioBasic which disables networking 2025-10-29 06:20:51 -07:00
Andrew Kelley
701d4bc80b objcopy: update for std.Io API 2025-10-29 06:20:51 -07:00
Andrew Kelley
5c527a1854 std.Io.Threaded: implement fileStat for Windows 2025-10-29 06:20:51 -07:00
Andrew Kelley
5d7672f2ad std.Io.Threaded: stub netConnectUnix for Windows 2025-10-29 06:20:51 -07:00
Andrew Kelley
89bb58e5a3 incr-check: windows source files depend on ws2_32 2025-10-29 06:20:51 -07:00
Andrew Kelley
a1f177d637 std.Io.Threaded: stub netListenUnix for Windows 2025-10-29 06:20:51 -07:00
Andrew Kelley
5578c760a7 std.Io.Kqueue: implement wait queue per fd
Solves the issue when one kevent() call would clobber another if they
used the same file descriptor as an identifier.
2025-10-29 06:20:51 -07:00
Andrew Kelley
6a64c9b7c8 std.Io.Kqueue: add missing Thread deinit logic 2025-10-29 06:20:51 -07:00
Andrew Kelley
cc11dd1f87 std.Io.Kqueue: implement EAGAIN logic for netRead 2025-10-29 06:20:51 -07:00
Andrew Kelley
0497f88d39 std.Io.Kqueue: implement netRead 2025-10-29 06:20:51 -07:00
Andrew Kelley
1b0dcd4007 std.Io.Threaded: fix setting of O_NONBLOCK flag 2025-10-29 06:20:51 -07:00
Andrew Kelley
f17c6bba57 std.Io.Kqueue: implement netConnect 2025-10-29 06:20:51 -07:00
Andrew Kelley
9d6750f01c std.Io.Kqueue: implement netSend 2025-10-29 06:20:51 -07:00
Andrew Kelley
92b8378814 concurrent and await 2025-10-29 06:20:51 -07:00
Andrew Kelley
dd945bf1f8 one kqueue per thread 2025-10-29 06:20:51 -07:00
Andrew Kelley
41070932f8 revert adding asyncDetached
instead we will have Io.Group
2025-10-29 06:20:51 -07:00
Andrew Kelley
df84dc18bc add bind 2025-10-29 06:20:51 -07:00
Andrew Kelley
d6b0686b05 std.Io: add Kqueue implementation 2025-10-29 06:20:51 -07:00
Andrew Kelley
a5c309a692 std.Io.net.Socket.send: fix compilation errors 2025-10-29 06:20:51 -07:00
Andrew Kelley
59ffa607a4 std.Io.Threaded: fix sending invalid pointer
OS wants valid control pointer even when len is zero
2025-10-29 06:20:51 -07:00
Andrew Kelley
873bcb5aa6 fix some std.Io compilation failures 2025-10-29 06:20:51 -07:00
Andrew Kelley
032152409b std.Io.Threaded: fix signature of dirMakeOpenPathWasi 2025-10-29 06:20:51 -07:00
Andrew Kelley
a3ddca3657 std.Io.Threaded: delete Windows implementation of if_nametoindex
Microsoft documentation says "The if_nametoindex function is implemented
for portability of applications with Unix environments, but the
ConvertInterface functions are preferred."

This was also the only dependency on iphlpapi.
2025-10-29 06:20:51 -07:00
Andrew Kelley
2f26025690 std: fix build failure on wasm32-freestanding 2025-10-29 06:20:51 -07:00
Andrew Kelley
00a3123fbe std.process.Child: update for std.Io changes 2025-10-29 06:20:51 -07:00
Andrew Kelley
ab003cd054 std.Io.Threaded: implement netLookup for Windows 2025-10-29 06:20:51 -07:00
Andrew Kelley
dab8dd5e03 std.os.windows.ws2_32: remove 'A' variants 2025-10-29 06:20:51 -07:00
Andrew Kelley
0107e584ef std.Io.Threaded: implement Windows futex functions 2025-10-29 06:20:51 -07:00
Andrew Kelley
d257b1337a std.Io.Threaded: fix compilation failures on Windows 2025-10-29 06:20:50 -07: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
4ed74a9f8a std.Io.Threaded: implement netConnectIp for Windows 2025-10-29 06:20:50 -07:00
Andrew Kelley
67df66c26c update some tests and tools for new Io APIs 2025-10-29 06:20:50 -07:00
Andrew Kelley
4174ac18e9 resinator: update for new Io APIs 2025-10-29 06:20:50 -07:00
Andrew Kelley
76107e9e65 std.Io.Threaded: implement netBindIp for Windows 2025-10-29 06:20:50 -07:00
Andrew Kelley
0b5179a231 std.Io.Threaded: implement netAccept for Windows 2025-10-29 06:20:50 -07:00
Andrew Kelley
34891b528e std.Io.Threaded: implement netListen for Windows 2025-10-29 06:20:50 -07:00
Andrew Kelley
62c0496d0a std.Io.Threaded: implement dirOpenDir 2025-10-29 06:20:50 -07:00
Andrew Kelley
dc6a4f3bf1 std.Io: add dirMakePath and dirMakeOpenPath 2025-10-29 06:20:50 -07:00
Andrew Kelley
71c86e1d28 std.posix: fix compilation on wasm32-freestanding 2025-10-29 06:20:50 -07:00
Andrew Kelley
894cb5a1fc std.posix: untangle getRandomBytesDevURandom from Io.Reader 2025-10-29 06:20:50 -07:00
Andrew Kelley
97bde94e36 compiler: upgrade unit tests to new API 2025-10-29 06:20:50 -07:00
Andrew Kelley
6d1b2c7f64 std.Io: introduce openSelfExe 2025-10-29 06:20:50 -07:00
Andrew Kelley
1c67607397 std.Io.Threaded: implement dirOpenFile for Windows 2025-10-29 06:20:50 -07:00
Andrew Kelley
b561d5f3fe std.Io.Threaded: implement dirCreateFile for Windows 2025-10-29 06:20:50 -07:00
Andrew Kelley
aa6e8eff40 std.Io.Threaded: implement dirAccess for Windows 2025-10-29 06:20:50 -07:00
Andrew Kelley
482343f2e2 std.Io.Threaded: implement dirStatPath for Windows 2025-10-29 06:20:50 -07:00
Andrew Kelley
f98352eecf std.debug.SelfInfo: add missing io parameter to getSymbol 2025-10-29 06:20:50 -07:00
Andrew Kelley
ed7747e90f std.Io.Threaded: add dirMake for Windows 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
b215f8667a std.Io.net.HostName.ResolvConf: ignore nameservers above max 2025-10-29 06:20:50 -07:00
Andrew Kelley
83e4ff6f4c std.Io: add dirClose 2025-10-29 06:20:50 -07:00
Andrew Kelley
21e195a1a9 std: move some windows path checking logic 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
97b9cc0adf aro: avoid asking for the time
this value should be calculated earlier and passed in
2025-10-29 06:20:50 -07:00
Andrew Kelley
43c2ba375d std: accessZ -> access 2025-10-29 06:20:50 -07:00
Andrew Kelley
752d38612f std.Io.Threaded: fix -fsingle-threaded build 2025-10-29 06:20:50 -07:00
Andrew Kelley
81e7e9fdbb std.Io: add dirOpenDir and WASI impl 2025-10-29 06:20:50 -07:00
Andrew Kelley
da6b959f64 std.Io.Threaded: implement dirOpenFile for WASI 2025-10-29 06:20:50 -07:00
Andrew Kelley
e87ceb76c2 std.Io.net.Server: refine AcceptError set 2025-10-29 06:20:50 -07:00
Andrew Kelley
cf6fa219fd std.Io.Threaded: fix netWrite cancellation
Move std.posix logic over rather than calling into it.
2025-10-29 06:20:50 -07:00
Andrew Kelley
d4215ffaa0 std.Io.Threaded: implement dirCreateFile for WASI 2025-10-29 06:20:50 -07:00
Andrew Kelley
143127529b std.Io.Threaded: implement dirMake for WASI 2025-10-29 06:20:50 -07:00
Andrew Kelley
ec9dfc540b std.Io.Threaded: handle ECANCELED
none of these APIs are documented to return this error code, but it
would be cool if they did.
2025-10-29 06:20:50 -07:00
Andrew Kelley
f8ea00bd6d std.Io: add dirAccess 2025-10-29 06:20:50 -07:00
Andrew Kelley
3bf0ce65a5 fix miscellaneous compilation errors
- ILSEQ -> error.BadPathName
- implement dirStatPath for WASI
2025-10-29 06:20:50 -07:00
Andrew Kelley
7b1502f327 std: fix compilation errors on macos 2025-10-29 06:20:50 -07:00
Andrew Kelley
f14c4c3db8 std.Io.net.HostName: fix connectMany not running DNS async 2025-10-29 06:20:50 -07:00
Andrew Kelley
6336d58661 std.Io.Threaded: fix getaddrinfo usage 2025-10-29 06:20:50 -07:00
Andrew Kelley
f7bbcb4a4b fix miscellaneous compilation failures 2025-10-29 06:20:50 -07:00
Andrew Kelley
22334f5730 std: make IPv6 address parsing system-independent
before, the max length of the host name depended on the target.
2025-10-29 06:20:50 -07:00
Andrew Kelley
90fdd21df6 std: move DNS record enum to a better namespace 2025-10-29 06:20:50 -07:00
Andrew Kelley
bf841bb4ae std.Io.Threaded: implement futexes on darwin 2025-10-29 06:20:50 -07:00
Andrew Kelley
18ec9685fb std.Io.Threaded: add support for getaddrinfo
this API sucks but it's the best we've got on some operating systems
2025-10-29 06:20:49 -07:00
Andrew Kelley
031044b399 std: fix macos compilation errors 2025-10-29 06:20:49 -07:00
Andrew Kelley
f7d47aed47 README: LLVM-less builds are more capable now 2025-10-29 06:20:49 -07:00
Andrew Kelley
bb1bf5b96f std.Io: stub file writing rather than incorrect impl 2025-10-29 06:20:49 -07:00
Andrew Kelley
1e81c3a925 std.Io: rename EventLoop to IoUring
`std.Io.Evented` is introduced to select an appropriate Io
implementation depending on OS
2025-10-29 06:20:49 -07:00
Andrew Kelley
81b1bfbfbb std.Io.Threaded: wrangle TODOs 2025-10-29 06:20:49 -07:00
Andrew Kelley
060fd975d9 std.Io.Group: add cancellation support to "wait" 2025-10-29 06:20:49 -07:00
Andrew Kelley
10bfbd7d60 std.Io.Threaded: rename from "pool" 2025-10-29 06:20:49 -07:00
Andrew Kelley
870a682cd8 std.Io.net.HostName.connect: fix resource leaks
Must free other succeeded connections that lost the race.
2025-10-29 06:20:49 -07:00
Andrew Kelley
426a377c7b std.Io.net.Stream: add "const" variant to "close"
useful for resource management
2025-10-29 06:20:49 -07:00
Andrew Kelley
80069c1e69 std.Io.Queue: add "uncancelable" variants to "get"
useful for resource management
2025-10-29 06:20:49 -07:00
Andrew Kelley
adaef433d2 std.net.HostName.connect: rework to avoid waiting for DNS
The previous implementation would eagerly attempt TCP connection upon
receiving a DNS reply, but it would still wait for all the DNS results
before returning from the function.

This implementation returns immediately upon first successful TCP
connection, canceling not only in-flight TCP connection attempts but
also unfinished DNS queries.
2025-10-29 06:20:49 -07:00
Andrew Kelley
d3c4158a10 std.Io: implement Select
and finish implementation of HostName.connect
2025-10-29 06:20:49 -07:00
Andrew Kelley
35ce907c06 std.Io.net.HostName: move lookup to the interface
Unfortunately this can't be implemented "above the vtable" because
various operating systems don't provide low level DNS resolution
primitives such as just putting the list of nameservers in a file.

Without libc on Linux it works great though!

Anyway this also changes the API to be based on Io.Queue. By using a
large enough buffer, reusable code can be written that does not require
concurrent, yet takes advantage of responding to DNS queries as they
come in. I sketched out a new implementation of `HostName.connect` to
demonstrate this, but it will require an additional API (`Io.Select`) to
be implemented in a future commit.

This commit also introduces "uncancelable" variants for mutex locking,
waiting on a condition, and putting items into a queue.
2025-10-29 06:20:49 -07:00
Andrew Kelley
1382e41226 std.Io.Threaded: import std.Io.net 2025-10-29 06:20:49 -07:00
Andrew Kelley
2bcdde2985 compiler: update for introduction of std.Io
only thing remaining is using libc dns resolution when linking libc
2025-10-29 06:20:49 -07:00
Andrew Kelley
c2d1a339da std.fs.File: begrudgingly add back deprecated APIs
I'm not ready to rework MachO linker file access at the moment.
2025-10-29 06:20:49 -07:00
Andrew Kelley
79a59c5165 coff linker: don't check the time
compiler toolchains have no business knowing what time it is
2025-10-29 06:20:49 -07:00
Andrew Kelley
0732ff2263 std.Io.Threaded: implement connecting to unix sockets 2025-10-29 06:20:49 -07:00
Andrew Kelley
e8cea8accb std.Io.Threaded: implement netListenUnix 2025-10-29 06:20:49 -07:00
Andrew Kelley
d680b9e9b2 std.Io.File: add WouldBlock to the error set
Even in an asynchronous world, the concept of a non-blocking flag is
useful because it determines under what conditions the operation
completes.
2025-10-29 06:20:49 -07:00
Andrew Kelley
539808239e std.net: IPv6 parsing fixes 2025-10-29 06:20:49 -07:00
Andrew Kelley
d3f0c460ec std.Io.net.HostName: fix DNS resolution
* merge conflict with changing behavior of takeDelimiterExclusive
* check bounds before adding to result array
2025-10-29 06:20:49 -07:00
Andrew Kelley
923a7bdd7e std.Io.net: fix parsing IPv4-mapped IPv6 addresses 2025-10-29 06:20:49 -07:00
Andrew Kelley
e0e463bcf7 std.Io.net.Stream.Reader: fix not using buffer 2025-10-29 06:20:49 -07:00
Andrew Kelley
4d62f08393 add BRANCH_TODO file
to be deleted before merging into master
2025-10-29 06:20:49 -07:00
Andrew Kelley
be1ae430a1 std.Io.Threaded.netReadPosix: support cancelation 2025-10-29 06:20:49 -07:00
Andrew Kelley
71ff6e0ef7 std: fix seekBy unit test 2025-10-29 06:20:49 -07:00
Andrew Kelley
d40803284e progress towards compiler building again 2025-10-29 06:20:49 -07:00
Andrew Kelley
3b34622368 std.Io: add unix domain sockets API
note that "reuseaddr" does nothing for these
2025-10-29 06:20:49 -07:00
Andrew Kelley
9e681cab56 std.Uri: fix compilation error 2025-10-29 06:20:49 -07:00
Andrew Kelley
63801c4b05 std.crypto.Certificate.Bundle: remove use of File.readAll 2025-10-29 06:20:49 -07:00
Lukas Lalinsky
fcac8617b4 Add missing clobbers to context switching
This only shows in release mode, the compiler tries to preserve some
value in rdi, but that gets replaced inside the fiber. This would not
happen in the C calling convention, but in these normal Zig functions,
it can happen.
2025-10-29 06:20:49 -07:00
Andrew Kelley
7d478114ec fix compilation errors introduced by rebasing 2025-10-29 06:20:49 -07:00
Andrew Kelley
b1733b7bce std.Io: implement dirOpenFile 2025-10-29 06:20:49 -07:00
Andrew Kelley
8a1e6c8c39 std.Io: implement dirStatPath 2025-10-29 06:20:49 -07:00
Andrew Kelley
750b1431bf std: fix some Io compilation errors 2025-10-29 06:20:49 -07:00
Andrew Kelley
eadfefa002 std.Io: implement dirMake
In the future, it might be nice to introduce a type for file system path
names. This would be a way to avoid having InvalidFileName in the error
set, since construction of such type could validate it above the
interface.
2025-10-29 06:20:49 -07:00
Andrew Kelley
e85df854aa std.mem: improve containsAtLeastScalar implementation and rename 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
89412fda77 std.Io: implement fileStat 2025-10-29 06:20:48 -07:00
Andrew Kelley
69b54b0cd1 remove bad assert 2025-10-29 06:20:48 -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
b428612a20 WIP: hack away at std.Io return flight 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
Andrew Kelley
85a6fea3be std.Io.net.HostName: implement DNS name expansion 2025-10-29 06:20:48 -07:00
Andrew Kelley
f1a590c876 std.Io.net.HostName: implement DNS reply parsing 2025-10-29 06:20:48 -07:00
Andrew Kelley
62d0dd0d36 std.Io.Threaded.netReceive: recvmsg first, then poll
Calling recvmsg first means no poll syscall needed when messages are
already in the operating system queue. Empirically, this happens when
repeating a DNS query that has been already been made recently. In such
case, poll() is never called!
2025-10-29 06:20:48 -07:00
Andrew Kelley
a6347a68a9 std.Io.net: implement receiving connectionless messages 2025-10-29 06:20:48 -07:00
Andrew Kelley
961961cf85 std: fix msghdr and cmsghdr when using musl libc
glibc and linux kernel use size_t for some field lengths while POSIX and
musl use int. This bug would have caused breakage the first time someone
tried to call sendmsg on a 64-bit big endian system when linking musl
libc.

my opinion:
* msghdr.iovlen: kernel and glibc have it right. This field should
  definitely be size_t. With int, the padding bytes are wasted for no
  reason.
* msghdr.controllen: POSIX and musl have it right. 4 bytes is plenty for
  the length, and it saves 4 bytes next to flags.
* cmsghdr.len: POSIX and musl have it right. 4 bytes is plenty for the
  length, and it saves 4 bytes since the other fields are also 32-bits
  each.
2025-10-29 06:20:48 -07:00
Andrew Kelley
95dee2af9c std.Io: implement netSend 2025-10-29 06:20:48 -07:00
Andrew Kelley
bcb6760fa5 std.os.linux: remove unnecessary warnings from sendmmsg
The one about INT_MAX is self-evident from the type system.

The one about kernel having bad types doesn't seem accurate as I checked
the source code and it uses size_t for all the appropriate types,
matching the libc struct definition for msghdr and msghdr_const.
2025-10-29 06:20:48 -07:00
Andrew Kelley
3b80fde6f4 std.os.linux: remove sendmmsg workaround
This "fix" is too opinionated to belong here. Better instead to
document the pitfalls.
2025-10-29 06:20:48 -07:00
Andrew Kelley
cde5a51d0c std.Io.net: make netSend support multiple messages
this lowers to sendmmsg on linux, and means Io.Group is no longer
needed, resulting in a more efficient implementation.
2025-10-29 06:20:48 -07:00
Andrew Kelley
b22400271f std.Io.net.HostName: finish implementing DNS lookup 2025-10-29 06:20:48 -07:00
Andrew Kelley
2e1ab5d3f7 std.Io.Threaded: implement Group.cancel 2025-10-29 06:20:48 -07:00
Andrew Kelley
8e1da66ba1 std.Io: implement Group API 2025-10-29 06:20:48 -07:00
Andrew Kelley
5469db66e4 std.Thread.ResetEvent: make it more reusable 2025-10-29 06:20:48 -07:00
Andrew Kelley
f9d976a4e1 std.Io: rename asyncConcurrent to concurrent 2025-10-29 06:20:48 -07:00
Andrew Kelley
60c4bdb14c Io.net: implement more networking
the next task is now implementing Io.Group
2025-10-29 06:20:48 -07:00
Andrew Kelley
8771a9f082 std.Io.net: progress towards DNS resolution 2025-10-29 06:20:48 -07:00
Andrew Kelley
5782158628 std.net: fix parsing IPv6 addr "::" 2025-10-29 06:20:48 -07:00
Andrew Kelley
885b3f8342 Io.net: finish implementing IPv6 parsing 2025-10-29 06:20:48 -07:00
Andrew Kelley
e7c9df9fb0 Io.net: use resolve for IPv6
/etc/resolv.conf might have IPv6 addresses with scope in it, so this is
needed.
2025-10-29 06:20:48 -07:00
Andrew Kelley
d776a6bbbe Io.net: rework IPv6 parsing and printing
extract pure functional logic into pure functions and then layer the
scope crap on top properly

the formatting code incorrectly didn't do the reverse operation
(if_indextoname). fix that with some TODO panics
2025-10-29 06:20:48 -07:00
Andrew Kelley
5089352b86 std.Io: rename ThreadPool to Threaded 2025-10-29 06:20:48 -07:00
Andrew Kelley
0e9280ef1a std.Io: extract Dir to separate file 2025-10-29 06:20:48 -07:00
Andrew Kelley
fc1e3d5bc9 Io.net: partial implementation of dns lookup 2025-10-29 06:20:48 -07:00
Andrew Kelley
b4e5e9d48f Io.net: implement sortLookupResults 2025-10-29 06:20:48 -07:00
Andrew Kelley
e7729a7b89 std: start moving fs.File to Io 2025-10-29 06:20:48 -07:00
Andrew Kelley
bd3c65f752 std.Io.net: partially implement HostName.lookup 2025-10-29 06:20:48 -07:00
Andrew Kelley
668f905243 add some networking 2025-10-29 06:20:48 -07:00
Andrew Kelley
d801a71d29 add std.testing.io 2025-10-29 06:20:48 -07:00
Andrew Kelley
84d60404be std.Io: delete asyncParallel 2025-10-29 06:20:48 -07:00
Andrew Kelley
7ead86e339 std.Io: fix error handling and asyncParallel docs 2025-10-29 06:20:48 -07:00
Andrew Kelley
f762597724 std.Io: add asyncConcurrent and asyncParallel 2025-10-29 06:20:48 -07:00
Andrew Kelley
ec3e4c00c3 std.Io.EventLoop: add aarch64 support 2025-10-29 06:20:48 -07:00
Andrew Kelley
30be75ca40 std.Io.ThreadPool: fix asyncDetached 2025-10-29 06:20:48 -07:00
Andrew Kelley
f5d8492b1f std.Io: rename go to asyncDetached
it's a better name because it's more descriptive, not a reference, and
hints that it is less common than async
2025-10-29 06:20:48 -07:00
Andrew Kelley
14c3dc4c49 revert std.Thread.Pool for now
and move the Io impl to a separate file
2025-10-29 06:20:48 -07:00
Andrew Kelley
fd4dd3befb update to sync with master 2025-10-29 06:20:48 -07:00
Andrew Kelley
e1cbcecf89 Io: update for new linked list API 2025-10-29 06:20:48 -07:00
Andrew Kelley
4b657d2de5 std.Io: remove @ptrCast workarounds
thanks to d53cc5e5b2ac51793ea19a847d8cee409af1dee3
2025-10-29 06:20:48 -07:00
Andrew Kelley
c88b8e3c15 std.Io.EventLoop: implement select 2025-10-29 06:20:48 -07:00
Andrew Kelley
f158ec5530 Io.EventLoop: select stub 2025-10-29 06:20:48 -07:00
Andrew Kelley
7aa4062f5c introduce Io.select and implement it in thread pool 2025-10-29 06:20:48 -07:00
Jacob Young
c4fcf85c43 Io.Condition: implement full API 2025-10-29 06:20:48 -07:00
Jacob Young
3eb7be5cf6 EventLoop: implement detached fibers 2025-10-29 06:20:48 -07:00
Andrew Kelley
0f105a8a10 EventLoop: let the allocator do its job
to bucket and free fiber allocations
2025-10-29 06:20:48 -07:00
Jacob Young
08ce000276 EventLoop: fix std.Io.Condition implementation
1. a fiber can't put itself on a queue that allows it to be rescheduled
 2. allow the idle fiber to unlock a mutex held by another fiber by
    ignoring reschedule requests originating from the idle fiber
2025-10-29 06:20:48 -07:00
Jacob Young
e366b13a65 EventLoop: revert incorrect optimization 2025-10-29 06:20:48 -07:00
Andrew Kelley
4063205746 EventLoop: remove broken mechanism for making deinit block on detached 2025-10-29 06:20:48 -07:00
Andrew Kelley
929b616e0f std.Io.Condition: change primitive to support only one
and no timer
2025-10-29 06:20:48 -07:00
Andrew Kelley
8773b63241 EventLoop: take DetachedClosure into account when allocating 2025-10-29 06:20:48 -07:00
Andrew Kelley
266bcfbf2f EventLoop: implement detached async
data races on deinit tho
2025-10-29 06:20:48 -07:00
Jacob Young
f84aca36c3 Io: implement faster mutex 2025-10-29 06:20:48 -07:00
Andrew Kelley
a1c1d06b19 std.Io: add detached async 2025-10-29 06:20:48 -07:00
Andrew Kelley
0d4b358dd8 implement Mutex, Condition, and Queue 2025-10-29 06:20:48 -07:00
Jacob Young
08b609a79f Io: implement sleep and fix cancel bugs 2025-10-29 06:20:48 -07:00
Jacob Young
5041c9ad9c EventLoop: implement thread-local queues and cancellation 2025-10-29 06:20:48 -07:00
Andrew Kelley
e7caf3a54c std.Io: introduce cancellation 2025-10-29 06:20:47 -07:00
Andrew Kelley
a29b2122d2 better API for Io.async 2025-10-29 06:20:47 -07:00
Jacob Young
d958077203 EventLoop: fix futex usage
How silly of me to forget that the kernel doesn't implement its own API.
The scheduling is not great, but at least doesn't deadlock or hammer.
2025-10-29 06:20:47 -07:00
Jacob Young
db0dd3a480 EventLoop: get file operations working
Something is horribly wrong with scheduling, as can be seen in the
debug output, but at least it somehow manages to exit cleanly...
2025-10-29 06:20:47 -07:00
Andrew Kelley
238de05d2c WIP 2025-10-29 06:20:47 -07:00
Andrew Kelley
66b0f7e92b start adding fs functions to std.Io 2025-10-29 06:20:47 -07:00
Andrew Kelley
08bb7c6c88 free freeing wrong amount in thread pool impl 2025-10-29 06:20:47 -07:00
Jacob Young
1493c3b5f3 EventLoop: move context after the async closure
This avoids needing to store more sizes and alignments.  Only the result
alignment needs to be stored, because `Fiber` is at a fixed zero offset.
2025-10-29 06:20:47 -07:00
Jacob Young
29355ff21c EventLoop: fix incorrect alignment panic
When the previous fiber did not request to be registered as an awaiter,
it may not have actually been a full blown `Fiber`, so only create the
`Fiber` pointer when needed.
2025-10-29 06:20:47 -07:00
Andrew Kelley
4c7c0c4178 update threaded fibers impl to actually storing args
sorry, something still not working correctly
2025-10-29 06:20:47 -07:00
Andrew Kelley
31ed2d6715 fix context passing in threaded Io impl 2025-10-29 06:20:47 -07:00
Jacob Young
f1dd06b01f EventLoop: implement main idle fiber 2025-10-29 06:20:47 -07:00
Jacob Young
9d0f44f08a EventLoop: add threads 2025-10-29 06:20:47 -07:00
Jacob Young
629a20459d EventLoop: rewrite context switching 2025-10-29 06:20:47 -07:00
Jacob Young
fe6f1efde4 EventLoop: prepare for threading 2025-10-29 06:20:47 -07:00
Andrew Kelley
4d56267938 demo: single-threaded green threads implementation 2025-10-29 06:20:47 -07:00
Andrew Kelley
cb9f9bf58d make thread pool satisfy async/await interface 2025-10-29 06:20:47 -07:00
Andrew Kelley
21b7316772 introduce std.Io interface
which is planned to have all I/O operations in the interface, but for
now has only async and await.
2025-10-29 06:20:47 -07:00
Ryan Liptak
6568f0f75b
Merge pull request #25705 from squeek502/linked-list-remove-docs
Document that `remove` of Singly/DoublyLinkedList relies on the node being in the list
2025-10-29 05:11:58 -07:00
Alex Rønne Petersen
b409cdf63f
Elf2: set ELFOSABI_OPENBSD for openbsd 2025-10-29 07:48:42 +01:00
Alex Rønne Petersen
49b5b4b249
Elf2: set ELFOSABI_FREEBSD for ps4 2025-10-29 07:48:29 +01:00
Alex Rønne Petersen
7881a60f1a
std.Target.aarch64: updates for LLVM 21.1.5 2025-10-29 07:48:12 +01:00
Matthew Lugg
8907dc8a4f Zcu: use shortest reference trace
The logic for computing reference traces was unintentionally finding the
*longest* possible trace (approximately). I think I already tried to fix
this before, but misunderstood how my own code works. Here, we fix it
properly: by slightly reworking the logic to use one ArrayHashMap for
both the result and the traversal queue, we trivially get a proper
breadth-first traversal so that we can find the shortest possible
reference trace for every referenced unit.
2025-10-29 05:34:19 +00:00
Adrian
4e9dd099c5
std.heap.debug_allocator outdated doc (#25634)
Fixed a relatively small outdated doc string, referring to the bucket linked list.
2025-10-28 10:26:04 +01:00
Cooksey99
2cbd0d3f08 spirv: fix airWorkGroupSize to use workgroup_size builtin 2025-10-28 10:23:32 +01:00
Alex Rønne Petersen
06d9e3bc06
Merge pull request #25691 from GasInfinity-Forks/x86_16-gcc
feat: init x86_16 arch via CBE
2025-10-28 10:19:21 +01:00
Sean
35e1755c99
Fix stale reference bug in std.zig.system.resolveTargetQuery (#25713)
Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>
2025-10-28 10:17:09 +01:00
Alex Rønne Petersen
dba1bf9353 remove all Oracle Solaris support
There is no straightforward way for the Zig team to access the Solaris system
headers; to do this, one has to create an Oracle account, accept their EULA to
download the installer ISO, and finally install it on a machine or VM. We do not
have to jump through hoops like this for any other OS that we support, and no
one on the team has expressed willingness to do it.

As a result, we cannot audit any Solaris contributions to std.c or other
similarly sensitive parts of the standard library. The best we would be able to
do is assume that Solaris and illumos are 100% compatible with no way to verify
that assumption. But at that point, the solaris and illumos OS tags would be
functionally identical anyway.

For Solaris especially, any contributions that involve APIs introduced after the
OS was made closed-source would also be inherently more risky than equivalent
contributions for other proprietary OSs due to the case of Google LLC v. Oracle
America, Inc., wherein Oracle clearly demonstrated its willingness to pursue
legal action against entities that merely copy API declarations.

Finally, Oracle laid off most of the Solaris team in 2017; the OS has been in
maintenance mode since, presumably to be retired completely sometime in the 2030s.

For these reasons, this commit removes all Oracle Solaris support.

Anyone who still wishes to use Zig on Solaris can try their luck by simply using
illumos instead of solaris in target triples - chances are it'll work. But there
will be no effort from the Zig team to support this use case; we recommend that
people move to illumos instead.
2025-10-27 07:35:38 -07:00
GasInfinity
104c272ae5
feat: init x86_16 arch via CBE 2025-10-27 11:19:51 +01:00
GasInfinity
9d3bd3c502
feat: init 16-bit x86 support in zig.h 2025-10-27 11:19:08 +01:00
GasInfinity
55c0693c4a
fix: make compiler_rt and std.Io.Writer compile on 16-bit platforms. 2025-10-27 11:17:48 +01:00
GasInfinity
914acf13cb
chore: make std.zig.target.intByteSize return an u16 2025-10-27 11:13:25 +01:00
Alex Rønne Petersen
9161923405
Revert "std.Target: xtensa defaults to windowed ABI"
This reverts commit c55e83eab1369373fe6db5072802c2fc1c4d7ebc.

This was a misreading of XtensaFeatures.td on my part.
2025-10-27 06:09:33 +01:00
Alex Rønne Petersen
6b4f57a257
test: enable tsan standalone test for x86_64-freebsd and aarch64-freebsd 2025-10-26 11:12:46 +01:00
Rajiv Singh
fe783d9ff3
tsan: fix cross build for FreeBSD by using direct syscalls instead of libsys
This patch can hopefully be dropped in the future; see #24989.

closes #24885
closes #24896

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>
2025-10-26 11:12:22 +01:00
Alex Rønne Petersen
67c9d57e27
Compilation: define __illumos__ for C/C++ when targeting illumos
Per the illumos GCC fork.
2025-10-26 09:51:35 +01:00
Alex Rønne Petersen
c9e0df97f9 std.debug.cpu_context: fix mcontext alignment for x86_64-illumos
It contains a upad128_t array which increases its alignment.
2025-10-26 08:48:21 +01:00
Felipe Cardozo
0ec45050e0 docs: fix handle_error_with_catch_block typo 2025-10-26 05:37:28 +01:00
Ryan Liptak
63a45b8ecd SinglyLinkedList.remove docs: Assumes -> asserts
Removing a node that is not in the list invokes safety-checked illegal behavior, so "asserts" is the recommended language to use.
2025-10-25 21:28:54 -07:00
IOKG04
a83db33ba2 *LinkedList.remove() assumes node is in the list
probably closes https://github.com/ziglang/zig/issues/16795
2025-10-25 21:10:02 -07:00
Techatrix
bd1e960bc0 fix std.fs.path.resolveWindows on UNC paths with mixed path separators 2025-10-26 02:18:11 +02:00
Alex Rønne Petersen
433846100b
Merge pull request #25700 from alexrp/solaris-illumos-stuff
Some Solaris/illumos fixes
2025-10-26 00:59:33 +02:00
Ryan Zezeski
ece9640a3e
std.c: implement sigrtmin()/sigrtmax() for solaris/illumos 2025-10-25 12:44:17 +02:00
Ryan Zezeski
bd1332acae
std.c: define MSG constants for solaris/illumos 2025-10-25 12:44:17 +02:00
Ryan Zezeski
ac3e4f4519
std.c: define arc4random_buf() for illumos 2025-10-25 12:44:17 +02:00
Stephen Gregoratto
f4ef7e8761
std.debug.cpu_context: add missing signal_ucontext_t fields for x86_64-solaris/illumos 2025-10-25 12:44:17 +02:00
Alex Rønne Petersen
e39b82bf4e
compiler: avoid using self-hosted backend on x86_64-solaris/illumos
https://github.com/ziglang/zig/issues/25699
2025-10-25 12:44:13 +02:00
Alex Rønne Petersen
bebfdc3661 llvm: remove some workarounds in loadTruncate()
No longer needed with LLVM 21.
2025-10-25 04:52:46 +02:00
Alex Rønne Petersen
feb05a716d
std.heap: define page size for alpha-netbsd 2025-10-23 20:15:46 +02:00
Alex Rønne Petersen
70206af482
Merge pull request #25640 from alexrp/std-target-more-arches
`std.Target`: add tags and info for alpha, hppa, microblaze, sh + some bonus commits
2025-10-23 19:35:54 +02:00
Alex Rønne Petersen
07d764dc30
std.zig.system: handle alpha, hppa, microblaze, sh in getExternalExecutor() 2025-10-23 19:34:02 +02:00
Alex Rønne Petersen
d8cb8b7bae
std.debug: fix FP unwinding for hppa/hppa64 2025-10-23 19:34:02 +02:00
Alex Rønne Petersen
c13355abda
std.debug: fix FP unwind progress check for stackGrowth() == .up targets 2025-10-23 19:34:02 +02:00
Alex Rønne Petersen
a689c38197
std.debug: FP unwinding is impossible on alpha, microblaze, sh 2025-10-23 19:34:02 +02:00
Alex Rønne Petersen
d99cf5061c
std.debug.cpu_context: add signal_ucontext_t for alpha, hppa, microblaze, sh 2025-10-23 19:34:02 +02:00
Alex Rønne Petersen
23b299056d
std.heap: define page size for hppa, sh on NetBSD 2025-10-23 19:34:02 +02:00
Alex Rønne Petersen
a03b924e74
std.heap: define page size for alpha, hppa, sh on OpenBSD 2025-10-23 19:34:02 +02:00
Alex Rønne Petersen
7eda0b5724
std.heap: define page size for alpha, hppa, microblaze, sh on Linux 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
3c5502ed8d
std.atomic: define cache line size for alpha, hppa, microblaze, sh 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
493889d5eb
std.Thread: implement freeAndExit() for sh-linux 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
3777d3c25b
std.Thread: implement freeAndExit() for microblaze-linux 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
f6c06d7069
std.Thread: implement freeAndExit() for hppa-linux 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
de87c856e7
std.Thread: implement freeAndExit() for alpha-linux 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
3d1b7811d4
std.Thread: implement freeAndExit() for m68k-linux 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
f723d69a58
std.os.linux.tls: add hppa support
Turns out Linux on PA-RISC does system calls in a pretty fascinating way; see
arch/parisc/kernel/syscall.S for details.
2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
aff557e4e8
std.os.linux.tls: add sh support 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
5e921261a0
std.os.linux.tls: add microblaze support
Implemented according to glibc because I'm pretty sure musl gets it wrong.
2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
9fde44229c
std.os.linux.tls: add alpha support 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
2b54437f24
std.pie: add sh support 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
fb2c02929e
std.pie: add microblaze support 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
fc48f8aa55
std.pie: add alpha support 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
4193ea8239
std.start: add sh support 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
c792ebfee2
std.start: add microblaze support 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
252e1fd7ec
std.start: add alpha support 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
340d6ce1bf
std.builtin: move AddressSpace.Context to std.Target.AddressSpaceContext
This type has nothing to do with the language.
2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
af1d777b27
std.builtin: add CallingConvention.sh_interrupt
Only supported in CBE.
2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
4fa453ce20
std.builtin: add CallingConvention.microblaze_interrupt
Only supported in CBE.
2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
abf40caeb7
std.builtin: add CallingConvention.msp430_interrupt
Supported by LLVM and CBE.
2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
beb507a1ed
std.builtin: add CallingConvention.x86_64_x32
This was forgotten during the refactoring of std.builtin.CallingConvention. It
mirrors mips64_n32 for MIPS.
2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
a1441943e4
std.Target: add stackGrowth() function 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
ee72f06f47
std.Target: add tags and info for alpha, hppa, microblaze, sh 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
c55e83eab1
std.Target: xtensa defaults to windowed ABI 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
3e2daa509a
std.Target: add arceb and xtensaeb Cpu.Arch tags 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
dda05b29c0
std.Target: fix cMaxIntAlignment() for a few architectures 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
45b80f2e41
std.Target: fix cTypePreferredAlignment() for arc 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
862e674758
std.Target: remove bogus hosted avr/msp430 prongs in cTypeBitSize()
These are microcontroller architectures; none of the OSs in the outer switch
run on them.
2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
cd56b06352
Zcu: simplify atomicPtrAlignment()
The value being computed here is almost always equal to the pointer bit width.
2025-10-23 09:27:16 +02:00
Alex Rønne Petersen
ae789fa50a
test: enable dynamic hexagon-linux-musl with -Dtest-extra-targets 2025-10-23 09:27:16 +02:00
Alex Rønne Petersen
022dcbc37a
std.Target.DynamicLinker: recognize standard hexagon-linux-musl path 2025-10-23 09:27:16 +02:00
Alex Rønne Petersen
a7f085f0d7
std.Target: fix cCallingConvention() to pick mips64_n32 for muslabin32 2025-10-23 09:27:16 +02:00
jonascloud
e5fcc8192d spir-v: Fix .storage_buffer pointer indexing
Renames arePointersLogical to shouldBlockPointerOps for clarity
adds capability check to allow pointer ops on .storage_buffer when
variable_pointers capability is enabled.

Fixes #25638
2025-10-23 03:21:15 +02:00
Alex Rønne Petersen
93d54cb866 std.Target: bump min-max versions for OpenBSD from 7.6-7.7 to 7.7-7.8
https://cdn.openbsd.org/pub/OpenBSD/7.8/ANNOUNCEMENT
2025-10-23 03:21:06 +02:00
Alex Rønne Petersen
0e15b2ac10
std.Target: handle some more cases in toCoffMachine() 2025-10-22 17:28:19 +02:00
Alex Rønne Petersen
362a44a122
std.Target: better Abi.default() behavior for arc and xtensa 2025-10-22 17:28:19 +02:00
Alex Rønne Petersen
e8d060e5f5
std.Target: update lists of omitted LLVM tags 2025-10-22 17:28:19 +02:00
Justus Klausecker
a027fa8b8c std.mem.Allocator: fix resize doc comment 2025-10-22 11:41:16 +02:00
Wim de With
8d4b5662cd std.{c,posix}: add getgid and getegid 2025-10-21 06:10:41 +02:00
Alex Rønne Petersen
dbf9c7b548 compiler: add support for arc_interrupt calling convention
Only for use with the C backend at the moment.
2025-10-19 22:27:19 +02:00
Wim de With
49eea79ec2 std.os.linux: add pivot_root syscall 2025-10-19 22:24:24 +02:00
Wim de With
5442e06632 std.os.linux: add setns syscall 2025-10-19 22:24:24 +02:00
Alex Rønne Petersen
031b0d6063 glibc: change library link order to prefer libc.so symbols
Also avoid resolving symbols in libraries that were later removed if possible.

closes #24347
2025-10-19 11:50:32 +02:00
Alex Rønne Petersen
328b121240
Merge pull request #25627 from alexrp/qemu-10.1.1-patched
`ci`: switch to patched QEMU 10.1.1.1
2025-10-19 11:50:23 +02:00
Alex Rønne Petersen
38caa4902f
Merge pull request #25623 from alexrp/or1k
Add `or1k-linux` support (via CBE)
2025-10-19 11:50:06 +02:00
Alex Rønne Petersen
c37d23f45a
delete file accidentally added in 6de339d5d3deb4c7a1585288888f8e788e489eb6 2025-10-19 02:02:19 +02:00
Bingwu Zhang
6de339d5d3 cbe: fix MIPS register names in inline assembly
Zig uses "rN" for MIPS register clobbers which are more
ergonomic and easier to write (.rN vs. .@"$N").
However, GCC and Clang uses "$N".

Bug: #25613
Signed-off-by: Bingwu Zhang <xtex@xtexx.eu.org>
2025-10-19 01:07:51 +02:00
GasInfinity
1bca158c6e fix(std): don't add the default _start and panic in homebrew targets
* even if std supported those targets, they're not posixy to be in that codepath.
2025-10-18 23:54:27 +02:00
Alex Rønne Petersen
08014589e2
std.atomic: define cache line size for or1k 2025-10-18 22:27:35 +02:00
Alex Rønne Petersen
49cd0e6f7c
std.debug: fix frame pointer unwinding on or1k 2025-10-18 22:27:35 +02:00
Alex Rønne Petersen
5e57ed9fda
std.Thread: implement freeAndExit() for or1k 2025-10-18 22:27:35 +02:00
Alex Rønne Petersen
562b88f7b1
std.heap: define min/max page size for or1k-linux 2025-10-18 22:27:35 +02:00
Alex Rønne Petersen
c571840e71
std.os.linux: add or1k arch bits 2025-10-18 22:27:35 +02:00
Alex Rønne Petersen
35e819aac8
std.os.linux.tls: implement or1k support 2025-10-18 22:27:35 +02:00
Alex Rønne Petersen
e646c47f67
std.pie: add or1k support 2025-10-18 22:27:34 +02:00
Alex Rønne Petersen
2d5cdfcfc2
std.start: align stack pointer according to ARC v3 ABI 2025-10-18 22:26:52 +02:00
Alex Rønne Petersen
0d2d51dd8c
std.start: add or1k support 2025-10-18 22:26:52 +02:00
Alex Rønne Petersen
afc6e88413
zig.h: add or1k support 2025-10-18 22:26:52 +02:00
Alex Rønne Petersen
489ce7f44e
Sema: or1k_sysv calling convention supports varargs 2025-10-18 22:26:52 +02:00
Alex Rønne Petersen
6bf5b7f2b4
Merge pull request #25622 from alexrp/inline-asm-fixes
`std`: some miscellaneous inline asm fixes for mips, mips64, mipsn32, and x32
2025-10-18 22:26:09 +02:00
Alex Rønne Petersen
653a191965
Revert "std.Thread: disable test on armeb in addition to thumbeb"
This reverts commit a73f246b2963de0024b9b7070448862e855d5a04.
2025-10-18 20:50:19 +02:00
Alex Rønne Petersen
1466401c15
Merge pull request #25614 from squeek502/windows-rename-delete
windows: Always try using POSIX_SEMANTICS/etc for rename/delete
2025-10-18 20:45:22 +02:00
Alex Rønne Petersen
e9e0526cf8
ci: switch to patched QEMU 10.1.1.1
https://github.com/ziglang/qemu-static/releases/tag/10.1.1.1
2025-10-18 17:11:44 +02:00
Alex Rønne Petersen
3585f79f44
std.os.linux: remove syscall7() on mips64/mipsn32
I'm not sure why this was here, but this is only a thing on O32, not N32/N64.
2025-10-18 14:01:41 +02:00
Alex Rønne Petersen
5e3c313366
std.pie: fix getDynamicSymbol() for mipsn32 2025-10-18 12:13:41 +02:00
Alex Rønne Petersen
2305527342
std.start: fix _start for mipsn32
This is more similar to O32 than N64.
2025-10-18 12:11:27 +02:00
Alex Rønne Petersen
adcfdce6be
std.Thread: fix some issues in x86_64/x32 inline asm
Wrong syscall on x32; return exit code 0 instead of 1 on both.

ref https://github.com/ziglang/zig/issues/22189
2025-10-18 11:36:26 +02:00
Alex Rønne Petersen
e59f2995a5
std.Thread: fix inline asm for mipsn32
This was using the mips64 syscalls.

ref https://github.com/ziglang/zig/issues/22189
2025-10-18 11:36:02 +02:00
Alex Rønne Petersen
842de66db8
std.os.linux: fix some issues in x32 inline asm
ref https://github.com/ziglang/zig/issues/22189
2025-10-18 11:16:31 +02:00
Alex Rønne Petersen
f3eacec226
std.os.linux: fix some issues in mipsn32 inline asm
ref https://github.com/ziglang/zig/issues/22189
2025-10-18 11:16:31 +02:00
Alex Rønne Petersen
b8d776928a
std: make all MIPS inline asm safe for MIPS I
MIPS I has load hazards so we need to insert nops in a few places. This is not a
problem for MIPS II and later.

While doing this, I also touched up all the inline asm to use ABI register
aliases and a consistent formatting convention. Also fixed a few places that
didn't properly check if the syscall return value should be negated.
2025-10-18 11:16:31 +02:00
Alex Rønne Petersen
f3da54f53c std.Target: move Cpu.supportsAddressSpace() up to here
This allows us to rule out support for certain address spaces based on the OS.
This commit is just a refactor, however, and doesn't actually make use of that
opportunity yet.
2025-10-18 11:13:28 +02:00
Alex Rønne Petersen
631915ad96
Merge pull request #25600 from alexrp/std-debug-more-arches
`std.debug`: add CPU contexts and DWARF mappings for more architectures
2025-10-18 11:12:56 +02:00
Matthew Lugg
35d0790514
Merge pull request #25029 from mlugg/unit-test-timing
build system: unit test enhancements

Contributes towards https://github.com/ziglang/zig/issues/19821, but does not close it, since the timeout currently cannot be modified per unit test.
2025-10-18 09:36:32 +01:00
Matthew Lugg
8f86ed78da
ci: final bump to all unit test timeouts
The last commit passed CI, so this final bump is just to allow for
deviation caused by different loads on the runner machines. With this
change, I don't expect any current unit test to ever time out, even when
CI is under extreme load.
2025-10-18 09:32:49 +01:00
Matthew Lugg
3d0009b9c6
ci: bump test timeouts to stupid numbers on Windows
Unfortunately, Windows' scheduler means that test timeouts get hit very
easily, because it seems the system can refuse to schedule a waiting
process for *upwards of 10 minutes*. We should look for a better
solution for this problem going forwards, but for now, just give Windows
a very high test timeout.

The 30 minute timeout set here is around the duration of a *full CI run*
on Windows, so it should be impossible to hit normally, but it means
that if a test gets stuck we'll at least get told (eventually).
2025-10-18 09:28:44 +01:00
Matthew Lugg
f4315a0a57
ci: bump unit test timeouts
i am in purgatory as a punishment bestowed upon me for daring to
question the sanctity of windows' scheduler
2025-10-18 09:28:44 +01: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
Matthew Lugg
db8330adaf
ci: add unit test timeouts to loongarch and x86_64-freebsd 2025-10-18 09:28:43 +01:00
Matthew Lugg
1881ee4587
std: split up ecdsa tests 2025-10-18 09:28:43 +01:00
Frank Denis
e77a7c5c45
crypto.ecdsa: trim the number of tests we perform
The Wycheproof test suite is extensive, but takes a long time to
complete on CI.

Keep only the most relevant ones and take it as an opportunity to describe
what they are.

The remaining ones are still available for manual testing when required.
2025-10-18 09:28:43 +01:00
mlugg
a7251e4191
ci: bump unit test timeouts 2025-10-18 09:28:43 +01:00
mlugg
b866c14328
std: make RwLock test less intensive
This test called `yield` 80,000 times, which is nothing on a system with
little load, but murder on a CI system. macOS' scheduler in particular
doesn't seem to deal with this very well. The `yield` calls also weren't
even necessarily doing what they were meant to: if the optimizer could
figure out that it doesn't clobber some memory, then it could happily
reorder around the `yield`s anyway!

The test has been simplified and made to work better, and the number of
yields have been reduced. The number of overall iterations has also been
reduced, because with the `yield` calls making races very likely, we
don't really need to run too many iterations to be confident that the
implementation is race-free.
2025-10-18 09:28:43 +01:00
mlugg
7a5d2a196f
tweak tests to avoid timeouts 2025-10-18 09:28:42 +01:00
mlugg
d0b92a8022
std.Build: do not expect server protocol for tests using immature backends
For instance, when running a Zig test using the self-hosted aarch64
backend, this logic was previously expecting `std.zig.Server` to be
used, but the default test runner intentionally does not do this because
the backend is too immature to handle it. On 'master', this is causing
sporadic failures; on this branch, they became consistent failures.
2025-10-18 09:28:42 +01:00
mlugg
b43bb3a32a
ci: set unit test timeouts 2025-10-18 09:28:42 +01:00
mlugg
263e7fe87a
build runner: final tweaks to output 2025-10-18 09:28:42 +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
Jon Parise
337762114f std.Uri: test file URIs without an authority field
Some environments (such as KDE) form file URIs without an authority
field (e.g. file:/etc/fstab). Also test this case for completeness.
2025-10-17 17:40:25 -07:00
Brandon Black
d18f1dde41 os.linux.timeval: use same field names as std.c
Otherwise, the field names in std.posix.timeval vary by target os.
I think this was an accidental change during the work of #25610
2025-10-18 01:51:44 +02:00
Alex Rønne Petersen
798f6b85e3
Merge pull request #25617 from alexrp/libcxx-libunwind-backports
`libcxx`, `libunwind`: backport llvm/llvm-project#162867, llvm/llvm-project#160182, llvm/llvm-project#158347
2025-10-18 00:37:37 +02:00
Alex Rønne Petersen
9fd7f38600
std.debug.cpu_context.Sparc: fix bad use of call delay slot 2025-10-18 00:36:52 +02:00
Alex Rønne Petersen
727942bc03
std.debug.cpu_context: let the compiler deal with clobbers
Otherwise we might be restoring registers we don't even need to.
2025-10-18 00:36:52 +02:00
Alex Rønne Petersen
1f15e265fe
std.debug.cpu_context: sort context decls according to switch prongs (NFC) 2025-10-18 00:36:52 +02:00
Alex Rønne Petersen
4c81a496e7
std.debug: add CPU context and DWARF mappings for arc 2025-10-18 00:36:52 +02:00
Alex Rønne Petersen
ba9ab3fb67
std.debug: add CPU context and DWARF mappings for m68k 2025-10-18 00:36:52 +02:00
Alex Rønne Petersen
eb36a45ed9
std.debug: add CPU context and DWARF mappings for or1k 2025-10-18 00:36:52 +02:00
Alex Rønne Petersen
de3947608c
std.debug: add CPU context and DWARF mappings for csky 2025-10-18 00:36:52 +02:00
Alex Rønne Petersen
81fe640dd2
std.debug: add CPU context and DWARF mappings for lanai 2025-10-18 00:36:52 +02:00
Alex Rønne Petersen
0b55393a2f
std.debug: add CPU context and DWARF mappings for ve 2025-10-18 00:36:52 +02:00
Alex Rønne Petersen
2eca0e42e5
std.debug: FP-based unwinding is impossible on avr, csky, msp430, and xcore
The ABIs do not define a frame pointer register, nor do they define a guaranteed
and fixed area on the stack where one might find saved registers such as a frame
pointer or return address.
2025-10-18 00:36:52 +02:00
Ryan Liptak
2ab0ca13bb langref: Bump 0.15.1 to 0.15.2 2025-10-17 15:03:51 +02:00
Alex Rønne Petersen
751375f3ca
libcxx: backport llvm/llvm-project#158347
https://github.com/llvm/llvm-project/pull/158347
2025-10-17 15:02:04 +02:00
Alex Rønne Petersen
2357ae06dd
libcxx: backport llvm/llvm-project#160182
https://github.com/llvm/llvm-project/pull/160182
2025-10-17 15:02:04 +02:00
Alex Rønne Petersen
671428359e
libunwind: backport llvm/llvm-project#162867
https://github.com/llvm/llvm-project/pull/162867
2025-10-17 15:02:02 +02:00
Alex Rønne Petersen
1f8a72175b
Merge pull request #25610 from alexrp/std-os-linux-cleanup
`std.os.linux`: some miscellaneous cleanup in arch bits
2025-10-17 12:07:51 +02:00
Alex Rønne Petersen
3091efaa18
Merge pull request #25609 from alexrp/test-targets
`test`: put some niche targets behind `-Dtest-extra-targets`
2025-10-17 10:53:46 +02:00
Alex Rønne Petersen
54b5087760
Merge pull request #25607 from alexrp/hexagon
Some `hexagon-linux` fixes + enable std tests in CI
2025-10-17 10:48:35 +02:00
Ryan Liptak
88fd8ce860 windows: Always try using POSIX_SEMANTICS/etc for rename/delete
The compile-time check against the minimum version here wasn't appropriate, since it still makes sense to try using FILE_RENAME_INFORMATION_EX even if the minimum version is something like `xp`, since that doesn't rule out the possibility of the compiled code running on Windows 10/11. This compile-time check was doubly bad since the default minimum windows version (`.win10`) was below the `.win10_rs5` that was checked for, so when providing a target like `x86_64-windows-gnu` it'd always rule out using this syscall.

After this commit, we always try using FILE_RENAME_INFORMATION_EX and then let the operating system tell us when some aspect of it is not supported. This allows us to get the benefits of these new syscalls/flags whenever it's actually possible.

The possible error returns were validated experimentally:
- INVALID_PARAMETER is returned when the underlying filesystem is FAT32
- INVALID_INFO_CLASS is returned on Windows 7 when trying to use FileRenameInformationEx/FileDispositionInformationEx
- NOT_SUPPORTED is returned on Windows 10 >= .win10_rs5 when setting a bogus flag value (I used `0x1000`)
2025-10-17 00:50:16 -07:00
Ryan Liptak
3eb3fbec9c windows: make FILE_DISPOSITION_ constants pub 2025-10-17 00:40:17 -07:00
Alex Rønne Petersen
29fb9e4da7
std.os.linux.tls: don't unnecessarily use std.posix 2025-10-17 02:46:47 +02:00
Alex Rønne Petersen
9ae8c48fdf
test: put soft float powerpc targets behind -Dtest-extra-targets 2025-10-17 02:15:48 +02:00
Alex Rønne Petersen
7215249aa9
test: put all n32 and x32 targets behind -Dtest-extra-targets 2025-10-17 02:13:31 +02:00
Alex Rønne Petersen
ca2da421dd
test: put all dynamic musl targets behind -Dtest-extra-targets 2025-10-17 02:03:02 +02:00
Alex Rønne Petersen
d5481e6536
std.os.linux: add incomplete x32 arch bits file
This is very likely full of wrong stuff. It's effectively just a copy of the
x86_64 file - needed because the former stopped using usize/isize. To be clear,
this is no more broken than the old situation was; this just makes the
brokenness explicit.
2025-10-17 01:20:33 +02:00
Alex Rønne Petersen
502eca7b09
std.os.linux: add incomplete mipsn32 arch bits file
This is very likely full of wrong stuff. It's effectively just a copy of the
mips64 file - needed because the former stopped using usize/isize. To be clear,
this is no more broken than the old situation was; this just makes the
brokenness explicit.
2025-10-17 01:20:33 +02:00
Alex Rønne Petersen
aa8e53908a
std.os.linux: clean up a bunch of dead consts 2025-10-17 01:20:33 +02:00
Alex Rønne Petersen
dc1bc52dd6
std.os.linux: retranslate F_* constants and Flock struct, and move out of arch bits
Flock is now equivalent to struct flock64, and the related F.* constants map to
the 64-bit variants on 32-bit systems.
2025-10-17 01:20:33 +02:00
Alex Rønne Petersen
cfdc0f0e34
std.os.linux: replace usize/isize in arch bits with fixed types for clarity 2025-10-17 01:20:33 +02:00
Alex Rønne Petersen
fc7a5f2ae4
std.os.linux: move some generic decls out of the arch bits 2025-10-17 01:20:31 +02:00
Alex Rønne Petersen
8970d80355
std.os.linux.thumb: remove some @setRuntimeSafety(false) with no clear purpose 2025-10-16 23:17:25 +02:00
Alex Rønne Petersen
d84faceebd
std.os.linux: remove some pointless asm clobbers in naked fns 2025-10-16 23:15:23 +02:00
Alex Rønne Petersen
92b555a4ed
test: enable std tests for hexagon 2025-10-16 22:13:10 +02:00
Alex Rønne Petersen
05b52da15e
std.os.linux: fix a bunch of syscall and time ABI issues on hexagon
I'm not particularly happy with sprinkling this check everywhere, but the
situation should improve once we complete the time64 migration.
2025-10-16 22:12:42 +02:00
Alex Rønne Petersen
3b5376eff5
std: disable a few failing tests on hexagon 2025-10-16 22:11:51 +02:00
xdBronch
f785e4745d detect invalid @bitCast with arrays 2025-10-16 19:36:11 +01:00
bnuuydev
173f497e29 llvm-backend: fix uefi data layout
the old logic caused the uefi case to fall through which caused an
assertion assertion in llvm to fail, as the data layout was wrong.
2025-10-16 13:59:02 +02:00
Alex Rønne Petersen
48f8133bea
Merge pull request #25569 from alexrp/std-debug-sparc
`std.debug`: implement `sparc*-linux` unwinding
2025-10-16 10:14:05 +02:00
Alex Rønne Petersen
493ad58ff7
Revert "ci: enable running libc-test on x86_64-linux-release"
This reverts commit fcfdf99122b17a928c144c3d70418b35e6b1620e.

This added too much load to the x86_64-linux machines, resulting in timeouts
pretty much across the board.
2025-10-15 21:30:25 +02:00
Frank Denis
6669885aa2
Faster BLAKE3 implementation (#25574)
This is a rewrite of the BLAKE3 implementation, with vectorization.

On Apple Silicon, the new implementation is about twice as fast as the previous one.

With AVX2, it is more than 4 times faster.

With AVX512, it is more than 7.5x faster than the previous implementation (from 678 MB/s to 5086 MB/s).
2025-10-15 14:03:56 +02:00
Alex Rønne Petersen
e0f10da270
std.debug: FP-based unwinding is ideal on SPARC
The way SPARC works due to its ABI built around register windows means that we
can always do fast FP-based unwinding.
2025-10-15 13:59:17 +02:00
Alex Rønne Petersen
dd7819220a
std.debug: fix return addresses being off on SPARC
The return address points to the call instruction on SPARC, so the actual return
address is 8 bytes after. This means that we shouldn't do the return address
adjustment that we normally do.
2025-10-15 13:59:17 +02:00
Alex Rønne Petersen
912fed3380
std.debug: use the SP as the initial FP on SPARC
The FP would point to the register save area for the previous frame, while the
SP points to the register save area for the current frame. So use the latter.
2025-10-15 13:59:17 +02:00
Alex Rønne Petersen
6de2d61a0c
std.debug: work around latest SPARC register window not being spilled on signal
I have no idea if this is a QEMU bug or real kernel behavior. Either way, the
register save area specifically exists for asynchronous spilling of incoming and
local registers, so there should be no harm in doing this.
2025-10-15 13:59:17 +02:00
Alex Rønne Petersen
78bc5d46e0
std.debug: the SPARC stack bias is only used on the 64-bit ABI 2025-10-15 13:59:17 +02:00
Alex Rønne Petersen
ebc0b90eb7
std.debug: rename some constants for clarity 2025-10-15 13:59:17 +02:00
Alex Rønne Petersen
62a8cfd5fe
std.debug: fix an invalid read in StackIterator.next()
We're overwriting the memory that unwind_context sits in, so we need to do the
getFp() call earlier.
2025-10-15 13:59:17 +02:00
Alex Rønne Petersen
a36dab2f90
std.debug.Dwarf: add SPARC register number mappings 2025-10-15 13:59:17 +02:00
Alex Rønne Petersen
b2732645b7
std.debug.cpu_context: add sparc*-linux context conversion support
It's not really a ucontext_t at all. Lovely stuff.
2025-10-15 13:59:17 +02:00
Alex Rønne Petersen
b8dd40fde8
std.debug.cpu_context.Sparc: flush register windows in current()
It's better to do this here than in StackIterator.init() so that
std.debug.cpu_context.Native.current() isn't a footgun on SPARC.
2025-10-15 13:59:17 +02:00
Alex Rønne Petersen
12b1d57df1
std.debug.cpu_context: add Sparc context 2025-10-15 13:59:17 +02:00
Alex Rønne Petersen
3d3aff0da9
std.debug: flush SPARC register windows from a new window
flushw and ta 3 flush all windows *except* the current one. So we need to do
this in a new register window to get all of the ones we care about.
2025-10-15 13:59:17 +02:00
Alex Rønne Petersen
f21a78b5a3
std.debug.SelfInfo.Elf: don't support DWARF unwinding for Hexagon and PowerPC
As for SPARC, FP-based unwinding is superior on these.
2025-10-15 13:59:17 +02:00
Alex Rønne Petersen
0ace906477
std.os.windows.CONTEXT: add sp field to getRegs() result for x86 2025-10-15 13:59:17 +02:00
Alex Rønne Petersen
70c21fdbab
libc-test: disable utime.c
Fails under heavy load in CI; futimens() effects aren't reflected in the
subsequent fstat() call for some reason.
2025-10-15 10:58:30 +02:00
Jacob Young
cc3c4d1069 windows: workaround kernel race condition in more places 2025-10-14 23:16:36 -04:00
Alex Rønne Petersen
595cd8935a ci: update to QEMU 10.1.1 2025-10-15 01:33:52 +02:00
Alex Rønne Petersen
27a396db4f
Merge pull request #25572 from alexrp/libcxx-backports
`libcxx`: backport llvm/llvm-project#155476, llvm/llvm-project#147389, llvm/llvm-project#155786
2025-10-15 00:24:35 +02:00
Alex Rønne Petersen
4edebf40d5
Merge pull request #25402 from alexrp/libc-test-ci
`ci`: enable running libc-test on `x86_64-linux-release`
2025-10-14 21:29:57 +02:00
Alex Rønne Petersen
c8b34bc8a3 libunwind: backport llvm/llvm-project#152942
https://github.com/llvm/llvm-project/pull/152942
2025-10-14 19:56:07 +02:00
Alex Rønne Petersen
b34a13da38 std.os.linux.sparc64: use icc instead of xcc in asm clobbers
LLVM currently doesn't recognize xcc; icc does what we want.
2025-10-14 16:56:44 +02:00
Alex Rønne Petersen
bc58b5dc53
libcxx: backport llvm/llvm-project#155786
https://github.com/llvm/llvm-project/pull/155786
2025-10-14 12:10:41 +02:00
Alex Rønne Petersen
10ea69912f
libcxx: backport llvm/llvm-project#147389
https://github.com/llvm/llvm-project/pull/147389
2025-10-14 12:07:43 +02:00
Alex Rønne Petersen
820dc9d767
libcxx: backport llvm/llvm-project#155476
https://github.com/llvm/llvm-project/pull/155476
2025-10-14 12:04:57 +02:00
aarvay
2f3234c76a
std.crypto: add AES-CCM and CBC-MAC (#25526)
* std.crypto: add AES-CCM and CBC-MAC

Add AES-CCM (Counter with CBC-MAC) authenticated encryption and
CBC-MAC message authentication code implementations to the standard
library.

AES-CCM combines CTR mode encryption with CBC-MAC authentication as
specified in NIST SP 800-38C and RFC 3610. It provides authenticated
encryption with support for additional authenticated data (AAD).

CBC-MAC is a simple MAC construction used internally by CCM, specified
in FIPS 113 and ISO/IEC 9797-1.

Includes comprehensive test vectors from RFC 3610 and NIST SP 800-38C.

* std.crypto: add CCM* (encryption-only) support to AES-CCM

Implements CCM* mode per IEEE 802.15.4 specification, extending
AES-CCM to support encryption-only mode when tag_len=0. This is
required by protocols like ZigBee, Thread, and WirelessHART.

Changes:
- Allow tag_len=0 for encryption-only mode (no authentication)
- Skip CBC-MAC computation when tag_len=0 in encrypt/decrypt
- Correctly encode M'=0 in B0 block for CCM* mode
- Add Aes128Ccm0 and Aes256Ccm0 convenience instances
- Add IEEE 802.15.4 test vectors and CCM* tests

* std.crypto: add doc comments for AES-CCM variants
2025-10-14 12:00:44 +02:00
Jacob Young
958faa7031 windows: workaround kernel race condition the most 2025-10-12 13:55:57 -04:00
Alex Rønne Petersen
ea694bfdb7 std.debug.cpu_context: consider arm and aarch64 reserved register ranges unsupported
If these ever get allocated, it's most likely going to be for things that don't
matter to us anyway, so completely abandoning DWARF unwinding just because we
see these doesn't seem justified. We will still do so if we're actually asked to
read from such a register, which is the only actually problematic case; see
c23a5ccd19 for more details.
2025-10-12 12:59:06 +02:00
Alex Rønne Petersen
9b4f2b40e3 musl: avoid r0 as address register in s390x __tls_get_offset
https://www.openwall.com/lists/musl/2025/10/12/4

See also 7b92d5f4052be651e9bc5cd4ad78a69ccbee865d...
2025-10-12 11:38:43 +02:00
Fri3dNstuff
87c18945c2
std.ArrayList: swapRemove set removed element to undefined (#25514) 2025-10-11 19:04:32 -07:00
Jacob Young
95242cc431 windows: workaround kernel race condition even more 2025-10-11 12:17:39 -04:00
Jacob Young
8efcfeaf1e windows: workaround kernel race condition better
Until I can do more testing, we bump the numbers until morale improves.
2025-10-11 10:01:17 -04:00
mlugg
923ddd94a1
std.posix: panic on unexpected error in munmap
This is to help diagnose #25498. We can't use `unexpectedErrno` here,
because `std.posix.munmap` is infallible. So, when the flag is set to
report unexpected errnos, we just call `std.debug.panic` to provide
details instead of doing `unreachable`.

Pushing straight to master after running checks locally; there's no
point waiting for CI on the PR just for this.
2025-10-11 11:46:30 +01:00
Jacob Young
2e31077fe0 Coff: implement threadlocal variables 2025-10-10 22:47:47 -07:00
Jacob Young
b2bc6073c8 windows: workaround kernel race condition
This was causing flaky CI failures.
2025-10-10 22:47:36 -07:00
Andrew Kelley
c17e18647b
Merge pull request #25495 from kcbanner/fixup_translate_c
Add error bundle support to `translate-c`, unify `cmdTranslateC` and `cImport`
2025-10-10 21:07:20 -07:00
Alex Rønne Petersen
66193e72d3
test: disable test-link macho on FreeBSD
See also d6d1fef.

https://github.com/ziglang/zig/issues/25323
2025-10-11 00:40:42 +02:00
usebeforefree
62e3d46287 replaced https://simonsapin.github.io/wtf-8/ with https://wtf-8.codeberg.page/ 2025-10-10 23:53:00 +02:00
mlugg
45143c6f04 MachO: emit absolute path in N_OSO stabs
This path being relative is unconventional and causes issues for us
if the output artifact is ever used from a different cwd than the one it
was built from. The behavior implemented by this commit of always
emitting these paths as absolute was actually the behavior in 0.14.x,
but it regressed in 0.15.1 due to internal reworks to path handling
which led to relative paths being more common in the compiler internals.

Resolves: #25433
2025-10-10 20:33:30 +01:00
Ryan Liptak
d629a146f5 Dir.realpathW: remove redundant buffer/copy
This same change was applied in 69007f096177143086e28da0dc1a0eff4efcc52c but accidentally reverted in 7bf740ee718f4b6109cd9fe7014d1784d48ada48
2025-10-10 12:13:35 -07:00
Alex Rønne Petersen
9aeabad519 std.debug.Dwarf.SelfUnwinder: assume same-value rule by default for all columns
This fixes leaf function unwinding, presumably among other things.
2025-10-10 15:12:27 +02:00
Alex Rønne Petersen
f010a31319
Merge pull request #25516 from alexrp/std-debug
`std.debug`: greatly expand target support for segfault handling/unwinding, and remove public `ucontext_t` completely
2025-10-10 14:04:02 +02:00
Alex Rønne Petersen
36dbe66cf4
std: stop exposing anything having to do with ucontext_t
This type is useful for two things:

* Doing non-local control flow with ucontext.h functions.
* Inspecting machine state in a signal handler.

The first use case is not one we support; we no longer expose bindings to those
functions in the standard library. They're also deprecated in POSIX and, as a
result, not available in musl.

The second use case is valid, but is very poorly served by the standard library.
As evidenced by my changes to std.debug.cpu_context.signal_context_t, users will
be better served rolling their own ucontext_t and especially mcontext_t types
which fit their specific situation. Further, these types tend to evolve
frequently as architectures evolve, and the standard library has not done a good
job keeping up, or even providing them for all supported targets.
2025-10-10 04:43:18 +02:00
Alex Rønne Petersen
f33d3a5166
std.debug: greatly expand target support for segfault handling/unwinding
I made a couple of decisions for this based on the fact that we don't expose the
signal_ucontext_t type outside of the file:

* Adding all the floating point and vector state to every ucontext_t and
  mcontext_t variant was way, way too much work, especially when we don't even
  use the stuff. So I deleted all that and kept only the bare minimum needed to
  reach into general-purpose registers.
* There is no particularly compelling reason to stick to the naming and struct
  nesting used in the system headers. So we can actually unify the access
  patterns for almost all of these variants by taking some liberties here; as a
  result, fromPosixSignalContext() is now much nicer to read and extend.
2025-10-10 04:43:15 +02:00
kcbanner
ed6d9e2a9d - Output error messages for fatal translate-c errors 2025-10-09 19:08:16 -04:00
marximimus
07b6dbf8ca std.crypto.tls.Client: fix infinite loop in std.Io.Writer.writeAll 2025-10-09 12:34:34 -07:00
Andrew Kelley
df712d0833 std.fs.File.Reader.seekTo: fix one more logical position bug 2025-10-09 11:59:53 -07:00
Alex Rønne Petersen
3f5e782357
std.debug: fix FP unwinding for LoongArch 2025-10-09 20:43:32 +02:00
Alex Rønne Petersen
98f0bf9b67
std.debug: fix SelfInfo default for freestanding ELF targets 2025-10-09 20:43:32 +02:00
Alex Rønne Petersen
6c760d76b9
std.os.linux: define PROT.SEM for xtensa 2025-10-09 20:42:19 +02:00
Alex Rønne Petersen
c8efebcf53
std.os.linux: remove dead/wrong msghdr definitions in some arch bits 2025-10-09 20:42:19 +02:00
mlugg
80f6b8c4b3 std.debug: fix incorrect FP unwinding on RISC-V and SPARC
I broke this when porting this logic for the `std.debug` rework in
https://github.com/ziglang/zig/pull/25227. The offset that I copied was
actually being treated as relative to the address of the *saved* base
pointer. I think it makes more sense to do what I did and just treat all
offsets as relative to this frame's base.
2025-10-09 19:31:44 +01:00
kcbanner
2ce10e0838 - aroDiagnosticsToErrorBundle: fixup not clearing notes after flushing the current error
- Compilation: renameTmpIntoCache doesn't need to be pub after the `translateC` change
2025-10-09 13:34:25 -04:00
Andrew Kelley
c383cd50d5 build.zig: rename -Dtest-default-only to -Dno-matrix
because it's more memorable
2025-10-09 09:59:55 -07:00
Andrew Kelley
529aa9f270
Merge pull request #25512 from ziglang/sendfile-fixes
std.Io: Writer and Reader bug fixes related to sendFile, delimiters, Limited, and seeking
2025-10-09 02:30:31 -07:00
Ryan Liptak
0bdd1b5274
Merge pull request #23657 from mpfaff/realpathW-no-convert
Return WTF-16 from W-suffixed functions instead of converting to WTF-8
2025-10-09 02:01:06 -07: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
kcbanner
447280d0d9 - Move aroDiagnosticsToErrorBundle to compiler/util.zig 2025-10-09 01:06:09 -04:00
kcbanner
478cb9ce6a - aro: fixup toErrorBundle not emitting the last error if it was followed by .off or .warning
- translate-c: emit `file_system_inputs` even in the case of failure, if available
- translate-c: fixup emitting zero-length `file_system_inputs`
2025-10-09 01:06:09 -04:00
kcbanner
4aa4d80ec6 - Rework translate-c to integrate with the build system (by outputing error bundles on stdout) via --zig-integration
- Revive some of the removed cache integration logic in `cmdTranslateC` now that `translate-c` can return error bundles
- Fixup inconsistent path separators (on Windows) when building the aro include path
- Move some error bundle logic from resinator into aro.Diagnostics
- Add `ErrorBundle.addRootErrorMessageWithNotes` (extracted from resinator)
2025-10-09 01:06:09 -04:00
Andrew Kelley
d83d79c032 std.Io.Reader: rework peekDelimiterInclusive
Now it's based on calling fillMore rather than an illegal aliased stream
into the Reader buffer.

This commit also includes a disambiguation block inspired by #25162. If
`StreamTooLong` was added to `RebaseError` then this logic could be
replaced by removing the exit condition from the while loop. That error
code would represent when `buffer` capacity is too small for an
operation, replacing the current use of asserts.
2025-10-08 19:30:36 -07:00
whatisaphone
b9f8b6ef06 Fix Reader.Limited end of stream conditions 2025-10-08 17:24:38 -07:00
Maciej 'vesim' Kuliński
e5a55f6144 std: std.fs.File fix sendFile with buffered data
fixes #25196

Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2025-10-08 17:14:03 -07:00
Michael Pfaff
7bf740ee71 Deprecate old realpathW correctly
- Rename modified `realpathW` to `realpathW2`
- Re-add original `realpathW`
- Add deprecation notice to `realpathW`
2025-10-08 17:07:38 -07:00
Michael Pfaff
eb46bbba34 Fix realpathW out_buffer size 2025-10-08 17:07:38 -07:00
Michael Pfaff
a7dfc6470f Reuse pathname_w buffer as out_buffer when calling realpathW 2025-10-08 17:07:38 -07:00
Michael Pfaff
2886a8bf45 Improve documentation on Dir.realpathW 2025-10-08 17:07:38 -07:00
Michael Pfaff
f2227ae677 Return WTF16LE encoded path from realpathW 2025-10-08 17:07:38 -07:00
mlugg
bf58b4e419 std.Io.Reader: fix delimiter bugs
Fix `takeDelimiter` and `takeDelimiterExclusive` tossing too many bytes
(#25132)

Also add/improve test coverage for all delimiter and sentinel methods,
update usages of `takeDelimiterExclusive` to not rely on the fixed bug,
tweak a handful of doc comments, and slightly simplify some logic.

I have not fixed #24950 in this commit because I am a little less
certain about the appropriate solution there.

Resolves: #25132

Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2025-10-08 17:00:15 -07:00
Andrew Kelley
889942a8b7 std: fix sendFileReading not accounting for buffer
Related to 1d764c1fdf04829cec5974d82cec901825a80e49

Test case provided by:

Co-authored-by: Kendall Condon <goon.pri.low@gmail.com>
2025-10-08 16:45:38 -07:00
Andrew Kelley
4c27eeff8e std: fix File.Writer sendfile with buffered contents
* File.Writer.seekBy passed wrong offset to setPosAdjustingBuffer.
* File.Writer.sendFile incorrectly used non-logical position.

Related to 1d764c1fdf04829cec5974d82cec901825a80e49

Test case provided by:

Co-authored-by: Kendall Condon <goon.pri.low@gmail.com>
2025-10-08 16:43:42 -07:00
Andrew Kelley
8964737ffc build.zig: add -Dtest-default-only option
handy during development when it is already known that not all tests
will pass.
2025-10-08 16:43:42 -07:00
Ryan Liptak
328ae41468 Reader.peekDelimiterInclusive: Fix handling of stream implementations that return 0
Previously, the logic in peekDelimiterInclusive (when the delimiter was not found in the existing buffer) used the `n` returned from `r.vtable.stream` as the length of the slice to check, but it's valid for `vtable.stream` implementations to return 0 if they wrote to the buffer instead of `w`. In that scenario, the `indexOfScalarPos` would be given a 0-length slice so it would never be able to find the delimiter.

This commit changes the logic to assume that `r.vtable.stream` can both:
- return 0, and
- modify seek/end (i.e. it's also valid for a `vtable.stream` implementation to rebase)

Also introduces `std.testing.ReaderIndirect` which helps in being able to test against Reader implementations that return 0 from `stream`/`readVec`

Fixes #25428
2025-10-08 16:42:55 -07:00
xdBronch
60be67d3c0 don't make OPV tuple fields comptime 2025-10-08 18:04:25 +01:00
tehlordvortex
60a332406c std.Build: duplicate sub_path for LazyPath's dependency variant 2025-10-08 11:50:51 +01:00
Alex Rønne Petersen
2aea7a42b0
Merge pull request #25493 from alexrp/std-debug-mips-ppc
`std.debug`: MIPS and PowerPC unwind support + some other stuff
2025-10-08 06:29:28 +02:00
Alex Rønne Petersen
e959a86bb9
ci: bump riscv64-linux-debug timeout to 8 hours on Forgejo Actions 2025-10-08 04:58:03 +02:00
Alex Rønne Petersen
b19ba7df3b
Merge pull request #25496 from alexrp/std-debug-reg-access
`std.debug`: be more resilient in the face of unsupported registers
2025-10-08 03:00:48 +02:00
Andrew Kelley
b824ca8494 Revert "Fix infinite loop in Reader.Limited"
This reverts commit 27aba2d776caf59bb6569934626af587fdba9c75.

I'd like to review this contribution more carefully, particularly with
the alternate implementation that is also open as a pull request
(#25109).

Reopens #25093
2025-10-07 14:35:08 -07:00
xdBronch
2c0aa1c6f5 don't make anonymous tuple fields referencing comptime vars comptime 2025-10-07 22:13:10 +01:00
Alex Rønne Petersen
a54906b46e
std.debug.cpu_context: make arch-specific implementations private 2025-10-07 19:18:46 +02:00
achan1989
27aba2d776 Fix infinite loop in Reader.Limited 2025-10-07 09:53:34 -07:00
Henry John Kupty
163ebe044b
std.mem.countScalar: rework to benefit from simd (#25477)
`findScalarPos` might do repetitive work, even if using simd. For
example, when searching the string `/abcde/fghijk/lm` for the character
`/`, a 16-byte wide search would yield `1000001000000100` but would only
count the first `1` and re-search the remaining of the string.

When testing locally, the difference was quite significative:
```
count scalar
  5737 iterations       522.83us per iterations
  0 bytes per iteration
  worst: 2370us median: 512us   stddev: 107.64us

count v2
  38333 iterations      78.03us per iterations
  0 bytes per iteration
  worst: 713us  median: 76us    stddev: 10.62us

count scalar v2
  99565 iterations      29.80us per iterations
  0 bytes per iteration
  worst: 41us   median: 29us    stddev: 1.04us
```

Note that `count v2` is a simpler string search, similar to the
remaining version of the simd approach:
```
pub fn countV2(comptime T: type, haystack: []const T, needle: T) usize {
    const n = haystack.len;
    if (n < 1) return 0;
    var count: usize = 0;
    for (haystack[0..n]) |item| {
        count += @intFromBool(item == needle);
    }

    return count;
}
```

Which implies the compiler yields some optimized code for a simpler loop
that is more performant than the `findScalarPos`-based approach, hence
the usage of iterative approach for the remaining of the haystack.

Co-authored-by: StAlKeR7779 <stalkek7779@yandex.ru>
2025-10-07 09:32:13 -07:00
Alex Rønne Petersen
a06db282c7
std.debug.SelfInfo.MachO: don't restore vector registers during unwinding
We know that these are unsupported and irrelevant for unwinding, so don't fail
the unwind attempt trying to read/write them for no ultimate purpose.
2025-10-07 17:13:58 +02:00
Alex Rønne Petersen
e4f0c62b5d
std.debug.Dwarf.expression: fix a test that assumes sp != fp
This does not hold on PowerPC.
2025-10-07 17:03:48 +02:00
Alex Rønne Petersen
7fdd5704ed
std.debug.cpu_context: map a bunch of known registers as unsupported instead of invalid 2025-10-07 16:47:57 +02:00
Alex Rønne Petersen
de3b22db4d
std.debug.cpu_context: remove support for s390x float registers
Let's for the moment assume that compilers haven't lost the plot.

Fingers crossed.
2025-10-07 16:47:57 +02:00
Alex Rønne Petersen
9cd37a0696
std.debug.Dwarf: use 66 as the (fake) MIPS PC register
32-63 conflict with the floating point registers. 64 and 65 are used for the
ac0 hi/lo registers.
2025-10-07 16:47:57 +02:00
Alex Rønne Petersen
f6403ed5ea
std.debug.Dwarf: use 67 as the (fake) PowerPC PC register
It's free real estate, as it turns out.
2025-10-07 16:47:57 +02:00
Alex Rønne Petersen
feba8a83a7
std.debug.Dwarf: use 65 as the (fake) RISC-V PC register
32-63 conflict with the floating point registers. 64 is the Alternate Frame
Return Column.
2025-10-07 16:47:57 +02:00
Alex Rønne Petersen
9a6fad2706
std.debug.Dwarf: use 64 as the (fake) LoongArch PC register
32-63 conflict with the floating point registers.
2025-10-07 16:47:57 +02:00
Alex Rønne Petersen
aa74eb505a
std.debug: add unwind support for powerpc*-linux 2025-10-07 16:47:57 +02:00
Alex Rønne Petersen
ca73d697b9
std.debug: add unwind support for mips*-linux 2025-10-07 16:47:57 +02:00
Alex Rønne Petersen
a5a9ffb90b
std.debug.cpu_context: check for architecture, i.e. register size, not bitness
We care about the hardware here, not the ABI.
2025-10-07 16:47:57 +02:00
Alex Rønne Petersen
081d6d12a1
std.debug.Dwarf.SelfUnwinder: add an s390x check missed in 95bdb0c1c65c128923ffac3f4be6b4619eb4a54b 2025-10-07 16:47:57 +02:00
Alex Rønne Petersen
fdd109420d
std.debug: add noinline to functions that capture the current stack trace
Fixes stack traces missing a frame depending on inlining decisions.

ref https://github.com/ziglang/zig/issues/25418
2025-10-07 16:47:57 +02:00
Alex Rønne Petersen
0b33891f4c
std.os.linux: add ucontext_t and mcontext_t for mips/mips64 2025-10-07 16:47:57 +02:00
Alex Rønne Petersen
98af7f34e9
std.os.linux: minor NFC corrections to hexagon ucontext_t and mcontext_t 2025-10-07 16:47:57 +02:00
Alex Rønne Petersen
9760068826 std.debug: prefer FP unwinding on targets where it is ideal
If the ABI requires a backchain pointer, FP unwinding is always possible, safe,
and fast, so there's really no reason not to use it.
2025-10-07 16:44:25 +02:00
Jacob Young
d28006153e llvm.Builder: allow Metadata to reference metadata strings
Closes #25486
2025-10-07 07:49:54 -04:00
xdBronch
2810e4b173 detect references to comptime var in default values and sentinels 2025-10-07 11:58:12 +01:00
Alex Rønne Petersen
c23a5ccd19
std.debug.Dwarf.SelfUnwinder: skip caching rules for unsupported registers
For unwinding purposes, we don't care about unsupported registers. Yet because
we added these rules to the cache entry, we'd later try to evaluate them and
thus fail the unwind attempt for no good reason. They'd also take up cache rule
slots that would be better spent on actually relevant registers.

Note that any attempt to read unsupported registers during unwinding will still
fail the unwind attempt as expected.
2025-10-07 09:28:43 +02:00
Andrew Kelley
6893e7feee
Merge pull request #25414 from squeek502/mingw-def-implib
Support generating import libraries from mingw .def files without LLVM
2025-10-06 13:38:07 -07:00
Zhenming Lin
9bfd4c3017
improve impl of __sqrth, sqrtf, sqrt, __sqrtx and sqrtq (#25416)
The previous version (ported from musl) used bit-by-bit calculations and was slow, but the current version (also ported from musl) uses lookup tables combined with Goldschmidt iterations to significantly improve the speed.
2025-10-06 11:45:51 -07:00
xdBronch
851ae9bb43 don't pass zero-length @memset to the backend 2025-10-06 11:28:56 -07:00
Jacob Young
969f2cff82 Elf2: implement virtual allocation
This allows segments to be moved around in the output file without
needing to reapply relocations until virtual address space is exhaused.
2025-10-06 11:27:39 -07:00
Alex Rønne Petersen
2962db333f
Merge pull request #25480 from alexrp/std-debug-hexagon
`std.debug`: add unwind support for `hexagon-linux`
2025-10-06 11:10:02 +02:00
xdBronch
ea9fb3ccfa fix read of undefined in http tests 2025-10-06 06:54:52 +02:00
Alex Rønne Petersen
7c87691a61
Merge pull request #25479 from alexrp/qemu-os-checks
`std.zig.system`: add OS checks for QEMU in `getExternalExecutor()`
2025-10-06 06:11:06 +02:00
Alex Rønne Petersen
ddc815e3d8 drop support for powerpc64 ELF v1
* ELF v1 on powerpc64 is only barely kept on life support in a couple of Linux
  distros. I don't anticipate that this will last much longer.
* Most of the Linux world has moved to powerpc64le which requires ELF v2.
* Some Linux distros have even started supporting powerpc64 with ELF v2.
* The BSD world has long since moved to ELF v2.
* We have no actual linking support for ELF v1.
* ELF v1 had confused DWARF register mappings which is becoming a problem in
  our DWARF code in std.debug.

It's clear that ELF v1 is on its way out, and we never fully supported it
anyway. So let's not waste any time or energy on it going forward.

closes #5927
2025-10-06 01:28:56 +02:00
Alex Rønne Petersen
9e61a64033
std.zig.system: add OS checks for QEMU in getExternalExecutor()
FreeBSD doesn't support the same number of platforms as Linux, and even then,
only has usermode emulation for a subset of its supported platforms.

NetBSD's usermode emulation support is apparently just broken at the moment.
2025-10-05 23:33:12 +02:00
Alex Rønne Petersen
a5ff376b8f
std.debug: add unwind support for hexagon-linux 2025-10-05 20:09:26 +02:00
Alex Rønne Petersen
26403fe3f9
std.os.linux: add mcontext_t and ucontext_t for hexagon 2025-10-05 20:08:55 +02:00
Alex Rønne Petersen
bd23e9a744
ci: bump x86_64-linux-release timeout to 8 hours on Forgejo Actions 2025-10-05 18:53:34 +02:00
Alex Rønne Petersen
5969d6180f
std.zig.system: handle or1k in getExternalExecutor() 2025-10-05 17:06:41 +02:00
Ryan Liptak
0a74d73459
Merge pull request #25320 from hkupty/walker2
std.fs.Dir: Add `walkSelectively` to provide more control over directory walking
2025-10-04 22:41:25 -07:00
Alex Rønne Petersen
e6e4792a58 std.debug: completely disable FP-based unwinding on mips 2025-10-05 07:18:50 +02:00
Alex Rønne Petersen
30f5258fe6 std.debug.SelfInfo.Elf: disable unwinding on mips n32 and x86 x32
The DWARF code can't handle these yet.

ref https://github.com/ziglang/zig/issues/25447
2025-10-05 07:18:50 +02:00
Jacob Young
906ce2ad7c InternPool: use sequential string indices instead of byte offsets
This allows more bytes to be referenced by a smaller index range.

Closes #22867
Closes #25297
Closes #25339
2025-10-05 00:25:21 -04:00
Alex Rønne Petersen
606c7bcc89
test: disable standalone tsan test
https://github.com/ziglang/zig/issues/25471
2025-10-05 02:13:21 +02:00
Alex Rønne Petersen
97fa0e3ebd
Merge pull request #25456 from alexrp/libcxx-cxx17-removed-functions
`libcxx`: stop defining `_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS`
2025-10-05 00:52:57 +02:00
Alex Rønne Petersen
73602f2a13
std.Target: baseline model for s390x-zos should be arch10, not arch8 2025-10-05 00:23:51 +02:00
Alex Rønne Petersen
ea46bd2772
test: move standalone/options/ to cli/options/
It's now used only by test-cli, so make that clear.
2025-10-04 21:55:39 +02:00
Alex Rønne Petersen
5bbbc8d299
Revert "test: remove standalone options test"
This reverts commit d9cd4d087648c6d83e22dda6a4b82929a72fc771.

Turns out Jacob restored this test as part of test-cli in cdba1d5.
2025-10-04 21:46:55 +02:00
Alex Rønne Petersen
c4b7caa528
ci: run the docs step on loongarch64-linux 2025-10-04 21:02:43 +02:00
Alex Rønne Petersen
3539cad176
test: remove standalone sigpipe test
This should be restored, but there's no point keeping disabled code that's just
going to bitrot.

https://github.com/ziglang/zig/issues/25466
2025-10-04 20:53:19 +02:00
Alex Rønne Petersen
d9cd4d0876
test: remove standalone options test
This functionality is already load-bearing for the compiler's own build script
so this (disabled, possibly bitrotted?) doesn't really add value.
2025-10-04 20:51:07 +02:00
Alex Rønne Petersen
f6c1864abf
test: remove standalone issue_13970 test
It's been disabled for ages and has bitrotted. Someone can readd it later if
they feel like it actually adds value.
2025-10-04 20:51:07 +02:00
Alex Rønne Petersen
95417948d0
test: remove ad-hoc nvptx tests
These were just testing random things in the LLVM NVPTX backend. That's not
really our job.
2025-10-04 20:51:07 +02:00
Alex Rønne Petersen
c68f9bc207
test: remove some tests that are now covered well enough by test-stack-traces
The amount of cross compilation required for these tests was too time-consuming
for how much value they added. test-stack-traces now cover these well enough,
especially as we add more exotic machines to the CI fleet to run native tests.
2025-10-04 20:51:07 +02:00
rpkak
b5ec75b7e7 make freebsd copy_file_range return type signed 2025-10-04 11:46:20 +02:00
Alex Rønne Petersen
b54bdace75
Merge pull request #25457 from linusg/more-serenity
std.debug: Add unwind support for serenity
2025-10-04 07:09:59 +02:00
David Rubin
e932ab003f
correct ed25519 test case (#25445) 2025-10-04 02:31:02 +00:00
Ryan Liptak
e393543e63 Support generating import libraries from mingw .def files without LLVM
For the supported COFF machine types of X64 (x86_64), I386 (x86), ARMNT (thumb), and ARM64 (aarch64), this new Zig implementation results in byte-for-byte identical .lib files when compared to the previous LLVM-backed implementation.
2025-10-03 18:26:05 -07:00
Ryan Liptak
900315a3f3 std.coff: Fix size of ImportHeader.types 2025-10-03 18:26:05 -07:00
Alex Rønne Petersen
9dbfa5b294 std.debug: consider FP-based unwinding on hexagon and powerpc safe
The ABIs make this safe and reliable due to their backchain requirements.
2025-10-04 03:22:40 +02:00
Alex Rønne Petersen
d8268fac98 std.debug: fix FP-based unwinding on powerpc64
This just needs to do the same thing as powerpc64le. Note that the saved LR is
at the same position in both ELF v1 and v2.
2025-10-04 03:03:54 +02:00
Ryan Liptak
b382119c02 std.coff: Set default values for ImportHeader sig1/sig2 fields
Just makes this a bit nicer to work with since those fields only have 1 intended value.
2025-10-03 17:44:36 -07:00
Ryan Liptak
a974198b94 std.coff: Add sizeOf function to WeakExternalDefinition
Convenience function similar in nature to Symbol.sizeOf
2025-10-03 17:44:36 -07:00
Ryan Liptak
78e07b8fc8 std.coff: Fix SectionHeader.setAlignment (off by 1)
Previously, `setAlignment` would set the value to 1 fewer than it should, so if you were intending to set alignment to 8 bytes, it would actually set it to 4 bytes, etc.
2025-10-03 17:44:36 -07:00
Ryan Liptak
894a991714 Add depth function to Walker.Entry
This enables depth-related use cases without any dependency on the Walker's internal stack which doesn't always pertain to the actual depth of the current entry (i.e. recursing into a directory immediately affects the stack).
2025-10-03 16:29:09 -07:00
Ryan Liptak
98dd8856ef std.mem: Add countScalar 2025-10-03 16:29:09 -07:00
Henry Kupty
83f8441c4f fix: Check if key exists instead of trying to match on null
Co-Authored-By: Ryan Liptak <squeek502@hotmail.com>
2025-10-03 16:29:09 -07:00
Henry Kupty
a0ec5d1c6e fix: Match prefix with static string map
Co-authored-by: Ryan Liptak <squeek502@hotmail.com>
2025-10-03 16:29:08 -07:00
Henry Kupty
7bee39c1fd test: enter after check to preserve depth 2025-10-03 16:29:08 -07:00
Henry Kupty
a26a654c55 test: Include expected depth test 2025-10-03 16:29:08 -07:00
Henry Kupty
ec4514def4 refactor: Reimplement tool using SelectiveWalker
This skips directory trees where top-level directories do not match the
defined ones
2025-10-03 16:29:08 -07:00
Henry Kupty
df394faf77 feat: Reintroduce depth
Some decision-making might depend on the level of the traversal, so
it makes sense to expose depth here since it's stable, and not in the
automatic walker where it's not.
2025-10-03 16:29:08 -07:00
Ryan Liptak
760127a760 Add SelectiveWalker/walkSelectively and implement Walker in terms of it
This is a breaking change, since the fields of Walker have changed. The function APIs are unchanged, though.
2025-10-03 16:29:08 -07:00
Alex Rønne Petersen
6870144a3b
libcxx: don't impose _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS on users
closes https://github.com/ziglang/zig/issues/25455
2025-10-04 00:46:04 +02:00
Alex Rønne Petersen
ef2001c7ff
libcxxabi: define _LIBCPP_BUILDING_LIBRARY in addition to _LIBCXXABI_BUILDING_LIBRARY 2025-10-04 00:46:04 +02:00
Alex Rønne Petersen
43888e6549
libcxxabi: don't build cxa_noexception.cpp if exceptions are enabled 2025-10-04 00:46:02 +02:00
Alex Rønne Petersen
920ea35714
libcxxabi: sort file list according to upstream CMakeLists.txt 2025-10-04 00:43:20 +02:00
Linus Groh
b0f280f4a4 std.debug: Add unwind support for serenity 2025-10-03 22:59:40 +01:00
Linus Groh
a76851b2ef std.c: Also make Sigaction flags a c_uint for serenity
This matches all other platforms. Even if this field is defined as 'int'
in the C definition, the expectation is that the full 32-bit unsigned
integer range can be used. In particular this Sigaction initializer in
the new std.debug code was causing a build failure:

```zig
.flags = (posix.SA.SIGINFO | posix.SA.RESTART | posix.SA.RESETHAND)
```
2025-10-03 22:19:25 +01:00
Linus Groh
701a6f394c std.c: Add missing SIG constants for serenity 2025-10-03 22:15:38 +01:00
Jacob Young
07c3f9ef8e x86_64: fix bool vector init register clobber
Closes #25439
2025-10-03 12:18:53 -04:00
Jacob Young
12ed0ff1ef
Merge pull request #25430 from jacobly0/x86_64-win
Coff2: create a new linker from scratch
2025-10-03 05:03:44 -04:00
Alex Rønne Petersen
1f083e9ed7
Merge pull request #25443 from alexrp/s390x-unwind
`std.debug`: add `s390x-linux` unwind support
2025-10-03 07:42:17 +02:00
Alex Rønne Petersen
95bdb0c1c6
std.debug.Dwarf.SelfUnwinder: default some s390x registers to the same-value rule 2025-10-03 03:45:52 +02:00
Alex Rønne Petersen
8263f55ab2
std.debug: add s390x-linux unwind support 2025-10-03 03:29:20 +02:00
Alex Rønne Petersen
006bc5a8ca
std.os.linux: improve the s390x mcontext_t definition
The old one was correct in terms of layout but very user-hostile.
2025-10-03 03:29:20 +02:00
Alex Rønne Petersen
0f56d7afe2
std.debug: use correct return address offset for s390x
Makes FP-based unwinding work.
2025-10-03 03:29:20 +02:00
Alex Rønne Petersen
91fa2c61aa
compiler: control the s390x backchain feature through the frame pointer option
This is a little different from how C/C++ compilers do this, but I think it's
justified because it's what users actually *mean* when the use frame pointer
options.

This is another one of those LLVM "CPU" features that have nothing to do with
CPU at all and should really be a TargetMachine option or something. One day
we'll figure out a better way of dealing with these...
2025-10-03 03:29:20 +02:00
Ryan Liptak
759e038a44 resinator: Update for std.coff changes 2025-10-02 17:44:52 -04:00
Jacob Young
1fa11e0954 Coff: delete 2025-10-02 17:44:52 -04:00
Jacob Young
e1f3fc6ce2 Coff2: create a new linker from scratch 2025-10-02 17:44:52 -04:00
Jacob Young
d5f09f56e0 x86_64: fix windows calling convention abi 2025-10-02 15:59:51 -04:00
Alex Rønne Petersen
bc4da9a907
Merge pull request #25437 from alexrp/std-debug
`std.debug`: LoongArch and RISC-V unwind support + some minor cleanups
2025-10-02 21:38:07 +02:00
Alex Rønne Petersen
a4f95b1e61
std.debug.Dwarf.Unwind: deal with invalid def_cfa_reg by GNU toolchains 2025-10-02 15:27:35 +02:00
Alex Rønne Petersen
14019a95a4
ci: bump x86_64-linux-release timeout to 7 hours on Forgejo Actions 2025-10-02 13:27:00 +02:00
mlugg
1914d1a6e5 Lld: fix implib emit path
Resolves: https://github.com/ziglang/zig/issues/24993
2025-10-02 02:31:44 +01:00
Alex Rønne Petersen
97de46dc16
std.debug: add riscv32-linux and riscv64-linux unwind support 2025-10-01 23:47:47 +02:00
Alex Rønne Petersen
8520e9312e
std.debug: add loongarch64-linux unwind support 2025-10-01 23:47:47 +02:00
Alex Rønne Petersen
b46867848e
std.debug: some adjustments to target handling
* driverkit handling missing in a few places.
* x86-solaris is a dead target.
* aarch64_be does not exist on Darwin, FreeBSD, Windows.
2025-10-01 23:47:47 +02:00
Alex Rønne Petersen
771410cbf2
std.debug.SelfInfo: rename Darwin to MachO 2025-10-01 23:47:47 +02:00
Alex Rønne Petersen
e1fb662f60
std.debug: don't use SelfInfo.Windows for UEFI
It is, in fact, Windows-only.
2025-10-01 23:47:47 +02:00
Alex Rønne Petersen
59633e54a2
std.debug: select SelfInfo using ObjectFormat.default() 2025-10-01 23:47:47 +02:00
Alex Rønne Petersen
2cdafe9106
ci: allow riscv64-linux on Forgejo Actions to run on PRs for now
Since it's not currently running on pushes to master, there's plenty of capacity
to run it on PRs on the Codeberg side.
2025-10-01 23:45:40 +02:00
Andrew Kelley
4bb9aa91eb these documents belong elsewhere
contributing is in the readme already, and code of conduct should go on
the website. this is a code repository; it doesn't dictate social norms.

the reason for these documents being in .github/ was to satisfy GitHub
demands so that the UI would look more favorably upon ziglang/zig but
that is no longer a concern.
2025-10-01 14:08:38 -07:00
Ryan Liptak
c50aa2b95c resinator: Sync with upstream, fix an alignment problem 2025-10-01 07:48:33 -07:00
Alex Rønne Petersen
fc59870e3b
move .github/FUNDING.yml to https://github.com/ziglang/.github 2025-10-01 13:48:09 +02:00
Alex Rønne Petersen
d57f1b1572
ci: run riscv64-linux on any non-PR Forgejo Actions event, including workflow_dispatch 2025-10-01 13:36:18 +02:00
Alex Rønne Petersen
bd9098e285
ci: bump x86_64-linux-debug-llvm timeout to 8 hours on Forgejo Actions 2025-10-01 13:17:31 +02:00
Alex Rønne Petersen
30e43f7246
move some docs out of .github/ 2025-10-01 13:08:03 +02:00
Alex Rønne Petersen
691be2f19f
ci: add Forgejo Actions workflow file 2025-10-01 13:00:22 +02:00
Alex Rønne Petersen
2aa9dd44a5
ci: we don't require s3cmd anymore 2025-10-01 13:00:22 +02:00
Alex Rønne Petersen
781cc731ed
ci: move Git repository unshallowing to the workflow 2025-10-01 13:00:22 +02:00
Alex Rønne Petersen
acf8d5234f
ci: stop requiring an ARCH environment variable to be set 2025-10-01 13:00:22 +02:00
Alex Rønne Petersen
9327aaefb6
test: disable an error trace test on optimized riscv64-linux 2025-10-01 12:58:20 +02:00
Ryan Liptak
dcfc851349 ArrayHashMapWithAllocator: add sortUnstable fn alongside sort 2025-09-30 19:33:03 -07:00
Timothy Bess
cbe3dd12c4 Fix zig build lazy -> eager dependency promotion
Before, this had a subtle ordering bug where duplicate
deps that are specified as both lazy and eager in different
parts of the dependency tree end up not getting fetched
depending on the ordering. I modified it to resubmit lazy
deps that were promoted to eager for fetching so that it will
be around for the builds that expect it to be eager downstream
of this.
2025-09-30 18:58:42 -07:00
Kendall Condon
f50c647977 add deflate compression, simplify decompression
Implements deflate compression from scratch. A history window is kept in
the writer's buffer for matching and a chained hash table is used to
find matches. Tokens are accumulated until a threshold is reached and
then outputted as a block. Flush is used to indicate end of stream.

Additionally, two other deflate writers are provided:
* `Raw` writes only in store blocks (the uncompressed bytes). It
  utilizes data vectors to efficiently send block headers and data.
* `Huffman` only performs Huffman compression on data and no matching.

The above are also able to take advantage of writer semantics since they
do not need to keep a history.

Literal and distance code parameters in `token` have also been reworked.
Their parameters are now derived mathematically, however the more
expensive ones are still obtained through a lookup table (expect on
ReleaseSmall).

Decompression bit reading has been greatly simplified, taking advantage
of the ability to peek on the underlying reader. Additionally, a few
bugs with limit handling have been fixed.
2025-09-30 18:28:47 -07:00
Alex Rønne Petersen
fcfdf99122
ci: enable running libc-test on x86_64-linux-release 2025-10-01 03:25:25 +02:00
Alex Rønne Petersen
f049ae6d57
libc-test: set a 1.6G max_rss for each test case
1.4G was the highest value I observed for any test case on x86_64-linux. This
change should prevent OOM conditions in CI.
2025-10-01 03:25:13 +02:00
Alex Rønne Petersen
e5ebdf9e41
libc-test: disable malloc-oom.c
This causes QEMU to OOM in CI.
2025-10-01 03:25:13 +02:00
Alex Rønne Petersen
e79a00adf6
ci: bump x86_64-freebsd max_rss from 30G to 40G 2025-10-01 01:08:31 +02:00
Alex Rønne Petersen
01a2989fcc
ci: run test-error-traces on riscv64-linux 2025-10-01 01:06:15 +02:00
Alex Rønne Petersen
d97954a8ea
test: remove stack_iterator standalone test
Our new stack trace tests cover all the important parts of this.
2025-10-01 01:06:13 +02:00
Alex Rønne Petersen
5a71e15f1f
test: don't run error/stack trace tests on self-hosted on BSDs
See: 0700ec35bda705fccb61cb3f28734ce11166fda5
2025-10-01 01:06:10 +02:00
Alex Rønne Petersen
43806cf0bd
test: disable an error trace test on optimized x86_64-freebsd and loongarch64-linux 2025-10-01 01:06:07 +02:00
Matthew Lugg
b64535e3c8
Merge pull request #25227 from mlugg/capture-stack
The Great `std.debug` Refactor
2025-09-30 20:24:58 +01:00
mlugg
1120546f72
std.debug.SelfInfo: remove shared logic
There were only a few dozen lines of common logic, and they frankly
introduced more complexity than they eliminated. Instead, let's accept
that the implementations of `SelfInfo` are all pretty different and want
to track different state. This probably fixes some synchronization and
memory bugs by simplifying a bunch of stuff. It also improves the DWARF
unwind cache, making it around twice as fast in a debug build with the
self-hosted x86_64 backend, because we no longer have to redundantly go
through the hashmap lookup logic to find the module. Unwinding on
Windows will also see a slight performance boost from this change,
because `RtlVirtualUnwind` does not need to know the module whatsoever,
so the old `SelfInfo` implementation was doing redundant work. Lastly,
this makes it even easier to implement `SelfInfo` on freestanding
targets; there is no longer a need to emulate a real module system,
since the user controls the whole implementation!

There are various other small refactors here in the `SelfInfo`
implementations as well as in the DWARF unwinding logic. This change
turned out to make a lot of stuff simpler!
2025-09-30 14:18:26 +01:00
mlugg
12ceb896fa
Dwarf.Unwind: fix typo 2025-09-30 13:44:56 +01:00
mlugg
a90eb50c80
typo 2025-09-30 13:44:56 +01:00
mlugg
8950831d3c
Dwarf.Unwind: handle macOS deviation from standard
Apparently the `__eh_frame` in Mach-O binaries doesn't include the
terminator entry, but in all other respects it acts like `.eh_frame`
rather than `.debug_frame`. I have no idea.
2025-09-30 13:44:56 +01:00
mlugg
156cd8f678
std.debug: significantly speed up capturing stack traces
By my estimation, these changes speed up DWARF unwinding when using the
self-hosted x86_64 backend by around 7x. There are two very significant
enhancements: we no longer iterate frames which don't fit in the stack
trace buffer, and we cache register rules (in a fixed buffer) to avoid
re-parsing and evaluating CFI instructions in most cases. Alongside this
are a bunch of smaller enhancements, such as pre-caching the result of
evaluating the CIE's initial instructions, avoiding re-parsing of CIEs,
and big simplifications to the `Dwarf.Unwind.VirtualMachine` logic.
2025-09-30 13:44:56 +01:00
mlugg
3f84b6c80e
cbe: workaround GCC miscompilation
This was causing a zig2 miscomp, which emitted slightly broken debug
information, which caused extremely slow stack unwinding. We're working
on fixing or reporting this upstream, but we can use this workaround for
now, because GCC guarantees arithmetic signed shift.
2025-09-30 13:44:56 +01:00
mlugg
dbda011ae6
std.debug.SelfInfo: mark ARM unwinding as unsupported
We need to parse the `.ARM.exidx` section to be able to reliably unwind
the stack on ARM.
2025-09-30 13:44:56 +01:00
mlugg
950a9d2a10
typo 2025-09-30 13:44:56 +01:00
mlugg
f7e0ff8a5f
std: clarify cpu_context register order rationale 2025-09-30 13:44:56 +01:00
mlugg
b0f222777c
std.debug: cap total stack trace frames
...just in case there is broken debug info and/or bad values on the
stack, either of which could cause stack unwinding to potentially loop
forever.
2025-09-30 13:44:56 +01:00
mlugg
c41bf99684
std.debug: don't assume return address register is defined if not specified
This logic was causing some occasional infinite looping on ARM, where
the `.debug_frame` section is often incomplete since the `.exidx`
section is used for unwind information. But the information we're
getting from the compiler is totally *valid*: it's leaving the rule as
the default, which is (as with most architectures) equivalent to
`.undefined`!
2025-09-30 13:44:55 +01:00
mlugg
099a950410
std.debug.SelfInfo: thread safety
This has been a TODO for ages, but in the past it didn't really matter
because stack traces are typically printed to stderr for which a mutex
is held so in practice there was a mutex guarding usage of `SelfInfo`.

However, now that `SelfInfo` is also used for simply capturing traces,
thread safety is needed. Instead of just a single mutex, though, there
are a couple of different mutexes involved; this helps make critical
sections smaller, particularly when unwinding the stack as `unwindFrame`
doesn't typically need to hold any lock at all.
2025-09-30 13:44:55 +01:00
mlugg
9c1821d3bf
ElfModule: fix assertion failure 2025-09-30 13:44:55 +01:00
mlugg
084e92879a
std: don't get CPU context when using CBE targeting MSVC
Calling `current` here causes compilation failures as the C backend
currently does not emit valid MSVC inline assembly. This change means
that when building for MSVC with the self-hosted C backend, only FP
unwinding can be used.
2025-09-30 13:44:55 +01:00
mlugg
dae703d3c0
std.posix.abort: only trigger breakpoint on Windows if being debugged
Processes should reasonably be able to expect their children to abort
with typical exit codes, rather than a debugger breakpoint signal. This
flag in the PEB is what would be checked by `IsDebuggerPresent` in
kernel32, which is the function you would typically use for this
purpose.

This fixes `test-stack-trace` failures on Windows, as these tests were
expecting exit code 3 to indicate abort.
2025-09-30 13:44:55 +01:00
mlugg
2ab650b481
std.debug: go back to storing return addresses instead of call addresses
...and just deal with signal handlers by adding 1 to create a fake
"return address". The system I tried out where the addresses returned by
`StackIterator` were pre-subtracted didn't play nicely with error
traces, which in hindsight, makes perfect sense. This definition also
removes some ugly off-by-one issues in matching `first_address`, so I do
think this is a better approach.
2025-09-30 13:44:55 +01:00
mlugg
9434bab313
std: work around crash parsing LLVM PDB
This crash exists on master, and seems to have existed since 2019; I
think it's just very rare and depends on the exact binary generated. In
theory, a stream block should always be a "data" block rather than a FPM
block; the FPMs use blocks `1, 4097, 8193, ...` and `2, 4097, 8194, ...`
respectively. However, I have observed LLVM emitting an otherwise valid
PDB which maps FPM blocks into streams. This is not a bug in
`std.debug.Pdb`, because `llvm-pdbutil` agrees with our stream indices.
I think this is arguably an LLVM bug; however, we don't really lose
anything from just weakening this check. To be fair, MSF doesn't have an
explicit specification, and LLVM's documentation (which is the closest
thing we have) does not explicitly state that FPM blocks cannot be
mapped into streams, so perhaps this is actually valid.

In the rare case that LLVM emits this, previously, stack traces would
have been completely useless; now, stack traces will work okay.
2025-09-30 13:44:55 +01:00
mlugg
23d6381e8b
std.debug: fix typo 2025-09-30 13:44:55 +01:00
mlugg
0c24b8ec66
update to new std.debug changes 2025-09-30 13:44:55 +01:00
mlugg
3a9c680ad7
std: allow disabling stack tracing
This option disables both capturing and printing stack traces. The
default is to disable if debug info is stripped.
2025-09-30 13:44:55 +01:00
mlugg
abb2b1e2da
std.debug: update support checks 2025-09-30 13:44:55 +01:00
mlugg
dd8d59686a
std.debug: miscellaneous fixes
Mostly on macOS, since Loris showed me a not-great stack trace, and I
spent 8 hours trying to make it better. The dyld shared cache is
designed in a way which makes this really hard to do right, and
documentation is non-existent, but this *seems* to work pretty well.
I'll leave the ruling on whether I did a good job to CI and our users.
2025-09-30 13:44:54 +01:00
mlugg
a18fd41064
std: rework/remove ucontext_t
Our usage of `ucontext_t` in the standard library was kind of
problematic. We unnecessarily mimiced libc-specific structures, and our
`getcontext` implementation was overkill for our use case of stack
tracing.

This commit introduces a new namespace, `std.debug.cpu_context`, which
contains "context" types for various architectures (currently x86,
x86_64, ARM, and AARCH64) containing the general-purpose CPU registers;
the ones needed in practice for stack unwinding. Each implementation has
a function `current` which populates the structure using inline
assembly. The structure is user-overrideable, though that should only be
necessary if the standard library does not have an implementation for
the *architecture*: that is to say, none of this is OS-dependent.

Of course, in POSIX signal handlers, we get a `ucontext_t` from the
kernel. The function `std.debug.cpu_context.fromPosixSignalContext`
converts this to a `std.debug.cpu_context.Native` with a big ol' target
switch.

This functionality is not exposed from `std.c` or `std.posix`, and
neither are `ucontext_t`, `mcontext_t`, or `getcontext`. The rationale
is that these types and functions do not conform to a specific ABI, and
in fact tend to get updated over time based on CPU features and
extensions; in addition, different libcs use different structures which
are "partially compatible" with the kernel structure. Overall, it's a
mess, but all we need is the kernel context, so we can just define a
kernel-compatible structure as long as we don't claim C compatibility by
putting it in `std.c` or `std.posix`.

This change resulted in a few nice `std.debug` simplifications, but
nothing too noteworthy. However, the main benefit of this change is that
DWARF unwinding---sometimes necessary for collecting stack traces
reliably---now requires far less target-specific integration.

Also fix a bug I noticed in `PageAllocator` (I found this due to a bug
in my distro's QEMU distribution; thanks, broken QEMU patch!) and I
think a couple of minor bugs in `std.debug`.

Resolves: #23801
Resolves: #23802
2025-09-30 13:44:54 +01:00
Jacob Young
b578cca022
link.Dwarf: i just fixed error union values, s'nothin' else to it 2025-09-30 13:44:54 +01:00
mlugg
604fb3001d
std.start: also don't print error trace targeting .other
This only matters if `callMain` is called by a user, since `std.start`
will never itself call `callMain` when `target.os.tag == .other`.
However, it *is* a valid use case for a user to call
`std.start.callMain` in their own startup logic, so this makes sense.
2025-09-30 13:44:54 +01:00
mlugg
e9c0d43c5b
test-error-traces: skip some more optimized traces 2025-09-30 13:44:54 +01:00
mlugg
2fefe0e4b3
tests: fix 32-bit compatible arch selection 2025-09-30 13:44:54 +01:00
mlugg
f5c8d80e08
windows_bat_args: fix path handling
The input path could be cwd-relative, in which case it must be modified
before it is written into the batch script.

Also, remove usage of deprecated `GeneralPurposeAllocator` alias, rename
`allocator` to `gpa`, use unmanaged `ArrayList`.
2025-09-30 13:44:54 +01:00
mlugg
d289667856
std.debug.Pdb: fix leak 2025-09-30 13:44:54 +01:00
mlugg
4cb84f8e48
test-standalone: update for std.debug changes 2025-09-30 13:44:54 +01:00
mlugg
51d08f4b9b
fix compile errors and minor bugs 2025-09-30 13:44:54 +01:00
mlugg
5f00738969
test-stack-traces: fix on x86-windows 2025-09-30 13:44:53 +01:00
mlugg
344ab62b3f
std.debug: don't attempt SelfInfo unwinding when unsupported 2025-09-30 13:44:53 +01:00
mlugg
cf13b40946
test-stack-traces: don't try to strip unwind tables on x86-windows 2025-09-30 13:44:53 +01:00
mlugg
e6eccc3c8f
SelfInfo: remove x86-windows unwinding path
Turns out that RtlCaptureStackBackTrace is actually just doing FP (ebp)
unwinding under the hood, making this logic completely redundant with
our own FP-walking implementation; see added comment for details.
2025-09-30 13:44:53 +01:00
mlugg
1a8a8c610d
tests: split up and enhance stack trace tests
Previously, the `test-stack-traces` step was essentially just testing
error traces, and even there we didn't have much coverage. This commit
solves that by splitting the "stack trace" tests into two separate
harnesses: the "stack trace" tests are for actual stack traces (i.e.
involving stack unwinding), while the "error trace" tests are
specifically for error return traces.

The "stack trace" tests will test different configurations of:

* `-lc`
* `-fPIE`
* `-fomit-frame-pointer`
* `-fllvm`
* unwind tables (currently disabled)
* strip debug info (currently disabled)

The main goal there is to test *stack unwinding* under different
conditions. Meanwhile, the "error trace" tests will test different
configurations of `-O` and `-fllvm`; the main goal here, aside from
checking that error traces themselves do not miscompile, is to check
whether debug info is still working even in optimized builds. Of course,
aggressive optimizations *can* thwart debug info no matter what, so as
before, there is a way to disable cases for specific targets / optimize
modes.

The program which converts stack traces into a more validatable format
by removing things like addresses (previously `check-stack-trace.zig`,
now `convert-stack-trace.zig`) has been rewritten and simplified. Also,
thanks to various fixes in this branch, several workarounds have become
unnecessary: for instance, we don't need to ignore the function name
printed in stack traces in release modes, because `std.debug.Dwarf` now
uses the correct DIE for inlined functions!

Neither `test-stack-traces` nor `test-error-traces` does general foreign
architecture testing, because it seems that (at least for now) external
executors often aren't particularly good at handling stack tracing
correctly (looking at you, Wine). Generally, they just test the native
target (this matches the old behavior of `test-stack-traces`). However,
there is one exception: when on an x86_64 or aarch64 host, we will also
test the 32-bit version (x86 or arm) if the OS supports it, because such
executables can be trivially tested without an external executor.

Oh, also, I wrote a bunch of stack trace tests. Previously there was,
erm, *one* test in `test-stack-traces` which wasn't for error traces.
Now there are a good few!
2025-09-30 13:44:53 +01:00
mlugg
cedd9de64f
std.debug.Dwarf: fix names of inlined functions 2025-09-30 13:44:53 +01:00
mlugg
a12ce28224
std: fix os.linux.x86.syscall6
It was possible for `arg6` to be passed as an operand relative to esp.
In that case, the `push` at the top clobbered esp and hence made the
reference to arg6 invalid. This was manifesting in this branch as broken
stack traces on x86-linux due to an `mmap2` syscall accidentally passing
the page offset as non-zero!

This commit fixes a bug introduced in cb0e6d8aa.
2025-09-30 13:44:53 +01:00
mlugg
9901b9389e
std: fix 32-bit build and some unsafe casts 2025-09-30 13:44:53 +01:00
mlugg
7601b397ef
fix bad merge
The API of `std.debug.Pdb` changed.
2025-09-30 13:44:53 +01:00
mlugg
02a0ade138
std.debug: never attempt FP unwind under fomit-frame-pointer 2025-09-30 13:44:53 +01:00
mlugg
4e45362529
link.Elf: fix static PIE
We mustn't emit the DT_PLTGOT entry in `.dynamic` in a statically-linked
PIE, because there's no dl to relocate it (and `std.pie.relocate`, or
the PIE relocator in libc, won't touch it). In that case, there cannot
be any PLT entries, so there's no point emitting the `.got.plt` section
at all. If we just don't create that section, `link.Elf` already knows
not to add the DT_PLTGOT entry to `.dynamic`.

Co-authored-by: Jacob Young <jacobly0@users.noreply.github.com>
2025-09-30 13:44:53 +01:00
mlugg
1123741fd5
Dwarf: use 'gpa' terminology 2025-09-30 13:44:52 +01:00
mlugg
bfbbda7751
compiler: fix new panic handler in release builds 2025-09-30 13:44:52 +01:00
mlugg
c1a30bd0d8
std: replace debug.Dwarf.ElfModule with debug.ElfFile
This abstraction isn't really tied to DWARF at all! Really, we're just
loading some information from an ELF file which is useful for debugging.
That *includes* DWARF, but it also includes other information. For
instance, the other change here:

Now, if DWARF information is missing, `debug.SelfInfo.ElfModule` will
name symbols by finding a matching symtab entry. We actually already do
this on Mach-O, so it makes obvious sense to do the same on ELF! This
change is what motivated the restructuring to begin with.

The symtab work is derived from #22077.

Co-authored-by: geemili <opensource@geemili.xyz>
2025-09-30 13:44:52 +01:00
mlugg
f798048739
std.debug: don't include dumpCurrentStackTrace frame
If it's not given, we should set `first_address` to the return address
of `dumpCurrentStackTrace` to avoid the call to `writeCurrentStackTrace`
appearing in the trace. However, we must only do that if no `context` is
given; if there's a context then we're starting the stack unwind
elsewhere.
2025-09-30 13:44:52 +01:00
mlugg
e6adddf80c
small reasonable change 2025-09-30 13:44:52 +01:00
mlugg
2743fdb7ce
std.debug: try removing a probably-redundant condition 2025-09-30 13:44:52 +01:00
mlugg
229f0a01b8
std.debug: handle ThreadContext slightly better
It's now user-overrideable, and uses `noreturn` types to neatly stop
analysis.
2025-09-30 13:44:52 +01:00
mlugg
1392a7af17
std.debug: unwinding on Windows
...using `RtlVirtualUnwind` on x86_64 and aarch64, and
`RtaCaptureStackBackTrace` on x86.
2025-09-30 13:44:52 +01:00
mlugg
ac4d633ed6
std: fix debug.Info and debug.Coverage 2025-09-30 13:44:52 +01:00
mlugg
f40fbdb3b3
link.Elf: restore eh_frame_hdr search table building
At least, when there's not a ZigObject. The old behavior was incorrect
in the presence of a ZigObject, and this doesn't really mix nicely with
incremental compilation anyway; but when the objects are all external,
we may as well build the search table.
2025-09-30 13:44:52 +01:00
mlugg
d9661e9e05
compiler: better crash handler
Far simpler, because everything which `crash_report.zig` did is now
handled pretty well by `std.debug` anyway. All we want is to print some
context around panics and segfaults. Using the new ability to override
the default segfault handler while still having std handle the
target-specific bits for us, that's really simple.
2025-09-30 13:44:52 +01:00
mlugg
3a561da38d
std: doc comments and tweaks 2025-09-30 13:44:51 +01:00
mlugg
0c7b2a7bd5
fix compiler ftbfs from std.macho and std.dwarf changes 2025-09-30 13:44:51 +01:00
mlugg
202aeacc05
std: fixes 2025-09-30 13:44:51 +01:00
mlugg
f1215adeda
SelfInfo.DarwinModule: rename field 2025-09-30 13:44:51 +01:00
mlugg
253fdfce70
SelfInfo: be honest about how general unwinding is
...in that it isn't: it's currently very specialized to DWARF unwinding.

Also, make a type unmanaged.
2025-09-30 13:44:51 +01:00
mlugg
9859440d83
add freestanding support IN THEORY
untested because this branch has errors rn
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
5709369d05
std.debug: improve the APIs and stuff 2025-09-30 13:44:51 +01:00
mlugg
d4f710791f
tweaks 2025-09-30 13:44:51 +01:00
mlugg
67fa5664b7
std.posix: mark getcontext as unsupported by default 2025-09-30 13:44:51 +01:00
mlugg
ba5d9d5a41
remove redundant test
turns out this actually has coverage in std.debug
2025-09-30 13:44:50 +01:00
mlugg
405075f745
SelfInfo: load eh_frame/debug_frame from ELF file if eh_frame_hdr omitted 2025-09-30 13:44:50 +01:00
mlugg
c895aa7a35
std.debug.SelfInfo: concrete error sets
The downside of this commit is that more precise errors are no longer
propagated up. However, these errors were pretty useless in isolation
due to them having no context; and regardless, we intentionally swallow
most of them in `std.debug` anyway. Therefore, this is better in
practice, because it allows `std.debug` to give slightly more useful
warnings when handling errors. This commit does that for unwind errors,
for instance, which differentiate between the unwind info being corrupt
vs missing vs inaccessible vs unsupported.

A better solution would be to also include more detailed information via
the diagnostics pattern, but this commit is an incremental improvement.
2025-09-30 13:44:50 +01:00
mlugg
dd9cb1beea
doc comments 2025-09-30 13:44:50 +01:00
mlugg
5e6a1919c7
fix aarch64-macos DWARF unwinding
turns out this isn't technically specific to that target at all; other
targets just don't emit mid-function 'ret' instructions as much so
certain CFI instruction patterns were only seen on aarch64.

thanks to jacob for finding the bug <3
2025-09-30 13:44:50 +01:00
mlugg
4b47a37717
stash? more like no 2025-09-30 13:44:50 +01:00
mlugg
665f13b0cd
SelfInfo deinit magic 2025-09-30 13:44:50 +01:00
mlugg
ba3f38959a
split SelfInfo into a file per impl 2025-09-30 13:44:50 +01:00
mlugg
1397b95143
std.debug.Dwarf: eliminate host pointer size dependency 2025-09-30 13:44:50 +01:00
mlugg
b762cd30fd
remove TODOs which are done or which i'm not actually gonna do lol 2025-09-30 13:44:50 +01:00
mlugg
e4dbfc109b
dont dupe state you silly billy 2025-09-30 13:44:50 +01:00
mlugg
8fdcdb8c69
the world if Dwarf.ElfModule was like REALLY good: 2025-09-30 13:44:49 +01:00
mlugg
84b65860cf
the world if ElfModule didn't suck: 2025-09-30 13:44:49 +01:00
mlugg
55a7affea4
me when i did a thing 2025-09-30 13:44:49 +01:00
mlugg
25e02bed4c
less hacky :D 2025-09-30 13:44:49 +01:00
mlugg
55ae6747e2
names 2025-09-30 13:44:49 +01:00
mlugg
3f6a90766c
sky pirates! which are even better! 2025-09-30 13:44:49 +01:00
mlugg
89d862180f
yet more 2025-09-30 13:44:49 +01:00
mlugg
fb88dab4c9
more still 2025-09-30 13:44:49 +01:00
mlugg
ed6ed62c42
more stuff 2025-09-30 13:44:49 +01:00
mlugg
b750e7cf9e
change one million things 2025-09-30 13:44:49 +01:00
Jacob Young
b706949736
debug: refactor stack frame capturing 2025-09-30 13:44:48 +01:00
Matthew Lugg
7adb15892e
Merge pull request #25353 from mlugg/x86_64-faster
x86_64: generate better constant memcpy code
2025-09-30 13:28:37 +01:00
Alex Rønne Petersen
df1909900c libc: update Linux headers to 6.17 2025-09-29 22:53:06 +02:00
Alex Rønne Petersen
f624191f9a
Merge pull request #25388 from alexrp/ksigaction
`std.os.linux`: Fix `k_sigaction` ABI issue on platforms w/o `SA_RESTORER`
2025-09-29 14:48:24 +02:00
Alex Rønne Petersen
fe468e4fa3
std.os.linux: delete restore and restore_rt for hexagon, loongarch, mips, riscv 2025-09-28 18:24:04 +02:00
Alex Rønne Petersen
42e4411377
std.os.linux: delete SA.RESTORER and k_sigaction.restorer for hexagon, loongarch, mips, riscv
The kABIs for these architectures don't define these concepts.
2025-09-28 18:23:58 +02:00
Alex Rønne Petersen
ba19c1104b
musl: delete dead __restore and __restore_rt functions for hexagon, loongarch64, riscv32, riscv64
https://www.openwall.com/lists/musl/2025/09/28/2
2025-09-28 17:04:56 +02:00
Alex Rønne Petersen
993a1a3df1
musl: delete SA_RESTORER for hexagon
https://github.com/quic/musl/pull/7
2025-09-28 16:25:24 +02:00
Alex Rønne Petersen
e89cb377d0
musl: delete SA_RESTORER for riscv32
https://www.openwall.com/lists/musl/2025/09/28/1
2025-09-28 15:54:21 +02:00
Alex Rønne Petersen
f90510b081 libcxx: respond to some feature macro changes in LLVM 20
ba87515fea

closes #25376
2025-09-28 14:45:31 +02:00
Jacob Young
a896a22932 x86_64: fix @mulAdd miscomp 2025-09-27 20:10:32 -04:00
Jacob Young
a744fbd22f x86_64: fix ~/! miscomps 2025-09-27 18:30:52 -04:00
Jacob Young
d79b3cc134 target: x86_64 backend can build compiler rt with coff
Without allowing this, the references to `compiler_rt.dll` emitted by
the coff linker will prevent the executable from running.
2025-09-27 18:30:52 -04:00
Jacob Young
b206b0626a x86_64: fix @floatFromInt miscomps 2025-09-27 18:30:52 -04:00
mlugg
237e8a5a7a tests: fix redundant target in matrix
Because -fno-llvm is now the default on x86_64-linux, this target was
exactly equivalent to one specified earlier in the matrix. This was
probably just missed when doing the work to enable the self-hosted
backend by default for x86_64.
2025-09-27 18:30:52 -04:00
mlugg
611c38e6da x86_64: fix unencodable rem lowerings
The memory operand might use one of the extended GPRs R8 through R15 and
hence require a REX prefix, but having a REX prefix makes the high-byte
register AH unencodeable as the src operand. This latent bug was exposed
by this branch, presumably because `select` now happens to be putting
something in an extended GPR instead of a legacy GPR.

In theory this could be fixed with minimal cost by introducing a way to
communicate to `select` that neither the destination memory nor the
other temporary can be in an extended GPR. However, I just went for the
simple solution which comes at a cost of one trivial instruction: copy
the remainder from AH to AL, and *then* copy AL to the destination.
2025-09-27 18:30:52 -04:00
mlugg
77fca1652f x86_64: fix miscompilation of mul on vectors of large ints 2025-09-27 18:30:52 -04:00
mlugg
0c476191a4 x86_64: generate better constant memcpy code
`rep movsb` isn't usually a great idea here. This commit makes the logic
which tentatively existed in `genInlineMemcpy` apply in more cases, and
in particular applies it to the "new" backend logic. Put simply, all
copies of 128 bytes or fewer will now attempt this path first,
where---provided there is an SSE register and/or a general-purpose
register available---we will lower the operation using a sequence of 32,
16, 8, 4, 2, and 1 byte copy operations.

The feedback I got on this diff was "Push it to master and if it
miscomps I'll revert it" so don't blame me when it explodes
2025-09-27 18:30:52 -04:00
Alex Rønne Petersen
1b0bde0d8d
Merge pull request #25373 from mneumann/fix-dragonfly-bootstrap
Fix DragonFly bootstrap
2025-09-27 20:05:40 +02:00
Alex Rønne Petersen
032df7202a
ci: remove -Dskip-translate-c from riscv64-linux scripts
This no longer exists and caused the build to fail.
2025-09-27 18:39:03 +02:00
Alex Rønne Petersen
1f7ee99b35 musl: add missing fenv C dummy functions for loongarch64-linux-muslsf
https://www.openwall.com/lists/musl/2025/09/27/1

closes #25367
2025-09-27 17:13:29 +02:00
Alex Rønne Petersen
b7ab625409
Merge pull request #25362 from alexrp/aro-valist
`aro`: `TypeStore`: synchronize `__va_list_tag` logic with Zig's `std.builtin.VaList`
2025-09-27 12:57:47 +02:00
Michael Neumann
035219132b lib/std/c: sync "struct stat" for DragonFly
* Add missing functions like ISDIR() or ISREG(). This is required to
  build the zig compiler

* Use octal notation for the S_ constants. This is how it is done for
  ".freebsd" and it is also the notation used by DragonFly in
  "sys/stat.h"

* Reorder S_ constants in the same order as ".freebsd" does. Again, this
  follows the ordering within "sys/stat.h"
2025-09-27 10:00:40 +02:00
Michael Neumann
19703a5db9 bootstrap: Add support for DragonFly 2025-09-27 10:00:36 +02:00
Ryan Liptak
b1a0a4e03b Update descriptions of -f[no-]error-tracing to match the actual behavior
Before https://github.com/ziglang/zig/pull/18160, error tracing defaulted to true in ReleaseSafe, but that is no longer the case. These option descriptions were never updating accordingly.
2025-09-26 14:01:17 -07:00
Alex Rønne Petersen
e98630aacf
aro: TypeStore: synchronize __va_list_tag logic with Zig's std.builtin.VaList
https://github.com/Vexu/arocc/pull/893

closes #25361
2025-09-26 16:24:59 +02:00
Alex Rønne Petersen
d16ff4d049
std.builtin: define VaList as *u8 for uefi 2025-09-26 16:20:24 +02:00
Alex Rønne Petersen
6ca52c00d9
std.builtin: remove dead powerpc-darwin handling for VaList 2025-09-26 16:20:24 +02:00
Alex Rønne Petersen
033d251626
std.builtin: define VaList for arc, csky, lanai, m68k, msp430, nvptx, ve, xcore 2025-09-26 16:20:24 +02:00
Alex Rønne Petersen
44c80fc6dc
std.builtin: sort VaList prongs a bit 2025-09-26 16:20:24 +02:00
Alex Rønne Petersen
4c798bb0bd
std.builtin: define VaList as struct { __ap: *anyopaque } for Arm per AAPCS 2025-09-26 16:20:15 +02: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
3b365a1f9b
Merge pull request #25351 from ziglang/chomp
std.mem: introduce cut functions; rename "index of" to "find"
2025-09-26 01:45:07 -07:00
Andrew Kelley
ad80a8b552 issue template: translate-c tracked by separate project 2025-09-25 20:36:58 -07:00
Alex Rønne Petersen
be24821464
ci: remove superfluous -Dtarget=native-native-none in x86_64-freebsd scripts 2025-09-26 02:41:28 +02: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
Andrew Kelley
2da8ec9865 fuzzing: fix off-by-one in limit count 2025-09-25 17:16:10 -07:00
Andrew Kelley
98253bc0ee Compilation: --debug-rt always Debug
--debug-rt previously would make rt libs match the root module. Now they
are always debug when --debug-rt is passed. This includes compiler-rt,
fuzzer lib, and others.
2025-09-25 17:15:47 -07:00
Alex Rønne Petersen
86077fe6bd compiler: move self-hosted backends from src/arch to src/codegen 2025-09-26 02:02:07 +02:00
Alex Rønne Petersen
212715f62d
test: remove pie test case from test-standalone
We already have test/cases/pie_linux.zig covering this.
2025-09-26 01:33:38 +02:00
Alex Rønne Petersen
459ad8c8e6
ci: stop passing -Dskip-translate-c -Dno-langref on loongarch64-linux
No longer necessary since we've stopped using Clang for this.
2025-09-26 01:33:38 +02:00
Alex Rønne Petersen
17f9a25924
test: remove -Dskip-translate-c from test-standalone
No longer necessary since we've stopped using Clang for this.
2025-09-26 01:33:26 +02:00
Andrew Kelley
2a88a6a456
Merge pull request #24497 from ziglang/aro-translate-c
compiler: update aro and translate-c to latest; delete clang translate-c
2025-09-25 14:18:49 -07:00
Andrew Kelley
14e227d8a6 std.mem: add cutLast and cutScalarLast 2025-09-25 11:38:38 -07:00
Andrew Kelley
97bef50dc3 std.mem: rename all "index of" functions
Moving towards our function naming convention of having one word per
concept and constructing function names out of concatenated concepts.
In `std.mem` the concepts are:
* "find" - return index of substring
* "pos" - starting index parameter
* "last" - search from the end
* "linear" - simple for loop rather than fancy algo
* "scalar" - substring is a single element
2025-09-25 11:28:58 -07:00
Andrew Kelley
3411b5e499 std.mem: add cut and cutScalar and example usage 2025-09-25 11:11:46 -07:00
Andrew Kelley
dd2f1cbebf std.mem: rename chomp to cut 2025-09-25 10:54:28 -07:00
Andrew Kelley
ccaf82d243 CLI: simpler semantics for prefixed integer args 2025-09-25 10:50:41 -07:00
Andrew Kelley
513389bc5b CLI: exploit std.mem.chompPrefix
fixes a bug in how -fstructured-cfg and -fno-structured-cfg are handled.
2025-09-25 10:50:41 -07:00
Andrew Kelley
ac4d79e322 std.mem: introduce chompPrefix and chompSuffix 2025-09-25 10:50:41 -07:00
Loris Cro
9bb0b43ea3 implement review suggestions 2025-09-25 18:20:19 +02:00
Alex Rønne Petersen
a73f246b29
std.Thread: disable test on armeb in addition to thumbeb
Same falky failure on both. See ed7ff0b693037078f451a7c6c1124611060f4892.
2025-09-25 17:49:47 +02:00
Alex Rønne Petersen
dd4be26f53 libc-test: disable daemon-failure.c
It's flaky in that systems with a high FD limit will get an unexpected ENOMEM
error from daemon(), failing the test.
2025-09-25 12:57:56 +02:00
Jacob Young
6257f4abb7 x86_64: improve support for large enums
Closes #25247
2025-09-24 21:20:27 -07:00
Andrew Kelley
5f763b7dc5 resinator: work around error VARARGS not implemented for this compiler 2025-09-24 21:04:46 -07:00
Zhenming-Lin
99323a4da1 improve impl of __floorh, __floorx, __ceilh and __ceilx 2025-09-24 20:57:25 -07:00
Andrew Kelley
41e5331c08 resinator: fix compile errors 2025-09-24 20:35:01 -07:00
Veikka Tuominen
d83c76eb5a update aro & translate-c 2025-09-24 20:01:19 -07:00
Andrew Kelley
e05073b9e4 aro does not have -mmacos version flags or -Wno-overriding-option 2025-09-24 20:01:19 -07:00
Andrew Kelley
3764f7b0f2 compiler: disable InternPool.debug_state as it is unsound
There can be more than one InternPool instance active at the same time.
2025-09-24 20:01:19 -07:00
Andrew Kelley
aa92c237e9 aro does not have a pragma-pack warning 2025-09-24 20:01:19 -07:00
Andrew Kelley
8cba6b1df8 aro: update
This is f5fb720a5399ee98e45f36337b2f68a4d23a783c plus ehaas's nonnull
attribute pull request currently at 4b26cb3ac610a0a070fc43e43da8b4cdf0e9101b
with zig patches intact.
2025-09-24 20:01:19 -07:00
Andrew Kelley
01132e0cf8 remove behavior test that depended on std.zig.c_translation
behavior tests may not depend on this namespace.
2025-09-24 20:01:19 -07:00
Andrew Kelley
79d9997d22 delete @cImport tests
These are now maintained in a separate repository: ziglang/translate-c
2025-09-24 20:01:19 -07:00
Andrew Kelley
e1d6f478c9 @cImport: don't pass args to Aro it doesn't understand 2025-09-24 20:01:19 -07:00
Andrew Kelley
9ad1e83e63 zig fmt 2025-09-24 20:01:19 -07:00
Andrew Kelley
f4d328e2ac Compilation: use renameTmpIntoCache
solves several problems with this pattern
2025-09-24 20:01:19 -07:00
Andrew Kelley
f0d3b7abb8 aro: fix dep file logic
also add ability to omit main source file from dep file as it messes up
caching strategy
2025-09-24 20:01:19 -07:00
Andrew Kelley
9e979e5a9d Compilation: re-implement cImport 2025-09-24 20:01:19 -07:00
Andrew Kelley
ea169e6ccf std.Build.Cache: clarify parameter is sub path, not basename 2025-09-24 20:01:19 -07:00
Andrew Kelley
b6930097ec translate-c: update for array list defaults 2025-09-24 20:01:19 -07:00
Andrew Kelley
e5f4dbdf8a fix rebase conflicts 2025-09-24 20:01:19 -07:00
Andrew Kelley
2f00b630f2 remove c_builtins.zig from cmake 2025-09-24 20:01:19 -07:00
Andrew Kelley
0f88f9c664 aro: avoid BoundedArray 2025-09-24 20:01:19 -07:00
Veikka Tuominen
21f5f06f1f Compilation: avoid passing Clang specific options to Aro 2025-09-24 20:01:18 -07:00
Veikka Tuominen
e7a622fb33 update aro and translate-c sources 2025-09-24 20:01:18 -07:00
Ryan Liptak
e8e8d7e5c8 resinator: Update for latest aro 2025-09-24 20:01:18 -07:00
Andrew Kelley
01d993b230 add translate-c CLI args 2025-09-24 20:01:18 -07:00
Andrew Kelley
8e27821b60 simplify diagnostics 2025-09-24 20:01:18 -07:00
Andrew Kelley
d1820d2a3e delete enough aro to make it compile 2025-09-24 20:01:18 -07:00
Andrew Kelley
328280b566 move translate-c helpers 2025-09-24 20:01:18 -07:00
Andrew Kelley
1bdcdbd996 delete all the translate-c tests
the ziglang/translate-c package has its own test suite, so these are
redundant
2025-09-24 20:01:17 -07:00
Andrew Kelley
f49a54745b compiler: update aro and translate-c to latest; delete clang translate-c 2025-09-24 19:57:28 -07:00
Alex Rønne Petersen
91b0adc4c1
Merge pull request #25231 from taylordotfish/bugfix/ppc-restore_rt
Fix `restore_rt` on PowerPC and remove unnecessary clobbers
2025-09-25 01:31:24 +02:00
Jacob Young
4a344de651 MappedFile: fix the insert range path not updating the root node 2025-09-24 16:09:46 -07:00
Jacob Young
94d319a10f x86_64: support more in/out forms
Closes #25303
2025-09-24 16:09:14 -07:00
Jacob Young
561e556aaf target: check for backend support for the new linker
Closes #25343
2025-09-24 16:08:26 -07:00
rpkak
9b3b7aa911 Integrate libc-test cases into the build system
zig build test-libc -Dlibc-test-path=/path/to/libc-test
2025-09-24 16:05:18 -07:00
rpkak
4fb08986cb optimize std.mem.swap 2025-09-24 12:29:43 -07:00
Loris Cro
0feacc2b81 fuzzing: implement limited fuzzing
Adds the limit option to `--fuzz=[limit]`. the limit expresses a number
of iterations that *each fuzz test* will perform at maximum before
exiting. The limit argument supports also 'K', 'M', and 'G' suffixeds
(e.g. '10K').

Does not imply `--web-ui` (like unlimited fuzzing does) and prints a
fuzzing report at the end.

Closes #22900 but does not implement the time based limit, as after
internal discussions we concluded to be problematic to both implement
and use correctly.
2025-09-24 12:46:48 +02:00
taylor.fish
c73df65ded Don't specify clobbers in restore_rt
Per @alexrp, this is unnecessary in naked functions.
2025-09-23 21:03:28 -07:00
taylor.fish
7f49dae284 Fix PowerPC restore_rt
Clang fails to compile the CBE translation of this code ("non-ASM
statement in naked function"). Similar to the implementations of
`restore_rt` on x86 and ARM, when the CBE is in use, this commit employs
alternative inline assembly that avoids using non-immediate input
operands.
2025-09-23 20:47:34 -07:00
Carter Snook
5bf52a6f50
std: always allow spawning processes when an env map is explicitly provided (#25092)
In a library, the two `builtin.link_libc` and `builtin.output_mode ==
.Exe` checks could both be false. Thus, you would get a compile error
even if you specified an `env_map` at runtime. This change turns the
compile error into a runtime panic and updates the documentation to
reflect the runtime requirement.
2025-09-24 03:12:28 +02:00
rpkak
bc512648db use copy_file_range syscall on linux 2025-09-24 03:08:12 +02:00
Kyle Schwarz
6260d2772f glibc: guard inet-fortified.h 2025-09-24 02:55:50 +02:00
taylor.fish
bdca0f93c4 Fix PowerPC syscalls causing invalid code from CBE
Fixes #25209.

On PowerPC, some registers are both inputs to syscalls and clobbered by
them. An example is r0, which initially contains the syscall number, but
may be overwritten during execution of the syscall.

musl and glibc use a `+` (read-write) constraint to indicate this, which
isn't supported in Zig. The current implementation of PowerPC syscalls
in the Zig standard library instead lists these registers as both inputs
and clobbers, but this results in the C backend generating code that is
invalid for at least some C compilers, like GCC, which doesn't support
the specifying the same register as both an input and a clobber.

This PR changes the PowerPC syscall functions to list such registers as
inputs and outputs rather than inputs and clobbers. Thanks to jacobly0
who pointed out that it's possible to have multiple outputs; I had
gotten the wrong idea from the documentation.
2025-09-24 02:54:55 +02:00
Andrew Kelley
ba137783ed
forbid trivial local address returned from functions (#25333)
progress towards #25312
2025-09-23 23:37:53 +00:00
Alex Rønne Petersen
7b92d5f405
std.pie: fix register constraint in getDynamicSymbol() for s390x (#25327)
If the compiler happens to pick `ret = r0`, then this will assemble to
`ag r0, 0` which is obviously not what we want. Using `a` instead of `r` will
ensure that we get an appropriate address register, i.e. `r1` through `r15`.

Re-enable pie_linux for s390x-linux which was disabled in
ed7ff0b693037078f451a7c6c1124611060f4892.
2025-09-22 18:36:47 +02:00
Alex Rønne Petersen
26825e9506
Merge pull request #25324 from alexrp/freebsd
Some changes to prepare for FreeBSD CI
2025-09-22 05:04:31 +02:00
Alex Rønne Petersen
16c18b835e
ci: stop building FreeBSD module tests on x86_64-linux
They're now built on the x86_64-freebsd machine.
2025-09-22 01:39:29 +02:00
alexrp
3675074c7c
ci: add x86_64-freebsd scripts 2025-09-22 01:37:32 +02:00
alexrp
b3432c2796
test: disable some stack trace tests on FreeBSD 2025-09-22 01:37:32 +02:00
alexrp
b2d2b441b2
test: disable test-link on FreeBSD
https://github.com/ziglang/zig/issues/25323
2025-09-22 01:37:32 +02:00
alexrp
f7d62009ff
std.posix: remove bogus assert that SIGRTMAX < NSIG 2025-09-22 01:37:32 +02:00
alexrp
0700ec35bd
compiler: don't use self-hosted backend on any BSD yet
There are some blocking bugs in the self-hosted ELF linker.
2025-09-22 01:37:32 +02:00
Jacob Young
f58200e3f2 Elf2: create a new linker from scratch
This iteration already has significantly better incremental support.

Closes #24110
2025-09-21 14:09:14 -07:00
Andrew Kelley
2a97e0af6d CI: stop testing x86_64-macos
There are two reasons for this:

1. Apple is about to drop support for this target. Zig will keep support
   but move it to a lower tier - one that does not require continuous CI
   testing. Support for this target will be maintained by the enthusiasm
   of contributors but will not block other bug fixes and enhancements.
2. This is our only non-self-hosted action runner. We are migrating away
   from GitHub soon at which point this runner will no longer be
   available.
2025-09-21 12:36:50 -07:00
Alex Rønne Petersen
4d8dcccbd4
ci: temporarily disable riscv64-linux
GitHub sucks:

    Sep 20 20:49:21 ganymede runsvc.sh[82817]: An error occured: Runner version v2.326.0 is deprecated and cannot receive messages.
    Sep 20 20:49:21 ganymede runsvc.sh[82817]: Runner listener exited with error code 1
    Sep 20 20:49:21 ganymede runsvc.sh[82817]: Runner listener exit with terminated error, stop the service, no retry needed.
2025-09-21 17:29:57 +02:00
Frank Denis
bdc31c9561 aarch64/zonCast: don't return a pointer to a stack element
Elements are computed at comptime, so don't declare them as "var".
2025-09-21 05:01:41 -07:00
Andrew Kelley
594cb38fcb
Merge pull request #25302 from ziglang/growCapacity
std: remove loop from growCapacity
2025-09-21 04:55:39 -07:00
Andrew Kelley
010d9a63f2
Merge pull request #25154 from ziglang/no-decl-val-3
rework byval ZIR instructions; forbid runtime vector indexes
2025-09-21 01:49:28 -07:00
Andrew Kelley
633162eb0c add behavior test: comptime C pointer to optional pointer 2025-09-20 18:58:32 -07:00
Andrew Kelley
1c9ac9dbb7 add behavior test: avoid unused field function body compile error 2025-09-20 18:51:43 -07:00
Andrew Kelley
500afbf076 add behavior test: resist alias of explicit copy...
...of array passed as arg

closes #22906
2025-09-20 18:51:26 -07:00
Andrew Kelley
ed7ff0b693 allow some test cases to regress
tracked by #24061 - these should be re-enabled once that is solved.
2025-09-20 18:33:01 -07:00
mlugg
0e16d933be fix rebase error 2025-09-20 18:33:01 -07:00
mlugg
20925f2957 Revert "frontend: another packedStructFieldPtrInfo fix"
This reverts commit dedccecda944f88a5278c12c24ffbea46126de63.
2025-09-20 18:33:01 -07:00
Jacob Young
f81a721e41 standalone: fix misaligned stack crash 2025-09-20 18:33:01 -07:00
Jacob Young
5144f10ec9 aarch64: fix behavior failures 2025-09-20 18:33:01 -07:00
Jacob Young
60cdacaff2 x86_64: rewrite vector element pointer access 2025-09-20 18:33:01 -07:00
Andrew Kelley
2ba03e98c8 disable failing stage2_aarch64 behavior tests 2025-09-20 18:33:01 -07:00
Andrew Kelley
5d8c1fb6ab frontend: another packedStructFieldPtrInfo fix
it was calculating host integer size in a wrong way. just use integer
abi size
2025-09-20 18:33:01 -07:00
mlugg
baaf715d21 cases: update for new error
The latest bugfix reverted this case to its old behavior (which is a
reasonable behavior to have).
2025-09-20 18:33:01 -07:00
mlugg
fcc7e378f8 Revert "delete failing test case"
This reverts commit ba4d4602ab9bb0dc17fc0d57141d9324bdbb356d.
2025-09-20 18:33:01 -07:00
mlugg
2f9d8d5a9b Zcu: fix analysis of type of decl with inferred type
If the `nav_ty` is resolved by the `nav_val`, then we need to also mark
the `nav_ty` as in progress when we begin resolving the `nav_val`.
2025-09-20 18:33:01 -07:00
Andrew Kelley
d7d50496d9 langref: don't assume too much about pointer to packed struct field 2025-09-20 18:33:01 -07:00
Andrew Kelley
725dec6aa7 Sema: add missed logic to checkPtrAttributes
It wasn't checking bit pointer data.
2025-09-20 18:33:01 -07:00
Andrew Kelley
7ffe068a79 delete failing test case
Matthew can revert this commit when he's ready to tackle the assertion
failure
2025-09-20 18:33:01 -07:00
Jacob Young
cbbb67c5df x86_64: fix safety crashes in storeRegs 2025-09-20 18:33:01 -07:00
Andrew Kelley
0681bf06ab frontend: packed struct field ptr no longer finds byte borders
technically breaking, but I doubt anyone will notice.
2025-09-20 18:33:01 -07:00
Andrew Kelley
e1a750655e disable wasm backend coverage
Disabled due to no active maintainer (feel free to fix the failures and
then re-enable at any time). The failures occur due to backend
miscompilation of different AIR from the frontend.
2025-09-20 18:33:01 -07:00
Andrew Kelley
c369def08e disable spirv64-vulkan coverage
Disabled due to no active maintainer (feel free to fix the failures and
then re-enable at any time). The failures occur due to changing AIR from
the frontend, and backend being incomplete.
2025-09-20 18:33:00 -07:00
Andrew Kelley
c0bbddb007 Sema: avoid ptr_add/ptr_sub instructions void elem type 2025-09-20 18:33:00 -07:00
Andrew Kelley
aacff8c800 add compile error coverage for dependency loop 2025-09-20 18:33:00 -07:00
Andrew Kelley
7b8a7989ef frontend: additionally handle C pointers in ptrOptPayload 2025-09-20 18:33:00 -07:00
Jacob Young
2fdf0e29b3 aarch64: enable fixed behavior 2025-09-20 18:33:00 -07:00
Andrew Kelley
e5adfd87bc translate-c: remove cases associated with runtime vector indexing
C translation is in the process of switching to be aro-based
(see #24497)

That codebase will need to gain some kind of helper for translating C
code that uses runtime vector indexing.
2025-09-20 18:33:00 -07:00
Andrew Kelley
f0fe55a9bb frontend: fix too strict assertion
field ptr can be based on C pointer
2025-09-20 18:33:00 -07:00
Jacob Young
f12c4f86fc aarch64: implement ptr_slice_*_ptr 2025-09-20 18:33:00 -07:00
Andrew Kelley
5ec0a7d8a5 coerce vectors to arrays rather than inline for 2025-09-20 18:33:00 -07:00
Andrew Kelley
9b74651cd2 Sema: fix YAGNI violation 2025-09-20 18:33:00 -07:00
Andrew Kelley
4fef90fa92 Sema: more conservative elem_ptr_load implementation
like field_ptr_load, this now does byval operations when the lhs is
comptime-known.
2025-09-20 18:33:00 -07:00
Andrew Kelley
9afa6835df frontend: replace elem_val_node with elem_ptr_load
avoids unnecessary copies
2025-09-20 18:33:00 -07:00
Andrew Kelley
95439c9820 std.Progress: avoid problematic catch syntax 2025-09-20 18:33:00 -07:00
Andrew Kelley
354c17869a frontend: replace field_val and field_val_named
with field_ptr_load and field_ptr_named_load.

These avoid doing by-val load operations for structs that are
runtime-known while keeping the previous semantics for comptime-known
values.
2025-09-20 18:33:00 -07:00
Andrew Kelley
3bd62e1bb6 Sema: fix source location of "declared here" note
point at the var not at the init expression
2025-09-20 18:33:00 -07:00
Andrew Kelley
d00aee021b x86 codegen: handle spilled tuples 2025-09-20 18:33:00 -07:00
Andrew Kelley
09e4fc4dcf std.zon.parse: fix not initializing array sentinel 2025-09-20 18:33:00 -07:00
Andrew Kelley
772793c004 Sema: fix accessing ptr field of double array pointer with sentinel 2025-09-20 18:33:00 -07:00
Andrew Kelley
426af68b7d compiler: require comptime vector indexes 2025-09-20 18:33:00 -07:00
Andrew Kelley
14bda4130a llvm backend: remove canElideLoad mechanism 2025-09-20 18:33:00 -07:00
Ryan Liptak
3fbb88c4bd Reader.defaultReadVec: Workaround bad r.end += r.vtable.stream() behavior
If `r.end` is updated in the `stream` implementation, then it's possible that `r.end += ...` will behave unexpectedly. What seems to happen is that it reverts back to its value before the function call and then the increment happens. Here's a reproduction:

```zig
test "fill when stream modifies `end` and returns 0" {
    var buf: [3]u8 = undefined;
    var zero_reader = infiniteZeroes(&buf);

    _ = try zero_reader.fill(1);
    try std.testing.expectEqual(buf.len, zero_reader.end);
}

pub fn infiniteZeroes(buf: []u8) std.Io.Reader {
    return .{
        .vtable = &.{
            .stream = stream,
        },
        .buffer = buf,
        .end = 0,
        .seek = 0,
    };
}

fn stream(r: *std.Io.Reader, _: *std.Io.Writer, _: std.Io.Limit) std.Io.Reader.StreamError!usize {
    @memset(r.buffer[r.seek..], 0);
    r.end = r.buffer.len;
    return 0;
}
```

When `fill` is called, it will call into `vtable.readVec` which in this case is `defaultReadVec`. In `defaultReadVec`:

- Before the `r.end += r.vtable.stream` line, `r.end` will be 0
- In `r.vtable.stream`, `r.end` is modified to 3 and it returns 0
- After the `r.end += r.vtable.stream` line, `r.end` will be 0 instead of the expected 3

Separating the `r.end += stream();` into two lines fixes the problem (and this separation is done elsewhere in `Reader` so it seems possible that this class of bug has been encountered before).

Potentially related issues:

- https://github.com/ziglang/zig/issues/4021
- https://github.com/ziglang/zig/issues/12064
2025-09-20 18:31:38 -07:00
Andrew Kelley
0e47bd16da add behavior test: return undefined pointer from function
This clarifies that it is legal to return an invalid pointer from a
function, provided that such pointer is not dereferenced.

This matches current status quo of the language. Any change to this
should be a proposal that argues for different semantics.

It is also legal in C to return a pointer to a local. The C backend
lowers such thing directly, so the corresponding warning in C must be
disabled (`-Wno-return-stack-address`).
2025-09-20 17:49:00 -07:00
Andrew Kelley
3cc0fc601a std.json: delete test tightly coupled to ArrayList growth
This test works by assuming that std.ArrayList will grow with a specific
capacity increasing pattern, which is an invalid assumption. Delete the
offending test.
2025-09-20 14:38:01 -07:00
Andrew Kelley
0c1fbc4ea6 std: remove loop from growCapacity
I measured this against master branch and found no statistical
difference. Since this code is simpler and logically superior due to
always leaving sufficient unused capacity when growing, it is preferred
over status quo.
2025-09-20 14:34:18 -07:00
Andrew Kelley
4d1b15bd9d
Merge pull request #25298 from ziglang/SegmentedList-orphaned-again
std: delete SegmentedList again
2025-09-20 10:29:02 -07:00
John Benediktsson
14fc4d4811 std.c: add MSG support for dragonfly 2025-09-20 19:21:14 +02:00
Alex Rønne Petersen
7857bbd116 std.crypto.ascon: disable Ascon-AEAD128 test on RISC-V with V support 2025-09-20 19:05:32 +02:00
John Benediktsson
1ac4c27d74 std.c: adjust shm_open to be variadic on darwin 2025-09-20 07:33:50 +02:00
Justus Klausecker
be571f32c3 std.Build.Step.Run: Enable passing (generated) file content as args
Adds `addFileContentArg` and `addPrefixedFileContentArg` to pass the content
of a file with a lazy path as an argument to a `std.Build.Step.Run`.
This enables replicating shell `$()` / cmake `execute_process` with `OUTPUT_VARIABLE`
as an input to another `execute_process` in conjuction with `captureStdOut`/`captureStdErr`.

To also be able to replicate `$()` automatically trimming trailing newlines and cmake
`OUTPUT_STRIP_TRAILING_WHITESPACE`, this patch adds an `options` arg to those functions
which allows specifying the desired handling of surrounding whitespace.

The `options` arg also allows to specify a custom `basename` for the output. e.g.
to add a file extension (concrete use case: Zig `@import()` requires files to have a
`.zig`/`.zon` extension to recognize them as valid source files).
2025-09-19 17:38:40 -07:00
Andrew Kelley
1eeb8fabe5 std: delete SegmentedList again
The data structure was originally added in
41e1cd185b82a518c58c92544c45f0348c03ef74 and then removed in
50a336fff899ebd8a687c453ec6beb18a5a9baf9, but brought back in
711bf55eaa643c3d05640bebbf3e4315477b8ed8 for Decl in the compiler
frontend, and then the last reference to it was eliminated in
548a087fafeda5b07d2237d5137906b8d07da699 which removed Decl in favor of
Nav and Cau.
2025-09-19 16:40:00 -07:00
Andrew Kelley
4a38d783e8 tools: eliminate dependency on std.SegmentedList 2025-09-19 16:40:00 -07:00
Andrew Kelley
164c598cd8
Merge pull request #23416 from gooncreeper/improved-fuzzer
greatly improve capabilities of the fuzzer
2025-09-19 09:27:25 -07:00
Frank Denis
bc921fec12 Fix duplicate LC_RPATH entries on macOS Tahoe
When building on macOS Tahoe, binaries were getting duplicate LC_RPATH
load commands which caused dyld to refuse to run them with a
"duplicate LC_RPATH" error that has become a hard error.

The duplicates occurred when library directories were being added
to rpath_list twice:

- from lib_directories
- from native system paths detection which includes the same dirs
2025-09-19 16:39:00 +02:00
Alex Rønne Petersen
97df4ae3ce
Merge pull request #25268 from alexrp/loongarch
Miscellaneous LoongArch work to prepare for CI
2025-09-19 12:09:48 +02:00
andrewkraevskii
de489031d8 Remove usages of deprecatedWriter 2025-09-18 22:39:33 -07:00
John Benediktsson
37ecaae639
std.fmt: migrate bufPrintZ to bufPrintSentinel (#25260) 2025-09-19 05:02:22 +00:00
Alex Rønne Petersen
47c932f896 std.simd: suggest more sensible vector sizes across the board 2025-09-19 04:01:08 +02:00
Kendall Condon
7c6ccca46d fuzzer: remove rodata load tracing
This can be re-evaluated at a later time, but at the moment the
performance and stability concerns hold it back. Additionally, it
promotes a non-smithing approach to fuzz tests.
2025-09-18 18:56:18 -04:00
Kendall Condon
b905c65661 add some new fuzz tests 2025-09-18 18:56:18 -04:00
Kendall Condon
e66b269333 greatly improve capabilities of the fuzzer
This PR significantly improves the capabilities of the fuzzer.

The changes made to the fuzzer to accomplish this feat mostly include
tracking memory reads from .rodata to determine fresh inputs, new
mutations (especially the ones that insert const values from .rodata
reads and __sanitizer_conv_const_cmp), and minimizing found inputs.
Additionally, the runs per second has greatly been increased due to
generating smaller inputs and avoiding clearing the 8-bit pc counters.

An additional feature added is that the length of the input file is now
stored and the old input file is rerun upon start.

Other changes made to the fuzzer include more logical initialization,
using one shared file `in` for inputs, creating corpus files with
proper sizes, and using hexadecimal-numbered corpus files for
simplicity.

Furthermore, I added several new fuzz tests to gauge the fuzzer's
efficiency. I also tried to add a test for zstandard decompression,
which it crashed within 60,000 runs (less than a second.)

Bug fixes include:
* Fixed a race conditions when multiple fuzzer processes needed to use
the same coverage file.
* Web interface stats now update even when unique runs is not changing.
* Fixed tokenizer.testPropertiesUpheld to allow stray carriage returns
since they are valid whitespace.
2025-09-18 18:56:10 -04:00
Frank Denis
19943f0f21 zig fmt help: mention that the argument can be a directory
I’ve been typing `zig fmt **/.zig` for a long time, until I discovered
that the argument can actually be a directory.

Mention this feature explicitly in the help message.
2025-09-18 22:15:57 +02:00
Alex Rønne Petersen
c26c5a3c1b
ci: add loongarch64-linux scripts 2025-09-18 12:42:24 +02:00
Alex Rønne Petersen
4aa35160eb
stage1: update zig1.wasm
Needed due to LoongArch CPU model changes.

Signed-off-by: Alex Rønne Petersen <alex@alexrp.com>
2025-09-18 12:42:24 +02:00
Alex Rønne Petersen
5e9e1fb0c8
std.Target: adjustments to LoongArch CPU models
* Remove the generic model; we already have generic_la32 and generic_la64 and
  pick appropriately based on bitness.
* Remove the loongarch64 model. We used this as our baseline for 64-bit, but it's
  actually pretty misleading and useless; it doesn't represent any real CPU and
  has less features than generic_la64.
* Add la64v1_0 and la64v1_1 models.
* Change our baseline CPU model for 64-bit to be la64v1_0, thus adding LSX to
  the baseline feature set.
2025-09-18 12:42:24 +02:00
Alex Rønne Petersen
6208e74145
std.zig.system: implement native CPU detection for LoongArch
ref #4591
2025-09-18 12:42:24 +02:00
Alex Rønne Petersen
f1c2ae271c
test: disable some SIMD ABI tests on LoongArch 2025-09-18 12:42:24 +02:00
Alex Rønne Petersen
beb25b0430
test: disable some vector ctz/clz behavior tests on LoongArch with LSX
https://github.com/llvm/llvm-project/issues/159529
2025-09-18 12:42:24 +02:00
Alex Rønne Petersen
35d2b1e99a
std.math.modf: disable vector test on LoongArch with LSX
https://github.com/llvm/llvm-project/issues/159529
2025-09-18 12:42:24 +02:00
Alex Rønne Petersen
c8c3882380
std.crypto.ml_kem: disable some Kyber tests on LoongArch with LSX
LLVM miscompiles these.
2025-09-18 12:42:24 +02:00
Alex Rønne Petersen
9095a7fefd
test: respect -Dskip-translate-c in test-standalone 2025-09-18 12:42:24 +02:00
Alex Rønne Petersen
4e9b8aec2c
test: remove unnecessary @cImport usage in some standalone tests 2025-09-18 12:42:24 +02:00
Alex Rønne Petersen
abd73083e4
test: skip dumpCurrentStackTrace test on architectures with no unwind support 2025-09-18 12:42:24 +02:00
Alex Rønne Petersen
e06bcd74c3
test: re-enable test-std for loongarch64-linux 2025-09-18 12:42:24 +02:00
Alex Rønne Petersen
f90548e740
test: skip alternative constraints behavior test on LoongArch
https://github.com/llvm/llvm-project/issues/159200
2025-09-18 12:42:14 +02:00
Alex Rønne Petersen
e7f1624e6e
std.mem: work around LoongArch inline asm bug in doNotOptimizeAway()
https://github.com/llvm/llvm-project/issues/159200
2025-09-18 10:08:38 +02:00
Alex Rønne Petersen
c547a05b65
langref: runtime_shrExact_overflow does not work as expected on LoongArch
https://github.com/ziglang/zig/issues/24304
2025-09-18 10:08:38 +02:00
Andrew Kelley
d6b4e1918b
Merge pull request #25195 from blblack/netdefs
std: Add several sockopt-related constants and structs
2025-09-17 21:43:23 -07:00
Silver
65a6bf1267
fix handling of comptime-only union fields in Type.getUnionLayout (#25182)
Fixes #25180
2025-09-17 21:39:47 -07:00
Andrew Kelley
220c679523
Merge pull request #25197 from rootbeer/24380-flaky-sigset-test
Re-enable std.posix "sigset_t bits" test
2025-09-17 21:19:01 -07:00
Jacob Young
09bc118c9f Elf: implement linksection
Closes #24330
2025-09-17 21:16:23 -07:00
Andrew Kelley
8e9f2f02d2
Merge pull request #25201 from jacobly0/x86_64-addsat
x86_64: fix strictness edge cases in `+|`
2025-09-17 21:15:03 -07:00
Andrew Kelley
d2e4ad613b
Merge pull request #25217 from blblack/setsiderr
std.os.linux.setsid(): return raw syscall0 result
2025-09-17 21:14:08 -07:00
Andrew Kelley
0df89cd0e1
Merge pull request #25225 from Justus2308/darwin-fixes
std.*.ptrace: support more platforms and features more correctly
2025-09-17 21:11:28 -07:00
Ryan Liptak
c330d2bdde mem.replace: Document that input/output cannot overlap 2025-09-17 20:12:03 -07:00
rohlem
92223ad36f langref: mention union support of @fieldParentPtr 2025-09-17 20:07:30 -07:00
Andrew Kelley
b782cdb9b3
Merge pull request #25249 from jedisct1/siv
std.crypto: add AES-SIV and AES-GCM-SIV
2025-09-17 20:05:23 -07:00
Frank Denis
4406127cca
std.crypto: add Ascon-AEAD, Ascon-Hash, Ascon-CHash (#25239)
Ascon is the family of cryptographic constructions standardized by NIST
for lightweight cryptography.

The Zig standard library already included the Ascon permutation itself,
but higher-level constructions built on top of it were intentionally
postponed until NIST released the final specification.

That specification has now been published as NIST SP 800-232:
https://csrc.nist.gov/pubs/sp/800/232/final

With this publication, we can now confidently include these constructions
in the standard library.
2025-09-17 19:59:55 -07:00
Frank Denis
6dd0270a19
std.sort.pdq: fix out-of-bounds access in partialInsertionSort (#25253)
* std.sort.pdq: fix out-of-bounds access in partialInsertionSort

When sorting a sub-range that doesn't start at index 0, the
partialInsertionSort function could access indices below the range
start. The loop condition `while (j >= 1)` didn't respect the
arbitrary range boundaries [a, b).

This changes the condition to `while (j > a)` to ensure indices
never go below the range start, fixing the issue where pdqContext
would access out-of-bounds indices.

Fixes #25250
2025-09-17 19:54:15 -07:00
marko
4314c9653a use block break instead of return 2025-09-17 19:45:33 -07:00
Alex Rønne Petersen
ae00a2a84d
Merge pull request #25257 from linusg/bump-macos-headers
libc: Update macOS headers to SDK 26.0
2025-09-17 15:35:48 +02:00
Frank Denis
8e8a143d62
Avoid logic where we return success in case of an error (#25251)
In ed25519.zig, we checked if a test succeeds, in which case we
returned an error. This was confusing, and Andrew pointed out that
Zig weights branches against errors by default.
2025-09-17 12:09:35 +02:00
Alex Rønne Petersen
9819f53453
Some miscellaneous test suite cleanups (#25256)
* test: remove test-compare-output and test-asm-link tests

These were low value and unfocused tests. We already have coverage of the
important aspects of these tests elsewhere. Additionally, there was really no
need for these to have their own test harness.

* test: rename issue_8550 standalone test to compile_asm

* test: rename backend=stage2 to backend=selfhosted, and add backend=auto

backend=auto (now the default if backend is omitted) means to let the compiler
pick whatever backend it wants as the default. This is important for platforms
where we don't yet have a self-hosted backend, such as loongarch64.

Also purge a bunch of redundant target=native.

* test: delete old stage1 compile_errors tests

generic_function_returning_opaque_type.zig was salvaged as it's still worth
having.

* test: pull tests in test/cases/llvm/ up to test/cases/

There is nothing inherently LLVM-specific about any of these.

* test: remove @cImport usage in interdependent_static_c_libs

* test: move glibc_compat from link to standalone tests

This is not really testing the linker.

* build: -Dskip-translate-c now implies -Dskip-run-translated-c

* build: skip test-cimport when -Dskip-translate-c is given
2025-09-17 08:11:41 +02:00
Alex Rønne Petersen
aae90762cc
build: skip test-cimport when -Dskip-translate-c is given 2025-09-16 23:39:29 +02:00
Alex Rønne Petersen
d12aed5f14
build: -Dskip-translate-c now implies -Dskip-run-translated-c 2025-09-16 23:39:29 +02:00
Alex Rønne Petersen
a5bb7108a9
test: move glibc_compat from link to standalone tests
This is not really testing the linker.
2025-09-16 23:39:29 +02:00
Alex Rønne Petersen
ab1946de92
test: remove @cImport usage in interdependent_static_c_libs 2025-09-16 23:39:29 +02:00
Alex Rønne Petersen
4dba253cd2
test: pull tests in test/cases/llvm/ up to test/cases/
There is nothing inherently LLVM-specific about any of these.
2025-09-16 23:39:29 +02:00
Alex Rønne Petersen
589e564f16
test: delete old stage1 compile_errors tests
generic_function_returning_opaque_type.zig was salvaged as it's still worth
having.
2025-09-16 23:39:29 +02:00
Alex Rønne Petersen
2e3fac3626
test: rename backend=stage2 to backend=selfhosted, and add backend=auto
backend=auto (now the default if backend is omitted) means to let the compiler
pick whatever backend it wants as the default. This is important for platforms
where we don't yet have a self-hosted backend, such as loongarch64.

Also purge a bunch of redundant target=native.
2025-09-16 23:39:26 +02:00
Frank Denis
b1b2cd7ef8 Parallelize deriveKeys 2025-09-16 23:13:58 +02:00
Frank Denis
5eb7610112 Import crypto/aes_gcm_siv.zig 2025-09-16 23:01:16 +02:00
Linus Groh
93218eacaa libc: Update macOS headers to SDK 26.0 2025-09-16 21:15:13 +01:00
Linus Groh
70715ced95 tools: Update fetch_them_macos_headers.zig for macOS 26 2025-09-16 21:13:38 +01:00
mlugg
580b6d1fad llvm: fix tagged union payload size in debug info
Resolves: #24415
2025-09-16 18:55:19 +01:00
Alex Rønne Petersen
d5c73a44b7
test: rename issue_8550 standalone test to compile_asm 2025-09-16 14:51:29 +02:00
Alex Rønne Petersen
fc20677fde
test: remove test-compare-output and test-asm-link tests
These were low value and unfocused tests. We already have coverage of the
important aspects of these tests elsewhere. Additionally, there was really no
need for these to have their own test harness.
2025-09-16 14:51:03 +02:00
Frank Denis
dd46e07fb9 std.crypto: add AES-SIV and AES-GCM-SIV
The Zig standard library lacked schemes that resist nonce reuse.

AES-SIV and AES-GCM-SIV are the standard options for this.

AES-GCM-SIV can be very useful when Zig is used to target embedded
systems, and AES-SIV is especially useful for key wrapping.

Also take it as an opportunity to add a bunch of test vectors to
modes.ctr and make sure it works with block ciphers whose size is
not 16.
2025-09-16 12:45:08 +02:00
George Huebner
496313a1bd bpf: use bitCast instead of intCast in ld_imm_impl
Any 32 bit immediate is allowed in a BPF instruction, including those
greater than the largest positive i32 value.
2025-09-15 15:24:30 +02:00
mlugg
8744865425 frontend: fix reference tracking through coerced function bodies
This bug was manifesting for user as a nasty link error because they
were calling their application's main entry point as a coerced function,
which essentially broke reference tracking for the entire ZCU, causing
exported symbols to silently not get exported.

I've been a little unsure about how coerced functions should interact
with the unit graph before, but the solution is actually really obvious
now: they shouldn't! `Sema` is now responsible for unwrapping
possibly-coerced functions *before* queuing analysis or marking unit
references. This makes the reference graph optimal (there are no
redundant edges representing coerced versions of the same function) and
simplifies logic elsewhere at the expense of just a few lines in Sema.
2025-09-15 11:29:31 +01:00
database64128
377a8b2a3b std.net.Ip6Address: format numerical scope id 2025-09-15 10:45:35 +01:00
mlugg
32a1aabff7 std.math.big.int: normalize zero result for small multiplications
Resolves: #25221
2025-09-13 17:13:27 +01:00
Justus Klausecker
1b4508cfb3 std.os.linux.ptrace: add PTRACE_EVENT_* and PTRACE_O_* values 2025-09-13 14:43:15 +02:00
Justus Klausecker
9b4cae4750 std.posix.ptrace: support more platforms more correctly 2025-09-13 14:35:19 +02:00
Brandon Black
6dbfba526f linux: Doc and check retval for no-fail pid calls
The switch from @bitCast() to @intCast() here safety-checks
Linux's assertion that these 3 calls never return errors (negative
values as pid_t).  getppid() can legally return 0 if the parent is
in a different pid namespace, but this is not an error.
2025-09-12 07:20:08 -05:00
Brandon Black
04071d64bb std.os.linux.setsid(): return raw syscall0 result
When not linking libc on 64-bit Linux and calling posix.setsid(),
we get a type error at compile time inside of posix.errno().  This
is because posix.errno()'s non-libc branch expects a usize-sized
value, which is what all the error-returning os.linux syscalls
return, and linux.setsid() instead returned a pid_t, which is only
32 bits wide.

This and the other 3 pid-related calls just below it (getpid(),
getppid(), and gettid()) are the only Linux syscall examples here
that are casting their return values to pid_t. For the other 3
this makes sense: those calls are documented to have no possible
errors and always return a valid pid_t value.

However, setsid() actually can return the error EPERM, and
therefore needs to return the raw value from syscall0 for
posix.errno() to process like normal.

Additionally, posix.setsid() needs an @intCast(rc) for the success
case as a result, like most other such cases.
2025-09-12 07:19:01 -05:00
Brandon Black
a0ec4e270e std.os.linux.socketpair(): switch to unsigned args
We need std.os.linux and std.c to agree on the types here, or else
we'd have to pointlessly cast across the difference up in the
std.posix wrapper.  I ran into this as a type error the first time
I tried to compile my code that calls posix.socketpair() on Linux
without libc.

All of our existing socket calls with these kinds of arguments in
std (including the existing c.socketpair as well as
os.linux.socket in this same file) use unsigned for all of these
parameters, and so this brings linux.socketpair() into alignment
with everything else.
2025-09-12 07:01:04 +02:00
Alex Rønne Petersen
4972c987fd compiler-rt: export __aeabi_read_tp for arm-freebsd
FreeBSD normally provides this symbol in libc, but it's in the
FBSDprivate_1.0 namespace, so it doesn't get included in our abilists file.
Fortunately, the implementation is identical for Linux and FreeBSD, so we can
just provide it in compiler-rt.

It's interesting to note that the same is not true for NetBSD where the
implementation is more complex to support older Arm versions. But we do include
the symbol in our abilists file for NetBSD libc, so that's fine.

closes #25215
2025-09-11 23:28:26 +02:00
Sardorbek Imomaliev
6b8cef8107
Fix standalone test simple/cat/main.zig after Writergate update (#25188)
* Make cat in test/standalone/simple working again

- Fixes:
    zig/0.15.1/lib/zig/std/Io/Writer.zig:939:11: 0x1049aef63 in sendFileAll (nclip)
        assert(w.buffer.len > 0);
- because we are no using non zero buffers for stdout - "do not forget to flush"

* replace std.fs with fs because we are already importing it
2025-09-11 16:43:11 +00:00
marko
fb3afc8d3d use pointer subtraction 2025-09-11 00:18:37 -07:00
Jacob Young
a2ba7dd1c2 x86_64: fix @splat typo 2025-09-10 23:14:10 -04:00
Jacob Young
e313b387a0 x86_64: delete usages of avx2 vpack?s??
This instruction actually has fairly useless semantics, and even the
cases that were semantically correct could save 1 cycle of latency by
using a different sequnce involving the avx version instead.

Closes #25174
2025-09-10 22:40:26 -04:00
Jacob Young
1a0a9d7d59 x86_64: fix strictness edge cases in +|
Closes #25145
2025-09-10 21:01:13 -04:00
Andrew Kelley
bfda12efcf
Merge pull request #24968 from ifreund/deque
std: add a Deque data structure
2025-09-10 14:28:13 -07:00
Tea
a50c2a4eae
README: update llvm requirement to 21 2025-09-10 21:58:26 +02:00
Pat Tullmann
bd4617033e standalone posix tests for sigaction
Fixes #24380
2025-09-09 22:07:44 -07:00
Pat Tullmann
ca09629bee standalone posix tests for relative path linking 2025-09-09 22:07:44 -07:00
Pat Tullmann
aa1d2adffc standalone posix test for env vars 2025-09-09 22:07:44 -07:00
Pat Tullmann
020eb622ee standalone posix test for current working directory 2025-09-09 22:07:44 -07:00
Pat Tullmann
c614d8d008 standalone posix tests: add skeleton
Add build.zig, README and empty test files.
2025-09-09 22:07:44 -07:00
Pat Tullmann
e46ddeeb29 posix/test.zig: "sigset_t bits" test fixes
Re-enable the test.  Will trigger #24380 as-is, but follow-on change moes
this code over to test/standalone.

Make the test a bit easier to debug by stashing the "seen" signal number
in the shared `seen_sig` (instead of just incrementing a counter for each
hit).  And only doing so if the `seen_sig` is zero.
2025-09-09 22:07:03 -07:00
Pat Tullmann
0edccc1079 Move some Thread tests out of posix/test.zig into Thread.zig
These tests aren't (directly) using Posix APIs, so they don't need to be
in posix/test.zig.  Put them over with the code and tests in Thread.zig.
Since the spawn/join test in the posix code was redundant, just dropped
that one.
2025-09-09 22:06:20 -07:00
LukaTD
0b75a2a1b1
langref: added missing newlines to destructuring tuples example
langref: added missing newlines to destructuring tuples example
2025-09-10 02:31:20 +00:00
Brandon Black
7995697527 std: add IP, IPV6, IPTOS sockopt constants
Because these lists are very long in several cases and quite
varied, I opted to place them in the existing c/foo.zig files.

There are many other sets of network-related constants like this
to add over time across all the OSes.  For now I picked these
because I needed a few constants from each of these namespaces for
my own project, so I tried to flesh out these namespaces
completely as best I could, at least for basic sockopt purposes.

Note windows has some of these already defined in ws2_32 as
individual constants rather than contained in a namespacing
struct.  I'm not sure what to do with that in the long run (break
it and namespace them?), but this doesn't change the status quo
for windows in any case.
2025-09-09 17:01:20 -05:00
Brandon Black
0e45b9d5db std: add linger struct for SO.LINGER 2025-09-09 16:59:50 -05:00
Brandon Black
3e372f1994 std: add in_pktinfo and in6_pktinfo structs defs
in_pktinfo is only used on a few targets for the IP_PKTINFO
sockopt, as many BSDs use an alternate mechanism (IP_RECVDSTADDR)
that doesn't require a special struct.  in6_pktinfo is more
universal.
2025-09-09 16:59:50 -05:00
Brandon Black
c449a30213 std.c: Add accept_filter_arg for some BSDs
This is the struct type used as set/getsockopt() option data with
SO.ACCEPTFILTER, which is also only declared on this same limited
set of BSD-ish targets.

In theory this could be aliased over to std.posix as well, but I
think for a corner case like this, it's not unreasonable for a
user that is avoiding uneccessary std.c references to access it as
"posix.system.accept_filter_arg" (which would still work fine if,
in the future, FreeBSD escapes its libc dep and defines it in
std.os.freebsd).
2025-09-09 16:59:50 -05:00
Brandon Black
c70521e7b1 std: Add SCM constants for socket control messages 2025-09-09 16:59:50 -05:00
Andrew Kelley
f63cd9194c
Merge pull request #25191 from ziglang/fix-linker-undef-memory
fix linker writing undefined memory to output file
2025-09-09 00:04:37 -07:00
Andrew Kelley
3071ba4272
Merge pull request #25190 from blblack/netcalls
Add missing posix wrappers for socketpair() and recvmsg()
2025-09-08 20:47:54 -07:00
Andrew Kelley
877d6df8f7 fix linker code writing undefined memory to the output file
missing `extern` on a struct.

but also all these instances that call pwriteAll with a `@ptrCast` are
endianness bugs.

this should be changed to use File.Writer and call writeSliceEndian
instead.

this commit fixes one immediate problem but does not fix everything.
2025-09-08 18:23:01 -07:00
Andrew Kelley
eac2bbfec9 std.Io.Writer.writeSliceEndian: add compile error
check when an auto-layout struct is attempted to be memory reinterpreted
and written out. it would be writing undefined memory
2025-09-08 18:18:27 -07:00
Frank Denis
1872c85ac2 std.crypto.ed25519: support cofactorless verification
Add verifyStrict() functions for cofactorless verification.

Also:

- Support messages < 64 characters in the test vectors
- Allow mulDoubleBasePublic to return the identity as a regular
value. There are valid use cases for this.
2025-09-08 14:25:57 -07:00
Igor Anić
c41b9d7508
ECDSA signature der encoding should produce smallest number of octets (#25177)
I noticed this by stress testing my tls server implementation. From time to time curl (and other tools: ab, vegeta) will report invalid signature. I trace the problem to the way how std lib is encoding raw signature into der format. Using raw signature I got in some cases different encoding using std and openssl. Std is not producing minimal der when signature `r` or `s` integers has leading zero(es).

Here is an example to illustrate difference. Notice leading 00 in `s`
integer which is removed in openssl encoding but not in std encoding.

```Zig
const std = @import("std");

test "ecdsa signature to der" {
    // raw signature r and s bytes
    const raw = hexToBytes(
        \\ 49  63  0c  94  95  2e  ff  4b  02  bf  35  c4  97  9e  a7  24
        \\ 20  dc  94  de  aa  1b  17  ff  e1  49  25  3e  34  ef  e8  d0
        \\ c4  43  aa  7b  a9  f3  9c  b9  f8  72  7d  d7  0c  9a  13  1e
        \\
        \\ 00  56  85  43  d3  d4  05  62  a1  1d  d8  a1  45  44  b5  dd
        \\ 62  9f  d1  e0  ab  f1  cd  4a  85  d0  1f  5d  11  d9  f8  89
        \\ 89  d4  59  0c  b0  6e  ea  3c  19  6a  f7  0b  1a  4a  ce  f1
    );
    // encoded by openssl
    const expected = hexToBytes(
        \\ 30  63  02  30
        \\ 49  63  0c  94  95  2e  ff  4b  02  bf  35  c4  97  9e  a7  24
        \\ 20  dc  94  de  aa  1b  17  ff  e1  49  25  3e  34  ef  e8  d0
        \\ c4  43  aa  7b  a9  f3  9c  b9  f8  72  7d  d7  0c  9a  13  1e
        \\
        \\ 02  2f
        \\ 56  85  43  d3  d4  05  62  a1  1d  d8  a1  45  44  b5  dd
        \\ 62  9f  d1  e0  ab  f1  cd  4a  85  d0  1f  5d  11  d9  f8  89
        \\ 89  d4  59  0c  b0  6e  ea  3c  19  6a  f7  0b  1a  4a  ce  f1
    );
    // encoded by std
    const actual = hexToBytes(
        \\ 30  64  02  30
        \\ 49  63  0c  94  95  2e  ff  4b  02  bf  35  c4  97  9e  a7  24
        \\ 20  dc  94  de  aa  1b  17  ff  e1  49  25  3e  34  ef  e8  d0
        \\ c4  43  aa  7b  a9  f3  9c  b9  f8  72  7d  d7  0c  9a  13  1e
        \\
        \\ 02  30
        \\ 00  56  85  43  d3  d4  05  62  a1  1d  d8  a1  45  44  b5  dd
        \\ 62  9f  d1  e0  ab  f1  cd  4a  85  d0  1f  5d  11  d9  f8  89
        \\ 89  d4  59  0c  b0  6e  ea  3c  19  6a  f7  0b  1a  4a  ce  f1
    );
    _ = actual;

    const Ecdsa = std.crypto.sign.ecdsa.EcdsaP384Sha384;
    const sig = Ecdsa.Signature.fromBytes(raw);
    var buf: [Ecdsa.Signature.der_encoded_length_max]u8 = undefined;
    const encoded = sig.toDer(&buf);

    try std.testing.expectEqualSlices(u8, &expected, encoded);
}

pub fn hexToBytes(comptime hex: []const u8) [removeNonHex(hex).len / 2]u8 {
    @setEvalBranchQuota(1000 * 100);
    const hex2 = comptime removeNonHex(hex);
    comptime var res: [hex2.len / 2]u8 = undefined;
    _ = comptime std.fmt.hexToBytes(&res, hex2) catch unreachable;
    return res;
}
fn removeNonHex(comptime hex: []const u8) []const u8 {
    @setEvalBranchQuota(1000 * 100);
    var res: [hex.len]u8 = undefined;
    var i: usize = 0;
    for (hex) |c| {
        if (std.ascii.isHex(c)) {
            res[i] = c;
            i += 1;
        }
    }
    return res[0..i];
}
```

Trimming leading zeroes from signature integers fixes encoding.
2025-09-08 22:53:03 +02:00
Brandon Black
c4c6c01cc5 recvmsg: posix wrapper, void on windows
Also, added EPIPE to recvfrom() error set (it's a documented error
for unix and tcp sockets, at least), which recvmsg() largely
shares.  Windows has an odd, callback-based form of recvmsg() that
doesn't fit the normal interface here.
2025-09-08 14:45:51 -05:00
Brandon Black
79313d844f socketpair: posix wrapper, void on windows
socketpair is something like a pipe2() for sockets, and generally
only works for AF_UNIX sockets for most platforms.  Winsock2
explicitly does not support this call, even though it does have
AF_UNIX sockets.
2025-09-08 14:45:51 -05:00
Andrew Kelley
05cff8a558
Merge pull request #25186 from ziglang/vector-memory-coercion
frontend: vectors and arrays no longer support in-memory coercion
2025-09-08 03:59:38 -07:00
Andrew Kelley
7666d5fc26 add compile error test case 2025-09-07 23:03:06 -07:00
Andrew Kelley
dca4c302dd std.mem.indexOfSentinel: eliminate unnecessary @ptrCast
it was always unnecessary but now it's illegal
2025-09-07 20:23:36 -07:00
Andrew Kelley
2d9df0bb1a behavior tests: remove one dependency on std lib 2025-09-07 20:23:05 -07:00
Andrew Kelley
04bd30f021 std.debug.assertAligned: support const pointers 2025-09-07 20:22:38 -07:00
Andrew Kelley
5701617b27 wasm backend: disable failing behavior tests 2025-09-07 20:11:37 -07:00
Andrew Kelley
6673b47685 frontend: vectors and arrays no longer support in-memory coercion
closes #25172
2025-09-07 17:29:36 -07:00
Andrew Kelley
426d65d700 Compilation: fix buildGlibcSharedObjects error handling
Oops, this was supposed to be only a temporary troubleshooting patch.
2025-09-06 19:32:27 -07:00
baltevl
34409635ad std.http.Client.Connection: make host() public
Closes #25153
2025-09-06 19:23:27 -07:00
Frank Denis
02396f8d5c
Document std.mem.* functions (#25168)
* Document std.mem.* functions

Functions in std.mem are essential for virtually all applications,
yet many of them lacked documentation.

Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2025-09-06 18:55:57 -07:00
kcbanner
cc6d9fdbf4 webui: fixup build errors in fuzz / time_report 2025-09-06 18:51:26 -07:00
Andrew Kelley
4c01275664
Merge pull request #25163 from ziglang/packed-union-unused
forbid unused bits in packed unions
2025-09-06 12:08:31 -07:00
Andrew Kelley
91b3769b03 langref: update "Choosing an Allocator" section
and delete "Implementing an Allocator" section because it is out of
scope.
2025-09-06 11:51:27 -07:00
Andrew Kelley
4f7aecd348 disable failing behavior test on stage2_aarch64 2025-09-05 23:47:56 -07:00
rpkak
1a5cf072a8 remove ResponseStorage
unused since 5ce8e9325b7aa15cbcc77221fc7075b6c46619cc
2025-09-05 22:50:14 -07:00
Andrew Kelley
5dc5bf6a6b add compile error test case for new error 2025-09-05 19:55:45 -07:00
Andrew Kelley
8c631ebfee langref: update for new packed union rules 2025-09-05 19:45:18 -07:00
Andrew Kelley
b074299124 std: update for new packed union rules 2025-09-05 19:45:07 -07:00
Andrew Kelley
b9a63433b7 behavior tests: update for new requirement
packed union fields must all have matching bit sizes
2025-09-05 19:44:54 -07:00
Andrew Kelley
52c6d7a929 Sema: forbid packed unions with mismatched field bit sizes 2025-09-05 18:45:24 -07:00
Andrew Kelley
1d764c1fdf Revert "Merge pull request #24905 from gooncreeper/file-reader-buffered"
This reverts commit ac42eaaadd0650ffc281f9a1ed1a642fde8984b7, reversing
changes made to 9fa2394f8c00d060931d69fb6f342f7f2e3d826e.

I would like a chance to review this, please. I already spotted some
issues.
2025-09-05 11:26:38 -07:00
Isaac Freund
ac42eaaadd
Merge pull request #24905 from gooncreeper/file-reader-buffered
Fix Io.Writer sendFile bugs with buffered reader contents
2025-09-05 16:28:08 +02:00
Alex Rønne Petersen
9fa2394f8c
Merge pull request #25147 from lunagl/reenable-tests
Reenable failing vector tests
2025-09-05 04:35:11 +02:00
Andrew Kelley
f78f70dbd8 std.fs.File.Writer: break up seekTo
- introduce seekToUnbuffered which asserts no buffered data and does not
  have WriteFailed in the error set
- remove WriteFailed from SeekError
- make seekTo based on calling flush and then seekToUnbuffered
- revert the change to reset seek_err since the error sets are
  compatible again
2025-09-04 16:05:55 -07:00
Kendall Condon
d26b532647 sendFileAll: use stream instead of sendFileReading
This is a simpler implementation and allows file_reader to do more
optimal streaming.
2025-09-04 17:26:52 -04:00
Kendall Condon
58dda3b10b fix sendFile implementations bypassing interface buffer
Also removes `File.Reader.read` since it is otherwise unused and is a
footgun.
2025-09-04 17:26:49 -04:00
Kendall Condon
7687b916fd File.Writer.sendFile: properly update reader pos
seekBy affects the reader's physical position, not its logical
position.
2025-09-04 16:38:50 -04:00
Luna Schwalbe
63ab0c0302
Reenable vector tests for armeb/thumbeb
https://github.com/ziglang/zig/issues/22060 has been fixed by upstream.
2025-09-04 16:23:18 +02:00
Luna Schwalbe
a9f06d16fd
Reenable std.fmt.test.vector for riscv64
The vector codegen issue as described in
https://github.com/ziglang/zig/issues/4486 has been fixed upstream.
2025-09-04 16:15:00 +02:00
Alex Rønne Petersen
d94e061ade
Merge pull request #25137 from alexrp/elf-gabi-4.3
ELF updates for gABI 4.3
2025-09-04 10:58:28 +02:00
Luna Schwalbe
9649ff37ef BitcodeReader: parse blockinfo inside block
Call start/endBlock before/after `parseBlockInfoBlock` in order to not
use the current block context, which is wrong and leads to e.g. incorrect
abbrevlen being used.
2025-09-03 21:47:32 -07:00
whatisaphone
ae518dcb41 Add allocator that always fails 2025-09-03 21:46:01 -07:00
Brandon Black
76c62e509b Fix cmsghdr struct for the *nixes
Previously we had a single definition of std.c.cmsghdr for all
libc-linking platforms which aliased from the Solaris definition,
a superfluous matching one in std.os.dragonfly, and no others.

The existing definition from std.c didn't actually work for Linux,
as Linux's "len" field is usize in the kernel's definition.

Emscripten follows the Linux model of course (but uses the
binary-compatible musl definition, which has an endian-sensitive
padding scheme to make the len type "socklen_t" even though the
kernel uses a usize, which is fair).

This unifies and documents all the known *nix-ish cases (I'm not
sure if wasi or windows really has cmsghdr support? Could be added
later, void for now), such that c.cmsghdr and posix.system.cmsghdr
should work correctly for all the known cases here, libc or
otherwise.
2025-09-03 21:45:03 -07:00
Josh GM Walker
b1189ab038
fix: std.fs.File.Writer.seekTo does not flush (#25135)
* add failing test case
* perform flush and allow error
* dont over constrain flush error
* reset seek error during conversion
2025-09-03 21:43:47 -07:00
Alex Rønne Petersen
32a34b64ca
Merge pull request #25125 from alexrp/loongarch-qemu-crashes
`std.debug`: disable stack traces on loongarch
2025-09-04 04:06:47 +02:00
Alex Rønne Petersen
210b764c03
link.Elf: truncate st_other to u3 before converting to std.elf.STV
See 6b6e336e07308fd23f3061b5be11407956b2a460 for context, but note that in
gABI 4.3, 3 bits are reserved for the visibility, up from the previous 2.
2025-09-04 01:16:27 +02:00
Alex Rønne Petersen
a82f446d91
std.elf: change STV enum from u2 to u3
In gABI 4.3, st_other was changed such that the lower 3 bits are reserved for
the visibility, up from the previous 2 bits.
2025-09-04 01:16:23 +02:00
Alex Rønne Petersen
9e076d8c75
std.elf: add new EM values from gABI 4.3 2025-09-04 01:16:22 +02:00
Alex Rønne Petersen
1ca446abc3
std.elf: document which EM values are not assigned in gABI 2025-09-04 01:13:59 +02:00
Alex Rønne Petersen
1c090d3d67
std.elf: document which OSABI values are not assigned in gABI 2025-09-04 01:13:59 +02:00
Brandon Black
048f9126b8 Return runtime err for EISCONN when connecting
Fixes #25063
2025-09-03 22:01:45 +02:00
doclic
18bdd0e9a4 std.c: add getresuid & getresgid 2025-09-03 21:28:07 +02:00
Alex Rønne Petersen
a11dfaf61a
Merge pull request #25122 from linusg/fix-getrandombytesdevurandom
std.posix: Fix getRandomBytesDevURandom()
2025-09-03 19:55:46 +02:00
Alex Rønne Petersen
b2ef6d01ff
Revert "test: disable non-native loongarch64 behavior and std tests"
This reverts commit f4ed35f800396f12c7cd6aa1f70cf2555ddf7c84.

This should no longer be needed now that stack traces are disabled on loongarch.

closes #24405
2025-09-03 11:32:57 +02:00
Alex Rønne Petersen
d8d0a3e5c7
std.debug: disable stack traces on loongarch
Observed to ~randomly crash during FP-based unwinding.

The path forward here will be DWARF-based unwinding.
2025-09-03 11:27:42 +02:00
binarycraft007
35f013db11 lzma2: fix premature finish
lzma2 Decoder already checks if decoding is finished or not inside the
process function, `range_decoder`finish does not mean the decoder has
finished, also need to check `ld.rep[0] == 0xFFFF_FFFF`, which was
already done inside the proccess function. This fix delete the redundant
`isFinish()` check for `range_decoder`.
2025-09-03 01:48:46 -07:00
Linus Groh
79f60302d6 std.c: Enable arc4random_buf for serenity 2025-09-03 02:24:47 +01:00
Linus Groh
deb46e1dd3 std.posix: Fix getRandomBytesDevURandom()
This is not exercised in CI because most platforms have a dedicated
implementation in getrandom().
2025-09-03 02:23:19 +01:00
Andrew Kelley
d51d18c986
Merge pull request #25105 from binarycraft007/lzma2-fix
lzma2: fix array list looping logic in appendLz
2025-09-02 13:16:09 -07:00
Andrew Kelley
90ac62cc75 std.compress.lzma2: optimize appendLz
make the hot loop be a for loop without any failures or allocation.
change a O(N) addition into O(1)
2025-09-02 12:00:43 -07:00
Ryan Liptak
f872dd03da zstd.Decompress: Assert buffer length requirements as early as possible
Without this assert, providing a buffer that's smaller than required results in more cryptic assertion failures later on.
2025-09-02 11:34:46 -07:00
binarycraft007
00b0beb682 lzma2: fix array list looping logic in appendLz 2025-09-01 17:01:54 +08:00
Ryan Liptak
bc7955306e Fix -M and --dep splitting on every = instead of just the first
Before this commit, -Mfoo=bar=baz would be incorrectly split into mod_name: `foo` and root_src_orig: `bar`
After this commit, -Mfoo=bar=baz will be correctly split into mod_name: `foo` and root_src_orig: `bar=baz`

Closes #25059
2025-08-31 19:32:07 -07:00
Travis Staloch
1ec8a7ab4c Io.Writer.Allocating: test new *Aligned methods
* added initAligned()
* added missing @alignCast in toArrayListAligned()
2025-08-31 19:29:02 -07:00
Andrew Kelley
4c01a6553a
Merge pull request #25088 from ziglang/delete-deprecated-fmt
std.fmt: delete deprecated APIs
2025-08-31 19:28:21 -07:00
Tadej Gašparovič
3aa31ffd86 Fix regression: std.http.Client basic authorization sending user:user instead of user:password when passed in URI 2025-08-31 15:48:47 -07:00
Andrew Kelley
ec36e0609f delete behavior test that depends on std.fmt
behavior tests should have minimal dependency on std
2025-08-31 12:49:18 -07:00
Andrew Kelley
150169f1e0 std.fmt: delete deprecated APIs
std.fmt.Formatter -> std.fmt.Alt
std.fmt.format -> std.Io.Writer.print
2025-08-31 12:49:18 -07:00
Alex Rønne Petersen
ab99dd9c5d zig_clang: fix ZigClangAPValueLValueBase struct layout to match Clang 21
Fixes the compiler build for various targets, especially 32-bit.
2025-08-31 20:18:57 +02:00
Brandon Mercer
7fdd60df1c
Populate MSG struct for OpenBSD (#25076)
* update the MSG struct with the correct values for openbsd

* add comment with link to sys/sys/socket.h

---------

Co-authored-by: Brandon Mercer <bmercer@eutonian.com>
2025-08-30 22:04:32 +00:00
Andrew Kelley
b7104231af
Merge pull request #25077 from ziglang/GenericReader
std.Io: delete GenericReader, AnyReader, FixedBufferStream; and related API breakage
2025-08-30 12:43:52 -07:00
Alex Rønne Petersen
151314346d
Merge pull request #25055 from ziglang/llvm21
LLVM 21
2025-08-30 21:00:53 +02:00
Andrew Kelley
e2fdaea0b3 Revert "std.Io.Reader: work around llvm backend bug"
This reverts commit 530cc2c1111699d9d02ad9ebef94efa6b99f5205.

The compiler bug has been fixed.
2025-08-30 06:04:25 -07:00
Alex Rønne Petersen
8896046b11
ci: update tarballs to 0.16.0-dev.104+689461e31 2025-08-30 13:27:25 +02:00
Alex Rønne Petersen
d2a038c082
stage1: update zig1.wasm
Needed because some std.Target.aarch64 features were renamed in LLVM 21.

Signed-off-by: Alex Rønne Petersen <alex@alexrp.com>
2025-08-30 13:27:25 +02:00
Alex Rønne Petersen
66b43234bb
std: disable sha3-512 single test on RISC-V with V support
https://github.com/ziglang/zig/issues/25083
2025-08-30 13:27:25 +02:00
Andrew Kelley
31a0c2a36a child process test: preemptively use streaming mode
works around #24984
2025-08-30 00:48:50 -07:00
Andrew Kelley
07da9567e6 compiler: fix macos build 2025-08-30 00:48:50 -07:00
Andrew Kelley
9adcc31ca3 update tools and other miscellaneous things to new APIs 2025-08-30 00:48:50 -07:00
Andrew Kelley
fadd268a60 upgrade more old API uses 2025-08-30 00:48:50 -07:00
Andrew Kelley
9a0970a12b rework std.Io.Writer.Allocating to support runtime-known alignment
Also, breaking API changes to:
* std.fs.Dir.readFileAlloc
* std.fs.Dir.readFileAllocOptions
2025-08-30 00:48:50 -07:00
Alex Rønne Petersen
0071917621
test: disable some varargs behavior tests on RISC-V due to LLVM 21 regression
https://github.com/ziglang/zig/issues/25064
2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
3a5b7a31ff
test: use -Wno-unterminated-string-initialization for cbe tests
https://github.com/llvm/llvm-project/issues/153314
2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
2cb412ff1b
test: re-enable a bunch of vector behavior tests on hexagon 2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
0683e1564c
test: use long calls for hexagon-linux module tests 2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
f149112951
test: expand C ABI test coverage to hexagon-linux-musl 2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
f6879c35af
std.posix.test: fix mmap() test to use actual page size instead of 4096 2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
59ee4e8e54
std.hash.xxhash: disable xxhash3 test on all mips64 targets
See also dd1de18f9629904b5d97d5791a47244ac63385da.

https://github.com/ziglang/zig/issues/23807
2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
af78c55676
std: skip some failing tests on hexagon 2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
367be3777c
std.Thread: make unreachable errors in sleep() clearer 2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
e351ee3b7f
Revert "llvm: workaround crashes in llvm loop optimizations"
This reverts commit b4fd57a9c114748afb9ba0a04bede61089a02ddf.

https://github.com/llvm/llvm-project/pull/149743
2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
907b5b73b4
compiler: remove medium code model workaround for loongarch64
The default was changed in LLVM 21.
2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
e4f38a611f
llvm: switch to native f16 IR type for all hexagon targets
This was fixed in LLVM 21, in particular for targets older than v68.
2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
1c858ba7e3
llvm: remove f16 special case for soft float aarch64 2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
d4882d10f8
llvm: switch to native f128 IR type for nvptx
LLVM 21 added support for this.
2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
53c53a2697
llvm: switch to native f16 IR type for s390x
LLVM 21 added support for this.
2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
c4592da882
compiler-rt: use native f16 type for loongarch
This ABI changed in LLVM 21.
2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
e9ac2ce116
compiler-rt: move strlen from libzigc to here
LLVM 21 has started recognizing strlen-like idioms and optimizing them to strlen
calls, so we need this function provided in compiler-rt for libc-less
compilations.
2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
dfa55e193d
musl: replace .data.rel.ro with .section .data.rel.ro,"aw"
The former was an LLVM extension that appears to have been removed in LLVM 21.

I won't bother fixing gen_stubs.zig; see #23881.
2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
2b84eb85ee
llvm: update data layout strings for LLVM 21 2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
c44f631c72
zig cc: pass -mthumb to the assembler as necessary 2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
8c47dda7df
zig cc: pass CPU features to Clang using the new -Xclangas when assembling
Unfortunately, we cannot yet remove the special-casing for RISC-V CPU features,
so that code stays.

Closes #10411.
2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
c0cfe571f9
zig cc: update options data to LLVM 21 2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
5b80900a5d
std.zig.system: update aarch64 and powerpc cpu detection for LLVM 21 2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
0b9f5e2549
std.Target: fix alignment for int/long types on m68k 2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
fdd32a2257
std.Target: add managarm OS tag 2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
464eef390b
std.Target: make ultrasparc3 the baseline for sparc64-solaris
https://github.com/llvm/llvm-project/pull/149990
2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
978555eea4
std.Target.x86: purge avx10.n-256, rename avx10.n_512 to avx10.n, require evex512 for avx512f
Intel has abandoned AVX10.N/128,256; AVX10.N is now always 512-bit.
2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
2c0cc81e74
std.Target: bump feature bit count from 288 to 317
/lib/std/debug.zig:559:14: error: reached unreachable code
        if (!ok) unreachable; // assertion failure
                 ^~~~~~~~~~~
    /lib/std/Target/riscv.zig:335:21: note: called at comptime here
        std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
        ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
587eddda28
std.Target: update CPU features to LLVM 21 2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
94f95fefe3
update_cpu_features: bump branch quota for amdgcn
/lib/std/Target/amdgcn.zig:1656:5: error: evaluation exceeded 1000 backwards branches
        for (&result, 0..) |*elem, i| {
        ^~~
2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
5739ce786e
update_cpu_features: fix a fmtId call to be fmtIdPU 2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
7e6cb7c7a5
compiler: respond to API changes in LLVM 21 2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
ac20506090
libtsan: update to LLVM 21 2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
85438e75e0
libunwind: update to LLVM 21 2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
c34fc8f198
llvm-libc: update to LLVM 21
Still only the subset needed for libcxx.
2025-08-30 06:36:41 +02:00
Alex Rønne Petersen
d9f0fbf983
libcxx: update to LLVM 21 2025-08-30 06:36:40 +02:00
Alex Rønne Petersen
e84e9d3a01
libcxxabi: update to LLVM 21 2025-08-30 06:36:40 +02:00
Alex Rønne Petersen
ce7339e80a
zig cc: update intrinsic headers to LLVM 21 2025-08-30 06:36:40 +02:00
Alex Rønne Petersen
b7a8c045ef
zig cc: update driver files to LLVM 21 2025-08-30 06:36:40 +02:00
Alex Rønne Petersen
008affa645
build: update to LLVM 21
Closes #20966.
2025-08-30 06:36:40 +02:00
Andrew Kelley
79f267f6b9 std.Io: delete GenericReader
and delete deprecated alias std.io
2025-08-29 17:14:26 -07:00
Andrew Kelley
558bea2a76 std.Io: delete CountingReader 2025-08-29 11:11:59 -07:00
Andrew Kelley
4b948e8556
Merge pull request #25036 from ziglang/GenericWriter
std.Io: delete GenericWriter, AnyWriter, and null_writer
2025-08-29 03:48:45 -07:00
Andrew Kelley
640c11171b LLVM backend:fix align 1 sret parameter load returned
closes #25067
2025-08-29 03:37:18 -07:00
Alex Rønne Petersen
98e9dde389 ci: update to QEMU 10.1.0 2025-08-29 10:52:32 +02:00
Andrew Kelley
43fbc37a49 std.debug.Pdb: migrate more towards new Reader API
There was some bug in this branch, and rather than diagnosing it, I
fully finished porting over to new Reader API. Did it fix the bug?
2025-08-28 22:41:06 -07:00
Andrew Kelley
7da9e4b35e std.tz: fix redundant endian handling
I didn't notice the check+swap before.
2025-08-28 18:30:57 -07:00
Andrew Kelley
530cc2c111 std.Io.Reader: work around llvm backend bug
tracked by #25067 and I already have a fix cooking in another branch
2025-08-28 18:30:57 -07:00
Ryan Liptak
46b60dc069 resinator: Complete the update to the new Reader/Writer 2025-08-28 18:30:57 -07:00
Andrew Kelley
9b47dd2028 update langref and docs to avoid GenericWriter 2025-08-28 18:30:57 -07:00
Andrew Kelley
8023f3dceb fix not discarding delimiter
perhaps these APIs have the defaults backwards, eh?
2025-08-28 18:30:57 -07:00
Andrew Kelley
e418197247 link.MachO: code sig size grows when emitting it 2025-08-28 18:30:57 -07:00
Andrew Kelley
5be9df710c 32-bit fixes 2025-08-28 18:30:57 -07:00
Andrew Kelley
8d80d67693 resinator: some updates to avoid GenericWriter
These are some hastily made, untested changes to get things compiling
again, since Ryan is working on a better upgrade patchset in the
meantime.
2025-08-28 18:30:57 -07:00
Andrew Kelley
f7884961c2 update more to avoid GenericWriter 2025-08-28 18:30:57 -07:00
Andrew Kelley
4f510dba10 behavior tests: remove "variadic functions" dependency on std lib 2025-08-28 18:30:57 -07:00
Andrew Kelley
ea3471288a update GenericWriter usage found by test-cases 2025-08-28 18:30:57 -07:00
Andrew Kelley
888f00e856 std.crypto.ml_kem: update to not use GenericWriter 2025-08-28 18:30:57 -07:00
Andrew Kelley
e9a271cba3 std.tz: update to new Reader API 2025-08-28 18:30:57 -07:00
Andrew Kelley
9860dd475a std: delete most remaining uses of GenericWriter 2025-08-28 18:30:57 -07:00
Andrew Kelley
8f4cb4614f compiler: update not to use GenericWriter 2025-08-28 18:30:57 -07:00
Andrew Kelley
5d7507214d aro: update to not use GenericWriter 2025-08-28 18:30:57 -07:00
Andrew Kelley
2151b10a41 more updates to not use GenericWriter 2025-08-28 18:30:57 -07:00
Andrew Kelley
379d7bc9f6 compiler: update to not use GenericWriter 2025-08-28 18:30:57 -07:00
Andrew Kelley
6713745ec4 link.Elf: update to not use GenericWriter 2025-08-28 18:30:57 -07:00
Andrew Kelley
cc931660eb link.MachO: update to not use GenericWriter 2025-08-28 18:30:57 -07:00
Andrew Kelley
2dc6ddd7e8 std.Io.Writer: add toArrayList/fromArrayList 2025-08-28 18:30:57 -07:00
Andrew Kelley
c8b983c59a link.Wasm: update for new writer API 2025-08-28 18:30:57 -07:00
Andrew Kelley
57dbc9e74a std.Io: delete GenericWriter 2025-08-28 18:30:57 -07:00
Alex Rønne Petersen
5cb8cdef10
Merge pull request #25045 from kada49/libc/common-impl-ceil
libc: delete some superfluous libc c implementations
2025-08-29 00:25:23 +02:00
David Senoner
70e22d79a4 libc: delete superfluous c and assembly trunc implementations 2025-08-28 20:09:07 +02:00
Ryan Liptak
224fca7e0e process.totalSystemMemory: Avoid overflow on Linux when totalram is a 32-bit usize
Fixes #25038
2025-08-28 17:05:39 +02:00
Ryan Liptak
2b73c28cec Reader.appendRemaining: Take ownership of the full allocated slice
Before this commit, calling appendRemaining with an ArrayList where list.items.len != list.capacity could result in illegal behavior if the Writer.Allocating resized the list during the appendRemaining call.

Fixes #25057
2025-08-28 07:56:50 -07:00
David Rubin
73a0b5441b
AstGen: forward result type through unary float builtins
Uses a new `float_op_result_ty` ZIR instruction tag.
2025-08-28 15:46:12 +01:00
mlugg
a31950aa57 std.debug: remove @frameAddress() "UAF"
We can't call `@frameAddress()` and then immediately `return`! That
invalidates the frame. This *usually* isn't a problem, because the stack
walk `next` call will *probably* have a stack frame and it will
*probably* be at the exact same address, but neither of those is a
guarantee. On powerpc, presumably some unfortunate inlining was going
on, so this frame was indeed invalidated when we started walking frames.

We need to explicitly pass `@frameAddress` into any function which will
return before we actually walk the stack. Pretty simple patch.

Resolves: #24970
2025-08-28 10:56:11 +01:00
tokyo4j
151c7dc74b std.os.uefi: fix type error at MemoryType.format() 2025-08-28 07:50:38 +01:00
Alex Rønne Petersen
417c68d249 std.os.linux: powerpc syscalls clobber ctr and xer
https://git.musl-libc.org/cgit/musl/commit/?id=f6944eb3c4ce1c97dc39dc36d32390dc9f70b67b
2025-08-28 07:41:22 +02:00
David Senoner
f707de15a1 libc: delete superfluous c and assembly ceil implementation 2025-08-28 07:33:50 +02:00
Jacob Young
733008ec6b x86_64: fix multiplication overflow detection with adx
Closes #24965
2025-08-27 20:00:46 -07:00
Andrew Kelley
ca2e17e0a1 delete some vestigal dead code 2025-08-27 17:09:07 -07:00
Andrew Kelley
50edad37ba
Merge pull request #25034 from ziglang/lzma
std.compress: update lzma, lzma2, and xz to new I/O API
2025-08-27 06:49:45 -07:00
David Senoner
f6b0d64ddc libc: remove c floorl implementaions forgotten in #24335 2025-08-27 13:40:08 +02:00
Frank Denis
12a58087a4
Fix TLS 1.2 client key exchange to use negotiated named group (#25007)
The TLS 1.2 implementation was incorrectly hardcoded to always send the
secp256r1 public key in the client key exchange message, regardless of
which elliptic curve the server actually negotiated.

This caused TLS handshake failures with servers that preferred other curves
like X25519.

This fix:

- Tracks the negotiated named group from the server key exchange message
- Dynamically selects the correct public key (X25519, secp256r1, or
  secp384r1) based on what the server negotiated
- Properly constructs the client key exchange message with the
  appropriate key size for each curve type

Fixes TLS 1.2 connections to servers like ziglang.freetls.fastly.net
that prefer X25519 over secp256r1.
2025-08-27 11:18:40 +02:00
Brandon Black
ae2622bf82 std.c: add correct SOMAXCONN for BSDs
Note the previous "28" here for openbsd was some kind of copy
error long ago.  That's the value of KERN.SOMAXCONN, which is an
entirely different thing.
2025-08-27 09:46:37 +02:00
Andrew Kelley
68f590d430 std.compress.xz: fix 32-bit targets 2025-08-26 21:07:09 -07:00
Andrew Kelley
0339c5793a fetch: update xz API usage 2025-08-26 21:00:58 -07:00
Andrew Kelley
668299f0db std: update xz unit tests to new I/O API 2025-08-26 21:00:58 -07:00
Andrew Kelley
980445f08b std.compress.lzma: fix unpacked size checking logic 2025-08-26 21:00:58 -07:00
Andrew Kelley
722e066173 std.compress.xz.Decompress: some tests passing 2025-08-26 21:00:58 -07:00
Andrew Kelley
d87eb7d4e4 std.compress.xz: skeleton in place
missing these things:
- implementation of finish()
- detect packed bytes read for check and block padding
- implementation of discard()
- implementation of block stream checksum
2025-08-26 21:00:58 -07:00
Andrew Kelley
a8ae6c2f42 std.compress.lzma2: tests passing 2025-08-26 21:00:58 -07:00
Andrew Kelley
3cb9baaf65 std.compress.lzma: delete dead parameter
update is always passed as true
2025-08-26 21:00:58 -07:00
Andrew Kelley
8523cbef0e std.compress.lzma: tests passing 2025-08-26 21:00:58 -07:00
Andrew Kelley
58e60697e2 std.compress.lzma: update for new I/O API 2025-08-26 21:00:58 -07:00
Andrew Kelley
6464e0d4fc std.compress.xz: flatten namespaces 2025-08-26 21:00:58 -07:00
Andrew Kelley
ea0ce7afb5 std.compress: flatten lzma and lzma2 namespaces 2025-08-26 21:00:58 -07:00
David Senoner
9399fcddce libc: use zig isnan and derivates for mingw 2025-08-27 03:58:32 +02:00
Yefeng Li
aae5560712 Remove memcmp and memset from bundled musl and wasi 2025-08-27 03:35:18 +02:00
mlugg
42eb1329b1 std.Build.WebServer: fix race
Just a typo: I wasn't actually using the duped message, so the message I
sent could be freed in this interval.
2025-08-26 19:03:49 +01:00
Ian Johnson
d4df65e355 std.Build.Step.Compile: fix race condition in args file creation
Fixes #23993

Previously, if multiple build processes tried to create the same args file, there was a race condition with the use of the non-atomic `writeFile` function which could cause a spawned compiler to read an empty or incomplete args file. This commit avoids the race condition by first writing to a temporary file with a random path and renaming it to the desired path.
2025-08-26 12:02:50 +01:00
Isaac Freund
6d4dbf05ef
Compilation: use std.Deque
And delete DeprecatedLinearFifo from the source tree.
2025-08-26 09:39:09 +02:00
Rue
d57b1e3552
std.ArrayList: add insertSliceAssumeCapacity() and insertSliceBounded() (#24978)
closes #24929
2025-08-26 00:25:25 -07:00
Maciej 'vesim' Kuliński
ff859088e4 std.Target: add vita os
Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>
2025-08-26 07:50:06 +02:00
AdamGoertz
99b2b61516
std.Build.Step.TranslateC: forward --cache-dir and --global-cache-dir flags 2025-08-26 03:54:00 +00:00
Alex Rønne Petersen
ade570f0d5 zig cc: don't pass -mcmodel for assembly files
It does nothing but generate a warning for these.
2025-08-25 21:59:35 +02:00
Sardorbek Imomaliev
91040b5678
add macOS handling for totalSystemMemory (#24903)
* add macos handling for totalSystemMemory

* fix return type cast for .freebsd in totalSystemMemory

* add handling for the whole Darwin family in totalSystemMemory
2025-08-25 19:25:53 +00:00
Qun He
a7769e25be os.linux: faccessat wrapper prefer to faccessat syscall when flags is zero.
This make `fs.Dir.access` has compatibility like the zig version before.

With this change the `zig build --search-prefix` command would work again like
the zig 0.14 version when used on Ubuntu22.04, kernel version 5.4.
2025-08-25 11:27:59 -07:00
Isaac Freund
3e77317261
std: add a Deque data structure
This is my penance for baiting andrew into deleting the existing generic
queue data structures with my talk of "too many ring buffers".

The new Reader and Writer interfaces are excellent ring buffers for many
use cases, but a generic queue container type is now missing.

This new double-ended queue, known more succinctly as a deque, is
implemented from scratch based on the API design lessons learned from
ArrayList over the years.

The API is not yet as featureful as ArrayList, but the core
functionality is in place and I will be using this in my personal
projects shortly. I think it makes sense to add further functions as
needed based on real-world use-cases.
2025-08-25 20:07:59 +02:00
Mason Remaley
5a0cf21775
Adds non allocating alternatives to ZON parse functions (#22916)
* Adds "flat" alternatives to zon.parse.from* that don't support pointers

* Fixes documentation

* Removes flat postfix from non allocating functions, adds alloc to others

* Stops using alloc variant in tests where not needed
2025-08-25 18:03:08 +02:00
Erik Schlyter
37f4bee92a
Fix #24999: copy left-overs before we XOR into c. (#25001)
It is important we copy the left-overs in the message *before* we XOR
it into the ciphertext, because if we're encrypting in-place (i.e., m ==
c), we will manipulate the message that will be used for tag generation.
This will generate faulty tags when message length doesn't conform with
16 byte blocks.
2025-08-25 15:59:42 +00:00
Alex Rønne Petersen
9924897c06
Merge pull request #24995 from alexrp/ubsan-rt-hidden
ubsan-rt: export symbols with hidden visibility
2025-08-25 17:07:33 +02:00
Alex Rønne Petersen
5d019abe4e start adding big endian RISC-V support
The big endian RISC-V effort is mostly driven by MIPS (the company) which is
pivoting to RISC-V, and presumably needs a big endian variant to fill the niche
that big endian MIPS (the ISA) did.

GCC already supports these targets, but LLVM support will only appear in 22;
this commit just adds the necessary target knowledge and checks on our end.
2025-08-25 16:15:17 +02:00
Andrew Kelley
12686d9b7d delete std.debug.FixedBufferReader
now that std.Io.Reader has sufficient debug performance
2025-08-25 04:05:37 -07:00
Alex Rønne Petersen
837e564312
Compilation: avoid ZCU strategy for ubsan-rt in Windows DLLs 2025-08-25 06:45:31 +02:00
Alex Rønne Petersen
afea419470 std.zig.system: fix check for sparc "v8+" in getExternalExecutor()
Targeting v9 on sparc32 doesn't by itself imply "v8+" mode (64-bit instructions
in 32-bit code).
2025-08-25 06:20:41 +02:00
Alex Rønne Petersen
bed8171d4e
ubsan-rt: export symbols with hidden visibility
see 092352ec63d3a4e9ff59a5d8ad8f119bf0eda468
2025-08-25 05:10:12 +02:00
Arnau Camprubí
c327444f5c Add test-obj to the help message 2025-08-24 23:40:14 +02:00
87
bc00932bb2 lib: Reword documentation for realloc to clarify size
"byte size" is confusing. Clarify we mean number of items.
2025-08-24 23:39:17 +02:00
Nathaniel Ketema
5c0ad01d3c fix: fix typo in comment by removing repeated 'business' word 2025-08-24 23:00:17 +02:00
Becker A.
718ee31e21 Update powi.zig to fix docstring formatting
Without this change, the docs are formatted s.t. the text "Edge case rules ordered by precedence:" is appended onto the prior line of text "Underflow: Absolute value of result smaller than 1", instead of getting its own line.
2025-08-24 22:59:08 +02:00
Andrew Kelley
83f773fc64
Merge pull request #24960 from ziglang/MemoryAccessor
std.debug: delete MemoryAccessor
2025-08-23 18:54:32 -07:00
Andrew Kelley
e4a7b15852 disable stack tracing on powerpc64
tracked by #24970
2025-08-23 13:48:52 -07:00
Andrew Kelley
d00cc10086 std.debug: delete MemoryAccessor
This API is based around the unsound idea that a process can perform
checked virtual memory loads to prevent crashing. This depends on
OS-specific APIs that may be unavailable, disabled, or impossible due to
virtualization.

It also makes collecting stack traces ridiculously slow, which is a
problem for users of DebugAllocator - in other words, everybody, all the
time. It also makes strace go from being superbly clean to being awful.
2025-08-23 13:48:52 -07:00
Alex Rønne Petersen
77c09d16f9 std.fs.Dir: fix updateFile() to flush the file before updating its times
AtomicFile.finish() calls flush() which renders any previous updateTimes() calls
useless. Regression introduced in f2a3ac7c0534a74ee544fdf6ef9d2176a8d62389.

Closes #24927.
2025-08-23 12:32:14 -07:00
John Benediktsson
47a2f2ddae
Merge pull request #24926 from mrjbq7/http-fetch
http.Client: don't forget to flush
2025-08-22 12:35:18 -07:00
GasInfinity
306176046e chore(std.Target): explicitly set baseline only to arm with 3ds
* `arm` is the only supported tag for 3ds

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>
2025-08-22 04:14:53 +02:00
GasInfinity
fca2a7a638 test(llvm_targets): remove unused thumb-3ds 2025-08-22 04:14:53 +02:00
GasInfinity
851f31b0e1 chore(std.Target): document the 3ds version range 2025-08-22 04:14:53 +02:00
GasInfinity
cc71936eb9 feat(std.Target): add 3ds os 2025-08-22 04:14:53 +02:00
Raiden1411
55daefdb10 std: remove lossy int to float coercion on json parse 2025-08-22 02:50:26 +02:00
Andrew Kelley
ba726ab65a langref: update nav link 2025-08-21 14:02:12 -07:00
Andrew Kelley
595c9d2353
Merge pull request #24921 from Justus2308/messy-mach
std.c.darwin: cleanup, expose everything in std.c
2025-08-21 11:52:22 -07:00
Justus Klausecker
1594c80555 zig reduce: adapt to new Writer API 2025-08-21 11:50:03 -07:00
Isaac Freund
52de06c3b0 langref: sync with zig-spec grammar.peg 2025-08-21 17:12:38 +02:00
Sardorbek Imomaliev
01b5023868
drop NameTooLong from sysctlbynameZ error set (#24909) 2025-08-21 12:36:57 +02:00
Justus Klausecker
da4c9af354 make some compile errors aliases instead 2025-08-21 11:33:34 +02:00
Lwazi Dube
cab6d752e8 std.os.uefi: Fix typo that causes compile time error #22809" 2025-08-21 03:10:28 +01:00
Brandon Black
8248597a27 Add mlock syscalls to std.c and std.posix
Linux already gained the relevant syscalls and consts in #24473

The basic mlock() and munlock() are fairly universal across the
*nix world with a consistent interface, but are missing on wasi
and windows.

The mlockall() and munlockall() calls are not as widely supported
as the basic ones.  Notable non-implementers include darwin,
haiku, and serenity (and of course wasi and windows again).

mlock2() is Linux-only, as are its MLOCK flags.
2025-08-20 23:38:45 +02:00
Carl Åstholm
172e97154d Use readStreaming, not readPositional, for streaming file readVec on Windows 2025-08-20 21:49:07 +02:00
Alex Rønne Petersen
07cc32b004 wasi-libc: update to c89896107d7b57aef69dcadede47409ee4f702ee 2025-08-20 19:18:11 +02:00
Justus Klausecker
590d264bdf std.c.darwin: cleanup, expose everything in std.c
This mainly just moves stuff around.
Justifications for other changes:
* `KEVENT.FLAGS` is backed by `c_uint` because that's what the `kevent64` flags param takes (according to the 'latest' manpage from 2008)
* `MACH_RCV_NOTIFY` is a legacy name and `MACH_RCV_OVERWRITE` is deprecated (xnu/osfmk/mach/message.h), so I removed them. They were 0 anyway and thus couldn't be represented
as a packed struct field.
* `MACH.RCV` and `MACH.SEND` are technically the same 'type' because they can both be supplied at the same time to `mach_msg`. I decided to still keep them separate because
naming works out better that way and all flags except for `MACH_MSG_STRICT_REPLY` aren't shared anyway. Both are part of a packed union `mach_msg_option_t` which supplies a
helper function to combine the two types.
* `PT` is backed by `c_int` because that's what `ptrace` takes as a request arg (according to the latest manpage from 2015)
2025-08-20 18:21:32 +02:00
Justus Klausecker
d748cc9c12 expose darwin.PT in std.c 2025-08-19 16:18:27 -07:00
Carl Åstholm
9e9cb3ad6d Fix bugs in Windows readVec implementations 2025-08-19 16:18:02 -07:00
TemariVirus
51a2c0feaf std.Io.Writer: fix upper case hex float formatting 2025-08-19 11:20:30 -07:00
Rohlem
81f5a7b8fd
never advance seek position in std.Io.Reader.peekDelimiterExclusive (#24899)
* extend std.Io.Reader.peekDelimiterExclusive test to repeat successful end-of-stream path (fails)

* fix std.Io.Reader.peekDelimiterExclusive to not advance seek position in successful end-of-stream path
2025-08-19 11:19:02 -07:00
Andrew Kelley
07e7cfa35b update .mailmap
keeps our contributor count in the release notes somewhat accurate
2025-08-18 21:56:23 -07:00
Andrew Kelley
cf5f8113c1 start the 0.16.0 release cycle 2025-08-18 21:33:09 -07:00
Andrew Kelley
94cda37d69 Release 0.15.0 2025-08-18 21:32:35 -07:00
Andrew Kelley
89c9282d34 std.http.Client: discard response body when reusing connection
When an error response was encountered, such as 404 not found, the body
wasn't discarded, leading to the string "404 not found" being
incorrectly interpreted as the next request's response.

closes #24732
2025-08-18 17:26:55 -07:00
Giuseppe Cesarano
b734d03340
Expanded std.os.linux perf-related definitions (#24264)
* Added perf_event_header definition

* Added perf_event_mmap_page definition

* Removed default values for perf_event_header

* Fixed comments typos

* Updated perf_event_attr definition

* Explicit packet struct type

* PERF.RECORD from struct to enum

* fix typo: miscs to misc

* misc as packed struct

* cpu_mode as named enum

* Rescoping CPU_MODE
2025-08-18 21:32:44 +00:00
Andrew Kelley
001ec07772
Merge pull request #24249 from antlilja/dwarf-extern-arg
Fix compiler crash when passing a comptime extern function arg to a function
2025-08-18 13:25:13 -07:00
mlugg
c1483eb05c Compilation: fix compiler_rt and ubsan_rt strategy logic
It doesn't really make sense for `target_util.canBuildLibCompilerRt`
(and its ubsan-rt friend) to take in `use_llvm`, because the caller
doesn't control that: they're just going to queue a sub-compilation for
the runtime. The only exception to that is the ZCU strategy, where we
effectively embed `_ = @import("compiler_rt")` into the Zig compilation:
there, the question does matter. Rather than trying to do multiple weird
calls to model this, just have `canBuildLibCompilerRt` return not just a
boolean, but also differentiate the self-hosted backend being capable of
building the library vs only LLVM being capable. Logic in `Compilation`
uses that difference to decide whether to use the ZCU strategy, and also
to disable the library if the compiler does not support LLVM and it is
required.

Also, remove a redundant check later on, when actually queuing jobs.
We've already checked that we can build `compiler_rt`, and
`compiler_rt_strat` is set accordingly. I'm guessing this was there to
work around a bug I saw in the old strategy assignment, where support
was ignored in some cases.

Resolves: #24623
2025-08-18 13:07:40 -07:00
Ali Cheraghi
2f422372b5 spirv: do not decorate nav alignment
they seem to be always `null` even when accessed through extern key so we have no way to tell whether they have natural alignment or not to decorate. And the reason we don't always decorate them is because some environments might be too dumb and crash for this.
2025-08-18 11:24:57 -07:00
Justus Klausecker
cf90a5e451 langref: add documentation for unions with inferred tag and explicit tag values 2025-08-17 19:17:02 -07:00
Isaac Freund
c315f2bc2e http.BodyWriter: improve clarity of chunked state machine
This is theoretically a bugfix as well, since it enforces the correct
limit on the first write after writing the header. This theoretical bug
hasn't been hit in practice though as far as I know.
2025-08-17 14:42:57 +02:00
Andrew Kelley
623290ea9b
Merge pull request #24864 from ifreund/fix-std-cmd
http.BodyWriter: handle EOF in chunkedSendFile, simplify
2025-08-16 16:24:11 -07:00
Isaac Freund
551e009da7 Build.Step.Run: fix missing stdin buffer and flush
Writer.sendFileAll() asserts non-zero buffer capacity in the case that
the fallback is hit. It also requires the caller to flush. The buffer
may be bypassed as an optimization but this is not a guarantee.

Also improve the Writer documentation and add an earlier assert on
buffer capacity in sendFileAll().
2025-08-16 15:43:48 -07:00
Andrew Kelley
399bace2f2
Merge pull request #24874 from ziglang/tls-client
std: more reliable HTTP and TLS networking
2025-08-16 14:47:52 -07: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
mlugg
0096c0806c Compilation: retain ZCU object when emitting unstripped Mach-O binary
On macOS, when using the LLVM backend, the output binary retains a
reference to this object file's debug info (as opposed to self-hosted
backends which instead emit a dSYM bundle). As such, we need to retain
this object file in such cases. This object does unfortunately "leak",
in that it won't be reused and will just sit in the cache forever (or
until GC'd in the future). But that's no worse than the cache behavior
prior to the rework that caused this, and it will become less of a
problem over time as the self-hosted backend gains usability for debug
builds and eventually becomes the default.

Resolves: #24369
2025-08-16 21:56:24 +01:00
Isaac Freund
0cfd07bc86
http.BodyWriter: handle EOF in chunkedSendFile, simplify
With these changes, the `zig std` command now works again and doesn't
trigger assertion failures or mess up the chunked transfer encoding.
2025-08-16 22:07:16 +02:00
Isaac Freund
ce4e8a991f
std-docs: improve error message on write failure 2025-08-16 17:43:15 +02:00
Josh Wolfe
4fcdb08390 [std] fix compile error in std.Io.Writer.failing 2025-08-16 00:23:47 -07:00
Özgür Akkurt
99c4890559
implement registering NAPI on IoUring (#24850) 2025-08-16 09:18:49 +02:00
Andrew Kelley
a0f9a5e78d std: more reliable HTTP and TLS networking
* std.Io.Reader: fix confused semantics of rebase. Before it was
  ambiguous whether it was supposed to be based on end or seek. Now it
  is clearly based on seek, with an added assertion for clarity.

* std.crypto.tls.Client: fix panic due to not enough buffer size
  available. Also, avoid unnecessary rebasing.

* std.http.Reader: introduce max_head_len to limit HTTP header length.
  This prevents crash in underlying reader which may require a minimum
  buffer length.

* std.http.Client: choose better buffer sizes for streams and TLS
  client. Crucially, the buffer shared by HTTP reader and TLS client
  needs to be big enough for all http headers *and* the max TLS record
  size. Bump HTTP header size default from 4K to 8K.

fixes #24872

I have noticed however that there are still fetch problems
2025-08-16 00:16:15 -07:00
Andrew Kelley
07b753f22b Fetch: bump zstd decompression buffer
see #24735
2025-08-16 00:07:40 -07:00
Ryan Liptak
98547713a3 zstd: Protect against index out-of-bounds when decoding sequences
Previously, index out-of-bounds could occur when copying match_length bytes while decoding whatever sequence happened to overflow `dest`. Now, each sequence checks that there is enough room for the full sequence_length (literal_length + match_length) before doing any copying.

Fixes the failing inputs found here: https://github.com/ziglang/zig/issues/24817#issuecomment-3192927715
2025-08-15 22:11:51 -07:00
Rue
ee85c8b6d0
re-enable std.math.modf vector tests (#24786)
* re-enable std.math.modf vector tests
* re-disable std.math.modf vector tests for `aarch64-macos`
* re-disable for s390x architecture
2025-08-16 02:36:09 +00:00
antlilja
52178d14b0 Add test for passing extern function to function 2025-08-15 18:29:06 -04:00
Jacob Young
375bc2d7b5 Dwarf: implement comptime-known extern values
Closes #24259
2025-08-15 18:29:06 -04:00
mlugg
8ef82e8355 what if we kissed by the extern source bit 2025-08-15 18:23:40 -04:00
mlugg
d835a6ba9a std.Build: improve error for peak RSS exceeding declared value
As well as the exact byte count, include a human-readable value so it's
clearer what the error is actually telling you. The exact byte count
might not be worth keeping, but I decided I would in case it's useful in
any scenario.
2025-08-15 23:03:16 +01:00
Fri3dNstuff
f758b97bfd
std.math: Add splat for vectors of u0s in rotl/rotr (#24822) 2025-08-15 23:45:33 +02:00
Manlio Perillo
39aca6f37e zon: Add anonymous struct literal in the example 2025-08-15 23:35:16 +02:00
Andrew Kelley
2201f74d7f disable failing test on windows
tracked by #24867
2025-08-15 13:34:19 -07:00
mlugg
8adabaa4ed Zcu: don't tell linkers about exports if there are compile errors
In the best case, this is redundant work, because we aren't actually
going to emit a working binary this update. In the worst case, it causes
bugs because the linker may not have *seen* the thing being exported due
to the compile errors.

Resolves: #24417
2025-08-15 20:00:30 +01:00
Andrew Kelley
ce2c9399dd zig translate-c: don't forget to flush
fixes #24672
2025-08-15 11:46:17 -07:00
Andrew Kelley
30b41dc510 std.compress.zstd.Decompress fixes
* std.Io.Reader: appendRemaining no longer supports alignment and has
  different rules about how exceeding limit. Fixed bug where it would
  return success instead of error.StreamTooLong like it was supposed to.

* std.Io.Reader: simplify appendRemaining and appendRemainingUnlimited
  to be implemented based on std.Io.Writer.Allocating

* std.Io.Writer: introduce unreachableRebase

* std.Io.Writer: remove minimum_unused_capacity from Allocating. maybe
  that flexibility could have been handy, but let's see if anyone
  actually needs it. The field is redundant with the superlinear growth
  of ArrayList capacity.

* std.Io.Writer: growingRebase also ensures total capacity on the
  preserve parameter, making it no longer necessary to do
  ensureTotalCapacity at the usage site of decompression streams.

* std.compress.flate.Decompress: fix rebase not taking into account seek

* std.compress.zstd.Decompress: split into "direct" and "indirect" usage
  patterns depending on whether a buffer is provided to init, matching
  how flate works. Remove some overzealous asserts that prevented buffer
  expansion from within rebase implementation.

* std.zig: fix readSourceFileToAlloc returning an overaligned slice
  which was difficult to free correctly.

fixes #24608
2025-08-15 10:44:35 -07:00
Andrew Kelley
6d7c6a0f4e
Merge pull request #24856 from jacobly0/aarch64-oom
aarch64: more assembler instructions
2025-08-15 10:44:00 -07:00
Frank Denis
c1eff72c4a
crypto/aes_ocb.zig: actually check against test vectors (#24835)
And use the correct bit endianness for padding
2025-08-15 13:09:06 +00:00
Jacob Young
56d62395d1 aarch64: more assembler instructions
Closes #24848
2025-08-15 06:12:45 -04:00
Will Lillis
e9eee8dace fix: print error set members in a consistent order
Co-authored-by: Matthew Lugg <mlugg@mlugg.co.uk>
2025-08-15 07:43:46 +01:00
Andrew Kelley
e395c24c6d std.fs.File.Reader: fix freestanding build failures
This should be enough to unblock people for now. We'll revisit the way
these things are organized with the upcoming std.Io interface.

fixes #24685
2025-08-14 23:10:29 -07:00
Alex Rønne Petersen
47e6528762
Merge pull request #24702 from The-King-of-Toasters/syscall-tables
Rewrite Linux syscalls generation
2025-08-15 05:38:02 +02:00
Ryan Liptak
08f0780cb2 zstd.Decompress.stream: Fix handling of skippable frames in new_frame state
The previous code assumed that `initFrame` during the `new_frame` state would always result in the `in_frame` state, but that's not always the case. `initFrame` can also result in the `skippable_frame` state, which would lead to access of union field 'in_frame' while field 'skipping_frame' is active.

Now, the switch is re-entered with the updated state so either case is handled appropriately.

Fixes the crashes from https://github.com/ziglang/zig/issues/24817
2025-08-14 17:37:51 -07:00
Andrew Kelley
e252e6c696
Merge pull request #24847 from squeek502/zstd-partial-magic
zstd.Decompress: Treat a partial magic number as a failure
2025-08-14 16:08:06 -07:00
Justus Klausecker
2761cc8be0 zig fmt: add tests for cast builtin canonicalization 2025-08-14 14:44:35 -07:00
Ryan Liptak
353cf1f671 zstd.Decompress: Delete unused/impossible "end" state 2025-08-14 14:08:49 -07:00
Ryan Liptak
60b0b21296 zstd.Decompress: Treat a partial magic number as a failure
Previously, the "allow EndOfStream" part of this logic was too permissive. If there are a few dangling bytes at the end of the stream, that should be treated as a bad magic number. The only case where EndOfStream is allowed is when the stream is truly at the end, with exactly zero bytes available.
2025-08-14 14:08:49 -07:00
Alex Rønne Petersen
be51d69dc7
Merge pull request #24845 from alexrp/netbsd-fixes
Update NetBSD system headers; make TSan cross-compilable for NetBSD
2025-08-14 22:55:02 +02:00
Andrew Kelley
af7e142485 std.Io.Writer: introduce rebase to the vtable
fixes #24814
2025-08-14 12:56:37 -07:00
Frank Denis
96e4825fbb
Validate wildcard TLS certificates correctly (#24829)
Validate wildcard certificates as specified in RFC 6125.

In particular, `*.example.com` should match `foo.example.com` but
NOT `bar.foo.example.com` as it previously did.
2025-08-14 13:57:00 +00:00
Alex Rønne Petersen
6317417fe1
test: enable tsan test for x86_64-netbsd 2025-08-14 08:25:50 +02:00
Alex Rønne Petersen
234630bb8d
netbsd: add some missing system headers
The Lua headers are needed because, yes, NetBSD has a kernel module for Lua
support. soundcard.h is technically a system header but is installed by
libossaudio and so was missed previously.

This also removes some riscv headers that shouldn't have been added because
NetBSD does not yet officially support the riscv32/riscv64 ports.

Closes #24737.
2025-08-14 08:25:08 +02:00
Andrew Kelley
6bcdcf85c7 std.fs.File.Writer.sendFile: handle sendfile errors
fixes #24842
2025-08-13 22:16:08 -07:00
Alex Rønne Petersen
007cc817a1
tsan: remove usage of libnvmm and libncurses headers on netbsd
https://github.com/llvm/llvm-project/pull/153534
2025-08-14 07:11:07 +02:00
Stephen Gregoratto
6080f2d5ea Linux: Use time64 syscalls when available
Newer 32-bit Linux targets like 32-bit RISC-V only use the 64-bit
time ABI, with these syscalls having `time64` as their suffix.

This is a stopgap solution in favor of a full audit of `std.os.linux` to
prepare for #4726.

See also #21440 for prior art.
2025-08-14 10:24:57 +10:00
Stephen Gregoratto
6f60c8eca7 Linux: Update syscall list for 6.16
The generic syscall table has different names for syscalls that take a
timespec64 on 32-bit targets, in that it adds the `_time64` suffix.
Similarly, the `_time32` suffix has been removed.

I'm not sure if the existing logic for determining the proper timespec
struct to use was subtly broken, but it should be a good chance to
finish #4726 - we only have 12 years after all...

As for the changes since 6.11..6.16:

6.11:
 - x86_64 gets `uretprobe`, a syscall to speed up returning BPF probes.
 - Hexagon gets `clone3`, but don't be fooled: it just returns ENOSYS.
6.13:
 - The `*xattr` family of syscalls have been enhanced with new `*xattrat`
   versions, similar to the other file-based `at` calls.
6.15:
 - Atomically create a detached mount tree and set mount options on it.

Finally, this commit also adds the syscall numbers for OpenRISC and maps
it to the `or1k` cpu.
2025-08-14 10:22:15 +10:00
Stephen Gregoratto
c5f10a3f7d Rewrite generate_linux_syscalls to be completely table based
Changes by Arnd Bergmann have migrated all supported architectures to
use a table for their syscall lists. This removes the need to use the
C pre-processor and simplifies the logic considerably.

All currently supported architectures have been added, with the ones Zig
doesn't support being commented out. Speaking of; OpenRisc has been
enabled for generation.
2025-08-14 10:19:31 +10:00
Alex Rønne Petersen
27d6614f81
Merge pull request #24825 from alexrp/freebsd-fixes 2025-08-14 01:00:30 +02:00
Matthew Lugg
b87b958687
Merge pull request #24816 from mlugg/small-fixes
two small fixes
2025-08-13 23:55:21 +01:00
mlugg
3736aac778 Dwarf: handle noreturn union fields in more places
A little clunky -- maybe the frontend should give an answer here -- but
this patch makes sense with the surrounding logic just to fix the crash.

Resolves: #24265
2025-08-13 23:52:40 +01:00
mlugg
e304a478c0 build runner: fix single-threaded build
Resolves: #24723
2025-08-13 23:50:57 +01:00
Kendall Condon
4f639ff880 http: fix handling of limit in chunkedSendFile
`limit` in chunkedSendFile applies only to the file, not the entire
chunk. `limit` in sendFileHeader does not include the header.

Additionally adds a comment to clarify what `limit` applies to in
sendFileHeader and fixed a small bug in it (`drain` is able to return
less then `header.len`).
2025-08-13 13:14:01 -07:00
Andrew Kelley
5e986fef1f std.fs.File.Reader: fix seekBy
Tested locally:

stage3/bin/zig build test -Dskip-release -Dskip-non-native

closes #24495
closes #24498
closes #24713
2025-08-13 12:24:14 -07:00
Matthew Lugg
a495628862
Merge pull request #24674 from Justus2308/undef-shift-bitwise
Sema: Improve comptime arithmetic undef handling
2025-08-13 14:04:59 +01:00
David Rubin
8e02f9f70d sema: strip @splat operand result type before checking it 2025-08-13 13:55:57 +01:00
Matthew Lugg
6e90ce2536
Merge pull request #24381 from Justus2308/switch-better-underscore
Enhance switch on non-exhaustive enums
2025-08-13 13:54:15 +01:00
mlugg
ba6abd71c2
llvm: unions which are equivalent to enums are not by-ref
The LLVM backend lowers unions where all fields are zero-bit as
equivalent to their backing enum, and expects them to have the same
by-ref-ness in at least one place in the backend, probably more.

Resolves: #23577
2025-08-13 11:36:16 +01:00
mlugg
38ba425b26
llvm: support small error limits
Resolves: #23533
2025-08-13 11:36:16 +01:00
Isaac Freund
b8124d9c0b std.io.Writer.Allocating: rename getWritten() to written()
This "get" is useless noise and was copied from FixedBufferWriter.
Since this API has not yet landed in a release, now is a good time
to make the breaking change to fix this.
2025-08-13 01:43:52 -07:00
Erik Schlyter
7abd62800c std.crypto.aegis: Absorb ad instead of encrypting it.
`Aegis256XGeneric` behaves differently than `Aegis128XGeneric` in that
it currently encrypts associated data instead of just absorbing it. Even
though the end result is the same, there's no point in encrypting and
copying the ad into a buffer that gets overwritten anyway. This fix
makes `Aegis256XGeneric` behave the same as `Aegis128XGeneric`.
2025-08-13 09:00:57 +02:00
Alex Rønne Petersen
113d3dd3f0 std.Target: bump default android API level from 24 to 29
According to https://apilevels.com, 88.5% of Android users are on 29+. Older API
levels require libc as of https://github.com/ziglang/zig/pull/24629, which has
confused some users. Seems reasonable to bump the default so most people won't
be confused by this.
2025-08-13 08:59:13 +02:00
Alex Rønne Petersen
662303d7e7
Merge pull request #24734 from Rexicon226/tsan-fix 2025-08-13 08:57:52 +02:00
Alex Rønne Petersen
b7602a17f8
freebsd: correctly define __FreeBSD_version to the first stable release
See: https://docs.freebsd.org/en/books/porters-handbook/versions

Closes #24819.
2025-08-13 08:46:52 +02:00
Alex Rønne Petersen
e089d21439
freebsd: fix PIC macro not being defined for crt1_s.S
Closes #24818.
2025-08-13 08:40:56 +02:00
Alex Rønne Petersen
e37fc57495
tsan: remove usage of libcrypt and libncurses headers
https://github.com/llvm/llvm-project/pull/153351

Closes #24736.
2025-08-13 08:40:35 +02:00
Rue
dd4e25cf44
optimize @intCast in llvm backend (#24739) 2025-08-13 00:56:31 +00:00
Justus Klausecker
8fda49ea8a fix: remove incorrect '&' 2025-08-12 16:33:58 +02:00
Justus Klausecker
277e4a8337 fix: emit vector instead of scalar u1_zero in shl_with_overflow logic 2025-08-12 16:33:58 +02:00
Justus Klausecker
4ec421372f add remaining undef value tests ; fix @truncate undef retval type 2025-08-12 16:33:58 +02:00
Justus Klausecker
f0ffe30f2f add undef shift tests ; mirror zirShl logic for @shlWithOverflow 2025-08-12 16:33:58 +02:00
Justus Klausecker
8f5ec2a1fb Sema: replace all remaining aggregate interns related to @typeInfo 2025-08-12 16:33:58 +02:00
Justus Klausecker
79756e681d remove redundant test cases 2025-08-12 16:33:58 +02:00
Justus Klausecker
76d2782149 replace most aggregate interns in x86_64/CodeGen 2025-08-12 16:33:57 +02:00
Justus Klausecker
79e5c138c6 replace even more aggregate interns 2025-08-12 16:33:57 +02:00
Justus Klausecker
7756fa6641 Sema: replace most aggregate interns with pt.aggregateValue 2025-08-12 16:33:57 +02:00
Justus Klausecker
05762ca02f address most comments 2025-08-12 16:33:57 +02:00
Justus Klausecker
0ef26d113a make >> a compile error with any undef arg ; add a bunch of test cases 2025-08-12 16:33:57 +02:00
Justus Klausecker
d0586da18e Sema: Improve comptime arithmetic undef handling
This commit expands on the foundations laid by https://github.com/ziglang/zig/pull/23177
and moves even more `Sema`-only functionality from `Value`
to `Sema.arith`. Specifically all shift and bitwise operations,
`@truncate`, `@bitReverse` and `@byteSwap` have been moved and
adapted to the new rules around `undefined`.

Especially the comptime shift operations have been basically
rewritten, fixing many open issues in the process.

New rules applied to operators:
* `<<`, `@shlExact`, `@shlWithOverflow`, `>>`, `@shrExact`: compile error if any operand is undef
* `<<|`, `~`, `^`, `@truncate`, `@bitReverse`, `@byteSwap`: return undef if any operand is undef
* `&`, `|`: Return undef if both operands are undef, turn undef into actual `0xAA` bytes otherwise

Additionally this commit canonicalizes the representation of
aggregates with all-undefined members in the `InternPool` by
disallowing them and enforcing the usage of a single typed
`undef` value instead. This reduces the amount of edge cases
and fixes a bunch of bugs related to partially undefined vecs.

List of operations directly affected by this patch:
* `<<`, `<<|`, `@shlExact`, `@shlWithOverflow`
* `>>`, `@shrExact`
* `&`, `|`, `~`, `^` and their atomic rmw + reduce pendants
* `@truncate`, `@bitReverse`, `@byteSwap`
2025-08-12 16:33:57 +02:00
Andrew Kelley
749f10af49 std.ArrayList: make unmanaged the default 2025-08-11 15:52:49 -07:00
Jacob Young
d625158354 aarch64: implement more assembler instructions 2025-08-11 15:47:51 -07:00
Andrew Kelley
59de7e3a57 std: introduce orderedRemoveMany
This algorithm is non-trivial and makes sense for any data structure
that acts as an array list, so I thought it would make sense as a
method.

I have a real world case for this in a music player application
(deleting queue items).

Adds the method to:
* ArrayList
* ArrayHashMap
* MultiArrayList
2025-08-11 13:32:12 -07:00
Andrew Kelley
282c3575b1 std.fs.File: prefer getSize over getEndPos
The former detects when it is appropriate to switch to streaming mode.

closes #24798
2025-08-11 12:27:52 -07:00
Jacob Young
60f8584927 Dwarf: port to new Writer API 2025-08-11 12:00:50 -07:00
Jacob Young
38dfa6537e cbe: emit nonstring attribute
Closes #24545
2025-08-11 11:30:51 -07:00
Andrew Kelley
0b3c3c02e3 linker: delete plan9 support
This experimental target was never fully completed. The operating system
is not that interesting or popular anyway, and the maintainer is no
longer around.

Not worth the maintenance burden. This code can be resurrected later if
it is worth it. In such case it will be subject to greater scrutiny.
2025-08-11 10:56:20 -07:00
Will Lillis
d1917b5c3a fix(fmt): return correct exit code for zig fmt --stdin --check 2025-08-11 07:34:26 +02:00
Ryan Liptak
3280fc98f3 Writer: Delete writePreserve/writeAllPreserve
This is one way of partially addressing https://github.com/ziglang/zig/issues/24767

- These functions are unused
- These functions are untested
- These functions are broken
  + The same dangling pointer bug from 6219c015d8e8c958d96e5caa5ef0dbab9c414996 exists in `writePreserve`
  + The order of the bytes preserved in relation to the `bytes` being written can differ depending on unused buffer capacity at the time of the call and the drain implementation.

If there ends up being a need for these functions, they can be fixed and added back.
2025-08-10 19:49:02 -07:00
David Rubin
20486c4a81 elf: fix potential overflow in got emission 2025-08-11 03:02:54 +02:00
David Rubin
826b33863f test: add a standalone test for compiling tsan 2025-08-11 03:02:54 +02:00
David Rubin
c42187732d tsan: remove interceptors for termio 2025-08-11 03:02:54 +02:00
Andrew Kelley
b9a6dae2ae std.fs.File.Reader.getSize: check file kind on stat
closes #24794
2025-08-10 17:51:22 -07:00
Andrew Kelley
e667884f9b std.net.Stream.Reader: init size_err
This code knows in advance that stat() should never be called.

closes #24754
2025-08-10 17:38:46 -07:00
Andrew Kelley
e25168d01b
Merge pull request #24774 from kcbanner/fixup_webui_windows
Fix `respondWebSocket`, use overlapped sockets on Windows, and re-enable --webui
2025-08-10 11:06:36 -07:00
Alexandre Blais
6eeceb4b14 docs(zon/stringify.zig): Added missing non-serializable type 2025-08-10 19:48:09 +02:00
Alex Rønne Petersen
6bb6013d3a
Merge pull request #24768 from alichraghi/spv5
spirv: remove prune_unused ISel
2025-08-10 19:45:16 +02:00
Techatrix
2983285815 zig fmt: flush stdout before exiting with error 2025-08-10 19:42:54 +02:00
Linus Groh
6a1d61d504 std.c: Remove serenity's internet_checksum() function
See: 59911d8da3
2025-08-10 18:21:47 +02:00
Andrew Kelley
0a1a738320
Merge pull request #24743 from ziglang/BufferedWriter
std.Io: delete BufferedWriter
2025-08-09 16:28:19 -07:00
kcbanner
95f57c3369 net: Always set WSA_FLAG_OVERLAPPED when creating Windows sockets. Rework send and receive logic to use overlapped I/O.
build-web: Remove the now-redundant supports_recv logic
2025-08-09 18:48:15 -04:00
kcbanner
125c4a265a Fix respondWebSocket, enable --webui on Windows
This commit re-enables the --webui functionality on windows, with the caveat that rebuild functionality is still disabled (due to deadlocks caused by reading to / writing from the same non-overlapped socket on multiple threads). I updated the UI to be aware of this, and hide the `Rebuild` button.

http.Server: Remove incorrect advance() call. This was causing browsers to disconnect the websocket, as we were sending undefined bytes.
build.WebServer: Re-enable on windows, but disable functionality that requires receiving messages from the client
build-web: Show total times in tables
2025-08-09 16:06:33 -04:00
Ali Cheraghi
64563e2fff
test: skip tests that were not meant to pass for spirv 2025-08-09 13:27:45 +03:30
Ali Cheraghi
bed99e1ecd
spirv: remove prune_unused ISel 2025-08-09 13:27:04 +03:30
Ian Johnson
14f11377cb Fetch.git: fix FetchStream packet reading
Progress towards #24732
2025-08-08 19:37:33 -07:00
Andrew Kelley
df46ee61c4 std.Io.Writer.Allocating: configurable bump amount 2025-08-08 19:22:08 -07:00
Andrew Kelley
045bb14897 zig std: fix build failures 2025-08-08 17:17:53 -07:00
Andrew Kelley
8c9dfcbd0f std.Io: remove BufferedWriter 2025-08-08 17:17:53 -07:00
mlugg
5f7a0bbabf Sema: fix unreasonable progress node numbers
The "completed" count in the "Semantic Analysis" progress node had
regressed since 0.14.0: the number got crazy big very fast, even on
simple cases. For instance, an empty `pub fn main` got to ~59,000 where
on 0.14 it only reached ~4,000. This was happening because I was
unintentionally introducing a node every time type resolution was
*requested*, even if (as is usually the case) it turned out to already
be done. The fix is simply to start the progress node a little later,
once we know we are actually doing semantic analysis. This brings the
number for that empty test case down to ~5,000, which makes perfect
sense. It won't exactly match 0.14, because the standard library has
changed, and also because the compiler's progress output does have some
*intentional* changes.
2025-08-08 23:14:26 +01:00
Andrew Kelley
2a8751e37f Fetch.git: replace a toss with discardAll
toss is only valid following a peek.
2025-08-08 15:03:05 -07:00
Andrew Kelley
91a81d3846 std.compress.flate.Decompress: fix buffer size in test 2025-08-08 15:03:05 -07:00
mlugg
1440519239 compiler: improve error reporting
The functions `Compilation.create` and `Compilation.update` previously
returned inferred error sets, which had built up a lot of crap over
time. This meant that certain error conditions -- particularly certain
filesystem errors -- were not being reported properly (at best the CLI
would just print the error name). This was also a problem in
sub-compilations, where at times only the error name -- which might just
be something like `LinkFailed` -- would be visible.

This commit makes the error handling here more disciplined by
introducing concrete error sets to these functions (and a few more as a
consequence). These error sets are small: errors in `update` are almost
all reported via compile errors, and errors in `create` are reported
through a new `Compilation.CreateDiagnostic` type, a tagged union of
possible error cases. This allows for better error reporting.

Sub-compilations also report errors more correctly in several cases,
leading to more informative errors in the case of compiler bugs.

Also fixes some race conditions in library building by replacing calls
to `setMiscFailure` with calls to `lockAndSetMiscFailure`. Compilation
of libraries such as libc happens on the thread pool, so the logic must
synchronize its access to shared `Compilation` state.
2025-08-08 22:37:27 +01:00
Andrew Kelley
3d25a9c1e0 std.Io.Writer.Allocating.sendFile: use logicalPos
fixes #24754

tested with `zig build test-std -Dskip-release`
2025-08-08 14:21:57 -07:00
Igor Anić
6219c015d8 Io.Writer fix dangling pointer
While underlying writer is Allocating writer buffer can grow in
vtable.drain call. We should not hold pointer to the buffer before that
call and use it after.
This remembers positions instead of holding reference.
2025-08-08 12:56:26 -07:00
Giuseppe Cesarano
3ee4252183 Fix: std.elf offset computation 2025-08-08 12:47:00 -07:00
Andrew Kelley
1ba6838bc3
Merge pull request #24740 from ziglang/http-plus-fixes
fetch, tls, and http fixes
2025-08-08 12:33:53 -07:00
Andrew Kelley
d2f7792039
Merge pull request #24742 from ziglang/CountingWriter
std.Io: delete CountingWriter
2025-08-08 12:30:09 -07:00
Igor Anić
3ea015db96 Io.Reader fix defaultReadVec
Running tar.pipeToFileSystem compressed_mingw_includes.tar file from #24732
finishes in infinite loop calling defaultReadVec with:
r.seek = 1024
r.end = 1024
r.buffer.len = 1024
first.len = 512
that combination calls vtable.stream with 0 capacity writer and loops
forever.

Comment is to use whichever has larger capacity, and this fix reflects that.
2025-08-08 12:28:00 -07:00
Ryan Liptak
23fff3442d flate: Handle invalid block type
Fixes `panic: invalid enum value` when the type bits had the u2 value of 3.

Contributes towards #24741
2025-08-08 12:27:25 -07:00
Alex Rønne Petersen
d984e7d2fa
ci: trigger ci-pr-riscv64-linux workflow on unlabeled events
This way, if the ci-riscv64-linux label was added to a PR previously, removing
it will cause the concurrency group of the workflow to cancel the runs triggered
by the label being added.
2025-08-08 17:15:44 +02:00
Alex Rønne Petersen
63b663a63b
ci: fix concurrency group for ci-pr-riscv64-linux workflow 2025-08-08 17:11:59 +02:00
Alex Rønne Petersen
87f2dadbf1
ci: run riscv64-linux jobs if ci-riscv64-linux label is applied
This needs to be a separate workflow so that it doesn't interfere with non-CI
labeling of pull requests.
2025-08-08 17:08:14 +02:00
Alex Rønne Petersen
ac3229a435
Revert "ci: run riscv64-linux jobs if ci-riscv64-linux label is applied"
This reverts commit 8101104db0bdc7edeb07d91ab758c8a8d0861061.
2025-08-08 17:05:20 +02:00
Alex Rønne Petersen
8101104db0
ci: run riscv64-linux jobs if ci-riscv64-linux label is applied 2025-08-08 16:49:54 +02:00
Andrew Kelley
9a538e0d54 link.Dwarf: minimal changes to remove CountingWriter 2025-08-07 22:26:42 -07:00
Andrew Kelley
281f657377 Revert "random patches from another branch"
This reverts commit 76ed05523d6327789a8365571b67a214ac527ef9.

they don't work
2025-08-07 22:26:42 -07:00
Andrew Kelley
c5a5983150 random patches from another branch 2025-08-07 22:26:42 -07:00
Andrew Kelley
94dd28b7f7 std.Io: delete CountingWriter 2025-08-07 22:26:42 -07:00
Alex Rønne Petersen
0d0f09fb0e std.os.windows: map RtlGenRandom() failure to error.SystemResources
Closes #23666.
2025-08-08 07:25:26 +02:00
Andrew Kelley
3fb86841cc
Merge pull request #24661 from alichraghi/spv4
spirv: refactor and remove deduplication ISel
2025-08-07 20:55:50 -07:00
Andrew Kelley
8da645c883 Fetch: fix FetchStream logic 2025-08-07 19:55:40 -07:00
Andrew Kelley
8721efece4 std.crypto.tls.Client: always write to buffer
simplifies the logic & makes it respect limit
2025-08-07 19:55:40 -07:00
Andrew Kelley
d7bf608821 Fetch: make FetchStream live longer 2025-08-07 19:55:40 -07:00
Andrew Kelley
6244f5c6cb std.http.bodyReader: add missing flush in endUnflushed
It's a bit counter-intuitive, but there are two streams here: the
implementation here, and the connected output stream.

When we say "unflushed" we mean don't flush the connected output stream
because that's managed externally. But an "end" operation should always
flush the implementation stream.
2025-08-07 19:55:40 -07:00
Andrew Kelley
af2ac24333 Fetch: handle compressed git+http 2025-08-07 19:55:40 -07:00
Andrew Kelley
5ce8e9325b std.http.Client: fix fetching by adding a buffer 2025-08-07 19:54:39 -07:00
Andrew Kelley
5998a8cebe
Merge pull request #24698 from ziglang/http
std: rework HTTP and TLS for new I/O API
2025-08-07 19:54:25 -07:00
TibboddiT
2cf15bee03
Fix some libc version checks for Bionic 2025-08-08 01:26:00 +00:00
Frank Denis
242102f9d1 std/zip.zig: perform backslash-to-forward-slash before isBadFilename()
Previously, when extracting a ZIP file, isBadFilename(), which is
designed to reject ../ patterns to prevent directory traversal, was
called before normalizing backslashes to forward slashes.

This allowed path traversal sequences like ..\\..\\..\\etc\\passwd
which pass validation but are then converted to ../../../etc/passwd
for file extraction.
2025-08-07 14:42:48 -07:00
Igor Anić
6de2310035
flate change bit reader Bits to usize (#24719)
Don't see why byte returned from specialPeek needs to be shifted by
remaining_needed_bits.
I believe that decision in specialPeek should be done on the number of
the remaining bits not of the content of that bits.

Some test result are changed, but they are now consistent with the
original state as found in:
5f790464b0/lib/std/compress/flate/Decompress.zig

Changing Bits from usize to u32 or u64 now returns same results.

* flate: simplify peekBitsEnding

`peekBits` returns at most asked number of bits. Fails with EndOfStream
when there are no available bits. If there are less bits available than
asked still returns that available bits.
Hopefully this change better reflects intention. On first input stream
peek error we break the loop.
2025-08-07 14:40:08 -07:00
Andrew Kelley
46b34949c3 TLS, HTTP, and package fetching fixes
* TLS: add missing assert for output buffer length requirement
* TLS: add missing flushes
* TLS: add flush implementation
* TLS: finish drain implementation
* HTTP: correct buffer sizes for TLS
* HTTP: expose a getReadError method on Connection
* HTTP: add missing flush on sendBodyComplete
* Fetch: remove unwanted deinit
* Fetch: improve error reporting
2025-08-07 10:04:52 -07:00
Andrew Kelley
172d31b0e2 std.fs.File.Reader: fix readVec fill
respect the case when there is existing buffer
2025-08-07 10:04:52 -07:00
Andrew Kelley
163a827826 std.http: remove custom method support
let's see if anybody notices it missing
2025-08-07 10:04:52 -07:00
Andrew Kelley
4567241d8d fetch: avoid copying Resource 2025-08-07 10:04:52 -07:00
Andrew Kelley
6b411f147c std.http: address review comments
thank you everybody
2025-08-07 10:04:52 -07:00
Andrew Kelley
618a435ad4 std.http.Server: add safety for invalidated Head strings
and fix bad unit test API usage that it finds
2025-08-07 10:04:52 -07:00
Ryan Liptak
858716aa4d resinator: a few more updates/fixes
Just enough to get things working correctly again
2025-08-07 10:04:52 -07:00
Andrew Kelley
5a743be6b4 resinator: just enough fixes to make it compile 2025-08-07 10:04:52 -07:00
Andrew Kelley
262bfc5826 std.Io: delete LimitedReader 2025-08-07 10:04:52 -07:00
Andrew Kelley
e061445fc2 std.Io: delete BufferedReader 2025-08-07 10:04:52 -07:00
Andrew Kelley
366884ab06 remove std.fifo
I never liked how this data structure took its API as a parameter.

This use case is now served by std.Io buffering.
2025-08-07 10:04:52 -07:00
Andrew Kelley
3f8ed5504e std.net: fix windows build 2025-08-07 10:04:52 -07:00
Andrew Kelley
3837862e52 fix 32-bit builds 2025-08-07 10:04:52 -07:00
Andrew Kelley
abd76938cb std.Io.Reader: fix appendRemainingUnlimited
Now it avoids mutating `r` unnecessarily, allowing the `ending` Reader
to work.
2025-08-07 10:04:52 -07:00
Andrew Kelley
9e5048c3a5 fetch: update for new http API
it's not quite finished because I need to make it not copy the Resource
2025-08-07 10:04:51 -07:00
Andrew Kelley
fef41c66db update build system to new http.Server API 2025-08-07 10:04:29 -07:00
Andrew Kelley
e2d81bf6c0 http fixes 2025-08-07 10:04:29 -07:00
Andrew Kelley
28190cc404 std.crypto.tls: rework for new std.Io API 2025-08-07 10:04:29 -07:00
Andrew Kelley
02908a2d8c std.http: rework for new std.Io API 2025-08-07 10:04:28 -07:00
Alex Rønne Petersen
8843631f7e
Merge pull request #24709 from rootbeer/24380-fstatat-race-fix 2025-08-07 16:36:52 +02:00
Meghan Denny
63c5329156 std: fix std.c._msize signature 2025-08-07 16:02:52 +02:00
Justus Klausecker
aaee26bb19 remove unnecessary discard 2025-08-07 14:34:05 +02:00
Justus Klausecker
0ecbd5a0e1 address comments 2025-08-07 13:58:49 +02:00
Justus Klausecker
ba549a7d67 Add support for both '_' and 'else' prongs at the same time in switch statements
If both are used, 'else' handles named members and '_' handles
unnamed members. In this case the 'else' prong will be unrolled
to an explicit case containing all remaining named values.
2025-08-07 13:58:47 +02:00
Justus Klausecker
1d9b1c0212 Permit explicit tags with '_' switch prong
Mainly affects ZIR representation of switch_block[_ref]
and special prong (detection) logic for switch.
Adds a new SpecialProng tag 'absorbing_under' that allows
specifying additional explicit tags in a '_' prong which
are respected when checking that every value is handled
during semantic analysis but are not transformed into AIR
and instead 'absorbed' by the '_' branch.
2025-08-07 13:57:57 +02:00
Matthew Lugg
fd9cfc39f5
Merge pull request #24199 from Justus2308/24106-fmt-casts
zig fmt: canonicalize nested cast builtin order
2025-08-07 10:55:03 +01:00
Pat Tullmann
cf47d283d1 lib/std/posix/test.zig: don't compare blksize in "fstatat"
In trying to reproduce the race in #24380, my system tripped over the stat
"blocks" field changing in this test.  The value was almost always 8
(effectively 4k) or very infrequently 0 (I saw the 0 from both `fstat` and
`fstatat`).  I believe the underlying filesystem is free to asynchronously
change this value. For example, if it migrates a file between some
"inline" or maybe journal storage, and actual on-disk blocks.  So it seems
plausible that its allowed to change between stat calls.

Breaking up the struct comparison this way means we also don't compare any
of the padding or "reserved" fields, too.  And we can narrow down the
s390x-linux work-around.
2025-08-06 22:12:42 -07:00
Pat Tullmann
caf80e90b8 linux/mips.zig: Use i32 for stat nsec fields
The `atime()`, etc wrappers here expect to create a `std.linux.timespec`
(defined in `linux.zig` to have `isize` fields), so the u32 causes errors:

   error: expected type 'isize', found 'u32'
   .nsec = self.atim_nsec,

Make the nsec fields signed for consistency with all the other structs,
with and with `std.linux.timespec`.

Also looks like the comment on `__pad1` was copied from `__pad0`, but it
only applies to `__pad0`.
2025-08-06 22:12:41 -07:00
Andrew Kelley
04fe1bfe3c std.Io.Reader: use readVec for fill functions
readVec has two updated responsibilities:
1. it must respect any existing already buffered data.
2. it must write to the buffer if data is empty
2025-08-06 21:23:06 -07:00
mlugg
e17a050bc6 link: prevent deadlock when prelink tasks fail
If an error occured which prevented a prelink task from being queued,
then `pending_prelink_tasks` would never be decremented, which could
cause deadlocks in some cases. So, instead of calculating ahead of time
the number of prelink tasks to expect, we use a simpler strategy which
is much like a wait group: we add 1 to a value when we spawn a worker,
and in the worker function, `defer` decrementing the value. The initial
value is 1, and there's a decrement after all of the workers are
spawned, so once it hits 0, prelink is done (be it with a failure or a
success).
2025-08-06 21:50:16 +01:00
mlugg
3de8bbd3d4 Sema: fix initializing comptime-known constant with OPV union field
Resolves: #24716
2025-08-06 20:47:03 +01:00
kj4tmp@gmail.com
44ea11d71f #24471: add mlock syscalls to std.os.linux 2025-08-06 12:18:45 +02:00
Alex Rønne Petersen
7ee6dab39f Revert "Sema: Stop adding Windows implib link inputs for extern "..." syntax."
This reverts commit b461d07a5464aec86c533434dab0b58edfffb331.

After some discussion in the team, we've decided that this is too disruptive,
especially because the linker errors are less than helpful. That's a fixable
problem, so we might reconsider this in the future, but revert it for now.
2025-08-06 06:15:13 +02:00
massi
9a158c1dae
autodoc: Use the search input's value on load (#24467)
Co-authored-by: massi <git@massi.world>
2025-08-06 03:23:24 +00:00
Igor Anić
d2149106a6 flate zlib fix end of block reading
`n` is wanted number of bits to toss
`buffered_n` is actual number of bytes in `next_int`
2025-08-05 17:09:41 -07:00
Andrew Kelley
d8cecffe31
Merge pull request #24699 from ziglang/bounded
remove RingBuffer; remove BoundedArray; use `@memmove`
2025-08-05 16:24:28 -07:00
Giuseppe Cesarano
3914eaf357
std.elf: buffer header iterator API (#24691)
Closes #24666.
2025-08-05 10:00:33 -07:00
Andrew Kelley
8c11ada66c std: delete RingBuffer
Progress towards #19231
2025-08-05 09:56:02 -07:00
Andrew Kelley
b6f84c47c4 std.base64: delete encodeFromReaderToWriter
this function is wacky, should not have been merged
2025-08-05 09:56:02 -07:00
Andrew Kelley
196e36bbb2 std: remove BoundedArray
This use case is handled by ArrayListUnmanaged via the "...Bounded"
method variants, and it's more optimal to share machine code, versus
generating multiple versions of each function for differing array
lengths.
2025-08-05 09:56:02 -07:00
Andrew Kelley
c47ec4f3d7 std.array_list: add bounded methods 2025-08-05 09:56:02 -07:00
Andrew Kelley
6f545683f3 std: replace various mem copies with @memmove 2025-08-05 09:56:02 -07:00
Veikka Tuominen
82961a8c9f std.c: fix utsname array sizes 2025-08-05 00:18:14 -07:00
David Rubin
def25b9189 crypto: fix typo in ecdsa comment 2025-08-05 07:51:39 +01:00
KNnut
fcb088cb6a std.Target.Query: fix WindowsVersion format in zigTriple() 2025-08-05 06:08:42 +02:00
Ian Johnson
96be6f6566 std.compress.flate.Decompress: return correct size for unbuffered decompression
Closes #24686

As a bonus, this commit also makes the `git.zig` "testing `main`" compile again.
2025-08-04 19:32:14 -07:00
Alex Rønne Petersen
163e9ce7d9
Merge pull request #24629 from alexrp/android-requires-libc
`std.Target`: require libc for Android API levels prior to 29
2025-08-04 17:59:47 +02:00
Matthew Lugg
9b509dad30
Merge pull request #24689 from mlugg/build-no-watch-regression
build runner: fix FTBFS on targets without `--watch` implementation
2025-08-04 16:23:58 +01:00
Loris Cro
70c6a9fba6 init: small fix to zig init template
it was placing the current zig version in the wrong field
2025-08-04 14:25:08 +02:00
Alex Rønne Petersen
65db19a289
Merge pull request #24680 from alexrp/target-os-versions
`std.Target`: Bump min/max OS versions for 0.15.0
2025-08-04 11:02:50 +02:00
mlugg
422e8d476c
build runner: fix FTBFS on targets without --watch implementation
This was a regression in #24588.

I have verified that this patch works by confirming that with the
downstream patches SerenityOS apply to the Zig source tree (sans the one
working around this regression), I can build the build runner for
SerenityOS.

Resolves: #24682
2025-08-04 09:47:56 +01:00
mlugg
32a069f909
cli: add --debug-libc to zig build
This option is similar to `--debug-target` in letting us override
details of the build runner target when debugging the build system.
While `--debug-target` lets us override the target query, this option
lets us override the libc installation. This option is only usable in a
compiler built with debug extensions.

I am using this to (try to) test the build runner targeting SerenityOS.
2025-08-04 09:47:56 +01:00
Ali Cheraghi
cd4b03c5ed
spirv: define and use extended instruction set opcodes 2025-08-04 07:05:00 +03:30
Andrew Kelley
dabae3f9dc linker: remove dependency on std.fifo 2025-08-03 19:22:28 -07:00
Alex Rønne Petersen
493265486c
Revert "ci: target baseline instead of spacemit_x60 on riscv64-linux"
This reverts commit fa445d86a110f1171b75824fe5ec139089fa4733.

Narrator: It did, in fact, make a difference.

For whatever reason, building LLVM against spacemit_x60 or baseline makes no
noticeable difference in terms of performance, but building the Zig compiler
against spacemit_x60 does. Also, the miscompilation that was causing
riscv64-linux-debug to fail was in the LLVM libraries, not in the Zig compiler,
so we may as well take the win here.
2025-08-03 22:40:13 +02:00
Alex Rønne Petersen
ba7cc72c47
std.Target: bump watchos min version to 8.0.0 2025-08-03 20:08:19 +02:00
Alex Rønne Petersen
71722df4ab
std.Target: bump driverkit min version to 20.0.0 2025-08-03 20:08:07 +02:00
Alex Rønne Petersen
e9093b8d18
std.Target: bump max versions for Apple targets 2025-08-03 20:05:21 +02:00
Alex Rønne Petersen
5b74d33471
std.Target: bump amdhsa max version to 6.4.2 2025-08-03 20:00:32 +02:00
Alex Rønne Petersen
afe458e9b6
std.Target: bump vulkan max version to 1.4.321 2025-08-03 19:59:46 +02:00
Alex Rønne Petersen
7f2140710f
std.Target: bump cuda max version to 12.9.1 2025-08-03 19:59:46 +02:00
Alex Rønne Petersen
39b653c5e7
std.Target: bump freebsd max version to 14.3.0 2025-08-03 19:59:43 +02:00
Alex Rønne Petersen
af3baee5ca
std.Target: bump linux max version to 6.16.0 2025-08-03 19:59:40 +02:00
Alex Rønne Petersen
1808ecfa04
std.Target: bump fuchsia max version to 27.0.0 2025-08-03 19:59:35 +02:00
Alex Rønne Petersen
765825b802
ci: bump riscv64-linux timeout from 6 hours to 7 hours
GitHub is apparently very bad at arithmetic and so will cancel jobs that pass
the 5 hours mark, even if they're nowhere near the 6 hours timeout. So add an
hour to assist GitHub in this very difficult task.
2025-08-03 16:46:15 +02:00
Justus Klausecker
7c35070b90 zig fmt: apply new cast builtin order 2025-08-03 14:59:56 +02:00
Justus Klausecker
81219493f8 zig fmt: canonicalize nested cast builtin order 2025-08-03 14:54:00 +02:00
Ali Cheraghi
246e1de554
Watch: do not fail when file is removed
before this we would get a crash
2025-08-03 13:16:49 +03:30
Alex Rønne Petersen
a5f891d0b3
Merge pull request #24562 from h57624paen/fix-win-spawn-double-normalize
std.process.Child: fix double path normalization in spawnWindows
2025-08-03 11:19:10 +02:00
Alex Rønne Petersen
fa445d86a1
ci: target baseline instead of spacemit_x60 on riscv64-linux
Doesn't seem to make much of a difference anyway, and LLVM 20 appears to still
have some miscompilations with vector and bitmanip extensions enabled.
2025-08-03 11:05:04 +02:00
Matthew Lugg
c80aa9f719
Merge pull request #22997 from Rexicon226/align-0-reify
sema: compile error on reifying align(0) fields and pointers
2025-08-03 09:58:23 +01:00
Ali Cheraghi
58b9200106
spirv: use packed struct's backing int type for shift value 2025-08-03 12:10:23 +03:30
DialecticalMaterialist
616e69c807 OpenGL SPIR-V support
The support was already there but somebody forgot to allow to use the
calling conventions spirv_fragment and spirv_vertex when having opengl
as os tag.
2025-08-03 10:39:07 +02:00
David Rubin
4d1010d36c llvm: correctly lower double_integer for rv32 2025-08-03 10:22:26 +02:00
Ali Cheraghi
d15a7b1b21
spirv: move more type emitting functions to Module 2025-08-03 04:54:28 +03:30
David Rubin
e82d67233b
disallow alignment on packed union fields 2025-08-02 09:51:26 -07:00
mlugg
e98aeeb73f std.Build: keep compiler alive under -fincremental --webui
Previously, this only applied when using `-fincremental --watch`, but
`--webui` makes the build runner stay alive just like `--watch` does, so
the same logic applies here. Without this, attempting to perform
incremental updates with `--webui` performs full rebuilds. (I did test
that before merging the PR, but at that time I was passing `--watch`
too -- which has since been disallowed -- so I missed that it doesn't
work as expected without that option!)
2025-08-02 08:56:19 +01:00
Alex Rønne Petersen
239efa7e67
Merge branch 'riscv-ci' 2025-08-02 09:41:04 +02:00
Alex Rønne Petersen
bab0de92b7
ci: re-renable riscv64-linux-debug and riscv64-linux-release for master 2025-08-02 09:39:56 +02:00
Alex Rønne Petersen
4ec232a346
ci: set riscv64-linux timeouts to 6 hours 2025-08-02 09:37:53 +02:00
Alex Rønne Petersen
930c6ca49d
ci: don't run test-standalone on riscv64-linux 2025-08-02 09:34:55 +02:00
Alex Rønne Petersen
a0e58501af
ci: use -Dskip-compile-errors on riscv64-linux 2025-08-02 09:34:55 +02:00
Alex Rønne Petersen
bcaae562d6
build: add -Dskip-compile-errors option
Skips tests in test/cases/compile_errors.
2025-08-02 09:34:55 +02:00
Alex Rønne Petersen
761857e3f9
ci: temporarily disable test-link on riscv64-linux
https://github.com/ziglang/zig/issues/24663
2025-08-02 09:34:53 +02:00
Ali Cheraghi
5525a90a47
spirv: remove deduplication ISel 2025-08-02 08:56:39 +03:30
mlugg
abf1795337 std.Build.Watch: add macOS implementation based on FSEventStream
Resolves: #21905
2025-08-02 05:13:13 +01:00
Ali Cheraghi
31de2c873f
spirv: refactor 2025-08-02 04:16:01 +03:30
Andrew Kelley
742956865c
Merge pull request #24614 from ziglang/flate
std.compress.flate: rework decompression and delete compression
2025-08-01 16:34:43 -07:00
mlugg
dcc3e6e1dd build system: replace fuzzing UI with build UI, add time report
This commit replaces the "fuzzer" UI, previously accessed with the
`--fuzz` and `--port` flags, with a more interesting web UI which allows
more interactions with the Zig build system. Most notably, it allows
accessing the data emitted by a new "time report" system, which allows
users to see which parts of Zig programs take the longest to compile.

The option to expose the web UI is `--webui`. By default, it will listen
on `[::1]` on a random port, but any IPv6 or IPv4 address can be
specified with e.g. `--webui=[::1]:8000` or `--webui=127.0.0.1:8000`.
The options `--fuzz` and `--time-report` both imply `--webui` if not
given. Currently, `--webui` is incompatible with `--watch`; specifying
both will cause `zig build` to exit with a fatal error.

When the web UI is enabled, the build runner spawns the web server as
soon as the configure phase completes. The frontend code consists of one
HTML file, one JavaScript file, two CSS files, and a few Zig source
files which are built into a WASM blob on-demand -- this is all very
similar to the old fuzzer UI. Also inherited from the fuzzer UI is that
the build system communicates with web clients over a WebSocket
connection.

When the build finishes, if `--webui` was passed (i.e. if the web server
is running), the build runner does not terminate; it continues running
to serve web requests, allowing interactive control of the build system.

In the web interface is an overall "status" indicating whether a build
is currently running, and also a list of all steps in this build. There
are visual indicators (colors and spinners) for in-progress, succeeded,
and failed steps. There is a "Rebuild" button which will cause the build
system to reset the state of every step (note that this does not affect
caching) and evaluate the step graph again.

If `--time-report` is passed to `zig build`, a new section of the
interface becomes visible, which associates every build step with a
"time report". For most steps, this is just a simple "time taken" value.
However, for `Compile` steps, the compiler communicates with the build
system to provide it with much more interesting information: time taken
for various pipeline phases, with a per-declaration and per-file
breakdown, sorted by slowest declarations/files first. This feature is
still in its early stages: the data can be a little tricky to
understand, and there is no way to, for instance, sort by different
properties, or filter to certain files. However, it has already given us
some interesting statistics, and can be useful for spotting, for
instance, particularly complex and slow compile-time logic.
Additionally, if a compilation uses LLVM, its time report includes the
"LLVM pass timing" information, which was previously accessible with the
(now removed) `-ftime-report` compiler flag.

To make time reports more useful, ZIR and compilation caches are ignored
by the Zig compiler when they are enabled -- in other words, `Compile`
steps *always* run, even if their result should be cached. This means
that the flag can be used to analyze a project's compile time without
having to repeatedly clear cache directory, for instance. However, when
using `-fincremental`, updates other than the first will only show you
the statistics for what changed on that particular update. Notably, this
gives us a fairly nice way to see exactly which declarations were
re-analyzed by an incremental update.

If `--fuzz` is passed to `zig build`, another section of the web
interface becomes visible, this time exposing the fuzzer. This is quite
similar to the fuzzer UI this commit replaces, with only a few cosmetic
tweaks. The interface is closer than before to supporting multiple fuzz
steps at a time (in line with the overall strategy for this build UI,
the goal will be for all of the fuzz steps to be accessible in the same
interface), but still doesn't actually support it. The fuzzer UI looks
quite different under the hood: as a result, various bugs are fixed,
although other bugs remain. For instance, viewing the source code of any
file other than the root of the main module is completely broken (as on
master) due to some bogus file-to-module assignment logic in the fuzzer
UI.

Implementation notes:

* The `lib/build-web/` directory holds the client side of the web UI.

* The general server logic is in `std.Build.WebServer`.

* Fuzzing-specific logic is in `std.Build.Fuzz`.

* `std.Build.abi` is the new home of `std.Build.Fuzz.abi`, since it now
  relates to the build system web UI in general.

* The build runner now has an **actual** general-purpose allocator,
  because thanks to `--watch` and `--webui`, the process can be
  arbitrarily long-lived. The gpa is `std.heap.DebugAllocator`, but the
  arena remains backed by `std.heap.page_allocator` for efficiency. I
  fixed several crashes caused by conflation of `gpa` and `arena` in the
  build runner and `std.Build`, but there may still be some I have
  missed.

* The I/O logic in `std.Build.WebServer` is pretty gnarly; there are a
  *lot* of threads involved. I anticipate this situation improving
  significantly once the `std.Io` interface (with concurrency support)
  is introduced.
2025-08-01 23:48:21 +01:00
David Rubin
5678a600ff
refactor reifyUnion alignment handling 2025-08-01 14:57:16 -07:00
David Rubin
d6c74a95fd
remove usages of .alignment = 0 2025-08-01 14:57:16 -07:00
David Rubin
17330867eb
Sema: compile error on reifying align(0) struct fields 2025-08-01 14:57:16 -07:00
Alex Rønne Petersen
a00edbd52d
Merge pull request #24640 from alexrp/glibc-2.42
glibc 2.42
2025-08-01 19:17:56 +02:00
Andrew Kelley
a6f7927764 std.compress.flate.Decompress: use 64 buffered bits
will have to find out why usize doesn't work for 32 bit targets some
other time
2025-08-01 09:04:27 -07:00
Alex Rønne Petersen
675b1a15a1
glibc: update crt0 code to 2.42 2025-08-01 09:00:27 +02:00
Andrew Kelley
eb17d4562a std.Io.Writer.Hashed: fix bad assert 2025-07-31 22:36:52 -07:00
Ian Johnson
d91744401f fetch: More Git fixes 2025-07-31 22:10:11 -07:00
Andrew Kelley
64814dc986 std.compress.flate.Decompress: respect stream limit 2025-07-31 22:10:11 -07:00
Andrew Kelley
6caa100f0d std.Io.Writer: fix wrong return value from fixedDrain 2025-07-31 22:10:11 -07:00
Andrew Kelley
a7808892f7 std.compress.flate.Decompress: be in indirect or direct mode
depending on whether buffered
2025-07-31 22:10:11 -07:00
Andrew Kelley
6eac56caf7 std.compress.flate.Decompress: allow users to swap out Writer 2025-07-31 22:10:11 -07:00
Andrew Kelley
2024abda6a std.debug.Dwarf: work around API deficiency
need to supply a big enough buffer when working with decompression
2025-07-31 22:10:11 -07:00
Andrew Kelley
95273337c5 fetch: remove checksum logic and fix new I/O API bugs
Thanks Ian Johnson for finding these
2025-07-31 22:10:11 -07:00
Andrew Kelley
c9ff068391 std.compress: fix discard impl and flate error detection 2025-07-31 22:10:11 -07:00
Andrew Kelley
165cd87c12 std.Io.Reader: don't set end to zero
because it may be used as a ring buffer
2025-07-31 22:10:11 -07:00
Andrew Kelley
111305678c std: match readVec fn prototype exactly
this is not necessary according to zig language, but works around a flaw
in the C backend
2025-07-31 22:10:11 -07:00
Andrew Kelley
ae67c26cab disable failing incremental test cases due to dwarf linker logic
tracked by #24634
2025-07-31 22:10:11 -07:00
Andrew Kelley
c49c90a42a fetch: update API usage 2025-07-31 22:10:11 -07:00
Andrew Kelley
4c04835a08 std.compress.zstd.Decompress: implement discard and readVec 2025-07-31 22:10:11 -07:00
Andrew Kelley
84e4343b0c fix test failures by adding readVec 2025-07-31 22:10:11 -07:00
Andrew Kelley
afe9f3a9ec std.compress.flate.Decompress: implement readVec and discard 2025-07-31 22:10:11 -07:00
Andrew Kelley
81af4f3efc link: update some dwarf code to non deprecated API 2025-07-31 22:10:11 -07:00
Andrew Kelley
3fff84a4a4 compiler: fix unit test compile errors
sorry, zip file creation has regressed because std lib no longer has a
deflate compression implementation
2025-07-31 22:10:11 -07:00
Andrew Kelley
6bcced31a0 fix 32-bit compilation 2025-07-31 22:10:11 -07:00
Andrew Kelley
42b10f08cc std.compress.flate.Decompress: delete bad unit tests
if I remove the last input byte from "don't read past deflate stream's
end" (on master branch), the test fails with error.EndOfStream. what,
then, is it supposed to be testing?
2025-07-31 22:10:11 -07:00
Andrew Kelley
5f790464b0 std.compress.flate.Decompress: hashing is out of scope
This API provides the data; applications can verify their own checksums.
2025-07-31 22:10:11 -07:00
Andrew Kelley
f3a38e30fa std.Io: delete SeekableStream
Alternative is to use File.Reader and File.Writer directly.
2025-07-31 22:10:11 -07:00
Andrew Kelley
4741a16d9a putting stuff back does not require mutation 2025-07-31 22:10:11 -07:00
Andrew Kelley
05ce1f99a6 compiler: update to new flate API 2025-07-31 22:10:11 -07:00
Andrew Kelley
2569f4ff85 simplify tossBitsEnding 2025-07-31 22:10:11 -07:00
Andrew Kelley
5bc63794cc fix takeBitsEnding 2025-07-31 22:10:11 -07:00
Andrew Kelley
63f496c4f9 make takeBits deal with integers only 2025-07-31 22:10:11 -07:00
Andrew Kelley
c00fb86db6 fix peekBitsEnding 2025-07-31 22:10:11 -07:00
Andrew Kelley
8ab91a6fe9 error.EndOfStream disambiguation 2025-07-31 22:10:11 -07:00
Andrew Kelley
f644f40702 implement tossBitsEnding 2025-07-31 22:10:11 -07:00
Andrew Kelley
2d8d0dd9b0 std.compress.flate.Decompress: unfuck the test suite 2025-07-31 22:10:11 -07:00
Andrew Kelley
c684b21b4f simplify test cases 2025-07-31 22:10:11 -07:00
Andrew Kelley
ac4fbb427b std.compress.flate.Decompress: don't compute checksums
These have no business being in-bound; simply provide the expected
values to user code for maximum flexibility.
2025-07-31 22:10:11 -07:00
Andrew Kelley
5f571f53d6 refactor gzip test cases
zig newbies love using for loops in unit tests
2025-07-31 22:10:11 -07:00
Andrew Kelley
e73ca2444e std.compress.flate.Decompress: implement peekBitsEnding and writeMatch 2025-07-31 22:10:11 -07:00
Andrew Kelley
7bf91d705c fix bit read not at eof 2025-07-31 22:10:11 -07:00
Andrew Kelley
73e5594c78 std.compress.flate.Decompress: fix bit read at eof 2025-07-31 22:10:11 -07:00
Andrew Kelley
9c8cb777d4 std.compress.flate.Decompress: implement more bit reading 2025-07-31 22:10:11 -07:00
Andrew Kelley
6509fa1cf3 std.compress.flate.Decompress: passing basic test case 2025-07-31 22:10:11 -07:00
Andrew Kelley
88ca750209 std.compress.flate.Decompress: add rebase impl 2025-07-31 22:10:11 -07:00
Andrew Kelley
fa410cc234 std.Io: delete BitReader 2025-07-31 22:10:11 -07:00
Andrew Kelley
1b43551190 std.Io: remove BitWriter 2025-07-31 22:10:11 -07:00
Andrew Kelley
824c157e0c std.compress.flate: finish reorganizing 2025-07-31 22:10:11 -07:00
Andrew Kelley
73c98ca0e6 simplify std.hash.Adler32 2025-07-31 22:10:11 -07:00
Andrew Kelley
a4f05a4588 delete flate implementation 2025-07-31 22:10:11 -07:00
Andrew Kelley
83513ade35 std.compress: rework flate to new I/O API 2025-07-31 22:10:11 -07:00
Chinmay Dalal
a2d21d6327 enable pwd.h functions for other OSes
also add the layout of `struct passwd` for DragonflyBSD
and FreeBSD:
 - c267aac007/include/pwd.h (L112)
 - https://cgit.freebsd.org/src/tree/include/pwd.h?id=d66f9c86fa3fd8d8f0a56ea96b03ca11f2fac1fb#n114
2025-08-01 04:34:45 +02:00
Andrew Kelley
0294e91451 std.Io.Reader: fix readVec at end 2025-07-31 19:26:12 -07:00
Jackson Wambolt
264bd7053e Sema: remove incorrect requireRuntimeBlock calls
Part of #22353

Resolves: #24273
Co-Authored-By: Matthew Lugg <mlugg@mlugg.co.uk>
2025-07-31 22:28:46 +01:00
mlugg
ac1e73e249 std.enums: fix EnumIndexer branch quota
It's quite silly to have this override which nonetheless makes
assumptions about the input type. Encode the actual complexity of the
sort.

Also, simplify the sorting logic, and fix a bug (grab min and max
*after* the sort, not *before*!)
2025-07-31 22:10:22 +01:00
Matthew Lugg
04d7b491b4
Merge pull request #24632 from mlugg/lossy-int-to-float-coercion
Sema: compile error on lossy int to float coercion
2025-07-31 21:49:37 +01:00
Alex Rønne Petersen
1804251dfb
glibc: update headers to 2.42 2025-07-31 22:02:37 +02:00
Alex Rønne Petersen
cdd6e9ee3a
glibc: update abilists file to 2.42 2025-07-31 21:47:02 +02:00
Andrew Kelley
982c387753
Merge pull request #24633 from linusg/more-serenity-fixes
std: A few more fixes for serenity
2025-07-31 09:56:26 -07:00
Andrew Kelley
627a292a11 fetch: remove calls to fsync
fsync blocks until the contents have been actually written to disk,
which would be useful if we didn't want to report success until having
achieved durability. But the OS will ensure coherency; i.e. if one
process writes stuff without calling fsync, then another process reads
that stuff, the writes will be seen even if they didn't get flushed to
disk yet.

Since this code deals with ephemeral cache data, it's not worth trying
to achieve this kind of durability guarantee. This is consistent with
all the other tooling on the system.

Certainly, if we wanted to change our stance on this, it would not be
something that affects only the git fetching logic.
2025-07-31 08:59:56 -07:00
mikastiv
1a15fbe960 Sema: add note suggesting dropping try on non error-unions 2025-07-31 16:55:17 +01:00
Alex Rønne Petersen
03facba496
std.Target: require libc for Android API levels prior to 29
Emulated TLS depends on libc pthread functions.

Closes #24589.
2025-07-31 17:08:25 +02:00
dweiller
19fc5f4fb2 Sema: disallow slicing many-item pointer with different sentinel
This change prevents adding or changing the sentinel in the type of a
many-item pointer via the slicing syntax `ptr[a.. :S]`.
2025-07-31 12:02:19 +01:00
mlugg
64bf8bb146
std: stop relying on precision-losing coercions 2025-07-31 10:57:04 +01:00
mlugg
e664bf4d81
Sema: compile error on lossy int to float coercion
Resolves: #21586
2025-07-31 10:57:04 +01:00
mlugg
bce6a7c215 langref: improve @import documentation
Rewrite to be more clear and correct. Also, explain ZON imports.

Resolves: #23314
2025-07-31 10:39:22 +01:00
Chinmay Dalal
e941ce3e68 add grp.h functions to c.zig 2025-07-30 21:28:42 -07:00
Matthew Lugg
032bbd68a7
Merge pull request #24537 from IOKG04/some-documentation-updates-0
some small langref changes
2025-07-31 02:32:32 +01:00
Linus Groh
ce776d3245 std: Add serenity to more OS checks 2025-07-30 23:28:58 +01:00
Linus Groh
813a0f125e std.posix: Default ACCMODE to NONE for serenity
Unlike all other platforms where RDONLY is 0 it does not work as a
default for the O flags on serenity - various syscalls other than
'open', e.g. 'pipe', return EINVAL if unexpected bits are set in the
flags.
2025-07-30 23:27:32 +01:00
Linus Groh
f5e9384335 std.c: Fix MAP for serenity
I accidentally translated MAP_ constants representing the type as
individual fields. MAP_FILE is for compatibility only and not needed
here.
2025-07-30 23:22:06 +01:00
Linus Groh
467a1f4a1c std.c: Fix msghdr_const for serenity 2025-07-30 23:19:29 +01:00
Loris Cro
de23ccfad1 build system: print captured stderr on Run step failure
when a Run step that captures stderr fails, no output from it is visible
by the user and, since the step failed, any downstream step that would
process the captured stream will not run, making it impossible for the
user to see the stderr output from the failed process invocation, which
makes for a frustrating puzzle when this happens in CI.
2025-07-30 22:40:36 +01:00
Jackson Wambolt
eb1a4970da
Sema: check min/max operand types 2025-07-30 20:48:38 +00:00
Matthew Lugg
389ccf692a
Merge pull request #24278 from gooncreeper/atomic-fixes
atomic fixes and clarification
2025-07-30 21:30:29 +01:00
Krzysztof Wolicki
3d639481d9
Sema: disallow tags on non-auto unions when reifying (#23488) 2025-07-30 18:18:49 +00:00
Alex Rønne Petersen
259b7c3f3f
std.Target: pull Os.requiresLibC() up to Target 2025-07-30 18:58:47 +02:00
Andrew Kelley
cf7a28febb std.Io.Reader: introduce readVec back into the VTable
simplifies and fixes things

addresses a subset of #24608
2025-07-30 09:26:34 -07:00
Alex Rønne Petersen
a9773944dc compiler: disable self-hosted x86_64 backend on OpenBSD
Same as 97ecb6c551eb628e5a37d18d5a9720d3714a04ef for NetBSD.
2025-07-30 17:17:22 +02:00
Justus Klausecker
6ec275ebd8 Sema: remove incorrect safety check for saturating left shift 2025-07-30 10:15:48 +01:00
Kurt Wagner
135a34c963 Update doc comment for ptr_type and ptr_type_bit_range to data of .extra_and_node
The other pointer types are `.opt_node_and_node` but `ptr_type` and `ptr_type_bit_range` contain `.extra_and_node` in their `data` field
2025-07-30 10:02:41 +01:00
Kendall Condon
cbe6e5b7fe langref: clarify allowed atomic types
Floats are not allowed in @cmpxchg

Packed structs are allowed for all atomic builtins
2025-07-30 09:56:38 +01:00
Kendall Condon
b0d6c227d3 Sema: catch error sets in atomic operations
also fix the struct test
2025-07-30 09:56:38 +01:00
Kendall Condon
f7dc9b50ab llvm: fix atomic widening of packed structs
Additionally, disable failing big-endian atomic test

also improve test paramaters to catch this when condition is removed

also some other cleanups
2025-07-30 09:56:38 +01:00
Techatrix
4a1594fbde update zig env to respect ZIG_LIB_DIR and support wasi 2025-07-30 09:45:03 +01:00
Andrew Kelley
1fcaf90dd3 std.Io.Reader: make fillUnbuffered respect prexisting buffer
addresses only one usage pattern in #24608
2025-07-29 23:10:50 -07:00
Matthew Lugg
8414638fb8
Sema: fixes (#24617)
* Sema: remove redundant comptime-known initializer tracking

This logic predates certain Sema enhancements whose behavior it
essentially tries to emulate in one specific case in a problematic way.
In particular, this logic handled initializing comptime-known `const`s
through RLS, which was reworked a few years back in 644041b to not rely
on this logic, and catching runtime fields in comptime-only
initializers, which has since been *correctly* fixed with better checks
in `Sema.storePtr2`. That made the highly complex logic in
`validateStructInit`, `validateUnionInit`, and `zirValidatePtrArrayInit`
entirely redundant. Worse, it was also causing some tracked bugs, as
well as a bug which I have identified and fixed in this PR (a
corresponding behavior test is added).

This commit simplifies union initialization by bringing the runtime
logic more in line with the comptime logic: the tag is now always
populated by `Sema.unionFieldPtr` based on `initializing`, where this
previously happened only in the comptime case (with `validateUnionInit`
instead handling it in the runtime case). Notably, this means that
backends are now able to consider getting a pointer to an inactive union
field as Illegal Behavior, because the `set_union_tag` instruction now
appears *before* the `struct_field_ptr` instruction as you would
probably expect it to.

Resolves: #24520
Resolves: #24595

* Sema: fix comptime-known union initialization with OPV field

The previous commit uncovered this existing OPV bug by triggering this
logic more frequently.

* Sema: remove dead logic

This is redundant because `storePtr2` will coerce to the return type
which (in `Sema.coerceInMemoryAllowedErrorSets`) will add errors to the
current function's IES if necessary.

* Sema: don't rely on Liveness

We're currently experimenting with backends which effectively do their
own liveness analysis, so this old trick of mine isn't necessarily valid
anymore. However, we can fix that trivially: just make the "nop"
instruction we jam into here have the right type. That way, the leftover
field/element pointer instructions are perfectly valid, but still
unused.
2025-07-30 04:04:06 +01:00
mlugg
08f1d63be1
disable more failing tests
Wow, *lots* of backends were reliant on Sema doing the heavy lifting for
them. CBE, Wasm, and SPIR-V have all regressed in places now that they
actually need to, like, initialize unions and such.
2025-07-29 22:44:01 +01:00
mlugg
0d482775cc
Sema: don't rely on Liveness
We're currently experimenting with backends which effectively do their
own liveness analysis, so this old trick of mine isn't necessarily valid
anymore. However, we can fix that trivially: just make the "nop"
instruction we jam into here have the right type. That way, the leftover
field/element pointer instructions are perfectly valid, but still
unused.
2025-07-29 15:52:19 +01:00
mlugg
d0bc5efba4
Sema: remove dead logic
This is redundant because `storePtr2` will coerce to the return type
which (in `Sema.coerceInMemoryAllowedErrorSets`) will add errors to the
current function's IES if necessary.
2025-07-29 15:52:19 +01:00
mlugg
b1dcf2b149
Sema: fix comptime-known union initialization with OPV field
The previous commit uncovered this existing OPV bug by triggering this
logic more frequently.
2025-07-29 15:52:19 +01:00
mlugg
a8888afcc0
Sema: remove redundant comptime-known initializer tracking
This logic predates certain Sema enhancements whose behavior it
essentially tries to emulate in one specific case in a problematic way.
In particular, this logic handled initializing comptime-known `const`s
through RLS, which was reworked a few years back in 644041b to not rely
on this logic, and catching runtime fields in comptime-only
initializers, which has since been *correctly* fixed with better checks
in `Sema.storePtr2`. That made the highly complex logic in
`validateStructInit`, `validateUnionInit`, and `zirValidatePtrArrayInit`
entirely redundant. Worse, it was also causing some tracked bugs, as
well as a bug which I have identified and fixed in this PR (a
corresponding behavior test is added).

This commit simplifies union initialization by bringing the runtime
logic more in line with the comptime logic: the tag is now always
populated by `Sema.unionFieldPtr` based on `initializing`, where this
previously happened only in the comptime case (with `validateUnionInit`
instead handling it in the runtime case). Notably, this means that
backends are now able to consider getting a pointer to an inactive union
field as Illegal Behavior, because the `set_union_tag` instruction now
appears *before* the `struct_field_ptr` instruction as you would
probably expect it to.

Resolves: #24520
Resolves: #24595
2025-07-29 15:52:19 +01:00
Jacob Young
3fbdd58a87 aarch64: implement scalar @mod 2025-07-28 22:23:19 -07:00
Kendall Condon
ecd3ea9bd2 DeprecatedReader.Adapted: fix EndOfStream handling 2025-07-28 21:41:19 -07:00
Silver
147a852806 Update zig init help with new -m arg
This was forgotten in #24555
2025-07-28 21:46:44 +01:00
Jacob Young
c334956a54 aarch64: workaround some optional/union issues 2025-07-28 09:03:17 -07:00
IOKG04
2dea904d5a .strong, not .Strong
https://github.com/ziglang/zig/pull/24537#issuecomment-3124556900
2025-07-28 15:15:49 +02:00
Rue
5381e7891d
Merge branch 'ziglang:master' into some-documentation-updates-0 2025-07-28 14:54:52 +02:00
Ivan
dea3ed7f59
build: fix error in standalone test when using --release
Co-authored-by: Carl Åstholm <carl@astholm.se>
2025-07-28 08:10:23 +01:00
Andrew Kelley
bb29846732 std.compress.xz: eliminate dependency on std.Io.bitReader 2025-07-27 22:08:52 -07:00
Andrew Kelley
89cd42ee80
Merge pull request #24600 from jacobly0/aarch64
aarch64: continued progress
2025-07-27 11:42:09 -07:00
Jacob Young
b26e732bd0 aarch64: fix error union constants 2025-07-27 08:01:07 -04:00
Jacob Young
771523c675 aarch64: implement var args 2025-07-27 06:59:38 -04:00
Andrew Kelley
da408bd6fc
Merge pull request #24585 from jacobly0/aarch64
aarch64: more progress
2025-07-27 00:17:19 -07:00
A cursed quail
e12dc4947c std.zig: fmtId returns a FormatId
Changes fmtId to return the FormatId type directly, and renames the
FormatId.render function to FormatId.format, so it can be used in a
format expression directly.

Why? Since `render` is private, you can't create functions that wrap
`fmtId` or `fmtIdFlags`, since you can't name the return type of those
functions outside of std itself.

The current setup _might_ be intentional? In which case I can live with
it, but I figured I'd make a small contrib to upstream zig :)
2025-07-26 21:53:23 -07:00
Andrew Kelley
04614d6ea1 std.Io.Reader: add rebase to the vtable
This eliminates a footgun and special case handling with fixed buffers,
as well as allowing decompression streams to keep a window in the output
buffer.
2025-07-26 20:00:25 -07:00
Andrew Kelley
de39c5f67f
Merge pull request #24587 from jacobly0/x86_64
x86_64: fix some bugs
2025-07-26 18:41:29 -07:00
Jacob Young
7894703ee7 aarch64: implement more optional/error union/union support 2025-07-26 21:39:50 -04:00
Jacob Young
69abc945e4 aarch64: implement some safety checks
Closes #24553
2025-07-26 17:31:04 -04:00
Jacob Young
1274254c48 aarch64: implement stack probing 2025-07-26 16:08:40 -04:00
Jacob Young
7c349da49c aarch64: implement complex switch prongs 2025-07-26 16:08:40 -04:00
Matthew Lugg
a51cdf3b24
Merge pull request #22587 from castholm/deprecate-compile-apis
std.Build: Deprecate `Step.Compile` APIs that mutate the root module
2025-07-26 18:03:33 +01:00
mlugg
c9ce1debe7 Sema: exclude sentinel from source array length in pointer cast to slice
Resolves: #24569
2025-07-26 14:54:04 +01:00
Jacob Young
3194a4d22b x86_64: fix dst create alloc reg clobbering src
Closes #24390
2025-07-26 07:44:12 -04:00
Jacob Young
68cfa736df x86_64: fix switch on mod result
Closes #24541
2025-07-26 06:24:03 -04:00
Carl Åstholm
154bd2fd05 Migrate from deprecated Step.Compile APIs 2025-07-26 12:06:43 +02:00
Carl Åstholm
413179ccfc std.Build: Deprecate Step.Compile APIs that mutate the root module
Not only are `Step.Compile` methods like `linkLibC()` redundant because
`Module` exposes the same APIs, it also might not be immediately obvious
to users that these methods modify the underlying root module, which can
be a footgun and lead to unintended results if the module is exported to
package consumers or shared by multiple compile steps.

Using `compile.root_module.link_libc = true` makes it more clear to
users which of the compile step and the module owns which options.
2025-07-26 12:06:42 +02:00
Ryan Liptak
0f4106356e child_process standalone test: Test spawning a path with leading ..
Also check that FileNotFound is consistently returned when the path is missing.

The new `run_relative` step will test spawning paths like:

    child_path: ../84385e7e669db0967d7a42765011dbe0/child
    missing_child_path: ../84385e7e669db0967d7a42765011dbe0/child_intentionally_missing
2025-07-26 01:35:15 -04: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
fc4b7c968a
Merge pull request #24564 from ziglang/terminal-progress-bar
std.Progress: support progress bar escape codes
2025-07-25 21:49:25 -07:00
Andrew Kelley
66e49d93b7
Merge pull request #24559 from ziglang/zstd
std: rework zstd for new I/O API
2025-07-25 20:02:53 -07:00
Andrew Kelley
9e11727c7c
Merge pull request #23340 from castholm/pass-null-to-b-dependency
Add support for passing null, string literals, enum lists and more to `b.dependency()`
2025-07-25 18:00:46 -07:00
Andrew Kelley
b22b9ebfe0 std.Progress: introduce Status 2025-07-25 17:33:11 -07:00
Andrew Kelley
799206a3ad std.Progress: support progress bar escape codes 2025-07-25 16:00:19 -07:00
Andrew Kelley
733b208256 std.posix.ftruncate: handle NonResizable properly 2025-07-25 14:15:33 -07:00
Andrew Kelley
8752d80c84 std.compress.zstd.Decompress: fix bytes_written tracking 2025-07-25 14:15:33 -07:00
Andrew Kelley
da51e94d50 std.fs.File.end: account for streaming mode 2025-07-25 14:15:33 -07:00
Andrew Kelley
7f43f78b5b std.compress.zstd: keep frame state between blocks 2025-07-25 14:15:33 -07:00
Andrew Kelley
13e08ea6f0 std.compress.zstd: fix endianness issue
instead of manually bitcast, use the handy dandy takeStruct function.
2025-07-25 14:15:33 -07:00
Andrew Kelley
ee4f5b3f92 std.compress.zstd: respect the window length 2025-07-25 14:15:33 -07:00
Andrew Kelley
7f1c04423e std.Io: add "preserve" variants to Reader/Writer 2025-07-25 14:15:33 -07:00
Andrew Kelley
3687eada6a std: rework zstd for new I/O API
This passes tests but it doesn't provide as big a window size as is
required to decompress larger streams.

The next commit in this branch will work towards that, without
introducing an additional buffer.
2025-07-25 14:15:33 -07:00
Jacob Young
869ef00602 aarch64: more progress
- factor out `loadReg`
 - support all general system control registers in inline asm
 - fix asserts after iterating field offsets
 - fix typo in `slice_elem_val`
 - fix translation of argument locations
2025-07-25 14:20:23 -04:00
mlugg
bb71a18ede init: replace '--strip' with '--minimal'
This option never worked properly (it emitted wrongly-formatted code),
and it doesn't seem particularly *useful* -- someone who's proficient
enough with `std.Build` to not need explanations probably just wants to
write their own thing. Meanwhile, the use case of writing your own
`build.zig` was extremely poorly served, because `build.zig.zon` *needs*
to be generated programmatically for a correct `fingerprint`, but the
only ways to do that were to a) do it wrong and get an error, or b) get
the full init template and delete the vast majority of it. Both of these
were pretty clunky, and `-s` didn't really help.

So, replace this flag with a new one, `--minimal`/`-m`, which uses a
different template. This template is trivial enough that I opted to just
hardcode it into the compiler for simplicity. The main job of
`zig init -m` is to generate a correct `build.zig.zon` (if it is unable
to do this, it exits with a fatal error). In addition, it will *attempt*
to generate a tiny stub `build.zig`, with only an `std` import and an
empty `pub fn build`. However, if `build.zig` already exists, it will
avoid overwriting it, and doesn't even complain. This serves the use
case of writing `build.zig` manually and *then* running `zig init -m`
to generate an appropriate `build.zig.zon`.
2025-07-25 16:24:02 +01:00
BreadTom
d407c4e52b Update wasm2c.c 2025-07-25 02:10:09 -07:00
Ian Johnson
f0fec952d2 zig std: fix sources.tar generation
Analogous to #24576 for `-femit-docs`
2025-07-24 19:44:19 -07:00
Ian Johnson
6dbcc3bd54 Autodoc: fix sources.tar generation
Closes #24565
2025-07-24 19:24:10 -07:00
Andrew Kelley
a189335ea2 zig std: update std.Io.poll API usage
fixes FTBFS
2025-07-24 19:15:40 -07:00
Andrew Kelley
4236ca40cd
Merge pull request #24561 from linusg/serenity-fixes
Small fixes for SerenityOS
2025-07-23 23:04:52 -07:00
Alex Rønne Petersen
5fb36d2600
Merge pull request #24557 from pavelverigo/wasm-try-ptr 2025-07-24 07:44:08 +02:00
Andrew Kelley
b8955a2e0a std.Io.poll: update to new I/O API 2025-07-23 21:25:34 -07:00
Linus Groh
bf4fda4db6 target: Add libc link flags for serenity 2025-07-24 00:54:40 +01:00
Linus Groh
26bd74e87f std.posix: Fix ACCMODE values for serenity 2025-07-24 00:54:40 +01:00
Linus Groh
ea90ec4d88 std.c: Fix dirent.name size for serenity
The null terminator is added to the buffer size.
2025-07-24 00:24:55 +01:00
Pavel Verigo
4328f71d9f Revert "disable -fno-llvm -target wasm32-wasi testing"
This reverts commit 83960e0eb068f786c46c3fe559016e1e9faea3cd.
2025-07-24 01:18:08 +02:00
Pavel Verigo
fcd9f521d2 stage2-wasm: implement try_ptr + is_(non_)err_ptr 2025-07-24 01:18:02 +02:00
Andrew Kelley
bc8e1a74c5
Merge pull request #24523 from ziglang/fifno
std.tar: update to new I/O API
2025-07-23 10:02:52 +02:00
Andrew Kelley
2365392e0e
Merge pull request #24536 from jacobly0/aarch64
aarch64: add new from scratch self-hosted backend
2025-07-23 09:18:50 +02:00
Alex Rønne Petersen
5c576573bb test: enable arm-freebsd-eabihf std tests
Closes #23949.
2025-07-23 05:23:42 +02:00
Andrew Kelley
e9b9a27a52 codegen: prevent AnyMir from bloating zig1.wasm 2025-07-22 19:43:47 -07:00
Jacob Young
5060ab99c9 aarch64: add new from scratch self-hosted backend 2025-07-22 19:43:47 -07:00
Jacob Young
a023b9b22b stage1: update zig1.wasm
Compiler needs cbe packed union fix.
2025-07-22 19:43:47 -07:00
Andrew Kelley
4fcb479de9 don't forget to advance in the deprecated adapter 2025-07-22 18:42:54 -07:00
Andrew Kelley
6038192fad std.tar: delete function redundant with std.mem 2025-07-22 17:40:12 -07:00
Andrew Kelley
2e8dbcac9a zig std: update for new tar I/O API 2025-07-22 17:07:19 -07:00
Andrew Kelley
11a81bc659 std.tar.Writer: delete ill-advised API
dependency on time is sus
2025-07-22 17:07:03 -07:00
Andrew Kelley
ec5cdb2fe3 std: fix deprecated writer not handling the buffer 2025-07-22 17:06:25 -07:00
Matthew Lugg
687370237f llvm: fix switch loop on larger than pointer integer 2025-07-22 14:50:22 -04:00
Andrew Kelley
91640f5f81 give the Reader API adapter a buffer
it needs one or else it always asserts
2025-07-22 09:41:44 -07:00
Andrew Kelley
6ae1bcd8bd fix docs wasm std.tar API usage 2025-07-22 09:41:44 -07:00
Andrew Kelley
cc334b4ee2 std.tar.Writer: fix 32-bit 2025-07-22 09:41:44 -07:00
Andrew Kelley
1dcea220a4 std.tar: update to new I/O API 2025-07-22 09:41:44 -07:00
Andrew Kelley
2ac81c76e3 std.Io: add deprecation warnings 2025-07-22 09:41:43 -07:00
Andrew Kelley
af0a02a2de std.Io: delete FindByteWriter
dead
2025-07-22 09:41:43 -07:00
Andrew Kelley
03a6892189 std.Io: delete ChangeDetectionStream
dead code
2025-07-22 09:41:43 -07:00
Andrew Kelley
d9a5a3e8c5 std.Io: delete MultiWriter
nah
2025-07-22 09:41:43 -07:00
Andrew Kelley
abed0f5129 std.Io: delete BufferedAtomicFile
this is now redundant
2025-07-22 09:41:43 -07:00
Andrew Kelley
a3efdd7279 std.Io: delete StreamSource
it shan't be missed
2025-07-22 09:41:43 -07:00
Andrew Kelley
d509bc933f std.Io: delete CWriter
it shan't be missed
2025-07-22 09:41:43 -07:00
Andrew Kelley
f34b4780b7
Merge pull request #24521 from ziglang/fs-streaming
std.fs.File: delete writeFileAll and friends
2025-07-22 18:40:11 +02:00
Andrew Kelley
34d2778239 std.fs.File.Reader.sendFile: fix 32-bit freebsd 2025-07-22 09:39:24 -07:00
IOKG04
84ae54fbe6 @rem() and @mod() take denominator != 0, not just denominator > 0
https://github.com/ziglang/zig/issues/23635

I also added tests for `@rem()` with `denominator < 0` cause there were none before
I hope I added them in the correct place, if not I can change it ofc
2025-07-22 13:35:55 +02:00
IOKG04
a91b4aab73 error return traces are *not* enabled for ReleaseSafe
https://github.com/ziglang/zig/issues/24232
2025-07-22 12:35:46 +02:00
IOKG04
3c046ab9d9 [:x]T coerces into [*:x]T
https://github.com/ziglang/zig/issues/9628
2025-07-22 12:30:19 +02:00
Andrew Kelley
76fe518d49 std.fs.File.Reader.sendFile: fix EndOfStream detection 2025-07-21 23:33:19 -07:00
Andrew Kelley
c41ac8f19e
Merge pull request #24534 from ziglang/fix-missed-opvs
Sema: fix missed simplifications of OPVs
2025-07-22 06:29:58 +02:00
Andrew Kelley
96cbdd145d std.fs.File.Reader: fix sendFile logic
it wasn't accounting for both writer and reader buffering
2025-07-21 20:00:45 -07:00
Andrew Kelley
b35c55e237 std.fs.File.Reader: fix seek position logic 2025-07-21 18:14:21 -07:00
Andrew Kelley
7d02b693be Sema: fix missed block OPV 2025-07-21 16:43:30 -07:00
Andrew Kelley
85b997b346 Sema: fix missed error union OPV 2025-07-21 16:11:26 -07:00
Andrew Kelley
63f672d322 Sema: fix missed union access OPV 2025-07-21 16:07:20 -07:00
Andrew Kelley
cb6702f42d Sema: fix missed union init OPV 2025-07-21 15:56:52 -07:00
Andrew Kelley
0958ea3391 Sema: fix missed slice access OPV 2025-07-21 15:45:17 -07:00
Andrew Kelley
71a9b35c0f Sema: fix missed pointer access OPV 2025-07-21 15:34:57 -07:00
Andrew Kelley
fe10c66d66 std.fs.File.Reader: only fcopyfile if size available 2025-07-21 12:32:37 -07:00
Andrew Kelley
38559e282b disable failing test
tracked by #24524
2025-07-21 12:32:37 -07:00
Andrew Kelley
f1576ef14c objcopy: delete most of it
this code is not up to zig project standards

tracked by #24522

oh, and fix not adjusting buffer seek position in std.fs.File.Reader
2025-07-21 12:32:37 -07:00
Andrew Kelley
f2a3ac7c05 std.fs.File: delete writeFileAll and friends
please use File.Writer for these use cases

also breaking API changes to std.fs.AtomicFile
2025-07-21 12:32:37 -07:00
Andrew Kelley
5df52ca0a2 build runner: print newline before summary 2025-07-21 12:32:37 -07:00
Andrew Kelley
c8c59d7ba5 std.json: delete dead API 2025-07-21 12:32:37 -07:00
Andrew Kelley
9abc3232a8 std.fs.File.Reader: fix missed advance writer positions 2025-07-21 13:08:43 +02:00
Andrew Kelley
f97c91ddb5 std.Thread: don't spin 2025-07-21 05:37:51 +02:00
Andrew Kelley
e4abdf5a13 std.Io.Reader: fix takeStruct/peekStruct packed
closes #24516
2025-07-20 11:23:12 -07:00
Kendall Condon
f657767b60 langref: upgrade grammar.y for asm clobber change 2025-07-20 19:37:41 +02:00
Carl Åstholm
ca57115da7 Support passing std.zig.BuildId to b.dependency() 2025-07-20 18:28:36 +02:00
Carl Åstholm
2c1a349fb9 Support passing enum slices to b.dependency() 2025-07-20 18:28:36 +02:00
Carl Åstholm
fd5eba9358 Coerce slice-like arguments passed to b.dependency()
You can now pass string literals as options.
2025-07-20 18:28:36 +02:00
Carl Åstholm
1a9fae2a70 Dupe string options 2025-07-20 18:28:36 +02:00
Carl Åstholm
e7604bba3e Serialize float options using the hexadecimal format
This ensures no information is lost when the value is round-tripped.
2025-07-20 18:28:36 +02:00
Carl Åstholm
5380e81924 Support passing null to b.dependency()
Both null literals and optionals are supported.
2025-07-20 18:28:36 +02:00
Carl Åstholm
00bc72b5ff Add standalone test case for passing options to dependencies 2025-07-20 18:28:36 +02:00
Carl Åstholm
b92b55ab8e Update test build.zig.zon files to conform to the new manifest rules 2025-07-20 18:28:36 +02:00
antlilja
14bb533203 use stdout_buffer instead of stdio_buffer in main.zig 2025-07-20 18:27:01 +02:00
Andrew Kelley
8373788c4c
Merge pull request #24488 from ziglang/more
std.zig: finish updating to new I/O API
2025-07-20 11:24:41 +02:00
Marc Tiehuis
4780cc50cf std.Io.Writer: support alignment for {t} specifier 2025-07-20 10:30:17 +02:00
Andrew Kelley
e43617e686
Merge pull request #24505 from ziglang/json
update std.json and std.zon to new I/O API
2025-07-20 09:48:25 +02:00
Alex Rønne Petersen
c58cce7999 std.Build.Step.Run: fix up 681d324c49e7cdc773cc891ea49ed69dd03c23c7
https://github.com/ziglang/zig/pull/24151/files#r2217494741
2025-07-20 07:25:05 +02:00
Andrew Kelley
c40fb96ca3 std.Io.Writer: fix writeSliceSwap
tried to be too clever, wrote bad code
2025-07-19 22:12:37 -07:00
Jacob Young
b4fd57a9c1 llvm: workaround crashes in llvm loop optimizations
Workaround for #24383
2025-07-20 06:42:47 +02:00
Andrew Kelley
741a66e03c std.zig.llvm.BitcodeReader: fix 32-bit skipBlock 2025-07-19 19:57:37 -07:00
Andrew Kelley
83960e0eb0 disable -fno-llvm -target wasm32-wasi testing
no active maintainer, and it's failing to lower some basic stuff
2025-07-19 19:57:37 -07:00
Andrew Kelley
d396780925 Compilation: unrevert some stuff 2025-07-19 19:57:37 -07:00
Andrew Kelley
b956ae20af frontend: align those stdio buffers 2025-07-19 19:57:37 -07:00
Andrew Kelley
8489bab1f4 std.Io.Writer: add missing writeSliceSwap 2025-07-19 19:57:37 -07:00
Andrew Kelley
bd64bf0e47 std.mem: add byteSwapAllElements 2025-07-19 19:57:37 -07:00
Andrew Kelley
83d1f88ac5 std.debug: add assertAligned 2025-07-19 19:57:37 -07:00
Andrew Kelley
bad836a69b Compilation: revert some stuff 2025-07-19 19:57:37 -07:00
Andrew Kelley
93378e2e7b std.zig: finish updating to new I/O API 2025-07-19 19:57:37 -07:00
Jacob Young
592f1043dc cbe: fix comptime-known packed unions 2025-07-20 03:29:25 +02:00
Andrew Kelley
0fb7a0a94b std.zon: better namespace for Serializer 2025-07-19 18:27:09 -07:00
Andrew Kelley
737b13357e resinator: fix std.json API usage 2025-07-19 18:27:09 -07:00
Andrew Kelley
c3da98cf5a std.zon: update to new I/O API 2025-07-19 18:27:09 -07:00
Andrew Kelley
b956b02187 zig env: update std.json API 2025-07-19 16:24:37 -07:00
Andrew Kelley
c30df072bd std.json: update to new I/O API
also do a little bit of namespace cleanup
2025-07-19 16:05:01 -07:00
Andrew Kelley
a288266f33 std.Io.Reader: remove aggressive assert from fill
with `.fixed("")` you should still be able to do `fill(1)` and have it
return error.EndOfStream.
2025-07-19 16:05:01 -07:00
Andrew Kelley
a0d1682921 std.hash.RapidHash: remove
Its design keeps evolving. See
https://github.com/Nicoshev/rapidhash/releases

It's great to see the design improving, but over time, this will lead to
code rot; versions that aren't widely used but would still have to live
in the standard library forever and be maintained.

Better to be maintained as an external dependency that applications can
opt into. Then, in a few years, if a version proves to be stable and
widely adopted, it could be considered for inclusion in the standard
library.
2025-07-19 11:49:33 -07:00
Alexandre
4e6a04929d Changed u64 to usize to fix #24208 2025-07-19 15:31:44 +02:00
mlugg
67e6df4313 tests: remove more old async tests
The rejection of #6025 indicates that if stackless coroutines return to
Zig, they will look quite different; see #23446 for the working draft
proposal for their return (though it will definitely be tweaked before
being accepted). Some of this test coverage was deleted in 40d11cc, but
because stackless coroutines will take on a new form if re-introduced, I
anticipate that essentially *none* of this coverage will be relevant. Of
course, if it for some reason is, we can always grab it from the Git
history.
2025-07-19 08:52:13 +02:00
AsmArtisan256
69cf40da60
std.os.uefi.protocol.file: fix getInfo() buffer alignment (#24496)
* std.os.uefi.protocol.file: use @alignCast in getInfo() method to fix #24480

* std.os.uefi.protocol.file: pass alignment responsabilities to caller by redefining the buffer type instead of blindly calling @alignCast
2025-07-18 19:07:05 +00:00
Andrew Kelley
6e55898661 Compilation: refactor std.fs -> fs
no functional change
2025-07-18 06:42:54 -07:00
Felix Koppe
3ae0ba096d
test: Restore and fix deleted tests that relied on intern pool types (#24422) 2025-07-17 22:07:50 +00:00
Alex Rønne Petersen
32c9e5df89
ci: skip single-threaded module tests on riscv64-linux 2025-07-17 19:40:59 +02:00
Alex Rønne Petersen
7da4e30da7
ci: skip translate-c tests on riscv64-linux 2025-07-17 19:37:42 +02:00
Alex Rønne Petersen
df92193941
ci: skip building docs on riscv64-linux 2025-07-17 19:34:46 +02:00
Andrew Kelley
a35688b613
Merge pull request #20069 from LewisGaul/math-tests-simplified
Math tests simplified (exp and log functions) with bugfixes
2025-07-17 18:44:51 +02:00
John Benediktsson
e62e42f0d9
std.io.Writer: remove requirement of a 2-byte buffer for extern unions (#24489)
closes #24486
2025-07-17 16:42:53 +00:00
Andrew Kelley
a8dc32e4ec
Merge pull request #24493 from ziglang/readSliceShort
std.Io.Reader: fix readSliceShort with smaller buffer than Reader
2025-07-17 18:35:38 +02:00
Andrew Kelley
155ab56cc6 std.zig.readSourceFileToEndAlloc: avoid resizing
+1 on the ensure total capacity to account for the fact that we add a
null byte before returning.

thanks matklad
2025-07-17 09:33:25 -07:00
Andrew Kelley
5784500572 std.Io.Reader: fix readSliceShort with smaller buffer than Reader
closes #24443
2025-07-17 09:26:31 -07:00
Andrew Kelley
86699acbb9 std.Io.Reader: update OneByteReader usage to std.testing.Reader 2025-07-17 09:26:31 -07:00
kcbanner
b7d7446fbb compiler_rt: export all the chkstk variations on MinGW 2025-07-17 14:36:52 +02:00
Alex Rønne Petersen
33041fdbe5
ci: increase max rss for riscv64-linux back to 64G 2025-07-17 14:12:05 +02:00
John Benediktsson
6e86910e19
std.Io: Fix GenericReader.adaptToNewApi; add DeprecatedReader.adaptToNewApi (#24484) 2025-07-17 11:29:22 +00:00
Andrew Kelley
c82403020d
Merge pull request #24472 from ziglang/zig-fmt
zig fmt: update related functionality to new I/O API
2025-07-17 12:06:40 +02:00
kcbanner
9af076615e std.Progress: reset end when failing to flush stderr 2025-07-17 09:05:29 +02:00
Andrew Kelley
27212a3e6b LLD: don't default allow_shlib_undefined when cross compiling
prevents e.g. lld-link: warning: undefined symbol: SystemFunction036
from being only a warning
2025-07-17 08:26:24 +02:00
Tristan Ross
5ef07302d7 std.Build.Step.ConfigHeader: add the lazy file styled input as a dependency 2025-07-17 05:20:24 +02:00
Lewis Gaul
03dfd2ecc3 Make sure to test the sign of the zero results 2025-07-17 05:04:59 +02:00
Lewis Gaul
7abb170f59 Add tests for math.expm1(), fixing bug in 32-bit function 2025-07-17 05:04:59 +02:00
Lewis Gaul
f34b26231e Add tests for math.log1p() 2025-07-17 05:04:59 +02:00
Lewis Gaul
36d5392f03 Add tests for log10() 2025-07-17 05:04:59 +02:00
Lewis Gaul
650e358220 Add tests for log2() 2025-07-17 05:04:59 +02:00
Lewis Gaul
936cf57a38 Add tests for log(), with bugfix for 64-bit boundary case 2025-07-17 05:04:59 +02:00
Lewis Gaul
da8974e57f Add tests for exp(), noting last-bit discrepancy for exp(1.0) with math.e 2025-07-17 05:04:59 +02:00
Lewis Gaul
9da19e51ea Add tests for exp2(), with bugfix for 64-bit boundary case 2025-07-17 05:04:59 +02:00
Andrew Kelley
741569d5a7 std.Ast.Render: fix conflicts with master branch 2025-07-16 17:58:06 -07:00
Andrew Kelley
70f514f1ba std.Io.Reader: fix appendRemaining harder
ensure that it issues a stream call that includes the buffer to detect
the end when needed, but otherwise does not offer Reader buffer to
append directly to the list.
2025-07-16 17:20:03 -07:00
Andrew Kelley
ad726587cc zig fmt: update to new I/O API 2025-07-16 17:20:03 -07:00
Andrew Kelley
aac301a655 update aro 2025-07-16 17:20:03 -07:00
Andrew Kelley
1f93f61958 std.zig.readSourceFileToEndAlloc: add file size heuristic 2025-07-16 17:20:03 -07:00
Andrew Kelley
73cfba4d0d std.Io.Writer: fix writeStruct 2025-07-16 17:20:03 -07:00
Andrew Kelley
e7a639967e std.Io.Reader: fix appendRemaining
it calls readVec which is a higher level function than was expected in
the previous implementation
2025-07-16 17:20:03 -07:00
Andrew Kelley
9222d201d7 add a happy little main function to src/fmt.zig
Provided for debugging/testing purposes; unused by the compiler.
2025-07-16 17:20:02 -07:00
Andrew Kelley
c4776d66af update compiler 2025-07-16 17:20:02 -07:00
Andrew Kelley
b3ee5a6c30 update cmake file listing 2025-07-16 17:20:02 -07:00
Andrew Kelley
2d5d2ba4f5 std.zig.Render: update it and references 2025-07-16 17:20:02 -07:00
Andrew Kelley
0389b4c7b9 move a file without changing it 2025-07-16 17:20:02 -07:00
Andrew Kelley
6c4a104822 std.zig.Ast: update to new I/O API 2025-07-16 17:20:02 -07:00
Andrew Kelley
1a20b467ea std.zig: update to new I/O API 2025-07-16 17:20:02 -07:00
Andrew Kelley
680358767e
Merge pull request #24419 from ziglang/asm-clobbers
inline assembly: use types for clobbers
2025-07-17 02:14:18 +02:00
Silver
d772c06272 fix splatBytesAll and writeSplatAll 2025-07-16 20:37:38 +02:00
Andrew Kelley
af084e537a add lr register to mips 2025-07-16 10:27:40 -07:00
Andrew Kelley
c2fa961b63 update docs 2025-07-16 10:27:40 -07:00
Andrew Kelley
8a478b4e9e fix sparc ccr regs 2025-07-16 10:27:40 -07:00
Andrew Kelley
5aa50bcbff fix mips clobbers 2025-07-16 10:27:40 -07:00
Andrew Kelley
8a19eeb8af canonicalize loongarch clobbers 2025-07-16 10:27:40 -07:00
Andrew Kelley
15e5e5b2bc fix mips inline asm
wtf are these dollar signs?
2025-07-16 10:27:40 -07:00
Andrew Kelley
3628137442 add clobbers for more architectures 2025-07-16 10:27:40 -07:00
Andrew Kelley
54f073377c std.zig.render: handle legacy clobber updating more gracefully
"that's really easy to handle correctly" he said
2025-07-16 10:27:39 -07:00
Andrew Kelley
15f45e89a7 remove condition codes
LLVM always assumes these are on. Zig backends do not observe them.

If Zig backends want to start using them, they can be introduced, one
arch at a time, with proper documentation.
2025-07-16 10:27:39 -07:00
Andrew Kelley
de9c0e4580 alexrp suggestions 2025-07-16 10:27:39 -07:00
Andrew Kelley
76d04c1662 zig fmt 2025-07-16 10:27:39 -07:00
Andrew Kelley
87ce83d5a5 zig1.wasm update
needed due to syntax update
2025-07-16 10:23:02 -07:00
Andrew Kelley
fcafc63f3d inline assembly: use types
until now these were stringly typed.

it's kinda obvious when you think about it.
2025-07-16 10:23:02 -07:00
DubbleClick
c7bcdb4802 fix glibc version for single_threaded.h (2.32 instead of 2.35) 2025-07-16 19:18:15 +02:00
Alex Kladov
7d63e777a4 fix memory leak
closes #24421
2025-07-16 18:34:34 +02:00
Alex Rønne Petersen
6002514b72
test: mark riscv soft float targets as extra targets
Soft float is a very rare use case for riscv*-linux. No point wasting CI
resources on these targets, especially since our arm and mips soft float
coverage is already likely to catch most soft float bugs.
2025-07-16 16:54:12 +02:00
Alex Rønne Petersen
89ab6b161d
Merge pull request #24470 from alexrp/fix-tools
Fix bitrot in tools
2025-07-16 13:15:35 +02:00
Alex Rønne Petersen
11a49868a1
test: actually build the tools! 2025-07-16 06:38:53 +02:00
Alex Rønne Petersen
2ffa63acef
tools: fix some bitrot 2025-07-16 06:37:48 +02:00
Alex Rønne Petersen
9a69aede0e
ci: add riscv workflow with manual trigger for experimentation 2025-07-16 03:25:10 +02:00
Andrew Kelley
dbe0e0c1bc
Merge pull request #24464 from ziglang/fixes
std.Io fixes, docs, and tests
2025-07-16 02:54:45 +02:00
dweiller
94e0c85b6b update dump-cov for alignment and writergate changes 2025-07-15 23:57:56 +02:00
Andrew Kelley
5f6e3245d1 std.os.windows: restore sendmsg, sendto, recvfrom
These regressed with 1a998886c863a1829d649f196093f1058cd9cf13

I'm not ready to tackle std.posix quite yet
2025-07-15 14:24:06 -07:00
Andrew Kelley
d4a191fc0a CI: disable RISC-V runners for now
these are taking too long. let's use a different workflow for now until
these runs are not holding up the pipeline, then they can be
reintroduced on master branch
2025-07-15 13:54:12 -07:00
Andrew Kelley
6d39c29564 std.Io.Writer.Allocating: fix sendFile EndOfStream 2025-07-15 11:43:55 -07:00
Andrew Kelley
c7f332a260 std.Io.Writer.Discarding: fix sendFile EndOfStream 2025-07-15 11:32:40 -07:00
Andrew Kelley
f521aa0520 std.io.Reader: add more docs for rebase
closes #24418
2025-07-15 10:04:45 -07:00
Andrew Kelley
0cb558ba3a better default min versions for freebsd and netbsd
Without this change, by default you get a failure when trying to cross
compile for these targets.

freebsd was error: undefined symbol: __libc_start1
netbsd was warning: invalid target NetBSD libc version: 9.4.0
error: unable to build NetBSD libc shared objects: InvalidTargetLibCVersion

now they work by default
2025-07-15 15:32:18 +02:00
Alex Rønne Petersen
9dc4759902 zig std: link ws2_32.dll on windows
Closes #24450.
2025-07-15 13:53:22 +02:00
Andrew Kelley
a5dbb656b1
Merge pull request #24454 from ziglang/packed-struct-streams
std.Io: handle packed structs better
2025-07-15 13:43:08 +02:00
Andrew Kelley
d3cd0b2714
Merge pull request #24448 from matklad/matklad/inline
langref: make example more interesting.
2025-07-15 08:51:56 +02:00
Travis Staloch
294db62d92 memory safety fix for Io.Writer.Allocating.toOwnedSlice*()
don't forget to save the list.  this allows a
`testing.checkAllAllocationFailures()` test to pass in one of my
projects which newly failed since #24329 was merged.
2025-07-15 08:49:54 +02:00
Andrew Kelley
4f5fa959aa std.Io.Reader.streamDelimiterEnding docs clarification 2025-07-14 21:01:40 -07:00
Andrew Kelley
deb9f3e88f std.Io: handle packed structs better
Rather than having the endian-suffixed functions be the preferred ones
the unsuffixed ones are the preferred ones and the tricky functions get
a special suffix.

Makes packed structs read and written the same as integers.

closes #12960
2025-07-14 18:43:56 -07:00
Andrew Kelley
34d7cf075e std.posix: skip flaky test
tracked by #24380
2025-07-14 18:38:50 -07:00
Alex Rønne Petersen
3473e6dc26
ci: skip building and checking stage4 on riscv64-linux 2025-07-15 02:37:26 +02:00
Alex Rønne Petersen
96ad898ab8
ci: skip some test steps on riscv64-linux
Specifically:

* test-fmt
* test-translate-c
* test-run-translated-c
* test-cli
* test-incremental
2025-07-15 02:36:46 +02:00
Alex Rønne Petersen
a885e8370a
ci: partial revert of f3f2a56859f96cee6f9bc8e8fe14b99ec653abaf
While I experiment with ways to cut down run times, run on master only.
2025-07-15 02:27:58 +02:00
Andrew Kelley
148befdaa3
Merge pull request #24409 from ziglang/net
std.net: update to new I/O API
2025-07-15 01:42:40 +02:00
Alex Rønne Petersen
f3f2a56859 ci: make changes to riscv64-linux to try to avoid timeouts
The idea is to have 2 runners per machine, since a lot of time is spent building
stage3 and stage4, both of which are largely single-core affairs. This will make
the test steps take longer, however, so the timeouts have been bumped a bit, and
max RSS for the test step has been lowered from 64G to 32G to prevent OOM.
Finally, we now only run a single ReleaseSafe job on PRs; Debug and Release jobs
are limited to pushes.
2025-07-15 01:30:46 +02:00
Andrew Kelley
d66f13c90d
Merge pull request #24433 from Justus2308/switch-label-halt
Sema: Fix invalid AIR generation for switch loop with comptime discarded tag
2025-07-14 19:04:19 +02:00
Andrew Kelley
b993728f10 make it a behavior test instead
It's important to check for correct runtime behavior, rather than only
checking that the compiler does not crash.
2025-07-14 10:02:37 -07:00
Justus Klausecker
29ac68b253 Sema: Fix invalid AIR generation for switch loop with comptime discarded tag
Add an additional check before emitting `.loop_switch_br` instead
of `.switch_br` in a tagged switch statement for whether any of the
continues referencing its tag are actually runtime reachable.
This fixes triggering an assertion in Liveness caused by the invalid
assumption that every tagged switch must be a loop if its tag is
referenced in any way even if this reference is not runtime reachable.
2025-07-14 09:59:13 -07:00
Andrew Kelley
e4ebbdb354 std.c: add missing netbsd and freebsd MSG flags 2025-07-14 09:35:38 -07:00
Alex Kladov
d90646d8fb langref: remove dead code 2025-07-14 17:34:52 +01:00
Alex Kladov
96bb1137c2 langref: don't encourage printing to stderr in tests
The rule: `pub fn main` owns file descriptors 0, 1, and 2. If you didn't
write `pub fn main()` it is, in general, not your business to print to
stderr.
2025-07-14 17:32:50 +01:00
Alex Kladov
d045eb7a4a langref: make example more interesting.
As written, I think langref's example is actually a poor reason to use
`inline`.

If you have

     if (foo(1200, 34) != 1234) {
         @compileError("bad");
     }

and you want to make sure that the call is executed at compile time, the
right way to fix it is to add comptime

     if (comptime foo(1200, 34) != 1234) {
         @compileError("bad");
     }

and not to make the function `inline`. I _think_ that inlining functions
just to avoid `comptime` at a call-site is an anti-pattern. When the
reader sees `foo(123)` at the call-site, they _expect_ this to be a
runtime call, as that's the normal rule in Zig.

Inline is still necessary when you can't make the _whole_ call
`comptime`, because it has some runtime effects, but you still want
comptime-known result.

A good example here is

    inline fn findImportPkgHashOrFatal(b: *Build, comptime asking_build_zig: type, comptime dep_name: []const u8) []const u8 {

from Build.zig, where the `b` argument is runtime, and is used for
side-effects, but where the result is comptime.

I don't know of a good small example to demonstrate the subtelty here,
so I went ahead with just adding a runtime print to `foo`. Hopefully
it'll be enough for motivated reader to appreciate the subtelty!
2025-07-14 16:20:33 +01:00
Ali Cheraghi
f43f89a705 spirv: snake-case the spec 2025-07-14 15:16:17 +02:00
Andrew Kelley
2f3cd175d3 compiler: raise the bar for backend contributions 2025-07-14 09:26:24 +02:00
Andrew Kelley
b510482525 std.fs.File.Reader.seekTo: add missing int cast 2025-07-14 00:21:20 -07:00
Andrew Kelley
524e2e19a5 std.Io.Writer.Discarding: fix drain calculation 2025-07-14 00:18:13 -07:00
Andrew Kelley
0c0d94a6da std.net: wasi does not have unix sockets 2025-07-14 00:16:49 -07:00
Andrew Kelley
36f356254c align those @fieldParentPtr casts 2025-07-14 00:16:49 -07:00
Andrew Kelley
890f1fa848 make msghdr.iovlen unsigned
I don't care what C headers say. This value is never supposed to be
negative.
2025-07-14 00:16:49 -07:00
Andrew Kelley
9a1f4cb011 std.net: update to new I/O API 2025-07-14 00:16:49 -07:00
Andrew Kelley
5496901e71 std.Io.Reader.appendRemaining: add missing assert 2025-07-14 00:14:21 -07:00
Andrew Kelley
093fe02b75 add adaptToNewApi to std.Io.Reader as well 2025-07-14 00:14:21 -07:00
Andrew Kelley
96a4e9b866 std.crypto: fix Sha1 namespace 2025-07-14 00:14:21 -07:00
xdBronch
5a8acc9115 fix some llvm ir printer bugs 2025-07-14 08:31:54 +02:00
Brandon Black
e8a4e47d38 Add setsid to std.(c|posix)
The interface and errors for this seem to be very universal and
generic. Note Linux already has this defined as a syscall as well.
2025-07-14 07:26:49 +02:00
Alex Rønne Petersen
c6a18e9534 libcxx: fix building for wasm32-wasi by disabling exceptions
I accidentally regressed this in the LLVM 20 upgrade.

Closes #24437.
2025-07-14 07:12:34 +02:00
Andrew Kelley
5696bbb307
Merge pull request #23552 from alichraghi
Progress towards support for running LLVM backend in a separate thread
2025-07-14 04:19:13 +02:00
Andrew Kelley
a558885321 LLVM backend: fixes
* delete dead code
* don't access stack trace too early
* revert unintended edit
2025-07-13 12:16:31 -07:00
Ali Cheraghi
041bcbd109 Do not store StackTrace type 2025-07-13 12:16:31 -07:00
antlilja
e3b79d65d8 LLVM: Move pt field from Object to NavGen
* LLVM: Pass correct tid to emit
* Store stack trace type in Zcu
* Don't use pt.errorIntType in LLVM backend
2025-07-13 12:16:17 -07:00
Andrew Kelley
e7b18a7ce6 std.crypto: remove inline from most functions
To quote the language reference,

It is generally better to let the compiler decide when to inline a
function, except for these scenarios:

* To change how many stack frames are in the call stack, for debugging
  purposes.
* To force comptime-ness of the arguments to propagate to the return
  value of the function, as in the above example.
* Real world performance measurements demand it. Don't guess!

Note that inline actually restricts what the compiler is allowed to do.
This can harm binary size, compilation speed, and even runtime
performance.

`zig run lib/std/crypto/benchmark.zig -OReleaseFast`
[-before-] vs {+after+}

              md5:        [-990-]        {+998+} MiB/s
             sha1:       [-1144-]       {+1140+} MiB/s
           sha256:       [-2267-]       {+2275+} MiB/s
           sha512:        [-762-]        {+767+} MiB/s
         sha3-256:        [-680-]        {+683+} MiB/s
         sha3-512:        [-362-]        {+363+} MiB/s
        shake-128:        [-835-]        {+839+} MiB/s
        shake-256:        [-680-]        {+681+} MiB/s
   turboshake-128:       [-1567-]       {+1570+} MiB/s
   turboshake-256:       [-1276-]       {+1282+} MiB/s
          blake2s:        [-778-]        {+789+} MiB/s
          blake2b:       [-1071-]       {+1086+} MiB/s
           blake3:       [-1148-]       {+1137+} MiB/s
            ghash:      [-10044-]      {+10033+} MiB/s
          polyval:       [-9726-]      {+10033+} MiB/s
         poly1305:       [-2486-]       {+2703+} MiB/s
         hmac-md5:        [-991-]        {+998+} MiB/s
        hmac-sha1:       [-1134-]       {+1137+} MiB/s
      hmac-sha256:       [-2265-]       {+2288+} MiB/s
      hmac-sha512:        [-765-]        {+764+} MiB/s
      siphash-2-4:       [-4410-]       {+4438+} MiB/s
      siphash-1-3:       [-7144-]       {+7225+} MiB/s
   siphash128-2-4:       [-4397-]       {+4449+} MiB/s
   siphash128-1-3:       [-7281-]       {+7374+} MiB/s
  aegis-128x4 mac:      [-73385-]      {+74523+} MiB/s
  aegis-256x4 mac:      [-30160-]      {+30539+} MiB/s
  aegis-128x2 mac:      [-66662-]      {+67267+} MiB/s
  aegis-256x2 mac:      [-16812-]      {+16806+} MiB/s
   aegis-128l mac:      [-33876-]      {+34055+} MiB/s
    aegis-256 mac:       [-8993-]       {+9087+} MiB/s
         aes-cmac:       2036 MiB/s
           x25519:      [-20670-]      {+16844+} exchanges/s
          ed25519:      [-29763-]      {+29576+} signatures/s
       ecdsa-p256:       [-4762-]       {+4900+} signatures/s
       ecdsa-p384:       [-1465-]       {+1500+} signatures/s
  ecdsa-secp256k1:       [-5643-]       {+5769+} signatures/s
          ed25519:      [-21926-]      {+21721+} verifications/s
          ed25519:      [-51200-]      {+50880+} verifications/s (batch)
 chacha20Poly1305:       [-1189-]       {+1109+} MiB/s
xchacha20Poly1305:       [-1196-]       {+1107+} MiB/s
 xchacha8Poly1305:       [-1466-]       {+1555+} MiB/s
 xsalsa20Poly1305:        [-660-]        {+620+} MiB/s
      aegis-128x4:      [-76389-]      {+78181+} MiB/s
      aegis-128x2:      [-53946-]      {+53495+} MiB/s
       aegis-128l:      [-27219-]      {+25621+} MiB/s
      aegis-256x4:      [-49351-]      {+49542+} MiB/s
      aegis-256x2:      [-32390-]      {+32366+} MiB/s
        aegis-256:       [-8881-]       {+8944+} MiB/s
       aes128-gcm:       [-6095-]       {+6205+} MiB/s
       aes256-gcm:       [-5306-]       {+5427+} MiB/s
       aes128-ocb:       [-8529-]      {+13974+} MiB/s
       aes256-ocb:       [-7241-]       {+9442+} MiB/s
        isapa128a:        [-204-]        {+214+} MiB/s
    aes128-single:  [-133857882-]  {+134170944+} ops/s
    aes256-single:   [-96306962-]   {+96408639+} ops/s
         aes128-8: [-1083210101-] {+1073727253+} ops/s
         aes256-8:  [-762042466-]  {+767091778+} ops/s
           bcrypt:      0.009 s/ops
           scrypt:      [-0.018-]      {+0.017+} s/ops
           argon2:      [-0.037-]      {+0.060+} s/ops
      kyber512d00:     [-206057-]     {+205779+} encaps/s
      kyber768d00:     [-156074-]     {+150711+} encaps/s
     kyber1024d00:     [-116626-]     {+115469+} encaps/s
      kyber512d00:     [-181149-]     {+182046+} decaps/s
      kyber768d00:     [-136965-]     {+135676+} decaps/s
     kyber1024d00:     [-101307-]     {+100643+} decaps/s
      kyber512d00:     [-123624-]     {+123375+} keygen/s
      kyber768d00:      [-69465-]      {+70828+} keygen/s
     kyber1024d00:      [-43117-]      {+43208+} keygen/s
2025-07-13 18:26:13 +02:00
Marcos Gutiérrez Alonso
f97baca6f6
Add documentation to std.crypto.aes_gcm.AesGcm.encrypt (#24427) 2025-07-13 07:33:08 +00:00
Joost Doornbos
3974540e5a Fix memory leak in CObject.Diag.Bundle.destroy() 2025-07-13 04:38:58 +02:00
mlugg
549a466dd1 std.Io.Reader: encourage inlining hot buffer check
Resolves: #24424
2025-07-12 23:52:13 +02:00
Carmen
5b4e982169
std.os.uefi.tables: ziggify boot and runtime services (#23441)
* std.os.uefi.tables: ziggify boot and runtime services

* avoid T{} syntax

Co-authored-by: linusg <mail@linusgroh.de>

* misc fixes

* work

* self-review quickfixes

* dont make MemoryMapSlice generic

* more review fixes, work

* more work

* more work

* review fixes

* update boot/runtime services references throughout codebase

* self-review fixes

* couple of fixes i forgot to commit earlier

* fixes from integrating in my own project

* fixes from refAllDeclsRecursive

* Apply suggestions from code review

Co-authored-by: truemedian <truemedian@gmail.com>

* more fixes from review

* fixes from project integration

* make natural alignment of Guid align-8

* EventRegistration is a new opaque type

* fix getNextHighMonotonicCount

* fix locateProtocol

* fix exit

* partly revert 7372d65

* oops exit data_len is num of bytes

* fixes from project integration

* MapInfo consistency, MemoryType update per review

* turn EventRegistration back into a pointer

* forgot to finish updating MemoryType methods

* fix IntFittingRange calls

* set uefi.Page nat alignment

* Back out "set uefi.Page nat alignment"

This backs out commit cdd9bd6f7f5fb763f994b8fbe3e1a1c2996a2393.

* get rid of some error.NotFound-s

* fix .exit call in panic

* review comments, add format method

* fix resetSystem data alignment

* oops, didnt do a final refAllDeclsRecursive i guess

* review comments

* writergate update MemoryType.format

* fix rename

---------

Co-authored-by: linusg <mail@linusgroh.de>
Co-authored-by: truemedian <truemedian@gmail.com>
2025-07-12 17:18:53 +00:00
Alex Rønne Petersen
bd97b66186 ci: Add riscv64-linux-debug and riscv64-linux-release 2025-07-12 03:24:28 +02:00
Alex Rønne Petersen
681d324c49 std.Build.Step.Run: Set WINEDEBUG=-all for -fwine by default.
This silences the excessive default stderr logging from Wine. The user can still
override this by setting WINEDEBUG in the environment; this just provides a more
sensible default.

Closes #24139.
2025-07-12 00:03:02 +02:00
Alex Rønne Petersen
f4ed35f800 test: disable non-native loongarch64 behavior and std tests
https://github.com/ziglang/zig/issues/24405
2025-07-11 21:31:27 +02:00
mochalins
61eff7b6dd std: Fix Io.Reader.Limited and add test 2025-07-11 17:46:14 +02:00
Atlas Yu
2cda4cfb39 std.posix.send: should expect ConnectionRefused
Closes: #20219
2025-07-11 13:06:13 +02:00
Andrew Kelley
b60e9f2e85
Merge pull request #24394 from ziglang/fixes
buffering fixes
2025-07-11 10:56:24 +02:00
Linus Groh
eb37552536 Remove numerous things deprecated during the 0.14 release cycle
Basically everything that has a direct replacement or no uses left.

Notable omissions:

- std.ArrayHashMap: Too much fallout, needs a separate cleanup.
- std.debug.runtime_safety: Too much fallout.
- std.heap.GeneralPurposeAllocator: Lots of references to it remain, not
  a simple find and replace as "debug allocator" is not equivalent to
  "general purpose allocator".
- std.io.Reader: Is being reworked at the moment.
- std.unicode.utf8Decode(): No replacement, needs a new API first.
- Manifest backwards compat options: Removal would break test data used
  by TestFetchBuilder.
- panic handler needs to be a namespace: Many tests still rely on it
  being a function, needs a separate cleanup.
2025-07-11 08:17:43 +02:00
Anton Serov
d83b95cbf4 fixed .fixed flush recursion 2025-07-11 05:17:31 +02:00
Isaac Freund
f551c7c581 link.Elf: check files in archives for ELF magic
Apparently raw LLVM IR Bitcode files ("Bitstreams") may appear in
archives with LTO enabled. I observed this in the wild on
Chimera Linux.

I'm not yet sure if it's in scope for Zig to support these special
archives, but we should at least give a correct error message.
2025-07-11 04:57:54 +02:00
Andrew Kelley
e255415498 std: add some missing doc comments 2025-07-10 16:52:29 -07:00
Andrew Kelley
88e50b30c3 std.debug.print: provide a small buffer 2025-07-10 16:52:29 -07:00
Andrew Kelley
bd5745ddf2 std.log.defaultLog: provide a small buffer 2025-07-10 16:52:29 -07:00
Andrew Kelley
5360968e03 std: rename io to Io in preparation
This commit is non-breaking.

std.io is deprecated in favor of std.Io, in preparation for that
namespace becoming an interface.
2025-07-11 01:16:27 +02:00
Andrew Kelley
43fba5ea83
Merge pull request #24387 from ziglang/std.log.default_level
std.log: adjust default level for ReleaseSmall to include info + bonus cleanup
2025-07-10 14:56:33 +02:00
Andrew Kelley
1a998886c8
Merge pull request #24329 from ziglang/writergate
Deprecates all existing std.io readers and writers in favor of the newly
provided std.io.Reader and std.io.Writer which are non-generic and have the
buffer above the vtable - in other words the buffer is in the interface, not
the implementation. This means that although Reader and Writer are no longer
generic, they are still transparent to optimization; all of the interface
functions have a concrete hot path operating on the buffer, and only make
vtable calls when the buffer is full.
2025-07-10 12:04:27 +02:00
triallax
5b4b033236 build runner: fix --verbose-llvm-bc= not properly accepting value
closes #21001
2025-07-10 11:04:29 +02:00
Andrew Kelley
40d74e4287 std: refactor to use Alignment.of 2025-07-09 23:07:18 -07:00
Andrew Kelley
36cf22c55c std.log: adjust default level for ReleaseSmall to include info
it was kind of wild to not do this before. sorry!
2025-07-09 23:03:35 -07:00
Alex Rønne Petersen
820f1a23a5 std: Disable std.zon parse float on dynamic x86-linux-musl
https://github.com/ziglang/zig/issues/23922#issuecomment-3054296672
2025-07-10 06:52:01 +02:00
Andrew Kelley
10d6db5d7d std.io.Writer: remove some unimplemented functions
YAGNI
2025-07-09 20:01:15 -07:00
Andrew Kelley
aa1bdb43e0 std.io.Writer.writeStructEndian: fix packed structs 2025-07-09 20:01:15 -07:00
Andrew Kelley
dce08d9a57 std.Build.Cache: remove debugging remnants
oops!
2025-07-09 20:01:15 -07:00
Andrew Kelley
55bced9563 std.fs.File.Writer: fix splat alias bug
same deal as previous commit
2025-07-09 20:01:15 -07:00
Andrew Kelley
9e52febeeb std.io.Writer.writeSplatHeader: fix splat alias bug
pointer comparison cannot be used since the buffers may alias
2025-07-09 18:29:10 -07:00
Andrew Kelley
09cdcf67e1 std.io.Writer.writeSplat: simplify and fix 2025-07-09 17:52:36 -07:00
Andrew Kelley
ab84dcc824 std.io.Reader: make vtable contract more consistent 2025-07-09 17:30:05 -07:00
Andrew Kelley
c072cf2bb8 std.io.Reader.peekDelimiterInclusive: simplify and fix 2025-07-09 17:18:23 -07:00
Andrew Kelley
93ac76594a std: fmt.format to io.Writer.print
allows reverting format -> deprecatedFormat, plus I think this is a
nicer place for the function.
2025-07-09 15:31:02 -07:00
Andrew Kelley
4d93545ded chicken out and allow ascii string alignment 2025-07-09 15:17:07 -07:00
Andrew Kelley
2468766a89 std: forbid alignment formatting options sometimes 2025-07-09 15:07:45 -07:00
Andrew Kelley
51a9a6aab6 std: replace formatInteger with formatNumber 2025-07-09 14:54:54 -07:00
Andrew Kelley
5bc95a6fa2 wasi.c: fix pread/pwrite
When stream is NULL it means reads should read 0 bytes and writes should
fake success with no side effects.
2025-07-09 10:47:36 -07:00
Andrew Kelley
5c6679922d CBE: avoid depending on std.io.Writer.count 2025-07-09 09:32:07 -07:00
Andrew Kelley
bc2cf0c173 eliminate all uses of std.io.Writer.count except for CBE 2025-07-09 09:32:07 -07:00
Alex Rønne Petersen
7c709f920b ci: Update to QEMU 10.0.2 2025-07-09 11:06:13 +02:00
Andrew Kelley
d345a10054 std.os.freebsd.copy_file_range: add missing error.Unexpected 2025-07-08 16:53:02 -07:00
Andrew Kelley
81b0c99915 std.zig.system.linux: update API usage 2025-07-08 15:15:21 -07:00
Andrew Kelley
c1c49a7d1c C backend: fix bitcasting regression 2025-07-08 15:15:08 -07:00
Andrew Kelley
1dcb20d27e std.fmt: refactor to remove cacheString
when this kind of trick is needed, do it inline
2025-07-08 11:07:23 -07:00
Andrew Kelley
fc335a3a48 update format strings in os/windows/test.zig 2025-07-08 08:46:31 -07:00
Andrew Kelley
83c4000319 std: revert big int test to master branch
oops, it depends on usize
2025-07-08 08:36:04 -07:00
Andrew Kelley
db021c4fd1 CI: disable self-hosted riscv64
it's missing some critical features like `@fieldParentPtr` and `@memmove`
2025-07-08 08:28:20 -07:00
Andrew Kelley
5955ba4f53 std.fs.File.Writer: implement positional writing for Windows 2025-07-07 23:09:14 -07:00
Jacob Young
720cd43fc1 cbe: fix code header being omitted from the output 2025-07-07 22:43:53 -07:00
Andrew Kelley
043079d765 std.io.Writer.VectorWrapper: fix vtable not being a unique addr 2025-07-07 22:43:53 -07:00
Andrew Kelley
a983f5b90f wasm backend: memcpy and memmove are the same
both lower to memory.fill operation, which are allowed to overlap
2025-07-07 22:43:53 -07:00
Andrew Kelley
c7b4b17ba2 fix test case expected float value
it's better now
2025-07-07 22:43:53 -07:00
Andrew Kelley
911cd2611f Sema: fix unintentional extra @compileLog newline 2025-07-07 22:43:53 -07:00
Andrew Kelley
26659c862f update compiler unit tests to new API 2025-07-07 22:43:53 -07:00
Andrew Kelley
b0395531d3 update autodocs and langref to new API 2025-07-07 22:43:53 -07:00
Andrew Kelley
d8e26275f2 update standalone and incremental tests to new API 2025-07-07 22:43:53 -07:00
Andrew Kelley
c873c2eed9 fix aro translate-c building from source 2025-07-07 22:43:53 -07:00
Andrew Kelley
e97a0ffb60 std.Build.Step.CheckObject: mostly revert to master branch
the updated code to use new std.io API is crashing
2025-07-07 22:43:53 -07:00
Andrew Kelley
f2ad3bcc1c fix 32-bit compilation 2025-07-07 22:43:53 -07:00
Andrew Kelley
b077e2979c std.io.Reader: fix peekByte 2025-07-07 22:43:53 -07:00
Andrew Kelley
a7387f0047 fix std.io.Writer.VectorWrapper mechanism
previous implementation erroneously attempted to detect whether vector
API was used via the buffer pointer. This implementation has an explicit
flag.
2025-07-07 22:43:53 -07:00
Andrew Kelley
9903587a63 std.Build.Step.Options: fix build failure 2025-07-07 22:43:53 -07:00
Andrew Kelley
fd7feed04b std.fs.File.Writer: implement positional writing 2025-07-07 22:43:53 -07:00
Andrew Kelley
7e2a26c0c4 std.io.Writer.printValue: rework logic
Alignment and fill options only apply to numbers.

Rework the implementation to mainly branch on the format string rather
than the type information. This is more straightforward to maintain and
more straightforward for comptime evaluation.

Enums support being printed as decimal, hexadecimal, octal, and binary.

`formatInteger` is another possible format method that is
unconditionally called when the value type is struct and one of the
integer-printing format specifiers are used.
2025-07-07 22:43:53 -07:00
Andrew Kelley
5378fdb153 std.fmt: fully remove format string from format methods
Introduces `std.fmt.alt` which is a helper for calling alternate format
methods besides one named "format".
2025-07-07 22:43:53 -07:00
Andrew Kelley
4ccc6f2b57 compiler: fix remaining build failures 2025-07-07 22:43:53 -07:00
Andrew Kelley
6489907662 std.zip: work around deprecated API 2025-07-07 22:43:53 -07:00
Andrew Kelley
f4720e1407 std.testing: update to new std.io API 2025-07-07 22:43:53 -07:00
Andrew Kelley
87a7568a44 build runner: restore missing newline 2025-07-07 22:43:52 -07:00
Andrew Kelley
9c8aef55b4 std.fmt.format: use {t} for tag name rather than {s}
prevents footgun when formatted type changes from string to enum
2025-07-07 22:43:52 -07:00
Andrew Kelley
30c2921eb8 compiler: update a bunch of format strings 2025-07-07 22:43:52 -07:00
Andrew Kelley
d09b99d043 C backend: fix compilation errors 2025-07-07 22:43:52 -07:00
Andrew Kelley
f409457925 compiler: fix a bunch of format strings 2025-07-07 22:43:52 -07:00
Andrew Kelley
494819be91 cbe: reapply writer changes 2025-07-07 22:43:52 -07:00
Andrew Kelley
6963a1c7b9 C backend: prepare for merge 2025-07-07 22:43:52 -07:00
Andrew Kelley
6314e6f238 compiler: fix a bunch of format strings 2025-07-07 22:43:52 -07:00
Andrew Kelley
d5c97fded5 compiler: fix a bunch of format strings 2025-07-07 22:43:52 -07:00
Andrew Kelley
3afc6fbac6 std.zig.llvm.Builder: update format API 2025-07-07 22:43:52 -07:00
Andrew Kelley
cce32bd1d5 fix build runner 2025-07-07 22:43:52 -07:00
Andrew Kelley
ec3b5f0c74 compiler: upgrade various std.io API usage 2025-07-07 22:43:52 -07:00
Andrew Kelley
756a2dbf1a compiler: upgrade various std.io API usage 2025-07-07 22:43:52 -07:00
Andrew Kelley
941bc37193 compiler: update all instances of std.fmt.Formatter 2025-07-07 22:43:52 -07:00
Andrew Kelley
49be02e6d7 MachO: revert unfinished changes 2025-07-07 22:43:52 -07:00
Andrew Kelley
c8fcd2ff2c MachO: update to new std.io APIs 2025-07-07 22:43:52 -07:00
Andrew Kelley
f71d97e4cb update compiler source to new APIs 2025-07-07 22:43:52 -07:00
Andrew Kelley
fac5fe57be std.io.Writer.Allocating: rename interface to writer 2025-07-07 22:43:52 -07:00
Andrew Kelley
fc310ee7bc std.io.Reader: fix appendRemaining 2025-07-07 22:43:52 -07:00
Andrew Kelley
4bca5faca6 std.Build.Cache: write manifest without heap allocating
Now that the buffered writing interface is not generic.
2025-07-07 22:43:52 -07:00
Andrew Kelley
d6ac04c478 std.Build.Step.CheckObject: fix the TODO 2025-07-07 22:43:52 -07:00
Andrew Kelley
87f32bec26 std.io.Reader: finish implementing the unit tests 2025-07-07 22:43:52 -07:00
Andrew Kelley
49093a659f std.debug: lil buffer for this guy 2025-07-07 22:43:52 -07:00
Andrew Kelley
8f4229158b std.io.Writer.Allocating: extra ensure byte
So that when returning from drain there is always capacity for at least
one more byte.
2025-07-07 22:43:52 -07:00
Andrew Kelley
d03d273117 std.io.Reader: fix fill implementation
now it avoids writing to buffer in the case of fixed
2025-07-07 22:43:52 -07:00
Andrew Kelley
1e1f026c83 std.mem.byteSwapAllFields: support slices 2025-07-07 22:43:52 -07:00
Andrew Kelley
1ee403ce93 std.io.Reader: add doctest for streamDelimiterLimit 2025-07-07 22:43:51 -07:00
Andrew Kelley
435ccf706d std.fs.File.Writer: fix drain implementation
it didn't account for data.len can no longer be zero
2025-07-07 22:43:51 -07:00
Andrew Kelley
77e839e283 std.io.Reader: fix streamDelimiter and streamDelimiterEnding 2025-07-07 22:43:51 -07:00
Andrew Kelley
1d763c8b29 std: formatted printing no longer prints type names
for structs, enums, and unions.

auto untagged unions are no longer printed as pointers; instead they are
printed as "{ ... }".

extern and packed untagged unions have each field printed, similar to
what gdb does.

also fix bugs in delimiter based reading
2025-07-07 22:43:51 -07:00
Andrew Kelley
7eae26d608 delete bad behavior test
behavior tests must not depend on std.io
2025-07-07 22:43:51 -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
Andrew Kelley
0b3f0124dc std.io: move getStdIn, getStdOut, getStdErr functions to fs.File
preparing to rearrange std.io namespace into an interface

how to upgrade:

std.io.getStdIn() -> std.fs.File.stdin()
std.io.getStdOut() -> std.fs.File.stdout()
std.io.getStdErr() -> std.fs.File.stderr()
2025-07-07 22:43:51 -07:00
Nameless
7c42517151 os: fix missing and incorrect msghdr definitions
Macos uses the BSD definition of msghdr

All linux architectures share a single msghdr definition. Many
architectures had manually inserted padding fields that were endian
specific and some had fields with different integers. This unifies all
architectures to use a single correct msghdr definition.
2025-07-07 22:43:51 -07:00
Andrew Kelley
9f27d770a1 std.io: deprecated Reader/Writer; introduce new API 2025-07-07 22:43:51 -07:00
Andrew Kelley
fc2c1883b3
Merge pull request #24362 (remove async, await, usingnamespace)
remove `async` and `await` keywords; remove `usingnamespace`
2025-07-08 07:41:39 +02:00
Alex Rønne Petersen
9e49652757 llvm: Revert #17963 (workaround for #16392) 2025-07-08 02:50:15 +02:00
Andrew Kelley
4ba0e7d424 update zig1.wasm
necessary because to pass `zig fmt --check` we need to use the canonical
identifier syntax, which means changing `.@"async"` to `.async` which
previous zig1 is unable to parse.
2025-07-07 13:39:48 -07:00
Andrew Kelley
34f64432b0 remove usingnamespace from the language
closes #20663
2025-07-07 13:39:48 -07:00
Andrew Kelley
aa52bb8327 zig fmt 2025-07-07 13:39:16 -07:00
Andrew Kelley
a59c35cbf8 build.zig: bump maxrss for behavior tests 2025-07-07 13:39:16 -07:00
Andrew Kelley
40d11cc25a remove async and await keywords
Also remove `@frameSize`, closing #3654.

While the other machinery might remain depending on #23446, it is
settled that there will not be `async`/ `await` keywords in the
language.
2025-07-07 13:39:16 -07:00
Alex Rønne Petersen
31e46be743 std.c: Use __sigemptyset14 for sigemptyset on NetBSD
Closes #24344.
2025-07-07 12:14:58 +02:00
Alex Rønne Petersen
9a1e754a58 compiler-rt: Implement __clear_cache() for mips-netbsd 2025-07-07 09:05:07 +02:00
Alex Rønne Petersen
5209e7e458 compiler-rt: Export __emutls_get_address for OpenHarmony 2025-07-07 07:23:24 +02:00
Alex Rønne Petersen
b5cc658ab4 llvm: Use emulated TLS when appropriate for the target
Closes #24236.
2025-07-07 07:23:24 +02:00
Alex Rønne Petersen
c96c913bab
Merge pull request #24352 from alexrp/wasi-emulated-libs
`wasi`: Build emulated libraries into `libc.a`
2025-07-07 03:42:51 +02:00
jaune
ef8db03d52 std.posix.accept: add WSAENOTSOCK 2025-07-07 00:26:21 +02:00
Alex Rønne Petersen
2bf9ff1b42
wasi: Fix libwasi-emulated-process-clocks build
Might have been broken in 05d8b565ad1a1d6c0c1e93dc47f1d828043fcafc.
2025-07-06 20:49:19 +02:00
Alex Rønne Petersen
1f1082e36d
wasi: Build emulated libraries into libc.a
This matches what we do for small helper libraries like this in MinGW-w64. It
simplifies the compiler a bit, and also means the build system doesn't have to
treat these library names specially.

Closes #24325.
2025-07-06 20:05:18 +02:00
Alex Rønne Petersen
97ecb6c551 compiler: Disable self-hosted x86_64 backend on NetBSD
https://github.com/ziglang/zig/issues/24341
2025-07-06 19:50:29 +02:00
Alex Rønne Petersen
b461d07a54 Sema: Stop adding Windows implib link inputs for extern "..." syntax.
Closes #23971.
2025-07-06 01:00:18 +02:00
Alex Rønne Petersen
044ccf4138 test: More cleanup of Windows targets in the module test matrix
It's kind of unclear what `*-windows-none` actually means, but as far as LLVM is
concerned, it's equivalent to `*-windows-msvc`. For clarity, only test
`*-windows-msvc` and `*-windows-gnu`. #20690 will clean this situation up
eventually.

Also ensure coverage of `link_libc = true` and `link_libc = false` for both.
2025-07-05 04:05:34 +02:00
Alex Rønne Petersen
fc993945a9
Merge pull request #24335 from kada49/common-impl-libc-floor 2025-07-05 03:18:31 +02:00
Silver
be20f97eb9 Update TracyAllocator to new allocator API 2025-07-05 00:24:40 +02:00
Alex Rønne Petersen
9a8f1f675b start: Only issue fninit for x86(_64)-windows
Closes #24263.
2025-07-04 20:09:20 +02:00
David Senoner
b78751051f
delete superfluous assembly libc floor implementations 2025-07-04 20:05:18 +02:00
David Senoner
3124f700c7
delete superfluous libc floor implementations 2025-07-04 12:54:31 +02:00
Alex Rønne Petersen
9ef4bdf234 test: Respect various test skip options in test-cases 2025-07-03 22:18:12 +02:00
Brandon Black
aa1556156e std.posix.getsockopt: set option length correctly
Fixes #24293
2025-07-03 09:41:26 +02:00
Andrew Kelley
31bc6d5a9d
Merge pull request #24322 from ziglang/delete-dead-backends
delete abandoned backends
2025-07-03 04:57:25 +02:00
Andrew Kelley
e126e5592d compiler: delete dead x86 bits file 2025-07-02 15:03:26 -07:00
Andrew Kelley
5ae2428d52 compiler: change canonical path for backend ABI source files 2025-07-02 15:01:50 -07:00
Andrew Kelley
a13f0d40eb compiler: delete arm backend
this backend was abandoned before it was completed, and it is not worth
salvaging.
2025-07-02 14:50:41 -07:00
Andrew Kelley
20a543097b compiler: delete aarch64 backend
this backend was abandoned before it was completed, and it is not worth
salvaging.
2025-07-02 14:42:20 -07:00
Andrew Kelley
80a9b8f326 compiler: delete powerpc backend stub
nobody is currently working on this
2025-07-02 14:35:13 -07:00
Alex Rønne Petersen
edf785db0f
Merge pull request #24302 from alexrp/riscv
Native RISC-V bootstrap and test fixes
2025-07-02 04:15:10 +02:00
Alex Rønne Petersen
8e511e031f
std.crypto.salsa20: Disable some tests on RISC-V with vector support
https://github.com/ziglang/zig/issues/24299
2025-07-01 23:03:15 +02:00
Alex Rønne Petersen
1c9d9b70ec
std.bit_set: Disable IntegerBitSet decltest on RISC-V with vector support
https://github.com/ziglang/zig/issues/24300
2025-07-01 23:03:15 +02:00
Alex Rønne Petersen
9f064dff47
langref: runtime_shrExact_overflow does not work as expected on RISC-V
https://github.com/ziglang/zig/issues/24304
2025-07-01 23:03:15 +02:00
Alex Rønne Petersen
b739fec841
test: Disable stack_iterator test on riscv64-linux
https://github.com/ziglang/zig/issues/24310
2025-07-01 23:03:15 +02:00
Alex Rønne Petersen
1f2e3b39ae
test: Disable vector division operators on RISC-V with vector support
https://github.com/ziglang/zig/issues/24301
2025-07-01 23:03:15 +02:00
Alex Rønne Petersen
1fcabe0bfc
test: Only run coff_dwarf test on aarch64, x86, x86_64
This will just fail if run on architectures like riscv64.
2025-07-01 23:03:15 +02:00
Alex Rønne Petersen
80c3de40b3
test: Properly limit glibc_compat versions based on the host 2025-07-01 23:03:15 +02:00
Alex Rønne Petersen
3d7fb4f204
std.zig.system.linux: Add detection for some extra RISC-V CPUs 2025-07-01 23:03:15 +02:00
Alex Rønne Petersen
fd2d4507c8
std.os.linux: Define ucontext_t and mcontext_t for RISC-V
Closes #24239.
2025-07-01 23:03:13 +02:00
Ivan Stepanov
ee6d19480d spirv: fix signed overflow detection for safe subtraction
The overflow check for safe signed subtraction was using the formula (rhs < 0) == (lhs > result). This logic is flawed and incorrectly reports an overflow when the right-hand side is zero.
For the expression 42 - 0, this check evaluated to (0 < 0) == (42 > 42), which is false == false, resulting in true. This caused the generated SPIR-V to incorrectly branch to an OpUnreachable instruction, preventing the result from being stored.

Fixes #24281.
2025-07-01 19:26:21 +02:00
Alex Rønne Petersen
07114e6bc6
llvm: Disable the machine outliner pass on RISC-V 2025-07-01 18:16:40 +02:00
Alex Rønne Petersen
aa7b32d781
llvm: Fix alignment of by-ref ptr_elem_val and slice_elem_val 2025-07-01 18:16:36 +02:00
Micah Switzer
b8ac740a1b Fix zig std regression FTBFS
Regressed in 9176408
2025-06-30 18:06:14 +02:00
Andrew Kelley
79db39307b
Merge pull request #24297 from ziglang/optional-empty-error-set
Sema: correct OPV for optional empty error set
2025-06-30 15:25:35 +02:00
Alex Rønne Petersen
6b6e336e07
std.Build.Step.CheckObject: Truncate st_other before interpreting it
Tools are free to use the upper bits of this field for whatever; thus, tools
that want to interpret the visibility type should truncate to 2 bits.
2025-06-30 12:21:38 +02:00
Alex Rønne Petersen
b64fe53ad5
std.simd: Increase branch quota in suggestVectorLengthForCpu()
This does a bunch of CPU family and feature checks. It would be annoying to have
to @setEvalBranchQuota() at every comptime use site.
2025-06-30 08:01:27 +02:00
Alex Rønne Petersen
197fb26da0
libunwind: Fix return type of DwarfFDECache<A>::findFDE()
https://github.com/llvm/llvm-project/pull/146308
2025-06-30 06:40:17 +02:00
Andrew Kelley
d9742acc23 Sema: detect one-possible-value types after function calls
produces better Air for backends
2025-06-29 17:53:52 -07:00
Andrew Kelley
7999374b21 Sema: correct OPV for optional empty error set
prevents crashes in backends; improves codegen; provides more
comptime-ness.
2025-06-29 17:20:23 -07:00
Alex Rønne Petersen
e837765956
zig rc: Fix include directory detection when cross-compiling from certain host archs (#24288)
* resinator: Only preprocess when the input is an .rc file

* resinator: Fix include directory detection when cross-compiling from certain host archs

Previously, resinator would use the host arch as the target arch when looking for windows-gnu include directories. However, Zig only thinks it can provide a libc for targets specified in the `std.zig.target.available_libcs` array, which only includes a few for windows-gnu. Therefore, when cross-compiling from a host architecture that doesn't have a windows-gnu target in the available_libcs list, resinator would fail to detect the MinGW include directories.

Now, the custom option `/:target` is passed to `zig rc` which is intended for the COFF object file target, but can be re-used for the include directory target as well. For the include directory target, resinator will convert the MachineType to the relevant arch, or fail if there is no  equivalent arch/no support for detecting the includes for the MachineType (currently 64-bit Itanium and EBC).

Fixes the `windows_resources` standalone test failing when the host is, for example, `riscv64-linux`.
2025-06-29 09:59:38 +02:00
Ryan Liptak
d3363b7a61 Replace unreachable with error return for non-standard Windows targets
This new error mirrors the error returned from the Elf struct (error.UnsupportedElfArchitecture):

0adcfd60f4/src/link/Lld.zig (L112)

Before:

```
$ zig build-exe -target riscv64-windows-gnu main.zig
thread 543087 panic: reached unreachable code
```

After:

```
$ zig build-exe -target riscv64-windows-gnu main.zig
error: unable to create compilation: UnsupportedCoffArchitecture
```

Closes #24287
2025-06-29 08:32:19 +02:00
Alex Rønne Petersen
6322dbd5bf
compiler: test runner: fix tests never fails on crippled architectures (#24180)
* compiler: test runner: fix tests never fails on crippled architectures

* riscv64: skip failing tests

* riscv64: enable test summary printing
2025-06-29 08:03:59 +02:00
Ryan Liptak
09f4e2d9d1 resinator: Fix include directory detection when cross-compiling from certain host archs
Previously, resinator would use the host arch as the target arch when looking for windows-gnu include directories. However, Zig only thinks it can provide a libc for targets specified in the `std.zig.target.available_libcs` array, which only includes a few for windows-gnu. Therefore, when cross-compiling from a host architecture that doesn't have a windows-gnu target in the available_libcs list, resinator would fail to detect the MinGW include directories.

Now, the custom option `/:target` is passed to `zig rc` which is intended for the COFF object file target, but can be re-used for the include directory target as well. For the include directory target, resinator will convert the MachineType to the relevant arch, or fail if there is no  equivalent arch/no support for detecting the includes for the MachineType (currently 64-bit Itanium and EBC).

Fixes the `windows_resources` standalone test failing when the host is, for example, `riscv64-linux`.
2025-06-28 19:52:18 -07:00
Ryan Liptak
761783f54d resinator: Only preprocess when the input is an .rc file 2025-06-28 19:43:22 -07:00
Bingwu Zhang
ff06de4c89
riscv64: enable test summary printing 2025-06-28 06:47:09 +08:00
Bingwu Zhang
e8d6ecb9ce
riscv64: skip failing tests 2025-06-28 06:47:09 +08:00
Bingwu Zhang
5db395f20b
compiler: test runner: fix tests never fails on crippled architectures 2025-06-27 19:12:16 +08:00
Jonathan Marler
0adcfd60f4
Fix warning WasmMut_toC not all control paths return a value (#24267)
* Fix warning WasmMut_toC not all control paths return a value

This is a follow up to https://github.com/ziglang/zig/pull/24206 where
I had previously submitted different mechanisms to fix this warning.
This PR is a suggestion by Alex to return NULL instead and Andrew
confirmed this is his preference.
2025-06-26 05:39:08 +00:00
Andrew Kelley
8eca338c27 fix zig libc FTBFS 2025-06-25 05:17:46 -07:00
Marc
75d6d4c3f2
add glibc versioning for a number of headers (#24237)
* getrandom was added in glibc 2.25
https://sourceware.org/bugzilla/show_bug.cgi?id=17252

* copy_file_range was added in glibc 2.27
https://sourceware.org/git/?p=glibc.git;a=commit;h=bad7a0c81f501fbbcc79af9eaa4b8254441c4a1f

* threads.h should not exist for glibc < 2.28

* single_threaded.h should not exist for glibc < 2.35

* Apply suggestions from code review

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>

* 2.35 instead of 35

* before 2.35 instead of 2.34 and before

---------

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>
2025-06-24 16:14:00 +00:00
Dacheng
35329b510c
c.darwin: define MSG for macos (#24224)
* c.darwin: define MSG for macos

* darwin: add series os name

* Update lib/std/c.zig

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>

---------

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>
2025-06-24 15:07:06 +02:00
Alex Rønne Petersen
342c34d95e
Merge pull request #24238 from taylordotfish/bugfix/ppc64le-syscall 2025-06-24 15:06:31 +02:00
Pat Tullmann
710632b45c lib/std/fs/test.zig: Some filesystems support 8 EiB files
Btrfs at least supports 16 EiB files (limited in practice to 8EiB by the
Linux VFS code which uses signed 64-bit offsets).  So fix the fs.zig test
case to expect either a FileTooBig or success from truncating a file to
8EiB.  And test that beyond that size the offset is interpreted as a
negative number.

Fixes #24242
2025-06-23 15:20:24 +02:00
Kevin Boulain
640a130651 std.Build.Watch: key fanotify file descriptors by mount id
Since marks are limited to a single filesystem.
Context: https://github.com/ziglang/zig/issues/20670
Original pull request: https://github.com/ziglang/zig/pull/20672

Co-authored-by: Maciej 'vesim' Kuliński <vesim809@pm.me>
2025-06-23 06:08:25 +02:00
Ali Cheraghi
1df79ab895 remove spirv cpu arch 2025-06-23 06:03:03 +02:00
Jacob Young
c71bb0f2b6 x86_64: fix pair live-out tracking
Closes #24226
2025-06-23 05:58:14 +02:00
Ali Cheraghi
24bfefa75e std.mem.byteSwapAllFields: support untagged unions 2025-06-23 05:57:56 +02:00
taylor.fish
95b638f613 Update 32-bit PowerPC syscall functions
musl and glibc both specify r0 as an output register because its value
may be overwritten by system calls. As with the updates for 64-bit
PowerPC in the previous commit, this commit brings Zig's syscall
functions for 32-bit PowerPC in line with musl and glibc by adding r0 to
the list of clobbers. (Listing r0 as both an input and a clobber is as
close as we can get to musl, which declares it as a "+r" read-write
output, since Zig doesn't support multiple outputs or the "+"
specifier.)
2025-06-22 16:48:36 -07:00
David Rubin
3034d1e377 minor grammatical mistake 2025-06-22 20:00:17 +02:00
taylor.fish
79807468e7 Fix illegal behavior from syscalls on powerpc64le
On powerpc64le Linux, the registers used for passing syscall parameters
(r4-r8, as well as r0 for the syscall number) are volatile, or
caller-saved. However, Zig's syscall wrappers for this architecture do
not include all such registers in the list of clobbers, leading the
compiler to assume these registers will maintain their values after the
syscall completes.

In practice, this resulted in a segfault when allocating memory with
`std.heap.SmpAllocator`, which calls `std.os.linux.sched_getaffinity`.
The third parameter to `sched_getaffinity` is a pointer to a `cpu_set_t`
and is stored in register r5. After the syscall, the code attempts to
access data in the `cpu_set_t`, but because the compiler doesn't realize
the value of r5 may have changed, it uses r5 as the memory address, which
in practice resulted in a memory access at address 0x8.

This commit adds all volatile registers to the list of clobbers.
2025-06-21 21:47:58 -07:00
Matthew Lugg
75d0ec9c04
Merge pull request #24227 from mlugg/misc-build-stuff
`std.Build`: more miscellaneous bits
2025-06-20 10:28:38 +01:00
Koki Ueha
9e340b3005 This commit enables fmax and fmin to differentiate between 0.0 and
-0.0, making it compatible with musl.
2025-06-20 10:17:24 +02:00
Alex Rønne Petersen
14ad8378a1
Merge pull request #23464 from rootbeer/futex-casts
Linux futex (v1 and v2) API fixes, tests and Ziggification
2025-06-20 10:08:22 +02:00
Jacob Young
cf1a7bbd44
Merge pull request #24193 from jacobly0/x86_64-spring-cleaning
x86_64: increase passing test coverage on windows
2025-06-20 00:20:56 -04:00
mlugg
4a9e8b73aa
std.Build.Step.Run: pass correct relative cache dir to tests
Fixes an additional bug reported in the closed #24216.
2025-06-20 00:33:44 +01:00
mlugg
a02a2219ee
standalone: add accidentally-excluded test 2025-06-20 00:24:57 +01:00
Jacob Young
1f98c98fff x86_64: increase passing test coverage on windows
Now that codegen has no references to linker state this is much easier.

Closes #24153
2025-06-19 18:41:12 -04:00
Jacob Young
ed37a1a33c coff: add hack to build a compiler-rt dynamic library
This is not meant to be a long-term solution, but it's the easiest thing
to get working quickly at the moment. The main intention of this hack is
to allow more tests to be enabled. By the time the coff linker is far
enough along to be enabled by default, this will no longer be required.
2025-06-19 18:41:12 -04:00
Jacob Young
e92b129063 Compilation: fix use after free
Closes #23967
2025-06-19 18:41:11 -04:00
Jacob Young
917640810e Target: pass and use locals by pointer instead of by value
This struct is larger than 256 bytes and code that copies it
consistently shows up in profiles of the compiler.
2025-06-19 11:45:06 -04:00
Jacob Young
16d78bc0c0 Build: add install commands to --verbose output 2025-06-19 11:45:06 -04:00
Jacob Young
df4068cabd Build: change how the target is printed in step names
e.g. `x86_64-windows.win10...win11_dt-gnu` -> `x86_64-windows-gnu`

When the OS version is the default this is redundant with checking the
default in the standard library.
2025-06-19 11:45:06 -04:00
Jonathan Marler
f5a327cd36 windows: msvc: avoid linking to non-redistributable ucrt 2025-06-19 13:43:27 +02:00
Pat Tullmann
89d15a8d47 linux: futex v2 API updates
* `futex2_waitv` always takes a 64-bit timespec.  Perhaps the
  `kernel_timespec` should be renamed `timespec64`?  Its used in iouring,
  too.

* Add `packed struct` for futex v2 flags and parameters.

* Add very basic "tests" for the futex v2 syscalls (just to ensure the
  code compiles).

* Update the stale or broken comments.  (I could also just delete these
  they're not really documenting Zig-specific behavior.)

Given that the futex2 APIs are not used by Zig's library (they're a bit
too new), and the fact that these are very specialized syscalls, and they
currently provide no benefit over the existing v1 API, I wonder if instead
of fixing these up, we should just replace them with a stub that says 'use
a 3rd party library'.
2025-06-18 19:53:50 -07:00
mlugg
36499c251c std.Build.Step.Run: prefix relative path arguments with './'
This is necessary in two cases:

* On POSIX, the exe path (`argv[0]`) must contain a path separator
* Some programs might treat a file named e.g. `-foo` as a flag, which
  can be avoided by passing `./-foo`

Rather than detecting these two cases, just always include the prefix;
there's no harm in it.

Also, if the cwd is specified, include it in the manifest. If the user
has set the cwd of a Run step, it is clearly because this affects the
behavior of the executable somehow, so that cwd path should be a part of
the step's manifest.

Resolves: #24216
2025-06-18 22:45:05 +01:00
Jonathan Marler
f3940ad858 windows: MSVC: disable extra dubious Microsoft runtime checks
Cmake by default adds the `/RTC1` compiler flag for debug builds.
However, this causes C code that conforms to the C standard and has
well-defined behavior to trap. Here I've updated CMAKE to use the more
lenient `/RTCs` by default which removes the uninitialized variable checks
but keeps the stack error checks.
2025-06-18 16:41:25 +02:00
Pat Tullmann
cfe5defd02 linux: futex v1 API cleanup
* Use `packed struct` for flags arguments.  So, instead of
  `linux.FUTEX.WAIT` use `.{ .cmd = .WAIT, .private = true }`

* rename `futex_wait` and `futex_wake` which didn't actually specify
  wait/wake, as `futex_3arg` and `futex_4arg` (as its the number
  of parameters that is different, the `op` is whatever is specified.

* expose the full six-arg flavor of the syscall (for some of the advanced
  ops), and add packed structs for their arguments.

* Use a `packed union` to support the 4th parameter which is sometimes a
  `timespec` pointer, and sometimes a `u32`.

* Add tests that make sure the structure layout is correct and that the
  basic argument passing is working (no actual futexes are contended).
2025-06-17 22:06:39 -07:00
Matthew Lugg
850655f06b
Merge pull request #24205 from mlugg/misc-build-stuff
`std.Build`: some miscelleanous bits
2025-06-17 19:58:10 +01:00
mlugg
8aab222ffb Compilation: add missing link file options to cache manifest
Also add a standalone test which covers the `-fentry` case. It does this
by performing two reproducible compilations which are identical other
than having different entry points, and checking whether the emitted
binaries are identical (they should *not* be).

Resolves: #23869
2025-06-17 15:33:50 +01:00
mlugg
f3c0555975
std.Build: introduce ConfigHeader.getOutputDir, small refactor
`std.Build.Step.ConfigHeader` emits a *directory* containing a config
header under a given sub path, but there's no good way to actually
access that directory as a `LazyPath` in the configure phase. This is
silly; it's perfectly valid to refer to that directory, perhaps to
explicitly pass as a "-I" flag to a different toolchain invoked via a
`Step.Run`. So now, instead of the `GeneratedFile` being the actual
*file*, it should be that *directory*, i.e. `cache/o/<digest>`. We can
then easily get the *file* if needed just by using `LazyPath.path` to go
"deeper", which there is a helper function for.

The legacy `getOutput` function is now a deprecated alias for
`getOutputFile`, and `getOutputDir` is introduced.

`std.Build.Module.IncludeDir.appendZigProcessFlags` needed a fix after
this change, so I took the opportunity to refactor it a little. I was
looking at this function while working on ziglang/translate-c yesterday
and realised it could be expressed much more simply -- particularly
after the `ConfigHeader` change here.

I had to update the test `standalone/cmakedefine/` -- it turns out this
test was well and truly reaching into build system internals, and doing
horrible not-really-allowed stuff like overriding the `makeFn` of a
`TopLevelStep`. To top it all off, the test forgot to set
`b.default_step` to its "test" step, so the test never even ran. I've
refactored it to follow accepted practices and to actually, like, work.
2025-06-17 11:55:36 +01:00
mlugg
a92427bf27
Build.Cache.Path: fix resolvePosix empty sub_path
This function is sometimes used to assume a canonical representation of
a path. However, when the `Path` referred to `root_dir` itself, this
function previously resolved `sub_path` to ".", which is incorrect; per
doc comments, it should set `sub_path` to "".

This fix ultimately didn't solve what I was trying to solve, though I'm
still PRing it, because it's still *correct*. The background to this
commit is quite interesting and worth briefly discussing.

I originally worked on this to try and fix a bug in the build system,
where if the root package (i.e. the one you `zig build`) depends on
package X which itself depends back on the root package (through a
`.path` dependency), invalid dependency modules are generated. I hit
this case working on ziglang/translate-c, which wants to depend on
"examples" (similar to the Zig compiler's "standalone" test cases) which
themselves depend back on the translate-c package. However, after this
patch just turned that error into another, I realised that this case
simply cannot work, because `std.Build` needs to eagerly execute build
scripts at `dependency` calls to learn which artifacts, modules, etc,
exist.

...at least, that's how the build system is currently designed. One can
imagine a world where `dependency` sort of "queues" the call, `artifact`
and `module` etc just pretend that the thing exists, and all configure
functions are called non-recursively by the runner. The downside is that
it becomes impossible to query state set by a dependency's configure
script. For instance, if a dependency exposes an artifact, it would
become impossible to get that artifact's resolved target in the
configure phase. However, as well as allowing recursive package imports
(which are certainly kinda nifty), it would also make lazy dependencies
far more useful! Right now, lazy dependencies only really work if you
use options (`std.Build.option`) to block their usage, since any call to
`lazyDependency` causes the dependency to be fetched. However, if we
made this change, lazy dependencies could be made far more versatile by
only fetching them *if the final step plan requires them*. I'm not 100%
sure if this is a good idea or not, but I might open an issue for it
soon.
2025-06-17 11:06:39 +01:00
Matthew Lugg
561fdd0ed3
Merge pull request #24188 from mlugg/intfromfloat-safety
Absorb std.math.big.rational logic into std.math.big.int; fix `@intFromFloat` safety check
2025-06-17 11:02:03 +01:00
Alex Rønne Petersen
080ee25ecf
Merge pull request #24192 from alichraghi/fix_spirv
rename spirv backend name
2025-06-16 16:47:00 +02:00
Alex Rønne Petersen
5f7780c533 compiler-rt: Export _fltused for UEFI.
Closes #24148.
2025-06-16 13:46:23 +02:00
Ali Cheraghi
872f68c9cb
rename spirv backend name
`stage2_spirv64` -> `stage2_spirv`
2025-06-16 13:22:19 +03:30
Ali Cheraghi
c126d6554f
build: add spirv to dev env 2025-06-16 01:09:07 +03:30
mlugg
e498d8da3c
std: disable test on LLVM (#24191) 2025-06-15 22:15:06 +01:00
mlugg
d90068db5a Sema: tiny refactor
There will be more call sites to `preparePanicId` as we transition away
from safety checks in Sema towards safety checked instructions; it's
silly for them to all have this clunky usage.
2025-06-15 14:15:18 -04:00
mlugg
6ffa285fc3 compiler: fix @intFromFloat safety check
This safety check was completely broken; it triggered unchecked illegal
behavior *in order to implement the safety check*. You definitely can't
do that! Instead, we must explicitly check the boundaries. This is a
tiny bit fiddly, because we need to make sure we do floating-point
rounding in the correct direction, and also handle the fact that the
operation truncates so the boundary works differently for min vs max.

Instead of implementing this safety check in Sema, there are now
dedicated AIR instructions for safety-checked intfromfloat (two
instructions; which one is used depends on the float mode). Currently,
no backend directly implements them; instead, a `Legalize.Feature` is
added which expands the safety check, and this feature is enabled for
all backends we currently test, including the LLVM backend.

The `u0` case is still handled in Sema, because Sema needs to check for
that anyway due to the comptime-known result. The old safety check here
was also completely broken and has therefore been rewritten. In that
case, we just check for 'abs(input) < 1.0'.

I've added a bunch of test coverage for the boundary cases of
`@intFromFloat`, both for successes (in `test/behavior/cast.zig`) and
failures (in `test/cases/safety/`).

Resolves: #24161
2025-06-15 14:15:18 -04:00
Jacob Young
6b41beb370 big.int: implement float conversions
These conversion routines accept a `round` argument to control how the
result is rounded and return whether the result is exact. Most callers
wanted this functionality and had hacks around it being missing.

Also delete `std.math.big.rational` because it was only being used for
float conversion, and using rationals for that is a lot more complex
than necessary. It also required an allocator, whereas the new integer
routines only need to be passed enough memory to store the result.
2025-06-15 14:15:18 -04:00
Jacob Young
13392ad33f stage1: update zig1.wasm
Compiler needs a subset of the legalization features enabled.
2025-06-15 11:55:57 -04:00
Jacob Young
6e72026e3b Legalize: make the feature set comptime-known in zig1
This allows legalizations to be added that aren't used by zig1 without
affecting the size of zig1.
2025-06-15 11:42:03 -04:00
Alex Rønne Petersen
1ca213dab0
Merge pull request #24168 from mlugg/relative-paths
std.Build: fix relative path bugs
2025-06-15 15:01:06 +02:00
Koki Ueha
878b7b80c1 libc: Prevent FCSEL instruction from being used to avoid raising an unintended exception
If you write an if expression in mem.doNotOptimizeAway like
doNotOptimizeAway(if (ix < 0x00100000) x / 0x1p120 else x + 0x1p120);,
FCSEL instruction is used on AArch64.
FCSEL instruction selects one of the two registers according to
the condition and copies its value.
In this example, `x / 0x1p120` and `x + 0x1p120` are expressions
that raise different floating-point exceptions.
However, since both are actually evaluated before the FCSEL
instruction, the exception not intended by the programmer may
also be raised.

To prevent FCSEL instruction from being used here, this commit
splits doNotOptimizeAway in two.
2025-06-15 04:01:43 -04:00
Jacob Young
3ce8d19f76 llvm.ir: fix subrange version
Closes #23898
2025-06-13 21:23:41 -04:00
Matthew Lugg
095c956c5c
Merge pull request #24171 from mlugg/atomic-order-derp
compiler: fix races in link queue
2025-06-14 02:10:20 +01:00
Loris Cro
180e8442af
zig init: simplify templating logic (#24170)
and also rename `advancedPrint` to `bufferedPrint` in the zig init templates

These are left overs from my previous changes to zig init.

The new templating system removes LITNAME because the new restrictions on package names make it redundant with NAME, and the use of underscores for marking templated identifiers lets us template variable names while still keeping zig fmt happy.
2025-06-13 22:31:29 +00:00
mlugg
55b7187429
link: fix obvious race condition
Did you know that allocators reuse addresses? If not, then don't feel
bad, because apparently I don't either! This dumb mistake was probably
responsible for the CI failures on `master` yesterday.
2025-06-13 22:05:03 +01:00
mlugg
121d620443
compiler: fix atomic orderings
I messed up atomic orderings on this variable because they changed in a
local refactor at some point. We need to always release on the store and
acquire on the loads so that a linker thread observing `.ready` sees the
stored MIR.
2025-06-13 19:05:44 +01:00
xdBronch
a74119ac49 bail when failing to parse error 2025-06-13 18:44:53 +01:00
mlugg
14e033ed95
std.Build.Step.Run: convert relative paths to be relative to child cwd
Because any `LazyPath` might be resolved to a relative path, it's
incorrect to pass that directly to a child process whose cwd might
differ. Instead, if the child has an overriden cwd, we need to convert
such paths to be relative to the child cwd using `std.fs.path.relative`.
2025-06-13 16:30:39 +01:00
mlugg
5c8b92db7f
tests: do not require absolute paths from the build system
File arguments added to `std.Build.Step.Run` with e.g. `addFileArg` are
not necessarily passed as absolute paths. It used to be the case that
they were as a consequence of an unnecessary path conversion done by the
frontend, but this no longer happens, at least not always, so these
tests were sometimes failing when run locally. Therefore, the standalone
tests must handle cwd-relative CLI paths correctly.
2025-06-13 15:46:43 +01:00
Andrew Kelley
dd75e7bcb1 Sema: add missing error and test for bool not on vector of ints 2025-06-13 05:59:25 -04:00
Andrew Kelley
dcdb4422b8
Merge pull request #24124 from mlugg/better-backend-pipeline-2
compiler: threaded codegen (and more goodies)
2025-06-12 20:46:36 -04:00
Daniel Kongsgaard
5e3c0b7af7
Allow more operators on bool vectors (#24131)
* Sema: allow binary operations and boolean not on vectors of bool

* langref: Clarify use of operators on vectors (`and` and `or` not allowed)

closes #24093
2025-06-12 15:16:23 -07:00
mlugg
43d01ff69f
x86_64.Lower: replace slow stringToEnum call
Looking at a compilation of 'test/behavior/x86_64/unary.zig' in
callgrind showed that a full 30% of the compiler runtime was spent in
this `stringToEnum` call, so optimizing it was low-hanging fruit.

We tried replacing it with nested `switch` statements using
`inline else`, but that generated too much code; it didn't emit huge
binaries or anything, but LLVM used a *ridiculous* amount of memory
compiling it in some cases. The core problem here is that only a small
subset of the cases are actually used (the rest fell through to an
"error" path), but that subset is computed at comptime, so we must rely
on the optimizer to eliminate the thousands of redundant cases. This
would be solved by #21507.

Instead, we pre-compute a lookup table at comptime. This table is pretty
big (I guess a couple hundred k?), but only the "valid" subset of
entries will be accessed in practice (unless a bug in the backend is
hit), so it's not too awful on the cache; and it performs much better
than the old `std.meta.stringToEnum` call.
2025-06-12 18:40:01 +01:00
mlugg
71baa5e769
compiler: improve progress output
Update the estimated total items for the codegen and link progress nodes
earlier. Rather than waiting for the main thread to dispatch the tasks,
we can add the item to the estimated total as soon as we queue the main
task. The only difference is we need to complete it even in error cases.
2025-06-12 17:51:31 +01:00
mlugg
5bb5aaf932
compiler: don't queue too much AIR/MIR
Without this cap, unlucky scheduling and/or details of what pipeline
stages perform best on the host machine could cause many gigabytes of
MIR to be stuck in the queue. At a certain point, pause the main thread
until some of the functions in flight have been processed.
2025-06-12 17:51:31 +01:00
mlugg
f9a670d46d
Compilation: prevent zig1 depending on fd_readdir
This isn't really coherent to model as a `Feature`; this makes sense
because of zig1's specific environment. As such, I opted to check
`dev.env` directly.
2025-06-12 17:51:31 +01:00
mlugg
de69d63175
stage1: elaborate on "unimplemented" in wasi.c 2025-06-12 17:51:30 +01:00
mlugg
d7afd797cc
Zcu: handle unreferenced test_functions correctly
Previously, `PerThread.populateTestFunctions` was analyzing the
`test_functions` declaration if it hadn't already been analyzed, so that
it could then populate it. However, the logic for doing this wasn't
actually correct, because it didn't trigger the necessary type
resolution. I could have tried to fix this, but there's actually a
simpler solution! If the `test_functions` declaration isn't referenced
or has a compile error, then we simply don't need to update it; either
it's unreferenced so its value doesn't matter, or we're going to get a
compile error anyway. Either way, we can just give up early. This avoids
doing semantic analysis after `performAllTheWork` finishes.

Also, get rid of the "Code Generation" progress node while updating the
test decl: this is a linking task.
2025-06-12 17:51:30 +01:00
Jacob Young
4d2b216121
test-stack-traces: correct expected object file name
The name of the ZCU object file emitted by the LLVM backend has been
changed in this branch from e.g. `foo.obj` to `foo_zcu.obj`. This is to
avoid name clashes. This commit just updates the stack trace tests which
started failing on windows because of the object name change.
2025-06-12 17:51:30 +01:00
mlugg
ff89a98c50
link.Queue: release safety lock before releasing mutex after stopping 2025-06-12 17:51:30 +01:00
mlugg
1b27369acb
cli: correctly error for missing output directories 2025-06-12 17:51:30 +01:00
mlugg
7f2f107a1e
Zcu: SPIR-V also doesn't generate MIR (yet) 2025-06-12 17:51:30 +01:00
mlugg
22e961070d
link: fix goff and xcoff flush 2025-06-12 17:51:30 +01:00
Jacob Young
afa07f723f
x86_64: implement coff relocations 2025-06-12 17:51:30 +01:00
Jacob Young
746137034e
Sema: fix union layout logic to match struct layout logic 2025-06-12 17:51:30 +01:00
Jacob Young
d312dfc1f2
codegen: make threadlocal logic consistent 2025-06-12 17:51:29 +01:00
Jacob Young
56119699bf
x86_64: fix dbg_var_ptr types in debug info 2025-06-12 17:51:29 +01:00
mlugg
a3abaaee0c
test-link: correct expected object file name
The name of the ZCU object file emitted by the LLVM backend has been
changed in this branch from e.g. `foo.o` to `foo_zcu.o`. This is to
avoid name clashes. This commit just updates a link test which started
failing because the object name in a linker error changed.
2025-06-12 17:51:29 +01:00
mlugg
89a6c732e5
Zcu: fix deleteExport crash with LLVM backend 2025-06-12 17:51:29 +01:00
mlugg
e28b699cbf
libs: fix caching behavior
glibc, freebsd, and netbsd all do caching manually, because of the fact
that they emit multiple files which they want to cache as a block.
Therefore, the individual sub-compilation on a cache miss should be
using `CacheMode.none` so that we can specify the output paths for each
sub-compilation as being in the shared output directory.
2025-06-12 17:51:29 +01:00
mlugg
ac745edbbd
compiler: estimate totals for "Code Generation" and "Linking" progress nodes 2025-06-12 13:55:41 +01:00
mlugg
db5d85b8c8
compiler: improve progress output
* "Flush" nodes ("LLVM Emit Object", "ELF Flush") appear under "Linking"

* "Code Generation" disappears when all analysis and codegen is done

* We only show one node under "Semantic Analysis" to accurately convey
  that analysis isn't happening in parallel, but rather that we're
  pausing one task to do another
2025-06-12 13:55:41 +01:00
Jacob Young
ba53b14028
x86_64: remove linker references from codegen 2025-06-12 13:55:41 +01:00
Jacob Young
c95b1bf2d3
x86_64: remove air references from mir 2025-06-12 13:55:41 +01:00
mlugg
c4ec382fc8
InternPool: store the Nav types are named after
When the name strategy is `.parent`, the DWARF info really wants to know
what `Nav` we were named after to emit a more optimal hierarchy.
2025-06-12 13:55:41 +01:00
Jacob Young
580d622b0d
Zcu: fix verbose air 2025-06-12 13:55:41 +01:00
mlugg
d24af29742
CMakeLists: update file list 2025-06-12 13:55:41 +01:00
mlugg
b5f73f8a7b
compiler: rework emit paths and cache modes
Previously, various doc comments heavily disagreed with the
implementation on both what lives where on the filesystem at what time,
and how that was represented in code. Notably, the combination of emit
paths outside the cache and `disable_lld_caching` created a kind of
ad-hoc "cache disable" mechanism -- which didn't actually *work* very
well, 'most everything still ended up in this cache. There was also a
long-standing issue where building using the LLVM backend would put a
random object file in your cwd.

This commit reworks how emit paths are specified in
`Compilation.CreateOptions`, how they are represented internally, and
how the cache usage is specified.

There are now 3 options for `Compilation.CacheMode`:
* `.none`: do not use the cache. The paths we have to emit to are
  relative to the compiler cwd (they're either user-specified, or
  defaults inferred from the root name). If we create any temporary
  files (e.g. the ZCU object when using the LLVM backend) they are
  emitted to a directory in `local_cache/tmp/`, which is deleted once
  the update finishes.
* `.whole`: cache the compilation based on all inputs, including file
  contents. All emit paths are computed by the compiler (and will be
  stored as relative to the local cache directory); it is a CLI error to
  specify an explicit emit path. Artifacts (including temporary files)
  are written to a directory under `local_cache/tmp/`, which is later
  renamed to an appropriate `local_cache/o/`. The caller (who is using
  `--listen`; e.g. the build system) learns the name of this directory,
  and can get the artifacts from it.
* `.incremental`: similar to `.whole`, but Zig source file contents, and
  anything else which incremental compilation can handle changes for, is
  not included in the cache manifest. We don't need to do the dance
  where the output directory is initially in `tmp/`, because our digest
  is computed entirely from CLI inputs.

To be clear, the difference between `CacheMode.whole` and
`CacheMode.incremental` is unchanged. `CacheMode.none` is new
(previously it was sort of poorly imitated with `CacheMode.whole`). The
defined behavior for temporary/intermediate files is new.

`.none` is used for direct CLI invocations like `zig build-exe foo.zig`.
The other cache modes are reserved for `--listen`, and the cache mode in
use is currently just based on the presence of the `-fincremental` flag.

There are two cases in which `CacheMode.whole` is used despite there
being no `--listen` flag: `zig test` and `zig run`. Unless an explicit
`-femit-bin=xxx` argument is passed on the CLI, these subcommands will
use `CacheMode.whole`, so that they can put the output somewhere without
polluting the cwd (plus, caching is potentially more useful for direct
usage of these subcommands).

Users of `--listen` (such as the build system) can now use
`std.zig.EmitArtifact.cacheName` to find out what an output will be
named. This avoids having to synchronize logic between the compiler and
all users of `--listen`.
2025-06-12 13:55:40 +01:00
mlugg
808c15dd39
link.Lld: remove dead caching logic
It turns out that LLD caching hasn't been in use for a while. On master,
it is currently only enabled when you compile via the build system,
passing `-fincremental`, using LLD (and so LLVM if there's a ZCU). That
case never happens, because `-fincremental` is only useful when you're
using a backend *other* than the LLVM backend. My previous commits
accidentally re-enabled this logic in some cases, exposing bugs; that
ultimately led to this realisation. So, let's just delete that logic --
less LLVM-related cruft to maintain.
2025-06-12 13:55:40 +01:00
mlugg
89ba885970
spirv: make the backend compile again
Unfortunately, the self-hosted SPIR-V backend is quite tightly coupled
with the self-hosted SPIR-V linker through its `Object` concept (which
is much like `llvm.Object`). Reworking this would be too much work for
this branch. So, for now, I have introduced a special case (similar to
the LLVM backend's special case) to the codegen logic when using this
backend. We will want to delete this special case at some point, but it
need not block this work.
2025-06-12 13:55:40 +01:00
mlugg
c0df707066
wasm: get self-hosted compiling, and supporting separate_thread
My original goal here was just to get the self-hosted Wasm backend
compiling again after the pipeline change, but it turned out that from
there it was pretty simple to entirely eliminate the shared state
between `codegen.wasm` and `link.Wasm`. As such, this commit not only
fixes the backend, but makes it the second backend (after CBE) to
support the new 1:N:1 threading model.
2025-06-12 13:55:40 +01:00
mlugg
5ab307cf47
compiler: get most backends compiling again
As of this commit, every backend other than self-hosted Wasm and
self-hosted SPIR-V compiles and (at least somewhat) functions again.
Those two backends are currently disabled with panics.

Note that `Zcu.Feature.separate_thread` is *not* enabled for the fixed
backends. Avoiding linker references from codegen is a non-trivial task,
and can be done after this branch.
2025-06-12 13:55:40 +01:00
mlugg
9eb400ef19
compiler: rework backend pipeline to separate codegen and link
The idea here is that instead of the linker calling into codegen,
instead codegen should run before we touch the linker, and after MIR is
produced, it is sent to the linker. Aside from simplifying the call
graph (by preventing N linkers from each calling into M codegen
backends!), this has the huge benefit that it is possible to
parallellize codegen separately from linking. The threading model can
look like this:

* 1 semantic analysis thread, which generates AIR
* N codegen threads, which process AIR into MIR
* 1 linker thread, which emits MIR to the binary

The codegen threads are also responsible for `Air.Legalize` and
`Air.Liveness`; it's more efficient to do this work here instead of
blocking the main thread for this trivially parallel task.

I have repurposed the `Zcu.Feature.separate_thread` backend feature to
indicate support for this 1:N:1 threading pattern. This commit makes the
C backend support this feature, since it was relatively easy to divorce
from `link.C`: it just required eliminating some shared buffers. Other
backends don't currently support this feature. In fact, they don't even
compile -- the next few commits will fix them back up.
2025-06-12 13:55:40 +01:00
mlugg
66d15d9d09
link: make checking for failed types the responsibility of Compilation 2025-06-12 13:55:40 +01:00
mlugg
2fb6f5c1ad
link: divorce LLD from the self-hosted linkers
Similar to the previous commit, this commit untangles LLD integration
from the self-hosted linkers. Despite the big network of functions which
were involved, it turns out what was going on here is quite simple. The
LLD linking logic is actually very self-contained; it requires a few
flags from the `link.File.OpenOptions`, but that's really about it. We
don't need any of the mutable state on `Elf`/`Coff`/`Wasm`, for
instance. There was some legacy code trying to handle support for using
self-hosted codegen with LLD, but that's not a supported use case, so
I've just stripped it out.

For now, I've just pasted the logic for linking the 3 targets we
currently support using LLD for into this new linker implementation,
`link.Lld`; however, it's almost certainly possible to combine some of
the logic and simplify this file a bit. But to be honest, it's not
actually that bad right now.

This commit ends up eliminating the distinction between `flush` and
`flushZcu` (formerly `flushModule`) in linkers, where the latter
previously meant something along the lines of "flush, but if you're
going to be linking with LLD, just flush the ZCU object file, don't
actually link"?. The distinction here doesn't seem like it was properly
defined, and most linkers seem to treat them as essentially identical
anyway. Regardless, all calls to `flushZcu` are gone now, so it's
deleted -- one `flush` to rule them all!

The end result of this commit and the preceding one is that LLVM and LLD
fit into the pipeline much more sanely:

* If we're using LLVM for the ZCU, that state is on `zcu.llvm_object`
* If we're using LLD to link, then the `link.File` is a `link.Lld`
* Calls to "ZCU link functions" (e.g. `updateNav`) lower to calls to the
  LLVM object if it's available, or otherwise to the `link.File` if it's
  available (neither is available under `-fno-emit-bin`)
* After everything is done, linking is finalized by calling `flush` on
  the `link.File`; for `link.Lld` this invokes LLD, for other linkers it
  flushes self-hosted linker state

There's one messy thing remaining, and that's how self-hosted function
codegen in a ZCU works; right now, we process AIR with a call sequence
something like this:

* `link.doTask`
* `Zcu.PerThread.linkerUpdateFunc`
* `link.File.updateFunc`
* `link.Elf.updateFunc`
* `link.Elf.ZigObject.updateFunc`
* `codegen.generateFunction`
* `arch.x86_64.CodeGen.generate`

So, we start in the linker, take a scenic detour through `Zcu`, go back
to the linker, into its implementation, and then... right back out, into
code which is generic over the linker implementation, and then dispatch
on the *backend* instead! Of course, within `arch.x86_64.CodeGen`, there
are some more places which switch on the `link` implementation being
used. This is all pretty silly... so it shall be my next target.
2025-06-12 13:55:39 +01:00
mlugg
3743c3e39c
compiler: slightly untangle LLVM from the linkers
The main goal of this commit is to make it easier to decouple codegen
from the linkers by being able to do LLVM codegen without going through
the `link.File`; however, this ended up being a nice refactor anyway.

Previously, every linker stored an optional `llvm.Object`, which was
populated when using LLVM for the ZCU *and* linking an output binary;
and `Zcu` also stored an optional `llvm.Object`, which was used only
when we needed LLVM for the ZCU (e.g. for `-femit-llvm-bc`) but were not
emitting a binary.

This situation was incredibly silly. It meant there were N+1 places the
LLVM object might be instead of just 1, and it meant that every linker
had to start a bunch of methods by checking for an LLVM object, and just
dispatching to the corresponding method on *it* instead if it was not
`null`.

Instead, we now always store the LLVM object on the `Zcu` -- which makes
sense, because it corresponds to the object emitted by, well, the Zig
Compilation Unit! The linkers now mostly don't make reference to LLVM.
`Compilation` makes sure to emit the LLVM object if necessary before
calling `flush`, so it is ready for the linker. Also, all of the
`link.File` methods which act on the ZCU -- like `updateNav` -- now
check for the LLVM object in `link.zig` instead of in every single
individual linker implementation. Notably, the change to LLVM emit
improves this rather ludicrous call chain in the `-fllvm -flld` case:

* Compilation.flush
* link.File.flush
* link.Elf.flush
* link.Elf.linkWithLLD
* link.Elf.flushModule
* link.emitLlvmObject
* Compilation.emitLlvmObject
* llvm.Object.emit

Replacing it with this one:

* Compilation.flush
* llvm.Object.emit

...although we do currently still end up in `link.Elf.linkWithLLD` to do
the actual linking. The logic for invoking LLD should probably also be
unified at least somewhat; I haven't done that in this commit.
2025-06-12 13:55:39 +01:00
mlugg
424e6ac54b
compiler: minor refactors to ZCU linking
* The `codegen_nav`, `codegen_func`, `codegen_type` tasks are renamed to
  `link_nav`, `link_func`, and `link_type`, to more accurately reflect
  their purpose of sending data to the *linker*. Currently, `link_func`
  remains responsible for codegen; this will change in an upcoming
  commit.

* Don't go on a pointless detour through `PerThread` when linking ZCU
  functions/`Nav`s; so, the `linkerUpdateNav` etc logic now lives in
  `link.zig`. Currently, `linkerUpdateFunc` is an exception, because it
  has broader responsibilities including codegen, but this will be
  solved in an upcoming commit.
2025-06-12 13:55:39 +01:00
Alex Rønne Petersen
4a02e080d1
Merge pull request #23912 from alexrp/mingw-update
`mingw`: Update MinGW-w64 to 38c8142f660b6ba11e7c408f2de1e9f8bfaf839e.
2025-06-12 02:51:36 +02:00
Danielkonge
f4c7290bc5 test: Enable some working vector tests
Closes #12827.
2025-06-11 22:29:51 +02:00
Alex Rønne Petersen
78d6f1c56a
mingw: Fix def file preprocessing.
This needs to actually set the target on the aro.Compilation so that we get the
expected target-specific preprocessor macros defined.
2025-06-11 20:10:15 +02:00
Alex Rønne Petersen
5e2b025f69
zig_llvm: Strip @<n> suffix from .def symbols on all targets.
We have to do this because upstream MinGW-w64 now has symbols in lib-common/
which are unconditionally decorated with @<n>.
2025-06-11 18:27:17 +02:00
Alex Rønne Petersen
879bc2e5cb
mingw: Update MinGW-w64 sources to 38c8142f660b6ba11e7c408f2de1e9f8bfaf839e. 2025-06-11 18:27:15 +02:00
Alex Rønne Petersen
0979e56bd2
mingw: Update MinGW-w64 headers to 38c8142f660b6ba11e7c408f2de1e9f8bfaf839e. 2025-06-11 15:28:36 +02:00
Alex Rønne Petersen
6671442a7c
mingw: Update MinGW-w64 definitions to 38c8142f660b6ba11e7c408f2de1e9f8bfaf839e. 2025-06-11 15:28:36 +02:00
Alex Rønne Petersen
6810ffa424
Merge pull request #24031 from ypsvlq/master
Haiku fixes
2025-06-10 17:54:19 +02:00
Andrew Kelley
4d79806459 std.Build.Step.Run: add addDecoratedDirectoryArg function
For directory arguments that need both prefix and suffix strings
appended.

Needed to unbreak ffmpeg package after fe855691f6f742a14678cb617422977c2a55be39
2025-06-09 05:25:30 -04:00
Marc Tiehuis
cffa98eef5 std.fmt.parseFloat: fix hex-float negative inf
Closes #24111.
2025-06-08 17:57:37 -04:00
Alex Rønne Petersen
201c0f54a5
Merge pull request #24117 from ziglang/cmake-arm
cmake: Fix arm/thumb arch checks
2025-06-08 09:22:55 +02:00
Alex Rønne Petersen
44155eb93c
cmake: Simplify some arm/thumb checks.
I'm not convinced that some of the possibilities that these regexes allowed are real. I've literally never seen or heard of "armhfel", nor of "thumb" ever showing up in `uname -m`, etc.
2025-06-07 22:24:09 +02:00
Alex Rønne Petersen
06d50d046a
cmake: Fix arm/thumb arch checks
Closes #24114.
2025-06-07 22:12:03 +02:00
Andrew Kelley
2e31544285 seriously don't put internpool indexes in test cases 2025-06-07 12:42:03 -07:00
Andrew Kelley
f088bb0d6e don't put intern pool indexes in test cases 2025-06-07 12:29:51 -07:00
PlayDay
3208c80f2b fix: MIME for ZIP in Zig Fetch
Closes: #24098
2025-06-07 13:14:52 -04:00
Jacob Young
857cd172d6 Dwarf: restore missing non-entry padding
Sections without padding were only supposed to omit entry padding.
Otherwise, the allocation behavior is degenerate.
2025-06-07 13:13:47 -04:00
Andrew Kelley
8b875b17ad
Merge pull request #24072 from jacobly0/x86_64-default
Compilation: enable the x86_64 backend by default for debug builds
2025-06-07 13:08:22 -04:00
Alex Kladov
173bc42744
langref: undefined _is_ materialized in all safe modes (#24107)
* trailing whitespace

* langref: undefined _is_ materialized in all safe modes

I am also not super happy about the clause that immediately follows. I
_believe_ what we want to say here is that, simultaneously:

* undefined is guaranteed to be matrerialized in in all safe modes.
  A Zig implementation that elides `ptr.* = undefined` in ReleaseSafe
  mode would be a non-conforming implementation.
* A Zig program that relies on undefined being materialized is buggy.

But I don't think it's the time to engage this level of language-lawering!
2025-06-07 10:07:53 -07:00
mlugg
aa65fd5d7c cases: fix type names
A different merge must have changed these numbers before this PR was
merged, leading to CI failures.
2025-06-07 13:06:51 -04:00
Andrew Kelley
5a52da1b7a CI: skip llvm backend tests in the script for testing x86 backend 2025-06-06 23:42:15 -07:00
Andrew Kelley
125a9aa82b restore debug llvm CI coverage
and reduce redundant coverage in slow runs to save time
2025-06-06 23:42:15 -07:00
Jacob Young
37f763560b x86_64: fix switch dispatch bug
Also closes #23902
2025-06-06 23:42:15 -07:00
mlugg
f28ef7ee29 tests: extern threadlocals require LLVM
This is a current limitation of our self-hosted linkers.
2025-06-06 23:42:15 -07:00
mlugg
437059f37c tests: avoid loading 16 MiB onto the stack
Currently, Zig semantically loads an array as a temporary when indexing
it. This means it cannot be guaranteed that only the requested element
is loaded; in particular, our self-hosted backends do not elide the load
of the full array, so this test case was crashing on self-hosted.
2025-06-06 23:42:15 -07:00
Jacob Young
0bf8617d96 x86_64: add support for pie executables 2025-06-06 23:42:14 -07:00
Jacob Young
178ee8aef1 Sema: fix invalid pure Air instruction with comptime-known operands 2025-06-06 23:42:14 -07:00
Andrew Kelley
e19886a898 Compilation.Config: prefer_llvm depends on pie 2025-06-06 23:42:14 -07:00
Andrew Kelley
d6b1ff7533 Compilation.Config: eliminate the only variable from this function 2025-06-06 23:42:14 -07:00
Andrew Kelley
2387305b23 Compilation.Config: "can_use_llvm" -> "prefer_llvm" 2025-06-06 23:42:14 -07:00
Andrew Kelley
a59d18779f langref: global assembly test depends on llvm
see #24046
2025-06-06 23:42:14 -07:00
Jacob Young
5986bdf868 Compilation: enable the x86_64 backend by default for debug builds
Closes #22257
2025-06-06 23:42:14 -07:00
Andrew Kelley
e96d86064e
Merge pull request #24090 from fardragon/handle-empty-hash
zig build: Handle empty hashes in build.zig.zon
2025-06-06 22:48:09 -04:00
mlugg
38266c5035 AstGen: fix name strategy bugs
Representing this with a `GenZir` field is incredibly bug-prone.
Instead, just pass this data directly to the relevant expression in the
very few places which actually provide a name strategy.

Resolves: #22798
2025-06-06 22:04:51 +01:00
Gungun974
21a0885ae7 Make zig fetch handle jar like zip 2025-06-06 16:59:40 -04:00
Andrew Kelley
98646e5cf8
Merge pull request #24094 from jacobly0/x86_64-ld-scripts
link: support static archives that are linker scripts
2025-06-06 16:25:17 -04:00
Andrew Kelley
bc3ce4b971 hash mismatch error: don't make empty such a special case
we can more simply use quotes instead
2025-06-06 11:16:44 -07:00
Andrew Kelley
8f7fc63847 Package.Hash.toSlice: consistent pointer
Makes the returned pointer always point inside `Hash.bytes` even when it
is length zero.
2025-06-06 11:13:36 -07:00
fardragon
3c151f0b1c Handle empty hashes in build.zig.zon 2025-06-06 11:11:49 -07:00
Alex Rønne Petersen
b6d9046242 libcxx: Fix locale-related compilation errors on NetBSD.
llvm/llvm-project#143055
2025-06-06 11:22:20 +02:00
Jacob Young
bcf387f0b9 Elf: support non-comdat groups
I haven't actually found any documentation about these, but apparently groups
aren't always comdats.
2025-06-06 00:45:37 -04:00
Jacob Young
25da0f8372 link: support static archives that are linker scripts
Note that `openLoadArchive` already has linker script support.

With this change I get a failure parsing a real archive in the self
hosted elf linker, rather than the previous behavior of getting an error
while trying to parse a pseudo archive that is actually a load script.
2025-06-06 00:04:19 -04:00
Alex Rønne Petersen
98cf81d51c test: Expand target coverage for C ABI tests. 2025-06-05 21:50:56 +02:00
Elaine Gibson
7f73187004 std.fs.Dir: haiku fixes 2025-06-05 13:45:52 +01:00
Elaine Gibson
ed48e2eb75 std.crypto.Certificate.Bundle: haiku support 2025-06-05 13:45:52 +01:00
Elaine Gibson
2e5b3b5c7c build runner: disable fuzz in single-threaded builds 2025-06-05 13:45:52 +01:00
Elaine Gibson
2cfa0f567d std.Build.Watch: not supported on haiku 2025-06-05 13:45:47 +01:00
Elaine Gibson
2139eb75f9 std.c: getcontext is not supported on haiku 2025-06-05 12:30:54 +01:00
Elaine Gibson
8910ac2ba8 std.c.SOCK: define NONBLOCK and CLOEXEC for haiku 2025-06-05 12:30:54 +01:00
Elaine Gibson
8cd56e7088 haiku: restore functions mistakenly removed in e8c4e79 2025-06-05 12:30:54 +01:00
Alex Rønne Petersen
adc4418bae std.fs.Dir.Iterator: Address a couple of alignment TODOs. 2025-06-05 07:17:40 +02:00
Alex Rønne Petersen
9d534790eb std.Target: Introduce Cpu convenience functions for feature tests.
Before:

* std.Target.arm.featureSetHas(target.cpu.features, .has_v7)
* std.Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx, .cmov })
* std.Target.wasm.featureSetHasAll(target.cpu.features, .{ .atomics, .bulk_memory })

After:

* target.cpu.has(.arm, .has_v7)
* target.cpu.hasAny(.x86, &.{ .sse, .avx, .cmov })
* target.cpu.hasAll(.wasm, &.{ .atomics, .bulk_memory })
2025-06-05 06:12:00 +02:00
Alex Rønne Petersen
14873f9a34
Merge pull request #24068 from alexrp/android-pic-pie
compiler: Rework PIE option logic.
2025-06-05 01:14:03 +02:00
Alex Rønne Petersen
80f2aeb8be ci: Bump x86_64-linux timeout from 8 hours to 9 hours.
The addition of FreeBSD and NetBSD targets to the test matrix in #24013 seems to
be causing timeouts under load. We might need to exclude some of those from CI,
but start by bumping the timeout so we can get a sense of how much more time is
actually needed.
2025-06-04 19:52:38 +02:00
Alex Rønne Petersen
2add31bfde valgrind: Add riscv64-linux support.
This appeared in Valgrind 3.25.0.
2025-06-04 19:24:08 +02:00
Andrew Kelley
100b76e17a std.Build.Step.Compile: clarify step name
In particular this makes it more obvious what step is compiling a unit
test versus which is running it.
2025-06-04 12:25:49 -04:00
Alex Rønne Petersen
bc8ace2a6d compiler-rt: Issue VALGRIND_DISCARD_TRANSLATIONS request in __clear_cache().
Closes #24030.
2025-06-04 13:25:21 +02:00
Alex Rønne Petersen
c8b92f3a8e
zig cc: Pass -f(no-)(PIC,PIE) to Clang for *-(windows,uefi)-(gnu,cygnus).
The previous supports_fpic() check was too broad.
2025-06-04 10:35:04 +02:00
Alex Rønne Petersen
c620836945
zig cc: Pass -f(no-)PIE to clang.
Otherwise we rely on Clang's default which is known to not always match ours.
2025-06-04 10:32:30 +02:00
Alex Rønne Petersen
0ccd2b0c5c
compiler: Always dynamically link executables for Fuchsia.
Fuchsia only supports PIE executables, specifically ET_DYN.

https://fuchsia.dev/fuchsia-src/concepts/process/program_loading
2025-06-04 06:54:10 +02:00
Alex Rønne Petersen
a81fb5fb76
compiler: Rework PIE option logic.
To my knowledge, the only platforms that actually *require* PIE are Fuchsia and
Android, and the latter *only* when building a dynamically-linked executable.
OpenBSD and macOS both strongly encourage using PIE by default, but it isn't
technically required. So for the latter platforms, we enable it by default but
don't enforce it.

Also, importantly, if we're building an object file or a static library, and the
user hasn't explicitly told us whether to build PIE or non-PIE code (and the
target doesn't require PIE), we should *not* default to PIE. Doing so produces
code that cannot be linked into non-PIE output. In other words, building an
object file or a static library as PIE is an optimization only to be done when
the user knows that it'll end up in a PIE executable in the end.

Closes #21837.
2025-06-04 06:48:19 +02:00
Alex Rønne Petersen
3b2bef8a95
Merge pull request #24025 from alexrp/glibc-deduplication
`libc`: Merge header directories for glibc and NetBSD libc where applicable
2025-06-04 05:14:21 +02:00
Alex Rønne Petersen
cd03a0a153 compiler: Don't link ucrtbased.dll when targeting *-windows-msvc in Debug mode.
Linking it by default means that we produce binaries that, effectively, only run
on systems which have the Windows SDK installed because ucrtbased.dll is not
redistributable, and the Windows SDK is what actually installs ucrtbased.dll
into %SYSTEM32%. The resulting binaries also can't run under Wine because Wine
does not provide ucrtbased.dll.

It is also inconsistent with our behavior for *-windows-gnu where we always link
ucrtbase.dll. See #23983, #24019, and #24053 for more details.

So just use ucrtbase.dll regardless of mode. With this change, we can also drop
the implicit definition of the _DEBUG macro in zig cc, which has in some cases
been problematic for users.

Users who want to opt into the old behavior can do so, both for *-windows-msvc
and *-windows-gnu, by explicitly passing -lucrtbased and -D_DEBUG. We might
consider adding a more ergonomic flag like -fdebug-crt to the zig build-* family
of commands in the future.

Closes #24052.
2025-06-04 05:04:29 +02:00
Andrew Kelley
826e1c30ba
Merge pull request #24013 from alexrp/test-matrix
More target coverage in the module test matrix
2025-06-03 17:05:15 -04:00
Jacob Young
80170d017b Legalize: handle packed semantics
Closes #22915
2025-06-03 15:04:43 -04:00
Andrew Kelley
597dd328e3
Merge pull request #24034 from papparapa/remove-musl-trigonometric-function
libc: replace musl's and MinGW's trigonometric functions with compiler_rt's
2025-06-03 02:54:36 -04:00
Jacob Young
2543e2d97c x86_64: implement integer @divFloor and @mod
Closes #24039
2025-06-02 22:45:15 -04:00
Alex Rønne Petersen
f4f4460e17
Merge pull request #23525 from alexrp/ci-max-rss
`std.Build`: Demote errors for exceeding `max_rss` to warnings.
2025-06-03 03:57:56 +02:00
Alex Rønne Petersen
87f8f47ba5
std.Build: Demote errors for exceeding max_rss to warnings.
We have no control over memory usage on arbitrary systems in the wild. But we
would still like to get the warnings so we can adjust the values based on
observations in the official ZSF CI.

Closes #23254.
Closes #23638.
2025-06-02 20:55:01 +02:00
Alex Rønne Petersen
e3b8aece4b
Revert "Allocate enough memory when building zig2"
This reverts commit 9356cb1475606a7afd2e722af60f87ce2b39f9f8.

https://github.com/ziglang/zig/pull/20514#issuecomment-2774509823
2025-06-02 20:33:36 +02:00
Super User
7bc3f294ce Added zig patch comments to annotate the deletion of the sincos symbol 2025-06-02 14:05:03 +00:00
Loris Cro
041eedc1cf zig init: appease zig fmt check
last commit introduced a templated variable name that made zig fmt angry
2025-06-02 15:42:21 +02:00
Loris Cro
1116d88196 zig init: add new --strip flag and improve template files
This commit introduces a new flag to generate a new Zig project using
`zig init` without comments for users who are already familiar with the
Zig build system.

Additionally, the generated files are now different. Previously we would
generate a set of files that defined a static library and an executable,
which real-life experience has shown to cause confusion to newcomers.

The new template generates one Zig module and one executable both in
order to accommodate the two most common use cases, but also to suggest
that a library could use a CLI tool (e.g. a parser library could use a
CLI tool that provides syntax checking) and vice-versa a CLI tool might
want to expose its core functionality as a Zig module.

All references to C interoperability are removed from the template under
the assumption that if you're tall enough to do C interop, you're also
tall enough to find your way around the build system. Experienced users
will still be able to use the current template and adapt it with minimal
changes in order to perform more advanced operations. As an example, one
only needs to change `b.addExecutable` to `b.addLibrary` to switch from
generating an executable to a dynamic (or static) library.
2025-06-02 13:13:56 +02:00
Ryan Liptak
8709326088 windows: Delete obsolete environment variable kernel32 wrappers and bindings
These functions have been unused for a long time (since cfffb9c5e96eeeae43cd724e2d02ec8c2b7714e0; the PEB is used for this stuff now), and the GetEnvironmentVariableW wrapper's parameter types don't make much sense to boot.

Contributes towards:
- https://github.com/ziglang/zig/issues/4426
- https://github.com/ziglang/zig/issues/1840
2025-06-02 10:34:37 +02:00
Alex Rønne Petersen
fa8073795a Revert "mingw: Link to ucrtbased.dll instead of API set DLLs in Debug mode."
This reverts commit 4641e9556d1343e95e4676e2f1e3024173db9962.

See discussion on #24052.
2025-06-02 08:06:37 +02:00
Jacob Young
8dbd29cc45
Merge pull request #24011 from jacobly0/legalize-unary
Legalize: implement scalarization and safety check expansion
2025-06-01 22:02:34 -04:00
Hilger Baumstark
0386730777
compiler-rt: add __addvsi3, __subvsi3, __mulvsi3, and __subvdi3 2025-06-01 20:17:25 +02:00
Jacob Young
6a63c8653a build: bump behavior max_rss 2025-06-01 11:58:58 -04:00
Koki Ueha
71ff3830df libc: replace MinGW's trigonometric functions with compiler_rt's
- sinf
- cosf
- sincos
- sincosf
- tanf
2025-06-01 11:25:51 +00:00
mlugg
fd72b38f68
std: remove old panic handlers after zig1.wasm update 2025-06-01 12:10:57 +01:00
Jacob Young
cc047fdd95
stage1: update zig1.wasm
Compiler needs cbe reserved identifier change. This also allows us to
delete the old `@intCast` panic handler declarations from the standard
library.
2025-06-01 12:10:57 +01:00
mlugg
493e37fa50
cases: include dirname in case names
For instance, the file 'cases/compile_errors/undeclared_identifier.zig'
now corresponds to test name 'compile_errors.undeclared_identifier'.
This is useful because you can now filter based on the case dirname
using `-Dtest-filter`.
2025-06-01 12:10:57 +01:00
mlugg
c1a5caa454
compiler: combine @intCast safety checks
`castTruncatedData` was a poorly worded error (all shrinking casts
"truncate bits", it's just that we assume those bits to be zext/sext of
the other bits!), and `negativeToUnsigned` was a pointless distinction
which forced the compiler to emit worse code (since two separate safety
checks were required for casting e.g. 'i32' to 'u16') and wasn't even
implemented correctly. This commit combines those safety panics into one
function, `integerOutOfBounds`. The name maybe isn't perfect, but that's
not hugely important; what matters is the new default message, which is
clearer than the old ones: "integer does not fit in destination type".
2025-06-01 12:10:57 +01:00
Jacob Young
6daa37ded9
x86_64: fix packed struct equality
Closes #22990
2025-06-01 08:24:01 +01:00
Jacob Young
9edfccb9a7
Legalize: implement scalarization of overflow intrinsics 2025-06-01 08:24:01 +01:00
Jacob Young
ec579aa0f3
Legalize: implement scalarization of @shuffle 2025-06-01 08:24:01 +01:00
mlugg
add2976a9b
compiler: implement better shuffle AIR
Runtime `@shuffle` has two cases which backends generally want to handle
differently for efficiency:

* One runtime vector operand; some result elements may be comptime-known
* Two runtime vector operands; some result elements may be undefined

The latter case happens if both vectors given to `@shuffle` are
runtime-known and they are both used (i.e. the mask refers to them).
Otherwise, if the result is not entirely comptime-known, we are in the
former case. `Sema` now diffentiates these two cases in the AIR so that
backends can easily handle them however they want to. Note that this
*doesn't* really involve Sema doing any more work than it would
otherwise need to, so there's not really a negative here!

Most existing backends have their lowerings for `@shuffle` migrated in
this commit. The LLVM backend uses new lowerings suggested by Jacob as
ones which it will handle effectively. The x86_64 backend has not yet
been migrated; for now there's a panic in there. Jacob will implement
that before this is merged anywhere.
2025-06-01 08:24:01 +01:00
Jacob Young
b48d6ff619
Legalize: implement scalarization of @select 2025-06-01 08:24:01 +01:00
Jacob Young
32a57bfeaa
Legalize: update for new Block API 2025-06-01 08:24:01 +01:00
Jacob Young
d9b6d1ed33
cbe: legalize safety instructions in non-zig1 builds
This is valid if the bootstrap dev env doesn't need to support runtime
safety.  Another solution can always be implemented if needs change.
2025-06-01 08:24:00 +01:00
mlugg
4c4dacf81a
Legalize: replace safety_checked_instructions
This adds 4 `Legalize.Feature`s:
* `expand_intcast_safe`
* `expand_add_safe`
* `expand_sub_safe`
* `expand_mul_safe`

These do pretty much what they say on the tin. This logic was previously
in Sema, used when `Zcu.Feature.safety_checked_instructions` was not
supported by the backend. That `Zcu.Feature` has been removed in favour
of this legalization.
2025-06-01 08:24:00 +01:00
Jacob Young
77e6513030 cbe: implement stdbool.h reserved identifiers
Also remove the legalize pass from zig1.
2025-05-31 18:54:28 -04:00
Jacob Young
6198f7afb7 Sema: remove all_vector_instructions logic
Backends can instead ask legalization on a per-instruction basis.
2025-05-31 18:54:28 -04:00
mlugg
b4a0a082dc codegen: fix accidental stack UAF 2025-05-31 18:54:28 -04:00
Jacob Young
b483defc5a Legalize: implement scalarization of binary operations 2025-05-31 18:54:28 -04:00
Jacob Young
c1e9ef9eaa Legalize: implement scalarization of unary operations 2025-05-31 18:54:28 -04:00
Linus Groh
c907866d55 libc: update macOS headers to SDK 15.5 2025-05-31 22:40:38 +02:00
Koki Ueha
21d9e03758 libc: replace musl's trigonometric functions with compiler_rt's
- sin
- sinf
- cos
- cosf
- sincos
- sincosf
- tan
- tanf
2025-05-30 15:32:52 +00:00
Alex Rønne Petersen
1a08c83eb3 ci: Revert aarch64-linux timeout to GitHub's default 6 hours.
We don't seem to be getting non-deterministic hangs since 4f3b59f, and e28b402
cut the run times significantly on top of that. Runs now seem to take around 1-2
hours, so the default timeout should be plenty.
2025-05-30 11:59:33 +02:00
Felix Rabe
561ab59cec
langref: Update calling convention (#24022)
* langref: Update calling convention

* Apply suggestions from code review

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>

* langref: Just use .winapi directly

---------

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>
2025-05-30 01:11:00 +00:00
Alex Rønne Petersen
4641e9556d mingw: Link to ucrtbased.dll instead of API set DLLs in Debug mode.
By using the debug UCRT, we get access to functions like _CrtDbgReport.

Closes #23983.
2025-05-30 02:11:36 +02:00
Alex Rønne Petersen
0cbff2ff7f mingw: Remove libscrnsav(e,w) support.
This defines a WinMain() function that can be potentially problematic when it
isn't wanted. If we add back support for this library in the future, it should
be built separately from mingw32.lib and on demand.
2025-05-30 01:03:47 +02:00
Alex Rønne Petersen
63a9048baf
libc: Merge header directories for glibc and NetBSD libc where applicable.
Manual patches:

* lib/libc/include/csky-linux-gnu/gnu/{lib-names,stubs}.h
* lib/libc/include/powerpc-linux-gnu/bits/long-double.h

Takes lib/libc/include from 115.5 MB to 113.4 MB.

Closes #21258.
2025-05-30 00:15:39 +02:00
Alex Rønne Petersen
7c7627b18a
compiler: Use new merged header paths for glibc and NetBSD libc. 2025-05-30 00:15:37 +02:00
Alex Rønne Petersen
dc760492a4
process_headers: Merge header directories for some targets.
These are almost entirely identical, with these exceptions:

* lib/libc/include/csky-linux-{gnueabi,gnueabihf}
    * gnu/{lib-names,stubs}.h will need manual patching for float ABI.
* lib/libc/include/{powerpc-linux-{gnueabi,gnueabihf},{powerpc64,powerpc64le}-linux-gnu}
    * bits/long-double.h will need manual patching for long double ABI.
2025-05-29 23:38:28 +02:00
Alex Rønne Petersen
cbf9d3c570
libc: Remove riscv32-netbsd-none and riscv64-netbsd-none headers.
These were not intended to be included as NetBSD's RISC-V port has not had an
official release yet.
2025-05-29 16:48:28 +02:00
Alex Rønne Petersen
aeebb131c8
test: Add NetBSD targets to module test matrix. 2025-05-29 16:48:28 +02:00
Veikka Tuominen
9d8acf973e
aro_translate_c: Fix an assertion in buildArgsHash().
Closes #24015.
2025-05-29 16:48:28 +02:00
Alex Rønne Petersen
92b3c4b451
std.c: Expand the definition of NetBSD's pthread_rwlock_t for more targets. 2025-05-29 16:48:28 +02:00
Alex Rønne Petersen
71fd5ac38a
std.c: Fix return type for NetBSD's __sigfillset14(). 2025-05-29 16:48:28 +02:00
Alex Rønne Petersen
c5a68e4168
test: Remove x86-freebsd-none and powerpc-freebsd-eabihf from llvm_targets.
These will be dropped in FreeBSD 15.0, so there's no point in us spending
resources these now.
2025-05-29 16:48:28 +02:00
Alex Rønne Petersen
c9ee69712a
test: Add FreeBSD targets to module test matrix.
std tests are temporarily disabled for arm-freebsd-eabihf due to #23949.

I omitted x86-freebsd-none and powerpc-freebsd-none because these will be
dropped in FreeBSD 15.0 anyway, so there's no point in us spending resources on
those now.
2025-05-29 16:48:28 +02:00
Alex Rønne Petersen
fb3a9fc18e
std.posix.test: Fix reserved_signo() for NetBSD. 2025-05-29 16:48:28 +02:00
Alex Rønne Petersen
309ac27d35
std.c: Fix sigrtmin()/sigrtmax() for FreeBSD and NetBSD.
They just define the constants in the system headers.
2025-05-29 16:48:28 +02:00
Alex Rønne Petersen
3d2b0a53fe
test: Improve Windows module test coverage.
There's not really any point in targeting *-windows-(gnu,msvc) when not linking
libc, so add entries for *-windows-(gnu,msvc) that actually link libc, and
change the old non-libc entries to *-windows-none.

Also add missing aarch64-windows-(none,msvc) and thumb-windows-(none,msvc)
entries. thumb-windows-gnu is disabled for now due to #24016.
2025-05-29 16:47:54 +02:00
Alex Rønne Petersen
358ee859ba
compiler-rt: Fix some exports for *-windows-none. 2025-05-29 15:35:35 +02:00
Alex Rønne Petersen
7cae6b8fa7
test: Skip *-windows-msvc + libc module tests on non-Windows.
We can't provide MSVC libc when cross-compiling (yet?).
2025-05-29 15:35:30 +02:00
Alex Rønne Petersen
c8ea81bf96
test: Sort module test and C ABI test target tables.
I removed the commented-out entries for backends that are bitrotted. Can add
these back later when we reboot those backends.
2025-05-29 15:01:45 +02:00
Jacob Young
c04be630d9 Legalize: introduce a new pass before liveness
Each target can opt into different sets of legalize features.
By performing these transformations before liveness, instructions
that become unreferenced will have up-to-date liveness information.
2025-05-29 03:57:48 -04:00
Jacob Young
f25212a479
Merge pull request #23924 from jacobly0/x86_64-rewrite
x86_64: implement reduce
2025-05-28 21:37:02 -04:00
Jacob Young
9f9e7e398f x86_64: implement strict float @reduce(.Max) 2025-05-28 15:10:22 -04:00
Jacob Young
f5a1aaf2fc x86_64: implement strict float @reduce(.Min) 2025-05-28 15:10:22 -04:00
Jacob Young
d29ea656b0 x86_64: implement optimized float @reduce(.Max) 2025-05-28 15:10:22 -04:00
Jacob Young
114a4eaf5c x86_64: implement optimized float @reduce(.Min) 2025-05-28 15:10:22 -04:00
Jacob Young
8bacf3e757 x86_64: implement integer @reduce(.Max) 2025-05-28 15:10:22 -04:00
Jacob Young
3fd3358f37 x86_64: implement integer @reduce(.Min) 2025-05-28 15:10:22 -04:00
Jacob Young
7d727ed7df x86_64: implement strict float @reduce(.Mul) 2025-05-28 15:10:22 -04:00
Jacob Young
d1785cf61c x86_64: implement strict float @reduce(.Add) 2025-05-28 15:10:22 -04:00
Jacob Young
a4a1ebdeed x86_64: implement optimized float @reduce(.Mul) 2025-05-28 15:10:22 -04:00
Jacob Young
612f5784cf x86_64: implement optimized float @reduce(.Add) 2025-05-28 15:10:22 -04:00
mlugg
7c31f9d4ff Sema: don't emit AIR reduce for single-element vectors
This is equivalent to `array_elem_val`, and doing that conversion in
Sema (seems reasonable since it's just a simple branch) is much easier
for the self-hosted x86_64 backend then actually handling this case.
2025-05-28 15:10:22 -04:00
Jacob Young
7bfdb7f26d x86_64: implement integer @reduce(.Mul) 2025-05-28 15:10:22 -04:00
Jacob Young
1f6f8b0ffe x86_64: implement integer @reduce(.Add) 2025-05-28 15:10:22 -04:00
Jacob Young
d69f4c48fc x86_64: rewrite bitwise @reduce 2025-05-28 15:10:22 -04:00
Jacob Young
4f3b59f708 debug: disable fp-based frame unwinding when fp is omitted
This has been causing non-deterministic timeouts on aarch64 CI.
2025-05-28 15:08:39 -04:00
Alex Rønne Petersen
e28b4027ee ci: Skip building non-native tests on aarch64-linux.
Because we don't pass -fqemu and -fwasmtime on aarch64-linux, we're just
spending a bunch of time compiling all these module tests only to not even run
them. x86_64-linux already covers both compiling and running them.
2025-05-28 11:03:39 +02:00
mlugg
92c63126e8 compiler: tlv pointers are not comptime-known
Pointers to thread-local variables do not have their addresses known
until runtime, so it is nonsensical for them to be comptime-known. There
was logic in the compiler which was essentially attempting to treat them
as not being comptime-known despite the pointer being an interned value.
This was a bit of a mess, the check was frequent enough to actually show
up in compiler profiles, and it was very awkward for backends to deal
with, because they had to grapple with the fact that a "constant" they
were lowering might actually require runtime operations.

So, instead, do not consider these pointers to be comptime-known in
*any* way. Never intern such a pointer; instead, when the address of a
threadlocal is taken, emit an AIR instruction which computes the pointer
at runtime. This avoids lots of special handling for TLVs across
basically all codegen backends; of all somewhat-functional backends, the
only one which wasn't improved by this change was the LLVM backend,
because LLVM pretends this complexity around threadlocals doesn't exist.

This change simplifies Sema and codegen, avoids a potential source of
bugs, and potentially improves Sema performance very slightly by
avoiding a non-trivial check on a hot path.
2025-05-27 19:23:11 +01:00
David Rubin
3ed9155f10 Sema: simplify comptime @intFromPtr logic 2025-05-27 02:40:58 +01:00
Matthew Lugg
ef35c3d5fe
Merge pull request #23986 from mlugg/incremental-stuff
incremental: bugfix (and a debugging feature that helped me do that bugfix)
2025-05-25 18:02:16 +01:00
Robin Voetter
dc6ffc28b5
Merge pull request #23815 from alichraghi/master
spirv: unroll all vector operations
2025-05-25 12:36:53 +02:00
mlugg
3d8e760552
Zcu: fix nav_ty dependency on nav_val
In the case where a declaration has no type annotation, the interaction
between resolution of `nav_ty` and `nav_val` is a little fiddly because
of the fact that resolving `nav_val` actually implicitly resolves the
type as well. This means `nav_ty` never gets an opporunity to mark its
dependency on the `nav_val`. So, `ensureNavValUpToDate` needs to be the
one to do it. It can't do it too early, though; otherwise, our marking
of dependees as out-of-date/up-to-date will go wrong.

Resolves: #23959
2025-05-25 05:50:26 +01:00
mlugg
aeed5f9ebd
compiler: introduce incremental debug server
In a compiler built with debug extensions, pass `--debug-incremental` to
spawn the "incremental debug server". This is a TCP server exposing a
REPL which allows querying a bunch of compiler state, some of which is
stored only when that flag is passed. Eventually, this will probably
move into `std.zig.Server`/`std.zig.Client`, but this is easier to work
with right now. The easiest way to interact with the server is `telnet`.
2025-05-25 04:43:43 +01:00
Andrew Kelley
35ba8d95a1 CI: bump maxrss for aarch64 linux
Reduced number of runners from 9 to 6.

This number is the total physical memory (251G) divided by the number of
runners we have active (6).

see previous commit 5b9e528bc550e7ea9e286fdd2324316f9895d5da
2025-05-24 11:36:30 -07:00
KNnut
7dbd21bd5b std.zig.LibCDirs: fix wasi-libc support 2025-05-24 13:32:17 +02:00
Felix Rabe
ad2b175d45 std.log: fix example 2025-05-24 10:52:56 +02:00
Andrew Kelley
4315a57233 langref: update nav link for 0.14.1 2025-05-23 14:43:47 -07:00
mlugg
d238078ae8
github: add link to issue template list warning against LLMs
GitHub have introduced an absolutely baffling feature where users can
use Copilot to take their simple explanation of a bug, and reword it
into a multi-paragraph monologue with no interesting details and added
false information, while also potentially ignoring issue templates.

So far, GitHub has not provided a way to block this feature at the
repository or organisation level, so for now, this is the only way to
prevent users from filing LLM-generated slop.

Related: https://github.com/orgs/community/discussions/159749
2025-05-23 15:51:11 +01:00
mlugg
9a3540d61e std.Build: resolved generated paths are cwd-relative
The doc comment here agreed with the implementation, but not with *any*
`Step` which populates a `GeneratedFile`, where they are treated as
cwd-relative. This is the obvious correct choice, because these paths
usually come from joining onto a cache root, and those are cwd-relative
if not absolute.

This was a pre-existing bug, but #23836 caused it to trigger more often,
because the compiler now commonly passes the local cache directory to
the build runner process as a relative path where it was previously an
absolute path.

Resolves: #23954
2025-05-22 08:43:37 +01:00
Evan Silberman
931c6f90f5 Add EVFILT_USER and friends for OpenBSD
OpenBSD -current grew EVFILT_USER. See commit message [1] and and
current sys/event.h [2]

Also EVFILT_DEVICE was missing.

Closes #23930

[1]: https://marc.info/?l=openbsd-cvs&m=174686993115485&w=2
[2]: https://codeberg.org/OpenBSD/src/src/branch/master/sys/sys/event.h
2025-05-22 04:37:57 +02:00
mlugg
a5861fcddd Module: name builtin module root directory correctly
37a9a4e accidentally turned paths `b/[hash]/` into `b[hash]/` in the
global cache. This doesn't technically break anything, but it pollutes
the global cache directory. Sorry about that one!
2025-05-21 15:20:23 +01:00
Ali Cheraghi
4bf1e4d198 target: auto-generated spirv features 2025-05-21 15:26:18 +03:30
mlugg
3416452d56 compiler: fix ZIR hash not including compiler version
This was an unintentional regression in 23c8175 which meant that
backwards-incompatible ZIR changes would have caused compiler crashes if
old caches were present.
2025-05-21 11:11:28 +01:00
Matthew Lugg
ef92c156b5
Merge pull request #23946 from mlugg/build-step-run-cwd
std.Build.Step.Run: inherit build runner cwd
2025-05-21 10:33:30 +01:00
Ali Cheraghi
8fa54eb798 spirv: error when execution mode is set more than once 2025-05-21 13:01:21 +03:30
Ali Cheraghi
9209f4b16a spirv: recognize builtin extern vars 2025-05-21 13:01:21 +03:30
Ali Cheraghi
dacd70fbe4 spirv: super basic composite int support 2025-05-21 13:01:20 +03:30
Ali Cheraghi
0901328f12 spirv: write error value in an storage buffer 2025-05-21 12:57:40 +03:30
Ali Cheraghi
fca5f3602d spirv: unroll all vector operations 2025-05-21 12:57:40 +03:30
Alex Rønne Petersen
f925e1379a std.zig.target: Remove thumb-freebsd-eabihf.
Leftover from 76d525f74a33e20dfa4c9e84b27ce8ad84529cac.
2025-05-21 09:55:23 +02:00
Alex Rønne Petersen
7c9035f635 link.Elf: Don't require linking libc for dynamic linker path to take effect.
Closes #23813.
2025-05-21 06:08:50 +02:00
Jacob Young
cdba1d591a test-cli: port build options test to new build system API
Since we need testing for passing `--build-file` and `--cache-dir`
together anyway, use it to test the disabled build options test.
2025-05-20 23:02:51 -04:00
mlugg
fe855691f6
std.Build.Step.Run: inherit build runner cwd
Right now, if you override the build root with `--build-root`, then
`Run` steps can fail to execute because of incorrect path handling in
the compiler: `std.process.Child` gets a cwd-relative path, but also has
its cwd set to the build root. The latter behavior is really weird; it
doesn't match my expectations, nor does it match how we spawn child
`zig` processes. So, this commit makes the child process inherit the
build runner's cwd, as `LazyPath.getPath2` *expects* it to.

After investigating, this behavior dates all the way back to 2017; it
was introduced in 4543413. So, there isn't any clear/documented reason
for this; it should be safe to revert, since under the modern `LazyPath`
system it is strictly a bug AFAICT.
2025-05-21 01:45:05 +01:00
David
55848363fd
libc: implement common abs for various integer sizes (#23893)
* libc: implement common `abs` for various integer sizes

* libc: move imaxabs to inttypes.zig and don't use cInclude

* libc: delete `fabs` c implementations because already implemented in compiler_rt

* libc: export functions depending on the target libc

Previously all the functions that were exported were handled equally,
though some may exist and some not inside the same file. Moving the
checks inside the file allows handling different functions differently

* remove empty ifs in inttypes

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>

* remove empty ifs in stdlib

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>

* libc: use `@abs` for the absolute value calculation

---------

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>
2025-05-21 00:57:38 +02:00
Alex Rønne Petersen
a63f7875f4 compiler: Fix build break due to #23836 being merged before #23913. 2025-05-20 13:22:11 +02:00
Alex Rønne Petersen
999777e73a compiler: Scaffold stage2_powerpc backend.
Nothing interesting here; literally just the bare minimum so I can work on this
on and off in a branch without worrying about merge conflicts in the non-backend
code.
2025-05-20 10:23:16 +02:00
Alex Rønne Petersen
d000e53b29
Merge pull request #23923 from alexrp/compiler-rt-symbols
Use hidden visibility in compiler-rt and libzigc except when testing
2025-05-20 07:48:35 +02:00
Alex Rønne Petersen
b27c5fbbde
Merge pull request #23913 from alexrp/netbsd-libc
Support dynamically-linked NetBSD libc when cross-compiling
2025-05-20 07:46:08 +02:00
Matthew Lugg
23c817548b
Merge pull request #23836 from mlugg/incr-fixes
Incremental fixes, refactor `Zcu.File`
2025-05-20 03:25:19 +01:00
mlugg
f2077f57ae Sema: allow @ptrCast single-item pointer to slice
Also, rework this logic a little to make it simpler. The length of the
result slice is now computed in one place.
2025-05-19 19:26:12 +01:00
mlugg
ac8720f399 Zcu: fix memory leak
Bug introduced by d717c96, sorry!
2025-05-19 19:12:31 +01:00
tjog
ad1e09eab0 libfuzzer test: use proper cache dir logic 2025-05-19 04:03:16 +02:00
mlugg
07a5efd072 Sema: rewrite analyzeMinMax
I only wanted to fix a bug originally, but this logic was kind of a
rat's nest. But now... okay, it still *is*, but it's now a slightly more
navigable nest, with cute little signs occasionally, painted by adorable
rats desparately trying to follow the specification.

Hopefully #3806 comes along at some point to simplify this logic a
little.

Resolves: #23139
2025-05-19 00:27:01 +01:00
Alex Rønne Petersen
b0c10e2262
test: Enable x86-linux-musl with dynamic linkage in the module test matrix.
Building upstream musl for this target works now that we use hidden visibility
for compiler-rt symbols.
2025-05-19 00:22:22 +02:00
Alex Rønne Petersen
e882956ef6
std.leb128: Disable two tests on x86-linux-musl with dynamic linkage.
https://github.com/ziglang/zig/issues/23922
2025-05-19 00:22:19 +02:00
Alex Rønne Petersen
07c93cb103
compiler-rt: Add a comment explaining why we currently need weak linkage. 2025-05-19 00:22:03 +02:00
Alex Rønne Petersen
90fb2d9754
compiler-rt: Fix some exports to respect the common linkage and visibility. 2025-05-19 00:22:03 +02:00
Alex Rønne Petersen
092352ec63
compiler-rt, zigc: Use hidden visibility except when testing.
This prevents symbols from these libraries from polluting the dynamic symbol
tables of binaries built with Zig. The downside is that we no longer deduplicate
the symbols at run time due to weak linkage.

Closes #7935.
Closes #13303.
Closes #19342.
2025-05-19 00:22:03 +02:00
Alex Rønne Petersen
846571ce4e
build: Bump max_rss for test-behavior to 2488843878. 2025-05-19 00:22:03 +02:00
Andrew Kelley
b77e601342
Merge pull request #23834 from jacobly0/x86_64-rewrite
x86_64: finish rewriting scalar overflow and saturate operations
2025-05-18 14:36:33 -04:00
mlugg
37a9a4e0f1
compiler: refactor Zcu.File and path representation
This commit makes some big changes to how we track state for Zig source
files. In particular, it changes:

* How `File` tracks its path on-disk
* How AstGen discovers files
* How file-level errors are tracked
* How `builtin.zig` files and modules are created

The original motivation here was to address incremental compilation bugs
with the handling of files, such as #22696. To fix this, a few changes
are necessary.

Just like declarations may become unreferenced on an incremental update,
meaning we suppress analysis errors associated with them, it is also
possible for all imports of a file to be removed on an incremental
update, in which case file-level errors for that file should be
suppressed. As such, after AstGen, the compiler must traverse files
(starting from analysis roots) and discover the set of "live files" for
this update.

Additionally, the compiler's previous handling of retryable file errors
was not very good; the source location the error was reported as was
based only on the first discovered import of that file. This source
location also disappeared on future incremental updates. So, as a part
of the file traversal above, we also need to figure out the source
locations of imports which errors should be reported against.

Another observation I made is that the "file exists in multiple modules"
error was not implemented in a particularly good way (I get to say that
because I wrote it!). It was subject to races, where the order in which
different imports of a file were discovered affects both how errors are
printed, and which module the file is arbitrarily assigned, with the
latter in turn affecting which other files are considered for import.
The thing I realised here is that while the AstGen worker pool is
running, we cannot know for sure which module(s) a file is in; we could
always discover an import later which changes the answer.

So, here's how the AstGen workers have changed. We initially ensure that
`zcu.import_table` contains the root files for all modules in this Zcu,
even if we don't know any imports for them yet. Then, the AstGen
workers do not need to be aware of modules. Instead, they simply ignore
module imports, and only spin off more workers when they see a by-path
import.

During AstGen, we can't use module-root-relative paths, since we don't
know which modules files are in; but we don't want to unnecessarily use
absolute files either, because those are non-portable and can make
`error.NameTooLong` more likely. As such, I have introduced a new
abstraction, `Compilation.Path`. This type is a way of representing a
filesystem path which has a *canonical form*. The path is represented
relative to one of a few special directories: the lib directory, the
global cache directory, or the local cache directory. As a fallback, we
use absolute (or cwd-relative on WASI) paths. This is kind of similar to
`std.Build.Cache.Path` with a pre-defined list of possible
`std.Build.Cache.Directory`, but has stricter canonicalization rules
based on path resolution to make sure deduplicating files works
properly. A `Compilation.Path` can be trivially converted to a
`std.Build.Cache.Path` from a `Compilation`, but is smaller, has a
canonical form, and has a digest which will be consistent across
different compiler processes with the same lib and cache directories
(important when we serialize incremental compilation state in the
future). `Zcu.File` and `Zcu.EmbedFile` both contain a
`Compilation.Path`, which is used to access the file on-disk;
module-relative sub paths are used quite rarely (`EmbedFile` doesn't
even have one now for simplicity).

After the AstGen workers all complete, we know that any file which might
be imported is definitely in `import_table` and up-to-date. So, we
perform a single-threaded graph traversal; similar to what
`resolveReferences` plays for `AnalUnit`s, but for files instead. We
figure out which files are alive, and which module each file is in. If a
file turns out to be in multiple modules, we set a field on `Zcu` to
indicate this error. If a file is in a different module to a prior
update, we set a flag instructing `updateZirRefs` to invalidate all
dependencies on the file. This traversal also discovers "import errors";
these are errors associated with a specific `@import`. With Zig's
current design, there is only one possible error here: "import outside
of module root". This must be identified during this traversal instead
of during AstGen, because it depends on which module the file is in. I
tried also representing "module not found" errors in this same way, but
it turns out to be much more useful to report those in Sema, because of
use cases like optional dependencies where a module import is behind a
comptime-known build option.

For simplicity, `failed_files` now just maps to `?[]u8`, since the
source location is always the whole file. In fact, this allows removing
`LazySrcLoc.Offset.entire_file` completely, slightly simplifying some
error reporting logic. File-level errors are now directly built in the
`std.zig.ErrorBundle.Wip`. If the payload is not `null`, it is the
message for a retryable error (i.e. an error loading the source file),
and will be reported with a "file imported here" note pointing to the
import site discovered during the single-threaded file traversal.

The last piece of fallout here is how `Builtin` works. Rather than
constructing "builtin" modules when creating `Package.Module`s, they are
now constructed on-the-fly by `Zcu`. The map `Zcu.builtin_modules` maps
from digests to `*Package.Module`s. These digests are abstract hashes of
the `Builtin` value; i.e. all of the options which are placed into
"builtin.zig". During the file traversal, we populate `builtin_modules`
as needed, so that when we see this imports in Sema, we just grab the
relevant entry from this map. This eliminates a bunch of awkward state
tracking during construction of the module graph. It's also now clearer
exactly what options the builtin module has, since previously it
inherited some options arbitrarily from the first-created module with
that "builtin" module!

The user-visible effects of this commit are:
* retryable file errors are now consistently reported against the whole
  file, with a note pointing to a live import of that file
* some theoretical bugs where imports are wrongly considered distinct
  (when the import path moves out of the cwd and then back in) are fixed
* some consistency issues with how file-level errors are reported are
  fixed; these errors will now always be printed in the same order
  regardless of how the AstGen pass assigns file indices
* incremental updates do not print retryable file errors differently
  between updates or depending on file structure/contents
* incremental updates support files changing modules
* incremental updates support files becoming unreferenced

Resolves: #22696
2025-05-18 17:37:02 +01:00
mlugg
d32829e053
std.Build.Cache: change contract of addFilePostContents
This function was broken, because it took ownership of the buffer on
error *sometimes*, in a way which the caller could not tell. Rather than
trying to be clever, it's easier to just follow the same interface as
all other `addFilePost` methods, and not take ownership of the path.

This is a breaking change. The next commits will apply it to the
compiler, which is the only user of this function in the ziglang/zig
repository.
2025-05-18 17:10:04 +01:00
mlugg
a0792e743f
incr-check: normalize path separators in file names in errors 2025-05-18 17:10:04 +01:00
mlugg
ed7335ce57
incr-check: support basic modules
Allow specifying modules which the root module depends on. More complex
graphs cannot currently be specified.
2025-05-18 17:10:04 +01:00
mlugg
6d7c89cb40
build.zig: use correct module graph for compiler unit tests 2025-05-18 17:10:04 +01:00
mlugg
e26c326996
tests: remove incorrect import 2025-05-18 17:10:04 +01:00
Alex Rønne Petersen
74a3ae4927 start: Don't artificially limit some posixCallMainAndExit() logic to Linux.
This code applies to ~any POSIX OS where we don't link libc. For example, it'll
be useful for FreeBSD and NetBSD.

As part of this, move std.os.linux.pie to std.pie since there's really nothing
Linux-specific about what that file is doing.
2025-05-18 17:14:09 +02:00
Jacob Young
a4eabd3979 x86_64: implement vector_store_elem 2025-05-17 20:31:25 -04:00
Jacob Young
a3b0c242b0 x86_64: rewrite @splat 2025-05-17 18:00:17 -04:00
Jacob Young
58d2bd601e x86_64: rewrite scalar <<|
Closes #23035
2025-05-17 18:00:17 -04:00
Jacob Young
d3dfe61eaa x86_64: rewrite scalar *| 2025-05-17 18:00:17 -04:00
Alex Rønne Petersen
cd1eea0964
freebsd: Fix stub libraries containing versioned symbols that shouldn't be.
Closes #23911.
2025-05-17 20:13:02 +02:00
Alex Rønne Petersen
a97e417ab1
compiler: Support building NetBSD crt1.o/Scrt1.o and stub shared libraries.
Only works for NetBSD 10.1+. Note that we still default to targeting NetBSD 9.

Contributes to #2877.
2025-05-17 20:12:56 +02:00
Jacob Young
96e35b3652 x86_64: rewrite vector -| 2025-05-17 02:08:41 -04:00
Jacob Young
3529889cf3 x86_64: rewrite scalar -| 2025-05-17 02:08:41 -04:00
Jacob Young
4adb7eca6a debug: correctly detect missing entries in .eh_frame_hdr 2025-05-17 02:08:41 -04:00
Jacob Young
025611629f x86_64: implement @memmove 2025-05-17 02:08:41 -04:00
Jacob Young
6d68a494c8 x86_64: rewrite vector +| 2025-05-17 02:08:41 -04:00
Jacob Young
6dbf1c7682 x86_64: rewrite scalar +| 2025-05-17 02:08:41 -04:00
Jacob Young
932298679f x86_64: rewrite scalar @shlWithOverflow 2025-05-17 02:08:41 -04:00
Alex Rønne Petersen
c5e669ff76
compiler: Link libc by default when targeting NetBSD.
We don't yet have a direct syscall layer in std.os.netbsd.
2025-05-17 04:41:27 +02:00
Alex Rønne Petersen
d29ba75c84
Compilation.Config: Default to dynamic linking with NetBSD libc. 2025-05-17 04:41:27 +02:00
Alex Rønne Petersen
1a82cceb8c
std.Target: Factor arch/ABI into NetBSD minimum OS version selection.
Based on data in std.zig.target.
2025-05-17 04:41:27 +02:00
Alex Rønne Petersen
a090ef007b
std.zig.target: Add NetBSD libc support. 2025-05-17 04:41:27 +02:00
Alex Rønne Petersen
e20fb7071c
compiler: Define __NetBSD_Version__ when targeting NetBSD libc. 2025-05-17 04:41:27 +02:00
Alex Rønne Petersen
c36d483ba0
libc: Add NetBSD libc abilists file.
Currently covers version 10.1.
2025-05-17 04:41:27 +02:00
Alex Rønne Petersen
90911b39d5
update_netbsd_libc: Add tool for updating NetBSD libc startup code. 2025-05-17 04:41:27 +02:00
Alex Rønne Petersen
1c342ca7c3
libc: Add NetBSD libc startup code from 10.1.
* sysident_assym.h was manually expanded.
    * The ELF_NOTE_MARCH_DESC and ELF_NOTE_MARCH_DESCSZ macros will be defined
      by the compiler.
* Legacy .init/.fini stuff was removed.
* GCJ nonsense was removed.
2025-05-17 04:41:27 +02:00
Alex Rønne Petersen
35f8121194
std.zig.LibCDirs: Add NetBSD libc support. 2025-05-17 04:41:27 +02:00
Alex Rønne Petersen
553cb3ed46
libc: Add NetBSD system and libc headers from 10.1.
sys/param.h was manually adjusted to not define __NetBSD_Version__ since it will
be defined by the compiler.
2025-05-17 04:41:27 +02:00
Alex Rønne Petersen
4371e695ef
process_headers: Add NetBSD libc support. 2025-05-17 04:41:27 +02:00
Alex Rønne Petersen
6028db7f29
std.Target: Add isNetBSDLibC() function. 2025-05-17 04:41:27 +02:00
Alex Rønne Petersen
8a7d925d36
std.Target: Fix requiresLibC() for NetBSD. 2025-05-17 04:41:27 +02:00
Alex Rønne Petersen
3d6f83b331
std.Target: Adjust DynamicLinker.standard() for NetBSD.
* powerpc64 does not appear to be a thing.
* riscv32/riscv64 have not had actual releases yet.
2025-05-17 04:41:27 +02:00
Alex Rønne Petersen
9af8e7c68e
std.c: Fill out some missing definitions for supported NetBSD libc targets.
This allows ubsan-rt to build.
2025-05-17 04:41:26 +02:00
Alex Rønne Petersen
d47cc5777d
test: Remove some nonsensical NetBSD targets from llvm_targets.
* mips64/mips64el on NetBSD are soft float; we have no support for this yet.
* powerpc64 does not appear to be a thing.
* riscv32/riscv64 have not seen official releases yet.
2025-05-17 04:41:26 +02:00
Alex Rønne Petersen
0d35a7760e
freebsd: Fix selection of unversioned symbol inclusion.
We want the latest unversioned inclusion that fits the target version. This
theoretically matters because it might have a different global vs weak linkage
compared to an older inclusion.
2025-05-17 04:41:26 +02:00
Alex Rønne Petersen
76d525f74a
freebsd: Remove dead Thumb handling code. 2025-05-17 04:41:26 +02:00
Alex Rønne Petersen
e52ffe6738
glibc: Fix a benign bug when selecting the size of an object symbol.
This didn't cause any problems in practice, but doing it this way is technically
more correct.
2025-05-17 04:41:24 +02:00
mlugg
8e72a25285 doctest: handle relative paths correctly
Evaluate all child processes in the temporary directory, and use
`std.fs.path.relative` to make every other path relative to that child
cwd instead of our cwd.

Resolves: #22119
2025-05-16 22:42:29 +01:00
Matthew Lugg
9064907b34
Merge pull request #23907 from mlugg/ref-trace
compiler: reference trace fixes
2025-05-16 22:42:07 +01:00
Alex Rønne Petersen
9e48e919e7
.gitattributes: Mark abilists files as binary. 2025-05-16 21:56:03 +02:00
Alex Rønne Petersen
9279ff888b test: Silence stderr output from test_obj_link_run. 2025-05-16 15:07:25 +01:00
Marc Tiehuis
224e39316f std.hash.Wyhash: fix dangling stack pointer
Closes #23895.
2025-05-16 15:28:20 +02:00
mlugg
46d7e808dc
build runner: don't incorrectly omit reference traces
It's incorrect to ever set `include_reference_trace` here, because the
compiler has already given or not given reference traces depending on
the `-freference-trace` option propagated to the compiler process by
`std.Build.Step.Compile`.

Perhaps in future we could make the compiler always return the reference
trace when communicating over the compiler protocol; that'd be more
versatile than the current behavior, because the build runner could, for
instance, show a reference trace on-demand without having to even invoke
the compiler. That seems really useful, since the reference trace is
*often* unnecessary noise, but *sometimes* essential. However, we don't
live in that world right now, so passing the option here doesn't make
sense.

Resolves: #23415
2025-05-16 13:40:52 +01:00
mlugg
16481c8ef3
cases: update to new "called from here" notes 2025-05-16 13:29:55 +01:00
mlugg
4296727050
Sema: improve "called from here" notes
To an average user, it may be unclear why these notes are not just in
the reference trace; that's because they are more important, because
they are inline calls through which comptime values may propagate. There
are now 3 possible wordings for this note:

* "called at comptime here"
* "called inline here"
* "generic function instantiated here"

An alternative could be these wordings:

* "while analyzing comptime call here"
* "while analyzing inline call here"
* "while analyzing generic instantiation here"

I'm not sure which is better -- but this commit is certainly better than
status quo.
2025-05-16 13:28:15 +01:00
mlugg
d717c96877
compiler: include inline calls in the reference trace
Inline calls which happened in the erroring `AnalUnit` still show as
error notes, because they tend to make very important context (e.g. to
see how comptime values propagate through them). However, "earlier"
inline calls are still useful to see to understand how something is
being referenced, so we should include them in the reference trace.
2025-05-16 13:28:15 +01:00
mlugg
70040778fb
Compilation: fix reference trace behavior without -freference-trace
When `-freference-trace` is not passed, we want to show exactly one
reference trace. Previously, we set the reference trace root in `Sema`
iff there were no other failed analyses. However, this results in an
arbitrary error being the one with the reference trace after error
sorting. It is also incompatible with incremental compilation, where
some errors might be unreferenced. Instead, set the field on all
analysis errors, and decide in `Compilation.getAllErrorsAlloc` which
reference trace[s] to actually show.
2025-05-16 11:55:35 +01:00
HydroH
cc1475c91d
std: remove std.crypto.Certificate.Parsed.pubKeySigAlgo method (#23811) 2025-05-16 00:21:25 +02:00
wooster0
56fad6a195 make error messages prettier
Error messages never contain periods or grave accents.
Get rid of the periods and use apostrophes instead in
probably the only two error messages that had them.
2025-05-15 16:39:15 +01:00
Bryson Miller
08d534e8d8
Introduce common strcasecmp and strncasecmp implementations (#23840) 2025-05-15 10:58:33 +02:00
Alex Rønne Petersen
bc377183ce reduce: Fix build due to std.mem.Alignment changes.
Closes #23884.
2025-05-15 03:13:41 +02:00
Isaac Freund
bc2f7c7547 Revert "Work around stage1 not yet returning null-terminated @typeInfo strings"
This reverts commit c8fa767f083e610840cef688b709783c5ad66acc.
2025-05-14 06:47:23 +02:00
Cezary Kupaj
518105471e
Fix SIGSEGV handler for AArch64 Darwin targets
* ucontext_t ptr is 8-byte aligned instead of 16-byte aligned which @alignCast() expects
* Retrieve pc address from ucontext_t since unwind_state is null
* Work around __mcontext_data being written incorrectly by the kernel
2025-05-14 05:38:38 +02:00
Alex Rønne Petersen
5b606d435d
Merge pull request #21882 from alexrp/compiler-fixes
compiler: Fix some real and theoretical miscompilations with `allowzero` and `volatile`
2025-05-13 10:42:05 +02:00
wooster0
a365971a33 std.meta.intToEnum -> std.enums.fromInt
Also use an optional as the return type instead of an error code.
2025-05-13 07:28:41 +02:00
Alex Rønne Petersen
a3693aae3a
Merge pull request #23856 from alexrp/backport-llvm-120036 2025-05-13 01:08:07 +02:00
Alex Rønne Petersen
bc3c50c21e
Merge pull request #23700 from sorairolake/rename-trims
chore(std.mem): Rename `trimLeft` and `trimRight` to `trimStart` and `trimEnd`
2025-05-12 17:11:52 +02:00
Alex Rønne Petersen
9d8adb38a1
std.Build: Make no_builtin a property of Module instead of Step.Compile.
This reflects how the compiler actually treats it.

Closes #23424.
2025-05-12 17:08:22 +02:00
Alex Rønne Petersen
aa7c6dcac1
main: List -f(no-)builtin as per-module options.
Contributes to #23424.
2025-05-12 17:07:50 +02:00
Alex Rønne Petersen
74f55175d5
test: Add some basic LLVM IR tests for atomics, volatile, and allowzero. 2025-05-12 17:07:50 +02:00
Alex Rønne Petersen
e63e3f7a7c
test: Add test-llvm-ir step and harness for testing generated LLVM IR. 2025-05-12 17:07:50 +02:00
Alex Rønne Petersen
fe5dbc2474
std.Build: Change Step.Compile.no_builtin from bool to ?bool.
To be in line with other, similar options.
2025-05-12 17:07:50 +02:00
Alex Rønne Petersen
af55b27d5a
test: Fix incorrect interpretation of -Dtest-filter=... for test-debugger. 2025-05-12 17:07:50 +02:00
Alex Rønne Petersen
44bf64a709
llvm: Fix a bunch of volatile semantics violations.
Also fix some cases where we were being overzealous in applying volatile.
2025-05-12 17:07:50 +02:00
Alex Rønne Petersen
427810f3ed
llvm: Don't set nonnull attribute on pointers in non-generic address spaces.
LLVM considers null pointers to be valid for such address spaces.
2025-05-12 17:07:50 +02:00
Alex Rønne Petersen
e9ae9a5fc4
llvm: Don't set nonnull attribute on allowzero slices. 2025-05-12 17:07:49 +02:00
Alex Rønne Petersen
e95e7651ec
llvm: Set null_pointer_is_valid attribute when accessing allowzero pointers.
This informs optimization passes that they shouldn't assume that a load from a
null pointer invokes undefined behavior.

Closes #15816.
2025-05-12 17:07:49 +02:00
Alex Rønne Petersen
5c2e300f42
Air: Fix mustLower() to consider volatile for a handful of instructions.
These can all potentially operate on volatile pointers.
2025-05-12 17:07:49 +02:00
Alex Rønne Petersen
47aaaec6ea
Air: Always return true for inline assembly in mustLower().
AstGen requires inline assembly to either have outputs or be marked volatile, so
there doesn't appear to be any point in doing these checks.
2025-05-12 17:07:49 +02:00
Alex Rønne Petersen
4c36a403a8
Air: Fix mustLower() for atomic_load with inter-thread ordering. 2025-05-12 17:07:49 +02:00
Alex Rønne Petersen
d4ca9804f8
riscv64: Handle writes to the zero register sensibly in result bookkeeping. 2025-05-12 17:07:49 +02:00
Alex Rønne Petersen
61ae9a2f45
riscv64: Add missing fence for seq_cst atomic_store. 2025-05-12 17:07:49 +02:00
Alex Rønne Petersen
e40de86082
riscv64: Get rid of some trailing whitespace. 2025-05-12 17:07:49 +02:00
Alex Rønne Petersen
8285de62d5
Merge pull request #23745 from alexrp/target-os-versions
`std.Target`: Update supported OS version ranges
2025-05-12 16:59:46 +02:00
Linus Groh
abbead1fb8 libc: update macOS headers to SDK 15.2 2025-05-12 16:50:17 +02:00
Alex Rønne Petersen
2a55fcd03a
libtsan: Disable warnings when building. 2025-05-12 16:24:59 +02:00
Alex Rønne Petersen
d14f7f7a09
libtsan: Backport llvm/llvm-project#120036.
https://github.com/llvm/llvm-project/pull/120036
2025-05-12 16:24:59 +02:00
Alex Rønne Petersen
833d4c9ce4
Merge pull request #23835 from alexrp/freebsd-libc
Support dynamically-linked FreeBSD libc when cross-compiling
2025-05-12 01:19:23 +02:00
Alex Rønne Petersen
c3906718b3
Merge pull request #23810 from alexrp/more-test-targets 2025-05-11 20:52:47 +02:00
Alex Rønne Petersen
f3e851dbd0
compiler: Link libc by default when targeting FreeBSD.
We don't yet have a direct syscall layer in std.os.freebsd.
2025-05-11 11:15:23 +02:00
Alex Rønne Petersen
4c2f1e01a7
freebsd: Create strong references to __progname and environ in stub libc.so.
These symbols are defined in the statically-linked startup code. The real
libc.so.7 contains strong references to them, so they need to be put into the
dynamic symbol table.
2025-05-11 11:15:23 +02:00
Alex Rønne Petersen
6282129218
test: Add {powerpc64,riscv32}-netbsd-none to llvm_targets. 2025-05-11 11:15:23 +02:00
Alex Rønne Petersen
e8992af7f0
Compilation.Config: Default to dynamic linking with FreeBSD libc. 2025-05-11 11:15:09 +02:00
Alex Rønne Petersen
2116f2e3b2
Compilation: Don't pass -mabi to Clang on powerpc64(le)-freebsd.
The driver doesn't support it, and FreeBSD 13+ on PPC64 uses ELFv2 anyway.
2025-05-10 20:58:28 +02:00
Alex Rønne Petersen
d3a6236eef
compiler: Support building FreeBSD crt1.o/Scrt1.o and stub shared libraries.
Only works for FreeBSD 14+. Note that we still default to targeting FreeBSD 13.

Contributes to #2876.
2025-05-10 20:58:15 +02:00
Alex Rønne Petersen
837e0f9c37 std.Target: Remove ObjectFormat.nvptx (and associated linker code).
Textual PTX is just assembly language like any other. And if we do ever add
support for emitting PTX object files after reverse engineering the bytecode
format, we'd be emitting ELF files like the CUDA toolchain. So there's really no
need for a special ObjectFormat tag here, nor linker code that treats it as a
distinct format.
2025-05-10 12:21:57 +02:00
Alex Rønne Petersen
0e3609b8e0
std.Target: Factor arch/ABI into FreeBSD minimum OS version selection.
Based on data in std.zig.target.
2025-05-10 12:19:26 +02:00
Alex Rønne Petersen
eeaa1b17c6
std.zig.target: Add FreeBSD libc support. 2025-05-10 12:19:26 +02:00
Alex Rønne Petersen
9e23e1d16c
compiler: Define __FreeBSD_version when targeting FreeBSD libc. 2025-05-10 12:19:26 +02:00
Alex Rønne Petersen
be566a4c11
libc: Add FreeBSD libc abilists file.
Currently covers version 1.7 (FreeBSD 14.0.0).
2025-05-10 12:19:26 +02:00
Alex Rønne Petersen
68cd00497f
update_freebsd_libc: Add tool for updating FreeBSD libc startup code. 2025-05-10 12:19:26 +02:00
Alex Rønne Petersen
a36dcef7dc
libc: Add FreeBSD libc startup code from 14.2.0.
* NT_FREEBSD_ABI_TAG was manually adjusted from using a hardcoded value to using
  __FreeBSD_version which will be defined by the compiler.
* GCJ stuff was removed.
* HAVE_CTORS definitions were removed.
2025-05-10 12:19:26 +02:00
Alex Rønne Petersen
01390cc533
std.zig.LibCDirs: Add FreeBSD libc support. 2025-05-10 12:19:26 +02:00
Alex Rønne Petersen
6e64bc845f
libc: Add FreeBSD system and libc headers from 14.2.0.
osreldate.h and sys/param.h were manually adjusted to not __FreeBSD_version
since it will be defined by the compiler.
2025-05-10 12:19:26 +02:00
Alex Rønne Petersen
df719f249d
process_headers: Add FreeBSD libc support. 2025-05-10 12:19:26 +02:00
Alex Rønne Petersen
162b11b250
libcxxabi: Pass -fPIC via module options instead of CFLAGS. 2025-05-10 12:19:26 +02:00
Alex Rønne Petersen
610d3cf9de
compiler: Move vendored library support to libs subdirectory. 2025-05-10 12:19:26 +02:00
Alex Rønne Petersen
309ff9c34e
std.Target: Add isFreeBSDLibC() function. 2025-05-10 12:19:26 +02:00
Alex Rønne Petersen
46042170cb
std.Target: Fix requiresLibC() for FreeBSD. 2025-05-10 12:19:26 +02:00
Alex Rønne Petersen
ba9f2571b7
test: Remove some nonsensical FreeBSD targets from llvm_targets. 2025-05-10 12:19:26 +02:00
David
2c241b263c
Introduce common bzero libc implementation. (#23812)
* Introduce common `bzero` libc implementation.

* Update test name according to review

Co-authored-by: Linus Groh <mail@linusgroh.de>

* address code review

- import common implementation when musl or wasi is included
- don't use `c_builtins`, use `@memset`

* bzero calling conv to .c

* Apply review

Co-authored-by: Veikka Tuominen <git@vexu.eu>

---------

Co-authored-by: Linus Groh <mail@linusgroh.de>
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2025-05-10 10:37:21 +02:00
Alex Rønne Petersen
85431e745c libcxx: Backport llvm/llvm-project#137594. 2025-05-10 09:10:27 +02:00
Michael Pfaff
49c7318056 Fix implementation of std.os.linux.accept on x86 2025-05-10 02:24:33 +02:00
Pat Tullmann
6eb5e56306 std.posix: Add sigrtmin() and sigrtmax()
For C code the macros SIGRTMIN and SIGRTMAX provide these values.  In
practice what looks like a constant is actually provided by a libc call.
So the Zig implementations are explicitly function calls.

glibc (and Musl) export a run-time minimum "real-time" signal number,
based on how many signals are reserved for internal implementation details
(generally threading).  In practice, on Linux, sigrtmin() is 35 on glibc
with the older LinuxThread and 34 with the newer NPTL-based
implementation.  Musl always returns 35.  The maximum "real-time" signal
number is NSIG - 1 (64 on most Linux kernels, but 128 on MIPS).

When not linking a C Library, Zig can report the full range of "rt"
signals (none are reserved by Zig).

Fixes #21189
2025-05-09 15:10:25 +02:00
Alex Rønne Petersen
23cb2b2662
std.Target: Handle {powerpc64,riscv32}-netbsd in DynamicLinker.standard(). 2025-05-09 14:07:40 +02:00
Alex Rønne Petersen
85a6b75e18 glibc: Fix stub libraries containing unwanted symbols.
Closes #8096.
2025-05-09 13:16:35 +02:00
mlugg
787020b30b Compilation: don't warn about failure to delete missing C depfile
If clang encountered bad imports, the depfile will not be generated. It
doesn't make sense to warn the user in this case. In fact,
`FileNotFound` is never worth warning about here; it just means that
the file we were deleting to save space isn't there in the first place!
If the missing file actually affected the compilation (e.g. another
process raced to delete it for some reason) we would already error in
the normal code path which reads these files, so we can safely omit the
warning in the `FileNotFound` case always, only warning when the file
might still exist.

To see what this fixes, create the following file...

```c
#include <nonexist>
```

...and run `zig build-obj` on it. Before this commit, you will get a
redundant warning; after this commit, that warning is gone.
2025-05-09 11:52:26 +01:00
Meghan Denny
a5cfa3db3a std.os: handle ENOENT for fnctl on macos 2025-05-09 11:20:42 +02:00
HydroH
32bf1fbf46 std: fix error.Unexpected on certain Windows file operations
Closes #23690.
2025-05-09 08:57:00 +02:00
Alex Rønne Petersen
c3734450bc
test: Add MIPS N32 targets to the module test matrix. 2025-05-08 21:32:22 +02:00
Alex Rønne Petersen
473f36d70f
test: Add dynamic musl targets to the module test matrix.
Most of these are gated by -Dtest-extra-targets because:

* We don't really have CI resources to spare at the moment.
* They're relatively niche if you're not on a musl distro.
    * And the few musl distros that exist don't support all these targets.
* Quite a few of them are broken and need investigating.

x86_64-linux-musl and aarch64-linux-musl are not gated as they're the most
common targets that people will be running dynamic musl on, so we'll want to
have some bare minimum coverage of those.
2025-05-08 21:32:22 +02:00
Alex Rønne Petersen
c272ddc070
std: Disable os.linux.test.test.fallocate on MIPS N32.
https://github.com/ziglang/zig/issues/23809
2025-05-08 21:32:22 +02:00
Alex Rønne Petersen
2261d13759
std: Disable posix.test.test.fchmodat smoke test on MIPS N32.
https://github.com/ziglang/zig/issues/23808
2025-05-08 21:32:22 +02:00
Alex Rønne Petersen
dd1de18f96
std: Disable hash.xxhash.test.xxhash3 on MIPS N32.
https://github.com/ziglang/zig/issues/23807
2025-05-08 21:32:22 +02:00
Alex Rønne Petersen
d381645c73
std: Disable fs.test.test.setEndPos on MIPS N32.
https://github.com/ziglang/zig/issues/23806
2025-05-08 21:32:22 +02:00
Alex Rønne Petersen
b3f52ae339
test: Disable arrays and vectors with big integers on MIPS N32.
https://github.com/ziglang/zig/issues/23805
2025-05-08 21:32:22 +02:00
Alex Rønne Petersen
d3e8541268
std.Target: Prune dead targets in Abi.default() and DynamicLinker.standard(). 2025-05-08 21:32:20 +02:00
xdBronch
10bf6964ed translate-c: fix callconv attribute in macro 2025-05-07 16:15:51 +03:00
Seiichi Uchida
bbc21393b4 Add register_file_alloc_range 2025-05-06 18:01:07 +02:00
Alex Rønne Petersen
35f30558ad
std.Build: Rename --glibc-runtimes to --libc-runtimes and enable it for musl. 2025-05-06 01:52:47 +02:00
HydroH
a14352b0b2
std: fix compile errors in std.crypto.ecc (#23797)
Implemented `neg()` method for `AffineCoordinates` struct of p256,
p384 and secp256k1 curves.

Resolves: #20505 (partially)
2025-05-05 18:50:25 +00:00
David Rubin
369177f0ba
crypto: add sub function to Ristretto255 (#23724) 2025-05-05 15:30:59 +02:00
Alex Rønne Petersen
7401f06f99 compiler: Set libc++ ABI version to 2 for Emscripten.
It remains 1 everywhere else.

Also remove some code that allowed setting the libc++ ABI version on the
Compilation since there are no current plans to actually expose this in the CLI.
2025-05-05 14:34:05 +02:00
Alex Rønne Petersen
f0feda820e
Merge pull request #23727 from tjog/add-libfuzz-standalone-test
add standalone test for libfuzzer initialization
2025-05-05 07:23:18 +02:00
Xavier Bouchoux
bb79c85cb7 fix system library lookup when cross-compiling to windows-msvc 2025-05-04 10:57:04 +02:00
Alex Rønne Petersen
dffd18f133
Merge pull request #23752 from alexrp/static-native-glibc
compiler: Allow linking native glibc statically
2025-05-04 01:53:51 +02:00
tjog
0ba77eca74
disable getauxvalImpl instrumentation as libfuzzer's allocator may need to call it 2025-05-03 23:33:26 +02:00
Matthew Lugg
f4e9846bca
Merge pull request #23263 from mlugg/comptime-field-ptr
Sema: fix pointers to comptime fields of comptime-known aggregate pointers
2025-05-03 20:10:42 +01:00
mlugg
f83fe2714b compiler: fix comptime memory store bugs
* When storing a zero-bit type, we should short-circuit almost
  immediately. Zero-bit stores do not need to do any work.
* The bit size computation for arrays is incorrect; the `abiSize` will
  already be appropriately aligned, but the logic to do so here
  incorrectly assumes that zero-bit types have an alignment of 0. They
  don't; their alignment is 1.

Resolves: #21202
Resolves: #21508
Resolves: #23307
2025-05-03 20:10:26 +01:00
mlugg
ae1b444d6a std.Progress: fix many bugs
There were several bugs with the synchronization here; most notably an
ABA problem which was causing #21663. I fixed that and some other
issues, and took the opportunity to get rid of the `.seq_cst` orderings
from this file. I'm at least relatively sure my new orderings are correct.

Co-authored-by: achan1989 <achan1989@gmail.com>
Resolves: #21663
2025-05-03 20:09:51 +01:00
tjog
68700e5de1
link+macho+fuzz: use correct input type
A debug build of the compiler detects invalid union access since `classifyInputFile`
detects `.archive` and this line constructed a `.object` input.
2025-05-03 17:23:32 +02:00
tjog
3ed159964a
libfuzzer: add standalone test for libfuzzer initialization 2025-05-03 17:15:59 +02:00
Alex Rønne Petersen
bf9b15ee67 std.Target: Add Cpu.Arch.or1k and basic target info. 2025-05-03 11:22:27 +02:00
Alex Rønne Petersen
d2f92e1797
compiler: Link libunwind when linking glibc statically.
glibc's libc.a depends on the functions provided by libunwind.
2025-05-03 10:54:36 +02:00
Alex Rønne Petersen
f6476e9cae
compiler: Allow linking native glibc statically.
This is generally ill-advised, but can be useful in some niche situations where
the caveats don't apply. It might also be useful when providing a libc.txt that
points to Eyra.
2025-05-03 10:54:33 +02:00
Alex Rønne Petersen
ae38575b42
compiler: Rename misleading libcNeedsLibUnwind() function.
It's about libc++, not libc.
2025-05-03 10:31:31 +02:00
samy007
c0ec264f75 inline assembly: implement gcc's "%=" syntax 2025-05-02 23:09:39 +02:00
Alex Rønne Petersen
c1fc353923
std.Target: Update maximum supported Vulkan version. 2025-05-02 19:56:00 +02:00
Alex Rønne Petersen
8b7f512b9a
std.Target: Update maximum supported CUDA version. 2025-05-02 19:55:58 +02:00
Alex Rønne Petersen
3af2594df5
std.Target: Update supported AMD ROCm version range. 2025-05-02 19:55:08 +02:00
Alex Rønne Petersen
b3977695bd
std.Target: Update supported Apple OS version ranges. 2025-05-02 19:54:48 +02:00
Alex Rønne Petersen
be8b6b5435
std.Target: Update supported OpenBSD version range. 2025-05-02 19:54:34 +02:00
Alex Rønne Petersen
f3bf26138c
std.Target: Update maximum supported Dragonfly BSD version. 2025-05-02 19:54:10 +02:00
Alex Rønne Petersen
9013d9ed78
std.Target: Update maximum supported AIX version. 2025-05-02 19:53:58 +02:00
Alex Rønne Petersen
2f999dd3af
std.Target: Update supported Hermit version range. 2025-05-02 19:52:47 +02:00
Alex Rønne Petersen
cb4022b039
std.Target: Update supported Fuchsia version range. 2025-05-02 19:52:23 +02:00
Pavel Verigo
a843be44a0 wasm-c-abi: llvm fix struct handling + reorganize
I changed to `wasm/abi.zig`, this design is certainly better than the previous one. Still there is some conflict of interest between llvm and self-hosted backend, better design will appear when abi tests will be tested with self-hosted.

Resolves: #23304
Resolves: #23305
2025-05-01 18:10:36 -04:00
Alex Rønne Petersen
ad9cb40112
Merge pull request #23601 from rootbeer/sig-split
Split glibc and linux sigset_t ABIs and the accessor functions
2025-05-01 21:29:23 +02:00
David John
971d19a3b2 fix(windows): handle commitment limit error in CreateProcessW 2025-05-01 19:25:27 +02:00
Cutie Deng
c1649d586a fix mount api
- mount syscall allow `source` to be null
2025-05-01 06:47:56 +02:00
Pat Tullmann
a55ecd7532 std.os.linux: Fix MIPS signal numbers
Dunno why the MIPS signal numbers are different, or why Zig had them
already special cased, but wrong.

We have the technology to test these constants.  We should use it.
2025-04-30 20:32:04 -07:00
Pat Tullmann
cf989374e9 linux: update sigmask in every arch ucontext_t
All the existing code that manipulates `ucontext_t` expects there to be a
glibc-compatible sigmask (1024-bit).  The `ucontext_t` struct need to be
cleaned up so the glibc-dependent format is only used when linking
glibc/musl library, but that is a more involved change.

In practice, no Zig code looks at the sigset field contents, so it just
needs to be the right size.
2025-04-30 20:32:04 -07:00
Pat Tullmann
120c4789c3 sigset_t: sigemptyset() and sigfillset() are functions that return sigset_t
By returning an initialized sigset (instead of taking the set as an output
parameter), these functions can be used to directly initialize the `mask`
parameter of a `Sigaction` instance.
2025-04-30 20:32:04 -07:00
Pat Tullmann
f0aefa625b posix: remove empty_sigset
When linking a libc, Zig should defer to the C library for sigset
operations.  The pre-filled constants signal sets (empty_sigset,
filled_sigset) are not compatible with C library initialization, so remove
them and use the runtime `sigemptyset` and `sigfillset` methods to
initialize any sigset.
2025-04-30 20:32:04 -07:00
Pat Tullmann
d16079d79a posix.zig: export sigset_t and matching operations from system
Unify the C library sigset_t and Linux native sigset_t and the accessor
operations.

Add tests that the various sigset_t operations are working.  And clean up
existing tests a bit.
2025-04-30 20:32:04 -07:00
Pat Tullmann
298b1886b2 std.os.linux: export kernel-sized sigset_t and operations
The kernel ABI sigset_t is smaller than the glibc one.  Define the
right-sized sigset_t and fixup the sigaction() wrapper to leverage it.
The Sigaction wrapper here is not an ABI, so relax it (drop the "extern"
and the "restorer" fields), the existing `k_sigaction` is the ABI
sigaction struct.

Linux defines `sigset_t` with a c_ulong, so it can be 32-bit or 64-bit,
depending on the platform.  This can make a difference on big-endian
systems.

Patch up `ucontext_t` so that this change doesn't impact its layout.
AFAICT, its currently the glibc layout.
2025-04-30 20:32:04 -07:00
Pat Tullmann
51654aea87 c.zig: glibc/musl export 1024-bit sigset_t
Export the sigset_t ops (sigaddset, etc) from the C library.  Don't rely
on the linux.zig defintions (which will be defined to use the kernel ABI).

Move Darwin sigset and NSIG declarations into darwin.zig.  Remove
extraneous (?) sigaddset.  The C library sigaddset can reject some signals
being added, so need to defer to it.
2025-04-30 20:32:04 -07:00
psbob
9f7c8b8b1b
Fix Unexpected error for 1453 on Windows (#23729) 2025-04-30 22:48:16 +00:00
Robin Voetter
cc381d56a6
Merge pull request #23654 from alichraghi/continue
Compilation: don't build compiler_rt or ubsan_rt for amdgcn and ptx
2025-04-30 20:46:12 +02:00
Shun Sakai
195471a98d
test(std.mem): Remove trimStart and trimEnd from test trim 2025-04-30 19:59:59 +09:00
Deatil
8e79fc64cd
fixed codecs.zig (#23706) 2025-04-29 22:07:30 +00:00
Dongjia Zhang
535a0c4270 use correcct symbol for the end of pcguard section 2025-04-30 00:04:22 +02:00
Alex Rønne Petersen
399da543e5
Merge pull request #23720 from alexrp/sparc-stuff 2025-04-29 00:34:01 +02:00
Andrew Kelley
8facd99d41
Merge pull request #23708 from ziglang/memmove-followups
`@memmove` followups
2025-04-28 15:06:18 -04:00
mlugg
d038676a1f Sema: fix a few indexing bugs
* Indexing zero-bit types should not produce AIR indexing instructions
* Getting a runtime-known element pointer from a many-pointer should
  check that the many-pointer is not comptime-only

Resolves: #23405
2025-04-28 19:43:58 +01:00
dweiller
365ed0ed68 sema: do checked cast when resolving aggregate size 2025-04-28 16:48:45 +01:00
Alex Rønne Petersen
1f6336794b wasi-libc: Fix paths to psignal.c and strsignal.c.
Closes #23709.
2025-04-28 13:36:11 +02:00
Alex Rønne Petersen
12f56b8740
test: Disable vector reduce operation for sparc.
https://github.com/ziglang/zig/issues/23719
2025-04-28 12:05:19 +02:00
Alex Rønne Petersen
fd4fcefe8a
test: Disable some varargs behavior tests on sparc.
https://github.com/ziglang/zig/issues/23718
2025-04-28 12:05:19 +02:00
Alex Rønne Petersen
d7e8337909
std.os.linux: Add missing time_t definition for sparc64. 2025-04-28 12:05:19 +02:00
Alex Rønne Petersen
2c5f54c898
compiler-rt: Add missing _Qp_sqrt export for sparc64.
https://github.com/ziglang/zig/issues/23716
2025-04-28 12:05:19 +02:00
Ali Cheraghi
9bd8f8ed56 test: skip "struct fields get automatically reordered" for spirv64 backend 2025-04-28 10:49:19 +03:30
Ali Cheraghi
710f9325ff Compilation: don't build compiler_rt for amdgcn and ubsan_rt for ptx 2025-04-28 10:49:17 +03:30
Ali Cheraghi
296b17f37b spirv: allow offset_and_cast for vectors when possible 2025-04-28 10:42:33 +03:30
Andrew Kelley
8be4511061 C backend: less branching 2025-04-27 23:30:00 -07:00
Andrew Kelley
7bd3207921 make @memcpy and @memmove share panic handlers 2025-04-27 23:30:00 -07:00
Alex Rønne Petersen
fc55c1b7a1
Merge pull request #23698 from alexrp/goff-xcoff-stubs
`link`: Stub out GOFF/XCOFF linker code based on LLVM
2025-04-28 07:50:37 +02:00
xdBronch
410298271e Sema: fix memcpy with C pointers 2025-04-28 05:09:12 +01:00
mlugg
81277b5487
cbe: aggregate assignment does not need a second cast
`writeCValue` already emits a cast; including another here is, in fact,
invalid, and emits errors under MSVC. Probably this code was originally
added to work around the incorrect `.Initializer` location which was
fixed in the previous commit.
2025-04-28 02:38:07 +01:00
Alex Rønne Petersen
78df3c9301
Merge pull request #23663 from alexrp/emit-asm-only 2025-04-28 02:18:45 +02:00
Jacob Young
029cc0640f
cbe: assignment is not initialization
Turns out the backend currently never emits a non-static initializer,
but the handling is kept in case it is needed again in the future.
2025-04-28 01:14:24 +01:00
mlugg
95932e98e5
Sema: fix alignment of runtime field pointer of underaligned tuple 2025-04-28 01:14:24 +01:00
mlugg
d4c5396646
Sema: fix pointers to comptime fields of comptime-known aggregate pointers
Resolves: #23190
2025-04-28 01:14:22 +01:00
Alex Rønne Petersen
5ed8bd5c85 Sema: Fix some ptr alignment checks to handle a potential ISA tag bit.
Closes #23570.
2025-04-27 23:54:54 +01:00
Alex Rønne Petersen
e7b46363ae std.Target: Remove Os.Tag.elfiamcu.
The last Intel Quark MCU was released in 2015. Quark was announced to be EOL in
2019, and stopped shipping entirely in 2022.

The OS tag was only meaningful for Intel's weird fork of Linux 3.8.7 with a
special ABI that differs from the regular i386 System V ABI; beyond that, the
CPU itself is just a plain old P54C (i586). We of course keep support for the
CPU itself, just not Intel's Linux fork.
2025-04-28 00:24:09 +02:00
Andrew Kelley
1b76d4c53a
Merge pull request #22605 from dweiller/memmove
add `@memmove` builtin
2025-04-27 14:39:21 -04:00
Shun Sakai
227d2b15e4 docs(std.ascii): Remove redundant three slashes 2025-04-27 19:37:43 +02:00
Kevin Primm
19b43ee627 compiler: Fix -m<os>-version-min=... ordering 2025-04-27 19:28:48 +02:00
psbob
d92649da80
Update Windows ReadFile and WriteFile to recognise Access Denied error when a read or write is attempted on a disconnected virtual com port 2025-04-27 14:42:15 +00:00
Alex Rønne Petersen
711e055f18
test: Uncomment a bunch of targets in llvm_targets. 2025-04-27 14:09:32 +02:00
Alex Rønne Petersen
b31b309b53
test: Configure emit_asm/emit_bin correctly for some targets in llvm_targets. 2025-04-27 14:09:05 +02:00
Alex Rønne Petersen
5411358956
test: Allow cases to set emit_asm (defaults to false). 2025-04-27 14:09:05 +02:00
Alex Rønne Petersen
26bb429093
compiler: Reject using LLVM for csky and xtensa.
These backends are completely unusable at the moment; they can produce neither
assembly files nor object files. So give a nicer error when users try to use
them.
2025-04-27 14:09:05 +02:00
Alex Rønne Petersen
386b869ec4
compiler: Error if the user targets arc with -femit-bin.
LLVM can only produce assembly files for this target currently.
2025-04-27 14:09:05 +02:00
Alex Rønne Petersen
3e7708b02b
link.Elf: Skip invoking LLD for zig build-obj for unsupported targets.
LLD doesn't support these yet. Doing this hack will at least allow basic
experimentation for these targets.
2025-04-27 14:09:05 +02:00
Alex Rønne Petersen
b16c094926
Merge pull request #23691 from alexrp/llvm-targets-updates 2025-04-27 11:50:06 +02:00
Shun Sakai
5fc4448e45 chore(std.mem): Rename trimLeft and trimRight
Rename `trimLeft` to `trimStart`, and `trimRight` to `trimEnd`.
`trimLeft` and `trimRight` functions remain as deprecated aliases for
these new names.
2025-04-27 18:03:59 +09:00
mlugg
3783b1b23c std.Build.Cache: fix several bugs
Aside from adding comments to document the logic in `Cache.Manifest.hit`
better, this commit fixes two serious bugs.

The first, spotted by Andrew, is that when upgrading from a shared to an
exclusive lock on the manifest file, we do not seek it back to the
start. This is a simple fix.

The second is more subtle, and has to do with the computation of file
digests. Broadly speaking, the goal of the main loop in `hit` is to
iterate the files listed in the manifest file, and check if they've
changed, based on stat and a file hash. While doing this, the
`bin_digest` field of `std.Build.Cache.File`, which is initially
`undefined`, is populated for all files, either straight from the
manifest (if the stat matches) or recomputed from the file on-disk. This
file digest is then used to update `man.hash.hasher`, which is building
the final hash used as, for instance, the output directory name when the
compiler emits into the cache directory. When `hit` returns a cache
miss, it is expected that `man.hash.hasher` includes the digests of all
"initial files"; that is, those which have been already added with e.g.
`addFilePath`, but not those which will later be added with
`addFilePost` (even though the manifest file has told us about some such
files). Previously, `hit` was using the `unhit` function to do this in a
few cases. However, this is incorrect, because `hit` assumes that all
files already have their `bin_digest` field populated; this function is
only valid to call *after* `hit` returns. Instead, we need to actually
compute the hashes which haven't yet been populated. Even if this logic
has been working, there was still a bug here, because we called `unhit`
when upgrading from a shared to an exclusive lock, writing the
(potentially `undefined`) file digests, but the loop itself writes the
file digests *again*! All in all, the hashing logic here was actually
incredibly broken.

I've taken the opportunity to restructure this section of the code into
what I think is a more readable format. A new function,
`hitWithCurrentLock`, uses the open manifest file to try and find a
cache hit. It returns a tagged union which, in the miss case, tells the
caller (`hit`) how many files already have their hash populated. This
avoids redundant work recomputing the same hash multiple times in
situations where the lock needs upgrading. This also eliminates the
outer loop from `hit`, which was a little confusing because it iterated
no more than twice!

The bugs fixed here could manifest in several different ways depending
on how contended file locks were satisfied. Most notably, on a cache
miss, the Zig compiler might have written the compilation output to the
incorrect directory (because it incorrectly constructed a hash using
`undefined` or repeated file digests), resulting in all future hits on
this manifest causing `error.FileNotFound`. This is #23110. I have been
able to reproduce #23110 on `master`, and have not been able to after
this commit, so I am relatively sure this commit resolves that issue.

Resolves: #23110
2025-04-27 05:42:18 +01:00
Alex Rønne Petersen
2d44bc5d2b
test: Add powerpc(64)-aix to llvm_targets. 2025-04-27 03:54:32 +02:00
Alex Rønne Petersen
5502a820e8
llvm: Fix data layout string for s390x-zos. 2025-04-27 03:54:32 +02:00
Alex Rønne Petersen
30e254fc31
link: Stub out GOFF/XCOFF linker code based on LLVM.
This allows emitting object files for s390x-zos (GOFF) and powerpc(64)-aix
(XCOFF).

Note that GOFF emission in LLVM is still being worked on upstream for LLVM 21;
the resulting object files are useless right now. Also, -fstrip is required, or
LLVM will SIGSEGV during DWARF emission.
2025-04-27 03:52:52 +02:00
Alex Rønne Petersen
b59f7f0726
test: Remove sparc(64)-illumos from llvm_targets.
Illumos dropped support for SPARC many years ago.
2025-04-27 02:53:46 +02:00
Alex Rønne Petersen
962b491745
test: Remove sparc-solaris and x86-solaris from llvm_targets.
These are no longer supported.
2025-04-27 02:53:45 +02:00
Alex Rønne Petersen
d9122e9f15
test: Remove some thumb(eb)-*-* targets from llvm_targets.
There is no evidence that these operating systems support pure Thumb, not even
just in userland.
2025-04-27 02:53:33 +02:00
Alex Rønne Petersen
c974590525
test: Remove mips(64)(el)-freebsd targets from llvm_targets.
These were dropped in FreeBSD 14 and we're not going to add e.g. libc support
for them anyway, so they're effectively dead to us.
2025-04-27 01:13:50 +02:00
Alex Rønne Petersen
5668c8b7ba std.Target: Bump minimum glibc to 2.34 for arches migrating to 64-bit time.
https://github.com/ziglang/zig/issues/21738#issuecomment-2822411842
2025-04-27 00:24:55 +02:00
Alex Rønne Petersen
b3537d0f4a compiler: Allow configuring UBSan mode at the module level.
* Accept -fsanitize-c=trap|full in addition to the existing form.
* Accept -f(no-)sanitize-trap=undefined in zig cc.
* Change type of std.Build.Module.sanitize_c to std.zig.SanitizeC.
* Add some missing Compilation.Config fields to the cache.

Closes #23216.
2025-04-26 22:54:34 +02:00
Alex Rønne Petersen
23440fbb99 std.Target: Remove Abi.gnuilp32.
* This has not seen meaningful development for about a decade.
* The Linux kernel port was never upstreamed.
* The glibc port was never upstreamed.
* GCC 15.1 recently deprecated support it.

It may still make sense to support an ILP32 ABI on AArch64 more broadly (which
we already have the Abi.ilp32 tag for), but, to the extent that it even existed
in any "official" sense, the *GNU* ILP32 ABI is certainly dead.
2025-04-26 22:12:31 +02:00
Alex Rønne Petersen
99a79f98ec
Merge pull request #23572 from alexrp/zig-cc-static-dynamic 2025-04-26 15:05:18 +02:00
Carter Snook
573d9aab5e std.c: use arch's ino_t and off_t for dirent
Fixes #23622. The integer types used for these fields before would not
work on some platforms.
2025-04-26 14:55:59 +02:00
tjog
2e35fdd032 fuzz: fix expected section start/end symbol name on MacOS when linking libfuzzer
Not only is the section name when adding the sancov variables different.

The linker symbol ending up in the binary is also different.

Reference: 60105ac6ba/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp (L1076-L1104)
2025-04-26 14:35:03 +02:00
Michael Pfaff
69007f0961 Calculate WTF-8 length before converting instead of converting into an intermediate buffer on the stack 2025-04-26 14:31:28 +02:00
dweiller
2e9c1553ef std: deprecate std.mem.copy{Forwards,Backwards} 2025-04-26 13:34:17 +10:00
dweiller
5cba7c8562 langref: document @memmove 2025-04-26 13:34:17 +10:00
dweiller
4e78836d29 test: add tests for @memmove 2025-04-26 13:34:17 +10:00
dweiller
898ca82458 compiler: add @memmove builtin 2025-04-26 13:34:16 +10:00
dweiller
b9f440620d test: add error return to memcpy_len_mismatch and memcpy_alias 2025-04-26 13:34:16 +10:00
Ryan Liptak
c06fecd466 FailingAllocator: remove outdated doc comments, move doc comment example to decltest
Note: The decltests for files-as-a-struct don't show up in autodoc currently
2025-04-23 19:28:28 -04:00
mlugg
927f233ff8 compiler: allow emitting tests to an object file
This is fairly straightforward; the actual compiler changes are limited
to the CLI, since `Compilation` already supports this combination.

A new `std.Build` API is introduced to allow representing this. By
passing the `emit_object` option to `std.Build.addTest`, you get a
`Step.Compile` which emits an object file; you can then use that as you
would any other object, such as either installing it for external use,
or linking it into another step.

A standalone test is added to cover the build system API. It builds a
test into an object, and links it into a final executable, which it then
runs.

Using this build system mechanism prevents the build system from
noticing that you're running a `zig test`, so the build runner and test
runner do not communicate over stdio. However, that's okay, because the
real-world use cases for this feature don't want to do that anyway!

Resolves: #23374
2025-04-22 22:50:36 +01:00
Matthew Lugg
6a7ca4b8b0
Merge pull request #23617 from mlugg/incr-fixes
incremental: fixes
2025-04-22 18:04:52 +01:00
Ali Cheraghi
ffd85ffcda revive nvptx linkage 2025-04-21 10:45:05 +02:00
Ali Cheraghi
13541bc1c0 Module: ignore xnack and sramecc features on some gpu models 2025-04-21 09:49:19 +02:00
mlugg
8c9c24e09b
compiler: integrate @compileLog with incremental compilation
Compile log output is now separated based on the `AnalUnit` which
perfomred the `@compileLog` call, so that we can omit the output for
unreferenced ("dead") units. The units are also sorted when collecting
the `ErrorBundle`, so that compile logs are always printed in a
consistent order, like compile errors are. This is important not only
for incremental compilation, but also for parallel analysis.

Resolves: #23609
2025-04-20 18:11:53 +01:00
mlugg
6561a98a61
incremental: correctly handle dead exporters
Resolves: #23604
2025-04-20 18:11:53 +01:00
Frank Denis
f01833e03e
crypto.ecdsa: add the ability to sign/verify prehashed messages (#23607) 2025-04-20 04:27:10 +02:00
Vadzim Dambrouski
86d3546184
Fix compile error in Fuzzer web-ui (#23605)
* Fix compile error in Fuzzer web-ui

The error was:
```
error: expected type '?mem.Alignment', found 'comptime_int'
```

* Apply suggestions from code review

`.of` call is shorter and clearer

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>

---------

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>
2025-04-19 23:10:51 +02:00
Alex Rønne Petersen
8f8f37fb0f test: Add powerpc-linux-gnueabi(hf) to the module test matrix.
Skips std tests for now: https://github.com/ziglang/zig/issues/2256
2025-04-17 17:32:33 +02:00
Alex Rønne Petersen
3be6809e27
Merge pull request #23217 from selfisekai/cmake-release-safe
* cmake: Add ZIG_RELEASE_SAFE option to build as ReleaseSafe
* cmake: Map MinSizeRel to ReleaseSmall.
2025-04-17 04:18:23 +02:00
Pavel Otchertsov
dc090e99cf cmake: support static linking against libxml2 2025-04-16 22:56:27 +02:00
Tobias Simetsreiter
5be3c7874c
std.tar: pass entry kind to rootDir to avoid setting root_dir to file (#23456) 2025-04-16 19:17:25 +00:00
Alex Rønne Petersen
f2363623e1
cmake: Map MinSizeRel to ReleaseSmall. 2025-04-16 20:46:41 +02:00
Alex Rønne Petersen
1a2ceb36c8
Merge pull request #23573 from samy-00007/bigint-shift-fix
std.math.big.int: fix a bug in `llshl` and update test syntax
2025-04-16 18:28:25 +02:00
samy007
8ae9ac6df4 improve test syntax for better stack trace in case of failure 2025-04-16 11:10:22 +02:00
Andrew Kelley
3746b3d93c
Merge pull request #21741 from kj4tmp/langref-packed-structs
langref: improve packed struct memory layout description
2025-04-16 04:56:22 -04:00
Andrew Kelley
bd38c417fc langref: reword some packed struct text and example 2025-04-15 19:19:23 -07:00
kj4tmp@gmail.com
a8621731ec langref: packed struct documentation 2025-04-15 19:17:07 -07:00
phatchman
ae38fc6a50
Return FileNotFound when CreateProcessW is called with a missing path (#23567) 2025-04-15 21:39:44 +00:00
Андрей Краевский
530228d953
Deprecate std.enums.nameCast. 2025-04-15 23:36:43 +02:00
Ryan King
6c598e8341 std: add os.linux.sysinfo(), use it for process.totalSystemMemory()
Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>
2025-04-15 20:08:59 +02:00
Frank Denis
933beb4cbd
crypto.ecdsa: stricter DER decoding of signatures (#23554)
Reject DER-encoded signatures with the top bit set but no leading
0x00

Also add test vectors from Project Wycheproof with ECDSA-P384
2025-04-15 18:12:12 +02:00
Alex Rønne Petersen
76da028239 ci: Bump aarch64-linux timeout to 9 hours.
These seem to be timing out under load lately.
2025-04-14 21:34:19 -04:00
Alex Rønne Petersen
85b3d02f76 ci: Bump x86_64-linux timeout to 8 hours.
We were really close to the timeout previously, and we recently added
hexagon-linux and loongarch64-linux to the test matrix.
2025-04-14 21:34:19 -04:00
samy007
c813b6a900 std.math.big: add and update tests 2025-04-14 22:54:10 +02:00
Chris Boesch
206bd1ced8
Merge pull request #23268 from chrboesch/i19875
std.posix: Added 'error.ProcessNotFound' where necessary
2025-04-14 22:20:44 +02:00
Alex Rønne Petersen
6a8228603c
zig cc: Respect Clang's -static and -dynamic flags.
Before:

    ❯ zig cc main.c -target x86_64-linux-musl && musl-ldd ./a.out
    musl-ldd: ./a.out: Not a valid dynamic program
    ❯ zig cc main.c -target x86_64-linux-musl -static && musl-ldd ./a.out
    musl-ldd: ./a.out: Not a valid dynamic program
    ❯ zig cc main.c -target x86_64-linux-musl -dynamic && musl-ldd ./a.out
    musl-ldd: ./a.out: Not a valid dynamic program

After:

    ❯ zig cc main.c -target x86_64-linux-musl && musl-ldd ./a.out
    musl-ldd: ./a.out: Not a valid dynamic program
    ❯ zig cc main.c -target x86_64-linux-musl -static && musl-ldd ./a.out
    musl-ldd: ./a.out: Not a valid dynamic program
    ❯ zig cc main.c -target x86_64-linux-musl -dynamic && musl-ldd ./a.out
            /lib/ld-musl-x86_64.so.1 (0x72c10019e000)
            libc.so => /lib/ld-musl-x86_64.so.1 (0x72c10019e000)

Closes #11909.
2025-04-14 22:10:08 +02:00
Alex Rønne Petersen
715984340b
compiler: MinGW-w64 import libs should not count towards any_dyn_libs.
They are, themselves, static libraries even if the resulting artifact strictly
speaking requires dynamic linking to the corresponding system DLLs to run. Note,
though, that there's no libc-provided dynamic linker on Windows like on POSIX,
so this isn't particularly problematic.

This matches x86_64-w64-mingw32-gcc behavior.
2025-04-14 21:10:29 +02:00
samy007
b08924e938 std.math.big.int: changed llshr and llshl implementation 2025-04-14 20:46:06 +02:00
Alex Rønne Petersen
667035fc78 std.Build.Step: Don't capture a stack trace if !std.debug.sys_can_stack_trace. 2025-04-14 06:06:07 +02:00
Andrew Kelley
2cb69e53b4
Merge pull request #23541 from alexrp/linux-5.10
`std.Target`: Bump minimum Linux kernel and glibc versions according to Debian LTS
2025-04-13 17:25:34 -04:00
samy007
b635b37249 std.math.big.int: remove setRuntimeSafety 2025-04-13 21:07:11 +02:00
Alex Rønne Petersen
e24e9ff7bd
Merge pull request #23555 from alexrp/gitattributes
Some `.gitattributes` updates
2025-04-13 09:24:33 +02:00
Andrew Kelley
f32a5d349d std: eradicate u29 and embrace std.mem.Alignment 2025-04-13 02:20:32 -04:00
Bingwu Zhang
ec28888581 doc: Bump LLVM version in README
Reported-by: Ricky8955555 <rkmiao@duck.com>
Signed-off-by: Bingwu Zhang <xtex@aosc.io>
2025-04-13 08:11:40 +02:00
Alex Rønne Petersen
6eabdc8972 link: Improve handling of --build-id when using LLD. 2025-04-13 01:46:15 +02:00
Luis Cáceres
d5ac3be608 src/libunwind.zig: Fix symbol visibility macro define
The define was changed in commit 729899f7b6bf6aff65988d895d7a639391a67608
in upstream llvm.
2025-04-12 22:27:28 +02:00
Alex Rønne Petersen
01aeb2f296
.gitattributes: Fix lib/libtsan path after ee0ff134e9f82bf87751a5174c27b191c04e16c0. 2025-04-12 20:30:38 +02:00
Alex Rønne Petersen
c3a408e245
.gitattributes: Add more testdata directories. 2025-04-12 20:30:11 +02:00
Frank Denis
a7122b7323
std.crypto: add constant-time codecs (#23420)
std.crypto: add constant-time codecs

Add constant-time hex/base64 codecs designed to process cryptographic
secrets, adapted from libsodium's implementations.

Introduce a `crypto.codecs` namespace for crypto-related encoders and
decoders. Move ASN.1 codecs to this namespace.

This will also naturally accommodate the proposed PEM codecs.
2025-04-12 20:13:45 +02:00
Alex Rønne Petersen
9352f379e8
Merge pull request #23529 from alexrp/2879-groundwork
Introduce libzigc for libc function implementations in Zig
2025-04-12 18:14:17 +02:00
Andrew Kelley
4e700fdf8e
Merge pull request #22516 from Jan200101/PR/build_id_option
std.Build: add build-id option
2025-04-11 16:37:46 -04:00
Andrew Kelley
65bd8d52c8
Merge pull request #23061 from pavelverigo/stage2-wasm-misc
stage2-wasm: multiple fixes
2025-04-11 15:56:35 -04:00
Andrew Kelley
08a6c4ca9b
Merge pull request #23272 from squeek502/getenvw-optim
Windows: Faster `getenvW` and a standalone environment variable test
2025-04-11 15:46:34 -04:00
g-logunov
326f254972
std.posix.getenv: early-return comparison (#23265)
Fixes std.posix.getenv() being slower than musl getenv() even when linking libc
2025-04-11 12:44:18 -07:00
kcbanner
fa59153896 Value: ensure that extern structs have their layout resolved in ptrField 2025-04-11 15:30:20 -04:00
Alex Rønne Petersen
2527c82482
std.os.linux: Use faccessat2 syscall in faccessat().
Only the former has a flags parameter. It's only available in Linux 5.8+.

Closes #16606.
2025-04-11 21:17:35 +02:00
Alex Rønne Petersen
46d03c5afa
std.Target: Bump minimum glibc version to 2.31.
This is the version in Debian LTS (bullseye).
2025-04-11 21:11:20 +02:00
Alex Rønne Petersen
731d6531bf
std.Target: Bump minimum Linux kernel version to 5.10.
This is the kernel in Debian LTS (bullseye).
2025-04-11 21:10:55 +02:00
Alex Rønne Petersen
90084f4ae3
Merge pull request #23483 from alexrp/target-int-functions
compiler: Move int size/alignment functions to `std.Target` and `std.zig.target`
2025-04-11 17:40:47 +02:00
Alex Rønne Petersen
1f896c1bf8
Introduce libzigc for libc function implementations in Zig.
This lays the groundwork for #2879. This library will be built and linked when a
static libc is going to be linked into the compilation. Currently, that means
musl, wasi-libc, and MinGW-w64. As a demonstration, this commit removes the musl
C code for a few string functions and implements them in libzigc. This means
that those libzigc functions are now load-bearing for musl and wasi-libc.

Note that if a function has an implementation in compiler-rt already, libzigc
should not implement it. Instead, as we recently did for memcpy/memmove, we
should delete the libc copy and rely on the compiler-rt implementation.

I repurposed the existing "universal libc" code to do this. That code hadn't
seen development beyond basic string functions in years, and was only usable-ish
on freestanding. I think that if we want to seriously pursue the idea of Zig
providing a freestanding libc, we should do so only after defining clear goals
(and non-goals) for it. See also #22240 for a similar case.
2025-04-11 17:12:31 +02:00
Jacob Young
27cfff8f44 x86_64: pass exact integer bit sizes to compiler-rt routines
This was a hack around compiler-rt not computing the correct size.
2025-04-11 07:06:01 -04:00
Jacob Young
b31a91bbef compiler-rt: compute correct integer sizes from bits at runtime
Also, accepting `align(1)` pointers ensures that the alignment is safety
checked rather than assumed.
2025-04-11 07:06:01 -04:00
Alex Rønne Petersen
ed9aa8f259 compiler: Move int size/alignment functions to std.Target and std.zig.target.
This allows using them in e.g. compiler-rt.
2025-04-11 05:22:00 -04:00
Alex Rønne Petersen
0132be7bf3 std.Target: Rename charSignedness() to cCharSignedness().
To be consistent with the other functions that answer C ABI questions.
2025-04-11 05:22:00 -04:00
Jacob Young
c82e1fe880
Merge pull request #23355 from jacobly0/x86_64-rewrite
x86_64: start rewriting overflow operations
2025-04-11 05:21:44 -04:00
Alex Rønne Petersen
9e21ba12d5 libcxx: Backport llvm/llvm-project#134874.
https://github.com/llvm/llvm-project/pull/134874
2025-04-11 09:05:44 +02:00
Alex Rønne Petersen
8f03217f3e
Merge pull request #23497 from alexrp/hexagon
Some `hexagon-linux` porting work
2025-04-11 08:42:53 +02:00
Alex Rønne Petersen
d01f2aa6e7
test: Add hexagon-linux-(none,musl) to the test matrix.
This skips std tests for now: https://github.com/llvm/llvm-project/pull/111217
2025-04-11 02:29:27 +02:00
Alex Rønne Petersen
01b5e8b296
std: Disable some vector-related tests for hexagon.
See:

* https://github.com/llvm/llvm-project/issues/118879
* https://github.com/llvm/llvm-project/issues/134659
2025-04-11 02:28:35 +02:00
Alex Rønne Petersen
382aa48f04
test: Disable a bunch of vector behavior tests for hexagon.
Most of the failures are:

* https://github.com/llvm/llvm-project/issues/118879
* https://github.com/llvm/llvm-project/issues/134659

But some are also miscompilations leading to wrong results. I'm not going to
investigate the latter further until all the backend crashes have been resolved.
2025-04-11 02:28:35 +02:00
Alex Rønne Petersen
0a5c088ecc
compiler: Add hexagon-linux-musl support.
Closes #21588.
2025-04-11 02:28:35 +02:00
Alex Rønne Petersen
e939fc859d
musl: Update libc.S for hexagon-linux-musl. 2025-04-11 02:28:35 +02:00
Alex Rønne Petersen
7f20b9f9db
musl: Add hexagon-linux-musl headers. 2025-04-11 02:28:35 +02:00
Alex Rønne Petersen
3df67dc414
musl: Add hexagon-linux-musl sources.
This is from Qualcomm's fork: https://github.com/quic/musl

I maintain a fork of musl where I rebase Qualcomm's changes on top of the latest
musl release, which I then use as the basis for musl updates in Zig. My fork can
be found here: https://github.com/alexrp/musl/tree/hexagon
2025-04-11 02:28:35 +02:00
Alex Rønne Petersen
30200edc1e
gen_stubs: Add hexagon-linux-musl support. 2025-04-11 02:28:35 +02:00
Alex Rønne Petersen
cd58615c17
process_headers: Add hexagon-linux-musl support. 2025-04-11 02:28:35 +02:00
Alex Rønne Petersen
2174014349
wasi-libc: Remove pointless alltypes.h.in file. 2025-04-11 02:28:35 +02:00
Alex Rønne Petersen
ee0ff134e9
tsan: Rename lib/tsan to lib/libtsan.
For consistency with other vendored C/C++ libraries.
2025-04-11 02:08:18 +02:00
Alex Rønne Petersen
71a237e764
std.zig.system: Force soft_float feature on for MIPS soft float targets.
Workaround for: https://github.com/llvm/llvm-project/issues/135283
2025-04-11 02:08:18 +02:00
Pat Tullmann
4b63f94b4e Fix sigaddset/sigdelset bit-fiddling math
The code was using u32 and usize interchangably, which doesn't work on
64-bit systems.  This:
  `pub const sigset_t = [1024 / 32]u32;`
is not consistent with this:
  `const shift = @as(u5, @intCast(s & (usize_bits - 1)));`

However, normal signal numbers are less than 31, so the bad math doesn't matter much.  Also, despite support for 1024 signals in the set, only setting signals between 1 and NSIG (which is mostly 65, but sometimes 128) is defined.  The existing tests only exercised signal numbers in the first 31 bits so they didn't trip over this:

The C library `sigaddset` will return `EINVAL` if given an out of bounds signal number.  I made the Zig code just silently ignore any out of bounds signal numbers.

Moved all the `sigset` related declarations next to each in the source, too.

The `filled_sigset` seems non-standard to me.  I think it is meant to be used like `empty_sigset`, but it only contains 31 set signals, which seems wrong (should be 64 or 128, aka `NSIG`).  It's also unused.  The oddly named but similar `all_mask` is used (by posix.zig) but sets all 1024 bits (which I understood to be undefined behavior but seems to work just fine).  For comparison the musl `sigfillset` fills in 65 bits or 128 bits.
2025-04-10 23:49:44 +02:00
Alex Rønne Petersen
a9ff2d56ce Compilation: Pass -m<os>-version-min=... to Clang for all applicable Darwin targets. 2025-04-10 22:11:13 +02:00
Jacob Young
73498737a2 x86_64: fix error_set_has_value of inferred error sets 2025-04-10 06:04:09 -04:00
Jacob Young
06eebafadd AstGen: redistribute inline asm limits 2025-04-10 06:04:09 -04:00
Jacob Young
7a2963efab x86_64: add avx512 registers 2025-04-10 02:04:52 -04:00
Jacob Young
bbf8abf5d3 x86_64: support rip-relative addressing to labels in inline asm 2025-04-10 02:04:52 -04:00
Jacob Young
f4a31bed98 x86_64: remove broken const value tracking 2025-04-10 02:04:52 -04:00
Jacob Young
1eb5d70d12 x86_64: fix switch on big ints 2025-04-09 20:14:12 -04:00
Jacob Young
bc10131db1 x86_64: rewrite scalar @mulWithOverflow
Closes #19607
2025-04-09 20:14:12 -04:00
Jacob Young
55ce756868 x86_64: rewrite scalar @subWithOverflow 2025-04-09 20:14:12 -04:00
Jacob Young
80068b6e59 x86_64: rewrite scalar @addWithOverflow 2025-04-09 20:14:12 -04:00
Jacob Young
426684b2f8 behavior: fix issues with x86_64 backend tests
* Oops, I accidentally disabled most of them.
 * Cleanup some workarounds for now closed issues.
 * Test binary operations with more scalar integer types.
2025-04-09 20:14:12 -04:00
Alex Rønne Petersen
ddcf6fcdf3 compiler: Allow using LLVM's SPIR-V backend. 2025-04-09 19:32:57 +02:00
Pat Tullmann
991560fb49 linux.zig: epoll_wait: pass kernel sigset size
Linux kernel syscalls expect to be given the number of bits of sigset that
they're built for, not the full 1024-bit sigsets that glibc supports.

I audited the other syscalls in here that use `sigset_t` and they're all
using `NSIG / 8`.

Fixes #12715
2025-04-09 16:37:58 +02:00
Manlio Perillo
f4e3631655 std.zon.parse: Fix typo in test "std.zon parse bool"
Replace "Correct floats" with "Correct bools".
2025-04-09 14:43:12 +02:00
Mun Maks
4fc783670a Sema/arith.zig: Fixing more typos from #23177.
This is a complementary PR to #23487 (I had only found one typo before).

Now I've looked at the whole `arith.zig` file, trying to find other potential problems.

Discussion about these changes:
https://github.com/ziglang/zig/pull/23177#discussion_r1997957095
2025-04-09 12:53:11 +01:00
Alex Rønne Petersen
79a620d617 zig_clang: Fix ZigClangAPValue being underaligned vs clang::APValue.
Also add a static_assert to catch future alignment mismatches on this type, and
reflect recent layout changes in the Zig bindings.
2025-04-09 11:53:24 +02:00
Meghan Denny
70437354c0 std: add nvidia as a known arm implementer 2025-04-09 10:14:42 +02:00
Techatrix
3830fc041b Compilation: Fix logic in addCCArgs() for various file types and flags.
Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>
2025-04-09 10:12:42 +02:00
Alex Rønne Petersen
1bfc71d4da build: Set LLVM_BUILD_STATIC/CLANG_BUILD_STATIC when linking statically.
This is needed since LLVM 20, particularly for Windows.
2025-04-09 10:11:52 +02:00
imreallybadatnames™️
7733b5dbe6
Merge pull request #23501 from imreallybadatnames/master
Step.Compile: use LtoMode enum for lto option
2025-04-09 05:16:36 +00:00
SuperAuguste
227788e6d5 Fix mach-o naming for sancov sections 2025-04-09 04:48:39 +02:00
Alex Rønne Petersen
9bbac42886
Merge pull request #23478 from alexrp/bsd-versions
`std.Target`: Bump some minimum OS versions for BSDs
2025-04-08 18:27:39 +02:00
Alex Rønne Petersen
2d33cc2e42
Merge pull request #23376 from sweiglbosker/m68k-archbits 2025-04-08 06:04:16 +02:00
Alex Rønne Petersen
d8153fa74a
Merge pull request #23495 from alexrp/loongarch
Some `loongarch64-linux` porting work
2025-04-08 01:02:24 +02:00
Matthew Roush
fb1d4990cb
Make translate-c more robust in handling macro functions.
Translate-c didn't properly account for C macro functions having parameter names that are C keywords. So something like `#define FOO(float) ((float) + 10)` would've been interpreted as casting `+10` to a `float` type, instead of adding `10` to the parameter `float`.

An example of a real-world macro function like this is SDL3's `SDL_DEFINE_AUDIO_FORMAT` from `SDL_audio.h`, which uses `signed` as a parameter.
2025-04-07 20:53:38 +00:00
Alex Rønne Petersen
f2f36c49c8 compiler: Switch default code model for loongarch64 to medium.
LLVM 21 will change the default, but we're making the change now to make
building Zig for loongarch64 less painful.

https://github.com/llvm/llvm-project/pull/132173
2025-04-07 21:36:56 +02:00
Maksat
4995509028 #23177, maintainter 'mlugg' wanted to fix that typo, 4 weeks without changes, might be forgotten 2025-04-07 16:50:28 +01:00
Alex Rønne Petersen
f13292abbc zig_clang: Fix size of ZigClangAPValue for Clang 20.
Fixes failing tarball builds for x86-linux and x86-windows.

The MSVC special case here is very sus, but that's a problem for another day.
2025-04-07 17:41:06 +02:00
Alex Rønne Petersen
f8439805d7
test: Add loongarch64-linux-(none,musl,gnu) to the test matrix.
Currently skips std tests which have many issues.
2025-04-07 16:03:22 +02:00
Alex Rønne Petersen
1cab57f361
std.os.linux: Add some missing arch bits for loongarch64. 2025-04-07 16:03:22 +02:00
Alex Rønne Petersen
9423712519
std: Disable usage of fstat() and friends on loongarch.
Like riscv32, loongarch exclusively uses statx().
2025-04-07 16:03:22 +02:00
Alex Rønne Petersen
6880d2c4a3
test: Disable @prefetch behavior test for loongarch.
https://github.com/llvm/llvm-project/issues/134624
2025-04-07 16:03:22 +02:00
Stefan Weigl-Bosker
bcb4ba9afd
std.os.linux: use heap.pageSize() instead of MMAP2_UNIT 2025-04-07 13:37:01 +02:00
Stefan Weigl-Bosker
6fd358d287
std.os.linux: add arch bits for m68k
fixup
2025-04-07 13:36:45 +02:00
Alex Rønne Petersen
4b5941c54b
start: Reduce stack alignment for hexagon.
The ABI requires 8-byte alignment, not 16.
2025-04-07 13:09:10 +02:00
Alex Rønne Petersen
d3bf6c518f
start: Align the stack on m68k. 2025-04-07 13:09:10 +02:00
Stefan Weigl-Bosker
8fea9f68e8
start: fix pc register syntax for m68k 2025-04-07 13:09:10 +02:00
SuperAuguste
36b9e56753 Remove overzealous LLVM anti-instrumentation attributes 2025-04-07 07:53:42 +02:00
Alex Rønne Petersen
45a54ef4fa libcxx: Backport llvm/llvm-project#134278. 2025-04-06 16:53:10 +02:00
Alex Rønne Petersen
c2f5515fb0 glibc: Add missing stubs-lp64s.h for loongarch64-linux-gnusf.
https://sourceware.org/bugzilla/show_bug.cgi?id=32776
2025-04-06 14:24:49 +02:00
Ziyi Yan
61b87ebae2
Add lld path of linuxbrew installation (#23466)
Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>
2025-04-06 06:25:39 +00:00
Alex Rønne Petersen
c8631ec523
std.Target: Bump minimum Dragonfly BSD version to 6.0.0. 2025-04-06 08:05:07 +02:00
Alex Rønne Petersen
af19161817
std.Target: Bump minimum OpenBSD version to 7.5.
Per: https://www.openbsd.org/faq/faq5.html#Flavors
2025-04-06 08:05:07 +02:00
Alex Rønne Petersen
a88db11c2a
std.Target: Bump minimum NetBSD version to 9.4.
Per: https://www.netbsd.org/releases
2025-04-06 08:05:07 +02:00
Alex Rønne Petersen
b22d53a5e7
test: Remove some dead FreeBSD targets from llvm_targets.
These were dropped in FreeBSD 12.x, and we now require 13.4+.
2025-04-06 08:05:07 +02:00
Alex Rønne Petersen
88e8e9fb91
std: Remove some FreeBSD version checks and resulting dead code.
We now require FreeBSD 13.4+.
2025-04-06 08:05:04 +02:00
Alex Rønne Petersen
ae98d79c87
std.Target: Bump minimum FreeBSD version to 13.4.
Per: https://www.freebsd.org/releases
2025-04-06 07:44:38 +02:00
Jacob Young
470e2b63d9 Dwarf: handle undefined type values
Closes #23461
2025-04-05 21:42:33 -04:00
Dacheng Gao
596e0bd47b std.os.linux: add constants for ETH 2025-04-06 02:52:20 +02:00
Jacob Young
9827ffe1de x86_64: fix incorrect handling of unreusable operands
Closes #23448
2025-04-05 20:49:56 -04:00
Jan200101
1a5dcff8e4
std.Build: update build-id flag description
it now denotes:
- all supported styles
- what a given style outputs
- what formats a given style supports
2025-04-05 22:11:07 +02:00
homersimpsons
95fdbc579f pow: fix typo 0 instead of inf 2025-04-05 21:20:10 +02:00
Andrew Kelley
0cd31fc7ff
Merge pull request #22780 from ziglang/llvm20
LLVM 20
2025-04-05 01:46:13 -04:00
Andrew Kelley
cefe65c1b8 ci: update tarballs to 0.15.0-dev.203+53270f008
these have assertions enabled
2025-04-04 15:28:18 -07:00
Andrew Kelley
8acedfd5ba
Merge pull request #23459 from ziglang/linked-lists
de-genericify linked lists
2025-04-04 17:48:06 -04:00
Carmen
84c9cee502 fix review 2025-04-04 12:42:28 +01:00
Carmen
65c943671e OpenMode is exhaustive 2025-04-04 12:42:28 +01:00
Carmen
a61678b754 dont return tuple, split into 2 functions 2025-04-04 12:42:28 +01:00
Carmen
45afde2036 Payload -> @FieldType and use mem.sliceTo 2025-04-04 12:42:28 +01:00
Carmen
2112167f8c std.os.uefi.protocol.File: fix some typed definitions 2025-04-04 12:42:28 +01:00
Zenomat
8a83fc7eba
std.net: Implement if_nametoindex for windows (#22555) 2025-04-04 11:40:44 +00:00
Andrew Kelley
810f70ef42 update compiler usage of DoublyLinkedList API 2025-04-03 22:58:52 -07:00
Alex Rønne Petersen
7c85dc4602
test: Disable error union switch with call operand (ReleaseSafe) on macos.
This started failing in LLVM 20:

test
+- test-stack-traces
   +- check error union switch with call operand (ReleaseSafe llvm) failure
error:
========= expected this stdout: =========
error: TheSkyIsFalling
source.zig:3:5: [address] in [function]
    return error.TheSkyIsFalling;
    ^

========= but found: ====================
error: TheSkyIsFalling
source.zig:13:27: [address] in [function]
        error.NonFatal => return,
                          ^
2025-04-04 06:08:10 +02:00
Alex Rønne Petersen
4b360a1ff0
ci: Update tarballs to 0.15.0-dev.203+53270f008. 2025-04-04 06:08:10 +02:00
Alex Rønne Petersen
957a5ae560
cmake: Pass -fno-sanitize=undefined when building zig2.
We build zig2.c and compiler_rt.c with -O0 but then proceed to link with -O3.
So zig2.o and compiler_rt.o will have references to ubsan-rt symbols, but the
-O3 causes the compiler to not link ubsan-rt. We don't actually need the safety
here, so just explicitly disable ubsan.
2025-04-04 06:08:10 +02:00
Alex Rønne Petersen
c3e88a21fb
compiler: Recognize -fno-sanitize=<...> in addition to -fsanitize=<...>. 2025-04-04 06:08:10 +02:00
Alex Rønne Petersen
7c5412c7a4
build: Rename -Dtest-slow-targets to -Dtest-extra-targets.
This can be used more broadly for targets that aren't quite ready to be tested
by default yet.
2025-04-04 06:08:10 +02:00
Alex Rønne Petersen
15a05fc324
Revert "compiler: Don't consider powerpc to have red zone support yet."
This reverts commit 4fad60fd3a70d0b059ce92ce825faabc1d2ac2e8.

Closes #23056.
2025-04-04 06:08:10 +02:00
Alex Rønne Petersen
9e4199d629
Compilation: Remove the PowerPC soft float preprocessor workaround.
Closes #21411.
2025-04-04 06:08:10 +02:00
Alex Rønne Petersen
28469636ba
zig cc: Avoid passing any "CPU" features related to float ABI to Clang. 2025-04-04 06:08:10 +02:00
Alex Rønne Petersen
6667e0fbb4
Revert "glibc: Patch to work around missing features in LLVM's s390x assembler."
This reverts commit b230e4f598bd18b47f3f1c981869c597a06c7452.

Closes #21329.
2025-04-04 06:08:10 +02:00
Alex Rønne Petersen
0d6f3aa6c1
llvm: Remove workaround for zero-length memset/memcpy on wasm.
Closes #16360.
2025-04-04 06:08:10 +02:00
Alex Rønne Petersen
33103071a7
std: Disable link with relative paths and linkat with different directories tests for mips64(el).
These started failing with LLVM 20 for unclear reasons:

test-std
└─ run test std-mips64-linux.4.19...6.13.4-gnuabi64.2.28-mips64r2-Debug-libc 2798/2878 passed, 2 failed, 78 skipped
error: 'posix.test.test.link with relative paths' failed: expected 2, found 0
/home/alexrp/Source/ziglang/zig-llvm20/lib/std/testing.zig:103:17: 0x1d9e5bf in expectEqualInner__anon_47031 (test)
                return error.TestExpectedEqual;
                ^
/home/alexrp/Source/ziglang/zig-llvm20/lib/std/posix/test.zig:311:9: 0x3650f57 in test.link with relative paths (test)
        try testing.expectEqual(@as(@TypeOf(nstat.nlink), 2), nstat.nlink);
        ^
error: 'posix.test.test.linkat with different directories' failed: expected 2, found 0
/home/alexrp/Source/ziglang/zig-llvm20/lib/std/testing.zig:103:17: 0x1d9e5bf in expectEqualInner__anon_47031 (test)
                return error.TestExpectedEqual;
                ^
/home/alexrp/Source/ziglang/zig-llvm20/lib/std/posix/test.zig:355:9: 0x3653377 in test.linkat with different directories (test)
        try testing.expectEqual(@as(@TypeOf(nstat.nlink), 2), nstat.nlink);
        ^
error: while executing test 'zig.system.darwin.macos.test.detect', the following test command failed:
qemu-mips64 -L /opt/glibc/mips64-linux-gnu-n64 /home/alexrp/Source/ziglang/zig-llvm20/.zig-cache/o/22a8c3762ea56ae3a674fa9ad15f6657/test --seed=0xa1dbb43c --cache-dir=/home/alexrp/Source/ziglang/zig-llvm20/.zig-cache --listen=-

test-std
└─ run test std-mips64-linux.4.19...6.13.4-gnuabi64.2.28-mips64r2-Debug-libc 2798/2878 passed, 1 failed, 79 skipped
error: 'posix.test.test.linkat with different directories' failed: expected 2, found 0
/home/alexrp/Source/ziglang/zig-llvm20/lib/std/testing.zig:103:17: 0x1d9e22f in expectEqualInner__anon_47031 (test)
                return error.TestExpectedEqual;
                ^
/home/alexrp/Source/ziglang/zig-llvm20/lib/std/posix/test.zig:356:9: 0x3650b47 in test.linkat with different directories (test)
        try testing.expectEqual(@as(@TypeOf(nstat.nlink), 2), nstat.nlink);
        ^
error: while executing test 'zig.system.darwin.macos.test.detect', the following test command failed:
qemu-mips64 -L /opt/glibc/mips64-linux-gnu-n64 /home/alexrp/Source/ziglang/zig-llvm20/.zig-cache/o/22a8c3762ea56ae3a674fa9ad15f6657/test --seed=0xa1dbb43c --cache-dir=/home/alexrp/Source/ziglang/zig-llvm20/.zig-cache --listen=-

Unfortunately, neither GDB nor LLDB want to play nice with qemu-mips64(el) at
the moment, so I can't easily debug these failures.
2025-04-04 06:08:10 +02:00
Alex Rønne Petersen
96fe4fb969
Revert "test: Partially disable vector float operators on mips."
This reverts commit 19a91084c2a29175bad47d41cd11935904ede0b9.

Closes #21051.
2025-04-04 06:08:10 +02:00
Alex Rønne Petersen
b9456d64d7
test: mips32 is no longer a slow target with LLVM 20.
We can now run these tests as part of test-modules w/o -Dtest-slow-targets.

Closes #21096.
2025-04-04 06:08:10 +02:00
Alex Rønne Petersen
7109e462b7
llvm: Use muslabin32/muslabi64 environments in the target triple.
Closes #2909.
2025-04-04 06:08:10 +02:00
Alex Rønne Petersen
9a59cff27f
llvm: Allow FastISel on mips again.
Closes #21215.
2025-04-04 06:08:10 +02:00
Alex Rønne Petersen
166766d63d
llvm: never_tail implies never_inline, so set noinline in this case too. 2025-04-04 06:08:10 +02:00
Alex Rønne Petersen
7415739e36
Sema: Prevent tail calls of std.builtin.returnError().
LLVM 20 started tail-calling it in some of our test cases, resulting in:

    error: AndMyCarIsOutOfGas
    /home/alexrp/Source/ziglang/zig-llvm20/repro.zig:2:5: 0x103ef9d in main (repro)
        return error.TheSkyIsFalling;
        ^
    /home/alexrp/Source/ziglang/zig-llvm20/repro.zig:6:5: 0x103efa5 in main (repro)
        return error.AndMyCarIsOutOfGas;
        ^
    /home/alexrp/Source/ziglang/zig-llvm20/lib/std/start.zig:656:37: 0x103ee83 in posixCallMainAndExit (repro)
                const result = root.main() catch |err| {
                                        ^

instead of the expected:

    error: AndMyCarIsOutOfGas
    /home/alexrp/Source/ziglang/zig-llvm20/repro.zig:2:5: 0x103f00d in main (repro)
        return error.TheSkyIsFalling;
        ^
    /home/alexrp/Source/ziglang/zig-llvm20/repro.zig:6:5: 0x103f015 in main (repro)
        return error.AndMyCarIsOutOfGas;
        ^
    /home/alexrp/Source/ziglang/zig-llvm20/repro.zig:11:9: 0x103f01d in main (repro)
            try bar();
            ^
2025-04-04 06:08:10 +02:00
Alex Rønne Petersen
82b9d9c0f6
compiler-rt: Fix names of some float/int conversion routines for hexagon. 2025-04-04 06:08:10 +02:00
Alex Rønne Petersen
858305385d
llvm: Update the list of targets that use native f16/f128.
Closes #22003.
Closes #22013.
2025-04-04 06:08:10 +02:00
Alex Rønne Petersen
cf9c6f5298
compiler: Update max int alignments for some targets. 2025-04-04 06:08:10 +02:00
Alex Rønne Petersen
4c5c5bcd91
llvm: Fix i128 alignment for various targets.
This ABI bug was fixed in LLVM 20.
2025-04-04 06:08:10 +02:00
Alex Rønne Petersen
3d1cfdb365
llvm: Set target-abi module flag.
LLVM is increasingly making use of this module flag when present.
2025-04-04 06:08:09 +02:00
Alex Rønne Petersen
e99c11856d
libtsan: Update to LLVM 20. 2025-04-04 06:08:09 +02:00
Alex Rønne Petersen
d67d52abe5
zig cc: Update options data to Clang 20. 2025-04-04 06:08:09 +02:00
Alex Rønne Petersen
8954e9748a
std.Target: Add Abi.muslf32 and Abi.muslsf. 2025-04-04 06:08:09 +02:00
Alex Rønne Petersen
1599f8ade0
std.Target: Bump baseline hexagon model to hexagonv68.
https://github.com/llvm/llvm-project/pull/125584
2025-04-04 06:08:09 +02:00
Alex Rønne Petersen
eefb334885
std.Target: Bump baseline bpfel/bpfeb model to v3.
https://github.com/llvm/llvm-project/pull/131691
2025-04-04 06:08:09 +02:00
Alex Rønne Petersen
4de368a1b6
std.Target: Update CPU models/features for LLVM 20.
Closes #21818.
2025-04-04 06:08:09 +02:00
Alex Rønne Petersen
8ea2e1ded5
compiler: Updates for LLVM/Clang 20 API changes. 2025-04-04 06:08:09 +02:00
Alex Rønne Petersen
156ab87500
libcxx: Update to Clang 20.
See:

* https://discourse.llvm.org/t/rfc-freezing-c-03-headers-in-libc/77319
* https://discourse.llvm.org/t/rfc-project-hand-in-hand-llvm-libc-libc-code-sharing/77701

We're dropping support for C++03 for Zig due to the first change; it would be
insane to ship 1018 duplicate header files just for this outdated use case.

As a result of the second change, I had to bring in a subset of the headers from
llvm-libc since libc++ now depends on these. Hopefully we can continue to get
away with not copying the entirety of llvm-libc.
2025-04-04 06:08:09 +02:00
Alex Rønne Petersen
7ab01c9a42
libcxxabi: Update to Clang 20. 2025-04-04 06:08:09 +02:00
Alex Rønne Petersen
a89b343256
libunwind: Update to LLVM 20. 2025-04-04 06:08:09 +02:00
Alex Rønne Petersen
ce754724b3
zig cc: Update intrinsic headers to Clang 20. 2025-04-04 06:08:09 +02:00
Alex Rønne Petersen
0181cfe8ad
zig cc: Update driver files to Clang 20. 2025-04-04 06:08:09 +02:00
Alex Rønne Petersen
c712f18d74
build: Update to LLVM/Clang 20. 2025-04-04 06:08:08 +02:00
Alex Rønne Petersen
50cb2fa0a2
ci: Stop triggering the workflow for llvm branches.
We usually do a PR for the llvm branches, so triggering a run for the branch
means we do extra work for no reason.
2025-04-04 06:06:39 +02:00
Dimitris Dinodimos
155b34ba05 Change the lld path on macos homebrew
Homebrew now provides lld in a separate formula; it was part of llvm
formula.
2025-04-04 06:03:19 +02:00
Andrew Kelley
337e1109f5 std.DoublyLinkedList: remove length tracking
this is trivial to tack on, and in my experience it is rarely wanted.
2025-04-03 15:57:35 -07:00
Andrew Kelley
3b77a845f9 de-genericify DoublyLinkedList
by making it always intrusive, we make it more broadly useful API, and
avoid binary bloat.
2025-04-03 15:35:21 -07:00
Andrew Kelley
1639fcea43 de-genericify SinglyLinkedList
by making it always intrusive, we make it a more broadly useful API, and
avoid binary bloat.
2025-04-03 14:55:04 -07:00
Alex Rønne Petersen
e9220525e8
Merge pull request #23447 from alexrp/cpuid-updates 2025-04-03 12:26:27 +02:00
Alex Rønne Petersen
bfbf4badd5
Merge pull request #23445 from alexrp/external-executor-fixes 2025-04-03 05:22:37 +02:00
Alex Rønne Petersen
e87387ee0c
std.zig.system.arm: Update some of the CPU lists based on LLVM 19. 2025-04-03 04:00:32 +02:00
Alex Rønne Petersen
8ff104380d
std.os.windows.PF: Add ARM_V83_LRCPC_INSTRUCTIONS_AVAILABLE. 2025-04-03 04:00:30 +02:00
Alex Rønne Petersen
9909465c1c
std.zig.system.darwin.macos: Handle tahiti/tupai in detectNativeCpuAndFeatures(). 2025-04-03 02:42:20 +02:00
Alex Rønne Petersen
b532f6c827
std.c.darwin.CPUFAMILY: Add ARM_TAHITI and ARM_TUPAI. 2025-04-03 02:41:44 +02:00
Alex Rønne Petersen
7289a073e5
std.zig.system.x86: Synchronize CPUID/XGETBV checks with LLVM 19.
Also fix a bunch of cases where we didn't toggle features off if the relevant
leaf isn't available, and switch XCR0 checks to a packed struct.

Closes #23385.
2025-04-03 02:29:26 +02:00
Alex Rønne Petersen
171cea74b6
std.zig.system: Make getExternalExecutor() allow Darling for driverkit. 2025-04-02 23:58:55 +02:00
Alex Rønne Petersen
c3f2222a59
std.zig.system: Make getExternalExecutor() less opinionated about Wasmtime.
Wasmtime supports both wasm32 and wasm64, and can run freestanding WASM binaries
just fine (although the usefulness of the latter is fairly limited).
2025-04-02 23:58:55 +02:00
Alex Rønne Petersen
11db7eaf4e
std.zig.system: Fix a check in getExternalExecutor() to use the host argument. 2025-04-02 23:58:54 +02:00
Alex Rønne Petersen
55ee88f9c0
std.zig.system: Fix wine executable name in getExternalExecutor().
I'm not actually aware of any distro where the name is wine64, so just use wine
in all cases. As part of this, I also fixed the architecture checks to match
reality.

Closes #23411.
2025-04-02 23:58:52 +02:00
Parker Liu
de62dc884e
translate-c: fix function prototype decalared inside a function
* If a function prototype is declarated inside a function, do not
  translate it to a top-level extern function declaration. Similar to
  extern local variable, just wrapped it into a block-local struct.

* Add a new extern_local_fn tag of aro_translate_c node for present
  extern local function declaration.

* When a function body has a C function prototype declaration, it adds
  an extern local function declaration. Subsequent function references
  will look for this function declaration.
2025-04-02 20:07:41 +00:00
Alex Rønne Petersen
9dfdf35032
Merge pull request #22337 from ruihe774/fix-app-mask
* std.os.linux: remove app_mask
* std.posix: on libc-less linux, block all signals in raise(), not just app_mask
2025-04-02 17:36:59 +02:00
Matthew Lugg
4303b43519
Merge pull request #22907 from MasonRemaley/import-zon-anon-type
Allow importing ZON without a result type (you can import build.zig.zon now)
2025-04-02 13:17:34 +01:00
Auguste Rame
bfab9582c7
DebugAllocator: Fix bucket removal logic causing segfault/leak (#23390)
Make buckets doubly linked
2025-04-02 12:15:04 +00:00
Matthew Lugg
896ffe6658
Merge pull request #22973 from MasonRemaley/zon-stop-on-node
Allow parsing into `Zoir.Node.Index` (it's easier to parse build.zig.zon at runtime now)
2025-04-02 12:00:23 +01:00
Misaki Kasumi
aa832d6a6d std.os.linux: block all signals in raise 2025-04-02 18:50:14 +08:00
Mason Remaley
fa1695a8b0
std.zon.parse: make ast and zoir fields of Diagnostics non-optional 2025-04-02 06:09:21 +01:00
Mason Remaley
65649576db
std.zon.parse: rename Status to Diagnostics
This name is more appropriate and in line with the rest of `std`.
2025-04-02 06:08:55 +01:00
Mason Remaley
3b2fec17a4
std.zon: populate Zoir.Node.Index values with corresponding ZOIR node
This allows using `std.zon` to parse schemas which are not directly
representable in the Zig type system; for instance, `build.zig.zon`.
2025-04-02 06:08:04 +01:00
mlugg
dd3f01eadf
incremental: add test for ZON file without result type 2025-04-02 05:58:29 +01:00
mlugg
d8ac37fcc8
stage1: fix wasi_snapshot_preview1_fd_seek on cache files
`wasm2c` uses an interesting mechanism to "fake" the existence of cache
directories. However, `wasi_snapshot_preview1_fd_seek` was not correctly
integrated with this system, so previously crashed when run on a file in
a cache directory due to trying to call `fseek` on a `FILE *` which was
`NULL`.
2025-04-02 05:57:50 +01:00
Mason Remaley
87209954a7
Zcu: fix ZOIR cache bugs
* When saving bigint limbs, we gave the iovec the wrong length, meaning
  bigint data (and the following string and compile error data) was corrupted.
* When updating a stale ZOIR cache, we failed to truncate the file, so
  just wrote more bytes onto the end of the stale cache.
2025-04-02 05:54:04 +01:00
Mason Remaley
06ee383da9
compiler: allow @import of ZON without a result type
In particular, this allows importing `build.zig.zon` at comptime.
2025-04-02 05:53:22 +01:00
David Rubin
1b62a22268 Sema: increment extra index even if return type is generic 2025-04-02 01:34:17 +02:00
Carmen
9720bade7a
std.start: allow return uefi error union in main (#23425) 2025-04-01 17:10:10 +00:00
Carmen
fa86e09fb3
std.os.uefi.protocol: ziggify function signatures (#23214) 2025-04-01 10:47:51 +00:00
Ali Cheraghi
b636d56d6a zon: normalize negative zeroes 2025-03-31 19:07:34 -04:00
Jacob Young
b431e9af97 Elf: fix incrementally reallocating the last atom in a section 2025-03-31 19:06:25 -04:00
mlugg
d53cc5e5b2 Sema: allow @ptrCast slice of zero-bit type to slice of non-zero-bit type
This is actually completely well-defined. The resulting slice always has
0 elements. The only disallowed case is casting *to* a slice of a
zero-bit type, because in that case, you cna't figure out how many
destination elements to use (and there's *no* valid destination length
if the source slice corresponds to more than 0 bits).
2025-03-31 19:03:08 -04:00
Parker Liu
0bdc0bb534
translate-c: fix referencing extern locals from nested blocks 2025-03-31 20:22:03 +03:00
Alex Rønne Petersen
0753af792a
Merge pull request #23371 from alexrp/ci-redundancy
Remove some `aarch64-linux` CI steps that are already covered by `x86_64-linux`
2025-03-31 17:51:25 +02:00
Alex Rønne Petersen
c118cd6406
Merge pull request #23417 from dweiller/zstd-fixes
Zstd fixes
2025-03-31 17:50:32 +02:00
Simon Brown
43ad87555e Add quota for comptime sort, add test 2025-03-31 17:47:46 +02:00
dweiller
d034f2a87b std.compress.zstd: ensure window size fits into usize 2025-03-31 17:22:44 +11:00
dweiller
7a7d6a02a5 std.compress.zstd: fix OOB access in literal decode
When decoding the literals section of a compressed block, the length of
the regenerated size of the literals must be checked against the buffer
literals are decoded into.
2025-03-31 17:22:44 +11:00
David Rubin
acfdad8581 Sema: convert slice sentinel to single pointer correctly 2025-03-30 03:41:00 +01:00
mlugg
f296eec294 Zcu: resolve layout of analyzed declaration type
Resolves: #19888
2025-03-29 22:46:31 +00:00
mlugg
eee752ea5a compiler: "illegal behavior", not "undefined behavior", in errors 2025-03-29 18:40:23 -04:00
Frank Denis
ca1fc3827e
crypto.ecdsa: fix EcdsaP384Sha3_384 constant name (#23403)
Spotted by @deatil -- Thanks!
2025-03-29 14:52:34 +00:00
Sean Stasiak
6e8493daa3 check result of mmap() call to handle a large base_addr value correctly 2025-03-27 20:34:41 +01:00
Alex Rønne Petersen
c85534a5c6 stage1: Update zig1.wasm.
Signed-off-by: Alex Rønne Petersen <alex@alexrp.com>
2025-03-27 17:43:05 +01:00
Alex Rønne Petersen
2b57f6b717
Merge pull request #23378 from alexrp/build-zig-cleanup 2025-03-27 17:12:17 +01:00
Alex Rønne Petersen
cc9634a2d3
Merge pull request #23373 from alexrp/get-base-address
`std.process`: Some minor fixes for `getBaseAddress()`
2025-03-27 15:39:24 +01:00
GalaxyShard
b5a5260546 std.Build: implement addEmbedPath for adding C #embed search directories 2025-03-27 09:47:42 +01:00
blurrycat
fb188c3d18
std.posix: add getuid()/geteuid() 2025-03-27 07:58:27 +00:00
Alex Rønne Petersen
dc66f4384f
build: increase test-std max rss 2025-03-27 04:36:27 +00:00
Андрей Краевский
aac800ec65
std.meta.FieldType -> @FieldType 2025-03-27 03:49:38 +00:00
Alex Rønne Petersen
f71590d4c4
build.zig: Statically link LLVM libraries for experimental targets if requested. 2025-03-27 00:31:11 +01:00
Alex Rønne Petersen
09783b8544
ci: Build stage4 and run behavior tests with it on aarch64-linux-debug.
This ensures that we at least have some relatively lightweight coverage of
building and using stage4 from a newly built stage3.
2025-03-27 00:22:54 +01:00
Alex Rønne Petersen
db7db48028
Merge pull request #23339 from Iced-Sun/master
std.posix: update LFS64 interfaces for android bionic C
2025-03-26 23:25:08 +01:00
Alex Rønne Petersen
2489b5fd74
build.zig: Stop setting _WIN32_WINNT=0x601 (Windows 7) when targeting MinGW.
Our default minimum version for Windows has been Windows 10 for a while.
2025-03-26 23:12:55 +01:00
Felix "xq" Queißner
0ed905b9c6 Enables parsing for '-Wl,-rpath,' in pkg-config output, allows better support for NixOS linking. 2025-03-26 22:55:18 +01:00
Alex Rønne Petersen
ccffc7f108
build.zig: Don't disable LTO when targeting MinGW.
We stopped building mingw32.lib with LTO recently, so this is no longer needed.
2025-03-26 22:46:27 +01:00
Pratham
5bb9963bbb
abiAndDynamicLinkerFromFile: return an error when the file is not actually dynamic (#19928) 2025-03-26 19:54:10 +00:00
Alex Rønne Petersen
b9efdbb412
std.process: Fix getBaseAddress() to handle all Darwin OSs. 2025-03-26 20:39:07 +01:00
Alex Rønne Petersen
d56a99442b
std.process: Don't use _mh_execute_header in getBaseAddress() on BSDs.
Only the Mach-O format has this symbol.
2025-03-26 20:39:07 +01:00
Alex Rønne Petersen
0cf5f0d0b0
std.process: Fix getBaseAddress() for linux + libc.
In this case we should use the getauxval() from libc, not our own.
2025-03-26 20:39:07 +01:00
wooster0
263ba34619 linux: don't export getauxval when not required 2025-03-26 20:37:35 +01:00
Eric Joldasov
27c1f2b3a0 zig build: allow to choose "lazy mode" for fetching process
`--fetch` flag now has additional optional parameter, which specifies
how lazy dependencies should be fetched:
 * `needed` — lazy dependencies are fetched only if they are required
   for current build configuration to work. Default and works same
   as old `--fetch` flag.
 * `all` — lazy dependencies are always fetched. If `--system` flag
   is used after that, it's guaranteed that **any** build configuration
   will not require additional download of dependencies during build.
   Helpful for distro packagers and CI systems:
   https://www.github.com/ziglang/zig/issues/14597#issuecomment-1426827495

If none is passed, behaviour is same as if `needed` was passed.

Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
2025-03-26 19:00:33 +01:00
Kendall Condon
b4b1daf001
Allocator.create: properly handle alignment for zero-sized types (#21864) 2025-03-26 15:31:57 +00:00
Alex Rønne Petersen
27108cc99e
ci: Don't do the update-zig1 test steps on aarch64-linux.
We already do these on the x86_64-linux machines. They're fairly costly, and it
seems very unlikely to me that they'll uncover issues that wouldn't be uncovered
on x86_64-linux.
2025-03-26 16:30:21 +01:00
Alex Rønne Petersen
628092c8c7
ci: Don't build the compiler for arm-linux-musleabihf on aarch64-linux.
We already do this smoke test on the x86_64-linux machines, so I don't see a
point in duplicating this effort here.
2025-03-26 16:30:02 +01:00
Alex Rønne Petersen
d9165aacce
ci: Set execute bit on aarch64-linux scripts. 2025-03-26 16:30:00 +01:00
dweiller
b84db311d9 zig build: add env_map entries to hash for Step.Run
This change fixes false-positive cache hits for run steps that get run
with different sets of environment variables due the the environment map
being excluded from the cache hash.
2025-03-26 14:48:04 +01:00
孙冰
0118912e2d
std.posix: update LFS64 interfaces for android bionic C 2025-03-26 20:00:05 +08:00
孙冰
d7e944a628
std.Target: Update default Android API level to 24
API level 24 completes _FILE_OFFSET_BITS=64 support in bionic, c.f.
https://android.googlesource.com/platform/bionic/+/HEAD/docs/status.md.

According to https://apilevels.com, API level 24 (Android 7 released in 2017)
has 97% cumulative usage.
2025-03-26 19:48:21 +08:00
Andrew Barchuk
5b4759bd3c Clarify the multidimensional array example
Use a rectangular matrix instead of a square one to distinguish rows and
columns more clearly. Extend the example with row access.
2025-03-26 11:52:52 +01:00
Alex Rønne Petersen
b350049f51
Merge pull request #23062 from ianic/io_uring_bind
io_uring: Update to kernel changes in 6.11 and 6.12
2025-03-26 11:39:56 +01:00
mlugg
a7ff042f98 Zcu: include named tests in resolved references
Oops, a little typo from yours truly! No test for this one, because we
don't have any way of testing the reference trace.
2025-03-26 10:20:19 +00:00
Ryan Liptak
63014d3819 Add test to ensure the BatBadBut mitigation handles trailing . and space safely
Context:
- https://blog.rust-lang.org/2024/09/04/cve-2024-43402.html
- https://github.com/rust-lang/rust/pull/129962

Note that the Rust test case for this checks that it executes the batch file successfully with the proper mitigation in place, while the Zig test case expects a FileNotFound error. This is because of a PATHEXT optimization that Zig does, and that Rust doesn't do because Rust doesn't do PATHEXT appending (it only appends .exe specifically). See the added comment for more details.
2025-03-26 10:55:18 +01:00
Pat Tullmann
2210c4c360 lib/std/posix: test ftruncate via std.fs.File.setEndPos()
Add a test for std.fs.File's `setEndPos` (which is a simple wrapper around
`std.posix.ftruncate`) to exercise some success and failure paths.

Explicitly check that the `ftruncate` length isn't negative when
interpreted as a signed value.  This avoids having to decode overloaded
`EINVAL` errors.

Add errno handling to Windows path to map INVALID_PARAMETER to FileTooBig.

Fixes #22960
2025-03-26 02:57:23 +01: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
Arnau Camprubí
8a8b3019f3
Fix std.debug.dumpHex address offsets 2025-03-25 23:20:56 +01:00
Alex Rønne Petersen
cb8d7a8110
Merge pull request #23310 from Rexicon226/fix-23309
big.int: return normalized results from `{add,sub}Carry`
2025-03-25 18:44:35 +01:00
Kuwazy
6b6dc1cd3a
Added check for HTTP version and GET method when upgrading WebSocket to comply with RFC 6455. (#23332) 2025-03-25 15:00:50 +01:00
Alex Rønne Petersen
e1c6af2840
Merge pull request #23220 from samy-00007/bytesAsSlice-fix
Minor fix for `Allocator.remap` and `mem.bytesAsSlice` for zero-sized types
2025-03-25 13:45:10 +01:00
孙冰
fbbdde41b4 std.c: android bionic C supports arc4random_buf and getentropy
1. https://android.googlesource.com/platform/bionic/+/refs/heads/main/libc/include/bits/getentropy.h
2. https://android.googlesource.com/platform/bionic/+/refs/heads/main/libc/include/stdlib.h
2025-03-25 13:17:45 +01:00
Alex Rønne Petersen
c94d926bba
Merge pull request #23007 from rootbeer/posix-eaccess-eperm
lib/std: Make usage of PermissionDenied & AccessDenied consistent
2025-03-25 11:21:05 +01:00
godalming123
5bb4fef30a
Update the documentation comment in arena_allocator.zig to be more accurate
Update the documentation comment in arena_allocator.zig to specify that free() is a no-op unless the item is the most recent allocation.
2025-03-25 06:19:28 +00:00
samy007
4595b1ee06 std.mem.bytesAsSlice: fix to support zero-bytes sized types
also added a test for json parsing of zero sized type
2025-03-24 22:08:05 +01:00
samy007
be483dabc8 fix: Allocator.remap now handles zero-bytes sized types 2025-03-24 22:05:57 +01:00
Chris Clark
525466b49d
std.zig.Ast: Fix error case memory leak in parse() 2025-03-24 20:14:01 +01:00
David Rubin
89db4f2e93 Sema: use unwrapped generic owner in getFuncInstanceIes 2025-03-24 19:04:10 +00:00
Pat Tullmann
14c046fc07 lib/std: PermissionDenied/AccessDenied cleanup and fallout
This PR consistently maps .ACCES into AccessDenied and .PERM into
PermissionDenied.  AccessDenied is returned if the file mode bit
(user/group/other rwx bits) disallow access (errno was `EACCES`).
PermissionDenied is returned if something else denies access (errno was
`EPERM`) (immutable bit, SELinux, capabilities, etc).  This somewhat
subtle distinction is a POSIX thing.

Most of the change is updating std.posix Error Sets to contain both
errors, and then propagating the pair up through caller Error Sets.

Fixes #16782
2025-03-24 16:20:45 +01:00
Pat Tullmann
02373eb2a5 lib/std/: WASI code should follow POSIX semantics for AccessDenied/PermissionDenied
Use error.AccessDenied for permissions (rights) failures on Wasi
(`EACCES`) and error.PermissionDenied (`EPERM`) for systemic failures.
And pass-through underlying Wasi errors (PermissionDenied or AccessDenied)
without mapping.
2025-03-24 16:20:45 +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
Meghan Denny
972cab5bb0
std: add bit_set.findLastSet() (#22411) 2025-03-24 16:12:23 +01:00
oittaa
c1db72cdbc
std.math: Add least common multiple (lcm) 2025-03-24 16:07:40 +01:00
rpkak
9f8d938d38 DepTokenizer: allow space between target and colon 2025-03-24 15:31:03 +01:00
Pavel Verigo
33ad2c949e stage2-wasm: packed store/load 128 bits 2025-03-24 15:00:00 +01:00
Pavel Verigo
911f4527f0 stage2-wasm: behavior tests pass with ReleaseFast/Small 2025-03-24 15:00:00 +01:00
Pavel Verigo
47cd0961cb stage2-wasm: pass field_parent_ptr tests
Handle packed containers, also fixes packed union lowering for non int type + union field pointer logic fix
2025-03-24 15:00:00 +01:00
Pavel Verigo
58b38238f5 stage2-wasm: enable undef test + ignore undef store/memset with safety off 2025-03-24 15:00:00 +01:00
Pavel Verigo
07f14bd43b stage2-wasm: fix error union handling 2025-03-24 15:00:00 +01:00
Pavel Verigo
0e109add37 stage2-wasm: clean memcpy + fix another bug in aggr_init for optionals arr 2025-03-24 15:00:00 +01:00
Pavel Verigo
15bc2ab0a8 stage2-wasm: clz fix 2025-03-24 15:00:00 +01:00
Pavel Verigo
a429d04ba9 stage2-wasm: enable already working tests 2025-03-24 14:59:58 +01:00
Pavel Verigo
ca2bd6d6ef stage2-wasm: fix comparing and storing optionals 2025-03-24 14:58:05 +01:00
David Rubin
22013f1b39
test: add a behavior test for 0-length loop fix 2025-03-24 06:58:01 -07:00
David Rubin
ae442e2c29
big.int: return normalized results from {add,sub}Carry 2025-03-24 06:58:01 -07:00
Shun Sakai
677b2d62e5 docs(std.base64): Add references to RFC 4648
There are multiple implementations of Base64, but `std.base64` appears
to be based on RFC 4648, so we clarify that it is based on RFC 4648.
2025-03-24 11:42:28 +00:00
GasInfinity
dfe0fb675d fix(std/fmt.zig): fix overflow in fmtDurationSigned
fixes #23315
2025-03-24 11:40:19 +00:00
Carter Snook
149eace5d5 deprecate O(n) union field type helpers in std.meta
Users should be using @FieldType() instead.
2025-03-24 11:13:58 +00:00
sdzx-1
adee3ee9a2 typo: block_two_semicolon -> block_two 2025-03-24 07:05:17 +01:00
Carl Åstholm
777215d78b Use -unknown when converting WASI/Emscripten target triples into LLVM triples
The "musl" part of the Zig target triples `wasm32-wasi-musl` and
`wasm32-emscripten-musl` refers to the libc, not really the ABI.

For WASM, most LLVM-based tooling uses `wasm32-wasi`, which is
normalized into `wasm32-unknown-wasi`, with an implicit `-unknown` and
without `-musl`.

Similarly, Emscripten uses `wasm32-unknown-emscripten` without `-musl`.

By using `-unknown` instead of `-musl` we get better compatibility with
external tooling.
2025-03-24 07:04:33 +01:00
mlugg
26fdb81c16 Sema: fix in-memory coercion of functions introducing new generic parameters
While it is not allowed for a function coercion to change whether a
function is generic, it *is* okay to make existing concrete parameters
of a generic function also generic, or vice versa. Either of these cases
implies that the result is a generic function, so comptime type checks
will happen when the function is ultimately called.

Resolves: #21099
2025-03-24 04:32:45 +00:00
Jacob Young
98640cbeb8
Merge pull request #23209 from jacobly0/x86_64-rewrite
x86_64: rewrite wrapping multiplication
2025-03-23 21:56:58 -04:00
Jacob Young
f7e045c806 Merge pull request #23256 from xtexx/fix-gh-20113
x86_64: fix packedStore miscomp by spilling EFLAGS
2025-03-23 21:46:46 -04:00
Jacob Young
6705cbd5eb codegen: fix packed byte-aligned relocations
Closes #23131
2025-03-23 18:35:34 -04:00
Carl Åstholm
f45f9649e3 Lower @returnAddress to a constant 0 in Emscripten release builds
Emscripten currently implements `emscripten_return_address()` by calling
out into JavaScript and parsing a stack trace, which introduces
significant overhead that we would prefer to avoid in release builds.

This is especially problematic for allocators because the generic parts
of `std.mem.Allocator` make frequent use of `@returnAddress`, even
though very few allocator implementations even observe the return
address, which makes allocators nigh unusable for performance-critical
applications like games if the compiler is unable to devirtualize the
allocator calls.
2025-03-23 17:13:19 -04:00
mlugg
9f235a105b link: mark prelink tasks as procesed under -fno-emit-bin
The old logic only decremented `remaining_prelink_tasks` if `bin_file`
was not `null`. This meant that on `-fno-emit-bin` builds with
registered prelink tasks (e.g. C source files), we exited from
`Compilation.performAllTheWorkInner` early, assuming a prelink error.

Instead, when `bin_file` is `null`, we still decrement
`remaining_prelink_tasks`; we just don't do any actual work.

Resolves: #22682
2025-03-22 21:44:46 -04:00
Ryan Liptak
66dcebcc76 getenvW: Take advantage of sliceTo/indexOfScalarPos optimizations
Both sliceTo and indexOfScalarPos use SIMD when available to speed up the search. On my x86_64 machine, this leads to getenvW being around 2-3x faster overall.

Additionally, any future improvements to sliceTo/indexOfScalarPos will benefit getenvW.
2025-03-22 16:02:58 -07:00
Ryan Liptak
78ecf3bb3a windows: Document Environment pointer 2025-03-22 15:44:27 -07:00
Ryan Liptak
752e7c0fd0 Add standalone test for environment variables
Tests all environment variable APIs in std.process
2025-03-22 15:44:27 -07:00
Bingwu Zhang
a26f1768d8
x86_64: add behavior test for packed store 2025-03-22 16:36:14 +08:00
Jacob Young
3c3a6c937b x86_64: fix rare miscomp that clobbers memory 2025-03-22 04:29:18 -04:00
Bingwu Zhang
c62fb118e7
x86_64: fix packedStore miscomp by spilling EFLAGS
Fixes #20113 and #20581.

AND instructions in packedStore clobbers EFLAGS.

Bug: https://github.com/ziglang/zig/issues/20113
Bug: https://github.com/ziglang/zig/issues/20581
Signed-off-by: Bingwu Zhang <xtex@aosc.io>
2025-03-22 16:06:07 +08:00
Jacob Young
2361468e23 x86_64: rewrite scalar shifts 2025-03-21 21:51:09 -04:00
Jacob Young
aff2be01c9 big.int: fix negative multi-limb shift right adjust crash 2025-03-21 21:51:08 -04:00
Jacob Young
8e15321c7c behavior: split up x86_64 math tests 2025-03-21 21:51:08 -04:00
Jacob Young
c5c1c8538d x86_64: rewrite wrapping multiplication 2025-03-21 21:51:08 -04:00
Jacob Young
ed284c1f98 big.int: fix yet another truncate bug
Too many bugs have been found with `truncate` at this point, so it was
rewritten from scratch.

Based on the doc comment, the utility of `convertToTwosComplement` over
`r.truncate(a, .unsigned, bit_count)` is unclear and it has a subtle
behavior difference that is almost certainly a bug, so it was deleted.
2025-03-21 21:51:08 -04:00
Ryan Liptak
9c9d3931df Trick the meson build system into thinking zig rc is rc.exe
When determining the type of RC compiler, meson passes `/?` or `--version` and then reads from `stdout` looking for particular string(s) anywhere in the output.

So, by adding the string "Microsoft Resource Compiler" to the `/?` output, meson will recognize `zig rc` as rc.exe and give it the correct options, which works fine since `zig rc` is drop-in CLI compatible with rc.exe.

This allows using `zig rc` with meson for (cross-)compiling, by either:

- Setting WINDRES="zig rc" or putting windres = ['zig', 'rc'] in the cross-file
  + This will work like rc.exe, so it will output .res files. This will only link successfully if you are using a linker that can do .res -> .obj conversion (so something like zig cc, MSVC, lld)
- Setting WINDRES="zig rc /:output-format coff" or putting windres = ['zig', 'rc', '/:output-format', 'coff'] in the cross-file
  + This will make meson pass flags as if it were rc.exe, but it will cause the resulting .res file to actually be a COFF object file, meaning it will work with any linker that handles COFF object files

Example cross file that uses `zig cc` (which can link `.res` files, so `/:output-format coff` is not necessary) and `zig rc`:

```
[binaries]
c = ['zig', 'cc', '--target=x86_64-windows-gnu']
windres = ['zig', 'rc']

[target_machine]
system = 'windows'
cpu_family = 'x86_64'
cpu = 'x86_64'
endian = 'little'
```
2025-03-21 18:07:16 -04:00
Robin Voetter
aa8aa66253
Merge pull request #23297 from igaryhe/dan/more-spirv-optype
spirv: Assemble OpTypeRuntimeArray.
2025-03-20 12:14:05 +01:00
dan
07c04bcd83 spirv: Assemble OpTypeRuntimeArray. 2025-03-19 11:45:35 +08:00
Alex Rønne Petersen
03123916e5 compiler: Support more GCC code models and fix the mapping to LLVM code models.
Closes #22517.
2025-03-19 03:15:16 +01:00
Robin Voetter
5105c3c7fa
Merge pull request #23158 from alichraghi/ali_spirv
spirv: miscellaneous stuff #2
2025-03-18 22:31:57 +01:00
Alex Rønne Petersen
074dd4d083 mingw: Rename mingw32.lib to libmingw32.lib.
LLD expects the library file name (minus extension) to be exactly libmingw32. By
calling it mingw32 previously, we prevented it from being detected as being in
LLD's list of libraries that are excluded from the MinGW-specific auto-export
mechanism.

b9d27ac252/lld/COFF/MinGW.cpp (L30-L56)

As a result, a DLL built for *-windows-gnu with Zig would export a bunch of
internal MinGW symbols. This sometimes worked out fine, but it could break at
link or run time when linking an EXE with a DLL, where both are targeting
*-windows-gnu and thus linking separate copies of mingw32.lib. In #23204, this
manifested as the linker getting confused about _gnu_exception_handler() because
it was incorrectly exported by the DLL while also being defined in the
mingw32.lib that was being linked into the EXE.

Closes #23204.
2025-03-18 10:58:52 +01:00
Ali Cheraghi
ee06b2ce76 spirv: require int8/int16 capabilities 2025-03-18 07:05:50 +03:30
Ali Cheraghi
d18eaf8586 spirv: aligned load for physical storage variables
Resolves #23212
2025-03-18 07:05:50 +03:30
Ali Cheraghi
54c097f50d spirv: packed struct init + field val access 2025-03-18 07:05:48 +03:30
Ryan Liptak
b2cc408a3e std.process: Allow WTF-8 in env var functions with comptime-known keys 2025-03-17 17:53:38 -07:00
Ryan Liptak
423761bb6d createWindowsEnvBlock: Reduce NUL terminator count to only what's required
This code previously added 4 NUL code units, but that was likely due to a misinterpretation of this part of the CreateProcess documentation:

> A Unicode environment block is terminated by four zero bytes: two for the last string, two more to terminate the block.

(four zero *bytes* means *two* zero code units)

Additionally, the second zero code unit is only actually needed when the environment is empty due to a quirk of the CreateProcess implementation. In the case of a non-empty environment, there always ends up being two trailing NUL code units since one will come after the last environment variable in the block.
2025-03-17 17:53:38 -07:00
Ali Cheraghi
50539a2447 spirv/target: arbitrary_precision_integers feature support 2025-03-17 21:56:17 +03:30
Ali Cheraghi
e2e7577474 spirv: lower more types in assembler 2025-03-17 21:56:17 +03:30
Ali Cheraghi
78ad866dd1 target: split addresses and physical_storage_buffer features 2025-03-17 21:56:17 +03:30
Ali Cheraghi
c1977bf0fb Sema: error on illegal code when targeting spirv 2025-03-17 21:56:14 +03:30
Ali Cheraghi
2fc409a32f spirv: don't hardcode test error type alignment 2025-03-17 20:19:08 +03:30
mlugg
2a4e06bcb3 Sema: rewrite comptime arithmetic
This commit reworks how Sema handles arithmetic on comptime-known
values, fixing many bugs in the process.

The general pattern is that arithmetic on comptime-known values is now
handled by the new namespace `Sema.arith`. Functions handling comptime
arithmetic no longer live on `Value`; this is because some of them can
emit compile errors, so some *can't* go on `Value`. Only semantic
analysis should really be doing arithmetic on `Value`s anyway, so it
makes sense for it to integrate more tightly with `Sema`.

This commit also implements more coherent rules surrounding how
`undefined` interacts with comptime and mixed-comptime-runtime
arithmetic. The rules are as follows.

* If an operation cannot trigger Illegal Behavior, and any operand is
  `undefined`, the result is `undefined`. This includes operations like
  `0 *| undef`, where the LHS logically *could* be used to determine a
  defined result. This is partly to simplify the language, but mostly to
  permit codegen backends to represent `undefined` values as completely
  invalid states.

* If an operation *can* trigger Illegal Behvaior, and any operand is
  `undefined`, then Illegal Behavior results. This occurs even if the
  operand in question isn't the one that "decides" illegal behavior; for
  instance, `undef / 1` is undefined. This is for the same reasons as
  described above.

* An operation which would trigger Illegal Behavior, when evaluated at
  comptime, instead triggers a compile error. Additionally, if one
  operand is comptime-known undef, such that the other (runtime-known)
  operand isn't needed to determine that Illegal Behavior would occur,
  the compile error is triggered.

* The only situation in which an operation with one comptime-known
  operand has a comptime-known result is if that operand is undefined,
  in which case the result is either undefined or a compile error per
  the above rules. This could potentially be loosened in future (for
  instance, `0 * rt` could be comptime-known 0 with a runtime assertion
  that `rt` is not undefined), but at least for now, defining it more
  conservatively simplifies the language and allows us to easily change
  this in future if desired.

This commit fixes many bugs regarding the handling of `undefined`,
particularly in vectors. Along with a collection of smaller tests, two
very large test cases are added to check arithmetic on `undefined`.

The operations which have been rewritten in this PR are:

* `+`, `+%`, `+|`, `@addWithOverflow`
* `-`, `-%`, `-|`, `@subWithOverflow`
* `*`, `*%`, `*|`, `@mulWithOverflow`
* `/`, `@divFloor`, `@divTrunc`, `@divExact`
* `%`, `@rem`, `@mod`

Other arithmetic operations are currently unchanged.

Resolves: #22743
Resolves: #22745
Resolves: #22748
Resolves: #22749
Resolves: #22914
2025-03-16 08:17:50 +00:00
mlugg
aa3db7cc15 Sema: correctly handle empty by-ref initializers
Resolves: #23210
2025-03-16 03:05:33 +00:00
Jonathan Gautheron
ea57fb55ea std.zig.c_translation: fix function pointer casting 2025-03-15 16:21:55 +02:00
Roman Frołow
37bbe7e930 typo: was issues -> was issued 2025-03-15 12:14:00 +01:00
Rémy Mathieu
42160327dc
posix/write: catch MSGSIZE error (#23238) 2025-03-15 12:04:42 +01:00
Loris Cro
11b49e9002 std.Build.Watch: fix macos implementation
The code did one useless thing and two wrong things:

- ref counting was basically a noop
- last_dir_fd was chosen from the wrong index and also under the wrong
  condition

This caused regular crashes on macOS which are now gone.
2025-03-15 05:29:54 +00:00
Elijah M. Immer
1f92b394e9
lib/std/http/Client.zig: Ignore empty proxy environment variables (#23223)
This fixes #21032 by ignoring proxy environment variables that are
empty.
2025-03-14 21:20:42 +01:00
TCROC
d590b87b6f
glibc: fix uninitialized memory in __pthread_cond_s for <=2.40
* https://sourceware.org/bugzilla/show_bug.cgi?id=32786
* https://inbox.sourceware.org/libc-alpha/87zfhpfqsm.fsf@oldenburg.str.redhat.com
2025-03-13 20:23:27 +00:00
LN Liberda
19888f759f cmake: Add ZIG_RELEASE_SAFE option to build as ReleaseSafe 2025-03-12 18:15:42 +01:00
Matthew Lugg
d0911786c9
Merge pull request #22397 from Techatrix/type-safe-ast
improve type safety of std.zig.Ast
2025-03-12 02:22:41 +00:00
mlugg
a0401cf3e4 Zcu: rename skip_analysis_errors to skip_analysis_this_update and respect it
On updates with failed files, we should refrain from doing any semantic
analysis, or even touching codegen/link. That way, incremental
compilation state is untouched for when the user fixes the AstGen
errors.

Resolves: #23205
2025-03-11 23:38:32 +00:00
mlugg
24db007cde std.mem.Allocator.remap: fix incorrect doc comment (part 2) 2025-03-11 22:15:43 +00:00
孙冰
77395457fe std.c: fix sysconf names (std.c._SC) for android api
c.f. https://android.googlesource.com/platform/bionic/+/refs/heads/main/libc/include/bits/sysconf.h
2025-03-11 21:41:58 +01:00
Andrew Kelley
982c500be5
Merge pull request #23188 from jacobly0/fix-23143
x86_64: fix crashes with symbols
2025-03-11 16:11:09 -04:00
Linus Groh
f660675467 std: Add support for SerenityOS in various places
Not nearly the entire downstream patchset but these are completely
uncontroversial and known to work.
2025-03-11 14:59:42 +00:00
Linus Groh
79a0de2a2f std.c: Add definitions for SerenityOS 2025-03-11 14:59:29 +00:00
mlugg
423907c270 Sema: fix handling of @This() on opaques
Resolves: #22869
2025-03-11 13:13:52 +00:00
Mathias Lafeldt
7e751e8040
Merge pull request #23193 from mlafeldt/fix-macho-detection
Fetch: enhance Mach-O executable detection for modern Macs

closes #21044
2025-03-11 06:12:13 +00:00
mlugg
5ffd8bf5f6 std.mem.Allocator.remap: fix incorrect doc comment
Resolves: #23194
2025-03-11 04:15:38 +00:00
Jacob Young
cff90e3ae0 x86_64: implement select of register mask 2025-03-10 10:38:33 -04:00
Jacob Young
0ef3250c34 x86_64: fix symbol bugs
Closes #23143
2025-03-10 10:38:30 -04:00
Jacob Young
e83607f52c Dwarf: remove comptime parameters from generic origin functions
Since generic instantiations are missing comptime arguments in Air, they
must be removed from the generic origins too.
2025-03-10 08:46:00 -04:00
Pat Tullmann
8e0a4ca4b3 Enable compiler-rt tests for wasm32-wasi
I think the underlying issue was the same as
https://github.com/ziglang/zig/issues/13258 and that has a work-around in
LLVM 19 (see https://github.com/llvm/llvm-project/issues/58557).

Fixes #15325
2025-03-10 06:15:12 +01:00
Andrew Kelley
539f3effd3
Merge pull request #21933 from kcbanner/comptime_nan_comparison
Fix float vector comparisons with signed zero and NaN, add test coverage
2025-03-09 15:06:25 -04:00
Alex Rønne Petersen
9840157c18 std.Target.Query: Don't append glibc version in zigTriple() if ABI isn't GNU. 2025-03-09 19:50:13 +01:00
Carmen
17b40b1d68 lib/std/os/uefi/status.zig: add error to enum conversion fn 2025-03-09 10:54:21 +00:00
Meghan Denny
0f6056903b std: Abi.default: only require an os tag 2025-03-09 09:44:11 +01:00
Pat Tullmann
eace31c6b3 std/lib: {fs,io,posix} test clean up
* use `tmp.dir.realpathAlloc()` to get full path into tmpDir instances
* use `testing.allocator` where that simplifies things (vs. manual ArenaAllocator for 1 or 2 allocs)
* Trust `TmpDir.cleanup()` to clean up contained files and sub-trees
* Remove some unnecessary absolute paths (enabling WASI to run the tests)
* Drop some no-longer necessary `[_][]const u8` casts
* Add scopes to reduce `var` usage in favor of `const`
2025-03-09 07:41:06 +01:00
remeh
02f63fdee9 std/containers: improve consistency using gpa parameter name for allocator. 2025-03-09 07:39:20 +01:00
Andrew Kelley
1eb729b9b9 Reapply "build: Don't check parent directories for git tag"
This reverts commit 7e0c25eccd8d9bc5b77953dbc9a39a26e383c550.

The `--git-dir` argument is relative to the `-C` argument, making this
patch OK after all.

I added a comment to go along with this since I found it confusing.

Apologies for the revert.
2025-03-08 12:34:13 -08:00
Ian Johnson
0bce4a4e05 Sema: handle generated tag enums in union field order check
Fixes #23059

The "note: enum field here" now references the field in the base union type rather than crashing.
2025-03-08 14:29:20 -05:00
Andrew Kelley
61c588d726
Merge pull request #22998 from jacobly0/x86_64-rewrite
x86_64: rewrite aggregate init
2025-03-08 14:27:57 -05:00
Jeremy Hertel
801a95035c std.time.epoch: change getDaysInMonth to accept the year as an argument 2025-03-08 14:25:28 -05:00
Jacob Young
a5900e310e compiler-rt: fix signed min int from float 2025-03-08 14:21:22 -05:00
Andrew Kelley
7e0c25eccd Revert "build: Don't check parent directories for git tag"
This reverts commit 21620f3c652bc874776acc7251f05b25d2838019.

This breaks running `zig build` from subdirectories.
2025-03-08 11:15:44 -08:00
LN Liberda
21620f3c65 build: Don't check parent directories for git tag
Sometimes Zig is built not from a git repository (e.g. from tarball), but inside another git repository (e.g. distro package repository). Make sure that the version check tries to parse a tag of Zig, and not of a parent directory.
2025-03-08 17:54:50 +00:00
Alex Rønne Petersen
3b3c18909d Compilation: Fix -fno-rtlib-defaultlib unused argument warning in ReleaseSafe.
Closes #23138.
2025-03-08 13:26:09 +01:00
Alex Rønne Petersen
5466a2f72d llvm: Replace DataLayoutBuilder with a simple target -> string switch.
This should be a lot easier to maintain. It's also a small step towards
eventually making the builder API parse the data layout string in order to
answer layout questions that we need to ask during code generation.
2025-03-08 12:16:13 +01:00
Alex Rønne Petersen
5c57e90ffb test: Disable test-elf-ld-script-path-error for now.
https://github.com/ziglang/zig/issues/23125
2025-03-08 07:04:27 +01:00
Jacob Young
5d115632d4 x86_64: reuse single register code during register write splitting 2025-03-07 23:59:38 -05:00
Jacob Young
54ed62755f x86_64: implement write register splitting 2025-03-07 23:59:31 -05:00
Jacob Young
f8f2a3ea6f x86_64: rewrite aggregate init 2025-03-07 23:59:09 -05:00
Pat Tullmann
214750fcfe lib/std/Build/Cache.zig: remove .wasi SkipZigTest checks
The build Cache test pass on Wasi now.

Fixes #5437
2025-03-08 04:38:29 +01:00
Alex Rønne Petersen
db77e46b49 zig cc: Don't pass -mabi for assembly files when targeting arm.
Clang's integrated Arm assembler doesn't understand -mabi yet, so this results
in "unused command line argument" warnings when building musl code and glibc
stubs, for example.
2025-03-08 03:52:28 +01:00
Techatrix
4129f7ff5a
std.zig.Ast: store lbrace and rbrace token in data of .error_set_decl
This makes the `.data` field the better choice over the `.main_token` for this tag.
2025-03-07 22:22:01 +01:00
Techatrix
d84055f9c6
std.zig.Ast: don't set the data field on .error_value and .enum_literal
The main_token already has the necessary information.
2025-03-07 22:22:01 +01:00
Techatrix
ba74af2ae8
std.zig.Ast: update doc comments of Node.Tag
The existing comment are incomplete, outdated and sometimes incorrect.
2025-03-07 22:22:01 +01:00
Techatrix
ca6fb30e99
std.zig.Ast: improve type safety
This commits adds the following distinct integer types to std.zig.Ast:
- OptionalTokenIndex
- TokenOffset
- OptionalTokenOffset
- Node.OptionalIndex
- Node.Offset
- Node.OptionalOffset

The `Node.Index` type has also been converted to a distinct type while
`TokenIndex` remains unchanged.

`Ast.Node.Data` has also been changed to a (untagged) union to provide
safety checks.
2025-03-07 22:22:01 +01:00
Techatrix
6dcd8f4f75
std.zig.Ast: add blockStatements and builtinCallParams 2025-03-07 22:20:35 +01:00
Techatrix
de9c889a0e
aro_translate_c: fix ast lowering of continue node
fixes #22601
2025-03-07 22:20:35 +01:00
Techatrix
e6596cbbf0
add a reference to #21690 2025-03-07 22:20:35 +01:00
Techatrix
c19f4c4402
fix ZonGen error message when encountering an array access 2025-03-07 22:20:35 +01:00
Techatrix
ad38af77fa
remove unreachable code paths from std.zig.Ast.lastToken
This function checks for various possibilities that are never produced
by the parser.
Given that lastToken is unsafe to call on an Ast with errors, I also
removed code paths that would be reachable on an Ast with errors.
2025-03-07 22:20:34 +01:00
Andrew Kelley
5765736867 fix InstallArtifact opening empty string
this appears to have been a problem since 43f73af3595c3174b8e67e9f2792c3774f2192e9
2025-03-07 15:21:40 -05:00
Jan200101
013a228960 std.Build: add build-id option 2025-03-07 10:59:02 +01:00
Andrew Kelley
4cefd1bd1b
Merge pull request #23097 from ziggoon/master
std.heap.PageAllocator updates to fix race condition and utilize NtAllocateVirtualMemory / NtFreeVirtualMemory instead of VirtualAlloc / VirtualFree
2025-03-06 14:39:09 -05:00
190n
1e0739f0c6 std.enums.tagName: preserve sentinel in return value 2025-03-06 08:41:51 +01:00
Kiëd Llaentenn
5f7dfc3577 langref: update splat section 2025-03-06 07:26:19 +01:00
Igor Anić
94b36dbe50 io_uring: refactor buf_reg flags
Use packed struct instead of or-ed integers.

Thanks to @linsug for pr comments: https://github.com/ziglang/zig/pull/23062
2025-03-05 13:35:52 +01:00
Igor Anić
c133171567 io_uring: incremental provided buffer consumption
[Incremental provided buffer
consumption](https://github.com/axboe/liburing/wiki/What's-new-with-io_uring-in-6.11-and-6.12#incremental-provided-buffer-consumption)
support is added in kernel 6.12.

IoUring.BufferGroup will now use incremental consumption whenever
kernel supports it.

Before, provided buffers are wholly consumed when picked. Each cqe
points to the different buffer. With this, cqe points to the part of the
buffer. Multiple cqe's can reuse same buffer.
Appropriate sizing of buffers becomes less important.

There are slight changes in BufferGroup interface (it now needs to track
current receive point for each buffer). Init requires allocator
instead of buffers slice, it will allocate buffers slice and head
pointers slice. Get and put now requires cqe becasue there we have
information will the buffer be reused.
2025-03-05 13:35:52 +01:00
Igor Anić
4df039d235 io_uring: add setsockopt/getsockopt
ring.cmd_sock is generic socket operation. Two most common uses are
setsockopt and getsockopt. This provides same interface as posix
versions of this methods.

libring has also [sqe_set_flags](https://man7.org/linux/man-pages/man3/io_uring_sqe_set_flags.3.html)
method. Adding that in our io_uring_sqe. Adding sqe.link_next method for setting most common flag.
2025-03-05 13:35:52 +01:00
Igor Anić
d98c0893b0 io_uring: probe capabilities function
ring.get_probe returns io_uring_probe which can be use to probe
capabilities of the current running kernel.

Ref:
https://unixism.net/loti/ref-liburing/supported_caps.html
e1003e496e/src/setup.c (L454)
2025-03-05 13:35:52 +01:00
Igor Anić
85e2074878 io_uring: fix tests on 5.4.0 kernel
Found it failing in a new way on that kernel.
2025-03-05 13:35:52 +01:00
Igor Anić
2da8eff9d6 io_uring: add bind and listen 2025-03-05 13:35:52 +01:00
kcbanner
144d69b571 test: add comptime memoization tests for bit-for-bit float equality 2025-03-04 23:31:12 -05:00
kcbanner
8eefc4c5c2 test: skip the float vector cmp tests on failing targets 2025-03-04 23:31:08 -05:00
ziggoon
5b03e248b7 add FFI & wrappers for NtAllocateVirtualMemory & NtFreeVirtualMemory + add missing alloction constants MEM_RESERVE_PLACEHOLDER / MEM_PRESERVE_PLACEHOLDER 2025-03-04 22:10:49 -06:00
ziggoon
16875b3598 update std.heap.PageAllocator Windows implementation to remove race condition and utilize NtAllocateVirtualMemory / NtFreeVirtualMemory instead of VirtualAlloc and VirtualFree 2025-03-04 22:01:08 -06:00
Linus Groh
79460d4a3e Remove uses of deprecated callconv aliases 2025-03-05 03:01:43 +00:00
Andrew Kelley
05937b362a start the 0.15.0 release cycle 2025-03-04 14:31:32 -08:00
kcbanner
71d0d4bbfe test: separate out float vector tests and skip them on unsupported backends 2025-03-03 15:35:07 -05:00
kcbanner
981f84157c Value: fix comparison of NaN in compareHeteroAdvanaced
Sema: fix equality comparison of signed zeroes and NaN in compareScalar
tests: add test coverage for vector float comparisons
2025-03-03 15:35:07 -05:00
Misaki Kasumi
cc65eaf0a9 std.os.linux: remove app_mask 2025-02-05 06:25:04 +01:00
10783 changed files with 1461953 additions and 555794 deletions

View File

@ -1,6 +1,6 @@
name: Bug Report
description: File a bug report
labels: ["bug"]
labels: ["kind/bug"]
body:
- type: markdown
attributes:

View File

@ -0,0 +1,13 @@
contact_links:
- name: Language Proposal
about: "Please do not submit a proposal to change the language"
url: https://ziglang.org/code-of-conduct
- name: Question
about: "Please use one of the community spaces instead for questions or general discussions."
url: https://ziglang.org/community
- name: C Translation
about: "Issues related to `zig translate-c` and `@cImport` are tracked separately."
url: https://codeberg.org/ziglang/translate-c
- name: Copilot and Other LLMs
about: "Please do not use GitHub Copilot or any other LLM to write an issue."
url: https://ziglang.org/code-of-conduct

View File

@ -1,6 +1,6 @@
name: Error message improvement
description: Compiler produces an unhelpful or misleading error message.
labels: ["error message"]
labels: ["kind/error message"]
body:
- type: input
id: version

196
.forgejo/workflows/ci.yaml Normal file
View File

@ -0,0 +1,196 @@
name: ci
on:
pull_request:
push:
branches:
- master
workflow_dispatch:
concurrency:
group: ${{ github.head_ref || github.run_id }}-${{ github.actor }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
permissions:
contents: read
jobs:
aarch64-linux-debug:
runs-on: [self-hosted, aarch64-linux]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/aarch64-linux-debug.sh
timeout-minutes: 180
aarch64-linux-release:
runs-on: [self-hosted, aarch64-linux]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/aarch64-linux-release.sh
timeout-minutes: 120
aarch64-macos-debug:
runs-on: [self-hosted, aarch64-macos]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/aarch64-macos-debug.sh
timeout-minutes: 180
aarch64-macos-release:
runs-on: [self-hosted, aarch64-macos]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/aarch64-macos-release.sh
timeout-minutes: 120
loongarch64-linux-debug:
runs-on: [self-hosted, loongarch64-linux]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/loongarch64-linux-debug.sh
timeout-minutes: 240
loongarch64-linux-release:
runs-on: [self-hosted, loongarch64-linux]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/loongarch64-linux-release.sh
timeout-minutes: 180
riscv64-linux-debug:
if: github.event_name != 'pull_request'
runs-on: [self-hosted, riscv64-linux]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/riscv64-linux-debug.sh
timeout-minutes: 600
riscv64-linux-release:
if: github.event_name != 'pull_request'
runs-on: [self-hosted, riscv64-linux]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/riscv64-linux-release.sh
timeout-minutes: 480
s390x-linux-debug:
runs-on: [self-hosted, s390x-linux]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/s390x-linux-debug.sh
timeout-minutes: 300
s390x-linux-release:
runs-on: [self-hosted, s390x-linux]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/s390x-linux-release.sh
timeout-minutes: 240
x86_64-freebsd-debug:
runs-on: [self-hosted, x86_64-freebsd]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/x86_64-freebsd-debug.sh
timeout-minutes: 120
x86_64-freebsd-release:
runs-on: [self-hosted, x86_64-freebsd]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/x86_64-freebsd-release.sh
timeout-minutes: 120
x86_64-linux-debug:
runs-on: [self-hosted, x86_64-linux]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/x86_64-linux-debug.sh
timeout-minutes: 240
x86_64-linux-debug-llvm:
runs-on: [self-hosted, x86_64-linux]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/x86_64-linux-debug-llvm.sh
timeout-minutes: 480
x86_64-linux-release:
runs-on: [self-hosted, x86_64-linux]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/x86_64-linux-release.sh
timeout-minutes: 480
x86_64-windows-debug:
runs-on: [self-hosted, x86_64-windows]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build and Test
run: ci/x86_64-windows-debug.ps1
timeout-minutes: 180
x86_64-windows-release:
runs-on: [self-hosted, x86_64-windows]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build and Test
run: ci/x86_64-windows-release.ps1
timeout-minutes: 180

20
.gitattributes vendored
View File

@ -2,14 +2,24 @@
*.zon text eol=lf
*.txt text eol=lf
langref.html.in text eol=lf
lib/std/compress/testdata/** binary
lib/std/compress/deflate/testdata/** binary
lib/std/compress/flate/testdata/** binary
lib/libc/*/abilists binary
lib/std/compress/testdata/** binary
lib/std/compress/flate/testdata/** binary
lib/std/compress/lzma/testdata/** binary
lib/std/compress/xz/testdata/** binary
lib/std/crypto/codecs/asn1/der/testdata/** binary
lib/std/tar/testdata/** binary
src/Package/Fetch/testdata/** binary
src/Package/Fetch/git/testdata/** binary
lib/compiler/aro/** linguist-vendored
lib/compiler/resinator/** linguist-vendored
lib/compiler/translate-c/** linguist-vendored
lib/include/** linguist-vendored
lib/libc/** linguist-vendored
lib/libcxx/** linguist-vendored
lib/libcxxabi/** linguist-vendored
lib/libtsan/** linguist-vendored
lib/libunwind/** linguist-vendored
lib/tsan/** linguist-vendored
lib/compiler/aro/** linguist-vendored

View File

@ -1,75 +0,0 @@
# Code of Conduct
Hello, and welcome! 👋
The Zig community is decentralized. Anyone is free to start and maintain their
own space for people to gather, and edit
[the Community wiki page](https://github.com/ziglang/zig/wiki/Community) to add
a link. There is no concept of "official" or "unofficial", however, each
gathering place has its own moderators and rules.
This is Andrew Kelley speaking. At least for now, I'm the moderator of the
ziglang organization GitHub repositories and the #zig IRC channel on Libera.chat.
**This document contains the rules that govern these two spaces only**.
The rules here are strict. This space is for focused, on topic, technical work
on the Zig project only. It is everyone's responsibility to maintain a positive
environment, especially when disagreements occur.
## Our Standards
Examples of behavior that contribute to creating a positive environment include:
* Using welcoming and inclusive language.
* Being respectful of differing viewpoints and experiences.
* Gracefully accepting constructive criticism.
* Helping another person accomplish their own goals.
* Showing empathy towards others.
* Showing appreciation for others' work.
* Validating someone else's experience, skills, insight, and use cases.
Examples of unacceptable behavior by participants include:
* Unwelcome sexual attention or advances, or use of sexualized language or
imagery that causes discomfort.
* Trolling, insulting/derogatory comments, and personal attacks. Anything
antagonistic towards someone else.
* Off-topic discussion of any kind - especially offensive or sensitive issues.
* Publishing others' private information, such as a physical or electronic
address, without explicit permission.
* Discussing this Code of Conduct or publicly accusing someone of violating it.
* Making someone else feel like an outsider or implying a lack of technical
abilities.
* Destructive behavior. Anything that harms Zig or another open-source project.
## Enforcement
If you need to report an issue you can contact me or Loris Cro, who are both
paid by the Zig Software Foundation, and so moderation of this space is part of
our job. We will swiftly remove anyone who is antagonizing others or being
generally destructive.
This includes Private Harassment. If person A is directly harassed or
antagonized by person B, person B will be blocked from participating in this
space even if the harassment didn't take place on one of the mediums directly
under rule of this Code of Conduct.
As noted, discussing this Code of Conduct should not take place on GitHub or IRC
because these spaces are for directly working on code, not for meta-discussion.
If you have any issues with it, you can contact me directly, or you can join one
of the community spaces that has different rules.
* Andrew Kelley <andrew@ziglang.org>
* Loris Cro <loris@ziglang.org>
## Conclusion
Thanks for reading the rules. Together, we can make this space welcoming and
inclusive for everyone, regardless of age, body size, disability, ethnicity,
sex characteristics, gender identity and expression, level of experience,
education, socio-economic status, nationality, personal appearance, race,
religion, or sexual identity and orientation.
Sincerely,
Andrew ✌️

View File

@ -1,3 +0,0 @@
Please see the
[Contributing](https://github.com/ziglang/zig/wiki/Contributing)
page on the wiki.

1
.github/FUNDING.yml vendored
View File

@ -1 +0,0 @@
github: [ziglang]

View File

@ -1,7 +0,0 @@
contact_links:
- name: Language Proposal
about: Propose to improve the Zig language
url: https://github.com/ziglang/zig/wiki/Language-Proposals
- name: Question
about: Please use one of the community spaces for questions or general discussions.
url: https://github.com/ziglang/zig/wiki/Community

View File

@ -1,94 +0,0 @@
name: ci
on:
pull_request:
push:
branches:
- master
- llvm19
concurrency:
# Cancels pending runs when a PR gets updated.
group: ${{ github.head_ref || github.run_id }}-${{ github.actor }}
cancel-in-progress: true
permissions:
# Sets permission policy for `GITHUB_TOKEN`
contents: read
jobs:
x86_64-linux-debug:
timeout-minutes: 420
runs-on: [self-hosted, Linux, x86_64]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Test
run: sh ci/x86_64-linux-debug.sh
x86_64-linux-release:
timeout-minutes: 420
runs-on: [self-hosted, Linux, x86_64]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Test
run: sh ci/x86_64-linux-release.sh
aarch64-linux-debug:
timeout-minutes: 480
runs-on: [self-hosted, Linux, aarch64]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Test
run: sh ci/aarch64-linux-debug.sh
aarch64-linux-release:
timeout-minutes: 480
runs-on: [self-hosted, Linux, aarch64]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Test
run: sh ci/aarch64-linux-release.sh
x86_64-macos-release:
runs-on: "macos-13"
env:
ARCH: "x86_64"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Test
run: ci/x86_64-macos-release.sh
aarch64-macos-debug:
runs-on: [self-hosted, macOS, aarch64]
env:
ARCH: "aarch64"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Test
run: ci/aarch64-macos-debug.sh
aarch64-macos-release:
runs-on: [self-hosted, macOS, aarch64]
env:
ARCH: "aarch64"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Test
run: ci/aarch64-macos-release.sh
x86_64-windows-debug:
timeout-minutes: 420
runs-on: [self-hosted, Windows, x86_64]
env:
ARCH: "x86_64"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Test
run: ci/x86_64-windows-debug.ps1
x86_64-windows-release:
timeout-minutes: 420
runs-on: [self-hosted, Windows, x86_64]
env:
ARCH: "x86_64"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Test
run: ci/x86_64-windows-release.ps1

4
.gitignore vendored
View File

@ -16,7 +16,3 @@ zig-out/
/build/
/build-*/
/docgen_tmp/
# Although this was renamed to .zig-cache, let's leave it here for a few
# releases to make it less annoying to work with multiple branches.
zig-cache/

View File

@ -4,8 +4,13 @@ Andrea Orru <andrea@orru.io> <andreaorru1991@gmail.com>
Andrew Kelley <andrew@ziglang.org> <superjoe30@gmail.com>
Bogdan Romanyuk <wrongnull@gmail.com> <65823030+wrongnull@users.noreply.github.com>
Casey Banner <kcbanner@gmail.com>
Dacheng Gao <successgdc@gmail.com>
Daniel Kongsgaard <dakongsgaard@gmail.com>
David Carlier <devnexen@gmail.com>
David Rubin <daviru007@icloud.com> <87927264+Rexicon226@users.noreply.github.com>
David Rubin <david@vortan.dev>
David Rubin <david@vortan.dev> <daviru007@icloud.com>
David Rubin <david@vortan.dev> <87927264+Rexicon226@users.noreply.github.com>
David Senoner <seda18@rolmail.net>
Dominic <4678790+dweiller@users.noreply.github.com>
Dominic <4678790+dweiller@users.noreply.github.com> <4678790+dweiller@users.noreplay.github.com>
Eric Eastwood <madlittlemods@gmail.com> <contact@ericeastwood.com>
@ -26,6 +31,7 @@ Igor Anić <igor.anic@gmail.com>
IntegratedQuantum <jahe788@gmail.com> <43880493+IntegratedQuantum@users.noreply.github.com>
Isaac Freund <mail@isaacfreund.com> <ifreund@ifreund.xyz>
Isaac Freund <mail@isaacfreund.com> <isaac.freund@coil.com>
Ivan Stepanov <ivanstepanovftw@gmail.com>
Jacob Young <amazingjacob@gmail.com>
Jacob Young <amazingjacob@gmail.com> <jacobly0@users.noreply.github.com>
Jacob Young <amazingjacob@gmail.com> <15544577+jacobly0@users.noreply.github.com>
@ -38,6 +44,7 @@ Jimmi Holst Christensen <jhc@dismail.de> <jimmiholstchristensen@gmail.com>
Jimmi Holst Christensen <jhc@dismail.de> <rainbowhejsil@gmail.com>
Joachim Schmidt <joachim.schmidt557@outlook.com>
Jonathan Marler <johnnymarler@gmail.com> <jonathan.j.marler@hp.com>
Kendall Condon <goon.pri.low@gmail.com> <149842806+gooncreeper@users.noreply.github.com>
Krzysztof Wolicki <der.teufel.mail@gmail.com>
Krzysztof Wolicki <der.teufel.mail@gmail.com> <46651553+der-teufel-programming@users.noreply.github.com>
LemonBoy <thatlemon@gmail.com> <LemonBoy@users.noreply.github.com>
@ -69,6 +76,7 @@ Travis Staloch <twostepted@gmail.com>
Travis Staloch <twostepted@gmail.com> <1562827+travisstaloch@users.noreply.github.com>
Veikka Tuominen <git@vexu.eu>
Veikka Tuominen <git@vexu.eu> <15308111+Vexu@users.noreply.github.com>
Veikka Tuominen <git@vexu.eu> <veikka@ziglang.org>
Will Lillis <will.lillis24@gmail.com>
Will Lillis <will.lillis24@gmail.com> <wlillis@umass.edu>
Wooster <r00ster91@proton.me>

View File

@ -38,7 +38,7 @@ project(zig
)
set(ZIG_VERSION_MAJOR 0)
set(ZIG_VERSION_MINOR 14)
set(ZIG_VERSION_MINOR 16)
set(ZIG_VERSION_PATCH 0)
set(ZIG_VERSION "" CACHE STRING "Override Zig version string. Default is to find out with git.")
@ -90,6 +90,7 @@ set(ZIG_STATIC_LLVM ${ZIG_STATIC} CACHE BOOL "Prefer linking against static LLVM
set(ZIG_STATIC_ZLIB ${ZIG_STATIC} CACHE BOOL "Prefer linking against static zlib")
set(ZIG_STATIC_ZSTD ${ZIG_STATIC} CACHE BOOL "Prefer linking against static zstd")
set(ZIG_STATIC_CURSES OFF CACHE BOOL "Enable static linking against curses")
set(ZIG_STATIC_LIBXML2 OFF CACHE BOOL "Enable static linking against libxml2")
if (ZIG_SHARED_LLVM AND ZIG_STATIC_LLVM)
message(SEND_ERROR "-DZIG_SHARED_LLVM and -DZIG_STATIC_LLVM cannot both be enabled simultaneously")
@ -132,9 +133,9 @@ else()
set(ZIG_SYSTEM_LIBCXX "stdc++" CACHE STRING "system libcxx name for build.zig")
endif()
find_package(llvm 19)
find_package(clang 19)
find_package(lld 19)
find_package(llvm 21)
find_package(clang 21)
find_package(lld 21)
if(ZIG_STATIC_ZLIB)
if (MSVC)
@ -158,6 +159,16 @@ if(ZIG_STATIC_ZSTD)
list(APPEND LLVM_LIBRARIES "${ZSTD}")
endif()
if (MSVC)
if(NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
# avoid linking to the debug versions of ucrt by default
# as they are not redistributable.
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
endif()
endif()
endif ()
if(ZIG_STATIC_CURSES)
list(REMOVE_ITEM LLVM_LIBRARIES "-lcurses")
find_library(CURSES NAMES libcurses.a libncurses.a NAMES_PER_DIR
@ -167,6 +178,12 @@ if(ZIG_STATIC_CURSES)
list(APPEND LLVM_LIBRARIES "${CURSES}")
endif()
if(ZIG_STATIC_LIBXML2)
list(REMOVE_ITEM LLVM_LIBRARIES "-lxml2")
find_library(LIBXML2 NAMES libxml2.a NAMES_PER_DIR)
list(APPEND LLVM_LIBRARIES "${LIBXML2}")
endif()
find_package(Threads)
set(ZIG_CONFIG_H_OUT "${PROJECT_BINARY_DIR}/config.h")
@ -180,7 +197,6 @@ set(ZIG_CPP_SOURCES
# These are planned to stay even when we are self-hosted.
src/zig_llvm.cpp
src/zig_llvm-ar.cpp
src/zig_clang.cpp
src/zig_clang_driver.cpp
src/zig_clang_cc1_main.cpp
src/zig_clang_cc1as_main.cpp
@ -195,9 +211,10 @@ set(ZIG_STAGE2_SOURCES
lib/compiler_rt/absvti2.zig
lib/compiler_rt/adddf3.zig
lib/compiler_rt/addf3.zig
lib/compiler_rt/addo.zig
lib/compiler_rt/addsf3.zig
lib/compiler_rt/addtf3.zig
lib/compiler_rt/addvsi3.zig
lib/compiler_rt/addvdi3.zig
lib/compiler_rt/addxf3.zig
lib/compiler_rt/arm.zig
lib/compiler_rt/atomics.zig
@ -316,6 +333,7 @@ set(ZIG_STAGE2_SOURCES
lib/compiler_rt/mulo.zig
lib/compiler_rt/mulsf3.zig
lib/compiler_rt/multf3.zig
lib/compiler_rt/mulvsi3.zig
lib/compiler_rt/mulxf3.zig
lib/compiler_rt/negXi2.zig
lib/compiler_rt/negdf2.zig
@ -336,9 +354,10 @@ set(ZIG_STAGE2_SOURCES
lib/compiler_rt/sqrt.zig
lib/compiler_rt/stack_probe.zig
lib/compiler_rt/subdf3.zig
lib/compiler_rt/subo.zig
lib/compiler_rt/subsf3.zig
lib/compiler_rt/subtf3.zig
lib/compiler_rt/subvdi3.zig
lib/compiler_rt/subvsi3.zig
lib/compiler_rt/subxf3.zig
lib/compiler_rt/tan.zig
lib/compiler_rt/trig.zig
@ -366,6 +385,9 @@ set(ZIG_STAGE2_SOURCES
lib/std/Build.zig
lib/std/Build/Cache.zig
lib/std/Build/Cache/DepTokenizer.zig
lib/std/Io.zig
lib/std/Io/Reader.zig
lib/std/Io/Writer.zig
lib/std/Progress.zig
lib/std/Random.zig
lib/std/Target.zig
@ -390,7 +412,6 @@ set(ZIG_STAGE2_SOURCES
lib/std/Thread/Futex.zig
lib/std/Thread/Mutex.zig
lib/std/Thread/Pool.zig
lib/std/Thread/ResetEvent.zig
lib/std/Thread/WaitGroup.zig
lib/std/array_hash_map.zig
lib/std/array_list.zig
@ -413,9 +434,7 @@ set(ZIG_STAGE2_SOURCES
lib/std/dwarf/OP.zig
lib/std/dwarf/TAG.zig
lib/std/elf.zig
lib/std/fifo.zig
lib/std/fmt.zig
lib/std/fmt/format_float.zig
lib/std/fmt/parse_float.zig
lib/std/fs.zig
lib/std/fs/AtomicFile.zig
@ -429,22 +448,8 @@ set(ZIG_STAGE2_SOURCES
lib/std/hash_map.zig
lib/std/heap.zig
lib/std/heap/arena_allocator.zig
lib/std/io.zig
lib/std/io/Reader.zig
lib/std/io/Writer.zig
lib/std/io/buffered_atomic_file.zig
lib/std/io/buffered_writer.zig
lib/std/io/change_detection_stream.zig
lib/std/io/counting_reader.zig
lib/std/io/counting_writer.zig
lib/std/io/find_byte_writer.zig
lib/std/io/fixed_buffer_stream.zig
lib/std/io/limited_reader.zig
lib/std/io/seekable_stream.zig
lib/std/json.zig
lib/std/json/stringify.zig
lib/std/leb128.zig
lib/std/linked_list.zig
lib/std/log.zig
lib/std/macho.zig
lib/std/math.zig
@ -486,6 +491,7 @@ set(ZIG_STAGE2_SOURCES
lib/std/unicode.zig
lib/std/zig.zig
lib/std/zig/Ast.zig
lib/std/zig/Ast/Render.zig
lib/std/zig/AstGen.zig
lib/std/zig/AstRlAnnotate.zig
lib/std/zig/LibCInstallation.zig
@ -493,8 +499,6 @@ set(ZIG_STAGE2_SOURCES
lib/std/zig/Server.zig
lib/std/zig/WindowsSdk.zig
lib/std/zig/Zir.zig
lib/std/zig/c_builtins.zig
lib/std/zig/render.zig
lib/std/zig/string_literal.zig
lib/std/zig/system.zig
lib/std/zig/system/NativePaths.zig
@ -506,13 +510,16 @@ set(ZIG_STAGE2_SOURCES
lib/std/zig/llvm/bitcode_writer.zig
lib/std/zig/llvm/ir.zig
src/Air.zig
src/Air/Legalize.zig
src/Air/Liveness.zig
src/Air/Liveness/Verify.zig
src/Air/print.zig
src/Air/types_resolved.zig
src/Builtin.zig
src/Compilation.zig
src/Compilation/Config.zig
src/DarwinPosixSpawn.zig
src/InternPool.zig
src/Liveness.zig
src/Liveness/Verify.zig
src/Package.zig
src/Package/Fetch.zig
src/Package/Fetch/git.zig
@ -522,69 +529,34 @@ set(ZIG_STAGE2_SOURCES
src/Sema.zig
src/Sema/bitcast.zig
src/Sema/comptime_ptr_access.zig
src/ThreadSafeQueue.zig
src/Type.zig
src/Value.zig
src/Zcu.zig
src/Zcu/PerThread.zig
src/arch/aarch64/CodeGen.zig
src/arch/aarch64/Emit.zig
src/arch/aarch64/Mir.zig
src/arch/aarch64/abi.zig
src/arch/aarch64/bits.zig
src/arch/arm/CodeGen.zig
src/arch/arm/Emit.zig
src/arch/arm/Mir.zig
src/arch/arm/abi.zig
src/arch/arm/bits.zig
src/arch/riscv64/abi.zig
src/arch/riscv64/bits.zig
src/arch/riscv64/CodeGen.zig
src/arch/riscv64/Emit.zig
src/arch/riscv64/encoding.zig
src/arch/riscv64/Lower.zig
src/arch/riscv64/Mir.zig
src/arch/riscv64/mnem.zig
src/arch/sparc64/CodeGen.zig
src/arch/sparc64/Emit.zig
src/arch/sparc64/Mir.zig
src/arch/sparc64/abi.zig
src/arch/sparc64/bits.zig
src/arch/wasm/CodeGen.zig
src/arch/wasm/Emit.zig
src/arch/wasm/Mir.zig
src/arch/wasm/abi.zig
src/arch/x86/bits.zig
src/arch/x86_64/CodeGen.zig
src/arch/x86_64/Disassembler.zig
src/arch/x86_64/Emit.zig
src/arch/x86_64/Encoding.zig
src/arch/x86_64/Lower.zig
src/arch/x86_64/Mir.zig
src/arch/x86_64/abi.zig
src/arch/x86_64/bits.zig
src/arch/x86_64/encoder.zig
src/arch/x86_64/encodings.zon
src/clang.zig
src/clang_options.zig
src/clang_options_data.zig
src/codegen.zig
src/codegen/aarch64.zig
src/codegen/aarch64/abi.zig
src/codegen/aarch64/Assemble.zig
src/codegen/aarch64/Disassemble.zig
src/codegen/aarch64/encoding.zig
src/codegen/aarch64/instructions.zon
src/codegen/aarch64/Mir.zig
src/codegen/aarch64/Select.zig
src/codegen/c.zig
src/codegen/c/Type.zig
src/codegen/llvm.zig
src/codegen/llvm/bindings.zig
src/codegen/spirv.zig
src/codegen/spirv/Assembler.zig
src/codegen/spirv/Module.zig
src/codegen/spirv/Section.zig
src/codegen/spirv/spec.zig
src/crash_report.zig
src/dev.zig
src/glibc.zig
src/libs/freebsd.zig
src/libs/glibc.zig
src/libs/netbsd.zig
src/introspect.zig
src/libcxx.zig
src/libtsan.zig
src/libunwind.zig
src/libs/libcxx.zig
src/libs/libtsan.zig
src/libs/libunwind.zig
src/link.zig
src/link/C.zig
src/link/Coff.zig
@ -606,7 +578,9 @@ set(ZIG_STAGE2_SOURCES
src/link/Elf/relocatable.zig
src/link/Elf/relocation.zig
src/link/Elf/synthetic_sections.zig
src/link/Elf2.zig
src/link/LdScript.zig
src/link/Lld.zig
src/link/MachO.zig
src/link/MachO/Archive.zig
src/link/MachO/Atom.zig
@ -633,14 +607,8 @@ set(ZIG_STAGE2_SOURCES
src/link/MachO/synthetic.zig
src/link/MachO/Thunk.zig
src/link/MachO/uuid.zig
src/link/NvPtx.zig
src/link/Plan9.zig
src/link/Plan9/aout.zig
src/link/SpirV.zig
src/link/SpirV/BinaryModule.zig
src/link/SpirV/deduplicate.zig
src/link/SpirV/lower_invocation_globals.zig
src/link/SpirV/prune_unused.zig
src/link/MappedFile.zig
src/link/Queue.zig
src/link/StringTable.zig
src/link/Wasm.zig
src/link/Wasm/Archive.zig
@ -656,10 +624,9 @@ set(ZIG_STAGE2_SOURCES
src/link/tapi/yaml.zig
src/link/tapi/yaml/test.zig
src/main.zig
src/mingw.zig
src/musl.zig
src/libs/mingw.zig
src/libs/musl.zig
src/mutable_value.zig
src/print_air.zig
src/print_env.zig
src/print_targets.zig
src/print_value.zig
@ -667,8 +634,7 @@ set(ZIG_STAGE2_SOURCES
src/register_manager.zig
src/target.zig
src/tracy.zig
src/translate_c.zig
src/wasi_libc.zig
src/libs/wasi_libc.zig
)
if(MSVC)
@ -677,6 +643,12 @@ if(MSVC)
set(ZIG_DIA_GUIDS_LIB "${MSVC_DIA_SDK_DIR}/lib/amd64/diaguids.lib")
string(REGEX REPLACE "\\\\" "\\\\\\\\" ZIG_DIA_GUIDS_LIB_ESCAPED "${ZIG_DIA_GUIDS_LIB}")
endif()
# The /RTC[c][s][u] flag enables extra runtime checks. ("/RTC1" == "/RTCsu")
# The "c" (PossibleDataLoss) and "u" (UninitializeVariable) flags trap on valid C code so we disable
# them. The "s" flag seems like it might be OK.
string(REPLACE "/RTC1" "/RTCs" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
string(REPLACE "/RTC1" "/RTCs" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
endif()
configure_file (
@ -699,6 +671,13 @@ add_library(zigcpp STATIC ${ZIG_CPP_SOURCES})
target_compile_features(zigcpp PRIVATE cxx_std_17)
set_target_properties(zigcpp PROPERTIES POSITION_INDEPENDENT_CODE ${ZIG_PIE})
if(LLVM_LINK_MODE STREQUAL "static")
target_compile_definitions(zigcpp PRIVATE
LLVM_BUILD_STATIC
CLANG_BUILD_STATIC
)
endif()
if(NOT MSVC)
if(MINGW)
target_compile_options(zigcpp PRIVATE -Wno-format)
@ -752,20 +731,22 @@ endforeach()
include(CheckSymbolExists)
string(TOLOWER "${CMAKE_HOST_SYSTEM_NAME}" ZIG_HOST_TARGET_OS)
if(ZIG_HOST_TARGET_OS STREQUAL "darwin")
if(ZIG_HOST_TARGET_OS STREQUAL "android")
set(ZIG_HOST_TARGET_OS "linux")
set(ZIG_HOST_TARGET_IS_ANDROID TRUE)
elseif(ZIG_HOST_TARGET_OS STREQUAL "darwin")
set(ZIG_HOST_TARGET_OS "macos")
elseif(ZIG_HOST_TARGET_OS STREQUAL "gnu")
set(ZIG_HOST_TARGET_OS "hurd")
elseif(ZIG_HOST_TARGET_OS STREQUAL "serenityos")
set(ZIG_HOST_TARGET_OS "serenity")
elseif(ZIG_HOST_TARGET_OS STREQUAL "sunos")
check_symbol_exists(__illumos__ "" ZIG_HOST_TARGET_HAS_ILLUMOS_MACRO)
if (ZIG_HOST_TARGET_HAS_ILLUMOS_MACRO)
set(ZIG_HOST_TARGET_OS "illumos")
else()
set(ZIG_HOST_TARGET_OS "solaris")
endif()
set(ZIG_HOST_TARGET_OS "illumos")
endif()
string(TOLOWER "${CMAKE_HOST_SYSTEM_PROCESSOR}" ZIG_HOST_TARGET_ARCH)
if(ZIG_HOST_TARGET_ARCH MATCHES "^i[3-9]86$")
if (ZIG_HOST_TARGET_OS MATCHES "(solaris|illumos)")
if (ZIG_HOST_TARGET_OS STREQUAL "illumos")
set(ZIG_HOST_TARGET_ARCH "x86_64")
else()
set(ZIG_HOST_TARGET_ARCH "x86")
@ -774,13 +755,12 @@ elseif(ZIG_HOST_TARGET_ARCH STREQUAL "amd64")
set(ZIG_HOST_TARGET_ARCH "x86_64")
elseif(ZIG_HOST_TARGET_ARCH STREQUAL "arm64")
set(ZIG_HOST_TARGET_ARCH "aarch64")
elseif(ZIG_HOST_TARGET_ARCH STREQUAL "armv7l")
elseif(ZIG_HOST_TARGET_ARCH MATCHES "^arm(el)?$" OR ZIG_HOST_TARGET_ARCH MATCHES "^armv[7-8]l$")
set(ZIG_HOST_TARGET_ARCH "arm")
elseif(ZIG_HOST_TARGET_ARCH STREQUAL "armv7b")
elseif(ZIG_HOST_TARGET_ARCH STREQUAL "armeb" OR ZIG_HOST_TARGET_ARCH MATCHES "^armv[7-8]b$")
set(ZIG_HOST_TARGET_ARCH "armeb")
endif()
string(REGEX REPLACE "^((arm|thumb)(hf?)?)el$" "\\1" ZIG_HOST_TARGET_ARCH "${ZIG_HOST_TARGET_ARCH}")
if(ZIG_HOST_TARGET_ARCH MATCHES "^arm(hf?)?(eb)?$")
if(ZIG_HOST_TARGET_ARCH MATCHES "^arm(eb)?$")
check_symbol_exists(__thumb__ "" ZIG_HOST_TARGET_DEFAULTS_TO_THUMB)
if(ZIG_HOST_TARGET_DEFAULTS_TO_THUMB)
string(REGEX REPLACE "^arm" "thumb" ZIG_HOST_TARGET_ARCH "${ZIG_HOST_TARGET_ARCH}")
@ -788,15 +768,17 @@ if(ZIG_HOST_TARGET_ARCH MATCHES "^arm(hf?)?(eb)?$")
endif()
string(REGEX REPLACE "^ppc((64)?(le)?)$" "powerpc\\1" ZIG_HOST_TARGET_ARCH "${ZIG_HOST_TARGET_ARCH}")
set(ZIG_HOST_TARGET_ABI "")
if(MSVC)
set(ZIG_HOST_TARGET_ABI "-msvc")
elseif(MINGW)
set(ZIG_HOST_TARGET_ABI "-gnu")
elseif(ZIG_HOST_TARGET_ARCH MATCHES "^(arm|thumb)hf?(eb)?$")
string(REGEX REPLACE "^(arm|thumb)hf?((eb)?)$" "\\1\\2" ZIG_HOST_TARGET_ARCH "${ZIG_HOST_TARGET_ARCH}")
set(ZIG_HOST_TARGET_ABI "-eabihf")
else()
set(ZIG_HOST_TARGET_ABI "")
elseif(ZIG_HOST_TARGET_IS_ANDROID)
if(ZIG_HOST_TARGET_ARCH STREQUAL "arm")
set(ZIG_HOST_TARGET_ABI "-androideabi")
else()
set(ZIG_HOST_TARGET_ABI "-android")
endif()
endif()
set(ZIG_HOST_TARGET_TRIPLE "${ZIG_HOST_TARGET_ARCH}-${ZIG_HOST_TARGET_OS}${ZIG_HOST_TARGET_ABI}" CACHE STRING "Host zig target triple.")
@ -809,7 +791,7 @@ if(MSVC)
else()
set(ZIG_WASM2C_COMPILE_FLAGS "-std=c99 -O2")
set(ZIG1_COMPILE_FLAGS "-std=c99 -Os")
set(ZIG2_COMPILE_FLAGS "-std=c99 -O0 -fno-stack-protector")
set(ZIG2_COMPILE_FLAGS "-std=c99 -O0 -fno-sanitize=undefined -fno-stack-protector")
if(APPLE)
set(ZIG2_LINK_FLAGS "-Wl,-stack_size,0x10000000")
elseif(MINGW)
@ -938,12 +920,24 @@ if(ZIG_EXTRA_BUILD_ARGS)
list(APPEND ZIG_BUILD_ARGS ${ZIG_EXTRA_BUILD_ARGS})
endif()
set(ZIG_RELEASE_SAFE OFF CACHE BOOL "Build Zig as ReleaseSafe (with debug assertions on)")
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
list(APPEND ZIG_BUILD_ARGS -Doptimize=Debug)
elseif("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
list(APPEND ZIG_BUILD_ARGS -Doptimize=ReleaseFast)
else()
list(APPEND ZIG_BUILD_ARGS -Doptimize=ReleaseFast -Dstrip)
if("${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel")
list(APPEND ZIG_BUILD_ARGS -Doptimize=ReleaseSmall)
else()
# Release and RelWithDebInfo
if(ZIG_RELEASE_SAFE)
list(APPEND ZIG_BUILD_ARGS -Doptimize=ReleaseSafe)
else()
list(APPEND ZIG_BUILD_ARGS -Doptimize=ReleaseFast)
endif()
if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
list(APPEND ZIG_BUILD_ARGS -Dstrip)
endif()
endif()
endif()
if(ZIG_STATIC AND NOT MSVC)
@ -966,10 +960,6 @@ if(NOT "${ZIG_TARGET_DYNAMIC_LINKER}" STREQUAL "")
list(APPEND ZIG_BUILD_ARGS "-Ddynamic-linker=${ZIG_TARGET_DYNAMIC_LINKER}")
endif()
if(MINGW AND "${ZIG_HOST_TARGET_ARCH}" STREQUAL "x86")
list(APPEND ZIG_BUILD_ARGS --maxrss 7000000000)
endif()
add_custom_target(stage3 ALL
DEPENDS "${PROJECT_BINARY_DIR}/stage3/bin/zig"

148
README.md
View File

@ -1,147 +1,3 @@
![ZIG](https://ziglang.org/img/zig-logo-dynamic.svg)
[Moved to Codeberg](https://ziglang.org/news/migrating-from-github-to-codeberg/)
A general-purpose programming language and toolchain for maintaining
**robust**, **optimal**, and **reusable** software.
https://ziglang.org/
## Documentation
If you are looking at this README file in a source tree, please refer to the
**Release Notes**, **Language Reference**, or **Standard Library
Documentation** corresponding to the version of Zig that you are using by
following the appropriate link on the
[download page](https://ziglang.org/download).
Otherwise, you're looking at a release of Zig, so you can find the language
reference at `doc/langref.html`, and the standard library documentation by
running `zig std`, which will open a browser tab.
## Installation
* [download a pre-built binary](https://ziglang.org/download/)
* [install from a package manager](https://github.com/ziglang/zig/wiki/Install-Zig-from-a-Package-Manager)
* [bootstrap zig for any target](https://github.com/ziglang/zig-bootstrap)
A Zig installation is composed of two things:
1. The Zig executable
2. The lib/ directory
At runtime, the executable searches up the file system for the lib/ directory,
relative to itself:
* lib/
* lib/zig/
* ../lib/
* ../lib/zig/
* (and so on)
In other words, you can **unpack a release of Zig anywhere**, and then begin
using it immediately. There is no need to install it globally, although this
mechanism supports that use case too (i.e. `/usr/bin/zig` and `/usr/lib/zig/`).
## Building from Source
Ensure you have the required dependencies:
* CMake >= 3.15
* System C/C++ Toolchain
* LLVM, Clang, LLD development libraries == 19.x
Then it is the standard CMake build process:
```
mkdir build
cd build
cmake ..
make install
```
For more options, tips, and troubleshooting, please see the
[Building Zig From Source](https://github.com/ziglang/zig/wiki/Building-Zig-From-Source)
page on the wiki.
## Building from Source without LLVM
In this case, the only system dependency is a C compiler.
```
cc -o bootstrap bootstrap.c
./bootstrap
```
This produces a `zig2` executable in the current working directory. This is a
"stage2" build of the compiler,
[without LLVM extensions](https://github.com/ziglang/zig/issues/16270), and is
therefore lacking these features:
- Release mode optimizations
- [aarch64 machine code backend](https://github.com/ziglang/zig/issues/21172)
- [@cImport](https://github.com/ziglang/zig/issues/20630)
- [zig translate-c](https://github.com/ziglang/zig/issues/20875)
- [Ability to compile assembly files](https://github.com/ziglang/zig/issues/21169)
- [Some ELF linking features](https://github.com/ziglang/zig/issues/17749)
- [Most COFF/PE linking features](https://github.com/ziglang/zig/issues/17751)
- [Some WebAssembly linking features](https://github.com/ziglang/zig/issues/17750)
- [Ability to create import libs from def files](https://github.com/ziglang/zig/issues/17807)
- [Ability to create static archives from object files](https://github.com/ziglang/zig/issues/9828)
- Ability to compile C, C++, Objective-C, and Objective-C++ files
However, a compiler built this way does provide a C backend, which may be
useful for creating system packages of Zig projects using the system C
toolchain. **In this case, LLVM is not needed!**
Furthermore, a compiler built this way provides an LLVM backend that produces
bitcode files, which may be compiled into object files via a system Clang
package. This can be used to produce system packages of Zig applications
without the Zig package dependency on LLVM.
## Contributing
[Donate monthly](https://ziglang.org/zsf/).
Zig is Free and Open Source Software. We welcome bug reports and patches from
everyone. However, keep in mind that Zig governance is BDFN (Benevolent
Dictator For Now) which means that Andrew Kelley has final say on the design
and implementation of everything.
One of the best ways you can contribute to Zig is to start using it for an
open-source personal project.
This leads to discovering bugs and helps flesh out use cases, which lead to
further design iterations of Zig. Importantly, each issue found this way comes
with real world motivations, making it straightforward to explain the reasoning
behind proposals and feature requests.
You will be taken much more seriously on the issue tracker if you have a
personal project that uses Zig.
The issue label
[Contributor Friendly](https://github.com/ziglang/zig/issues?q=is%3Aissue+is%3Aopen+label%3A%22contributor+friendly%22)
exists to help you find issues that are **limited in scope and/or knowledge of
Zig internals.**
Please note that issues labeled
[Proposal](https://github.com/ziglang/zig/issues?q=is%3Aissue+is%3Aopen+label%3Aproposal)
but do not also have the
[Accepted](https://github.com/ziglang/zig/issues?q=is%3Aissue+is%3Aopen+label%3Aaccepted)
label are still under consideration, and efforts to implement such a proposal
have a high risk of being wasted. If you are interested in a proposal which is
still under consideration, please express your interest in the issue tracker,
providing extra insights and considerations that others have not yet expressed.
The most highly regarded argument in such a discussion is a real world use case.
For more tips, please see the
[Contributing](https://github.com/ziglang/zig/wiki/Contributing) page on the
wiki.
## Community
The Zig community is decentralized. Anyone is free to start and maintain their
own space for Zig users to gather. There is no concept of "official" or
"unofficial". Each gathering place has its own moderators and rules. Users are
encouraged to be aware of the social structures of the spaces they inhabit, and
work purposefully to facilitate spaces that align with their values.
Please see the [Community](https://github.com/ziglang/zig/wiki/Community) wiki
page for a public listing of social spaces.
**This repository is not mirrored.**

View File

@ -64,6 +64,8 @@ static const char *get_host_os(void) {
return "linux";
#elif defined(__FreeBSD__)
return "freebsd";
#elif defined(__DragonFly__)
return "dragonfly";
#elif defined(__HAIKU__)
return "haiku";
#else

331
build.zig
View File

@ -3,7 +3,6 @@ const builtin = std.builtin;
const tests = @import("test/tests.zig");
const BufMap = std.BufMap;
const mem = std.mem;
const ArrayList = std.ArrayList;
const io = std.io;
const fs = std.fs;
const InstallDirectoryOptions = std.Build.InstallDirectoryOptions;
@ -11,7 +10,7 @@ const assert = std.debug.assert;
const DevEnv = @import("src/dev.zig").Env;
const ValueInterpretMode = enum { direct, by_name };
const zig_version: std.SemanticVersion = .{ .major = 0, .minor = 14, .patch = 0 };
const zig_version: std.SemanticVersion = .{ .major = 0, .minor = 16, .patch = 0 };
const stack_size = 46 * 1024 * 1024;
pub fn build(b: *std.Build) !void {
@ -82,16 +81,23 @@ pub fn build(b: *std.Build) !void {
docs_step.dependOn(langref_step);
docs_step.dependOn(std_docs_step);
const no_matrix = b.option(bool, "no-matrix", "Limit test matrix to exactly one target configuration") orelse false;
const skip_debug = b.option(bool, "skip-debug", "Main test suite skips debug builds") orelse false;
const skip_release = b.option(bool, "skip-release", "Main test suite skips release builds") orelse false;
const skip_release = b.option(bool, "skip-release", "Main test suite skips release builds") orelse no_matrix;
const skip_release_small = b.option(bool, "skip-release-small", "Main test suite skips release-small builds") orelse skip_release;
const skip_release_fast = b.option(bool, "skip-release-fast", "Main test suite skips release-fast builds") orelse skip_release;
const skip_release_safe = b.option(bool, "skip-release-safe", "Main test suite skips release-safe builds") orelse skip_release;
const skip_non_native = b.option(bool, "skip-non-native", "Main test suite skips non-native builds") orelse false;
const skip_non_native = b.option(bool, "skip-non-native", "Main test suite skips non-native builds") orelse no_matrix;
const skip_libc = b.option(bool, "skip-libc", "Main test suite skips tests that link libc") orelse false;
const skip_single_threaded = b.option(bool, "skip-single-threaded", "Main test suite skips tests that are single-threaded") orelse false;
const skip_translate_c = b.option(bool, "skip-translate-c", "Main test suite skips translate-c tests") orelse false;
const skip_run_translated_c = b.option(bool, "skip-run-translated-c", "Main test suite skips run-translated-c tests") orelse false;
const skip_compile_errors = b.option(bool, "skip-compile-errors", "Main test suite skips compile error tests") orelse false;
const skip_freebsd = b.option(bool, "skip-freebsd", "Main test suite skips targets with freebsd OS") orelse false;
const skip_netbsd = b.option(bool, "skip-netbsd", "Main test suite skips targets with netbsd OS") orelse false;
const skip_windows = b.option(bool, "skip-windows", "Main test suite skips targets with windows OS") orelse false;
const skip_darwin = b.option(bool, "skip-darwin", "Main test suite skips targets with darwin OSs") orelse false;
const skip_linux = b.option(bool, "skip-linux", "Main test suite skips targets with linux OS") orelse false;
const skip_llvm = b.option(bool, "skip-llvm", "Main test suite skips targets that use LLVM backend") orelse false;
const skip_test_incremental = b.option(bool, "skip-test-incremental", "Main test step omits dependency on test-incremental step") orelse false;
const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false;
@ -196,12 +202,11 @@ pub fn build(b: *std.Build) !void {
});
exe.pie = pie;
exe.entitlements = entitlements;
exe.use_new_linker = b.option(bool, "new-linker", "Use the new linker");
exe.build_id = b.option(
std.zig.BuildId,
"build-id",
"Request creation of '.note.gnu.build-id' section",
);
const use_llvm = b.option(bool, "use-llvm", "Use the llvm backend");
exe.use_llvm = use_llvm;
exe.use_lld = use_llvm;
if (no_bin) {
b.getInstallStep().dependOn(&exe.step);
@ -214,15 +219,6 @@ pub fn build(b: *std.Build) !void {
test_step.dependOn(&exe.step);
if (target.result.os.tag == .windows and target.result.abi == .gnu) {
// LTO is currently broken on mingw, this can be removed when it's fixed.
exe.want_lto = false;
}
const use_llvm = b.option(bool, "use-llvm", "Use the llvm backend");
exe.use_llvm = use_llvm;
exe.use_lld = use_llvm;
const exe_options = b.addOptions();
exe.root_module.addOptions("build_options", exe_options);
@ -257,19 +253,16 @@ pub fn build(b: *std.Build) !void {
var code: u8 = undefined;
const git_describe_untrimmed = b.runAllowFail(&[_][]const u8{
"git",
"-C",
b.build_root.path orelse ".",
"describe",
"--match",
"*.*.*",
"--tags",
"--abbrev=9",
"-C", b.build_root.path orelse ".", // affects the --git-dir argument
"--git-dir", ".git", // affected by the -C argument
"describe", "--match", "*.*.*", //
"--tags", "--abbrev=9",
}, &code, .Ignore) catch {
break :v version_string;
};
const git_describe = mem.trim(u8, git_describe_untrimmed, " \n\r");
switch (mem.count(u8, git_describe, "-")) {
switch (mem.countScalar(u8, git_describe, '-')) {
0 => {
// Tagged release version (e.g. 0.10.0).
if (!mem.eql(u8, git_describe, version_string)) {
@ -287,7 +280,7 @@ pub fn build(b: *std.Build) !void {
const ancestor_ver = try std.SemanticVersion.parse(tagged_ancestor);
if (zig_version.order(ancestor_ver) != .gt) {
std.debug.print("Zig version '{}' must be greater than tagged ancestor '{}'\n", .{ zig_version, ancestor_ver });
std.debug.print("Zig version '{f}' must be greater than tagged ancestor '{f}'\n", .{ zig_version, ancestor_ver });
std.process.exit(1);
}
@ -312,7 +305,7 @@ pub fn build(b: *std.Build) !void {
if (enable_llvm) {
const cmake_cfg = if (static_llvm) null else blk: {
if (findConfigH(b, config_h_path_option)) |config_h_path| {
const file_contents = fs.cwd().readFileAlloc(b.allocator, config_h_path, max_config_h_bytes) catch unreachable;
const file_contents = fs.cwd().readFileAlloc(config_h_path, b.allocator, .limited(max_config_h_bytes)) catch unreachable;
break :blk parseConfigH(b, file_contents);
} else {
std.log.warn("config.h could not be located automatically. Consider providing it explicitly via \"-Dconfig_h\"", .{});
@ -334,7 +327,12 @@ pub fn build(b: *std.Build) !void {
try addCmakeCfgOptionsToExe(b, cfg, exe, use_zig_libcxx);
} else {
// Here we are -Denable-llvm but no cmake integration.
try addStaticLlvmOptionsToModule(exe.root_module);
try addStaticLlvmOptionsToModule(exe.root_module, .{
.llvm_has_m68k = llvm_has_m68k,
.llvm_has_csky = llvm_has_csky,
.llvm_has_arc = llvm_has_arc,
.llvm_has_xtensa = llvm_has_xtensa,
});
}
if (target.result.os.tag == .windows) {
// LLVM depends on networking as of version 18.
@ -362,11 +360,7 @@ pub fn build(b: *std.Build) !void {
&[_][]const u8{ tracy_path, "public", "TracyClient.cpp" },
);
// On mingw, we need to opt into windows 7+ to get some features required by tracy.
const tracy_c_flags: []const []const u8 = if (target.result.os.tag == .windows and target.result.abi == .gnu)
&[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined", "-D_WIN32_WINNT=0x601" }
else
&[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" };
const tracy_c_flags: []const []const u8 = &.{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" };
exe.root_module.addIncludePath(.{ .cwd_relative = tracy_path });
exe.root_module.addCSourceFile(.{ .file = .{ .cwd_relative = client_cpp }, .flags = tracy_c_flags });
@ -383,7 +377,7 @@ pub fn build(b: *std.Build) !void {
const test_filters = b.option([]const []const u8, "test-filter", "Skip tests that do not match any filter") orelse &[0][]const u8{};
const test_target_filters = b.option([]const []const u8, "test-target-filter", "Skip tests whose target triple do not match any filter") orelse &[0][]const u8{};
const test_slow_targets = b.option(bool, "test-slow-targets", "Enable running module tests for targets that have a slow compiler backend") orelse false;
const test_extra_targets = b.option(bool, "test-extra-targets", "Enable running module tests for additional targets") orelse false;
var chosen_opt_modes_buf: [4]builtin.OptimizeMode = undefined;
var chosen_mode_index: usize = 0;
@ -422,9 +416,18 @@ pub fn build(b: *std.Build) !void {
test_step.dependOn(check_fmt);
const test_cases_step = b.step("test-cases", "Run the main compiler test cases");
try tests.addCases(b, test_cases_step, test_filters, test_target_filters, target, .{
.skip_translate_c = skip_translate_c,
.skip_run_translated_c = skip_run_translated_c,
try tests.addCases(b, test_cases_step, .{
.test_filters = test_filters,
.test_target_filters = test_target_filters,
.skip_compile_errors = skip_compile_errors,
.skip_non_native = skip_non_native,
.skip_freebsd = skip_freebsd,
.skip_netbsd = skip_netbsd,
.skip_windows = skip_windows,
.skip_darwin = skip_darwin,
.skip_linux = skip_linux,
.skip_llvm = skip_llvm,
.skip_libc = skip_libc,
}, .{
.enable_llvm = enable_llvm,
.llvm_has_m68k = llvm_has_m68k,
@ -440,7 +443,7 @@ pub fn build(b: *std.Build) !void {
test_modules_step.dependOn(tests.addModuleTests(b, .{
.test_filters = test_filters,
.test_target_filters = test_target_filters,
.test_slow_targets = test_slow_targets,
.test_extra_targets = test_extra_targets,
.root_src = "test/behavior.zig",
.name = "behavior",
.desc = "Run the behavior tests",
@ -448,30 +451,22 @@ pub fn build(b: *std.Build) !void {
.include_paths = &.{},
.skip_single_threaded = skip_single_threaded,
.skip_non_native = skip_non_native,
.test_default_only = no_matrix,
.skip_freebsd = skip_freebsd,
.skip_netbsd = skip_netbsd,
.skip_windows = skip_windows,
.skip_darwin = skip_darwin,
.skip_linux = skip_linux,
.skip_llvm = skip_llvm,
.skip_libc = skip_libc,
.use_llvm = use_llvm,
.max_rss = 2 * 1024 * 1024 * 1024,
// 3888779264 was observed on an x86_64-linux-gnu host.
.max_rss = 4000000000,
}));
test_modules_step.dependOn(tests.addModuleTests(b, .{
.test_filters = test_filters,
.test_target_filters = test_target_filters,
.test_slow_targets = test_slow_targets,
.root_src = "test/c_import.zig",
.name = "c-import",
.desc = "Run the @cImport tests",
.optimize_modes = optimization_modes,
.include_paths = &.{"test/c_import"},
.skip_single_threaded = true,
.skip_non_native = skip_non_native,
.skip_libc = skip_libc,
.use_llvm = use_llvm,
}));
test_modules_step.dependOn(tests.addModuleTests(b, .{
.test_filters = test_filters,
.test_target_filters = test_target_filters,
.test_slow_targets = test_slow_targets,
.test_extra_targets = test_extra_targets,
.root_src = "lib/compiler_rt.zig",
.name = "compiler-rt",
.desc = "Run the compiler_rt tests",
@ -479,31 +474,43 @@ pub fn build(b: *std.Build) !void {
.include_paths = &.{},
.skip_single_threaded = true,
.skip_non_native = skip_non_native,
.test_default_only = no_matrix,
.skip_freebsd = skip_freebsd,
.skip_netbsd = skip_netbsd,
.skip_windows = skip_windows,
.skip_darwin = skip_darwin,
.skip_linux = skip_linux,
.skip_llvm = skip_llvm,
.skip_libc = true,
.use_llvm = use_llvm,
.no_builtin = true,
}));
test_modules_step.dependOn(tests.addModuleTests(b, .{
.test_filters = test_filters,
.test_target_filters = test_target_filters,
.test_slow_targets = test_slow_targets,
.test_extra_targets = test_extra_targets,
.root_src = "lib/c.zig",
.name = "universal-libc",
.desc = "Run the universal libc tests",
.name = "zigc",
.desc = "Run the zigc tests",
.optimize_modes = optimization_modes,
.include_paths = &.{},
.skip_single_threaded = true,
.skip_non_native = skip_non_native,
.test_default_only = no_matrix,
.skip_freebsd = skip_freebsd,
.skip_netbsd = skip_netbsd,
.skip_windows = skip_windows,
.skip_darwin = skip_darwin,
.skip_linux = skip_linux,
.skip_llvm = skip_llvm,
.skip_libc = true,
.use_llvm = use_llvm,
.no_builtin = true,
}));
test_modules_step.dependOn(tests.addModuleTests(b, .{
.test_filters = test_filters,
.test_target_filters = test_target_filters,
.test_slow_targets = test_slow_targets,
.test_extra_targets = test_extra_targets,
.root_src = "lib/std/std.zig",
.name = "std",
.desc = "Run the standard library tests",
@ -511,21 +518,25 @@ pub fn build(b: *std.Build) !void {
.include_paths = &.{},
.skip_single_threaded = skip_single_threaded,
.skip_non_native = skip_non_native,
.test_default_only = no_matrix,
.skip_freebsd = skip_freebsd,
.skip_netbsd = skip_netbsd,
.skip_windows = skip_windows,
.skip_darwin = skip_darwin,
.skip_linux = skip_linux,
.skip_llvm = skip_llvm,
.skip_libc = skip_libc,
.use_llvm = use_llvm,
// I observed a value of 5136793600 on the M2 CI.
.max_rss = 5368709120,
// I observed a value of 5605064704 on the M2 CI.
.max_rss = 6165571174,
}));
const unit_tests_step = b.step("test-unit", "Run the compiler source unit tests");
test_step.dependOn(unit_tests_step);
const unit_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.root_module = addCompilerMod(b, .{
.optimize = optimize,
.target = target,
.link_libc = link_libc,
.single_threaded = single_threaded,
}),
.filters = test_filters,
@ -533,10 +544,12 @@ pub fn build(b: *std.Build) !void {
.use_lld = use_llvm,
.zig_lib_dir = b.path("lib"),
});
if (link_libc) {
unit_tests.root_module.link_libc = true;
}
unit_tests.root_module.addOptions("build_options", exe_options);
unit_tests_step.dependOn(&b.addRunArtifact(unit_tests).step);
test_step.dependOn(tests.addCompareOutputTests(b, test_filters, optimization_modes));
test_step.dependOn(tests.addStandaloneTests(
b,
optimization_modes,
@ -547,12 +560,18 @@ pub fn build(b: *std.Build) !void {
test_step.dependOn(tests.addCAbiTests(b, .{
.test_target_filters = test_target_filters,
.skip_non_native = skip_non_native,
.skip_freebsd = skip_freebsd,
.skip_netbsd = skip_netbsd,
.skip_windows = skip_windows,
.skip_darwin = skip_darwin,
.skip_linux = skip_linux,
.skip_llvm = skip_llvm,
.skip_release = skip_release,
}));
test_step.dependOn(tests.addLinkTests(b, enable_macos_sdk, enable_ios_sdk, enable_symlinks_windows));
test_step.dependOn(tests.addStackTraceTests(b, test_filters, optimization_modes));
test_step.dependOn(tests.addStackTraceTests(b, test_filters, skip_non_native));
test_step.dependOn(tests.addErrorTraceTests(b, test_filters, optimization_modes, skip_non_native));
test_step.dependOn(tests.addCliTests(b));
test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filters, optimization_modes));
if (tests.addDebuggerTests(b, .{
.test_filters = test_filters,
.test_target_filters = test_target_filters,
@ -560,9 +579,13 @@ pub fn build(b: *std.Build) !void {
.lldb = b.option([]const u8, "lldb", "path to lldb binary"),
.optimize_modes = optimization_modes,
.skip_single_threaded = skip_single_threaded,
.skip_non_native = skip_non_native,
.skip_libc = skip_libc,
})) |test_debugger_step| test_step.dependOn(test_debugger_step);
if (tests.addLlvmIrTests(b, .{
.enable_llvm = enable_llvm,
.test_filters = test_filters,
.test_target_filters = test_target_filters,
})) |test_llvm_ir_step| test_step.dependOn(test_llvm_ir_step);
try addWasiUpdateStep(b, version);
@ -587,7 +610,15 @@ pub fn build(b: *std.Build) !void {
const test_incremental_step = b.step("test-incremental", "Run the incremental compilation test cases");
try tests.addIncrementalTests(b, test_incremental_step);
test_step.dependOn(test_incremental_step);
if (!skip_test_incremental) test_step.dependOn(test_incremental_step);
if (tests.addLibcTests(b, .{
.optimize_modes = optimization_modes,
.test_filters = test_filters,
.test_target_filters = test_target_filters,
// Highest RSS observed in any test case was exactly 1802878976 on x86_64-linux.
.max_rss = 2253598720,
})) |test_libc_step| test_step.dependOn(test_libc_step);
}
fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
@ -648,17 +679,17 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
});
run_opt.addArtifactArg(exe);
run_opt.addArg("-o");
run_opt.addFileArg(b.path("stage1/zig1.wasm"));
const optimized_wasm = run_opt.addOutputFileArg("zig1.wasm");
const copy_zig_h = b.addUpdateSourceFiles();
copy_zig_h.addCopyFileToSource(b.path("lib/zig.h"), "stage1/zig.h");
const update_zig1 = b.addUpdateSourceFiles();
update_zig1.addCopyFileToSource(optimized_wasm, "stage1/zig1.wasm");
update_zig1.addCopyFileToSource(b.path("lib/zig.h"), "stage1/zig.h");
const update_zig1_step = b.step("update-zig1", "Update stage1/zig1.wasm");
update_zig1_step.dependOn(&run_opt.step);
update_zig1_step.dependOn(&copy_zig_h.step);
update_zig1_step.dependOn(&update_zig1.step);
}
const AddCompilerStepOptions = struct {
const AddCompilerModOptions = struct {
optimize: std.builtin.OptimizeMode,
target: std.Build.ResolvedTarget,
strip: ?bool = null,
@ -667,7 +698,7 @@ const AddCompilerStepOptions = struct {
single_threaded: ?bool = null,
};
fn addCompilerStep(b: *std.Build, options: AddCompilerStepOptions) *std.Build.Step.Compile {
fn addCompilerMod(b: *std.Build, options: AddCompilerModOptions) *std.Build.Module {
const compiler_mod = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = options.target,
@ -675,24 +706,6 @@ fn addCompilerStep(b: *std.Build, options: AddCompilerStepOptions) *std.Build.St
.strip = options.strip,
.sanitize_thread = options.sanitize_thread,
.single_threaded = options.single_threaded,
.code_model = switch (options.target.result.cpu.arch) {
// NB:
// For loongarch, LLVM supports only small, medium and large
// code model. If we don't explicitly specify the code model,
// the default value `small' will be used.
//
// Since zig binary itself is relatively large, using a `small'
// code model will cause
//
// relocation R_LARCH_B26 out of range
//
// error when linking a loongarch32/loongarch64 zig binary.
//
// Here we explicitly set code model to `medium' to avoid this
// error.
.loongarch32, .loongarch64 => .medium,
else => .default,
},
.valgrind = options.valgrind,
});
@ -700,18 +713,16 @@ fn addCompilerStep(b: *std.Build, options: AddCompilerStepOptions) *std.Build.St
.root_source_file = b.path("lib/compiler/aro/aro.zig"),
});
const aro_translate_c_mod = b.createModule(.{
.root_source_file = b.path("lib/compiler/aro_translate_c.zig"),
});
aro_translate_c_mod.addImport("aro", aro_mod);
compiler_mod.addImport("aro", aro_mod);
compiler_mod.addImport("aro_translate_c", aro_translate_c_mod);
return compiler_mod;
}
fn addCompilerStep(b: *std.Build, options: AddCompilerModOptions) *std.Build.Step.Compile {
const exe = b.addExecutable(.{
.name = "zig",
.max_rss = 7_800_000_000,
.root_module = compiler_mod,
.root_module = addCompilerMod(b, options),
});
exe.stack_size = stack_size;
@ -731,6 +742,9 @@ const exe_cflags = [_][]const u8{
"-Wno-type-limits",
"-Wno-missing-braces",
"-Wno-comment",
// `exe_cflags` is only used for static linking.
"-DLLVM_BUILD_STATIC",
"-DCLANG_BUILD_STATIC",
};
fn addCmakeCfgOptionsToExe(
@ -740,7 +754,7 @@ fn addCmakeCfgOptionsToExe(
use_zig_libcxx: bool,
) !void {
const mod = exe.root_module;
const target = mod.resolved_target.?.result;
const target = &mod.resolved_target.?.result;
if (target.os.tag.isDarwin()) {
// useful for package maintainers
@ -805,7 +819,7 @@ fn addCmakeCfgOptionsToExe(
try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes);
if (static) try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes);
},
.solaris, .illumos => {
.illumos => {
try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes);
try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes);
},
@ -821,7 +835,12 @@ fn addCmakeCfgOptionsToExe(
}
}
fn addStaticLlvmOptionsToModule(mod: *std.Build.Module) !void {
fn addStaticLlvmOptionsToModule(mod: *std.Build.Module, options: struct {
llvm_has_m68k: bool,
llvm_has_csky: bool,
llvm_has_arc: bool,
llvm_has_xtensa: bool,
}) !void {
// Adds the Zig C++ sources which both stage1 and stage2 need.
//
// We need this because otherwise zig_clang_cc1_main.cpp ends up pulling
@ -845,6 +864,22 @@ fn addStaticLlvmOptionsToModule(mod: *std.Build.Module) !void {
mod.linkSystemLibrary(lib_name, .{});
}
if (options.llvm_has_m68k) for (llvm_libs_m68k) |lib_name| {
mod.linkSystemLibrary(lib_name, .{});
};
if (options.llvm_has_csky) for (llvm_libs_csky) |lib_name| {
mod.linkSystemLibrary(lib_name, .{});
};
if (options.llvm_has_arc) for (llvm_libs_arc) |lib_name| {
mod.linkSystemLibrary(lib_name, .{});
};
if (options.llvm_has_xtensa) for (llvm_libs_xtensa) |lib_name| {
mod.linkSystemLibrary(lib_name, .{});
};
mod.linkSystemLibrary("z", .{});
mod.linkSystemLibrary("zstd", .{});
@ -872,7 +907,7 @@ fn addCxxKnownPath(
return error.RequiredLibraryNotFound;
const path_padded = run: {
var args = std.ArrayList([]const u8).init(b.allocator);
var args = std.array_list.Managed([]const u8).init(b.allocator);
try args.append(ctx.cxx_compiler);
var it = std.mem.tokenizeAny(u8, ctx.cxx_compiler_arg1, &std.ascii.whitespace);
while (it.next()) |arg| try args.append(arg);
@ -1098,7 +1133,6 @@ fn toNativePathSep(b: *std.Build, s: []const u8) []u8 {
const zig_cpp_sources = [_][]const u8{
// These are planned to stay even when we are self-hosted.
"src/zig_llvm.cpp",
"src/zig_clang.cpp",
"src/zig_llvm-ar.cpp",
"src/zig_clang_driver.cpp",
"src/zig_clang_cc1_main.cpp",
@ -1124,7 +1158,6 @@ const clang_libs = [_][]const u8{
"clangBasic",
"clangEdit",
"clangLex",
"clangARCMigrate",
"clangRewriteFrontend",
"clangRewrite",
"clangCrossTU",
@ -1152,10 +1185,10 @@ const llvm_libs = [_][]const u8{
"LLVMXRay",
"LLVMLibDriver",
"LLVMDlltoolDriver",
"LLVMTelemetry",
"LLVMTextAPIBinaryReader",
"LLVMCoverage",
"LLVMLineEditor",
"LLVMSandboxIR",
"LLVMXCoreDisassembler",
"LLVMXCoreCodeGen",
"LLVMXCoreDesc",
@ -1182,6 +1215,10 @@ const llvm_libs = [_][]const u8{
"LLVMSystemZCodeGen",
"LLVMSystemZDesc",
"LLVMSystemZInfo",
"LLVMSPIRVCodeGen",
"LLVMSPIRVDesc",
"LLVMSPIRVInfo",
"LLVMSPIRVAnalysis",
"LLVMSparcDisassembler",
"LLVMSparcAsmParser",
"LLVMSparcCodeGen",
@ -1266,32 +1303,34 @@ const llvm_libs = [_][]const u8{
"LLVMOrcTargetProcess",
"LLVMOrcShared",
"LLVMDWP",
"LLVMDWARFCFIChecker",
"LLVMDebugInfoLogicalView",
"LLVMDebugInfoGSYM",
"LLVMOption",
"LLVMObjectYAML",
"LLVMObjCopy",
"LLVMMCA",
"LLVMMCDisassembler",
"LLVMLTO",
"LLVMPasses",
"LLVMHipStdPar",
"LLVMCFGuard",
"LLVMCoroutines",
"LLVMipo",
"LLVMVectorize",
"LLVMLinker",
"LLVMInstrumentation",
"LLVMFrontendOpenMP",
"LLVMFrontendOffloading",
"LLVMFrontendOpenACC",
"LLVMFrontendHLSL",
"LLVMFrontendDriver",
"LLVMExtensions",
"LLVMPasses",
"LLVMHipStdPar",
"LLVMCoroutines",
"LLVMCFGuard",
"LLVMipo",
"LLVMInstrumentation",
"LLVMVectorize",
"LLVMSandboxIR",
"LLVMLinker",
"LLVMFrontendOpenMP",
"LLVMFrontendDirective",
"LLVMFrontendAtomic",
"LLVMFrontendOffloading",
"LLVMObjectYAML",
"LLVMDWARFLinkerParallel",
"LLVMDWARFLinkerClassic",
"LLVMDWARFLinker",
"LLVMCodeGenData",
"LLVMGlobalISel",
"LLVMMIRParser",
"LLVMAsmPrinter",
@ -1300,6 +1339,7 @@ const llvm_libs = [_][]const u8{
"LLVMTarget",
"LLVMObjCARCOpts",
"LLVMCodeGenTypes",
"LLVMCGData",
"LLVMIRPrinter",
"LLVMInterfaceStub",
"LLVMFileCheck",
@ -1315,14 +1355,16 @@ const llvm_libs = [_][]const u8{
"LLVMDebugInfoBTF",
"LLVMDebugInfoPDB",
"LLVMDebugInfoMSF",
"LLVMDebugInfoCodeView",
"LLVMDebugInfoGSYM",
"LLVMDebugInfoDWARF",
"LLVMDebugInfoDWARFLowLevel",
"LLVMObject",
"LLVMTextAPI",
"LLVMMCParser",
"LLVMIRReader",
"LLVMAsmParser",
"LLVMMC",
"LLVMDebugInfoCodeView",
"LLVMBitReader",
"LLVMFuzzerCLI",
"LLVMCore",
@ -1333,6 +1375,33 @@ const llvm_libs = [_][]const u8{
"LLVMSupport",
"LLVMDemangle",
};
const llvm_libs_m68k = [_][]const u8{
"LLVMM68kDisassembler",
"LLVMM68kAsmParser",
"LLVMM68kCodeGen",
"LLVMM68kDesc",
"LLVMM68kInfo",
};
const llvm_libs_csky = [_][]const u8{
"LLVMCSKYDisassembler",
"LLVMCSKYAsmParser",
"LLVMCSKYCodeGen",
"LLVMCSKYDesc",
"LLVMCSKYInfo",
};
const llvm_libs_arc = [_][]const u8{
"LLVMARCDisassembler",
"LLVMARCCodeGen",
"LLVMARCDesc",
"LLVMARCInfo",
};
const llvm_libs_xtensa = [_][]const u8{
"LLVMXtensaDisassembler",
"LLVMXtensaAsmParser",
"LLVMXtensaCodeGen",
"LLVMXtensaDesc",
"LLVMXtensaInfo",
};
fn generateLangRef(b: *std.Build) std.Build.LazyPath {
const doctest_exe = b.addExecutable(.{
@ -1345,7 +1414,7 @@ fn generateLangRef(b: *std.Build) std.Build.LazyPath {
});
var dir = b.build_root.handle.openDir("doc/langref", .{ .iterate = true }) catch |err| {
std.debug.panic("unable to open '{}doc/langref' directory: {s}", .{
std.debug.panic("unable to open '{f}doc/langref' directory: {s}", .{
b.build_root, @errorName(err),
});
};
@ -1366,7 +1435,7 @@ fn generateLangRef(b: *std.Build) std.Build.LazyPath {
// in a temporary directory
"--cache-root", b.cache_root.path orelse ".",
});
cmd.addArgs(&.{ "--zig-lib-dir", b.fmt("{}", .{b.graph.zig_lib_directory}) });
cmd.addArgs(&.{ "--zig-lib-dir", b.fmt("{f}", .{b.graph.zig_lib_directory}) });
cmd.addArgs(&.{"-i"});
cmd.addFileArg(b.path(b.fmt("doc/langref/{s}", .{entry.name})));

59
ci/aarch64-linux-debug.sh Normal file → Executable file
View File

@ -5,20 +5,14 @@
set -x
set -e
ARCH="$(uname -m)"
TARGET="$ARCH-linux-musl"
TARGET="aarch64-linux-musl"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.14.0-dev.1622+2ac543388"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
export PATH="$HOME/local/bin:$PATH"
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git fetch --unshallow || true
git fetch --tags
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
@ -48,48 +42,23 @@ unset CXX
ninja install
# simultaneously test building self-hosted without LLVM and with 32-bit arm
stage3-debug/bin/zig build \
-Dtarget=arm-linux-musleabihf \
-Dno-lib
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-debug/bin/zig build test docs \
--maxrss 24696061952 \
--maxrss 44918199637 \
-Dstatic-llvm \
-Dskip-non-native \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
-Denable-superhtml
-Denable-superhtml \
--test-timeout 3m
# Ensure that updating the wasm binary from this commit will result in a viable build.
stage3-debug/bin/zig build update-zig1
mkdir ../build-new
cd ../build-new
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Debug \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja
unset CC
unset CXX
ninja install
stage3/bin/zig test ../test/behavior.zig
stage3/bin/zig build -p stage4 \
-Dstatic-llvm \
-Dtarget=native-native-musl \
stage3-debug/bin/zig build \
--prefix stage4-debug \
-Denable-llvm \
-Dno-lib \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib"
stage4/bin/zig test ../test/behavior.zig
-Dtarget=$TARGET \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-debug/bin/zig version)"
stage4-debug/bin/zig test ../test/behavior.zig

53
ci/aarch64-linux-release.sh Normal file → Executable file
View File

@ -5,20 +5,14 @@
set -x
set -e
ARCH="$(uname -m)"
TARGET="$ARCH-linux-musl"
TARGET="aarch64-linux-musl"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.14.0-dev.1622+2ac543388"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
export PATH="$HOME/local/bin:$PATH"
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git fetch --unshallow || true
git fetch --tags
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
@ -48,19 +42,16 @@ unset CXX
ninja install
# simultaneously test building self-hosted without LLVM and with 32-bit arm
stage3-release/bin/zig build \
-Dtarget=arm-linux-musleabihf \
-Dno-lib
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-release/bin/zig build test docs \
--maxrss 24696061952 \
--maxrss 44918199637 \
-Dstatic-llvm \
-Dskip-non-native \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
-Denable-superhtml
-Denable-superhtml \
--test-timeout 3m
# Ensure that stage3 and stage4 are byte-for-byte identical.
stage3-release/bin/zig build \
@ -77,35 +68,3 @@ stage3-release/bin/zig build \
echo "If the following command fails, it means nondeterminism has been"
echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
diff stage3-release/bin/zig stage4-release/bin/zig
# Ensure that updating the wasm binary from this commit will result in a viable build.
stage3-release/bin/zig build update-zig1
mkdir ../build-new
cd ../build-new
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja
unset CC
unset CXX
ninja install
stage3/bin/zig test ../test/behavior.zig
stage3/bin/zig build -p stage4 \
-Dstatic-llvm \
-Dtarget=native-native-musl \
-Dno-lib \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib"
stage4/bin/zig test ../test/behavior.zig

View File

@ -3,13 +3,10 @@
set -x
set -e
# Script assumes the presence of the following:
# s3cmd
ZIGDIR="$PWD"
TARGET="$ARCH-macos-none"
TARGET="aarch64-macos-none"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.14.0-dev.1622+2ac543388"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
PREFIX="$HOME/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
@ -21,11 +18,6 @@ fi
cd $ZIGDIR
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git fetch --unshallow || true
git fetch --tags
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
@ -35,7 +27,7 @@ export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-debug
cd build-debug
PATH="$HOME/local/bin:$PATH" cmake .. \
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-debug" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Debug \
@ -47,11 +39,12 @@ PATH="$HOME/local/bin:$PATH" cmake .. \
-DZIG_NO_LIB=ON \
-GNinja
$HOME/local/bin/ninja install
ninja install
stage3-debug/bin/zig build test docs \
--zig-lib-dir "$PWD/../lib" \
-Denable-macos-sdk \
-Dstatic-llvm \
-Dskip-non-native \
--search-prefix "$PREFIX"
--search-prefix "$PREFIX" \
--test-timeout 2m

View File

@ -3,13 +3,10 @@
set -x
set -e
# Script assumes the presence of the following:
# s3cmd
ZIGDIR="$PWD"
TARGET="$ARCH-macos-none"
TARGET="aarch64-macos-none"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.14.0-dev.1622+2ac543388"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
PREFIX="$HOME/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
@ -21,11 +18,6 @@ fi
cd $ZIGDIR
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git fetch --unshallow || true
git fetch --tags
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
@ -35,7 +27,7 @@ export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-release
cd build-release
PATH="$HOME/local/bin:$PATH" cmake .. \
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-release" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
@ -47,14 +39,15 @@ PATH="$HOME/local/bin:$PATH" cmake .. \
-DZIG_NO_LIB=ON \
-GNinja
$HOME/local/bin/ninja install
ninja install
stage3-release/bin/zig build test docs \
--zig-lib-dir "$PWD/../lib" \
-Denable-macos-sdk \
-Dstatic-llvm \
-Dskip-non-native \
--search-prefix "$PREFIX"
--search-prefix "$PREFIX" \
--test-timeout 2m
# Ensure that stage3 and stage4 are byte-for-byte identical.
stage3-release/bin/zig build \

View File

@ -1,5 +1,5 @@
$TARGET = "$($Env:ARCH)-windows-gnu"
$ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.14.0-dev.1622+2ac543388"
$TARGET = "aarch64-windows-gnu"
$ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
$MCPU = "baseline"
$ZIG_LLVM_CLANG_LLD_URL = "https://ziglang.org/deps/$ZIG_LLVM_CLANG_LLD_NAME.zip"
$PREFIX_PATH = "$(Get-Location)\..\$ZIG_LLVM_CLANG_LLD_NAME"
@ -22,14 +22,6 @@ function CheckLastExitCode {
return 0
}
# Make the `zig version` number consistent.
# This will affect the `zig build` command below which uses `git describe`.
git fetch --tags
if ((git rev-parse --is-shallow-repository) -eq "true") {
git fetch --unshallow # `git describe` won't work on a shallow repo
}
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
@ -66,7 +58,8 @@ Write-Output "Main test suite..."
--search-prefix "$PREFIX_PATH" `
-Dstatic-llvm `
-Dskip-non-native `
-Denable-symlinks-windows
-Denable-symlinks-windows `
--test-timeout 30m
CheckLastExitCode
# Ensure that stage3 and stage4 are byte-for-byte identical.

64
ci/loongarch64-linux-debug.sh Executable file
View File

@ -0,0 +1,64 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="loongarch64-linux-musl"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.157+7fdd60df1"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-debug
cd build-debug
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-debug" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Debug \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-debug/bin/zig build test docs \
--maxrss 60129542144 \
-Dstatic-llvm \
-Dskip-non-native \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m
stage3-debug/bin/zig build \
--prefix stage4-debug \
-Denable-llvm \
-Dno-lib \
-Dtarget=$TARGET \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-debug/bin/zig version)"
stage4-debug/bin/zig test ../test/behavior.zig

70
ci/loongarch64-linux-release.sh Executable file
View File

@ -0,0 +1,70 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="loongarch64-linux-musl"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.157+7fdd60df1"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-release
cd build-release
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-release" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-release/bin/zig build test docs \
--maxrss 60129542144 \
-Dstatic-llvm \
-Dskip-non-native \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m
# Ensure that stage3 and stage4 are byte-for-byte identical.
stage3-release/bin/zig build \
--prefix stage4-release \
-Denable-llvm \
-Dno-lib \
-Doptimize=ReleaseFast \
-Dstrip \
-Dtarget=$TARGET \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-release/bin/zig version)"
# diff returns an error code if the files differ.
echo "If the following command fails, it means nondeterminism has been"
echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
diff stage3-release/bin/zig stage4-release/bin/zig

55
ci/riscv64-linux-debug.sh Executable file
View File

@ -0,0 +1,55 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="riscv64-linux-musl"
MCPU="spacemit_x60"
CACHE_BASENAME="zig+llvm+lld+clang-riscv64-linux-musl-0.16.0-dev.104+689461e31"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
export PATH="$HOME/local/bin:$PATH"
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-debug
cd build-debug
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-debug" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Debug \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-debug/bin/zig build test-cases test-modules test-unit test-c-abi test-stack-traces test-error-traces test-llvm-ir \
--maxrss 68719476736 \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-single-threaded \
-Dskip-compile-errors \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m

55
ci/riscv64-linux-release.sh Executable file
View File

@ -0,0 +1,55 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="riscv64-linux-musl"
MCPU="spacemit_x60"
CACHE_BASENAME="zig+llvm+lld+clang-riscv64-linux-musl-0.16.0-dev.104+689461e31"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
export PATH="$HOME/local/bin:$PATH"
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-release
cd build-release
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-release" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-release/bin/zig build test-cases test-modules test-unit test-c-abi test-stack-traces test-error-traces test-llvm-ir \
--maxrss 68719476736 \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-single-threaded \
-Dskip-compile-errors \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m

65
ci/s390x-linux-debug.sh Executable file
View File

@ -0,0 +1,65 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="s390x-linux-musl"
MCPU="z15"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.1354+94e98bfe8"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-debug
cd build-debug
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-debug" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Debug \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-debug/bin/zig build test docs \
--maxrss 30064771072 \
-Dstatic-llvm \
-Dskip-non-native \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m
stage3-debug/bin/zig build \
--prefix stage4-debug \
-Denable-llvm \
-Dno-lib \
-Dtarget=$TARGET \
-Dcpu=$MCPU \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-debug/bin/zig version)"
stage4-debug/bin/zig test ../test/behavior.zig

71
ci/s390x-linux-release.sh Executable file
View File

@ -0,0 +1,71 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="s390x-linux-musl"
MCPU="z15"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.1354+94e98bfe8"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-release
cd build-release
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-release" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-release/bin/zig build test docs \
--maxrss 30064771072 \
-Dstatic-llvm \
-Dskip-non-native \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m
# Ensure that stage3 and stage4 are byte-for-byte identical.
stage3-release/bin/zig build \
--prefix stage4-release \
-Denable-llvm \
-Dno-lib \
-Doptimize=ReleaseFast \
-Dstrip \
-Dtarget=$TARGET \
-Dcpu=$MCPU \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-release/bin/zig version)"
# diff returns an error code if the files differ.
echo "If the following command fails, it means nondeterminism has been"
echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
diff stage3-release/bin/zig stage4-release/bin/zig

65
ci/x86_64-freebsd-debug.sh Executable file
View File

@ -0,0 +1,65 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="x86_64-freebsd-none"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.312+164c598cd"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-debug
cd build-debug
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-debug" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Debug \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
stage3-debug/bin/zig build test docs \
--maxrss 42949672960 \
-Dstatic-llvm \
-Dskip-linux \
-Dskip-netbsd \
-Dskip-windows \
-Dskip-darwin \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 2m
stage3-debug/bin/zig build \
--prefix stage4-debug \
-Denable-llvm \
-Dno-lib \
-Dtarget=$TARGET \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-debug/bin/zig version)"
stage4-debug/bin/zig test ../test/behavior.zig

71
ci/x86_64-freebsd-release.sh Executable file
View File

@ -0,0 +1,71 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="x86_64-freebsd-none"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.312+164c598cd"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-release
cd build-release
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-release" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
stage3-release/bin/zig build test docs \
--maxrss 42949672960 \
-Dstatic-llvm \
-Dskip-linux \
-Dskip-netbsd \
-Dskip-windows \
-Dskip-darwin \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 2m
# Ensure that stage3 and stage4 are byte-for-byte identical.
stage3-release/bin/zig build \
--prefix stage4-release \
-Denable-llvm \
-Dno-lib \
-Doptimize=ReleaseFast \
-Dstrip \
-Dtarget=$TARGET \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-release/bin/zig version)"
# diff returns an error code if the files differ.
echo "If the following command fails, it means nondeterminism has been"
echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
diff stage3-release/bin/zig stage4-release/bin/zig

65
ci/x86_64-linux-debug-llvm.sh Executable file
View File

@ -0,0 +1,65 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="x86_64-linux-musl"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
export PATH="$HOME/deps/wasmtime-v38.0.3-x86_64-linux:$HOME/deps/qemu-linux-x86_64-10.1.1.1/bin:$HOME/local/bin:$PATH"
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-debug-llvm
cd build-debug-llvm
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-debug" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Debug \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-DZIG_EXTRA_BUILD_ARGS="-Duse-llvm=true" \
-GNinja
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
# simultaneously test building self-hosted without LLVM and with 32-bit arm
stage3-debug/bin/zig build \
-Dtarget=arm-linux-musleabihf \
-Dno-lib
stage3-debug/bin/zig build test docs \
--maxrss 21000000000 \
-Dlldb=$HOME/deps/lldb-zig/Debug-e0a42bb34/bin/lldb \
-fqemu \
-fwasmtime \
-Dstatic-llvm \
-Dskip-freebsd \
-Dskip-netbsd \
-Dskip-windows \
-Dskip-darwin \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
-Denable-superhtml \
--test-timeout 12m

View File

@ -5,19 +5,13 @@
set -x
set -e
ARCH="$(uname -m)"
TARGET="$ARCH-linux-musl"
TARGET="x86_64-linux-musl"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.14.0-dev.1622+2ac543388"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
export PATH="$HOME/deps/wasmtime-v29.0.0-$ARCH-linux:$HOME/deps/qemu-linux-x86_64-9.2.0-rc1/bin:$HOME/local/bin:$PATH"
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git fetch --unshallow || true
git fetch --tags
export PATH="$HOME/deps/wasmtime-v38.0.3-x86_64-linux:$HOME/deps/qemu-linux-x86_64-10.1.1.1/bin:$HOME/local/bin:$PATH"
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
@ -25,12 +19,6 @@ git fetch --tags
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
# Test building from source without LLVM.
cc -o bootstrap bootstrap.c
./bootstrap
./zig2 build -Dno-lib
./zig-out/bin/zig test test/behavior.zig
mkdir build-debug
cd build-debug
@ -65,39 +53,13 @@ stage3-debug/bin/zig build test docs \
-fqemu \
-fwasmtime \
-Dstatic-llvm \
-Dskip-freebsd \
-Dskip-netbsd \
-Dskip-windows \
-Dskip-darwin \
-Dskip-llvm \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
-Denable-superhtml
# Ensure that updating the wasm binary from this commit will result in a viable build.
stage3-debug/bin/zig build update-zig1
mkdir ../build-new
cd ../build-new
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Debug \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja
unset CC
unset CXX
ninja install
stage3/bin/zig test ../test/behavior.zig
stage3/bin/zig build -p stage4 \
-Dstatic-llvm \
-Dtarget=native-native-musl \
-Dno-lib \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib"
stage4/bin/zig test ../test/behavior.zig
-Denable-superhtml \
--test-timeout 10m

View File

@ -5,19 +5,13 @@
set -x
set -e
ARCH="$(uname -m)"
TARGET="$ARCH-linux-musl"
TARGET="x86_64-linux-musl"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.14.0-dev.1622+2ac543388"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
export PATH="$HOME/deps/wasmtime-v29.0.0-$ARCH-linux:$HOME/deps/qemu-linux-x86_64-9.2.0-rc1/bin:$HOME/local/bin:$PATH"
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git fetch --unshallow || true
git fetch --tags
export PATH="$HOME/deps/wasmtime-v38.0.3-x86_64-linux:$HOME/deps/qemu-linux-x86_64-10.1.1.1/bin:$HOME/local/bin:$PATH"
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
@ -68,7 +62,8 @@ stage3-release/bin/zig build test docs \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
-Denable-superhtml
-Denable-superhtml \
--test-timeout 12m
# Ensure that stage3 and stage4 are byte-for-byte identical.
stage3-release/bin/zig build \

View File

@ -1,75 +0,0 @@
#!/bin/sh
set -x
set -e
ZIGDIR="$PWD"
TARGET="$ARCH-macos-none"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.14.0-dev.1622+2ac543388"
PREFIX="$HOME/$CACHE_BASENAME"
JOBS="-j3"
ZIG="$PREFIX/bin/zig"
if [ ! -d "$PREFIX" ]; then
cd $HOME
curl -L -O "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz"
tar xf "$CACHE_BASENAME.tar.xz"
fi
cd $ZIGDIR
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git fetch --unshallow || true
git fetch --tags
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
# Test building from source without LLVM.
cc -o bootstrap bootstrap.c
./bootstrap
./zig2 build -Dno-lib
./zig-out/bin/zig test test/behavior.zig
mkdir build
cd build
cmake .. \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER="$ZIG;cc;-target;$TARGET;-mcpu=$MCPU" \
-DCMAKE_CXX_COMPILER="$ZIG;c++;-target;$TARGET;-mcpu=$MCPU" \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON
make $JOBS install
stage3/bin/zig build test docs \
--zig-lib-dir "$PWD/../lib" \
-Denable-macos-sdk \
-Dstatic-llvm \
-Dskip-non-native \
--search-prefix "$PREFIX"
# Ensure that stage3 and stage4 are byte-for-byte identical.
stage3/bin/zig build \
--prefix stage4 \
-Denable-llvm \
-Dno-lib \
-Doptimize=ReleaseFast \
-Dstrip \
-Dtarget=$TARGET \
-Duse-zig-libcxx \
-Dversion-string="$(stage3/bin/zig version)"
# diff returns an error code if the files differ.
echo "If the following command fails, it means nondeterminism has been"
echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
diff stage3/bin/zig stage4/bin/zig

View File

@ -1,5 +1,5 @@
$TARGET = "$($Env:ARCH)-windows-gnu"
$ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.14.0-dev.1622+2ac543388"
$TARGET = "x86_64-windows-gnu"
$ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
$MCPU = "baseline"
$ZIG_LLVM_CLANG_LLD_URL = "https://ziglang.org/deps/$ZIG_LLVM_CLANG_LLD_NAME.zip"
$PREFIX_PATH = "$($Env:USERPROFILE)\$ZIG_LLVM_CLANG_LLD_NAME"
@ -22,14 +22,6 @@ function CheckLastExitCode {
return 0
}
# Make the `zig version` number consistent.
# This will affect the `zig build` command below which uses `git describe`.
git fetch --tags
if ((git rev-parse --is-shallow-repository) -eq "true") {
git fetch --unshallow # `git describe` won't work on a shallow repo
}
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
@ -67,7 +59,9 @@ Write-Output "Main test suite..."
-Dstatic-llvm `
-Dskip-non-native `
-Dskip-release `
-Denable-symlinks-windows
-Dskip-test-incremental `
-Denable-symlinks-windows `
--test-timeout 30m
CheckLastExitCode
Write-Output "Build x86_64-windows-msvc behavior tests using the C backend..."
@ -102,7 +96,7 @@ Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\
CheckLastExitCode
Write-Output "Build and run behavior tests with msvc..."
& cl.exe -I..\lib test-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /W3 /Z7 -link -nologo -debug -subsystem:console kernel32.lib ntdll.lib libcmt.lib
& cl.exe -I..\lib test-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /W3 /Z7 -link -nologo -debug -subsystem:console kernel32.lib ntdll.lib libcmt.lib ws2_32.lib
CheckLastExitCode
& .\test-x86_64-windows-msvc.exe

View File

@ -1,5 +1,5 @@
$TARGET = "$($Env:ARCH)-windows-gnu"
$ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.14.0-dev.1622+2ac543388"
$TARGET = "x86_64-windows-gnu"
$ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
$MCPU = "baseline"
$ZIG_LLVM_CLANG_LLD_URL = "https://ziglang.org/deps/$ZIG_LLVM_CLANG_LLD_NAME.zip"
$PREFIX_PATH = "$($Env:USERPROFILE)\$ZIG_LLVM_CLANG_LLD_NAME"
@ -22,14 +22,6 @@ function CheckLastExitCode {
return 0
}
# Make the `zig version` number consistent.
# This will affect the `zig build` command below which uses `git describe`.
git fetch --tags
if ((git rev-parse --is-shallow-repository) -eq "true") {
git fetch --unshallow # `git describe` won't work on a shallow repo
}
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
@ -66,7 +58,9 @@ Write-Output "Main test suite..."
--search-prefix "$PREFIX_PATH" `
-Dstatic-llvm `
-Dskip-non-native `
-Denable-symlinks-windows
-Dskip-test-incremental `
-Denable-symlinks-windows `
--test-timeout 30m
CheckLastExitCode
# Ensure that stage3 and stage4 are byte-for-byte identical.
@ -120,7 +114,7 @@ Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\
CheckLastExitCode
Write-Output "Build and run behavior tests with msvc..."
& cl.exe -I..\lib test-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /W3 /Z7 -link -nologo -debug -subsystem:console kernel32.lib ntdll.lib libcmt.lib
& cl.exe -I..\lib test-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /W3 /Z7 -link -nologo -debug -subsystem:console kernel32.lib ntdll.lib libcmt.lib ws2_32.lib
CheckLastExitCode
& .\test-x86_64-windows-msvc.exe

View File

@ -17,10 +17,10 @@ find_path(CLANG_INCLUDE_DIRS NAMES clang/Frontend/ASTUnit.h
if(${LLVM_LINK_MODE} STREQUAL "shared")
find_library(CLANG_LIBRARIES
NAMES
libclang-cpp.so.19
libclang-cpp.so.19.1
clang-cpp-19.0
clang-cpp190
libclang-cpp.so.21
libclang-cpp.so.21.1
clang-cpp-21.0
clang-cpp210
clang-cpp
NAMES_PER_DIR
HINTS "${LLVM_LIBDIRS}"
@ -60,7 +60,6 @@ else()
FIND_AND_ADD_CLANG_LIB(clangBasic)
FIND_AND_ADD_CLANG_LIB(clangEdit)
FIND_AND_ADD_CLANG_LIB(clangLex)
FIND_AND_ADD_CLANG_LIB(clangARCMigrate)
FIND_AND_ADD_CLANG_LIB(clangRewriteFrontend)
FIND_AND_ADD_CLANG_LIB(clangRewrite)
FIND_AND_ADD_CLANG_LIB(clangCrossTU)

View File

@ -9,21 +9,23 @@
find_path(LLD_INCLUDE_DIRS NAMES lld/Common/Driver.h
HINTS ${LLVM_INCLUDE_DIRS}
PATHS
/usr/lib/llvm-19/include
/usr/local/llvm190/include
/usr/local/llvm19/include
/usr/local/opt/llvm@19/include
/opt/homebrew/opt/llvm@19/include
/usr/lib/llvm-21/include
/usr/local/llvm210/include
/usr/local/llvm21/include
/usr/local/opt/lld@21/include
/opt/homebrew/opt/lld@21/include
/home/linuxbrew/.linuxbrew/opt/lld@21/include
/mingw64/include)
find_library(LLD_LIBRARY NAMES lld-19.0 lld190 lld NAMES_PER_DIR
find_library(LLD_LIBRARY NAMES lld-21.0 lld210 lld NAMES_PER_DIR
HINTS ${LLVM_LIBDIRS}
PATHS
/usr/lib/llvm-19/lib
/usr/local/llvm190/lib
/usr/local/llvm19/lib
/usr/local/opt/llvm@19/lib
/opt/homebrew/opt/llvm@19/lib
/usr/lib/llvm-21/lib
/usr/local/llvm210/lib
/usr/local/llvm21/lib
/usr/local/opt/lld@21/lib
/opt/homebrew/opt/lld@21/lib
/home/linuxbrew/.linuxbrew/opt/lld@21/lib
)
if(EXISTS ${LLD_LIBRARY})
set(LLD_LIBRARIES ${LLD_LIBRARY})
@ -34,11 +36,12 @@ else()
HINTS ${LLVM_LIBDIRS}
PATHS
${LLD_LIBDIRS}
/usr/lib/llvm-19/lib
/usr/local/llvm190/lib
/usr/local/llvm19/lib
/usr/local/opt/llvm@19/lib
/opt/homebrew/opt/llvm@19/lib
/usr/lib/llvm-21/lib
/usr/local/llvm210/lib
/usr/local/llvm21/lib
/usr/local/opt/lld@21/lib
/opt/homebrew/opt/lld@21/lib
/home/linuxbrew/.linuxbrew/opt/lld@21/lib
/mingw64/lib
/c/msys64/mingw64/lib
c:/msys64/mingw64/lib)

View File

@ -17,12 +17,12 @@ if(ZIG_USE_LLVM_CONFIG)
# terminate when the right LLVM version is not found.
unset(LLVM_CONFIG_EXE CACHE)
find_program(LLVM_CONFIG_EXE
NAMES llvm-config-19 llvm-config-19.0 llvm-config190 llvm-config19 llvm-config NAMES_PER_DIR
NAMES llvm-config-21 llvm-config-21.0 llvm-config210 llvm-config21 llvm-config NAMES_PER_DIR
PATHS
"/mingw64/bin"
"/c/msys64/mingw64/bin"
"c:/msys64/mingw64/bin"
"C:/Libraries/llvm-19.0.0/bin")
"C:/Libraries/llvm-21.0.0/bin")
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
if (NOT LLVM_CONFIG_ERROR_MESSAGES STREQUAL "")
@ -40,9 +40,9 @@ if(ZIG_USE_LLVM_CONFIG)
OUTPUT_STRIP_TRAILING_WHITESPACE)
get_filename_component(LLVM_CONFIG_DIR "${LLVM_CONFIG_EXE}" DIRECTORY)
if("${LLVM_CONFIG_VERSION}" VERSION_LESS 19 OR "${LLVM_CONFIG_VERSION}" VERSION_EQUAL 20 OR "${LLVM_CONFIG_VERSION}" VERSION_GREATER 20)
if("${LLVM_CONFIG_VERSION}" VERSION_LESS 21 OR "${LLVM_CONFIG_VERSION}" VERSION_EQUAL 22 OR "${LLVM_CONFIG_VERSION}" VERSION_GREATER 22)
# Save the error message, in case this is the last llvm-config we find
list(APPEND LLVM_CONFIG_ERROR_MESSAGES "expected LLVM 19.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
list(APPEND LLVM_CONFIG_ERROR_MESSAGES "expected LLVM 21.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
# Ignore this directory and try the search again
list(APPEND CMAKE_IGNORE_PATH "${LLVM_CONFIG_DIR}")
@ -66,9 +66,9 @@ if(ZIG_USE_LLVM_CONFIG)
if (LLVM_CONFIG_ERROR)
# Save the error message, in case this is the last llvm-config we find
if (ZIG_SHARED_LLVM)
list(APPEND LLVM_CONFIG_ERROR_MESSAGES "LLVM 19.x found at ${LLVM_CONFIG_EXE} does not support linking as a shared library")
list(APPEND LLVM_CONFIG_ERROR_MESSAGES "LLVM 21.x found at ${LLVM_CONFIG_EXE} does not support linking as a shared library")
else()
list(APPEND LLVM_CONFIG_ERROR_MESSAGES "LLVM 19.x found at ${LLVM_CONFIG_EXE} does not support linking as a static library")
list(APPEND LLVM_CONFIG_ERROR_MESSAGES "LLVM 21.x found at ${LLVM_CONFIG_EXE} does not support linking as a static library")
endif()
# Ignore this directory and try the search again
@ -83,7 +83,7 @@ if(ZIG_USE_LLVM_CONFIG)
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_TARGETS_BUILT "${LLVM_TARGETS_BUILT_SPACES}")
set(ZIG_LLVM_REQUIRED_TARGETS "AArch64;AMDGPU;ARM;AVR;BPF;Hexagon;Lanai;Mips;MSP430;NVPTX;PowerPC;RISCV;Sparc;SystemZ;VE;WebAssembly;X86;XCore")
set(ZIG_LLVM_REQUIRED_TARGETS "AArch64;AMDGPU;ARM;AVR;BPF;Hexagon;Lanai;LoongArch;Mips;MSP430;NVPTX;PowerPC;RISCV;SPIRV;Sparc;SystemZ;VE;WebAssembly;X86;XCore")
set(ZIG_LLVM_REQUIRED_TARGETS_ENABLED TRUE)
foreach(TARGET_NAME IN LISTS ZIG_LLVM_REQUIRED_TARGETS)
@ -197,10 +197,10 @@ else()
FIND_AND_ADD_LLVM_LIB(LLVMXRay)
FIND_AND_ADD_LLVM_LIB(LLVMLibDriver)
FIND_AND_ADD_LLVM_LIB(LLVMDlltoolDriver)
FIND_AND_ADD_LLVM_LIB(LLVMTelemetry)
FIND_AND_ADD_LLVM_LIB(LLVMTextAPIBinaryReader)
FIND_AND_ADD_LLVM_LIB(LLVMCoverage)
FIND_AND_ADD_LLVM_LIB(LLVMLineEditor)
FIND_AND_ADD_LLVM_LIB(LLVMSandboxIR)
FIND_AND_ADD_LLVM_LIB(LLVMXCoreDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMXCoreCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMXCoreDesc)
@ -227,6 +227,10 @@ else()
FIND_AND_ADD_LLVM_LIB(LLVMSystemZCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMSystemZDesc)
FIND_AND_ADD_LLVM_LIB(LLVMSystemZInfo)
FIND_AND_ADD_LLVM_LIB(LLVMSPIRVCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMSPIRVDesc)
FIND_AND_ADD_LLVM_LIB(LLVMSPIRVInfo)
FIND_AND_ADD_LLVM_LIB(LLVMSPIRVAnalysis)
FIND_AND_ADD_LLVM_LIB(LLVMSparcDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMSparcAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMSparcCodeGen)
@ -311,32 +315,34 @@ else()
FIND_AND_ADD_LLVM_LIB(LLVMOrcTargetProcess)
FIND_AND_ADD_LLVM_LIB(LLVMOrcShared)
FIND_AND_ADD_LLVM_LIB(LLVMDWP)
FIND_AND_ADD_LLVM_LIB(LLVMDWARFCFIChecker)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoLogicalView)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoGSYM)
FIND_AND_ADD_LLVM_LIB(LLVMOption)
FIND_AND_ADD_LLVM_LIB(LLVMObjectYAML)
FIND_AND_ADD_LLVM_LIB(LLVMObjCopy)
FIND_AND_ADD_LLVM_LIB(LLVMMCA)
FIND_AND_ADD_LLVM_LIB(LLVMMCDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMLTO)
FIND_AND_ADD_LLVM_LIB(LLVMPasses)
FIND_AND_ADD_LLVM_LIB(LLVMHipStdPar)
FIND_AND_ADD_LLVM_LIB(LLVMCFGuard)
FIND_AND_ADD_LLVM_LIB(LLVMCoroutines)
FIND_AND_ADD_LLVM_LIB(LLVMipo)
FIND_AND_ADD_LLVM_LIB(LLVMVectorize)
FIND_AND_ADD_LLVM_LIB(LLVMLinker)
FIND_AND_ADD_LLVM_LIB(LLVMInstrumentation)
FIND_AND_ADD_LLVM_LIB(LLVMFrontendOpenMP)
FIND_AND_ADD_LLVM_LIB(LLVMFrontendOffloading)
FIND_AND_ADD_LLVM_LIB(LLVMFrontendOpenACC)
FIND_AND_ADD_LLVM_LIB(LLVMFrontendHLSL)
FIND_AND_ADD_LLVM_LIB(LLVMFrontendDriver)
FIND_AND_ADD_LLVM_LIB(LLVMExtensions)
FIND_AND_ADD_LLVM_LIB(LLVMPasses)
FIND_AND_ADD_LLVM_LIB(LLVMHipStdPar)
FIND_AND_ADD_LLVM_LIB(LLVMCoroutines)
FIND_AND_ADD_LLVM_LIB(LLVMCFGuard)
FIND_AND_ADD_LLVM_LIB(LLVMipo)
FIND_AND_ADD_LLVM_LIB(LLVMInstrumentation)
FIND_AND_ADD_LLVM_LIB(LLVMVectorize)
FIND_AND_ADD_LLVM_LIB(LLVMSandboxIR)
FIND_AND_ADD_LLVM_LIB(LLVMLinker)
FIND_AND_ADD_LLVM_LIB(LLVMFrontendOpenMP)
FIND_AND_ADD_LLVM_LIB(LLVMFrontendDirective)
FIND_AND_ADD_LLVM_LIB(LLVMFrontendAtomic)
FIND_AND_ADD_LLVM_LIB(LLVMFrontendOffloading)
FIND_AND_ADD_LLVM_LIB(LLVMObjectYAML)
FIND_AND_ADD_LLVM_LIB(LLVMDWARFLinkerParallel)
FIND_AND_ADD_LLVM_LIB(LLVMDWARFLinkerClassic)
FIND_AND_ADD_LLVM_LIB(LLVMDWARFLinker)
FIND_AND_ADD_LLVM_LIB(LLVMCodeGenData)
FIND_AND_ADD_LLVM_LIB(LLVMGlobalISel)
FIND_AND_ADD_LLVM_LIB(LLVMMIRParser)
FIND_AND_ADD_LLVM_LIB(LLVMAsmPrinter)
@ -345,6 +351,7 @@ else()
FIND_AND_ADD_LLVM_LIB(LLVMTarget)
FIND_AND_ADD_LLVM_LIB(LLVMObjCARCOpts)
FIND_AND_ADD_LLVM_LIB(LLVMCodeGenTypes)
FIND_AND_ADD_LLVM_LIB(LLVMCGData)
FIND_AND_ADD_LLVM_LIB(LLVMIRPrinter)
FIND_AND_ADD_LLVM_LIB(LLVMInterfaceStub)
FIND_AND_ADD_LLVM_LIB(LLVMFileCheck)
@ -360,14 +367,16 @@ else()
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoBTF)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoPDB)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoMSF)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoCodeView)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoGSYM)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoDWARF)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoDWARFLowLevel)
FIND_AND_ADD_LLVM_LIB(LLVMObject)
FIND_AND_ADD_LLVM_LIB(LLVMTextAPI)
FIND_AND_ADD_LLVM_LIB(LLVMMCParser)
FIND_AND_ADD_LLVM_LIB(LLVMIRReader)
FIND_AND_ADD_LLVM_LIB(LLVMAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMMC)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoCodeView)
FIND_AND_ADD_LLVM_LIB(LLVMBitReader)
FIND_AND_ADD_LLVM_LIB(LLVMFuzzerCLI)
FIND_AND_ADD_LLVM_LIB(LLVMCore)

View File

@ -316,7 +316,8 @@
<a href="https://ziglang.org/documentation/0.11.0/">0.11.0</a> |
<a href="https://ziglang.org/documentation/0.12.0/">0.12.0</a> |
<a href="https://ziglang.org/documentation/0.13.0/">0.13.0</a> |
<a href="https://ziglang.org/documentation/0.14.0/">0.14.0</a> |
<a href="https://ziglang.org/documentation/0.14.1/">0.14.1</a> |
<a href="https://ziglang.org/documentation/0.15.2/">0.15.2</a> |
master
</nav>
<nav aria-labelledby="table-of-contents">
@ -374,7 +375,8 @@
<p>
Most of the time, it is more appropriate to write to stderr rather than stdout, and
whether or not the message is successfully written to the stream is irrelevant.
For this common case, there is a simpler API:
Also, formatted printing often comes in handy. For this common case,
there is a simpler API:
</p>
{#code|hello_again.zig#}
@ -419,8 +421,7 @@
{#code|unattached_doc-comment.zig#}
<p>
Doc comments can be interleaved with normal comments. Currently, when producing
the package documentation, normal comments are merged with doc comments.
Doc comments can be interleaved with normal comments, which are ignored.
</p>
{#header_close#}
{#header_open|Top-Level Doc Comments#}
@ -637,7 +638,7 @@
{#syntax#}i7{#endsyntax#} refers to a signed 7-bit integer. The maximum allowed bit-width of an
integer type is {#syntax#}65535{#endsyntax#}.
</p>
{#see_also|Integers|Floats|void|Errors|@Type#}
{#see_also|Integers|Floats|void|Errors|@Int#}
{#header_close#}
{#header_open|Primitive Values#}
<div class="table-wrapper">
@ -777,7 +778,7 @@
value. Using this value would be a bug. The value will be unused, or overwritten before being used."
</p>
<p>
In {#link|Debug#} mode, Zig writes {#syntax#}0xaa{#endsyntax#} bytes to undefined memory. This is to catch
In {#link|Debug#} and {#link|ReleaseSafe#} mode, Zig writes {#syntax#}0xaa{#endsyntax#} bytes to undefined memory. This is to catch
bugs early, and to help detect use of undefined memory in a debugger. However, this behavior is only an
implementation feature, not a language semantic, so it is not guaranteed to be observable to code.
</p>
@ -1649,6 +1650,7 @@ unwrapped == 1234{#endsyntax#}</pre>
<li>{#link|Floats#}</li>
<li>{#link|bool|Primitive Types#}</li>
<li>{#link|type|Primitive Types#}</li>
<li>{#link|packed struct#}</li>
</ul>
</td>
<td>
@ -1925,8 +1927,10 @@ or
Vector types are created with the builtin function {#link|@Vector#}.
</p>
<p>
Vectors support the same builtin operators as their underlying base types.
These operations are performed element-wise, and return a vector of the same length
Vectors generally support the same builtin operators as their underlying base types.
The only exception to this is the keywords `and` and `or` on vectors of bools, since
these operators affect control flow, which is not allowed for vectors.
All other operations are performed element-wise, and return a vector of the same length
as the input vectors. This includes:
</p>
<ul>
@ -1936,6 +1940,7 @@ or
<li>Bitwise operators ({#syntax#}>>{#endsyntax#}, {#syntax#}<<{#endsyntax#}, {#syntax#}&{#endsyntax#},
{#syntax#}|{#endsyntax#}, {#syntax#}~{#endsyntax#}, etc.)</li>
<li>Comparison operators ({#syntax#}<{#endsyntax#}, {#syntax#}>{#endsyntax#}, {#syntax#}=={#endsyntax#}, etc.)</li>
<li>Boolean not ({#syntax#}!{#endsyntax#})</li>
</ul>
<p>
It is prohibited to use a math operator on a mixture of scalars (individual numbers)
@ -1963,6 +1968,14 @@ or
</p>
{#see_also|@splat|@shuffle|@select|@reduce#}
{#header_open|Relationship with Arrays#}
<p>Vectors and {#link|Arrays#} each have a well-defined <strong>bit layout</strong>
and therefore support {#link|@bitCast#} between each other. {#link|Type Coercion#} implicitly peforms
{#syntax#}@bitCast{#endsyntax#}.</p>
<p>Arrays have well-defined byte layout, but vectors do not, making {#link|@ptrCast#} between
them {#link|Illegal Behavior#}.</p>
{#header_close#}
{#header_open|Destructuring Vectors#}
<p>
Vectors can be destructured:
@ -2224,20 +2237,24 @@ or
{#header_open|packed struct#}
<p>
Unlike normal structs, {#syntax#}packed{#endsyntax#} structs have guaranteed in-memory layout:
{#syntax#}packed{#endsyntax#} structs, like {#syntax#}enum{#endsyntax#}, are based on the concept
of interpreting integers differently. All packed structs have a <strong>backing integer</strong>,
which is implicitly determined by the total bit count of fields, or explicitly specified.
Packed structs have well-defined memory layout - exactly the same ABI as their backing integer.
</p>
<p>
Each field of a packed struct is interpreted as a logical sequence of bits, arranged from
least to most significant. Allowed field types:
</p>
<ul>
<li>Fields remain in the order declared, least to most significant.</li>
<li>There is no padding between fields.</li>
<li>Zig supports arbitrary width {#link|Integers#} and although normally, integers with fewer
than 8 bits will still use 1 byte of memory, in packed structs, they use
exactly their bit width.
</li>
<li>{#syntax#}bool{#endsyntax#} fields use exactly 1 bit.</li>
<li>An {#link|integer|Integers#} field uses exactly as many bits as its
bit width. For example, a {#syntax#}u5{#endsyntax#} will use 5 bits of
the backing integer.</li>
<li>A {#link|bool|Primitive Types#} field uses exactly 1 bit.</li>
<li>An {#link|enum#} field uses exactly the bit width of its integer tag type.</li>
<li>A {#link|packed union#} field uses exactly the bit width of the union field with
the largest bit width.</li>
<li>Packed structs support equality operators.</li>
<li>A {#syntax#}packed struct{#endsyntax#} field uses the bits of its backing integer.</li>
</ul>
<p>
This means that a {#syntax#}packed struct{#endsyntax#} can participate
@ -2245,10 +2262,11 @@ or
This even works at {#link|comptime#}:
</p>
{#code|test_packed_structs.zig#}
<p>
The backing integer is inferred from the fields' total bit width.
Optionally, it can be explicitly provided and enforced at compile time:
The backing integer can be inferred or explicitly provided. When
inferred, it will be unsigned. When explicitly provided, its bit width
will be enforced at compile time to exactly match the total bit width of
the fields:
</p>
{#code|test_missized_packed_struct.zig#}
@ -2289,19 +2307,19 @@ or
{#code|test_aligned_struct_fields.zig#}
<p>
Equating packed structs results in a comparison of the backing integer,
and only works for the `==` and `!=` operators.
Equating packed structs results in a comparison of the backing integer,
and only works for the {#syntax#}=={#endsyntax#} and {#syntax#}!={#endsyntax#} {#link|Operators#}.
</p>
{#code|test_packed_struct_equality.zig#}
<p>
Using packed structs with {#link|volatile#} is problematic, and may be a compile error in the future.
For details on this subscribe to
<a href="https://github.com/ziglang/zig/issues/1761">this issue</a>.
TODO update these docs with a recommendation on how to use packed structs with MMIO
(the use case for volatile packed structs) once this issue is resolved.
Don't worry, there will be a good solution for this use case in zig.
Field access and assignment can be understood as shorthand for bitshifts
on the backing integer. These operations are not {#link|atomic|Atomics#},
so beware using field access syntax when combined with memory-mapped
input-output (MMIO). Instead of field access on {#link|volatile#} {#link|Pointers#},
construct a fully-formed new value first, then write that value to the volatile pointer.
</p>
{#code|packed_struct_mmio.zig#}
{#header_close#}
{#header_open|Struct Naming#}
@ -2459,6 +2477,13 @@ or
</p>
{#code|test_union_method.zig#}
<p>
Unions with inferred enum tag types can also assign ordinal values to their inferred tag.
This requires the tag to specify an explicit integer type.
{#link|@intFromEnum#} can be used to access the ordinal value corresponding to the active field.
</p>
{#code|test_tagged_union_with_tag_values.zig#}
<p>
{#link|@tagName#} can be used to return a {#link|comptime#}
{#syntax#}[:0]const u8{#endsyntax#} value representing the field name:
@ -2478,6 +2503,7 @@ or
{#header_open|packed union#}
<p>A {#syntax#}packed union{#endsyntax#} has well-defined in-memory layout and is eligible
to be in a {#link|packed struct#}.</p>
<p>All fields in a packed union must have the same {#link|@bitSizeOf#}.</p>
{#header_close#}
{#header_open|Anonymous Union Literals#}
@ -2998,7 +3024,7 @@ or
{#syntax#}catch{#endsyntax#} after performing some logic, you
can combine {#syntax#}catch{#endsyntax#} with named {#link|Blocks#}:
</p>
{#code|handle_error_with_catch_block.zig.zig#}
{#code|handle_error_with_catch_block.zig#}
{#header_close#}
{#header_open|try#}
@ -3205,7 +3231,7 @@ fn createFoo(param: i32) !Foo {
to increase their development pace.
</p>
<p>
Error Return Traces are enabled by default in {#link|Debug#} and {#link|ReleaseSafe#} builds and disabled by default in {#link|ReleaseFast#} and {#link|ReleaseSmall#} builds.
Error Return Traces are enabled by default in {#link|Debug#} builds and disabled by default in {#link|ReleaseFast#}, {#link|ReleaseSafe#} and {#link|ReleaseSmall#} builds.
</p>
<p>
There are a few ways to activate this error return tracing feature:
@ -3679,27 +3705,27 @@ void do_a_thing(struct Foo *foo) {
<tr>
<th scope="row">{#syntax#}.{x}{#endsyntax#}</th>
<td>{#syntax#}T{#endsyntax#}</td>
<td>{#syntax#}x{#endsyntax#} is a {#syntax#}std.meta.FieldType(T, .@"0"){#endsyntax#}</td>
<td>{#syntax#}x{#endsyntax#} is a {#syntax#}@FieldType(T, "0"){#endsyntax#}</td>
</tr>
<tr>
<th scope="row">{#syntax#}.{ .a = x }{#endsyntax#}</th>
<td>{#syntax#}T{#endsyntax#}</td>
<td>{#syntax#}x{#endsyntax#} is a {#syntax#}std.meta.FieldType(T, .a){#endsyntax#}</td>
<td>{#syntax#}x{#endsyntax#} is a {#syntax#}@FieldType(T, "a"){#endsyntax#}</td>
</tr>
<tr>
<th scope="row">{#syntax#}T{x}{#endsyntax#}</th>
<td>-</td>
<td>{#syntax#}x{#endsyntax#} is a {#syntax#}std.meta.FieldType(T, .@"0"){#endsyntax#}</td>
<td>{#syntax#}x{#endsyntax#} is a {#syntax#}@FieldType(T, "0"){#endsyntax#}</td>
</tr>
<tr>
<th scope="row">{#syntax#}T{ .a = x }{#endsyntax#}</th>
<td>-</td>
<td>{#syntax#}x{#endsyntax#} is a {#syntax#}std.meta.FieldType(T, .a){#endsyntax#}</td>
<td>{#syntax#}x{#endsyntax#} is a {#syntax#}@FieldType(T, "a"){#endsyntax#}</td>
</tr>
<tr>
<th scope="row">{#syntax#}@Type(x){#endsyntax#}</th>
<th scope="row">{#syntax#}@Int(x, y){#endsyntax#}</th>
<td>-</td>
<td>{#syntax#}x{#endsyntax#} is a {#syntax#}std.builtin.Type{#endsyntax#}</td>
<td>{#syntax#}x{#endsyntax#} is a {#syntax#}std.builtin.Signedness{#endsyntax#}, {#syntax#}y{#endsyntax#} is a {#syntax#}u16{#endsyntax#}</td>
</tr>
<tr>
<th scope="row">{#syntax#}@typeInfo(x){#endsyntax#}</th>
@ -3813,9 +3839,9 @@ void do_a_thing(struct Foo *foo) {
<td>{#syntax#}x{#endsyntax#} has no result location (typed initializers do not propagate result locations)</td>
</tr>
<tr>
<th scope="row">{#syntax#}@Type(x){#endsyntax#}</th>
<td>{#syntax#}ptr{#endsyntax#}</td>
<td>{#syntax#}x{#endsyntax#} has no result location</td>
<th scope="row">{#syntax#}@Int(x, y){#endsyntax#}</th>
<td>-</td>
<td>{#syntax#}x{#endsyntax#} and {#syntax#}y{#endsyntax#} do not have result locations</td>
</tr>
<tr>
<th scope="row">{#syntax#}@typeInfo(x){#endsyntax#}</th>
@ -3833,37 +3859,6 @@ void do_a_thing(struct Foo *foo) {
{#header_close#}
{#header_close#}
{#header_open|usingnamespace#}
<p>
{#syntax#}usingnamespace{#endsyntax#} is a declaration that mixes all the public
declarations of the operand, which must be a {#link|struct#}, {#link|union#}, {#link|enum#},
or {#link|opaque#}, into the namespace:
</p>
{#code|test_usingnamespace.zig#}
<p>
{#syntax#}usingnamespace{#endsyntax#} has an important use case when organizing the public
API of a file or package. For example, one might have <code class="file">c.zig</code> with all of the
{#link|C imports|Import from C Header File#}:
</p>
{#syntax_block|zig|c.zig#}
pub usingnamespace @cImport({
@cInclude("epoxy/gl.h");
@cInclude("GLFW/glfw3.h");
@cDefine("STBI_ONLY_PNG", "");
@cDefine("STBI_NO_STDIO", "");
@cInclude("stb_image.h");
});
{#end_syntax_block#}
<p>
The above example demonstrates using {#syntax#}pub{#endsyntax#} to qualify the
{#syntax#}usingnamespace{#endsyntax#} additionally makes the imported declarations
{#syntax#}pub{#endsyntax#}. This can be used to forward declarations, giving precise control
over what declarations a given file exposes.
</p>
{#header_close#}
{#header_open|comptime#}
<p>
Zig places importance on the concept of whether an expression is known at compile-time.
@ -4270,16 +4265,9 @@ pub fn print(self: *Writer, arg0: []const u8, arg1: i32) !void {
{#header_close#}
{#header_open|Async Functions#}
<p>Async functions regressed with the release of 0.11.0. Their future in
the Zig language is unclear due to multiple unsolved problems:</p>
<ul>
<li>LLVM's lack of ability to optimize them.</li>
<li>Third-party debuggers' lack of ability to debug them.</li>
<li><a href="https://github.com/ziglang/zig/issues/5913">The cancellation problem</a>.</li>
<li>Async function pointers preventing the stack size from being known.</li>
</ul>
<p>These problems are surmountable, but it will take time. The Zig team
is currently focused on other priorities.</p>
<p>Async functions regressed with the release of 0.11.0. The current plan is to
reintroduce them as a lower level primitive that powers I/O implementations.</p>
<p>Tracking issue: <a href="https://github.com/ziglang/zig/issues/23446">Proposal: stackless coroutines as low-level primitives</a></p>
{#header_close#}
{#header_open|Builtin Functions|2col#}
@ -4347,7 +4335,7 @@ comptime {
</p>
<p>
{#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#}, a float,
an integer or an enum.
an integer, an enum, or a packed struct.
</p>
<p>{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.</p>
{#see_also|@atomicStore|@atomicRmw||@cmpxchgWeak|@cmpxchgStrong#}
@ -4361,7 +4349,7 @@ comptime {
</p>
<p>
{#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#}, a float,
an integer or an enum.
an integer, an enum, or a packed struct.
</p>
<p>{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.</p>
<p>{#syntax#}AtomicRmwOp{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicRmwOp{#endsyntax#}.</p>
@ -4375,7 +4363,7 @@ comptime {
</p>
<p>
{#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#}, a float,
an integer or an enum.
an integer, an enum, or a packed struct.
</p>
<p>{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.</p>
{#see_also|@atomicLoad|@atomicRmw|@cmpxchgWeak|@cmpxchgStrong#}
@ -4604,8 +4592,8 @@ comptime {
more efficiently in machine instructions.
</p>
<p>
{#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#}, a float,
an integer or an enum.
{#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#},
an integer, an enum, or a packed struct.
</p>
<p>{#syntax#}@typeInfo(@TypeOf(ptr)).pointer.alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}</p>
<p>{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.</p>
@ -4636,8 +4624,8 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
However if you need a stronger guarantee, use {#link|@cmpxchgStrong#}.
</p>
<p>
{#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#}, a float,
an integer or an enum.
{#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#},
an integer, an enum, or a packed struct.
</p>
<p>{#syntax#}@typeInfo(@TypeOf(ptr)).pointer.alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}</p>
<p>{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.</p>
@ -4868,7 +4856,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
<p>
This builtin can be called from a {#link|comptime#} block to conditionally export symbols.
When <code>ptr</code> points to a function with the C calling convention and
{#syntax#}options.linkage{#endsyntax#} is {#syntax#}.Strong{#endsyntax#}, this is equivalent to
{#syntax#}options.linkage{#endsyntax#} is {#syntax#}.strong{#endsyntax#}, this is equivalent to
the {#syntax#}export{#endsyntax#} keyword used on a function:
</p>
{#code|export_builtin.zig#}
@ -4908,8 +4896,8 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
{#header_open|@fieldParentPtr#}
<pre>{#syntax#}@fieldParentPtr(comptime field_name: []const u8, field_ptr: *T) anytype{#endsyntax#}</pre>
<p>
Given a pointer to a struct field, returns a pointer to the struct containing that field.
The return type (and struct in question) is the inferred result type.
Given a pointer to a struct or union field, returns a pointer to the struct or union containing that field.
The return type (pointer to the parent struct or union in question) is the inferred result type.
</p>
<p>
If {#syntax#}field_ptr{#endsyntax#} does not point to the {#syntax#}field_name{#endsyntax#} field of an instance of
@ -4980,34 +4968,25 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
{#header_close#}
{#header_open|@import#}
<pre>{#syntax#}@import(comptime path: []const u8) type{#endsyntax#}</pre>
<p>
This function finds a zig file corresponding to {#syntax#}path{#endsyntax#} and adds it to the build,
if it is not already added.
</p>
<p>
Zig source files are implicitly structs, with a name equal to the file's basename with the extension
truncated. {#syntax#}@import{#endsyntax#} returns the struct type corresponding to the file.
</p>
<p>
Declarations which have the {#syntax#}pub{#endsyntax#} keyword may be referenced from a different
source file than the one they are declared in.
</p>
<p>
{#syntax#}path{#endsyntax#} can be a relative path or it can be the name of a package.
If it is a relative path, it is relative to the file that contains the {#syntax#}@import{#endsyntax#}
function call.
</p>
<p>
The following packages are always available:
</p>
<pre>{#syntax#}@import(comptime target: []const u8) anytype{#endsyntax#}</pre>
<p>Imports the file at {#syntax#}target{#endsyntax#}, adding it to the compilation if it is not already
added. {#syntax#}target{#endsyntax#} is either a relative path to another file from the file containing
the {#syntax#}@import{#endsyntax#} call, or it is the name of a {#link|module|Compilation Model#}, with
the import referring to the root source file of that module. Either way, the file path must end in
either <code>.zig</code> (for a Zig source file) or <code>.zon</code> (for a ZON data file).</p>
<p>If {#syntax#}target{#endsyntax#} refers to a Zig source file, then {#syntax#}@import{#endsyntax#} returns
that file's {#link|corresponding struct type|Source File Structs#}, essentially as if the builtin call was
replaced by {#syntax#}struct { FILE_CONTENTS }{#endsyntax#}. The return type is {#syntax#}type{#endsyntax#}.</p>
<p>If {#syntax#}target{#endsyntax#} refers to a ZON file, then {#syntax#}@import{#endsyntax#} returns the value
of the literal in the file. If there is an inferred {#link|result type|Result Types#}, then the return type
is that type, and the ZON literal is interpreted as that type ({#link|Result Types#} are propagated through
the ZON expression). Otherwise, the return type is the type of the equivalent Zig expression, essentially as
if the builtin call was replaced by the ZON file contents.</p>
<p>The following modules are always available for import:</p>
<ul>
<li>{#syntax#}@import("std"){#endsyntax#} - Zig Standard Library</li>
<li>{#syntax#}@import("builtin"){#endsyntax#} - Target-specific information
The command <code>zig build-exe --show-builtin</code> outputs the source to stdout for reference.
</li>
<li>{#syntax#}@import("root"){#endsyntax#} - Root source file
This is usually <code>src/main.zig</code> but depends on what file is built.
<li>{#syntax#}@import("builtin"){#endsyntax#} - Target-specific information. The command <code>zig build-exe --show-builtin</code> outputs the source to stdout for reference.</li>
<li>{#syntax#}@import("root"){#endsyntax#} - Alias for the root module. In typical project structures, this means it refers back to <code>src/main.zig</code>.
</li>
</ul>
{#see_also|Compile Variables|@embedFile#}
@ -5143,6 +5122,23 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
{#syntax#}std.crypto.secureZero{#endsyntax#}</p>
{#header_close#}
{#header_open|@memmove#}
<pre>{#syntax#}@memmove(dest, source) void{#endsyntax#}</pre>
<p>This function copies bytes from one region of memory to another, but unlike
{#link|@memcpy#} the regions may overlap.</p>
<p>{#syntax#}dest{#endsyntax#} must be a mutable slice, a mutable pointer to an array, or
a mutable many-item {#link|pointer|Pointers#}. It may have any
alignment, and it may have any element type.</p>
<p>{#syntax#}source{#endsyntax#} must be a slice, a pointer to
an array, or a many-item {#link|pointer|Pointers#}. It may
have any alignment, and it may have any element type.</p>
<p>The {#syntax#}source{#endsyntax#} element type must have the same in-memory
representation as the {#syntax#}dest{#endsyntax#} element type.</p>
<p>Similar to {#link|for#} loops, at least one of {#syntax#}source{#endsyntax#} and
{#syntax#}dest{#endsyntax#} must provide a length, and if two lengths are provided,
they must be equal.</p>
{#header_close#}
{#header_open|@min#}
<pre>{#syntax#}@min(...) T{#endsyntax#}</pre>
<p>
@ -5190,7 +5186,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
<pre>{#syntax#}@mod(numerator: T, denominator: T) T{#endsyntax#}</pre>
<p>
Modulus division. For unsigned integers this is the same as
{#syntax#}numerator % denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator > 0{#endsyntax#}, otherwise the
{#syntax#}numerator % denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator != 0{#endsyntax#}, otherwise the
operation will result in a {#link|Remainder Division by Zero#} when runtime safety checks are enabled.
</p>
<ul>
@ -5295,7 +5291,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
<pre>{#syntax#}@rem(numerator: T, denominator: T) T{#endsyntax#}</pre>
<p>
Remainder division. For unsigned integers this is the same as
{#syntax#}numerator % denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator > 0{#endsyntax#}, otherwise the
{#syntax#}numerator % denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator != 0{#endsyntax#}, otherwise the
operation will result in a {#link|Remainder Division by Zero#} when runtime safety checks are enabled.
</p>
<ul>
@ -5498,8 +5494,9 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
{#header_open|@splat#}
<pre>{#syntax#}@splat(scalar: anytype) anytype{#endsyntax#}</pre>
<p>
Produces a vector where each element is the value {#syntax#}scalar{#endsyntax#}.
The return type and thus the length of the vector is inferred.
Produces an array or vector where each element is the value
{#syntax#}scalar{#endsyntax#}. The return type and thus the length of the
vector is inferred.
</p>
{#code|test_splat_builtin.zig#}
@ -5758,41 +5755,75 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
</p>
{#header_close#}
{#header_open|@Type#}
<pre>{#syntax#}@Type(comptime info: std.builtin.Type) type{#endsyntax#}</pre>
<p>
This function is the inverse of {#link|@typeInfo#}. It reifies type information
into a {#syntax#}type{#endsyntax#}.
</p>
<p>
It is available for the following types:
</p>
<ul>
<li>{#syntax#}type{#endsyntax#}</li>
<li>{#syntax#}noreturn{#endsyntax#}</li>
<li>{#syntax#}void{#endsyntax#}</li>
<li>{#syntax#}bool{#endsyntax#}</li>
<li>{#link|Integers#} - The maximum bit count for an integer type is {#syntax#}65535{#endsyntax#}.</li>
<li>{#link|Floats#}</li>
<li>{#link|Pointers#}</li>
<li>{#syntax#}comptime_int{#endsyntax#}</li>
<li>{#syntax#}comptime_float{#endsyntax#}</li>
<li>{#syntax#}@TypeOf(undefined){#endsyntax#}</li>
<li>{#syntax#}@TypeOf(null){#endsyntax#}</li>
<li>{#link|Arrays#}</li>
<li>{#link|Optionals#}</li>
<li>{#link|Error Set Type#}</li>
<li>{#link|Error Union Type#}</li>
<li>{#link|Vectors#}</li>
<li>{#link|opaque#}</li>
<li>{#syntax#}anyframe{#endsyntax#}</li>
<li>{#link|struct#}</li>
<li>{#link|enum#}</li>
<li>{#link|Enum Literals#}</li>
<li>{#link|union#}</li>
<li>{#link|Functions#}</li>
</ul>
{#header_open|@EnumLiteral#}
<pre>{#syntax#}@EnumLiteral() type{#endsyntax#}</pre>
<p>Returns the comptime-only "enum literal" type. This is the type of uncoerced {#link|Enum Literals#}. Values of this type can coerce to any {#link|enum#} with a matching field.</p>
{#header_close#}
{#header_open|@Int#}
<pre>{#syntax#}@Int(comptime signedness: std.builtin.Signedness, comptime bits: u16) type{#endsyntax#}</pre>
<p>Returns an integer type with the given signedness and bit width.</p>
<p>For instance, {#syntax#}@Int(.unsigned, 18){#endsyntax#} returns the type {#syntax#}u18{#endsyntax#}.</p>
{#header_close#}
{#header_open|@Tuple#}
<pre>{#syntax#}@Tuple(comptime field_types: []const type) type{#endsyntax#}</pre>
<p>Returns a {#link|tuple|Tuples#} type with the given field types.</p>
{#header_close#}
{#header_open|@Pointer#}
<pre>{#syntax#}@Pointer(
comptime size: std.builtin.Type.Pointer.Size,
comptime attrs: std.builtin.Type.Pointer.Attributes,
comptime Element: type,
comptime sentinel: ?Element,
) type{#endsyntax#}</pre>
<p>Returns a {#link|pointer|Pointers#} type with the properties specified by the arguments.</p>
{#header_close#}
{#header_open|@Fn#}
<pre>{#syntax#}@Fn(
comptime param_types: []const type,
comptime param_attrs: *const [param_types.len]std.builtin.Type.Fn.Param.Attributes,
comptime ReturnType: type,
comptime attrs: std.builtin.Type.Fn.Attributes,
) type{#endsyntax#}</pre>
<p>Returns a {#link|function|Functions#} type with the properties specified by the arguments.</p>
{#header_close#}
{#header_open|@Struct#}
<pre>{#syntax#}@Struct(
comptime layout: std.builtin.Type.ContainerLayout,
comptime BackingInt: ?type,
comptime field_names: []const []const u8,
comptime field_types: *const [field_names.len]type,
comptime field_attrs: *const [field_names.len]std.builtin.Type.StructField.Attributes,
) type{#endsyntax#}</pre>
<p>Returns a {#link|struct#} type with the properties specified by the arguments.</p>
{#header_close#}
{#header_open|@Union#}
<pre>{#syntax#}@Union(
comptime layout: std.builtin.Type.ContainerLayout,
/// Either the integer tag type, or the integer backing type, depending on `layout`.
comptime ArgType: ?type,
comptime field_names: []const []const u8,
comptime field_types: *const [field_names.len]type,
comptime field_attrs: *const [field_names.len]std.builtin.Type.UnionField.Attributes,
) type{#endsyntax#}</pre>
<p>Returns a {#link|union#} type with the properties specified by the arguments.</p>
{#header_close#}
{#header_open|@Enum#}
<pre>{#syntax#}@Enum(
comptime TagInt: type,
comptime mode: std.builtin.Type.Enum.Mode,
comptime field_names: []const []const u8,
comptime field_values: *const [field_names.len]TagInt,
) type{#endsyntax#}</pre>
<p>Returns an {#link|enum#} type with the properties specified by the arguments.</p>
{#header_close#}
{#header_open|@typeInfo#}
<pre>{#syntax#}@typeInfo(comptime T: type) std.builtin.Type{#endsyntax#}</pre>
<p>
@ -6096,7 +6127,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
{#header_close#}
{#header_open|Exact Left Shift Overflow#}
<p>At compile-time:</p>
{#code|test_comptime_shlExact_overwlow.zig#}
{#code|test_comptime_shlExact_overflow.zig#}
<p>At runtime:</p>
{#code|runtime_shlExact_overflow.zig#}
@ -6260,9 +6291,8 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
C has a default allocator - <code>malloc</code>, <code>realloc</code>, and <code>free</code>.
When linking against libc, Zig exposes this allocator with {#syntax#}std.heap.c_allocator{#endsyntax#}.
However, by convention, there is no default allocator in Zig. Instead, functions which need to
allocate accept an {#syntax#}Allocator{#endsyntax#} parameter. Likewise, data structures such as
{#syntax#}std.ArrayList{#endsyntax#} accept an {#syntax#}Allocator{#endsyntax#} parameter in
their initialization functions:
allocate accept an {#syntax#}Allocator{#endsyntax#} parameter. Likewise, some data structures
accept an {#syntax#}Allocator{#endsyntax#} parameter in their initialization functions:
</p>
{#code|test_allocator.zig#}
@ -6289,10 +6319,6 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
</li>
<li>Are you linking libc? In this case, {#syntax#}std.heap.c_allocator{#endsyntax#} is likely
the right choice, at least for your main allocator.</li>
<li>
Need to use the same allocator in multiple threads? Use one of your choice
wrapped around {#syntax#}std.heap.ThreadSafeAllocator{#endsyntax#}
</li>
<li>
Is the maximum number of bytes that you will need bounded by a number known at
{#link|comptime#}? In this case, use {#syntax#}std.heap.FixedBufferAllocator{#endsyntax#}.
@ -6302,7 +6328,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
cyclical pattern (such as a video game main loop, or a web server request handler),
such that it would make sense to free everything at once at the end?
In this case, it is recommended to follow this pattern:
{#code|cli_allocation.zig#}
{#code|cli_allocation.zig#}
When using this kind of allocator, there is no need to free anything manually. Everything
gets freed at once with the call to {#syntax#}arena.deinit(){#endsyntax#}.
@ -6325,14 +6351,18 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
</li>
<li>
Finally, if none of the above apply, you need a general purpose allocator.
Zig's general purpose allocator is available as a function that takes a {#link|comptime#}
{#link|struct#} of configuration options and returns a type.
Generally, you will set up one {#syntax#}std.heap.GeneralPurposeAllocator{#endsyntax#} in
your main function, and then pass it or sub-allocators around to various parts of your
If you are in Debug mode, {#syntax#}std.heap.DebugAllocator{#endsyntax#} is available as a
function that takes a {#link|comptime#} {#link|struct#} of configuration options and returns a type.
Generally, you will set up exactly one in your main function, and
then pass it or sub-allocators around to various parts of your
application.
</li>
<li>
You can also consider {#link|Implementing an Allocator#}.
If you are compiling in ReleaseFast mode, {#syntax#}std.heap.smp_allocator{#endsyntax#} is
a solid choice for a general purpose allocator.
</li>
<li>
You can also consider implementing an allocator.
</li>
</ol>
{#header_close#}
@ -6367,17 +6397,6 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
<p>TODO: thread local variables</p>
{#header_close#}
{#header_open|Implementing an Allocator#}
<p>Zig programmers can implement their own allocators by fulfilling the Allocator interface.
In order to do this one must read carefully the documentation comments in std/mem.zig and
then supply a {#syntax#}allocFn{#endsyntax#} and a {#syntax#}resizeFn{#endsyntax#}.
</p>
<p>
There are many example allocators to look at for inspiration. Look at std/heap.zig and
{#syntax#}std.heap.GeneralPurposeAllocator{#endsyntax#}.
</p>
{#header_close#}
{#header_open|Heap Allocation Failure#}
<p>
Many programming languages choose to handle the possibility of heap allocation failure by
@ -6525,7 +6544,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
</p>
<ul>
<li>If a call to {#syntax#}@import{#endsyntax#} is analyzed, the file being imported is analyzed.</li>
<li>If a type (including a file) is analyzed, all {#syntax#}comptime{#endsyntax#}, {#syntax#}usingnamespace{#endsyntax#}, and {#syntax#}export{#endsyntax#} declarations within it are analyzed.</li>
<li>If a type (including a file) is analyzed, all {#syntax#}comptime{#endsyntax#} and {#syntax#}export{#endsyntax#} declarations within it are analyzed.</li>
<li>If a type (including a file) is analyzed, and the compilation is for a {#link|test|Zig Test#}, and the module the type is within is the root module of the compilation, then all {#syntax#}test{#endsyntax#} declarations within it are also analyzed.</li>
<li>If a reference to a named declaration (i.e. a usage of it) is analyzed, the declaration being referenced is analyzed. Declarations are order-independent, so this reference may be above or below the declaration being referenced, or even in another file entirely.</li>
</ul>
@ -7119,10 +7138,12 @@ coding style.
</p>
<ul>
<li>
If {#syntax#}x{#endsyntax#} is a {#syntax#}type{#endsyntax#}
then {#syntax#}x{#endsyntax#} should be {#syntax#}TitleCase{#endsyntax#}, unless it
is a {#syntax#}struct{#endsyntax#} with 0 fields and is never meant to be instantiated,
in which case it is considered to be a "namespace" and uses {#syntax#}snake_case{#endsyntax#}.
If {#syntax#}x{#endsyntax#} is a {#syntax#}struct{#endsyntax#} with 0 fields and is never meant to be instantiated
then {#syntax#}x{#endsyntax#} is considered to be a "namespace" and should be {#syntax#}snake_case{#endsyntax#}.
</li>
<li>
If {#syntax#}x{#endsyntax#} is a {#syntax#}type{#endsyntax#} or {#syntax#}type{#endsyntax#} alias
then {#syntax#}x{#endsyntax#} should be {#syntax#}TitleCase{#endsyntax#}.
</li>
<li>
If {#syntax#}x{#endsyntax#} is callable, and {#syntax#}x{#endsyntax#}'s return type is
@ -7161,8 +7182,7 @@ const namespace_name = @import("dir_name/file_name.zig");
const TypeName = @import("dir_name/TypeName.zig");
var global_var: i32 = undefined;
const const_name = 42;
const primitive_type_alias = f32;
const string_alias = []u8;
const PrimitiveTypeAlias = f32;
const StructName = struct {
field: i32,
@ -7345,29 +7365,6 @@ fn readU32Be() u32 {}
</ul>
</td>
</tr>
<tr>
<th scope="row">
<pre>{#syntax#}async{#endsyntax#}</pre>
</th>
<td>
{#syntax#}async{#endsyntax#} can be used before a function call to get a pointer to the function's frame when it suspends.
<ul>
<li>See also {#link|Async Functions#}</li>
</ul>
</td>
</tr>
<tr>
<th scope="row">
<pre>{#syntax#}await{#endsyntax#}</pre>
</th>
<td>
{#syntax#}await{#endsyntax#} can be used to suspend the current function until the frame provided after the {#syntax#}await{#endsyntax#} completes.
{#syntax#}await{#endsyntax#} copies the value returned from the target function's frame to the caller.
<ul>
<li>See also {#link|Async Functions#}</li>
</ul>
</td>
</tr>
<tr>
<th scope="row">
<pre>{#syntax#}break{#endsyntax#}</pre>
@ -7785,18 +7782,6 @@ fn readU32Be() u32 {}
</ul>
</td>
</tr>
<tr>
<th scope="row">
<pre>{#syntax#}usingnamespace{#endsyntax#}</pre>
</th>
<td>
{#syntax#}usingnamespace{#endsyntax#} is a top-level declaration that imports all the public declarations of the operand,
which must be a struct, union, or enum, into the current scope.
<ul>
<li>See also {#link|usingnamespace#}</li>
</ul>
</td>
</tr>
<tr>
<th scope="row">
<pre>{#syntax#}var{#endsyntax#}</pre>
@ -7851,11 +7836,11 @@ fn readU32Be() u32 {}
{#header_close#}
{#header_open|Grammar#}
{#syntax_block|peg|grammar.y#}
Root <- skip container_doc_comment? ContainerMembers eof
{#syntax_block|peg|grammar.peg#}
Root <- skip ContainerMembers eof
# *** Top level ***
ContainerMembers <- ContainerDeclaration* (ContainerField COMMA)* (ContainerField / ContainerDeclaration*)
ContainerMembers <- container_doc_comment? ContainerDeclaration* (ContainerField COMMA)* (ContainerField / ContainerDeclaration*)
ContainerDeclaration <- TestDecl / ComptimeDecl / doc_comment? KEYWORD_pub? Decl
@ -7866,7 +7851,6 @@ ComptimeDecl <- KEYWORD_comptime Block
Decl
<- (KEYWORD_export / KEYWORD_extern STRINGLITERALSINGLE? / KEYWORD_inline / KEYWORD_noinline)? FnProto (SEMICOLON / Block)
/ (KEYWORD_export / KEYWORD_extern STRINGLITERALSINGLE?)? KEYWORD_threadlocal? GlobalVarDecl
/ KEYWORD_usingnamespace Expr SEMICOLON
FnProto <- KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? AddrSpace? LinkSection? CallConv? EXCLAMATIONMARK? TypeExpr
@ -7885,7 +7869,6 @@ Statement
/ KEYWORD_errdefer Payload? BlockExprStatement
/ IfStatement
/ LabeledStatement
/ SwitchExpr
/ VarDeclExprStatement
ComptimeStatement
@ -7896,7 +7879,7 @@ IfStatement
<- IfPrefix BlockExpr ( KEYWORD_else Payload? Statement )?
/ IfPrefix AssignExpr ( SEMICOLON / KEYWORD_else Payload? Statement )
LabeledStatement <- BlockLabel? (Block / LoopStatement)
LabeledStatement <- BlockLabel? (Block / LoopStatement / SwitchExpr)
LoopStatement <- KEYWORD_inline? (ForStatement / WhileStatement)
@ -7950,7 +7933,7 @@ PrimaryExpr
/ KEYWORD_break BreakLabel? Expr?
/ KEYWORD_comptime Expr
/ KEYWORD_nosuspend Expr
/ KEYWORD_continue BreakLabel?
/ KEYWORD_continue BreakLabel? Expr?
/ KEYWORD_resume Expr
/ KEYWORD_return Expr?
/ BlockLabel? LoopExpr
@ -7979,8 +7962,7 @@ TypeExpr <- PrefixTypeOp* ErrorUnionExpr
ErrorUnionExpr <- SuffixExpr (EXCLAMATIONMARK TypeExpr)?
SuffixExpr
<- KEYWORD_async PrimaryTypeExpr SuffixOp* FnCallArguments
/ PrimaryTypeExpr (SuffixOp / FnCallArguments)*
<- PrimaryTypeExpr (SuffixOp / FnCallArguments)*
PrimaryTypeExpr
<- BUILTINIDENTIFIER FnCallArguments
@ -8001,7 +7983,6 @@ PrimaryTypeExpr
/ KEYWORD_anyframe
/ KEYWORD_unreachable
/ STRINGLITERAL
/ SwitchExpr
ContainerDecl <- (KEYWORD_extern / KEYWORD_packed)? ContainerDeclAuto
@ -8014,6 +7995,7 @@ IfTypeExpr <- IfPrefix TypeExpr (KEYWORD_else Payload? TypeExpr)?
LabeledTypeExpr
<- BlockLabel Block
/ BlockLabel? LoopTypeExpr
/ BlockLabel? SwitchExpr
LoopTypeExpr <- KEYWORD_inline? (ForTypeExpr / WhileTypeExpr)
@ -8034,7 +8016,7 @@ AsmInput <- COLON AsmInputList AsmClobbers?
AsmInputItem <- LBRACKET IDENTIFIER RBRACKET STRINGLITERAL LPAREN Expr RPAREN
AsmClobbers <- COLON StringList
AsmClobbers <- COLON Expr
# *** Helper grammar ***
BreakLabel <- COLON IDENTIFIER
@ -8156,7 +8138,6 @@ PrefixOp
/ MINUSPERCENT
/ AMPERSAND
/ KEYWORD_try
/ KEYWORD_await
PrefixTypeOp
<- QUESTIONMARK
@ -8184,7 +8165,7 @@ PtrTypeStart
ArrayTypeStart <- LBRACKET Expr (COLON Expr)? RBRACKET
# ContainerDecl specific
ContainerDeclAuto <- ContainerDeclType LBRACE container_doc_comment? ContainerMembers RBRACE
ContainerDeclAuto <- ContainerDeclType LBRACE ContainerMembers RBRACE
ContainerDeclType
<- KEYWORD_struct (LPAREN Expr RPAREN)?
@ -8204,8 +8185,6 @@ AsmOutputList <- (AsmOutputItem COMMA)* AsmOutputItem?
AsmInputList <- (AsmInputItem COMMA)* AsmInputItem?
StringList <- (STRINGLITERAL COMMA)* STRINGLITERAL?
ParamDeclList <- (ParamDecl COMMA)* ParamDecl?
ExprList <- (Expr COMMA)* Expr?
@ -8252,7 +8231,7 @@ oxC2_oxDF <- [\302-\337]
# [0xF1,0xF3] [0x80,0xBF] [0x80,0xBF] [0x80,0xBF]
# 0xF4 [0x80,0x8F] [0x80,0xBF] [0x80,0xBF]
mb_utf8_literal <-
multibyte_utf8 <-
oxF4 ox80_ox8F ox80_oxBF ox80_oxBF
/ oxF1_oxF3 ox80_oxBF ox80_oxBF ox80_oxBF
/ oxF0 ox90_0xBF ox80_oxBF ox80_oxBF
@ -8262,46 +8241,47 @@ mb_utf8_literal <-
/ oxE0 oxA0_oxBF ox80_oxBF
/ oxC2_oxDF ox80_oxBF
ascii_char_not_nl_slash_squote <- [\000-\011\013-\046\050-\133\135-\177]
non_control_ascii <- [\040-\176]
char_escape
<- "\\x" hex hex
/ "\\u{" hex+ "}"
/ "\\" [nr\\t'"]
char_char
<- mb_utf8_literal
<- multibyte_utf8
/ char_escape
/ ascii_char_not_nl_slash_squote
/ ![\\'\n] non_control_ascii
string_char
<- char_escape
/ [^\\"\n]
<- multibyte_utf8
/ char_escape
/ ![\\"\n] non_control_ascii
container_doc_comment <- ('//!' [^\n]* [ \n]* skip)+
doc_comment <- ('///' [^\n]* [ \n]* skip)+
line_comment <- '//' ![!/][^\n]* / '////' [^\n]*
line_string <- ("\\\\" [^\n]* [ \n]*)+
line_string <- ('\\\\' [^\n]* [ \n]*)+
skip <- ([ \n] / line_comment)*
CHAR_LITERAL <- "'" char_char "'" skip
CHAR_LITERAL <- ['] char_char ['] skip
FLOAT
<- "0x" hex_int "." hex_int ([pP] [-+]? dec_int)? skip
/ dec_int "." dec_int ([eE] [-+]? dec_int)? skip
/ "0x" hex_int [pP] [-+]? dec_int skip
<- '0x' hex_int '.' hex_int ([pP] [-+]? dec_int)? skip
/ dec_int '.' dec_int ([eE] [-+]? dec_int)? skip
/ '0x' hex_int [pP] [-+]? dec_int skip
/ dec_int [eE] [-+]? dec_int skip
INTEGER
<- "0b" bin_int skip
/ "0o" oct_int skip
/ "0x" hex_int skip
<- '0b' bin_int skip
/ '0o' oct_int skip
/ '0x' hex_int skip
/ dec_int skip
STRINGLITERALSINGLE <- "\"" string_char* "\"" skip
STRINGLITERALSINGLE <- ["] string_char* ["] skip
STRINGLITERAL
<- STRINGLITERALSINGLE
/ (line_string skip)+
IDENTIFIER
<- !keyword [A-Za-z_] [A-Za-z0-9_]* skip
/ "@" STRINGLITERALSINGLE
BUILTINIDENTIFIER <- "@"[A-Za-z_][A-Za-z0-9_]* skip
/ '@' STRINGLITERALSINGLE
BUILTINIDENTIFIER <- '@'[A-Za-z_][A-Za-z0-9_]* skip
AMPERSAND <- '&' ![=] skip
@ -8377,8 +8357,6 @@ KEYWORD_and <- 'and' end_of_word
KEYWORD_anyframe <- 'anyframe' end_of_word
KEYWORD_anytype <- 'anytype' end_of_word
KEYWORD_asm <- 'asm' end_of_word
KEYWORD_async <- 'async' end_of_word
KEYWORD_await <- 'await' end_of_word
KEYWORD_break <- 'break' end_of_word
KEYWORD_callconv <- 'callconv' end_of_word
KEYWORD_catch <- 'catch' end_of_word
@ -8415,14 +8393,13 @@ KEYWORD_threadlocal <- 'threadlocal' end_of_word
KEYWORD_try <- 'try' end_of_word
KEYWORD_union <- 'union' end_of_word
KEYWORD_unreachable <- 'unreachable' end_of_word
KEYWORD_usingnamespace <- 'usingnamespace' end_of_word
KEYWORD_var <- 'var' end_of_word
KEYWORD_volatile <- 'volatile' end_of_word
KEYWORD_while <- 'while' end_of_word
keyword <- KEYWORD_addrspace / KEYWORD_align / KEYWORD_allowzero / KEYWORD_and
/ KEYWORD_anyframe / KEYWORD_anytype / KEYWORD_asm / KEYWORD_async
/ KEYWORD_await / KEYWORD_break / KEYWORD_callconv / KEYWORD_catch
/ KEYWORD_anyframe / KEYWORD_anytype / KEYWORD_asm
/ KEYWORD_break / KEYWORD_callconv / KEYWORD_catch
/ KEYWORD_comptime / KEYWORD_const / KEYWORD_continue / KEYWORD_defer
/ KEYWORD_else / KEYWORD_enum / KEYWORD_errdefer / KEYWORD_error / KEYWORD_export
/ KEYWORD_extern / KEYWORD_fn / KEYWORD_for / KEYWORD_if
@ -8431,7 +8408,7 @@ keyword <- KEYWORD_addrspace / KEYWORD_align / KEYWORD_allowzero / KEYWORD_and
/ KEYWORD_pub / KEYWORD_resume / KEYWORD_return / KEYWORD_linksection
/ KEYWORD_struct / KEYWORD_suspend / KEYWORD_switch / KEYWORD_test
/ KEYWORD_threadlocal / KEYWORD_try / KEYWORD_union / KEYWORD_unreachable
/ KEYWORD_usingnamespace / KEYWORD_var / KEYWORD_volatile / KEYWORD_while
/ KEYWORD_var / KEYWORD_volatile / KEYWORD_while
{#end_syntax_block#}
{#header_close#}
{#header_open|Zen#}

View File

@ -53,8 +53,7 @@ pub fn syscall1(number: usize, arg1: usize) usize {
// memory locations - not only the memory pointed to by a declared indirect
// output. In this example we list $rcx and $r11 because it is known the
// kernel syscall does not preserve these registers.
: "rcx", "r11"
);
: .{ .rcx = true, .r11 = true });
}
// syntax

View File

@ -17,7 +17,7 @@ pub fn main() !void {
.maximum = 0.20,
};
const category = threshold.categorize(0.90);
try std.io.getStdOut().writeAll(@tagName(category));
try std.fs.File.stdout().writeAll(@tagName(category));
}
const std = @import("std");

View File

@ -4,8 +4,10 @@ pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "example",
.root_source_file = b.path("example.zig"),
.optimize = optimize,
.root_module = b.createModule(.{
.root_source_file = b.path("example.zig"),
.optimize = optimize,
}),
});
b.default_step.dependOn(&exe.step);
}

View File

@ -1,17 +1,22 @@
const std = @import("std");
pub fn build(b: *std.Build) void {
const lib = b.addSharedLibrary(.{
const lib = b.addLibrary(.{
.linkage = .dynamic,
.name = "mathtest",
.root_source_file = b.path("mathtest.zig"),
.root_module = b.createModule(.{
.root_source_file = b.path("mathtest.zig"),
}),
.version = .{ .major = 1, .minor = 0, .patch = 0 },
});
const exe = b.addExecutable(.{
.name = "test",
.root_module = b.createModule(.{
.link_libc = true,
}),
});
exe.addCSourceFile(.{ .file = b.path("test.c"), .flags = &.{"-std=c99"} });
exe.linkLibrary(lib);
exe.linkSystemLibrary("c");
exe.root_module.addCSourceFile(.{ .file = b.path("test.c"), .flags = &.{"-std=c99"} });
exe.root_module.linkLibrary(lib);
b.default_step.dependOn(&exe.step);

View File

@ -3,15 +3,19 @@ const std = @import("std");
pub fn build(b: *std.Build) void {
const obj = b.addObject(.{
.name = "base64",
.root_source_file = b.path("base64.zig"),
.root_module = b.createModule(.{
.root_source_file = b.path("base64.zig"),
}),
});
const exe = b.addExecutable(.{
.name = "test",
.root_module = b.createModule(.{
.link_libc = true,
}),
});
exe.addCSourceFile(.{ .file = b.path("test.c"), .flags = &.{"-std=c99"} });
exe.addObject(obj);
exe.linkSystemLibrary("c");
exe.root_module.addCSourceFile(.{ .file = b.path("test.c"), .flags = &.{"-std=c99"} });
exe.root_module.addObject(obj);
b.installArtifact(exe);
}

View File

@ -1,8 +1,7 @@
const std = @import("std");
const expect = std.testing.expect;
const print = std.debug.print;
test "defer unwinding" {
pub fn main() void {
print("\n", .{});
defer {
@ -19,4 +18,4 @@ test "defer unwinding" {
}
}
// test
// exe=succeed

View File

@ -15,8 +15,8 @@ pub fn main() void {
break :blk .{ min, max };
};
print("min = {}", .{ min });
print("max = {}", .{ max });
print("min = {}\n", .{ min });
print("max = {}\n", .{ max });
}
// exe=succeed

View File

@ -2,6 +2,6 @@ comptime {
@export(&internalName, .{ .name = "foo", .linkage = .strong });
}
fn internalName() callconv(.C) void {}
fn internalName() callconv(.c) void {}
// obj

View File

@ -1,8 +1,7 @@
const std = @import("std");
pub fn main() !void {
const stdout = std.io.getStdOut().writer();
try stdout.print("Hello, {s}!\n", .{"world"});
try std.fs.File.stdout().writeAll("Hello, World!\n");
}
// exe=succeed

View File

@ -1,7 +1,7 @@
const std = @import("std");
pub fn main() void {
std.debug.print("Hello, world!\n", .{});
std.debug.print("Hello, {s}!\n", .{"World"});
}
// exe=succeed

View File

@ -15,8 +15,7 @@ pub fn syscall1(number: usize, arg1: usize) usize {
: [ret] "={rax}" (-> usize),
: [number] "{rax}" (number),
[arg1] "{rdi}" (arg1),
: "rcx", "r11"
);
: .{ .rcx = true, .r11 = true });
}
pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
@ -26,8 +25,7 @@ pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
[arg1] "{rdi}" (arg1),
[arg2] "{rsi}" (arg2),
[arg3] "{rdx}" (arg3),
: "rcx", "r11"
);
: .{ .rcx = true, .r11 = true });
}
// exe=succeed

View File

@ -1,11 +1,14 @@
test "inline function call" {
const std = @import("std");
pub fn main() void {
if (foo(1200, 34) != 1234) {
@compileError("bad");
}
}
inline fn foo(a: i32, b: i32) i32 {
std.debug.print("runtime a = {} b = {}", .{ a, b });
return a + b;
}
// test
// exe=succeed

View File

@ -0,0 +1,19 @@
pub const GpioRegister = packed struct(u8) {
GPIO0: bool,
GPIO1: bool,
GPIO2: bool,
GPIO3: bool,
reserved: u4 = 0,
};
const gpio: *volatile GpioRegister = @ptrFromInt(0x0123);
pub fn writeToGpio(new_states: GpioRegister) void {
// Example of what not to do:
// BAD! gpio.GPIO0 = true; BAD!
// Instead, do this:
gpio.* = new_states;
}
// syntax

View File

@ -1,3 +1,4 @@
const builtin = @import("builtin");
const std = @import("std");
pub fn main() void {
@ -5,6 +6,8 @@ pub fn main() void {
_ = &x;
const y = @shrExact(x, 2);
std.debug.print("value: {}\n", .{y});
if ((builtin.cpu.arch.isRISCV() or builtin.cpu.arch.isLoongArch() or builtin.cpu.arch == .s390x) and builtin.zig_backend == .stage2_llvm) @panic("https://github.com/ziglang/zig/issues/24304");
}
// exe=fail

View File

@ -11,7 +11,7 @@ pub const std_options: std.Options = .{
fn myLogFn(
comptime level: std.log.Level,
comptime scope: @Type(.enum_literal),
comptime scope: @EnumLiteral(),
comptime format: []const u8,
args: anytype,
) void {

View File

@ -67,4 +67,11 @@ test "*T to *[1]T" {
try expect(z[0] == 1234);
}
// Sentinel-terminated slices can be coerced into sentinel-terminated pointers
test "[:x]T to [*:x]T" {
const buf: [:0]const u8 = "hello";
const buf2: [*:0]const u8 = buf;
try expect(buf2[4] == 'o');
}
// test

View File

@ -41,7 +41,7 @@ test "coercion between unions and enums" {
try expect(u_4.tag() == 1);
// The following example is invalid.
// error: coercion from enum '@TypeOf(.enum_literal)' to union 'test_coerce_unions_enum.U2' must initialize 'f32' field 'b'
// error: coercion from enum '@EnumLiteral()' to union 'test_coerce_unions_enum.U2' must initialize 'f32' field 'b'
//var u_5: U2 = .b;
//try expect(u_5.tag() == 2);
}

View File

@ -0,0 +1,6 @@
comptime {
const x = @shlExact(@as(u8, 0b01010101), 2);
_ = x;
}
// test_error=overflow of integer type 'u8' with value '340'

View File

@ -1,6 +0,0 @@
comptime {
const x = @shlExact(@as(u8, 0b01010101), 2);
_ = x;
}
// test_error=operation caused overflow

View File

@ -2,7 +2,7 @@ const std = @import("std");
const testing = std.testing;
const builtin = @import("builtin");
fn add(count: c_int, ...) callconv(.C) c_int {
fn add(count: c_int, ...) callconv(.c) c_int {
var ap = @cVaStart();
defer @cVaEnd(&ap);
var i: usize = 0;
@ -22,6 +22,10 @@ test "defining a variadic function" {
// https://github.com/ziglang/zig/issues/16961
return error.SkipZigTest;
}
if (builtin.cpu.arch == .s390x) {
// https://github.com/ziglang/zig/issues/21350#issuecomment-3543006475
return error.SkipZigTest;
}
try std.testing.expectEqual(@as(c_int, 0), add(0));
try std.testing.expectEqual(@as(c_int, 1), add(1, @as(c_int, 1)));

View File

@ -23,8 +23,7 @@ export fn sub(a: i8, b: i8) i8 {
// dynamically. The quoted identifier after the extern keyword specifies
// the library that has the function. (e.g. "c" -> libc.so)
// The callconv specifier changes the calling convention of the function.
const WINAPI: std.builtin.CallingConvention = if (native_arch == .x86) .Stdcall else .C;
extern "kernel32" fn ExitProcess(exit_code: u32) callconv(WINAPI) noreturn;
extern "kernel32" fn ExitProcess(exit_code: u32) callconv(.winapi) noreturn;
extern "c" fn atan2(a: f64, b: f64) f64;
// The @branchHint builtin can be used to tell the optimizer that a function is rarely called ("cold").
@ -35,7 +34,7 @@ fn abort() noreturn {
// The naked calling convention makes a function not have any function prologue or epilogue.
// This can be useful when integrating with assembly.
fn _start() callconv(.Naked) noreturn {
fn _start() callconv(.naked) noreturn {
abort();
}

View File

@ -19,3 +19,4 @@ test "global assembly" {
// test
// target=x86_64-linux
// llvm=true

View File

@ -5,4 +5,4 @@ test "integer cast panic" {
_ = b;
}
// test_error=cast truncated bits
// test_error=integer does not fit in destination type

View File

@ -1,18 +1,22 @@
const std = @import("std");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
const mat4x4 = [4][4]f32{
[_]f32{ 1.0, 0.0, 0.0, 0.0 },
[_]f32{ 0.0, 1.0, 0.0, 1.0 },
[_]f32{ 0.0, 0.0, 1.0, 0.0 },
[_]f32{ 0.0, 0.0, 0.0, 1.0 },
const mat4x5 = [4][5]f32{
[_]f32{ 1.0, 0.0, 0.0, 0.0, 0.0 },
[_]f32{ 0.0, 1.0, 0.0, 1.0, 0.0 },
[_]f32{ 0.0, 0.0, 1.0, 0.0, 0.0 },
[_]f32{ 0.0, 0.0, 0.0, 1.0, 9.9 },
};
test "multidimensional arrays" {
// mat4x5 itself is a one-dimensional array of arrays.
try expectEqual(mat4x5[1], [_]f32{ 0.0, 1.0, 0.0, 1.0, 0.0 });
// Access the 2D array by indexing the outer array, and then the inner array.
try expect(mat4x4[1][1] == 1.0);
try expect(mat4x5[3][4] == 9.9);
// Here we iterate with for loops.
for (mat4x4, 0..) |row, row_index| {
for (mat4x5, 0..) |row, row_index| {
for (row, 0..) |cell, column_index| {
if (row_index == column_index) {
try expect(cell == 1.0);
@ -20,8 +24,8 @@ test "multidimensional arrays" {
}
}
// initialize a multidimensional array to zeros
const all_zero: [4][4]f32 = .{.{0} ** 4} ** 4;
// Initialize a multidimensional array to zeros.
const all_zero: [4][5]f32 = .{.{0} ** 5} ** 4;
try expect(all_zero[0][0] == 0);
}

View File

@ -3,7 +3,7 @@ const builtin = @import("builtin");
const native_arch = builtin.cpu.arch;
const expect = std.testing.expect;
const WINAPI: std.builtin.CallingConvention = if (native_arch == .x86) .Stdcall else .C;
const WINAPI: std.builtin.CallingConvention = if (native_arch == .x86) .{ .x86_stdcall = .{} } else .c;
extern "kernel32" fn ExitProcess(exit_code: c_uint) callconv(WINAPI) noreturn;
test "foo" {

View File

@ -2,7 +2,7 @@ const Derp = opaque {};
const Wat = opaque {};
extern fn bar(d: *Derp) void;
fn foo(w: *Wat) callconv(.C) void {
fn foo(w: *Wat) callconv(.c) void {
bar(w);
}

View File

@ -8,7 +8,7 @@ const S = packed struct {
test "overaligned pointer to packed struct" {
var foo: S align(4) = .{ .a = 1, .b = 2 };
const ptr: *align(4) S = &foo;
const ptr_to_b: *u32 = &ptr.b;
const ptr_to_b = &ptr.b;
try expect(ptr_to_b.* == 2);
}

View File

@ -7,4 +7,10 @@ test "vector @splat" {
try expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 }));
}
test "array @splat" {
const scalar: u32 = 5;
const result: [4]u32 = @splat(scalar);
try expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 }));
}
// test

View File

@ -8,20 +8,22 @@ const Instruction = enum {
};
fn evaluate(initial_stack: []const i32, code: []const Instruction) !i32 {
var stack = try std.BoundedArray(i32, 8).fromSlice(initial_stack);
var buffer: [8]i32 = undefined;
var stack = std.ArrayList(i32).initBuffer(&buffer);
try stack.appendSliceBounded(initial_stack);
var ip: usize = 0;
return vm: switch (code[ip]) {
// Because all code after `continue` is unreachable, this branch does
// not provide a result.
.add => {
try stack.append(stack.pop().? + stack.pop().?);
try stack.appendBounded(stack.pop().? + stack.pop().?);
ip += 1;
continue :vm code[ip];
},
.mul => {
try stack.append(stack.pop().? * stack.pop().?);
try stack.appendBounded(stack.pop().? * stack.pop().?);
ip += 1;
continue :vm code[ip];

View File

@ -0,0 +1,17 @@
const std = @import("std");
const expect = std.testing.expect;
const Tagged = union(enum(u32)) {
int: i64 = 123,
boolean: bool = 67,
};
test "tag values" {
const int: Tagged = .{ .int = -40 };
try expect(@intFromEnum(int) == 123);
const boolean: Tagged = .{ .boolean = false };
try expect(@intFromEnum(boolean) == 67);
}
// test

View File

@ -1,8 +0,0 @@
test "using std namespace" {
const S = struct {
usingnamespace @import("std");
};
try S.testing.expect(true);
}
// test

View File

@ -17,7 +17,7 @@ test "Basic vector usage" {
}
test "Conversion between vectors, arrays, and slices" {
// Vectors and fixed-length arrays can be automatically assigned back and forth
// Vectors can be coerced to arrays, and vice versa.
const arr1: [4]f32 = [_]f32{ 1.1, 3.2, 4.5, 5.6 };
const vec: @Vector(4, f32) = arr1;
const arr2: [4]f32 = vec;

View File

@ -1,9 +1,10 @@
const std = @import("std");
test "detect leak" {
var list = std.ArrayList(u21).init(std.testing.allocator);
// missing `defer list.deinit();`
try list.append('☔');
const gpa = std.testing.allocator;
var list: std.ArrayList(u21) = .empty;
// missing `defer list.deinit(gpa);`
try list.append(gpa, '☔');
try std.testing.expect(list.items.len == 1);
}

View File

@ -4,6 +4,11 @@ const std = @import("std");
const os = std.os;
const assert = std.debug.assert;
// Custom error set definition:
const ExampleErrorSet = error{
ExampleErrorVariant,
};
pub fn main() void {
// integers
const one_plus_one: i32 = 1 + 1;
@ -36,7 +41,7 @@ pub fn main() void {
});
// error union
var number_or_error: anyerror!i32 = error.ArgNotFound;
var number_or_error: ExampleErrorSet!i32 = ExampleErrorSet.ExampleErrorVariant;
print("\nerror union 1\ntype: {}\nvalue: {!}\n", .{
@TypeOf(number_or_error),

378
lib/build-web/fuzz.zig Normal file
View File

@ -0,0 +1,378 @@
// Server timestamp.
var start_fuzzing_timestamp: i64 = undefined;
const js = struct {
extern "fuzz" fn requestSources() void;
extern "fuzz" fn ready() void;
extern "fuzz" fn updateStats(html_ptr: [*]const u8, html_len: usize) void;
extern "fuzz" fn updateEntryPoints(html_ptr: [*]const u8, html_len: usize) void;
extern "fuzz" fn updateSource(html_ptr: [*]const u8, html_len: usize) void;
extern "fuzz" fn updateCoverage(covered_ptr: [*]const SourceLocationIndex, covered_len: u32) void;
};
pub fn sourceIndexMessage(msg_bytes: []u8) error{OutOfMemory}!void {
Walk.files.clearRetainingCapacity();
Walk.decls.clearRetainingCapacity();
Walk.modules.clearRetainingCapacity();
recent_coverage_update.clearRetainingCapacity();
selected_source_location = null;
js.requestSources();
const Header = abi.fuzz.SourceIndexHeader;
const header: Header = @bitCast(msg_bytes[0..@sizeOf(Header)].*);
const directories_start = @sizeOf(Header);
const directories_end = directories_start + header.directories_len * @sizeOf(Coverage.String);
const files_start = directories_end;
const files_end = files_start + header.files_len * @sizeOf(Coverage.File);
const source_locations_start = files_end;
const source_locations_end = source_locations_start + header.source_locations_len * @sizeOf(Coverage.SourceLocation);
const string_bytes = msg_bytes[source_locations_end..][0..header.string_bytes_len];
const directories: []const Coverage.String = @alignCast(std.mem.bytesAsSlice(Coverage.String, msg_bytes[directories_start..directories_end]));
const files: []const Coverage.File = @alignCast(std.mem.bytesAsSlice(Coverage.File, msg_bytes[files_start..files_end]));
const source_locations: []const Coverage.SourceLocation = @alignCast(std.mem.bytesAsSlice(Coverage.SourceLocation, msg_bytes[source_locations_start..source_locations_end]));
start_fuzzing_timestamp = header.start_timestamp;
try updateCoverageSources(directories, files, source_locations, string_bytes);
js.ready();
}
var coverage = Coverage.init;
/// Index of type `SourceLocationIndex`.
var coverage_source_locations: std.ArrayList(Coverage.SourceLocation) = .empty;
/// Contains the most recent coverage update message, unmodified.
var recent_coverage_update: std.ArrayListAlignedUnmanaged(u8, .of(u64)) = .empty;
fn updateCoverageSources(
directories: []const Coverage.String,
files: []const Coverage.File,
source_locations: []const Coverage.SourceLocation,
string_bytes: []const u8,
) !void {
coverage.directories.clearRetainingCapacity();
coverage.files.clearRetainingCapacity();
coverage.string_bytes.clearRetainingCapacity();
coverage_source_locations.clearRetainingCapacity();
try coverage_source_locations.appendSlice(gpa, source_locations);
try coverage.string_bytes.appendSlice(gpa, string_bytes);
try coverage.files.entries.resize(gpa, files.len);
@memcpy(coverage.files.entries.items(.key), files);
try coverage.files.reIndexContext(gpa, .{ .string_bytes = coverage.string_bytes.items });
try coverage.directories.entries.resize(gpa, directories.len);
@memcpy(coverage.directories.entries.items(.key), directories);
try coverage.directories.reIndexContext(gpa, .{ .string_bytes = coverage.string_bytes.items });
}
pub fn coverageUpdateMessage(msg_bytes: []u8) error{OutOfMemory}!void {
recent_coverage_update.clearRetainingCapacity();
recent_coverage_update.appendSlice(gpa, msg_bytes) catch @panic("OOM");
try updateStats();
try updateCoverage();
}
var entry_points: std.ArrayList(SourceLocationIndex) = .empty;
pub fn entryPointsMessage(msg_bytes: []u8) error{OutOfMemory}!void {
const header: abi.fuzz.EntryPointHeader = @bitCast(msg_bytes[0..@sizeOf(abi.fuzz.EntryPointHeader)].*);
const slis: []align(1) const SourceLocationIndex = @ptrCast(msg_bytes[@sizeOf(abi.fuzz.EntryPointHeader)..]);
assert(slis.len == header.locsLen());
try entry_points.resize(gpa, slis.len);
@memcpy(entry_points.items, slis);
try updateEntryPoints();
}
/// Index into `coverage_source_locations`.
const SourceLocationIndex = enum(u32) {
_,
fn haveCoverage(sli: SourceLocationIndex) bool {
return @intFromEnum(sli) < coverage_source_locations.items.len;
}
fn ptr(sli: SourceLocationIndex) *Coverage.SourceLocation {
return &coverage_source_locations.items[@intFromEnum(sli)];
}
fn sourceLocationLinkHtml(
sli: SourceLocationIndex,
out: *std.ArrayList(u8),
focused: bool,
) error{OutOfMemory}!void {
const sl = sli.ptr();
try out.print(gpa, "<code{s}>", .{
@as([]const u8, if (focused) " class=\"status-running\"" else ""),
});
try sli.appendPath(out);
try out.print(gpa, ":{d}:{d} </code><button class=\"linkish\" onclick=\"wasm_exports.fuzzSelectSli({d});\">View</button>", .{
sl.line,
sl.column,
@intFromEnum(sli),
});
}
fn appendPath(sli: SourceLocationIndex, out: *std.ArrayList(u8)) error{OutOfMemory}!void {
const sl = sli.ptr();
const file = coverage.fileAt(sl.file);
const file_name = coverage.stringAt(file.basename);
const dir_name = coverage.stringAt(coverage.directories.keys()[file.directory_index]);
try html_render.appendEscaped(out, dir_name);
try out.appendSlice(gpa, "/");
try html_render.appendEscaped(out, file_name);
}
fn toWalkFile(sli: SourceLocationIndex) ?Walk.File.Index {
var buf: std.ArrayList(u8) = .empty;
defer buf.deinit(gpa);
sli.appendPath(&buf) catch @panic("OOM");
return @enumFromInt(Walk.files.getIndex(buf.items) orelse return null);
}
fn fileHtml(
sli: SourceLocationIndex,
out: *std.ArrayList(u8),
) error{ OutOfMemory, SourceUnavailable }!void {
const walk_file_index = sli.toWalkFile() orelse return error.SourceUnavailable;
const root_node = walk_file_index.findRootDecl().get().ast_node;
var annotations: std.ArrayList(html_render.Annotation) = .empty;
defer annotations.deinit(gpa);
try computeSourceAnnotations(sli.ptr().file, walk_file_index, &annotations, coverage_source_locations.items);
html_render.fileSourceHtml(walk_file_index, out, root_node, .{
.source_location_annotations = annotations.items,
}) catch |err| {
fatal("unable to render source: {s}", .{@errorName(err)});
};
}
};
fn computeSourceAnnotations(
cov_file_index: Coverage.File.Index,
walk_file_index: Walk.File.Index,
annotations: *std.ArrayList(html_render.Annotation),
source_locations: []const Coverage.SourceLocation,
) !void {
// Collect all the source locations from only this file into this array
// first, then sort by line, col, so that we can collect annotations with
// O(N) time complexity.
var locs: std.ArrayList(SourceLocationIndex) = .empty;
defer locs.deinit(gpa);
for (source_locations, 0..) |sl, sli_usize| {
if (sl.file != cov_file_index) continue;
const sli: SourceLocationIndex = @enumFromInt(sli_usize);
try locs.append(gpa, sli);
}
std.mem.sortUnstable(SourceLocationIndex, locs.items, {}, struct {
pub fn lessThan(context: void, lhs: SourceLocationIndex, rhs: SourceLocationIndex) bool {
_ = context;
const lhs_ptr = lhs.ptr();
const rhs_ptr = rhs.ptr();
if (lhs_ptr.line < rhs_ptr.line) return true;
if (lhs_ptr.line > rhs_ptr.line) return false;
return lhs_ptr.column < rhs_ptr.column;
}
}.lessThan);
const source = walk_file_index.get_ast().source;
var line: usize = 1;
var column: usize = 1;
var next_loc_index: usize = 0;
for (source, 0..) |byte, offset| {
if (byte == '\n') {
line += 1;
column = 1;
} else {
column += 1;
}
while (true) {
if (next_loc_index >= locs.items.len) return;
const next_sli = locs.items[next_loc_index];
const next_sl = next_sli.ptr();
if (next_sl.line > line or (next_sl.line == line and next_sl.column >= column)) break;
try annotations.append(gpa, .{
.file_byte_offset = offset,
.dom_id = @intFromEnum(next_sli),
});
next_loc_index += 1;
}
}
}
export fn fuzzUnpackSources(tar_ptr: [*]u8, tar_len: usize) void {
const tar_bytes = tar_ptr[0..tar_len];
log.debug("received {d} bytes of sources.tar", .{tar_bytes.len});
unpackSourcesInner(tar_bytes) catch |err| {
fatal("unable to unpack sources.tar: {s}", .{@errorName(err)});
};
}
fn unpackSourcesInner(tar_bytes: []u8) !void {
var tar_reader: std.Io.Reader = .fixed(tar_bytes);
var file_name_buffer: [1024]u8 = undefined;
var link_name_buffer: [1024]u8 = undefined;
var it: std.tar.Iterator = .init(&tar_reader, .{
.file_name_buffer = &file_name_buffer,
.link_name_buffer = &link_name_buffer,
});
while (try it.next()) |tar_file| {
switch (tar_file.kind) {
.file => {
if (tar_file.size == 0 and tar_file.name.len == 0) break;
if (std.mem.endsWith(u8, tar_file.name, ".zig")) {
log.debug("found file: '{s}'", .{tar_file.name});
const file_name = try gpa.dupe(u8, tar_file.name);
// This is a hack to guess modules from the tar file contents. To handle modules
// properly, the build system will need to change the structure here to have one
// directory per module. This in turn requires compiler enhancements to allow
// the build system to actually discover the required information.
const mod_name, const is_module_root = p: {
if (std.mem.find(u8, file_name, "std/")) |i| break :p .{ "std", std.mem.eql(u8, file_name[i + 4 ..], "std.zig") };
if (std.mem.endsWith(u8, file_name, "/builtin.zig")) break :p .{ "builtin", true };
break :p .{ "root", std.mem.endsWith(u8, file_name, "/root.zig") };
};
const gop = try Walk.modules.getOrPut(gpa, mod_name);
const file: Walk.File.Index = @enumFromInt(Walk.files.entries.len);
if (!gop.found_existing or is_module_root) gop.value_ptr.* = file;
const file_bytes = tar_reader.take(@intCast(tar_file.size)) catch unreachable;
it.unread_file_bytes = 0; // we have read the whole thing
assert(file == try Walk.add_file(file_name, file_bytes));
} else {
log.warn("skipping: '{s}' - the tar creation should have done that", .{tar_file.name});
}
},
else => continue,
}
}
}
fn updateStats() error{OutOfMemory}!void {
@setFloatMode(.optimized);
if (recent_coverage_update.items.len == 0) return;
const hdr: *abi.fuzz.CoverageUpdateHeader = @ptrCast(@alignCast(
recent_coverage_update.items[0..@sizeOf(abi.fuzz.CoverageUpdateHeader)],
));
const covered_src_locs: usize = n: {
var n: usize = 0;
const covered_bits = recent_coverage_update.items[@sizeOf(abi.fuzz.CoverageUpdateHeader)..];
for (covered_bits) |byte| n += @popCount(byte);
break :n n;
};
const total_src_locs = coverage_source_locations.items.len;
const avg_speed: f64 = speed: {
const ns_elapsed: f64 = @floatFromInt(nsSince(start_fuzzing_timestamp));
const n_runs: f64 = @floatFromInt(hdr.n_runs);
break :speed n_runs / (ns_elapsed / std.time.ns_per_s);
};
const html = try std.fmt.allocPrint(gpa,
\\<span slot="stat-total-runs">{d}</span>
\\<span slot="stat-unique-runs">{d} ({d:.1}%)</span>
\\<span slot="stat-coverage">{d} / {d} ({d:.1}%)</span>
\\<span slot="stat-speed">{d:.0}</span>
, .{
hdr.n_runs,
hdr.unique_runs,
@as(f64, @floatFromInt(hdr.unique_runs)) / @as(f64, @floatFromInt(hdr.n_runs)),
covered_src_locs,
total_src_locs,
@as(f64, @floatFromInt(covered_src_locs)) / @as(f64, @floatFromInt(total_src_locs)),
avg_speed,
});
defer gpa.free(html);
js.updateStats(html.ptr, html.len);
}
fn updateEntryPoints() error{OutOfMemory}!void {
var html: std.ArrayList(u8) = .empty;
defer html.deinit(gpa);
for (entry_points.items) |sli| {
try html.appendSlice(gpa, "<li>");
try sli.sourceLocationLinkHtml(&html, selected_source_location == sli);
try html.appendSlice(gpa, "</li>\n");
}
js.updateEntryPoints(html.items.ptr, html.items.len);
}
fn updateCoverage() error{OutOfMemory}!void {
if (recent_coverage_update.items.len == 0) return;
const want_file = (selected_source_location orelse return).ptr().file;
var covered: std.ArrayList(SourceLocationIndex) = .empty;
defer covered.deinit(gpa);
// This code assumes 64-bit elements, which is incorrect if the executable
// being fuzzed is not a 64-bit CPU. It also assumes little-endian which
// can also be incorrect.
comptime assert(abi.fuzz.CoverageUpdateHeader.trailing[0] == .pc_bits_usize);
const n_bitset_elems = (coverage_source_locations.items.len + @bitSizeOf(u64) - 1) / @bitSizeOf(u64);
const covered_bits = std.mem.bytesAsSlice(
u64,
recent_coverage_update.items[@sizeOf(abi.fuzz.CoverageUpdateHeader)..][0 .. n_bitset_elems * @sizeOf(u64)],
);
var sli: SourceLocationIndex = @enumFromInt(0);
for (covered_bits) |elem| {
try covered.ensureUnusedCapacity(gpa, 64);
for (0..@bitSizeOf(u64)) |i| {
if ((elem & (@as(u64, 1) << @intCast(i))) != 0) {
if (sli.ptr().file == want_file) {
covered.appendAssumeCapacity(sli);
}
}
sli = @enumFromInt(@intFromEnum(sli) + 1);
}
}
js.updateCoverage(covered.items.ptr, covered.items.len);
}
fn updateSource() error{OutOfMemory}!void {
if (recent_coverage_update.items.len == 0) return;
const file_sli = selected_source_location.?;
var html: std.ArrayList(u8) = .empty;
defer html.deinit(gpa);
file_sli.fileHtml(&html) catch |err| switch (err) {
error.OutOfMemory => |e| return e,
error.SourceUnavailable => {},
};
js.updateSource(html.items.ptr, html.items.len);
}
var selected_source_location: ?SourceLocationIndex = null;
/// This function is not used directly by `main.js`, but a reference to it is
/// emitted by `SourceLocationIndex.sourceLocationLinkHtml`.
export fn fuzzSelectSli(sli: SourceLocationIndex) void {
if (!sli.haveCoverage()) return;
selected_source_location = sli;
updateEntryPoints() catch @panic("out of memory"); // highlights the selected one green
updateSource() catch @panic("out of memory");
updateCoverage() catch @panic("out of memory");
}
const std = @import("std");
const Allocator = std.mem.Allocator;
const Coverage = std.debug.Coverage;
const abi = std.Build.abi;
const assert = std.debug.assert;
const gpa = std.heap.wasm_allocator;
const Walk = @import("Walk");
const html_render = @import("html_render");
const nsSince = @import("main.zig").nsSince;
const Slice = @import("main.zig").Slice;
const fatal = @import("main.zig").fatal;
const log = std.log;
const String = Slice(u8);

217
lib/build-web/index.html Normal file
View File

@ -0,0 +1,217 @@
<!doctype html>
<meta charset="utf-8">
<title>Zig Build System</title>
<link rel="stylesheet" href="style.css">
<!-- Highly compressed 32x32 Zig logo -->
<link rel="icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAABSklEQVRYw8WWXbLDIAiFP5xuURYpi+Q+VDvJTYxaY8pLJ52EA5zDj/AD8wRABCw8DeyJBDiAKMiDGaecNYCKYgCvh4EBjPgGh0UVqAB/MEU3D57efDRMiRhWddprCljRAECPCE0Uw4iz4Jn3tP2zFYAB6on4/8NBM1Es+9kl0aKgaMRnwHPpT5MIDb6YzLzp57wNIyIC7iCCdijeL3gv78jZe6cVENn/drRbXbxl4lXSmB3FtbY0iNrjIEwMm6u2VFFjWQCN0qtov6+wANxG/IV7eR8DHw6gzft4NuEXvA8HcDfv31SgyvsMeDUA90/WTd47bsCdv8PUrWzDyw02uIYv13ktgOVr+IqCouila7gWgNYuly/BfVSEdsP5Vdqyiz7pPC40C+p2e21bL5/dByGtAD6eZPuzeznwjoIN748BfyqwmVDyJHCxPwLSkjUkraEXAAAAAElFTkSuQmCC">
<!-- Templates, to be cloned into shadow DOMs by JavaScript -->
<template id="timeReportEntryTemplate">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="time_report.css">
<details>
<summary><slot name="step-name"></slot></summary>
<div id="genericReport">
<div class="stats">
Time: <slot name="stat-total-time"></slot><br>
</div>
</div>
<div id="compileReport">
<div class="stats">
Files Discovered: <slot name="stat-reachable-files"></slot><br>
Files Analyzed: <slot name="stat-imported-files"></slot><br>
Generic Instances Analyzed: <slot name="stat-generic-instances"></slot><br>
Inline Calls Analyzed: <slot name="stat-inline-calls"></slot><br>
Compilation Time: <slot name="stat-compilation-time"></slot><br>
</div>
<table class="time-stats">
<thead>
<tr>
<th scope="col">Pipeline Component</th>
<th scope="col" class="tooltip">CPU Time
<span class="tooltip-content">Sum across all threads of the time spent in this pipeline component</span>
</th>
<th scope="col" class="tooltip">Real Time
<span class="tooltip-content">Wall-clock time elapsed between the start and end of this compilation phase</span>
</th>
<th scope="col">Compilation Phase</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row" class="tooltip">Parsing
<span class="tooltip-content"><code>tokenize</code> converts a file of Zig source code into a sequence of tokens, which are then processed by <code>Parse</code> into an Abstract Syntax Tree (AST).</span>
</th>
<td><slot name="cpu-time-parse"></slot></td>
<td rowspan="2"><slot name="real-time-files"></slot></td>
<th scope="row" rowspan="2" class="tooltip">File Lower
<span class="tooltip-content">Tokenization, parsing, and lowering of Zig source files to a high-level IR.<br><br>Starting from module roots, every file theoretically accessible through a chain of <code>@import</code> calls is processed. Individual source files are processed serially, but different files are processed in parallel by a thread pool.<br><br>The results of this phase of compilation are cached on disk per source file, meaning the time spent here is typically only relevant to "clean" builds.</span>
</th>
</tr>
<tr>
<th scope="row" class="tooltip">AST Lowering
<span class="tooltip-content"><code>AstGen</code> converts a file's AST into a high-level SSA IR named Zig Intermediate Representation (ZIR). The resulting ZIR code is cached on disk to avoid, for instance, re-lowering all source files in the Zig standard library each time the compiler is invoked.</span>
</th>
<td><slot name="cpu-time-astgen"></slot></td>
</tr>
<tr>
<th scope="row" class="tooltip">Semantic Analysis
<span class="tooltip-content"><code>Sema</code> interprets ZIR to perform type checking, compile-time code execution, and type resolution, collectively termed "semantic analysis". When a runtime function body is analyzed, it emits Analyzed Intermediate Representation (AIR) code to be sent to the next pipeline component. Semantic analysis is currently entirely single-threaded.</span>
</th>
<td><slot name="cpu-time-sema"></slot></td>
<td rowspan="3"><slot name="real-time-decls"></slot></td>
<th scope="row" rowspan="3" class="tooltip">Declaration Lower
<span class="tooltip-content">Semantic analysis, code generation, and linking, at the granularity of individual declarations (as opposed to whole source files).<br><br>These components are run in parallel with one another. Semantic analysis is almost always the bottleneck, as it is complex and currently can only run single-threaded.<br><br>This phase completes when a work queue empties, but semantic analysis may add work by one declaration referencing another.<br><br>This is the main phase of compilation, typically taking significantly longer than File Lower (even in a clean build).</span>
</th>
</tr>
<tr>
<th scope="row" class="tooltip">Code Generation
<span class="tooltip-content"><code>CodeGen</code> converts AIR from <code>Sema</code> into machine instructions in the form of Machine Intermediate Representation (MIR). This work is usually highly parallel, since in most cases, arbitrarily many functions can be run through <code>CodeGen</code> simultaneously.</span>
</th>
<td><slot name="cpu-time-codegen"></slot></td>
</tr>
<tr>
<th scope="row" class="tooltip">Linking
<span class="tooltip-content"><code>link</code> converts MIR from <code>CodeGen</code>, as well as global constants and variables from <code>Sema</code>, and places them in the output binary. MIR is converted to a finished sequence of real instruction bytes.<br><br>When using the LLVM backend, most of this work is instead deferred to the "LLVM Emit" phase.</span>
</th>
<td><slot name="cpu-time-link"></slot></td>
</tr>
<tr class="llvm-only">
<th class="empty-cell"></th>
<td class="empty-cell"></td>
<td><slot name="real-time-llvm-emit"></slot></td>
<th scope="row" class="tooltip">LLVM Emit
<span class="tooltip-content"><b>Only applicable when using the LLVM backend.</b><br><br>Conversion of generated LLVM bitcode to an object file, including any optimization passes.<br><br>When using LLVM, this phase of compilation is typically the slowest by a significant margin. Unfortunately, the Zig compiler implementation has essentially no control over it.</span>
</th>
</tr>
<tr>
<th class="empty-cell"></th>
<td class="empty-cell"></td>
<td><slot name="real-time-link-flush"></slot></td>
<th scope="row" class="tooltip">Linker Flush
<span class="tooltip-content">Finalizing the emitted binary, and ensuring it is fully written to disk.<br><br>When using LLD, this phase represents the entire linker invocation. Otherwise, the amount of work performed here is dependent on details of Zig's linker implementation for the particular output format, but typically aims to be fairly minimal.</span>
</th>
</tr>
</tbody>
</table>
<details class="section">
<summary>Files</summary>
<table class="time-stats">
<thead>
<tr>
<th scope="col">File</th>
<th scope="col">Semantic Analysis</th>
<th scope="col">Code Generation</th>
<th scope="col">Linking</th>
<th scope="col">Total</th>
</tr>
</thead>
<!-- HTML does not allow placing a 'slot' inside of a 'tbody' for backwards-compatibility
reasons, so we unfortunately must template on the `id` here. -->
<tbody id="fileTableBody"></tbody>
</table>
</details>
<details class="section">
<summary>Declarations</summary>
<table class="time-stats">
<thead>
<tr>
<th scope="col">File</th>
<th scope="col">Declaration</th>
<th scope="col" class="tooltip">Analysis Count
<span class="tooltip-content">The number of times the compiler analyzed some part of this declaration. If this is a function, <code>inline</code> and <code>comptime</code> calls to it are <i>not</i> included here. Typically, this value is approximately equal to the number of instances of a generic declaration.</span>
</th>
<th scope="col">Semantic Analysis</th>
<th scope="col">Code Generation</th>
<th scope="col">Linking</th>
<th scope="col">Total</th>
</tr>
</thead>
<!-- HTML does not allow placing a 'slot' inside of a 'tbody' for backwards-compatibility
reasons, so we unfortunately must template on the `id` here. -->
<tbody id="declTableBody"></tbody>
</table>
</details>
<details class="section llvm-only">
<summary>LLVM Pass Timings</summary>
<div><slot name="llvm-pass-timings"></slot></div>
</details>
</div>
<div id="runTestReport">
<table class="time-stats">
<thead>
<tr>
<th scope="col">Test Name</th>
<th scope="col">Duration</th>
</tr>
</thead>
<!-- HTML does not allow placing a 'slot' inside of a 'tbody' for backwards-compatibility
reasons, so we unfortunately must template on the `id` here. -->
<tbody id="runTestTableBody"></tbody>
</div>
</div>
</details>
</template>
<template id="fuzzEntryTemplate">
<link rel="stylesheet" href="style.css">
<ul>
<li>Total Runs: <slot name="stat-total-runs"></slot></li>
<li>Unique Runs: <slot name="stat-unique-runs"></slot></li>
<li>Speed: <slot name="stat-speed"></slot> runs/sec</li>
<li>Coverage: <slot name="stat-coverage"></slot></li>
</ul>
<!-- I have observed issues in Firefox clicking frequently-updating slotted links, so the entry
point list is handled separately since it rarely changes. -->
<ul id="entryPointList" class="no-marker"></ul>
<div id="source" class="hidden">
<h2>Source Code</h2>
<pre><code id="sourceText"></code></pre>
</div>
</template>
<!-- The actual body: fairly minimal, content populated by JavaScript -->
<p id="connectionStatus">Loading JavaScript...</p>
<p class="hidden" id="firefoxWebSocketBullshitExplainer">
If you are using Firefox and <code>zig build --listen</code> is definitely running, you may be experiencing an unreasonably aggressive exponential
backoff for WebSocket connection attempts, which is enabled by default and can block connection attempts for up to a minute. To disable this limit,
open <code>about:config</code> and set the <code>network.websocket.delay-failed-reconnects</code> option to <code>false</code>.
</p>
<main class="hidden">
<h1>Zig Build System</h1>
<p><span id="summaryStatus"></span> | <span id="summaryStepCount"></span> steps</p>
<button class="big-btn" id="buttonRebuild" disabled>Rebuild</button>
<ul class="no-marker" id="stepList"></ul>
<hr>
<div id="timeReport" class="hidden">
<h1>Time Report</h1>
<div id="timeReportList"></div>
<hr>
</div>
<div id="fuzz" class="hidden">
<h1>Fuzzer</h1>
<p id="fuzzStatus"></p>
<div id="fuzzEntries"></div>
<hr>
</div>
<h1>Help</h1>
<p>This is the Zig Build System web interface. It allows live interaction with the build system.</p>
<p>The following <code>zig build</code> flags can expose extra features of this interface:</p>
<ul>
<li><code>--time-report</code>: collect and show statistics about the time taken to evaluate a build graph</li>
<li><code>--fuzz</code>: enable the fuzzer for any Zig test binaries in the build graph (experimental)</li>
</ul>
</main>
<!-- JavaScript at the very end -->
<script src="main.js"></script>

366
lib/build-web/main.js Normal file
View File

@ -0,0 +1,366 @@
const domConnectionStatus = document.getElementById("connectionStatus");
const domFirefoxWebSocketBullshitExplainer = document.getElementById("firefoxWebSocketBullshitExplainer");
const domMain = document.getElementsByTagName("main")[0];
const domSummary = {
stepCount: document.getElementById("summaryStepCount"),
status: document.getElementById("summaryStatus"),
};
const domButtonRebuild = document.getElementById("buttonRebuild");
const domStepList = document.getElementById("stepList");
let domSteps = [];
let wasm_promise = fetch("main.wasm");
let wasm_exports = null;
const text_decoder = new TextDecoder();
const text_encoder = new TextEncoder();
domButtonRebuild.addEventListener("click", () => wasm_exports.rebuild());
setConnectionStatus("Loading WebAssembly...", false);
WebAssembly.instantiateStreaming(wasm_promise, {
core: {
log: function(ptr, len) {
const msg = decodeString(ptr, len);
console.log(msg);
},
panic: function (ptr, len) {
const msg = decodeString(ptr, len);
throw new Error("panic: " + msg);
},
timestamp: function () {
return BigInt(new Date());
},
hello: hello,
updateBuildStatus: updateBuildStatus,
updateStepStatus: updateStepStatus,
sendWsMessage: (ptr, len) => ws.send(new Uint8Array(wasm_exports.memory.buffer, ptr, len)),
},
fuzz: {
requestSources: fuzzRequestSources,
ready: fuzzReady,
updateStats: fuzzUpdateStats,
updateEntryPoints: fuzzUpdateEntryPoints,
updateSource: fuzzUpdateSource,
updateCoverage: fuzzUpdateCoverage,
},
time_report: {
updateGeneric: timeReportUpdateGeneric,
updateCompile: timeReportUpdateCompile,
updateRunTest: timeReportUpdateRunTest,
},
}).then(function(obj) {
setConnectionStatus("Connecting to WebSocket...", true);
connectWebSocket();
wasm_exports = obj.instance.exports;
window.wasm = obj; // for debugging
});
function connectWebSocket() {
const host = document.location.host;
const pathname = document.location.pathname;
const isHttps = document.location.protocol === 'https:';
const match = host.match(/^(.+):(\d+)$/);
const defaultPort = isHttps ? 443 : 80;
const port = match ? parseInt(match[2], 10) : defaultPort;
const hostName = match ? match[1] : host;
const wsProto = isHttps ? "wss:" : "ws:";
const wsUrl = wsProto + '//' + hostName + ':' + port + pathname;
ws = new WebSocket(wsUrl);
ws.binaryType = "arraybuffer";
ws.addEventListener('message', onWebSocketMessage, false);
ws.addEventListener('error', onWebSocketClose, false);
ws.addEventListener('close', onWebSocketClose, false);
ws.addEventListener('open', onWebSocketOpen, false);
}
function onWebSocketOpen() {
setConnectionStatus("Waiting for data...", false);
}
function onWebSocketMessage(ev) {
const jsArray = new Uint8Array(ev.data);
const ptr = wasm_exports.message_begin(jsArray.length);
const wasmArray = new Uint8Array(wasm_exports.memory.buffer, ptr, jsArray.length);
wasmArray.set(jsArray);
wasm_exports.message_end();
}
function onWebSocketClose() {
setConnectionStatus("WebSocket connection closed. Re-connecting...", true);
ws.removeEventListener('message', onWebSocketMessage, false);
ws.removeEventListener('error', onWebSocketClose, false);
ws.removeEventListener('close', onWebSocketClose, false);
ws.removeEventListener('open', onWebSocketOpen, false);
ws = null;
setTimeout(connectWebSocket, 1000);
}
function setConnectionStatus(msg, is_websocket_connect) {
domConnectionStatus.textContent = msg;
if (msg.length > 0) {
domConnectionStatus.classList.remove("hidden");
domMain.classList.add("hidden");
} else {
domConnectionStatus.classList.add("hidden");
domMain.classList.remove("hidden");
}
if (is_websocket_connect) {
domFirefoxWebSocketBullshitExplainer.classList.remove("hidden");
} else {
domFirefoxWebSocketBullshitExplainer.classList.add("hidden");
}
}
function hello(
steps_len,
build_status,
time_report,
) {
domSummary.stepCount.textContent = steps_len;
updateBuildStatus(build_status);
setConnectionStatus("", false);
{
let entries = [];
for (let i = 0; i < steps_len; i += 1) {
const step_name = unwrapString(wasm_exports.stepName(i));
const code = document.createElement("code");
code.textContent = step_name;
const li = document.createElement("li");
li.appendChild(code);
entries.push(li);
}
domStepList.replaceChildren(...entries);
for (let i = 0; i < steps_len; i += 1) {
updateStepStatus(i);
}
}
if (time_report) timeReportReset(steps_len);
fuzzReset();
}
function updateBuildStatus(s) {
let text;
let active = false;
let reset_time_reports = false;
if (s == 0) {
text = "Idle";
} else if (s == 1) {
text = "Watching for changes...";
} else if (s == 2) {
text = "Running...";
active = true;
reset_time_reports = true;
} else if (s == 3) {
text = "Starting fuzzer...";
active = true;
} else {
console.log(`bad build status: ${s}`);
}
domSummary.status.textContent = text;
if (active) {
domSummary.status.classList.add("status-running");
domSummary.status.classList.remove("status-idle");
domButtonRebuild.disabled = true;
} else {
domSummary.status.classList.remove("status-running");
domSummary.status.classList.add("status-idle");
domButtonRebuild.disabled = false;
}
if (reset_time_reports) {
// Grey out and collapse all the time reports
for (const time_report_host of domTimeReportList.children) {
const details = time_report_host.shadowRoot.querySelector(":host > details");
details.classList.add("pending");
details.open = false;
}
}
}
function updateStepStatus(step_idx) {
const li = domStepList.children[step_idx];
const step_status = wasm_exports.stepStatus(step_idx);
li.classList.remove("step-wip", "step-success", "step-failure");
if (step_status == 0) {
// pending
} else if (step_status == 1) {
li.classList.add("step-wip");
} else if (step_status == 2) {
li.classList.add("step-success");
} else if (step_status == 3) {
li.classList.add("step-failure");
} else {
console.log(`bad step status: ${step_status}`);
}
}
function decodeString(ptr, len) {
if (len === 0) return "";
return text_decoder.decode(new Uint8Array(wasm_exports.memory.buffer, ptr, len));
}
function getU32Array(ptr, len) {
if (len === 0) return new Uint32Array();
return new Uint32Array(wasm_exports.memory.buffer, ptr, len);
}
function unwrapString(bigint) {
const ptr = Number(bigint & 0xffffffffn);
const len = Number(bigint >> 32n);
return decodeString(ptr, len);
}
const time_report_entry_template = document.getElementById("timeReportEntryTemplate").content;
const domTimeReport = document.getElementById("timeReport");
const domTimeReportList = document.getElementById("timeReportList");
function timeReportReset(steps_len) {
let entries = [];
for (let i = 0; i < steps_len; i += 1) {
const step_name = unwrapString(wasm_exports.stepName(i));
const host = document.createElement("div");
const shadow = host.attachShadow({ mode: "open" });
shadow.appendChild(time_report_entry_template.cloneNode(true));
shadow.querySelector(":host > details").classList.add("pending");
const slotted_name = document.createElement("code");
slotted_name.setAttribute("slot", "step-name");
slotted_name.textContent = step_name;
host.appendChild(slotted_name);
entries.push(host);
}
domTimeReportList.replaceChildren(...entries);
domTimeReport.classList.remove("hidden");
}
function timeReportUpdateCompile(
step_idx,
inner_html_ptr,
inner_html_len,
file_table_html_ptr,
file_table_html_len,
decl_table_html_ptr,
decl_table_html_len,
use_llvm,
) {
const inner_html = decodeString(inner_html_ptr, inner_html_len);
const file_table_html = decodeString(file_table_html_ptr, file_table_html_len);
const decl_table_html = decodeString(decl_table_html_ptr, decl_table_html_len);
const host = domTimeReportList.children.item(step_idx);
const shadow = host.shadowRoot;
shadow.querySelector(":host > details").classList.remove("pending", "no-llvm");
shadow.getElementById("genericReport").classList.add("hidden");
shadow.getElementById("compileReport").classList.remove("hidden");
shadow.getElementById("runTestReport").classList.add("hidden");
if (!use_llvm) shadow.querySelector(":host > details").classList.add("no-llvm");
host.innerHTML = inner_html;
shadow.getElementById("fileTableBody").innerHTML = file_table_html;
shadow.getElementById("declTableBody").innerHTML = decl_table_html;
}
function timeReportUpdateGeneric(
step_idx,
inner_html_ptr,
inner_html_len,
) {
const inner_html = decodeString(inner_html_ptr, inner_html_len);
const host = domTimeReportList.children.item(step_idx);
const shadow = host.shadowRoot;
shadow.querySelector(":host > details").classList.remove("pending", "no-llvm");
shadow.getElementById("genericReport").classList.remove("hidden");
shadow.getElementById("compileReport").classList.add("hidden");
shadow.getElementById("runTestReport").classList.add("hidden");
host.innerHTML = inner_html;
}
function timeReportUpdateRunTest(
step_idx,
table_html_ptr,
table_html_len,
) {
const table_html = decodeString(table_html_ptr, table_html_len);
const host = domTimeReportList.children.item(step_idx);
const shadow = host.shadowRoot;
shadow.querySelector(":host > details").classList.remove("pending", "no-llvm");
shadow.getElementById("genericReport").classList.add("hidden");
shadow.getElementById("compileReport").classList.add("hidden");
shadow.getElementById("runTestReport").classList.remove("hidden");
shadow.getElementById("runTestTableBody").innerHTML = table_html;
}
const fuzz_entry_template = document.getElementById("fuzzEntryTemplate").content;
const domFuzz = document.getElementById("fuzz");
const domFuzzStatus = document.getElementById("fuzzStatus");
const domFuzzEntries = document.getElementById("fuzzEntries");
let domFuzzInstance = null;
function fuzzRequestSources() {
domFuzzStatus.classList.remove("hidden");
domFuzzStatus.textContent = "Loading sources tarball...";
fetch("sources.tar").then(function(response) {
if (!response.ok) throw new Error("unable to download sources");
domFuzzStatus.textContent = "Parsing fuzz test sources...";
return response.arrayBuffer();
}).then(function(buffer) {
if (buffer.length === 0) throw new Error("sources.tar was empty");
const js_array = new Uint8Array(buffer);
const ptr = wasm_exports.alloc(js_array.length);
const wasm_array = new Uint8Array(wasm_exports.memory.buffer, ptr, js_array.length);
wasm_array.set(js_array);
wasm_exports.fuzzUnpackSources(ptr, js_array.length);
domFuzzStatus.textContent = "";
domFuzzStatus.classList.add("hidden");
});
}
function fuzzReady() {
domFuzz.classList.remove("hidden");
// TODO: multiple fuzzer instances
if (domFuzzInstance !== null) return;
const host = document.createElement("div");
const shadow = host.attachShadow({ mode: "open" });
shadow.appendChild(fuzz_entry_template.cloneNode(true));
domFuzzInstance = host;
domFuzzEntries.appendChild(host);
}
function fuzzReset() {
domFuzz.classList.add("hidden");
domFuzzEntries.replaceChildren();
domFuzzInstance = null;
}
function fuzzUpdateStats(stats_html_ptr, stats_html_len) {
if (domFuzzInstance === null) throw new Error("fuzzUpdateStats called when fuzzer inactive");
const stats_html = decodeString(stats_html_ptr, stats_html_len);
const host = domFuzzInstance;
host.innerHTML = stats_html;
}
function fuzzUpdateEntryPoints(entry_points_html_ptr, entry_points_html_len) {
if (domFuzzInstance === null) throw new Error("fuzzUpdateEntryPoints called when fuzzer inactive");
const entry_points_html = decodeString(entry_points_html_ptr, entry_points_html_len);
const domEntryPointList = domFuzzInstance.shadowRoot.getElementById("entryPointList");
domEntryPointList.innerHTML = entry_points_html;
}
function fuzzUpdateSource(source_html_ptr, source_html_len) {
if (domFuzzInstance === null) throw new Error("fuzzUpdateSource called when fuzzer inactive");
const source_html = decodeString(source_html_ptr, source_html_len);
const domSourceText = domFuzzInstance.shadowRoot.getElementById("sourceText");
domSourceText.innerHTML = source_html;
domFuzzInstance.shadowRoot.getElementById("source").classList.remove("hidden");
}
function fuzzUpdateCoverage(covered_ptr, covered_len) {
if (domFuzzInstance === null) throw new Error("fuzzUpdateCoverage called when fuzzer inactive");
const shadow = domFuzzInstance.shadowRoot;
const domSourceText = shadow.getElementById("sourceText");
const covered = getU32Array(covered_ptr, covered_len);
for (let i = 0; i < domSourceText.children.length; i += 1) {
const childDom = domSourceText.children[i];
if (childDom.id != null && childDom.id[0] == "l") {
childDom.classList.add("l");
childDom.classList.remove("c");
}
}
for (const sli of covered) {
shadow.getElementById(`l${sli}`).classList.add("c");
}
}

214
lib/build-web/main.zig Normal file
View File

@ -0,0 +1,214 @@
const std = @import("std");
const assert = std.debug.assert;
const abi = std.Build.abi;
const gpa = std.heap.wasm_allocator;
const log = std.log;
const Allocator = std.mem.Allocator;
const fuzz = @import("fuzz.zig");
const time_report = @import("time_report.zig");
/// Nanoseconds.
var server_base_timestamp: i64 = 0;
/// Milliseconds.
var client_base_timestamp: i64 = 0;
pub var step_list: []Step = &.{};
/// Not accessed after initialization, but must be freed alongside `step_list`.
pub var step_list_data: []u8 = &.{};
const Step = struct {
name: []const u8,
status: abi.StepUpdate.Status,
};
const js = struct {
extern "core" fn log(ptr: [*]const u8, len: usize) void;
extern "core" fn panic(ptr: [*]const u8, len: usize) noreturn;
extern "core" fn timestamp() i64;
extern "core" fn hello(
steps_len: u32,
status: abi.BuildStatus,
time_report: bool,
) void;
extern "core" fn updateBuildStatus(status: abi.BuildStatus) void;
extern "core" fn updateStepStatus(step_idx: u32) void;
extern "core" fn sendWsMessage(ptr: [*]const u8, len: usize) void;
};
pub const std_options: std.Options = .{
.logFn = logFn,
};
pub fn panic(msg: []const u8, st: ?*std.builtin.StackTrace, addr: ?usize) noreturn {
_ = st;
_ = addr;
log.err("panic: {s}", .{msg});
@trap();
}
fn logFn(
comptime message_level: log.Level,
comptime scope: @EnumLiteral(),
comptime format: []const u8,
args: anytype,
) void {
const level_txt = comptime message_level.asText();
const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): ";
var buf: [500]u8 = undefined;
const line = std.fmt.bufPrint(&buf, level_txt ++ prefix2 ++ format, args) catch l: {
buf[buf.len - 3 ..][0..3].* = "...".*;
break :l &buf;
};
js.log(line.ptr, line.len);
}
export fn alloc(n: usize) [*]u8 {
const slice = gpa.alloc(u8, n) catch @panic("OOM");
return slice.ptr;
}
var message_buffer: std.ArrayListAlignedUnmanaged(u8, .of(u64)) = .empty;
/// Resizes the message buffer to be the correct length; returns the pointer to
/// the query string.
export fn message_begin(len: usize) [*]u8 {
message_buffer.resize(gpa, len) catch @panic("OOM");
return message_buffer.items.ptr;
}
export fn message_end() void {
const msg_bytes = message_buffer.items;
const tag: abi.ToClientTag = @enumFromInt(msg_bytes[0]);
switch (tag) {
_ => @panic("malformed message"),
.hello => return helloMessage(msg_bytes) catch @panic("OOM"),
.status_update => return statusUpdateMessage(msg_bytes) catch @panic("OOM"),
.step_update => return stepUpdateMessage(msg_bytes) catch @panic("OOM"),
.fuzz_source_index => return fuzz.sourceIndexMessage(msg_bytes) catch @panic("OOM"),
.fuzz_coverage_update => return fuzz.coverageUpdateMessage(msg_bytes) catch @panic("OOM"),
.fuzz_entry_points => return fuzz.entryPointsMessage(msg_bytes) catch @panic("OOM"),
.time_report_generic_result => return time_report.genericResultMessage(msg_bytes) catch @panic("OOM"),
.time_report_compile_result => return time_report.compileResultMessage(msg_bytes) catch @panic("OOM"),
.time_report_run_test_result => return time_report.runTestResultMessage(msg_bytes) catch @panic("OOM"),
}
}
const String = Slice(u8);
pub fn Slice(T: type) type {
return packed struct(u64) {
ptr: u32,
len: u32,
pub fn init(s: []const T) @This() {
return .{
.ptr = @intFromPtr(s.ptr),
.len = s.len,
};
}
};
}
pub fn fatal(comptime format: []const u8, args: anytype) noreturn {
var buf: [500]u8 = undefined;
const line = std.fmt.bufPrint(&buf, format, args) catch l: {
buf[buf.len - 3 ..][0..3].* = "...".*;
break :l &buf;
};
js.panic(line.ptr, line.len);
}
fn helloMessage(msg_bytes: []align(4) u8) Allocator.Error!void {
if (msg_bytes.len < @sizeOf(abi.Hello)) @panic("malformed Hello message");
const hdr: *const abi.Hello = @ptrCast(msg_bytes[0..@sizeOf(abi.Hello)]);
const trailing = msg_bytes[@sizeOf(abi.Hello)..];
client_base_timestamp = js.timestamp();
server_base_timestamp = hdr.timestamp;
const steps = try gpa.alloc(Step, hdr.steps_len);
errdefer gpa.free(steps);
const step_name_lens: []align(1) const u32 = @ptrCast(trailing[0 .. steps.len * 4]);
const step_name_data_len: usize = len: {
var sum: usize = 0;
for (step_name_lens) |n| sum += n;
break :len sum;
};
const step_name_data: []const u8 = trailing[steps.len * 4 ..][0..step_name_data_len];
const step_status_bits: []const u8 = trailing[steps.len * 4 + step_name_data_len ..];
const duped_step_name_data = try gpa.dupe(u8, step_name_data);
errdefer gpa.free(duped_step_name_data);
var name_off: usize = 0;
for (steps, step_name_lens, 0..) |*step_out, name_len, step_idx| {
step_out.* = .{
.name = duped_step_name_data[name_off..][0..name_len],
.status = @enumFromInt(@as(u2, @truncate(step_status_bits[step_idx / 4] >> @intCast((step_idx % 4) * 2)))),
};
name_off += name_len;
}
gpa.free(step_list);
gpa.free(step_list_data);
step_list = steps;
step_list_data = duped_step_name_data;
js.hello(step_list.len, hdr.status, hdr.flags.time_report);
}
fn statusUpdateMessage(msg_bytes: []u8) Allocator.Error!void {
if (msg_bytes.len < @sizeOf(abi.StatusUpdate)) @panic("malformed StatusUpdate message");
const msg: *const abi.StatusUpdate = @ptrCast(msg_bytes[0..@sizeOf(abi.StatusUpdate)]);
js.updateBuildStatus(msg.new);
}
fn stepUpdateMessage(msg_bytes: []u8) Allocator.Error!void {
if (msg_bytes.len < @sizeOf(abi.StepUpdate)) @panic("malformed StepUpdate message");
const msg: *const abi.StepUpdate = @ptrCast(msg_bytes[0..@sizeOf(abi.StepUpdate)]);
if (msg.step_idx >= step_list.len) @panic("malformed StepUpdate message");
step_list[msg.step_idx].status = msg.bits.status;
js.updateStepStatus(msg.step_idx);
}
export fn stepName(idx: usize) String {
return .init(step_list[idx].name);
}
export fn stepStatus(idx: usize) u8 {
return @intFromEnum(step_list[idx].status);
}
export fn rebuild() void {
const msg: abi.Rebuild = .{};
const raw: []const u8 = @ptrCast(&msg);
js.sendWsMessage(raw.ptr, raw.len);
}
/// Nanoseconds passed since a server timestamp.
pub fn nsSince(server_timestamp: i64) i64 {
const ms_passed = js.timestamp() - client_base_timestamp;
const ns_passed = server_base_timestamp - server_timestamp;
return ns_passed + ms_passed * std.time.ns_per_ms;
}
pub fn fmtEscapeHtml(unescaped: []const u8) HtmlEscaper {
return .{ .unescaped = unescaped };
}
const HtmlEscaper = struct {
unescaped: []const u8,
pub fn format(he: HtmlEscaper, w: *std.Io.Writer) !void {
for (he.unescaped) |c| switch (c) {
'&' => try w.writeAll("&amp;"),
'<' => try w.writeAll("&lt;"),
'>' => try w.writeAll("&gt;"),
'"' => try w.writeAll("&quot;"),
'\'' => try w.writeAll("&#39;"),
else => try w.writeByte(c),
};
}
};

240
lib/build-web/style.css Normal file
View File

@ -0,0 +1,240 @@
body {
font-family: system-ui, -apple-system, Roboto, "Segoe UI", sans-serif;
color: #000000;
padding: 1em 10%;
}
ul.no-marker {
list-style-type: none;
padding-left: 0;
}
hr {
margin: 2em 0;
}
.hidden {
display: none;
}
.empty-cell {
background: #ccc;
}
table.time-stats > tbody > tr > th {
text-align: left;
}
table.time-stats > tbody > tr > td {
text-align: right;
}
details > summary {
cursor: pointer;
font-size: 1.5em;
}
.tooltip {
text-decoration: underline;
cursor: help;
}
.tooltip-content {
border-radius: 6px;
display: none;
position: absolute;
background: #fff;
border: 1px solid black;
max-width: 500px;
padding: 1em;
text-align: left;
font-weight: normal;
pointer-events: none;
}
.tooltip:hover > .tooltip-content {
display: block;
}
table {
margin: 1.0em auto 1.5em 0;
border-collapse: collapse;
}
th, td {
padding: 0.5em 1em 0.5em 1em;
border: 1px solid;
border-color: black;
}
a, button {
color: #2A6286;
}
button {
background: #eee;
cursor: pointer;
border: none;
border-radius: 3px;
padding: 0.2em 0.5em;
}
button.big-btn {
font-size: 1.3em;
}
button.linkish {
background: none;
text-decoration: underline;
padding: 0;
}
button:disabled {
color: #888;
cursor: not-allowed;
}
pre {
font-family: "Source Code Pro", monospace;
font-size: 1em;
background-color: #F5F5F5;
padding: 1em;
margin: 0;
overflow-x: auto;
}
:not(pre) > code {
white-space: break-spaces;
}
code {
font-family: "Source Code Pro", monospace;
font-size: 0.9em;
}
code a {
color: #000000;
}
kbd {
color: #000;
background-color: #fafbfc;
border-color: #d1d5da;
border-bottom-color: #c6cbd1;
box-shadow-color: #c6cbd1;
display: inline-block;
padding: 0.3em 0.2em;
font: 1.2em monospace;
line-height: 0.8em;
vertical-align: middle;
border: solid 1px;
border-radius: 3px;
box-shadow: inset 0 -1px 0;
cursor: default;
}
.status-running { color: #181; }
.status-idle { color: #444; }
.step-success { color: #181; }
.step-failure { color: #d11; }
.step-wip::before {
content: '';
position: absolute;
margin-left: -1.5em;
width: 1em;
text-align: center;
animation-name: spinner;
animation-duration: 0.5s;
animation-iteration-count: infinite;
animation-timing-function: step-start;
}
@keyframes spinner {
0% { content: '|'; }
25% { content: '/'; }
50% { content: '-'; }
75% { content: '\\'; }
100% { content: '|'; }
}
.l {
display: inline-block;
background: red;
width: 1em;
height: 1em;
border-radius: 1em;
}
.c {
background-color: green;
}
.tok-kw {
color: #333;
font-weight: bold;
}
.tok-str {
color: #d14;
}
.tok-builtin {
color: #0086b3;
}
.tok-comment {
color: #777;
font-style: italic;
}
.tok-fn {
color: #900;
font-weight: bold;
}
.tok-null {
color: #008080;
}
.tok-number {
color: #008080;
}
.tok-type {
color: #458;
font-weight: bold;
}
@media (prefers-color-scheme: dark) {
body {
background-color: #111;
color: #ddd;
}
pre {
background-color: #222;
}
a, button {
color: #88f;
}
button {
background: #333;
}
button:disabled {
color: #555;
}
code a {
color: #eee;
}
th, td {
border-color: white;
}
.empty-cell {
background: #000;
}
.tooltip-content {
background: #060606;
border-color: white;
}
.status-running { color: #90ee90; }
.status-idle { color: #bbb; }
.step-success { color: #90ee90; }
.step-failure { color: #f66; }
.l {
background-color: red;
}
.c {
background-color: green;
}
.tok-kw {
color: #eee;
}
.tok-str {
color: #2e5;
}
.tok-builtin {
color: #ff894c;
}
.tok-comment {
color: #aa7;
}
.tok-fn {
color: #B1A0F8;
}
.tok-null {
color: #ff8080;
}
.tok-number {
color: #ff8080;
}
.tok-type {
color: #68f;
}
}

View File

@ -0,0 +1,43 @@
:host > details {
padding: 0.5em 1em;
background: #f2f2f2;
margin-bottom: 1.0em;
overflow-x: scroll;
}
:host > details.pending {
pointer-events: none;
background: #fafafa;
color: #666;
}
:host > details > div {
margin: 1em 2em;
overflow: scroll; /* we'll try to avoid overflow, but if it does happen, this makes sense */
}
.stats {
font-size: 1.2em;
}
details.section {
margin: 1.0em 0 0 0;
}
details.section > summary {
font-weight: bold;
}
details.section > :not(summary) {
margin-left: 2em;
}
:host > details.no-llvm .llvm-only {
display: none;
}
@media (prefers-color-scheme: dark) {
:host > details {
background: #222;
}
:host > details.pending {
background: #181818;
color: #888;
}
}
th {
max-width: 20em; /* don't let the 'file' column get crazy long */
overflow-wrap: anywhere; /* avoid overflow where possible */
}

View File

@ -0,0 +1,280 @@
const std = @import("std");
const gpa = std.heap.wasm_allocator;
const abi = std.Build.abi.time_report;
const fmtEscapeHtml = @import("root").fmtEscapeHtml;
const step_list = &@import("root").step_list;
const js = struct {
extern "time_report" fn updateGeneric(
/// The index of the step.
step_idx: u32,
// The HTML which will be used to populate the template slots.
inner_html_ptr: [*]const u8,
inner_html_len: usize,
) void;
extern "time_report" fn updateCompile(
/// The index of the step.
step_idx: u32,
// The HTML which will be used to populate the template slots.
inner_html_ptr: [*]const u8,
inner_html_len: usize,
// The HTML which will populate the <tbody> of the file table.
file_table_html_ptr: [*]const u8,
file_table_html_len: usize,
// The HTML which will populate the <tbody> of the decl table.
decl_table_html_ptr: [*]const u8,
decl_table_html_len: usize,
/// Whether the LLVM backend was used. If not, LLVM-specific statistics are hidden.
use_llvm: bool,
) void;
extern "time_report" fn updateRunTest(
/// The index of the step.
step_idx: u32,
// The HTML which will populate the <tbody> of the test table.
table_html_ptr: [*]const u8,
table_html_len: usize,
) void;
};
pub fn genericResultMessage(msg_bytes: []u8) error{OutOfMemory}!void {
if (msg_bytes.len != @sizeOf(abi.GenericResult)) @panic("malformed GenericResult message");
const msg: *const abi.GenericResult = @ptrCast(msg_bytes);
if (msg.step_idx >= step_list.*.len) @panic("malformed GenericResult message");
const inner_html = try std.fmt.allocPrint(gpa,
\\<code slot="step-name">{[step_name]f}</code>
\\<span slot="stat-total-time">{[stat_total_time]D}</span>
, .{
.step_name = fmtEscapeHtml(step_list.*[msg.step_idx].name),
.stat_total_time = msg.ns_total,
});
defer gpa.free(inner_html);
js.updateGeneric(msg.step_idx, inner_html.ptr, inner_html.len);
}
pub fn compileResultMessage(msg_bytes: []u8) error{ OutOfMemory, WriteFailed }!void {
const max_table_rows = 500;
if (msg_bytes.len < @sizeOf(abi.CompileResult)) @panic("malformed CompileResult message");
const hdr: *const abi.CompileResult = @ptrCast(msg_bytes[0..@sizeOf(abi.CompileResult)]);
if (hdr.step_idx >= step_list.*.len) @panic("malformed CompileResult message");
var trailing = msg_bytes[@sizeOf(abi.CompileResult)..];
const llvm_pass_timings = trailing[0..hdr.llvm_pass_timings_len];
trailing = trailing[hdr.llvm_pass_timings_len..];
const FileTimeReport = struct {
name: []const u8,
ns_sema: u64,
ns_codegen: u64,
ns_link: u64,
};
const DeclTimeReport = struct {
file_name: []const u8,
name: []const u8,
sema_count: u32,
ns_sema: u64,
ns_codegen: u64,
ns_link: u64,
};
const slowest_files = try gpa.alloc(FileTimeReport, hdr.files_len);
defer gpa.free(slowest_files);
const slowest_decls = try gpa.alloc(DeclTimeReport, hdr.decls_len);
defer gpa.free(slowest_decls);
for (slowest_files) |*file_out| {
const i = std.mem.indexOfScalar(u8, trailing, 0) orelse @panic("malformed CompileResult message");
file_out.* = .{
.name = trailing[0..i],
.ns_sema = 0,
.ns_codegen = 0,
.ns_link = 0,
};
trailing = trailing[i + 1 ..];
}
for (slowest_decls) |*decl_out| {
const i = std.mem.indexOfScalar(u8, trailing, 0) orelse @panic("malformed CompileResult message");
const file_idx = std.mem.readInt(u32, trailing[i..][1..5], .little);
const sema_count = std.mem.readInt(u32, trailing[i..][5..9], .little);
const sema_ns = std.mem.readInt(u64, trailing[i..][9..17], .little);
const codegen_ns = std.mem.readInt(u64, trailing[i..][17..25], .little);
const link_ns = std.mem.readInt(u64, trailing[i..][25..33], .little);
const file = &slowest_files[file_idx];
decl_out.* = .{
.file_name = file.name,
.name = trailing[0..i],
.sema_count = sema_count,
.ns_sema = sema_ns,
.ns_codegen = codegen_ns,
.ns_link = link_ns,
};
trailing = trailing[i + 33 ..];
file.ns_sema += sema_ns;
file.ns_codegen += codegen_ns;
file.ns_link += link_ns;
}
const S = struct {
fn fileLessThan(_: void, lhs: FileTimeReport, rhs: FileTimeReport) bool {
const lhs_ns = lhs.ns_sema + lhs.ns_codegen + lhs.ns_link;
const rhs_ns = rhs.ns_sema + rhs.ns_codegen + rhs.ns_link;
return lhs_ns > rhs_ns; // flipped to sort in reverse order
}
fn declLessThan(_: void, lhs: DeclTimeReport, rhs: DeclTimeReport) bool {
//if (true) return lhs.sema_count > rhs.sema_count;
const lhs_ns = lhs.ns_sema + lhs.ns_codegen + lhs.ns_link;
const rhs_ns = rhs.ns_sema + rhs.ns_codegen + rhs.ns_link;
return lhs_ns > rhs_ns; // flipped to sort in reverse order
}
};
std.mem.sort(FileTimeReport, slowest_files, {}, S.fileLessThan);
std.mem.sort(DeclTimeReport, slowest_decls, {}, S.declLessThan);
const stats = hdr.stats;
const inner_html = try std.fmt.allocPrint(gpa,
\\<code slot="step-name">{[step_name]f}</code>
\\<span slot="stat-reachable-files">{[stat_reachable_files]d}</span>
\\<span slot="stat-imported-files">{[stat_imported_files]d}</span>
\\<span slot="stat-generic-instances">{[stat_generic_instances]d}</span>
\\<span slot="stat-inline-calls">{[stat_inline_calls]d}</span>
\\<span slot="stat-compilation-time">{[stat_compilation_time]D}</span>
\\<span slot="cpu-time-parse">{[cpu_time_parse]D}</span>
\\<span slot="cpu-time-astgen">{[cpu_time_astgen]D}</span>
\\<span slot="cpu-time-sema">{[cpu_time_sema]D}</span>
\\<span slot="cpu-time-codegen">{[cpu_time_codegen]D}</span>
\\<span slot="cpu-time-link">{[cpu_time_link]D}</span>
\\<span slot="real-time-files">{[real_time_files]D}</span>
\\<span slot="real-time-decls">{[real_time_decls]D}</span>
\\<span slot="real-time-llvm-emit">{[real_time_llvm_emit]D}</span>
\\<span slot="real-time-link-flush">{[real_time_link_flush]D}</span>
\\<pre slot="llvm-pass-timings"><code>{[llvm_pass_timings]f}</code></pre>
\\
, .{
.step_name = fmtEscapeHtml(step_list.*[hdr.step_idx].name),
.stat_reachable_files = stats.n_reachable_files,
.stat_imported_files = stats.n_imported_files,
.stat_generic_instances = stats.n_generic_instances,
.stat_inline_calls = stats.n_inline_calls,
.stat_compilation_time = hdr.ns_total,
.cpu_time_parse = stats.cpu_ns_parse,
.cpu_time_astgen = stats.cpu_ns_astgen,
.cpu_time_sema = stats.cpu_ns_sema,
.cpu_time_codegen = stats.cpu_ns_codegen,
.cpu_time_link = stats.cpu_ns_link,
.real_time_files = stats.real_ns_files,
.real_time_decls = stats.real_ns_decls,
.real_time_llvm_emit = stats.real_ns_llvm_emit,
.real_time_link_flush = stats.real_ns_link_flush,
.llvm_pass_timings = fmtEscapeHtml(llvm_pass_timings),
});
defer gpa.free(inner_html);
var file_table_html: std.Io.Writer.Allocating = .init(gpa);
defer file_table_html.deinit();
for (slowest_files[0..@min(max_table_rows, slowest_files.len)]) |file| {
try file_table_html.writer.print(
\\<tr>
\\ <th scope="row"><code>{f}</code></th>
\\ <td>{D}</td>
\\ <td>{D}</td>
\\ <td>{D}</td>
\\ <td>{D}</td>
\\</tr>
\\
, .{
fmtEscapeHtml(file.name),
file.ns_sema,
file.ns_codegen,
file.ns_link,
file.ns_sema + file.ns_codegen + file.ns_link,
});
}
if (slowest_files.len > max_table_rows) {
try file_table_html.writer.print(
\\<tr><td colspan="4">{d} more rows omitted</td></tr>
\\
, .{slowest_files.len - max_table_rows});
}
var decl_table_html: std.Io.Writer.Allocating = .init(gpa);
defer decl_table_html.deinit();
for (slowest_decls[0..@min(max_table_rows, slowest_decls.len)]) |decl| {
try decl_table_html.writer.print(
\\<tr>
\\ <th scope="row"><code>{f}</code></th>
\\ <th scope="row"><code>{f}</code></th>
\\ <td>{d}</td>
\\ <td>{D}</td>
\\ <td>{D}</td>
\\ <td>{D}</td>
\\ <td>{D}</td>
\\</tr>
\\
, .{
fmtEscapeHtml(decl.file_name),
fmtEscapeHtml(decl.name),
decl.sema_count,
decl.ns_sema,
decl.ns_codegen,
decl.ns_link,
decl.ns_sema + decl.ns_codegen + decl.ns_link,
});
}
if (slowest_decls.len > max_table_rows) {
try decl_table_html.writer.print(
\\<tr><td colspan="6">{d} more rows omitted</td></tr>
\\
, .{slowest_decls.len - max_table_rows});
}
js.updateCompile(
hdr.step_idx,
inner_html.ptr,
inner_html.len,
file_table_html.written().ptr,
file_table_html.written().len,
decl_table_html.written().ptr,
decl_table_html.written().len,
hdr.flags.use_llvm,
);
}
pub fn runTestResultMessage(msg_bytes: []u8) error{OutOfMemory}!void {
if (msg_bytes.len < @sizeOf(abi.RunTestResult)) @panic("malformed RunTestResult message");
const hdr: *const abi.RunTestResult = @ptrCast(msg_bytes[0..@sizeOf(abi.RunTestResult)]);
if (hdr.step_idx >= step_list.*.len) @panic("malformed RunTestResult message");
const trailing = msg_bytes[@sizeOf(abi.RunTestResult)..];
const durations: []align(1) const u64 = @ptrCast(trailing[0 .. hdr.tests_len * 8]);
var offset: usize = hdr.tests_len * 8;
var table_html: std.ArrayList(u8) = .empty;
defer table_html.deinit(gpa);
for (durations) |test_ns| {
const test_name_len = std.mem.indexOfScalar(u8, trailing[offset..], 0) orelse @panic("malformed RunTestResult message");
const test_name = trailing[offset..][0..test_name_len];
offset += test_name_len + 1;
try table_html.print(gpa, "<tr><th scope=\"row\"><code>{f}</code></th>", .{fmtEscapeHtml(test_name)});
if (test_ns == std.math.maxInt(u64)) {
try table_html.appendSlice(gpa, "<td class=\"empty-cell\"></td>"); // didn't run
} else {
try table_html.print(gpa, "<td>{D}</td>", .{test_ns});
}
try table_html.appendSlice(gpa, "</tr>\n");
}
if (offset != trailing.len) @panic("malformed RunTestResult message");
js.updateRunTest(
hdr.step_idx,
table_html.items.ptr,
table_html.items.len,
);
}

190
lib/c.zig
View File

@ -1,180 +1,38 @@
//! This is Zig's multi-target implementation of libc.
//! When builtin.link_libc is true, we need to export all the functions and
//! provide an entire C API.
//!
//! When `builtin.link_libc` is true, we need to export all the functions and
//! provide a libc API compatible with the target (e.g. musl, wasi-libc, ...).
const std = @import("std");
const builtin = @import("builtin");
const math = std.math;
const isNan = std.math.isNan;
const maxInt = std.math.maxInt;
const native_os = builtin.os.tag;
const native_arch = builtin.cpu.arch;
const native_abi = builtin.abi;
const std = @import("std");
const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .internal else .strong;
const is_wasm = switch (native_arch) {
.wasm32, .wasm64 => true,
else => false,
};
const is_freestanding = switch (native_os) {
.freestanding, .other => true,
else => false,
};
// Avoid dragging in the runtime safety mechanisms into this .o file, unless
// we're trying to test zigc.
pub const panic = if (builtin.is_test)
std.debug.FullPanic(std.debug.defaultPanic)
else
std.debug.no_panic;
comptime {
if (is_freestanding and is_wasm and builtin.link_libc) {
@export(&wasm_start, .{ .name = "_start", .linkage = .strong });
_ = @import("c/inttypes.zig");
_ = @import("c/stdlib.zig");
_ = @import("c/math.zig");
if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
// Files specific to musl and wasi-libc.
_ = @import("c/string.zig");
_ = @import("c/strings.zig");
}
if (builtin.link_libc) {
@export(&strcmp, .{ .name = "strcmp", .linkage = linkage });
@export(&strncmp, .{ .name = "strncmp", .linkage = linkage });
@export(&strerror, .{ .name = "strerror", .linkage = linkage });
@export(&strlen, .{ .name = "strlen", .linkage = linkage });
@export(&strcpy, .{ .name = "strcpy", .linkage = linkage });
@export(&strncpy, .{ .name = "strncpy", .linkage = linkage });
@export(&strcat, .{ .name = "strcat", .linkage = linkage });
@export(&strncat, .{ .name = "strncat", .linkage = linkage });
}
}
// Avoid dragging in the runtime safety mechanisms into this .o file,
// unless we're trying to test this file.
pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
@branchHint(.cold);
_ = error_return_trace;
if (builtin.is_test) {
std.debug.panic("{s}", .{msg});
}
switch (native_os) {
.freestanding, .other, .amdhsa, .amdpal => while (true) {},
else => std.os.abort(),
}
}
extern fn main(argc: c_int, argv: [*:null]?[*:0]u8) c_int;
fn wasm_start() callconv(.C) void {
_ = main(0, undefined);
}
fn strcpy(dest: [*:0]u8, src: [*:0]const u8) callconv(.C) [*:0]u8 {
var i: usize = 0;
while (src[i] != 0) : (i += 1) {
dest[i] = src[i];
}
dest[i] = 0;
return dest;
}
test "strcpy" {
var s1: [9:0]u8 = undefined;
s1[0] = 0;
_ = strcpy(&s1, "foobarbaz");
try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.sliceTo(&s1, 0));
}
fn strncpy(dest: [*:0]u8, src: [*:0]const u8, n: usize) callconv(.C) [*:0]u8 {
var i: usize = 0;
while (i < n and src[i] != 0) : (i += 1) {
dest[i] = src[i];
}
while (i < n) : (i += 1) {
dest[i] = 0;
if (builtin.target.isMuslLibC()) {
// Files specific to musl.
}
return dest;
}
test "strncpy" {
var s1: [9:0]u8 = undefined;
s1[0] = 0;
_ = strncpy(&s1, "foobarbaz", @sizeOf(@TypeOf(s1)));
try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.sliceTo(&s1, 0));
}
fn strcat(dest: [*:0]u8, src: [*:0]const u8) callconv(.C) [*:0]u8 {
var dest_end: usize = 0;
while (dest[dest_end] != 0) : (dest_end += 1) {}
var i: usize = 0;
while (src[i] != 0) : (i += 1) {
dest[dest_end + i] = src[i];
if (builtin.target.isWasiLibC()) {
// Files specific to wasi-libc.
}
dest[dest_end + i] = 0;
return dest;
}
test "strcat" {
var s1: [9:0]u8 = undefined;
s1[0] = 0;
_ = strcat(&s1, "foo");
_ = strcat(&s1, "bar");
_ = strcat(&s1, "baz");
try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.sliceTo(&s1, 0));
}
fn strncat(dest: [*:0]u8, src: [*:0]const u8, avail: usize) callconv(.C) [*:0]u8 {
var dest_end: usize = 0;
while (dest[dest_end] != 0) : (dest_end += 1) {}
var i: usize = 0;
while (i < avail and src[i] != 0) : (i += 1) {
dest[dest_end + i] = src[i];
if (builtin.target.isMinGW()) {
// Files specific to MinGW-w64.
}
dest[dest_end + i] = 0;
return dest;
}
test "strncat" {
var s1: [9:0]u8 = undefined;
s1[0] = 0;
_ = strncat(&s1, "foo1111", 3);
_ = strncat(&s1, "bar1111", 3);
_ = strncat(&s1, "baz1111", 3);
try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.sliceTo(&s1, 0));
}
fn strcmp(s1: [*:0]const u8, s2: [*:0]const u8) callconv(.C) c_int {
return switch (std.mem.orderZ(u8, s1, s2)) {
.lt => -1,
.eq => 0,
.gt => 1,
};
}
fn strlen(s: [*:0]const u8) callconv(.C) usize {
return std.mem.len(s);
}
fn strncmp(_l: [*:0]const u8, _r: [*:0]const u8, _n: usize) callconv(.C) c_int {
if (_n == 0) return 0;
var l = _l;
var r = _r;
var n = _n - 1;
while (l[0] != 0 and r[0] != 0 and n != 0 and l[0] == r[0]) {
l += 1;
r += 1;
n -= 1;
}
return @as(c_int, l[0]) - @as(c_int, r[0]);
}
fn strerror(errnum: c_int) callconv(.C) [*:0]const u8 {
_ = errnum;
return "TODO strerror implementation";
}
test "strncmp" {
try std.testing.expect(strncmp("a", "b", 1) < 0);
try std.testing.expect(strncmp("a", "c", 1) < 0);
try std.testing.expect(strncmp("b", "a", 1) > 0);
try std.testing.expect(strncmp("\xff", "\x02", 1) > 0);
}

15
lib/c/common.zig Normal file
View File

@ -0,0 +1,15 @@
const builtin = @import("builtin");
const std = @import("std");
pub const linkage: std.builtin.GlobalLinkage = if (builtin.is_test)
.internal
else
.strong;
/// Determines the symbol's visibility to other objects.
/// For WebAssembly this allows the symbol to be resolved to other modules, but will not
/// export it to the host runtime.
pub const visibility: std.builtin.SymbolVisibility = if (linkage != .internal)
.hidden
else
.default;

20
lib/c/inttypes.zig Normal file
View File

@ -0,0 +1,20 @@
const std = @import("std");
const common = @import("common.zig");
const builtin = @import("builtin");
const intmax_t = std.c.intmax_t;
comptime {
if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
// Functions specific to musl and wasi-libc.
@export(&imaxabs, .{ .name = "imaxabs", .linkage = common.linkage, .visibility = common.visibility });
}
}
fn imaxabs(a: intmax_t) callconv(.c) intmax_t {
return @intCast(@abs(a));
}
test imaxabs {
const val: intmax_t = -10;
try std.testing.expectEqual(10, imaxabs(val));
}

26
lib/c/math.zig Normal file
View File

@ -0,0 +1,26 @@
const std = @import("std");
const common = @import("common.zig");
const builtin = @import("builtin");
comptime {
if (builtin.target.isMinGW()) {
@export(&isnan, .{ .name = "isnan", .linkage = common.linkage, .visibility = common.visibility });
@export(&isnan, .{ .name = "__isnan", .linkage = common.linkage, .visibility = common.visibility });
@export(&isnanf, .{ .name = "isnanf", .linkage = common.linkage, .visibility = common.visibility });
@export(&isnanf, .{ .name = "__isnanf", .linkage = common.linkage, .visibility = common.visibility });
@export(&isnanl, .{ .name = "isnanl", .linkage = common.linkage, .visibility = common.visibility });
@export(&isnanl, .{ .name = "__isnanl", .linkage = common.linkage, .visibility = common.visibility });
}
}
fn isnan(x: f64) callconv(.c) c_int {
return if (std.math.isNan(x)) 1 else 0;
}
fn isnanf(x: f32) callconv(.c) c_int {
return if (std.math.isNan(x)) 1 else 0;
}
fn isnanl(x: c_longdouble) callconv(.c) c_int {
return if (std.math.isNan(x)) 1 else 0;
}

39
lib/c/stdlib.zig Normal file
View File

@ -0,0 +1,39 @@
const std = @import("std");
const common = @import("common.zig");
const builtin = @import("builtin");
comptime {
if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
// Functions specific to musl and wasi-libc.
@export(&abs, .{ .name = "abs", .linkage = common.linkage, .visibility = common.visibility });
@export(&labs, .{ .name = "labs", .linkage = common.linkage, .visibility = common.visibility });
@export(&llabs, .{ .name = "llabs", .linkage = common.linkage, .visibility = common.visibility });
}
}
fn abs(a: c_int) callconv(.c) c_int {
return @intCast(@abs(a));
}
fn labs(a: c_long) callconv(.c) c_long {
return @intCast(@abs(a));
}
fn llabs(a: c_longlong) callconv(.c) c_longlong {
return @intCast(@abs(a));
}
test abs {
const val: c_int = -10;
try std.testing.expectEqual(10, abs(val));
}
test labs {
const val: c_long = -10;
try std.testing.expectEqual(10, labs(val));
}
test llabs {
const val: c_longlong = -10;
try std.testing.expectEqual(10, llabs(val));
}

104
lib/c/string.zig Normal file
View File

@ -0,0 +1,104 @@
const builtin = @import("builtin");
const std = @import("std");
const common = @import("common.zig");
comptime {
@export(&strcmp, .{ .name = "strcmp", .linkage = common.linkage, .visibility = common.visibility });
@export(&strncmp, .{ .name = "strncmp", .linkage = common.linkage, .visibility = common.visibility });
@export(&strcasecmp, .{ .name = "strcasecmp", .linkage = common.linkage, .visibility = common.visibility });
@export(&strncasecmp, .{ .name = "strncasecmp", .linkage = common.linkage, .visibility = common.visibility });
@export(&__strcasecmp_l, .{ .name = "__strcasecmp_l", .linkage = common.linkage, .visibility = common.visibility });
@export(&__strncasecmp_l, .{ .name = "__strncasecmp_l", .linkage = common.linkage, .visibility = common.visibility });
@export(&__strcasecmp_l, .{ .name = "strcasecmp_l", .linkage = .weak, .visibility = common.visibility });
@export(&__strncasecmp_l, .{ .name = "strncasecmp_l", .linkage = .weak, .visibility = common.visibility });
}
fn strcmp(s1: [*:0]const c_char, s2: [*:0]const c_char) callconv(.c) c_int {
// We need to perform unsigned comparisons.
return switch (std.mem.orderZ(u8, @ptrCast(s1), @ptrCast(s2))) {
.lt => -1,
.eq => 0,
.gt => 1,
};
}
fn strncmp(s1: [*:0]const c_char, s2: [*:0]const c_char, n: usize) callconv(.c) c_int {
if (n == 0) return 0;
var l: [*:0]const u8 = @ptrCast(s1);
var r: [*:0]const u8 = @ptrCast(s2);
var i = n - 1;
while (l[0] != 0 and r[0] != 0 and i != 0 and l[0] == r[0]) {
l += 1;
r += 1;
i -= 1;
}
return @as(c_int, l[0]) - @as(c_int, r[0]);
}
fn strcasecmp(s1: [*:0]const c_char, s2: [*:0]const c_char) callconv(.c) c_int {
const toLower = std.ascii.toLower;
var l: [*:0]const u8 = @ptrCast(s1);
var r: [*:0]const u8 = @ptrCast(s2);
while (l[0] != 0 and r[0] != 0 and (l[0] == r[0] or toLower(l[0]) == toLower(r[0]))) {
l += 1;
r += 1;
}
return @as(c_int, toLower(l[0])) - @as(c_int, toLower(r[0]));
}
fn __strcasecmp_l(s1: [*:0]const c_char, s2: [*:0]const c_char, locale: *anyopaque) callconv(.c) c_int {
_ = locale;
return strcasecmp(s1, s2);
}
fn strncasecmp(s1: [*:0]const c_char, s2: [*:0]const c_char, n: usize) callconv(.c) c_int {
const toLower = std.ascii.toLower;
var l: [*:0]const u8 = @ptrCast(s1);
var r: [*:0]const u8 = @ptrCast(s2);
var i = n - 1;
while (l[0] != 0 and r[0] != 0 and i != 0 and (l[0] == r[0] or toLower(l[0]) == toLower(r[0]))) {
l += 1;
r += 1;
i -= 1;
}
return @as(c_int, toLower(l[0])) - @as(c_int, toLower(r[0]));
}
fn __strncasecmp_l(s1: [*:0]const c_char, s2: [*:0]const c_char, n: usize, locale: *anyopaque) callconv(.c) c_int {
_ = locale;
return strncasecmp(s1, s2, n);
}
test strcasecmp {
try std.testing.expect(strcasecmp(@ptrCast("a"), @ptrCast("b")) < 0);
try std.testing.expect(strcasecmp(@ptrCast("b"), @ptrCast("a")) > 0);
try std.testing.expect(strcasecmp(@ptrCast("A"), @ptrCast("b")) < 0);
try std.testing.expect(strcasecmp(@ptrCast("b"), @ptrCast("A")) > 0);
try std.testing.expect(strcasecmp(@ptrCast("A"), @ptrCast("A")) == 0);
try std.testing.expect(strcasecmp(@ptrCast("B"), @ptrCast("b")) == 0);
try std.testing.expect(strcasecmp(@ptrCast("bb"), @ptrCast("AA")) > 0);
}
test strncasecmp {
try std.testing.expect(strncasecmp(@ptrCast("a"), @ptrCast("b"), 1) < 0);
try std.testing.expect(strncasecmp(@ptrCast("b"), @ptrCast("a"), 1) > 0);
try std.testing.expect(strncasecmp(@ptrCast("A"), @ptrCast("b"), 1) < 0);
try std.testing.expect(strncasecmp(@ptrCast("b"), @ptrCast("A"), 1) > 0);
try std.testing.expect(strncasecmp(@ptrCast("A"), @ptrCast("A"), 1) == 0);
try std.testing.expect(strncasecmp(@ptrCast("B"), @ptrCast("b"), 1) == 0);
try std.testing.expect(strncasecmp(@ptrCast("bb"), @ptrCast("AA"), 2) > 0);
}
test strncmp {
try std.testing.expect(strncmp(@ptrCast("a"), @ptrCast("b"), 1) < 0);
try std.testing.expect(strncmp(@ptrCast("a"), @ptrCast("c"), 1) < 0);
try std.testing.expect(strncmp(@ptrCast("b"), @ptrCast("a"), 1) > 0);
try std.testing.expect(strncmp(@ptrCast("\xff"), @ptrCast("\x02"), 1) > 0);
}

19
lib/c/strings.zig Normal file
View File

@ -0,0 +1,19 @@
const std = @import("std");
const common = @import("common.zig");
comptime {
@export(&bzero, .{ .name = "bzero", .linkage = common.linkage, .visibility = common.visibility });
}
fn bzero(s: *anyopaque, n: usize) callconv(.c) void {
const s_cast: [*]u8 = @ptrCast(s);
@memset(s_cast[0..n], 0);
}
test bzero {
var array: [10]u8 = [_]u8{ '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
var a = std.mem.zeroes([array.len]u8);
a[9] = '0';
bzero(&array[0], 9);
try std.testing.expect(std.mem.eql(u8, &array, &a));
}

View File

@ -1,26 +0,0 @@
<img src="https://aro.vexu.eu/aro-logo.svg" alt="Aro" width="120px"/>
# Aro
A C compiler with the goal of providing fast compilation and low memory usage with good diagnostics.
Aro is included as an alternative C frontend in the [Zig compiler](https://github.com/ziglang/zig)
for `translate-c` and eventually compiling C files by translating them to Zig first.
Aro is developed in https://github.com/Vexu/arocc and the Zig dependency is
updated from there when needed.
Currently most of standard C is supported up to C23 and as are many of the common
extensions from GNU, MSVC, and Clang
Basic code generation is supported for x86-64 linux and can produce a valid hello world:
```sh-session
$ cat hello.c
extern int printf(const char *restrict fmt, ...);
int main(void) {
printf("Hello, world!\n");
return 0;
}
$ zig build && ./zig-out/bin/arocc hello.c -o hello
$ ./hello
Hello, world!
```

View File

@ -5,12 +5,14 @@ pub const Driver = @import("aro/Driver.zig");
pub const Parser = @import("aro/Parser.zig");
pub const Preprocessor = @import("aro/Preprocessor.zig");
pub const Source = @import("aro/Source.zig");
pub const StringInterner = @import("aro/StringInterner.zig");
pub const Target = @import("aro/Target.zig");
pub const Tokenizer = @import("aro/Tokenizer.zig");
pub const Toolchain = @import("aro/Toolchain.zig");
pub const Tree = @import("aro/Tree.zig");
pub const Type = @import("aro/Type.zig");
pub const TypeMapper = @import("aro/StringInterner.zig").TypeMapper;
pub const target_util = @import("aro/target.zig");
pub const TypeStore = @import("aro/TypeStore.zig");
pub const QualType = TypeStore.QualType;
pub const Type = TypeStore.Type;
pub const Value = @import("aro/Value.zig");
const backend = @import("backend.zig");
@ -18,6 +20,7 @@ pub const Interner = backend.Interner;
pub const Ir = backend.Ir;
pub const Object = backend.Object;
pub const CallingConvention = backend.CallingConvention;
pub const Assembly = backend.Assembly;
pub const version_str = backend.version_str;
pub const version = backend.version;
@ -28,12 +31,11 @@ test {
_ = @import("aro/char_info.zig");
_ = @import("aro/Compilation.zig");
_ = @import("aro/Driver/Distro.zig");
_ = @import("aro/Driver/Filesystem.zig");
_ = @import("aro/Driver/GCCVersion.zig");
_ = @import("aro/InitList.zig");
_ = @import("aro/LangOpts.zig");
_ = @import("aro/Preprocessor.zig");
_ = @import("aro/target.zig");
_ = @import("aro/Target.zig");
_ = @import("aro/Tokenizer.zig");
_ = @import("aro/toolchains/Linux.zig");
_ = @import("aro/Value.zig");
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,62 +1,115 @@
const std = @import("std");
const Compilation = @import("Compilation.zig");
const Type = @import("Type.zig");
const TypeDescription = @import("Builtins/TypeDescription.zig");
const target_util = @import("target.zig");
const StringId = @import("StringInterner.zig").StringId;
const LangOpts = @import("LangOpts.zig");
const Parser = @import("Parser.zig");
const Target = @import("Target.zig");
const TypeStore = @import("TypeStore.zig");
const QualType = TypeStore.QualType;
const Builder = TypeStore.Builder;
const TypeDescription = @import("Builtins/TypeDescription.zig");
const properties = @import("Builtins/properties.zig");
const Properties = @import("Builtins/Properties.zig");
pub const Builtin = @import("Builtins/Builtin.zig").with(Properties);
const Expanded = struct {
ty: Type,
builtin: Builtin,
const BuiltinBase = struct {
param_str: [*:0]const u8,
language: properties.Language = .all_languages,
attributes: properties.Attributes = .{},
header: properties.Header = .none,
};
const NameToTypeMap = std.StringHashMapUnmanaged(Type);
const BuiltinTarget = struct {
param_str: [*:0]const u8,
language: properties.Language = .all_languages,
attributes: properties.Attributes = .{},
header: properties.Header = .none,
features: ?[*:0]const u8 = null,
};
const aarch64 = @import("Builtins/aarch64.zig").with(BuiltinTarget);
const amdgcn = @import("Builtins/amdgcn.zig").with(BuiltinTarget);
const arm = @import("Builtins/arm.zig").with(BuiltinTarget);
const bpf = @import("Builtins/bpf.zig").with(BuiltinTarget);
const common = @import("Builtins/common.zig").with(BuiltinBase);
const hexagon = @import("Builtins/hexagon.zig").with(BuiltinTarget);
const loongarch = @import("Builtins/loongarch.zig").with(BuiltinTarget);
const mips = @import("Builtins/mips.zig").with(BuiltinBase);
const nvptx = @import("Builtins/nvptx.zig").with(BuiltinTarget);
const powerpc = @import("Builtins/powerpc.zig").with(BuiltinTarget);
const riscv = @import("Builtins/riscv.zig").with(BuiltinTarget);
const s390x = @import("Builtins/s390x.zig").with(BuiltinTarget);
const ve = @import("Builtins/ve.zig").with(BuiltinBase);
const x86_64 = @import("Builtins/x86_64.zig").with(BuiltinTarget);
const x86 = @import("Builtins/x86.zig").with(BuiltinTarget);
const xcore = @import("Builtins/xcore.zig").with(BuiltinBase);
pub const Tag = union(enum) {
aarch64: aarch64.Tag,
amdgcn: amdgcn.Tag,
arm: arm.Tag,
bpf: bpf.Tag,
common: common.Tag,
hexagon: hexagon.Tag,
loongarch: loongarch.Tag,
mips: mips.Tag,
nvptx: nvptx.Tag,
powerpc: powerpc.Tag,
riscv: riscv.Tag,
s390x: s390x.Tag,
ve: ve.Tag,
x86_64: x86_64.Tag,
x86: x86.Tag,
xcore: xcore.Tag,
};
pub const Expanded = struct {
tag: Tag,
qt: QualType,
language: properties.Language = .all_languages,
attributes: properties.Attributes = .{},
header: properties.Header = .none,
};
const Builtins = @This();
_name_to_type_map: NameToTypeMap = .{},
_name_to_type_map: std.StringHashMapUnmanaged(Expanded) = .{},
pub fn deinit(b: *Builtins, gpa: std.mem.Allocator) void {
b._name_to_type_map.deinit(gpa);
}
fn specForSize(comp: *const Compilation, size_bits: u32) Type.Builder.Specifier {
var ty = Type{ .specifier = .short };
if (ty.sizeof(comp).? * 8 == size_bits) return .short;
fn specForSize(comp: *const Compilation, size_bits: u32) TypeStore.Builder.Specifier {
var qt: QualType = .short;
if (qt.bitSizeof(comp) == size_bits) return .short;
ty.specifier = .int;
if (ty.sizeof(comp).? * 8 == size_bits) return .int;
qt = .int;
if (qt.bitSizeof(comp) == size_bits) return .int;
ty.specifier = .long;
if (ty.sizeof(comp).? * 8 == size_bits) return .long;
qt = .long;
if (qt.bitSizeof(comp) == size_bits) return .long;
ty.specifier = .long_long;
if (ty.sizeof(comp).? * 8 == size_bits) return .long_long;
qt = .long_long;
if (qt.bitSizeof(comp) == size_bits) return .long_long;
unreachable;
}
fn createType(desc: TypeDescription, it: *TypeDescription.TypeIterator, comp: *const Compilation, allocator: std.mem.Allocator) !Type {
var builder: Type.Builder = .{ .error_on_invalid = true };
fn createType(desc: TypeDescription, it: *TypeDescription.TypeIterator, comp: *Compilation) !QualType {
var parser: Parser = undefined;
parser.comp = comp;
var builder: TypeStore.Builder = .{ .parser = &parser, .error_on_invalid = true };
var actual_suffix = desc.suffix;
var require_native_int32 = false;
var require_native_int64 = false;
for (desc.prefix) |prefix| {
switch (prefix) {
.L => builder.combine(undefined, .long, 0) catch unreachable,
.LL => {
builder.combine(undefined, .long, 0) catch unreachable;
builder.combine(undefined, .long, 0) catch unreachable;
},
.L => builder.combine(.long, 0) catch unreachable,
.LL => builder.combine(.long_long, 0) catch unreachable,
.LLL => {
switch (builder.specifier) {
.none => builder.specifier = .int128,
.signed => builder.specifier = .sint128,
.unsigned => builder.specifier = .uint128,
switch (builder.type) {
.none => builder.type = .int128,
.signed => builder.type = .sint128,
.unsigned => builder.type = .uint128,
else => unreachable,
}
},
@ -64,331 +117,285 @@ fn createType(desc: TypeDescription, it: *TypeDescription.TypeIterator, comp: *c
.W => require_native_int64 = true,
.N => {
std.debug.assert(desc.spec == .i);
if (!target_util.isLP64(comp.target)) {
builder.combine(undefined, .long, 0) catch unreachable;
if (!comp.target.isLP64()) {
builder.combine(.long, 0) catch unreachable;
}
},
.O => {
builder.combine(undefined, .long, 0) catch unreachable;
builder.combine(.long, 0) catch unreachable;
if (comp.target.os.tag != .opencl) {
builder.combine(undefined, .long, 0) catch unreachable;
builder.combine(.long, 0) catch unreachable;
}
},
.S => builder.combine(undefined, .signed, 0) catch unreachable,
.U => builder.combine(undefined, .unsigned, 0) catch unreachable,
.S => builder.combine(.signed, 0) catch unreachable,
.U => builder.combine(.unsigned, 0) catch unreachable,
.I => {
// Todo: compile-time constant integer
},
}
}
switch (desc.spec) {
.v => builder.combine(undefined, .void, 0) catch unreachable,
.b => builder.combine(undefined, .bool, 0) catch unreachable,
.c => builder.combine(undefined, .char, 0) catch unreachable,
.s => builder.combine(undefined, .short, 0) catch unreachable,
.v => builder.combine(.void, 0) catch unreachable,
.b => builder.combine(.bool, 0) catch unreachable,
.c => builder.combine(.char, 0) catch unreachable,
.s => builder.combine(.short, 0) catch unreachable,
.i => {
if (require_native_int32) {
builder.specifier = specForSize(comp, 32);
builder.type = specForSize(comp, 32);
} else if (require_native_int64) {
builder.specifier = specForSize(comp, 64);
builder.type = specForSize(comp, 64);
} else {
switch (builder.specifier) {
switch (builder.type) {
.int128, .sint128, .uint128 => {},
else => builder.combine(undefined, .int, 0) catch unreachable,
else => builder.combine(.int, 0) catch unreachable,
}
}
},
.h => builder.combine(undefined, .fp16, 0) catch unreachable,
.x => builder.combine(undefined, .float16, 0) catch unreachable,
.y => {
// Todo: __bf16
return .{ .specifier = .invalid };
},
.f => builder.combine(undefined, .float, 0) catch unreachable,
.h => builder.combine(.fp16, 0) catch unreachable,
.x => builder.combine(.float16, 0) catch unreachable,
.y => builder.combine(.bf16, 0) catch unreachable,
.f => builder.combine(.float, 0) catch unreachable,
.d => {
if (builder.specifier == .long_long) {
builder.specifier = .float128;
if (builder.type == .long_long) {
builder.type = .float128;
} else {
builder.combine(undefined, .double, 0) catch unreachable;
builder.combine(.double, 0) catch unreachable;
}
},
.z => {
std.debug.assert(builder.specifier == .none);
builder.specifier = Type.Builder.fromType(comp.types.size);
std.debug.assert(builder.type == .none);
builder.type = Builder.fromType(comp, comp.type_store.size);
},
.w => {
std.debug.assert(builder.specifier == .none);
builder.specifier = Type.Builder.fromType(comp.types.wchar);
std.debug.assert(builder.type == .none);
builder.type = Builder.fromType(comp, comp.type_store.wchar);
},
.F => {
std.debug.assert(builder.specifier == .none);
builder.specifier = Type.Builder.fromType(comp.types.ns_constant_string.ty);
},
.G => {
// Todo: id
return .{ .specifier = .invalid };
},
.H => {
// Todo: SEL
return .{ .specifier = .invalid };
},
.M => {
// Todo: struct objc_super
return .{ .specifier = .invalid };
std.debug.assert(builder.type == .none);
builder.type = Builder.fromType(comp, comp.type_store.ns_constant_string);
},
.a => {
std.debug.assert(builder.specifier == .none);
std.debug.assert(builder.type == .none);
std.debug.assert(desc.suffix.len == 0);
builder.specifier = Type.Builder.fromType(comp.types.va_list);
builder.type = Builder.fromType(comp, comp.type_store.va_list);
},
.A => {
std.debug.assert(builder.specifier == .none);
std.debug.assert(builder.type == .none);
std.debug.assert(desc.suffix.len == 0);
var va_list = comp.types.va_list;
if (va_list.isArray()) va_list.decayArray();
builder.specifier = Type.Builder.fromType(va_list);
var va_list = comp.type_store.va_list;
std.debug.assert(!va_list.is(comp, .array));
builder.type = Builder.fromType(comp, va_list);
},
.V => |element_count| {
std.debug.assert(desc.suffix.len == 0);
const child_desc = it.next().?;
const child_ty = try createType(child_desc, undefined, comp, allocator);
const arr_ty = try allocator.create(Type.Array);
arr_ty.* = .{
var child_desc = it.next().?;
actual_suffix = child_desc.suffix;
child_desc.suffix = &.{};
const elem_qt = try createType(child_desc, undefined, comp);
const vector_qt = try comp.type_store.put(comp.gpa, .{ .vector = .{
.elem = elem_qt,
.len = element_count,
.elem = child_ty,
};
const vector_ty: Type = .{ .specifier = .vector, .data = .{ .array = arr_ty } };
builder.specifier = Type.Builder.fromType(vector_ty);
} });
builder.type = .{ .other = vector_qt };
},
.q => {
// Todo: scalable vector
return .{ .specifier = .invalid };
.Q => {
// Todo: target builtin type
return .invalid;
},
.E => {
// Todo: ext_vector (OpenCL vector)
return .{ .specifier = .invalid };
return .invalid;
},
.X => |child| {
builder.combine(undefined, .complex, 0) catch unreachable;
builder.combine(.complex, 0) catch unreachable;
switch (child) {
.float => builder.combine(undefined, .float, 0) catch unreachable,
.double => builder.combine(undefined, .double, 0) catch unreachable,
.float => builder.combine(.float, 0) catch unreachable,
.double => builder.combine(.double, 0) catch unreachable,
.longdouble => {
builder.combine(undefined, .long, 0) catch unreachable;
builder.combine(undefined, .double, 0) catch unreachable;
builder.combine(.long, 0) catch unreachable;
builder.combine(.double, 0) catch unreachable;
},
}
},
.Y => {
std.debug.assert(builder.specifier == .none);
std.debug.assert(builder.type == .none);
std.debug.assert(desc.suffix.len == 0);
builder.specifier = Type.Builder.fromType(comp.types.ptrdiff);
builder.type = Builder.fromType(comp, comp.type_store.ptrdiff);
},
.P => {
std.debug.assert(builder.specifier == .none);
if (comp.types.file.specifier == .invalid) {
return comp.types.file;
std.debug.assert(builder.type == .none);
if (comp.type_store.file.isInvalid()) {
return comp.type_store.file;
}
builder.specifier = Type.Builder.fromType(comp.types.file);
builder.type = Builder.fromType(comp, comp.type_store.file);
},
.J => {
std.debug.assert(builder.specifier == .none);
std.debug.assert(builder.type == .none);
std.debug.assert(desc.suffix.len == 0);
if (comp.types.jmp_buf.specifier == .invalid) {
return comp.types.jmp_buf;
if (comp.type_store.jmp_buf.isInvalid()) {
return comp.type_store.jmp_buf;
}
builder.specifier = Type.Builder.fromType(comp.types.jmp_buf);
builder.type = Builder.fromType(comp, comp.type_store.jmp_buf);
},
.SJ => {
std.debug.assert(builder.specifier == .none);
std.debug.assert(builder.type == .none);
std.debug.assert(desc.suffix.len == 0);
if (comp.types.sigjmp_buf.specifier == .invalid) {
return comp.types.sigjmp_buf;
if (comp.type_store.sigjmp_buf.isInvalid()) {
return comp.type_store.sigjmp_buf;
}
builder.specifier = Type.Builder.fromType(comp.types.sigjmp_buf);
builder.type = Builder.fromType(comp, comp.type_store.sigjmp_buf);
},
.K => {
std.debug.assert(builder.specifier == .none);
if (comp.types.ucontext_t.specifier == .invalid) {
return comp.types.ucontext_t;
std.debug.assert(builder.type == .none);
if (comp.type_store.ucontext_t.isInvalid()) {
return comp.type_store.ucontext_t;
}
builder.specifier = Type.Builder.fromType(comp.types.ucontext_t);
builder.type = Builder.fromType(comp, comp.type_store.ucontext_t);
},
.p => {
std.debug.assert(builder.specifier == .none);
std.debug.assert(builder.type == .none);
std.debug.assert(desc.suffix.len == 0);
builder.specifier = Type.Builder.fromType(comp.types.pid_t);
builder.type = Builder.fromType(comp, comp.type_store.pid_t);
},
.@"!" => return .{ .specifier = .invalid },
}
for (desc.suffix) |suffix| {
for (actual_suffix) |suffix| {
switch (suffix) {
.@"*" => |address_space| {
_ = address_space; // TODO: handle address space
const elem_ty = try allocator.create(Type);
elem_ty.* = builder.finish(undefined) catch unreachable;
const ty = Type{
.specifier = .pointer,
.data = .{ .sub_type = elem_ty },
};
builder.qual = .{};
builder.specifier = Type.Builder.fromType(ty);
const pointer_qt = try comp.type_store.put(comp.gpa, .{ .pointer = .{
.child = builder.finish() catch unreachable,
.decayed = null,
} });
builder.@"const" = null;
builder.@"volatile" = null;
builder.restrict = null;
builder.type = .{ .other = pointer_qt };
},
.C => builder.qual.@"const" = 0,
.D => builder.qual.@"volatile" = 0,
.R => builder.qual.restrict = 0,
.C => builder.@"const" = 0,
.D => builder.@"volatile" = 0,
.R => builder.restrict = 0,
}
}
return builder.finish(undefined) catch unreachable;
return builder.finish() catch unreachable;
}
fn createBuiltin(comp: *const Compilation, builtin: Builtin, type_arena: std.mem.Allocator) !Type {
var it = TypeDescription.TypeIterator.init(builtin.properties.param_str);
fn createBuiltin(comp: *Compilation, param_str: [*:0]const u8) !QualType {
var it = TypeDescription.TypeIterator.init(param_str);
const ret_ty_desc = it.next().?;
if (ret_ty_desc.spec == .@"!") {
// Todo: handle target-dependent definition
}
const ret_ty = try createType(ret_ty_desc, &it, comp, type_arena);
const ret_ty = try createType(ret_ty_desc, &it, comp);
var param_count: usize = 0;
var params: [Builtin.max_param_count]Type.Func.Param = undefined;
var params: [32]TypeStore.Type.Func.Param = undefined;
while (it.next()) |desc| : (param_count += 1) {
params[param_count] = .{ .name_tok = 0, .ty = try createType(desc, &it, comp, type_arena), .name = .empty };
params[param_count] = .{ .name_tok = 0, .qt = try createType(desc, &it, comp), .name = .empty, .node = .null };
}
const duped_params = try type_arena.dupe(Type.Func.Param, params[0..param_count]);
const func = try type_arena.create(Type.Func);
func.* = .{
return comp.type_store.put(comp.gpa, .{ .func = .{
.return_type = ret_ty,
.params = duped_params,
};
return .{
.specifier = if (builtin.properties.isVarArgs()) .var_args_func else .func,
.data = .{ .func = func },
};
.kind = if (properties.isVarArgs(param_str)) .variadic else .normal,
.params = params[0..param_count],
} });
}
/// Asserts that the builtin has already been created
pub fn lookup(b: *const Builtins, name: []const u8) Expanded {
const builtin = Builtin.fromName(name).?;
const ty = b._name_to_type_map.get(name).?;
return .{
.builtin = builtin,
.ty = ty,
};
return b._name_to_type_map.get(name).?;
}
pub fn getOrCreate(b: *Builtins, comp: *Compilation, name: []const u8, type_arena: std.mem.Allocator) !?Expanded {
const ty = b._name_to_type_map.get(name) orelse {
const builtin = Builtin.fromName(name) orelse return null;
if (!comp.hasBuiltinFunction(builtin)) return null;
pub fn getOrCreate(b: *Builtins, comp: *Compilation, name: []const u8) !?Expanded {
if (b._name_to_type_map.get(name)) |expanded| return expanded;
try b._name_to_type_map.ensureUnusedCapacity(comp.gpa, 1);
const ty = try createBuiltin(comp, builtin, type_arena);
b._name_to_type_map.putAssumeCapacity(name, ty);
return .{
.builtin = builtin,
.ty = ty,
};
};
const builtin = Builtin.fromName(name).?;
return .{
.builtin = builtin,
.ty = ty,
};
}
pub const Iterator = struct {
index: u16 = 1,
name_buf: [Builtin.longest_name]u8 = undefined,
pub const Entry = struct {
/// Memory of this slice is overwritten on every call to `next`
name: []const u8,
builtin: Builtin,
};
pub fn next(self: *Iterator) ?Entry {
if (self.index > Builtin.data.len) return null;
const index = self.index;
const data_index = index - 1;
self.index += 1;
return .{
.name = Builtin.nameFromUniqueIndex(index, &self.name_buf),
.builtin = Builtin.data[data_index],
};
const builtin = fromName(comp, name) orelse return null;
if (builtin.features) |_| {
// TODO check features
}
try b._name_to_type_map.ensureUnusedCapacity(comp.gpa, 1);
const expanded: Expanded = .{
.tag = builtin.tag,
.qt = try createBuiltin(comp, builtin.param_str),
.attributes = builtin.attributes,
.header = builtin.header,
.language = builtin.language,
};
b._name_to_type_map.putAssumeCapacity(name, expanded);
return expanded;
}
pub const FromName = struct {
tag: Tag,
param_str: [*:0]const u8,
language: properties.Language = .all_languages,
attributes: properties.Attributes = .{},
header: properties.Header = .none,
features: ?[*:0]const u8 = null,
};
test Iterator {
var it = Iterator{};
var seen = std.StringHashMap(Builtin).init(std.testing.allocator);
defer seen.deinit();
var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena_state.deinit();
const arena = arena_state.allocator();
while (it.next()) |entry| {
const index = Builtin.uniqueIndex(entry.name).?;
var buf: [Builtin.longest_name]u8 = undefined;
const name_from_index = Builtin.nameFromUniqueIndex(index, &buf);
try std.testing.expectEqualStrings(entry.name, name_from_index);
if (seen.contains(entry.name)) {
std.debug.print("iterated over {s} twice\n", .{entry.name});
std.debug.print("current data: {}\n", .{entry.builtin});
std.debug.print("previous data: {}\n", .{seen.get(entry.name).?});
return error.TestExpectedUniqueEntries;
}
try seen.put(try arena.dupe(u8, entry.name), entry.builtin);
pub fn fromName(comp: *Compilation, name: []const u8) ?FromName {
if (fromNameExtra(name, .common)) |found| return found;
switch (comp.target.cpu.arch) {
.aarch64, .aarch64_be => if (fromNameExtra(name, .aarch64)) |found| return found,
.amdgcn => if (fromNameExtra(name, .amdgcn)) |found| return found,
.arm, .armeb, .thumb, .thumbeb => if (fromNameExtra(name, .arm)) |found| return found,
.bpfeb, .bpfel => if (fromNameExtra(name, .bpf)) |found| return found,
.hexagon => if (fromNameExtra(name, .hexagon)) |found| return found,
.loongarch32, .loongarch64 => if (fromNameExtra(name, .loongarch)) |found| return found,
.mips64, .mips64el, .mips, .mipsel => if (fromNameExtra(name, .mips)) |found| return found,
.nvptx, .nvptx64 => if (fromNameExtra(name, .nvptx)) |found| return found,
.powerpc64, .powerpc64le, .powerpc, .powerpcle => if (fromNameExtra(name, .powerpc)) |found| return found,
.riscv32, .riscv32be, .riscv64, .riscv64be => if (fromNameExtra(name, .riscv)) |found| return found,
.s390x => if (fromNameExtra(name, .s390x)) |found| return found,
.ve => if (fromNameExtra(name, .ve)) |found| return found,
.xcore => if (fromNameExtra(name, .xcore)) |found| return found,
.x86_64 => {
if (fromNameExtra(name, .x86_64)) |found| return found;
if (fromNameExtra(name, .x86)) |found| return found;
},
.x86 => if (fromNameExtra(name, .x86)) |found| return found,
else => {},
}
try std.testing.expectEqual(@as(usize, Builtin.data.len), seen.count());
return null;
}
test "All builtins" {
var comp = Compilation.init(std.testing.allocator, std.fs.cwd());
defer comp.deinit();
_ = try comp.generateBuiltinMacros(.include_system_defines);
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena.deinit();
fn fromNameExtra(name: []const u8, comptime arch: std.meta.Tag(Tag)) ?FromName {
const list = @field(@This(), @tagName(arch));
const tag = list.tagFromName(name) orelse return null;
const builtin = list.data[@intFromEnum(tag)];
const type_arena = arena.allocator();
var builtin_it = Iterator{};
while (builtin_it.next()) |entry| {
const name = try type_arena.dupe(u8, entry.name);
if (try comp.builtins.getOrCreate(&comp, name, type_arena)) |func_ty| {
const get_again = (try comp.builtins.getOrCreate(&comp, name, std.testing.failing_allocator)).?;
const found_by_lookup = comp.builtins.lookup(name);
try std.testing.expectEqual(func_ty.builtin.tag, get_again.builtin.tag);
try std.testing.expectEqual(func_ty.builtin.tag, found_by_lookup.builtin.tag);
}
}
return .{
.tag = @unionInit(Tag, @tagName(arch), tag),
.param_str = builtin.param_str,
.header = builtin.header,
.language = builtin.language,
.attributes = builtin.attributes,
.features = if (@hasField(@TypeOf(builtin), "features")) builtin.features else null,
};
}
test "Allocation failures" {
const Test = struct {
fn testOne(allocator: std.mem.Allocator) !void {
var comp = Compilation.init(allocator, std.fs.cwd());
defer comp.deinit();
_ = try comp.generateBuiltinMacros(.include_system_defines);
var arena = std.heap.ArenaAllocator.init(comp.gpa);
defer arena.deinit();
test "all builtins" {
const list_names = comptime std.meta.fieldNames(Tag);
inline for (list_names) |list_name| {
const list = @field(Builtins, list_name);
for (list.data, 0..) |builtin, index| {
{
var it = TypeDescription.TypeIterator.init(builtin.param_str);
while (it.next()) |_| {}
}
if (@hasField(@TypeOf(builtin), "features")) {
const corrected_name = comptime if (std.mem.eql(u8, list_name, "x86_64")) "x86" else list_name;
const features = &@field(std.Target, corrected_name).all_features;
const type_arena = arena.allocator();
const feature_string = builtin.features orelse continue;
var it = std.mem.tokenizeAny(u8, std.mem.span(feature_string), "()|,");
const num_builtins = 40;
var builtin_it = Iterator{};
for (0..num_builtins) |_| {
const entry = builtin_it.next().?;
_ = try comp.builtins.getOrCreate(&comp, entry.name, type_arena);
outer: while (it.next()) |feature| {
for (features) |valid_feature| {
if (std.mem.eql(u8, feature, valid_feature.name)) continue :outer;
}
std.debug.panic("unknown feature {s} on {t}\n", .{ feature, @as(list.Tag, @enumFromInt(index)) });
}
}
}
};
try std.testing.checkAllAllocationFailures(std.testing.allocator, Test.testOne, .{});
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,143 +0,0 @@
const std = @import("std");
const Properties = @This();
param_str: []const u8,
language: Language = .all_languages,
attributes: Attributes = Attributes{},
header: Header = .none,
target_set: TargetSet = TargetSet.initOne(.basic),
/// Header which must be included for a builtin to be available
pub const Header = enum {
none,
/// stdio.h
stdio,
/// stdlib.h
stdlib,
/// setjmpex.h
setjmpex,
/// stdarg.h
stdarg,
/// string.h
string,
/// ctype.h
ctype,
/// wchar.h
wchar,
/// setjmp.h
setjmp,
/// malloc.h
malloc,
/// strings.h
strings,
/// unistd.h
unistd,
/// pthread.h
pthread,
/// math.h
math,
/// complex.h
complex,
/// Blocks.h
blocks,
};
/// Languages in which a builtin is available
pub const Language = enum {
all_languages,
all_ms_languages,
all_gnu_languages,
gnu_lang,
};
pub const Attributes = packed struct {
/// Function does not return
noreturn: bool = false,
/// Function has no side effects
pure: bool = false,
/// Function has no side effects and does not read memory
@"const": bool = false,
/// Signature is meaningless; use custom typecheck
custom_typecheck: bool = false,
/// A declaration of this builtin should be recognized even if the type doesn't match the specified signature.
allow_type_mismatch: bool = false,
/// this is a libc/libm function with a '__builtin_' prefix added.
lib_function_with_builtin_prefix: bool = false,
/// this is a libc/libm function without a '__builtin_' prefix. This builtin is disableable by '-fno-builtin-foo'
lib_function_without_prefix: bool = false,
/// Function returns twice (e.g. setjmp)
returns_twice: bool = false,
/// Nature of the format string passed to this function
format_kind: enum(u3) {
/// Does not take a format string
none,
/// this is a printf-like function whose Nth argument is the format string
printf,
/// function is like vprintf in that it accepts its arguments as a va_list rather than through an ellipsis
vprintf,
/// this is a scanf-like function whose Nth argument is the format string
scanf,
/// the function is like vscanf in that it accepts its arguments as a va_list rather than through an ellipsis
vscanf,
} = .none,
/// Position of format string argument. Only meaningful if format_kind is not .none
format_string_position: u5 = 0,
/// if false, arguments are not evaluated
eval_args: bool = true,
/// no side effects and does not read memory, but only when -fno-math-errno and FP exceptions are ignored
const_without_errno_and_fp_exceptions: bool = false,
/// no side effects and does not read memory, but only when FP exceptions are ignored
const_without_fp_exceptions: bool = false,
/// this function can be constant evaluated by the frontend
const_evaluable: bool = false,
};
pub const Target = enum {
/// Supported on all targets
basic,
aarch64,
aarch64_neon_sve_bridge,
aarch64_neon_sve_bridge_cg,
amdgpu,
arm,
bpf,
hexagon,
hexagon_dep,
hexagon_map_custom_dep,
loong_arch,
mips,
neon,
nvptx,
ppc,
riscv,
riscv_vector,
sve,
systemz,
ve,
vevl_gen,
webassembly,
x86,
x86_64,
xcore,
};
/// Targets for which a builtin is enabled
pub const TargetSet = std.enums.EnumSet(Target);
pub fn isVarArgs(properties: Properties) bool {
return properties.param_str[properties.param_str.len - 1] == '.';
}

View File

@ -13,10 +13,10 @@ pub const Component = union(enum) {
};
pub const ComponentIterator = struct {
str: []const u8,
str: [*:0]const u8,
idx: usize,
pub fn init(str: []const u8) ComponentIterator {
pub fn init(str: [*:0]const u8) ComponentIterator {
return .{
.str = str,
.idx = 0,
@ -30,8 +30,8 @@ pub const ComponentIterator = struct {
}
pub fn next(self: *ComponentIterator) ?Component {
if (self.idx == self.str.len) return null;
const c = self.str[self.idx];
if (c == 0) return null;
self.idx += 1;
switch (c) {
'L' => {
@ -68,18 +68,14 @@ pub const ComponentIterator = struct {
'z' => return .{ .spec = .z },
'w' => return .{ .spec = .w },
'F' => return .{ .spec = .F },
'G' => return .{ .spec = .G },
'H' => return .{ .spec = .H },
'M' => return .{ .spec = .M },
'a' => return .{ .spec = .a },
'A' => return .{ .spec = .A },
'V', 'q', 'E' => {
'V', 'E' => {
const start = self.idx;
while (std.ascii.isDigit(self.str[self.idx])) : (self.idx += 1) {}
const count = std.fmt.parseUnsigned(u32, self.str[start..self.idx], 10) catch unreachable;
return switch (c) {
'V' => .{ .spec = .{ .V = count } },
'q' => .{ .spec = .{ .q = count } },
'E' => .{ .spec = .{ .E = count } },
else => unreachable,
};
@ -103,16 +99,12 @@ pub const ComponentIterator = struct {
'p' => return .{ .spec = .p },
'.' => {
// can only appear at end of param string; indicates varargs function
std.debug.assert(self.idx == self.str.len);
std.debug.assert(self.str[self.idx] == 0);
return null;
},
'!' => {
std.debug.assert(self.str.len == 1);
return .{ .spec = .@"!" };
},
'*' => {
if (self.idx < self.str.len and std.ascii.isDigit(self.str[self.idx])) {
if (std.ascii.isDigit(self.str[self.idx])) {
defer self.idx += 1;
const addr_space = self.str[self.idx] - '0';
return .{ .suffix = .{ .@"*" = addr_space } };
@ -123,6 +115,14 @@ pub const ComponentIterator = struct {
'C' => return .{ .suffix = .C },
'D' => return .{ .suffix = .D },
'R' => return .{ .suffix = .R },
'Q' => {
defer self.idx += 1;
switch (self.str[self.idx]) {
'a' => return .{ .spec = .{ .Q = .aarch64_svcount_t } },
'b' => return .{ .spec = .{ .Q = .amdgpu_buffer_rsrc_t } },
else => unreachable,
}
},
else => unreachable,
}
return null;
@ -130,13 +130,13 @@ pub const ComponentIterator = struct {
};
pub const TypeIterator = struct {
param_str: []const u8,
param_str: [*:0]const u8,
prefix: [4]Prefix,
spec: Spec,
suffix: [4]Suffix,
idx: usize,
pub fn init(param_str: []const u8) TypeIterator {
pub fn init(param_str: [*:0]const u8) TypeIterator {
return .{
.param_str = param_str,
.prefix = undefined,
@ -176,7 +176,7 @@ pub const TypeIterator = struct {
_ = it.next();
}
if (maybe_spec) |spec| {
return TypeDescription{
return .{
.prefix = self.prefix[0..prefix_count],
.spec = spec,
.suffix = self.suffix[0..suffix_count],
@ -236,20 +236,17 @@ const Spec = union(enum) {
w,
/// constant CFString
F,
/// id
G,
/// SEL
H,
/// struct objc_super
M,
/// __builtin_va_list
a,
/// "reference" to __builtin_va_list
A,
/// Vector, followed by the number of elements and the base type.
V: u32,
/// Scalable vector, followed by the number of elements and the base type.
q: u32,
/// target builtin type, followed by a character to distinguish the builtin type
Q: enum {
aarch64_svcount_t,
amdgpu_buffer_rsrc_t,
},
/// ext_vector, followed by the number of elements and the base type.
E: u32,
/// _Complex, followed by the base type.
@ -270,8 +267,6 @@ const Spec = union(enum) {
K,
/// pid_t
p,
/// Used to indicate a builtin with target-dependent param types. Must appear by itself
@"!",
};
const Suffix = union(enum) {

1150
lib/compiler/aro/aro/Builtins/aarch64.zig vendored Normal file

File diff suppressed because it is too large Load Diff

2851
lib/compiler/aro/aro/Builtins/amdgcn.zig vendored Normal file

File diff suppressed because it is too large Load Diff

1076
lib/compiler/aro/aro/Builtins/arm.zig vendored Normal file

File diff suppressed because it is too large Load Diff

231
lib/compiler/aro/aro/Builtins/bpf.zig vendored Normal file
View File

@ -0,0 +1,231 @@
//! Autogenerated by GenerateDef from src/aro/Builtins/bpf.def, do not edit
// zig fmt: off
const std = @import("std");
pub fn with(comptime Properties: type) type {
return struct {
/// Integer starting at 0 derived from the unique index,
/// corresponds with the data array index.
pub const Tag = enum(u16) { __builtin_btf_type_id,
__builtin_preserve_enum_value,
__builtin_preserve_field_info,
__builtin_preserve_type_info,
};
pub fn fromName(name: []const u8) ?Properties {
const data_index = tagFromName(name) orelse return null;
return data[@intFromEnum(data_index)];
}
pub fn tagFromName(name: []const u8) ?Tag {
const unique_index = uniqueIndex(name) orelse return null;
return @enumFromInt(unique_index - 1);
}
pub fn fromTag(tag: Tag) Properties {
return data[@intFromEnum(tag)];
}
pub fn nameFromTagIntoBuf(tag: Tag, name_buf: []u8) []u8 {
std.debug.assert(name_buf.len >= longest_name);
const unique_index = @intFromEnum(tag) + 1;
return nameFromUniqueIndex(unique_index, name_buf);
}
pub fn nameFromTag(tag: Tag) NameBuf {
var name_buf: NameBuf = undefined;
const unique_index = @intFromEnum(tag) + 1;
const name = nameFromUniqueIndex(unique_index, &name_buf.buf);
name_buf.len = @intCast(name.len);
return name_buf;
}
pub const NameBuf = struct {
buf: [longest_name]u8 = undefined,
len: std.math.IntFittingRange(0, longest_name),
pub fn span(self: *const NameBuf) []const u8 {
return self.buf[0..self.len];
}
};
pub fn exists(name: []const u8) bool {
if (name.len < shortest_name or name.len > longest_name) return false;
var index: u16 = 0;
for (name) |c| {
index = findInList(dafsa[index].child_index, c) orelse return false;
}
return dafsa[index].end_of_word;
}
pub const shortest_name = 21;
pub const longest_name = 29;
/// Search siblings of `first_child_index` for the `char`
/// If found, returns the index of the node within the `dafsa` array.
/// Otherwise, returns `null`.
pub fn findInList(first_child_index: u16, char: u8) ?u16 {
@setEvalBranchQuota(8);
var index = first_child_index;
while (true) {
if (dafsa[index].char == char) return index;
if (dafsa[index].end_of_list) return null;
index += 1;
}
unreachable;
}
/// Returns a unique (minimal perfect hash) index (starting at 1) for the `name`,
/// or null if the name was not found.
pub fn uniqueIndex(name: []const u8) ?u16 {
if (name.len < shortest_name or name.len > longest_name) return null;
var index: u16 = 0;
var node_index: u16 = 0;
for (name) |c| {
const child_index = findInList(dafsa[node_index].child_index, c) orelse return null;
var sibling_index = dafsa[node_index].child_index;
while (true) {
const sibling_c = dafsa[sibling_index].char;
std.debug.assert(sibling_c != 0);
if (sibling_c < c) {
index += dafsa[sibling_index].number;
}
if (dafsa[sibling_index].end_of_list) break;
sibling_index += 1;
}
node_index = child_index;
if (dafsa[node_index].end_of_word) index += 1;
}
if (!dafsa[node_index].end_of_word) return null;
return index;
}
/// Returns a slice of `buf` with the name associated with the given `index`.
/// This function should only be called with an `index` that
/// is already known to exist within the `dafsa`, e.g. an index
/// returned from `uniqueIndex`.
pub fn nameFromUniqueIndex(index: u16, buf: []u8) []u8 {
std.debug.assert(index >= 1 and index <= data.len);
var node_index: u16 = 0;
var count: u16 = index;
var w = std.Io.Writer.fixed(buf);
while (true) {
var sibling_index = dafsa[node_index].child_index;
while (true) {
if (dafsa[sibling_index].number > 0 and dafsa[sibling_index].number < count) {
count -= dafsa[sibling_index].number;
} else {
w.writeByte(dafsa[sibling_index].char) catch unreachable;
node_index = sibling_index;
if (dafsa[node_index].end_of_word) {
count -= 1;
}
break;
}
if (dafsa[sibling_index].end_of_list) break;
sibling_index += 1;
}
if (count == 0) break;
}
return w.buffered();
}
const Node = packed struct {
char: u8,
/// Nodes are numbered with "an integer which gives the number of words that
/// would be accepted by the automaton starting from that state." This numbering
/// allows calculating "a one-to-one correspondence between the integers 1 to L
/// (L is the number of words accepted by the automaton) and the words themselves."
///
/// Essentially, this allows us to have a minimal perfect hashing scheme such that
/// it's possible to store & lookup the properties of each builtin using a separate array.
number: std.math.IntFittingRange(0, data.len),
/// If true, this node is the end of a valid builtin.
/// Note: This does not necessarily mean that this node does not have child nodes.
end_of_word: bool,
/// If true, this node is the end of a sibling list.
/// If false, then (index + 1) will contain the next sibling.
end_of_list: bool,
/// Index of the first child of this node.
child_index: u16,
};
const dafsa = [_]Node{
.{ .char = 0, .end_of_word = false, .end_of_list = true, .number = 0, .child_index = 1 },
.{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 4, .child_index = 2 },
.{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 4, .child_index = 3 },
.{ .char = 'b', .end_of_word = false, .end_of_list = true, .number = 4, .child_index = 4 },
.{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 4, .child_index = 5 },
.{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 4, .child_index = 6 },
.{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 4, .child_index = 7 },
.{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 4, .child_index = 8 },
.{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 4, .child_index = 9 },
.{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 4, .child_index = 10 },
.{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 4, .child_index = 11 },
.{ .char = 'b', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 13 },
.{ .char = 'p', .end_of_word = false, .end_of_list = true, .number = 3, .child_index = 14 },
.{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 15 },
.{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 3, .child_index = 16 },
.{ .char = 'f', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 17 },
.{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 3, .child_index = 18 },
.{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 19 },
.{ .char = 's', .end_of_word = false, .end_of_list = true, .number = 3, .child_index = 20 },
.{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 21 },
.{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 3, .child_index = 22 },
.{ .char = 'y', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 23 },
.{ .char = 'r', .end_of_word = false, .end_of_list = true, .number = 3, .child_index = 24 },
.{ .char = 'p', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 25 },
.{ .char = 'v', .end_of_word = false, .end_of_list = true, .number = 3, .child_index = 26 },
.{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 27 },
.{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 3, .child_index = 28 },
.{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 29 },
.{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 3, .child_index = 30 },
.{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 33 },
.{ .char = 'e', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 34 },
.{ .char = 'f', .end_of_word = false, .end_of_list = false, .number = 1, .child_index = 35 },
.{ .char = 't', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 36 },
.{ .char = 'd', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },
.{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 37 },
.{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 38 },
.{ .char = 'y', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 39 },
.{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 40 },
.{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 41 },
.{ .char = 'p', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 42 },
.{ .char = 'm', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 43 },
.{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 44 },
.{ .char = 'e', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 45 },
.{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 46 },
.{ .char = 'd', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 45 },
.{ .char = '_', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 47 },
.{ .char = 'v', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 48 },
.{ .char = 'i', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 49 },
.{ .char = 'a', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 50 },
.{ .char = 'n', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 51 },
.{ .char = 'l', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 52 },
.{ .char = 'f', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 53 },
.{ .char = 'u', .end_of_word = false, .end_of_list = true, .number = 1, .child_index = 54 },
.{ .char = 'o', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },
.{ .char = 'e', .end_of_word = true, .end_of_list = true, .number = 1, .child_index = 0 },
};
pub const data = blk: {
@setEvalBranchQuota(36);
break :blk [_]Properties{
.{ .param_str = "LUi.", .attributes = .{ .custom_typecheck = true } },
.{ .param_str = "Li.", .attributes = .{ .custom_typecheck = true } },
.{ .param_str = "Ui.", .attributes = .{ .custom_typecheck = true } },
.{ .param_str = "LUi.", .attributes = .{ .custom_typecheck = true } },
};
};
};
}

Some files were not shown because too many files have changed in this diff Show More