Commit graph

36452 commits

Author SHA1 Message Date
Jacob Young
4f7a3c23e7 Elf2: improve dynamic linking support 2026-01-02 23:47:59 -05:00
Carl Åstholm
c9fa8e46df Use mmap std.heap.page_allocator impl when compiling for Wasm + libc
When linking libc, it should be the libc that manages the heap. The main
Wasm memory might have been configured as non-growable, which makes
`WasmAllocator` a poor default and causes the common `DebugAllocator`
use case fail with OOM errors unless the user uses `std_options` to
override the default page allocator. Additionally, on Emscripten,
growing Wasm memory without notifying the JS glue code will cause array
buffers to get detached and lead to spurious crashes.
2026-01-02 16:55:11 -08:00
jedisct1
1bf29757d9 Merge pull request 'crypto.edwards25519: optimize rejectLowOrder' (#30650) from jedisct1/zig:ed25519rej into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30650
2026-01-02 23:37:12 +01:00
e820
4cee1f7b9a Forgo const qualifiers on register locals generated by asm (#30645)
See https://codeberg.org/ziglang/zig/issues/30637 for details.

Works around https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86673

Co-authored-by: Laurin-Luis Lehning <65224843+e820@users.noreply.github.com>
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30645
Reviewed-by: Andrew Kelley <andrewrk@noreply.codeberg.org>
Co-authored-by: e820 <e820@noreply.codeberg.org>
Co-committed-by: e820 <e820@noreply.codeberg.org>
2026-01-02 23:16:08 +01:00
Meghan Denny
53ebfde6b4 std: use decl literals to improve endian ergonomics 2026-01-01 20:34:55 -08:00
hixuyuming
0c5f879b98 Fix: tryFindProgram fails when $PATH contains relative paths (#30619)
Fixes a issue in tryFindProgram where it would fail if the PATH environment variable contained relative paths, due to its incorrect assumption that the full_path argument is always absolute path.

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30619
Co-authored-by: hixuyuming <hixuyuming@gmail.com>
Co-committed-by: hixuyuming <hixuyuming@gmail.com>
2026-01-02 02:51:16 +01:00
Frank Denis
1baa127c65 crypto.edwards25519: optimize rejectLowOrder
Reject low-order points by checking projective coordinates directly
instead of using affine coordinates.

Equivalent, but saves CPU cycles (~254 field multiplications total
before, 3 field multiplications after).
2026-01-01 23:56:20 +01:00
Rick Calixte
2bd02883c7 git.zig: Process data packets of all lengths, discarding unrecognized packets
This addresses the regression specific to GitHub's chunked transfer encoding
for larger repositories while leaving existing functionality intact.
2026-01-01 20:37:52 +01:00
Ben Krieger
4ad8bc3413 Make Io.Mutex an extern struct 2025-12-31 16:40:34 -05:00
Steeve Morin
9d497d0d77 Update posix.getRandomBytesDevURandom to use linux.statx
Fixes #30631
2025-12-31 20:20:51 +01:00
Andrew Kelley
e956948f99 std: remove fs.getAppDataDir with no replacement
This API is a bit too opinionated for the Zig standard library.
Applications should contain this logic instead.
2025-12-30 16:21:25 -08:00
PeterMcKinnis
96ba0ab930 fix lockStderr API calls in test_runner fuzz code 2025-12-30 15:09:17 -05:00
Andrew Kelley
1eb8fe7c61 Merge pull request 'bsd-futex' (#30626) from mikdusan/zig:bsd-futex into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30626
Reviewed-by: Andrew Kelley <andrewrk@noreply.codeberg.org>
2025-12-30 20:24:00 +01:00
Andrew Kelley
2a02c7a0d5 std.Io.Group: async and concurrent support Cancelable results
Now, the return type of functions spawned with `Group.async` and
`Group.concurrent` may be anything that coerces to `Io.Cancelable!void`.

Before this commit, group tasks were the only exception to the rule
"error.Canceled should never be swallowed". Now, there is no exception,
and it is enforced with an assertion upon closure completion.

Finally, fixes a case of swallowing error.Canceled in the compiler,
solving a TODO.

There are three ways to handle `error.Canceled`. In order of most
common:
1. Propagate it
2. After receiving it, io.recancel() and then don't propagate it
3. Make it unreachable with io.swapCancelProtection()
2025-12-29 22:51:06 -08:00
Andrew Kelley
2adfd4d107 std.Io: fix and improve Group API
Rename `wait` to `await` to be consistent with Future API. The
convention here is that this set of functionality goes together:
* async/concurrent
* await/cancel

Also rename Select `wait` to `await` for the same reason.

`Group.await` now can return `error.Canceled`. Furthermore,
`Group.await` does not auto-propagate cancelation. Instead, users should
follow the pattern of `defer group.cancel(io);` after initialization,
and doing `try group.await(io);` at the end of the success path.
Advanced logic can choose to do something other than this pattern in the
event of cancelation.

Additionally, fixes a bug in `std.Io.Threaded` future await, in which it
swallowed an `error.Canceled`. Now if a task is canceled while awaiting
a future, after propagating the cancel request, it also recancels,
meaning that the awaiting task will properly detect its own cancelation
at the next cancelation point.

Furthermore, fixes a bug in the compiler where `error.Canceled` was
being swallowed in `dispatchPrelinkWork`.

Finally, fixes std.crypto code that inappropriately used
`catch unreachable` in response to cancelation without even so much as a
comment explaining why it was believed to be unreachable. Now, those
functions have `error.Canceled` in the error set and propagate
cancelation properly.

With this way of doing things, `Group.await` has a nice property: even if
all tasks in the group are CPU bound and without cancelation points, the
`Group.await` can still be canceled. In such case, the task that was
waiting for `await` wakes up with a chance to do some more resource
cleanup tasks, such as canceling more things, before entering the
deferred `Group.cancel` call at which point it has to suspend until the
canceled but uninterruptible CPU bound tasks complete.

closes #30601
2025-12-29 22:47:34 -08:00
Michael Dusan
4b26c49076
dragonfly: make test lib/std/std.zig pass 2025-12-29 22:29:56 -05:00
Michael Dusan
3c851ec396
dragonfly: Io.Threaded: use futex 2025-12-29 22:29:48 -05:00
Michael Dusan
09f06082f0
openbsd: make test lib/std/std.zig pass
* According to OpenBSD's getdents docs indicate the buffer must be
  greater or or equal to the block size associated with the file and to
  refer to stat(2).
* Use S_BLKSIZE, which is 512, instead of @sizeOf(std.c.dirent), which is 280.
* Oddly the other BSDs are not this picky.
2025-12-29 21:40:02 -05:00
Michael Dusan
1ea2d5692d
openbsd: init Io.Threaded.argv0 for tests
Some tests (eg. std.process.openExecutable) require argv0 for OpenBSD,
otherwise error.OperationUnsupported is encountered.
2025-12-29 21:06:08 -05:00
Michael Dusan
51728f1053
openbsd: add timespec OMIT and NOW definitions 2025-12-29 21:06:08 -05:00
Michael Dusan
ceb59b48b4
openbsd: Io.Threaded: use futex 2025-12-29 21:06:08 -05:00
Andrew Kelley
f862762f09 std: fix Progress flickering
move some of the clearing logic from std.Io.Threaded to the Io interface
layer, thus allowing it to be skipped by advanced usage code via calling
the vtable functions directly.

then take advantage of this in std.Progress to avoid clearing the
terminal twice.

closes #30611
2025-12-29 12:49:43 -08:00
Sivecano
ec13e8eaaa emit error and crash when trying to use the broken -femit-h option (#30229)
I know the real solution would be to fix this.
But this is still way better than unexplained bugs.

I hope this is the correct way to do this.
I've tested it and it seems to work as advertised.
This may not fix it in the build system... but yk, better than nothing.

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30229
Reviewed-by: Andrew Kelley <andrewrk@noreply.codeberg.org>
Co-authored-by: Sivecano <sivecano@gmail.com>
Co-committed-by: Sivecano <sivecano@gmail.com>
2025-12-29 05:55:03 +01:00
Andrew Kelley
744e22b18a build_runner: re-order the help menu
closes #30615
2025-12-28 19:53:42 -08:00
Steven Casper
8d4a9119b8 Properly support passing a packed struct to byteSwapAllFields (#30571)
Reopening [#25698](https://github.com/ziglang/zig/pull/25698)
Closes [#25054](https://github.com/ziglang/zig/issues/25054)

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30571
Reviewed-by: Andrew Kelley <andrewrk@noreply.codeberg.org>
Co-authored-by: Steven Casper <sebastiancasper3@gmail.com>
Co-committed-by: Steven Casper <sebastiancasper3@gmail.com>
2025-12-29 02:36:11 +01:00
Lukas Lalinsky
e8a2e6578a Add std.Io.net.Stream.shutdown 2025-12-29 02:20:37 +01:00
nyx-xyn
f2f474fc78 std.Io.Dir: pass io to Walker.leave 2025-12-29 00:36:57 +01:00
Michael Dusan
6ca1c88e46 Merge pull request 'minor bsd fixups' (#30609) from mikdusan/zig:bsd into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30609
Reviewed-by: Andrew Kelley <andrewrk@noreply.codeberg.org>
2025-12-28 23:23:54 +01:00
Michael Dusan
ac4c9b8fb2 openbsd: initialize Io.Threaded.argv0 2025-12-28 20:20:43 +01:00
Michael Dusan
b335e52ed6 openbsd: fixup nullz handling in Io.Threaded 2025-12-28 20:20:43 +01:00
Michael Dusan
0ae629ee22 netbsd: use correct symbol for wait4 2025-12-28 20:20:43 +01:00
Andrew Kelley
6984992153 Merge pull request 'std.Io.File.Stat: make access time optional' (#30607) from atime into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30607
2025-12-27 23:35:51 +01:00
unerr
2e73288e63 Fix #30167: std.mem.window returns slices smaller or equal to size 2025-12-27 20:45:26 +01:00
Andrew Kelley
6bf9499c0c Merge pull request 'Optimize {write,take}Leb128' (#30012) from NicoElbers/zig:leb-perf into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30012
Reviewed-by: Andrew Kelley <andrewrk@noreply.codeberg.org>
2025-12-27 20:43:13 +01:00
Lucas Santos
ef77cc0de1 Fixes doc comment of Futex.wait
On Windows, changing the value at the target address is not sufficient, there needs to be a wake call.
From [MSDN](https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-waitonaddress):
> If the value at Address differs from the value at CompareAddress, the function returns immediately. If the values are the same, the function does not return until another thread in the same process signals that the value at Address has changed by calling WakeByAddressSingle or WakeByAddressAll or the timeout elapses, whichever comes first.
We could note that this behavior is only observed on Windows. However, if we want the function to have consistent behavior across all platforms, we should require users to call wake. On platforms where changing the value is sufficient to wake the waiting thread, an unblocking of the thread without a matching wake would just be considered a spurious wake.
2025-12-27 20:40:19 +01:00
Aaron Ang
9db3e23e80 std.math.big: require sufficient capacity for aliased params 2025-12-27 20:38:33 +01:00
Andrew Kelley
212968c574 std.Io.Threaded: handle missing atime from statx 2025-12-27 11:18:16 -08:00
Andrew Kelley
c0809c9b68 std: add more timespec OMIT and NOW definitions 2025-12-27 11:08:56 -08:00
Andrew Kelley
10e72a8cad std.Io.Threaded: implement fileSetTimestamps on WASI 2025-12-27 11:01:16 -08:00
Andrew Kelley
dd98188ce0 std.Io.Threaded: mostly implement fileSetTimestamps for Windows
it's still missing the case of setting to now (which was also not
implemented before)
2025-12-27 10:52:17 -08:00
Andrew Kelley
a7c9d11b28 std.Io: make file access time optional
Some filesystems, such as ZFS, do not report atime. It's pretty useless
in general, so make it an optional field in File.Stat.

Also take the opportunity to make setting timestamps API more flexible
and match the APIs widely available, which have UTIME_OMIT and UTIME_NOW
constants that can be independently set for both fields.

This is needed to handle smoothly the case when atime is null.
2025-12-27 10:40:24 -08:00
Andrew Kelley
e55e6b5528 Merge pull request 'std: migrate all fs APIs to Io' (#30232) from std.Io-fs into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30232
2025-12-27 14:10:46 +01:00
Matthew Lugg
60a1ba0a8f
stage1: add more wasi.c stubs
Because `std.Io` forces analysis of unused functions in the vtable,
there are now references to 4 more WASI functions, even though the
compiler does not actually call them at runtime.

Therefore, these new stubs fix the bootstrap process after a zig1.wasm
update (though this branch does *not* update zig1.wasm).
2025-12-27 10:23:46 +00:00
Andrew Kelley
d8460910b4 std.Io.Threaded: init stderr_writer in streaming mode 2025-12-26 19:58:56 -08:00
Andrew Kelley
2fb46b0ed9 std.Progress: recancel in start()
one must never swallow error.Canceled; if you can't handle it, either
temporarily disable it for the function, or recancel if you catch it.
2025-12-26 19:58:56 -08:00
Andrew Kelley
e08837b0fe build.zig: simplify max_rss compiler_rt on windows
I observed this take more memory than the previous declaration
2025-12-26 19:58:56 -08:00
Ryan Liptak
e3f36d0d81 Fix a few standalone tests on Windows 2025-12-26 19:58:56 -08:00
Ryan Liptak
4f8aa8213d Fix for compile error in resinator 2025-12-26 19:58:56 -08:00
Ryan Liptak
ec5c2d4ce3 Skip posix-specific standalone test on Windows 2025-12-26 19:58:56 -08:00
Ryan Liptak
447f80c0cc Delete test_symlink in standalone/posix, it's fully redundant
See readlink tests in std/fs/test.zig
2025-12-26 19:58:56 -08:00