Compare commits

...

2722 commits

Author SHA1 Message Date
Ryan Liptak
f16eb18ce8 Use / as path separator when writing tar files
Some checks are pending
ci / aarch64-freebsd-debug (push) Waiting to run
ci / aarch64-freebsd-release (push) Waiting to run
ci / aarch64-linux-debug (push) Waiting to run
ci / aarch64-linux-release (push) Waiting to run
ci / aarch64-netbsd-debug (push) Waiting to run
ci / aarch64-netbsd-release (push) Waiting to run
ci / aarch64-macos-debug (push) Waiting to run
ci / aarch64-macos-release (push) Waiting to run
ci / loongarch64-linux-debug (push) Waiting to run
ci / loongarch64-linux-release (push) Waiting to run
ci / powerpc64le-linux-debug (push) Waiting to run
ci / powerpc64le-linux-release (push) Waiting to run
ci / riscv64-linux-debug (push) Waiting to run
ci / riscv64-linux-release (push) Waiting to run
ci / s390x-linux-debug (push) Waiting to run
ci / s390x-linux-release (push) Waiting to run
ci / x86_64-freebsd-debug (push) Waiting to run
ci / x86_64-freebsd-release (push) Waiting to run
ci / x86_64-linux-debug (push) Waiting to run
ci / x86_64-linux-debug-llvm (push) Waiting to run
ci / x86_64-linux-release (push) Waiting to run
ci / x86_64-netbsd-debug (push) Waiting to run
ci / x86_64-netbsd-release (push) Waiting to run
ci / x86_64-openbsd-debug (push) Waiting to run
ci / x86_64-openbsd-release (push) Waiting to run
ci / x86_64-windows-debug (push) Waiting to run
ci / x86_64-windows-release (push) Waiting to run
The tar format expects `/`, although some untar implementations do seem to handle Windows-style `\` path separators (7-Zip at least).

The tar.Writer API can't really enforce this, though, as doing so would effectively make `\` an illegal character when it's really not. So, it's up to the user to provide paths with the correct path separators.

`Build/WebServer.zig` will still output tars with `\` as a path separator on Windows, but that's currently only used during fuzzing which is not yet implemented on Windows.
2026-03-08 02:10:00 +01:00
Alex Rønne Petersen
c91bb87b01
std.zig.target: enable loongarch64-linux-muslf32
Some checks are pending
ci / aarch64-linux-release (push) Waiting to run
ci / aarch64-freebsd-debug (push) Waiting to run
ci / aarch64-freebsd-release (push) Waiting to run
ci / aarch64-linux-debug (push) Waiting to run
ci / aarch64-netbsd-debug (push) Waiting to run
ci / aarch64-netbsd-release (push) Waiting to run
ci / aarch64-macos-debug (push) Waiting to run
ci / aarch64-macos-release (push) Waiting to run
ci / loongarch64-linux-debug (push) Waiting to run
ci / loongarch64-linux-release (push) Waiting to run
ci / powerpc64le-linux-debug (push) Waiting to run
ci / powerpc64le-linux-release (push) Waiting to run
ci / riscv64-linux-debug (push) Waiting to run
ci / riscv64-linux-release (push) Waiting to run
ci / s390x-linux-debug (push) Waiting to run
ci / s390x-linux-release (push) Waiting to run
ci / x86_64-freebsd-debug (push) Waiting to run
ci / x86_64-freebsd-release (push) Waiting to run
ci / x86_64-linux-debug (push) Waiting to run
ci / x86_64-linux-debug-llvm (push) Waiting to run
ci / x86_64-linux-release (push) Waiting to run
ci / x86_64-netbsd-debug (push) Waiting to run
ci / x86_64-netbsd-release (push) Waiting to run
ci / x86_64-openbsd-debug (push) Waiting to run
ci / x86_64-openbsd-release (push) Waiting to run
ci / x86_64-windows-debug (push) Waiting to run
ci / x86_64-windows-release (push) Waiting to run
This should still be considered an experimental target as the LP64F ABI has not
been stabilized yet.
2026-03-08 02:01:26 +01:00
Alex Rønne Petersen
5a176d57b6
test/llvm_targets.zig: fix a typo 2026-03-08 02:01:26 +01:00
breakmit
46658257f4 Io.Threaded.spawnPosix: implement passing file descriptors as stdio (#31379)
`std.process.spawn`: remove the TODO for nonblocking file stdio and document the behavior.

Fix a bug in Io.Uring.dup2 where the function does not return on success

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31379
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: breakmit <breakmit@noreply.codeberg.org>
Co-committed-by: breakmit <breakmit@noreply.codeberg.org>
2026-03-06 04:51:28 +01:00
Khitiara
30c8a75997 Fix #20283 2026-03-06 04:34:22 +01:00
Nathan Michaels
aa2f318935 std.mem.ReverseIterator: make public 2026-03-05 21:07:36 +01:00
Koko Bhadra
4fa465fc8f compiler_rt: optimize udivmod large-divisor case with trial quotient
Replace the O(n) shift-subtract loop with a constant-time trial
quotient approach (Knuth Algorithm D, TAOCP Vol 2 Section 4.3.1).

The old code iterates clz(b_hi)-clz(a_hi)+1 times (up to 64
iterations of 128-bit arithmetic). The new code uses a single
divwide call to get a trial quotient, then verifies with two
native-width widening multiplies.

Benchmark (Apple M1, ReleaseFast):
- Large divisor, large shift: 87ns -> 7.5ns (11.5x faster)
- Small divisor / uniform: unchanged
2026-03-05 20:22:19 +01:00
xeondev
15f0af09d0 Io.Threaded.batchAwaitConcurrent: fix poll args 2026-03-05 20:17:21 +01:00
Alex Rønne Petersen
b778826df5
std.crypto.argon2: disable kdf test
https://codeberg.org/ziglang/zig/issues/31402
2026-03-05 18:49:31 +01:00
Alex Rønne Petersen
571543237f
ci: update to wasmtime 42.0.1 2026-03-04 21:29:48 +01:00
Alex Rønne Petersen
0ae1c6b54a
std.Io.RwLock: disable smoke test on aarch64-netbsd
https://codeberg.org/ziglang/zig/issues/31393
2026-03-04 12:14:11 +01:00
Alex Rønne Petersen
ce32003625
std.Io.net.test: disable listen on a port, send bytes, receive bytes
https://codeberg.org/ziglang/zig/issues/31388
2026-03-04 01:21:08 +01:00
Alex Rønne Petersen
af1ab5fa08
ci: bump aarch64-freebsd-debug timeout by 1 hour 2026-03-04 00:16:47 +01:00
Alex Rønne Petersen
96a19d3a6b ci: stop downloading tarballs on x86_64-windows
It's annoying to have jobs fail on new machines or when switching tarball. Also
quirky is easily accessible over SSH now, so we can just upload tarballs as we
do for other machines.
2026-03-03 23:28:01 +01:00
Alex Rønne Petersen
852c5d2824
build: bump some max_rss values 2026-03-03 22:50:48 +01:00
Robby Zambito
d2db1d45f1 fix: inline to propagate comptime-ness to call site
See conversation at: https://ziggit.dev/t/why-is-the-comptime-keyword-needed-in-this-inline-for-loop-condition/14090
2026-03-03 21:10:30 +01:00
Andrew Kelley
2d88a5a103 Merge pull request 'Another dll dependency bites the dust (advapi32.dll)' (#31384) from squeek502/zig:delete-advapi32 into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31384
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-03-03 18:26:12 +01:00
Ryan Liptak
fdde8e6394 Delete advapi32 bindings 2026-03-03 01:12:48 -08:00
Ryan Liptak
70058471e3 WindowsSdk: Use ntdll instead of advapi32 APIs for registry querying
The dependency on advapi32.dll actually silently brings along 3 other dlls at runtime (msvcrt.dll, sechost.dll, bcrypt.dll), even if no advapi32 APIs are called. So, this commit actually reduces the number of dlls loaded at runtime by 4 (but only when LLVM is not linked, since LLVM has its own dependency on advapi32.dll).

The data is not super conclusive, but the ntdll version of WindowsSdk appears to run slightly faster than the previous advapi32 version:

Benchmark 1: libc-ntdll.exe ..
  Time (mean ± σ):       6.0 ms ±   0.6 ms    [User: 3.9 ms, System: 7.1 ms]
  Range (min … max):     4.8 ms …   7.9 ms    112 runs

Benchmark 2: libc-advapi32.exe ..
  Time (mean ± σ):       7.2 ms ±   0.5 ms    [User: 5.4 ms, System: 9.2 ms]
  Range (min … max):     6.1 ms …   8.9 ms    103 runs

Summary
  'libc-ntdll.exe ..' ran
    1.21 ± 0.15 times faster than 'libc-advapi32.exe ..'

and this mostly seems to be due to changes in the implementation (the advapi32 APIs do a lot of NtQueryKey calls that the new implementation doesn't do) rather than due to the decrease in dll loading. LLVM-less zig binaries don't show the same reduction (the only difference here is the DLLs being loaded):

Benchmark 1: stage4-ntdll\bin\zig.exe version
  Time (mean ± σ):       3.0 ms ±   0.6 ms    [User: 5.3 ms, System: 4.8 ms]
  Range (min … max):     1.3 ms …   4.2 ms    112 runs

Benchmark 2: stage4-advapi32\bin\zig.exe version
  Time (mean ± σ):       3.5 ms ±   0.6 ms    [User: 6.9 ms, System: 5.5 ms]
  Range (min … max):     2.5 ms …   5.9 ms    111 runs

Summary
  'stage4-ntdll\bin\zig.exe version' ran
    1.16 ± 0.28 times faster than 'stage4-advapi32\bin\zig.exe version'

---

With the removal of the advapi32 dependency, the non-ntdll dependencies that remain in an LLVM-less Zig binary are ws2_32.dll (which brings along rpcrt4.dll at runtime), kernel32.dll (which brings along kernelbase.dll at runtime), and crypt32.dll (which brings along ucrtbase.dll at runtime).
2026-03-03 01:12:47 -08:00
Andrew Kelley
0a412853aa std.Io: fix Select cancel deadlock with no tasks 2026-03-03 02:26:23 +01:00
Alex Rønne Petersen
ac24e6caf5 Merge pull request 'enable aarch64-netbsd CI' (#31377) from alexrp/zig:aarch64-netbsd-ci into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31377
2026-03-03 01:25:45 +01:00
Alex Rønne Petersen
421c3c3cc5 ci: update qemu to 10.2.1.1
https://patchwork.kernel.org/project/qemu-devel/list/?series=1059138
2026-03-02 19:25:09 +01:00
invlpg
0a2f6a048b fix msghdr and cmsghdr on non-Linux targets, document musl behaviour
The following assertions fail on non-Linux platforms after c0c2010535
which inserted padding based on musl definitions. This padding only
exists on musl to workaround a discrepancy betweeen the POSIX API and
Linux ABI, and is incorrect on other POSIX operating systems.

This change makes the padding musl-only, and documents the reason it
exists. With this change, the assertions pass on Linux and FreeBSD
targets. The corresponding definitions on other targets line up with the
POSIX and FreeBSD ones, so they should work there too.

```zig
const std = @import("std");
const assert = std.debug.assert;
const msghdr = std.c.msghdr;
const cmsghdr = std.c.cmsghdr;

const c = @cImport({
    @cInclude("sys/socket.h");
});

comptime {
    assert(@offsetOf(msghdr, "iovlen") == @offsetOf(c.msghdr, "msg_iovlen"));
    assert(@offsetOf(msghdr, "controllen") == @offsetOf(c.msghdr, "msg_controllen"));
    assert(@offsetOf(msghdr, "control") == @offsetOf(c.msghdr, "msg_control"));
    assert(@offsetOf(msghdr, "flags") == @offsetOf(c.msghdr, "msg_flags"));

    assert(@sizeOf(msghdr) == @sizeOf(c.msghdr));

    assert(@offsetOf(cmsghdr, "len") == @offsetOf(c.cmsghdr, "cmsg_len"));
    assert(@offsetOf(cmsghdr, "level") == @offsetOf(c.cmsghdr, "cmsg_level"));

    assert(@sizeOf(cmsghdr) == @sizeOf(c.cmsghdr));
}
```
2026-03-02 17:46:26 +01:00
Alex Rønne Petersen
d6e9b9eb64
ci: enable aarch64-netbsd 2026-03-02 15:08:37 +01:00
Alex Rønne Petersen
d182feacf7
ci: add aarch64-netbsd scripts 2026-03-02 15:08:37 +01:00
Alex Rønne Petersen
f75e4027bd
test: disable an error trace test on optimized aarch64-netbsd 2026-03-02 15:08:37 +01:00
rpkak
442b292a37
zig fetch: wait until all jobs are finished 2026-03-02 10:17:55 +01:00
Ryan Liptak
e58fea8227 tar: Fix symlink test when symlinks can't be created on Windows 2026-03-01 15:01:51 -08:00
hemisputnik
74f361a5ce std.math.big.int: address log2/log10 reviews
There were good reviews made after #31365 was merged, so this commit
addresses them separately.

1. Assert that the number is greater than zero
2. Use `constants` instead of calculating constants manually
3. Use `Const.bitCountAbs` for log2
2026-03-01 20:34:17 +01:00
Alex Rønne Petersen
da6d4e28ef
Revert "ci: disable aarch64-freebsd"
This reverts commit 104e73ecb2.

The OOM issues should be resolved now.
2026-03-01 17:54:47 +01:00
Alex Rønne Petersen
104e73ecb2
ci: disable aarch64-freebsd
Working through some OOM issues.
2026-03-01 12:04:55 +01:00
Alex Rønne Petersen
bf13b6b41d
test: partially disable cmakedefine standalone test
https://codeberg.org/ziglang/zig/issues/31368
2026-03-01 11:53:05 +01:00
Andrew Kelley
9ef1050bb3 Merge pull request 'std.math.big.int: add log2 and log10 operations' (#31365) from hemisputnik/zig:work/13642-bigint-log2-log10 into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31365
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-03-01 03:35:16 +01:00
hemisputnik
bd6f512f0c
std.math.big.int: add log10 2026-02-28 20:16:32 +02:00
Alex Rønne Petersen
41594c1903 Merge pull request 'enable aarch64-freebsd CI' (#31354) from alexrp/zig:aarch64-freebsd-ci into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31354
2026-02-28 08:19:51 +01:00
Alex Rønne Petersen
b3c8c0df0d ci: switch to VS 2026 in x86_64-windows scripts 2026-02-28 07:08:06 +01:00
Andrew Kelley
02142a54d2 std.Io: remove cancelation propagation assertions
While the general guidance remains useful, it is not the case that
error.Canceled will always pass across the Group task function boundary.

Remove the too-aggressive assertions and add unit test coverage.

Closes #30096
Closes #31340
Closes #31358
2026-02-28 05:07:54 +01:00
hemisputnik
925f82da09
std.math.big.int: add log2 2026-02-28 04:15:19 +02:00
hemisputnik
99229ceb55 std.Io.{Writer|Duration}: move duration formatting to a format method
Remove the `{D}` format specifier. It is moved into `std.Io.Duration` as
a format method.

Migration plan:

```diff
-writer.print("{D}", .{ns});
+writer.print("{f}", .{std.Io.Duration{ .nanoseconds = ns }});
```

All instances where `{D}` was used have been changed to use
`std.Io.Duration` and `{f}`.

Fixes #31281
2026-02-28 02:46:04 +01:00
Andrew Kelley
8c70fd0a57 std.Io.Select: introduce cancelDiscard
and make the return value of `cancel` return queue items.

I don't think it's possible to make `cancel` not deadlock with an empty
queue buffer without introducing a new Group primitive.

This is the best I could come up with based on existing primitives.
Let's see if applications find these APIs palatable.
2026-02-28 01:46:43 +01:00
Alex Rønne Petersen
424061381b
ci: enable aarch64-freebsd 2026-02-27 20:30:31 +01:00
mintonmu
e779ca7223 fix(docs/wasm):zig std html render error function 'a' 2026-02-27 19:17:47 +01:00
Nils Juto
2da1370a7e sync CallModifier in langref with what's actually there 2026-02-27 13:50:12 +01:00
Alex Rønne Petersen
d130f76bab
ci: add aarch64-freebsd scripts 2026-02-27 08:49:27 +01:00
Alex Rønne Petersen
b781615e09
test: disable an error trace test on optimized aarch64-freebsd 2026-02-27 08:49:27 +01:00
Justus Klausecker
bbc77df3eb std.heap: delete ThreadSafeAllocator
We can keep ourselves safe from those threads perfectly well without you, thanks!
2026-02-26 21:20:34 +01:00
Saurabh Mishra
4e2cec265d Make std.PriorityQueue an unmanaged container (#31299)
## Summary of changes

+ Make adjustments to the `allocator` field and ensure the below tests pass:

  ```sh
  zig test lib/std/std.zig --zig-lib-dir lib
  zig build test-std -Dno-matrix --summary all
  ```

+ Rename `add` to `push` and `remove` to `pop` in methods and tests

+ Incorporate the functionality of `pop` in `popOrNull`, then rename the `popOrNull` to `pop` and update tests

+ Use `.empty` to set default field values and rename the `init` method to `initContext`

+ Improve variable types in tests: min heap uses the less than context function and max heap uses greater than context function

+ Remove the `dump` method as its not being used anywhere

+ Document methods `clearRetainingCapacity`, `clearAndFree`, `update`, and `ensureTotalCapacityPrecise`

Closes https://codeberg.org/ziglang/zig/issues/31298

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31299
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: Saurabh Mishra <saurabh.m@proton.me>
Co-committed-by: Saurabh Mishra <saurabh.m@proton.me>
2026-02-26 21:09:52 +01:00
estevesnp
0b6b65b387 fix: Allow async and concurrent from Io.Select to accept non-void error unions 2026-02-26 20:49:05 +01:00
Alex Rønne Petersen
2d867223be build: use -ffunction-sections -fdata-sections for the Zig compiler on ARM
See 7daf0b6f46; builds for ARM can run into the
same problems due to limited branch range.
2026-02-26 20:48:29 +01:00
Andrew Kelley
7bc6546fdf Merge pull request 'std.heap.ArenaAllocator: Get rid of cmpxchg loop in hot path' (#31343) from justusk/zig:lock-free-arena-overshoot into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31343
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-02-26 20:42:30 +01:00
Justus Klausecker
de41123957 std.heap.ArenaAllocator: fix reset creating undersized nodes
Previously resetting with `retain_capacity < @sizeOf(Node)` would create
an invalid node. This is now fixed, plus `Node.size` now has its own `Size`
type that provides additional safety via assertions to prevent bugs like
this in the future.
2026-02-26 15:40:48 +01:00
Justus Klausecker
2fa2300ba4 std.heap.ArenaAllocator: Get rid of cmpxchg loop in hot path
This is achieved by bumping `end_index` by a large enough amount so that
a suitably aligned region of memory can always be provided. The potential
wasted space this creates is then recovered by a single cmpxchg. This is
always successful for single-threaded arenas which means that this version
still behaves exactly the same as the old single-threaded implementation
when only being accessed by one thread at a time. It can however fail when
another thread bumps `end_index` in the meantime. The observerd failure
rates under extreme load are:

2 Threads: 4-5%
3 Threads: 13-15%
4 Threads: 15-17%
5 Threads: 17-18%
6 Threads: 19-20%
7 Threads: 18-21%

This version offers ~25% faster performance under extreme load from 7 threads,
with diminishing speedups for less threads. The performance for 1 and 2
threads is nearly identical.
2026-02-26 15:30:55 +01:00
Motiejus Jakštys
56253d9e31 x86_64 codegen: fix RoundMode vroundss immediate value
Quoting Vol. 2B 4-590 of [Intel SSA manual][1]:

> Bit 3 of the immediate byte controls processor behavior for a
precision exception <...>

The Direction struct is incorrectly sized to 4 bits, which pushes the
precision exception bit to the reserved bits, which helpfully crashes
under valgrind (but works on real hardware, since CPU ignores it):

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

noinline fn ceil(x: f32) f32 {
    return @ceil(x);
}

test "ceil" {
    try std.testing.expectEqual(@as(f32, 2.0), ceil(1.5));
}
```

With Zig 0.15.1:

```
$ zig test -fno-llvm -mcpu x86_64_v3  -fvalgrind  ceil_test.zig  --test-cmd valgrind --test-cmd --quiet --test-cmd-bin
Illegal instruction at address 0x102d14d
/home/motiejus/code/ceil_test.zig:4:5: 0x102d14d in ceil (ceil_test.zig)
    return @ceil(x);
    ^
/home/motiejus/code/ceil_test.zig:8:52: 0x102d097 in test.ceil (ceil_test.zig)
    try std.testing.expectEqual(@as(f32, 2.0), ceil(1.5));
                                                   ^
/nix/store/n81qdpd96d86ngfv5bqymy26b8kqm654-zig-0.15.1/lib/compiler/test_runner.zig:218:25: 0x1167e80 in mainTerminal (test_runner.zig)
        if (test_fn.func()) |_| {
                        ^
/nix/store/n81qdpd96d86ngfv5bqymy26b8kqm654-zig-0.15.1/lib/compiler/test_runner.zig:66:28: 0x11610a1 in main (test_runner.zig)
        return mainTerminal();
                           ^
/nix/store/n81qdpd96d86ngfv5bqymy26b8kqm654-zig-0.15.1/lib/std/start.zig:618:22: 0x115ae3d in posixCallMainAndExit (std.zig)
            root.main();
                     ^
/nix/store/n81qdpd96d86ngfv5bqymy26b8kqm654-zig-0.15.1/lib/std/start.zig:232:5: 0x115a6d1 in _start (std.zig)
    asm volatile (switch (native_arch) {
    ^
???:?:?: 0x0 in ??? (???)
error: the following test command crashed:
valgrind --quiet /home/motiejus/.cache/zig/o/7cc564b5410fc3facdb6e8768643074e/test
```

Zig 0.15.1 with this patch:

```
zig/zig3 test -fno-llvm -mcpu x86_64_v3  -fvalgrind  ceil_test.zig  --test-cmd valgrind --test-cmd --quiet --test-cmd-bin
All 1 tests passed.
```

Looking through `CodeGen.zig` it _seems_ like the same RoundMode struct
is used for vroundss/vroundps/vcvtps2ph, so update the comment while
we're at it. But I am only 90% sure it's true.

[1]: https://cdrdv2.intel.com/v1/dl/getContent/671200
2026-02-25 20:34:08 +01:00
Andrew Kelley
e0173c2ce0 Merge pull request 'rework fuzz testing to be smith based' (#31205) from gooncreeper/zig:integrated-smith into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31205
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-02-25 20:23:36 +01:00
Kendall Condon
bb304796f4 optimize flate decompression
Matches now use memcpy and memset when possible.

Block loops have been rewritten to be more optimizer friendly.

Reworks Symbol and HuffmanDecoder
* Symbol now only includes the value and number of code bits.
  decodeSymbol returns only the value.
* HuffmanDecoder now takes the regular bits instead of the reversed.
* Code table construction now uses buckets instead of sorting.
* For linked codes, the value field of Symbol is now used as the next
  index. The actual value is the element index.
* InvalidCode is now detected only once with a special linked index.

Performance is 39.7% faster than before and 1.1% faster than gzip using
a sample created from compressing a tar of the src directory.
2026-02-25 20:05:48 +01:00
Ivan Agafonov
333055ced7 langref: specific expectEqual* functions instead of expect 2026-02-25 19:34:30 +01:00
Justus Klausecker
a3a9dc111d std.heap.ArenaAllocator: make it threadsafe
Modifies the `Allocator` implementation provided by `ArenaAllocator` to be
threadsafe using only atomics and no synchronization primitives locked
behind an `Io` implementation.

At its core this is a lock-free singly linked list which uses CAS loops to
exchange the head node. A nice property of `ArenaAllocator` is that the
only functions that can ever remove nodes from its linked list are `reset`
and `deinit`, both of which are not part of the `Allocator` interface and
thus aren't threadsafe, so node-related ABA problems are impossible.

There *are* some trade-offs: end index tracking is now per node instead of
per allocator instance. It's not possible to publish a head node and its
end index at the same time if the latter isn't part of the former.

Another compromise had to be made in regards to resizing existing nodes.
Annoyingly, `rawResize` of an arbitrary thread-safe child allocator can
of course never be guaranteed to be an atomic operation, so only one
`alloc` call can ever resize at the same time, other threads have to
consider any resizes they attempt during that time failed. This causes
slightly less optimal behavior than what could be achieved with a mutex.
The LSB of `Node.size` is used to signal that a node is being resized.
This means that all nodes have to have an even size.

Calls to `alloc` have to allocate new nodes optimistically as they can
only know whether any CAS on a head node will succeed after attempting it,
and to attempt the CAS they of course already need to know the address of
the freshly allocated node they are trying to make the new head.
The simplest solution to this would be to just free the new node again if
a CAS fails, however this can be expensive and would mean that in practice
arenas could only really be used with a GPA as their child allocator. To
work around this, this implementation keeps its own free list of nodes
which didn't make their CAS to be reused by a later `alloc` invocation.
To keep things simple and avoid ABA problems the free list is only ever
be accessed beyond its head by 'stealing' the head node (and thus the
entire list) with an atomic swap. This makes iteration and removal trivial
since there's only ever one thread doing it at a time which also owns all
nodes it's holding. When the thread is done it can just push its list onto
the free list again.

This implementation offers comparable performance to the previous one when
only being accessed by a single thread and a slight speedup compared to
the previous implementation wrapped into a `ThreadSafeAllocator` up to ~7
threads performing operations on it concurrently.
(measured on a base model MacBook Pro M1)
2026-02-25 19:12:35 +01:00
hemisputnik
2f8e660805 std.math.log10: handle comptime_int inputs correctly
also add a few tests for comptime types

fixes #31333
2026-02-25 18:57:58 +01:00
Andrew Kelley
608b07a3d7 Merge pull request 'fix std.heap.PageAllocator to not intrude on stacks + re-enable LoongArch CI' (#31271) from alexrp/zig:page-allocator-fixes into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31271
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-02-24 21:24:50 +01:00
Toufiq Shishir
784e89fd4b fix: remove null argument from std.debug.lockStderr call inside std.json.Value.dump 2026-02-24 04:23:25 +01:00
Justus Klausecker
360bc28c96 fix cmpxchg behavior test
This has to be a `@cmpxchgStrong` instead of a `@cmpxchgWeak` otherwise
this test will fail spuriously on LL/SC architectures like PowerPC.
2026-02-23 21:13:26 +01:00
Frank Denis
ee82d926a6 Merge pull request 'Expose the elligator map for Curve25519' (#31318) from jedisct1/zig:elligator-curve25519 into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31318
2026-02-23 19:53:09 +01:00
Frank Denis
e8ca9229c8 Expose the elligator map for Curve25519
This is the same as for Edwards25519 without the y coordinate,
since it returns Montgomery coordinates, but it can be confusing
to call the Edwards25519 function while working on the
Curve25519 representation.

New protocols such as CPACE requires the map over Curve25519.
2026-02-23 13:04:58 +01:00
George Huebner
27ef6e9a9b bpf: add missing helpers 2026-02-23 02:27:13 +01:00
Yusuf Bham
de6c0d500f uefi(guid): don't use @byteSwap in fmt, adjust fmt test
@byteSwap shouldn't be called since we're formatting
ints again, and UEFI only officially supports LE.
2026-02-22 23:13:33 +01:00
inge4pres
29e52aa040 lib: add cgroup BPF helpers
Add bpf_cgrp_storage_get and bpf_cgrp_storage_delete from
libbpf helpers.

Signed-off-by: inge4pres <fgualazzi@gmail.com>
2026-02-22 20:24:51 +01:00
Jacob Young
d7f90722f7 x86_64: fix parsing of sib operands 2026-02-21 18:10:50 -05:00
Alex Rønne Petersen
bd80ad4647
Revert "ci: disable loongarch64-linux"
This reverts commit f061c0dc28.
2026-02-21 23:39:34 +01:00
Alex Rønne Petersen
b5bcbf2a62
std.heap.DebugAllocator: make BucketHeader.fromPage() use wrapping arithmetic
If we've allocated the very last page in the address space then these operations
will overflow and underflow respectively - which is fine.
2026-02-21 23:39:34 +01:00
Matthew Lugg
a9d18c4a0c
std.heap.PageAllocator: avoid mremaps which may reserve potential stack space
Linux's approach to mapping the main thread's stack is quite odd: it essentially
tries to select an mmap address (assuming unhinted mmap calls) which do not
cover the region of virtual address space into which the stack *would* grow
(based on the stack rlimit), but it doesn't actually *prevent* those pages from
being mapped. It also doesn't try particularly hard: it's been observed that the
first (unhinted) mmap call in a simple application is usually put at an address
which is within a gigabyte or two of the stack, which is close enough to make
issues somewhat likely. In particular, if we get an address which is close-ish
to the stack, and then `mremap` it without the MAY_MOVE flag, we are *very*
likely to map pages in this "theoretical stack region". This is particularly a
problem on loongarch64, where the initial mmap address is empirically only
around 200 megabytes from the stack (whereas on most other 64-bit targets it's
closer to a gigabyte).

To work around this, we just need to avoid mremap in some cases. Unfortunately,
this system call isn't used too heavily by musl or glibc, so design issues like
this can and do exist without being caught. So, when `PageAllocator.resize` is
called, let's not try to `mremap` to grow the pages. We can still call `mremap`
in the `PageAllocator.remap` path, because in that case we can set the
`MAY_MOVE` flag, which empirically appears to make the Linux kernel avoid the
problematic "theoretical stack region".
2026-02-21 23:39:34 +01:00
Alex Rønne Petersen
c8dd050305
std.heap.PageAllocator: hint mmaps in the same direction as stack growth
The old logic was fine for targets where the stack grows up (so, literally just
hppa), but problematic on targets where it grows down, because we could hint
that we wanted an allocation to happen in an area of the address space that the
kernel expects to be able to expand the stack into. The kernel is happy to
satisfy such a hint despite the obvious problems this leads to later down the
road.

Co-authored-by: rpkak <rpkak@noreply.codeberg.org>
2026-02-21 23:39:20 +01:00
Andrew Kelley
cd02b1703b Merge pull request 'std.Io.Select: add awaitMany, documentation, and unit test; remove outstanding field' (#31296) from select-enhancement into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31296
2026-02-21 05:22:20 +01:00
Andrew Kelley
311bba4af0 std.Io.Select: add awaitMany function and unit test
and fix documentation. these functions are in fact threadsafe.
2026-02-20 17:28:33 -08:00
Andrew Kelley
f9053f38e5 std.Io.Select: add documentation 2026-02-20 17:08:13 -08:00
Andrew Kelley
54eb03cbf6 std.Io.Select: remove "outstanding" field
it is not fundamentally part of this abstraction
2026-02-20 16:42:37 -08:00
Andrew Kelley
5ac6ff43d4 Merge pull request 'Io.Select: cancelation and concurrent' (#30836) from blblack/zig:select-stuff into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30836
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-02-21 01:29:06 +01:00
Andrew Kelley
6a9510c0eb Merge pull request 'Make std.PriorityDequeue an unmanaged container' (#31273) from saurabh/zig:unmanaged-priority-dequeue into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31273
2026-02-20 07:11:57 +01:00
John Benediktsson
14d06330e0 std.c: fix SO_LINGER on darwin and define SO_LINGER_SEC 2026-02-20 05:36:46 +01:00
David Rubin
8259d8d631 minimal 2026-02-20 05:34:54 +01:00
Alex Rønne Petersen
e95132476d std.os.linux: fix the mmap2 unit for various architectures
closes https://codeberg.org/ziglang/zig/issues/31033
2026-02-20 04:56:07 +01:00
Lukas Lalinsky
7dddcd043f Add lr and sp clobbers for arm/thumb 2026-02-20 01:16:33 +01:00
Yusuf Bham
1e26d885d3 uefi(guid): don't use std.mem.asBytes in format
Using std.mem.asBytes causes a panic when format
is called as slices can no longer have hex options
when formatting, so instead just print the ints.
2026-02-18 20:19:50 -05:00
Saurabh Mishra
5140455264 min heap is formed with less than comparison 2026-02-18 13:24:03 -08:00
Saurabh Mishra
293710c1cd use .empty for default field values intead of init() and introduce initContext() 2026-02-18 12:38:26 -08:00
Saurabh Mishra
23252c27be merge popMinOrNull into popMin and popMaxOrNull into popMax, and update tests 2026-02-18 11:58:13 -08:00
Saurabh Mishra
535722b374 rename add to push and remove to pop in methods and tests 2026-02-18 11:43:57 -08:00
Saurabh Mishra
d297f7b8f2 make priority dequeue an unmanaged container and ensure tests pass 2026-02-18 11:20:32 -08:00
Marcel W. Wysocki
0e3c6514a4 link: recognize thin archives in ld script detection
Needed for linking the Linux kernel.
2026-02-17 23:15:32 +01:00
Alex Rønne Petersen
0fd8dc8ea6 ci: update to qemu 10.2.1 2026-02-17 19:16:25 +01:00
Marcel W. Wysocki
0e45a44991 cc: disable implicit runtimes with -nostdlib, matching clang 2026-02-16 19:42:13 +08:00
Andrew Kelley
27eec9bd62 Revert "Allow overriding std.Io at a namespace level."
This reverts commit e314dadb01.

This idea requires more consideration before committing to it.
At the very least let's not regress autodocs.

Closes #31230
2026-02-15 20:26:12 -08:00
vitalii
1838134200 fix segfault when /etc/hosts missing last newline 2026-02-15 23:12:13 +01:00
rpkak
17dd2f0a85 spirv: implement AIR tag struct_field_ptr 2026-02-15 23:09:24 +01:00
Iku Iwasa
8c83acd3d4 Add missing EV flags for NetBSD
- Add FLAG1, ERROR and EOF.
2026-02-15 23:08:11 +01:00
Andrew Kelley
c8f54a2f07 Merge pull request 'std.Io: remove select function' (#31223) from remove-select into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31223
2026-02-15 19:29:21 +01:00
Jacob Young
5763f7dbcc std.Io.Evented: clean up supporting code for select 2026-02-15 05:52:07 -05:00
Andrew Kelley
d9fc7fa04d std.Io: remove select function
This function works with a slice of futures and returns the index of a
completed one. This doesn't work very well in practice because it's
either too high level or too low level.

At the lower level we have Io.Batch for doing this kind of thing at the
Operation API layer.

At the higher level we have Io.Select which is a convenience wrapper
around an Io.Group and an Io.Queue.
2026-02-14 18:31:48 -08:00
Andrew Kelley
c6eeae8a8c Merge pull request 'std.math.acos/asin: Add @Vector(?,f32) and @Vector(?,f64) support' (#31209) from lzm-build/zig:acos_asin_simd into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31209
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-02-14 23:35:03 +01:00
Jacob Young
771047ae93 Io.Dispatch.sleep: add cancelation support 2026-02-14 16:26:49 -05:00
Jacob Young
b7f93695f9 Io.Dispatch.Mutex: fix deadlock conditions 2026-02-14 05:52:59 -05:00
lzm-build
51509fe63b std.math.acos/asin: Add @Vector(?,f32) and @Vector(?,f64) support 2026-02-14 16:57:05 +08:00
Andrew Kelley
f996d28666 fetch: use tmp dir inside zig-pkg/
Using the tmp dir of the local .zig-cache/ could result in
error.CrossDevice if the user chose a non-default local cache path.

closes #31148
2026-02-14 09:34:15 +01:00
Andrew Kelley
017228de89 libc malloc: introduce a canary
Instead of padding, use static entropy to detect corrupted header.

* 64-bit, safe modes: 10 canary bits
* 64-bit, unsafe modes: 0 canary bits
* 32-bit: 27 canary bits

A further enhancement, not done here, would be to upgrade from canary to
parity.
2026-02-14 09:25:41 +01:00
lzm-build
ef13a373bc fix assertion argument order in acos/asin/atan 2026-02-14 13:33:55 +08:00
Kendall Condon
5d58306162 rework fuzz testing to be smith based
-- On the standard library side:

The `input: []const u8` parameter of functions passed to `testing.fuzz`
has changed to `smith: *testing.Smith`. `Smith` is used to generate
values from libfuzzer or input bytes generated by libfuzzer.

`Smith` contains the following base methods:
* `value` as a generic method for generating any type
* `eos` for generating end-of-stream markers. Provides the additional
  guarantee `true` will eventually by provided.
* `bytes` for filling a byte array.
* `slice` for filling part of a buffer and providing the length.

`Smith.Weight` is used for giving value ranges a higher probability of
being selected. By default, every value has a weight of zero (i.e. they
will not be selected). Weights can only apply to values that fit within
a u64. The above functions have corresponding ones that accept weights.
Additionally, the following functions are provided:
* `baselineWeights` which provides a set of weights containing every
  possible value of a type.
* `eosSimpleWeighted` for unique weights for `true` and `false`
* `valueRangeAtMost` and `valueRangeLessThan` for weighing only a range
  of values.

-- On the libfuzzer and abi side:

--- Uids

These are u32s which are used to classify requested values. This solves
the problem of a mutation causing a new value to be requested and
shifting all future values; for example:

1. An initial input contains the values 1, 2, 3 which are interpreted
as a, b, and c respectively by the test.

2. The 1 is mutated to a 4 which causes the test to request an extra
value interpreted as d. The input is now 4, 2, 3, 5 (new value) which
the test corresponds to a, d, b, c; however, b and c no longer
correspond to their original values.

Uids contain a hash component and type component. The hash component
is currently determined in `Smith` by taking a hash of the calling
`@returnAddress()` or via an argument in the corresponding `WithHash`
functions. The type component is used extensively in libfuzzer with its
hashmaps.

--- Mutations

At the start of a cycle (a run), a random number of values to mutate is
selected with less being exponentially more likely. The indexes of the
values are selected from a selected uid with a logarithmic bias to uids
with more values.

Mutations may change a single values, several consecutive values in a
uid, or several consecutive values in the uid-independent order they
were requested. They may generate random values, mutate from previous
ones, or copy from other values in the same uid from the same input or
spliced from another.

For integers, mutations from previous ones currently only generates
random values. For bytes, mutations from previous mix new random data
and previous bytes with a set number of mutations.

--- Passive Minimization

A different approach has been taken for minimizing inputs: instead of
trying a fixed set of mutations when a fresh input is found, the input
is instead simply added to the corpus and removed when it is no longer
valuable.

The quality of an input is measured based off how many unique pcs it
hit and how many values it needed from the fuzzer. It is tracked which
inputs hold the best qualities for each pc for hitting the minimum and
maximum unique pcs while needing the least values.

Once all an input's qualities have been superseded for the pcs it hit,
it is removed from the corpus.

-- Comparison to byte-based smith

A byte-based smith would be much more inefficient and complex than this
solution. It would be unable to solve the shifting problem that Uids
do. It is unable to provide values from the fuzzer past end-of-stream.
Even with feedback, it would be unable to act on dynamic weights which
have proven essential with the updated tests (e.g. to constrain values
to a range).

-- Test updates

All the standard library tests have been updated to use the new smith
interface. For `Deque`, an ad hoc allocator was written to improve
performance and remove reliance on heap allocation. `TokenSmith` has
been added to aid in testing Ast and help inform decisions on the smith
interface.
2026-02-13 22:12:19 -05:00
Kendall Condon
5b9bb0a404 add -Dfuzz-only
Runs only one configuration suitable for fuzzing.
2026-02-13 17:58:09 -05:00
Kendall Condon
e40557b1f7 allow specifying mode in --debug-rt
The motivation is that libfuzzer is slow in Debug mode and bugs usually
manifest late into fuzzing, which makes testing it in ReleaseSafe
useful.
2026-02-13 17:58:09 -05:00
Kendall Condon
1a9d75ebe0 fix fuzzing speed with prior runs 2026-02-13 17:58:09 -05:00
Kendall Condon
af1e196db3 align end of elf archives
The end of the archive needs to also be aligned to a two-byte boundary,
not just the start of records. This was causing lld to reject archives.

Notably, this was happening with compiler_rt when rebuilding in fuzz
mode, which is why this commit is included in this patchset.
2026-02-13 17:58:09 -05:00
Kendall Condon
3c9024be08 update fuzzing for build system changes 2026-02-13 17:58:09 -05:00
Andrew Kelley
d2c862e6ff Merge pull request 'Io.Dispatch: introduce grand central dispatch io impl' (#31198) from dispatch into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31198
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-02-13 23:19:32 +01:00
Andrew Kelley
e262a32ad1 Merge branch 'std.math.atan: Add @Vector(?,f32) and @Vector(?,f64) support'
Add SIMD support for atan (f32 and f64), based on the [ARM
impl](https://github.com/ARM-software/optimized-routines/blob/master/math/aarch64/advsimd/atanf.c).
To reduce branching, more polynomial approximation is used.

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31195
2026-02-13 12:26:11 -08:00
Andrew Kelley
12e6ac2e8f std.math.atan: simplify type logic 2026-02-13 12:25:53 -08:00
lzm-build
8901d38b7d std.math.atan: Add @Vector(?,f32) and @Vector(?,f64) support 2026-02-13 12:20:53 -08:00
Chris Boesch
07b08b9638 compiler_rt: Implemented missing handling of denormal numbers when dividing f128 (#30198)
Replaces the "flush denormals to zero" placeholder in divtf3.zig with IEEE 754 denormal support including rounding.

fixes #30179

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30198
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: Chris Boesch <chrboesch@noreply.codeberg.org>
Co-committed-by: Chris Boesch <chrboesch@noreply.codeberg.org>
2026-02-13 20:49:14 +01:00
hubidubi
fd74c5742d std.Io.Threaded: fix FreeBSD Futex max_waiters (#30094)
On FreeBSD, the maximum waiters should be Cs INT_MAX instead of the maximum of a u32. Waiting for the Io.Event in the broadcast test triggers this bug.

Resolves #30715

Co-authored-by: Simon Galli <hubi@hubidubi.net>
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30094
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: hubidubi <hubidubi@noreply.codeberg.org>
Co-committed-by: hubidubi <hubidubi@noreply.codeberg.org>
2026-02-13 20:39:38 +01:00
Andrew Kelley
dbfe34167d Merge branch 'jeffective-jeff/libzigc-acosf'
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30996
2026-02-13 11:31:15 -08:00
kj4tmp@gmail.com
004872baec zig libc: acosf: fix fp exceptions
some fp exceptions are prohibited by zig test-libc (libc-test).
Promoting to f64 prevents vectorization of some floating point
divisions. The vectorization has unused lanes which contain zero. On
division the lanes containing zero are divided and trigger the INVALID
fp flags.
2026-02-13 11:30:19 -08:00
kj4tmp@gmail.com
3dc2a1f9ac zig libc: acosf 2026-02-13 11:30:14 -08:00
rpkak
4ea9904923 remove some unused libc files 2026-02-13 19:57:59 +01:00
Jacob Young
0eb1e0c30a crash_report: finish reverting panic changes better
I missed that the types were `pub`.
2026-02-13 12:29:40 -05:00
Jacob Young
2fa1a78491 Io.Dispatch: introduce grand central dispatch io impl 2026-02-13 12:29:40 -05:00
IntegratedQuantum
0bed4fb384 crypto: Allow arbitrary types for secureZeroes
also removed some related ptrCasts
2026-02-13 17:07:03 +01:00
Andrew Kelley
469bf6af07 Merge branch std.Deque: add *Ptr and *Slice functions
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31179
2026-02-12 21:46:19 -08:00
Andrew Kelley
13e42b16cd std.deque: fix typo in unit test 2026-02-12 21:45:52 -08:00
Justus Klausecker
623723507f std.Deque: add peek and *Ptr functions to Iterator
The iterator should be as powerful as manual access via `as` and `asPtr`
to justify its existence.
2026-02-12 21:45:13 -08:00
Justus Klausecker
527e97b252 std.Deque: add *Slice variants of push functions
This mirrors the `*Slice` variants e.g. `std.ArrayList` already provides.
2026-02-12 21:45:13 -08:00
Justus Klausecker
35c5611f07 std.Deque: add *Ptr variants of getter functions
This makes it practical to store large items or items that are meant to
be mutable directly inside of the deque.
It is the responsibility of the user to stop using the returned pointers
after calling a function that could invalidate them.
2026-02-12 21:45:13 -08:00
kineye
f36d0573cd zig libc: add rint 2026-02-12 21:42:38 -08:00
Neel
5132d78e83 libc: implement insque and remque in Zig
Implements insque() and remque() doubly-linked list functions
in lib/c/search.zig and removes musl C implementation.
Contributes to #30978
2026-02-12 21:35:36 -08:00
Andrew Kelley
4a3adaaa23 Merge pull request 'zig libc: implement malloc' (#31177) from libc-malloc into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31177
2026-02-13 06:30:42 +01:00
Karel Marek
37109fa4ef Fix IpAddress.setPort 2026-02-13 06:09:47 +01:00
Andrew Kelley
0957761d5c std.heap.BrkAllocator: fix incorrect assumptions 2026-02-12 16:30:27 -08:00
Andrew Kelley
6296924214 build: bump behavior max_rss 2026-02-12 16:30:24 -08:00
Andrew Kelley
6d52678a6c zig libc malloc: skip export when unit testing
These functions can only be exported when external libc components are
available due to the errno location dependency. Note that even when zig
libc is complete, on Windows, errno location will always be external (in
ucrtbase.dll).
2026-02-12 13:14:51 -08:00
Andrew Kelley
ec02571a30 zig libc malloc: set errno when returning null 2026-02-12 13:14:51 -08:00
Andrew Kelley
0de7668c01 test harness: refmt for readability 2026-02-12 13:14:51 -08:00
Andrew Kelley
21829a5b4a zig libc: export all symbols weak
Normally, libc goes into a static archive, making all symbols
overrideable. However, Zig supports including the libc functions as part
of the Zig Compilation Unit, so to support this use case we make all
symbols weak.
2026-02-12 13:14:51 -08:00
Andrew Kelley
f5d5dbd166 wasi libc: remove malloc defines 2026-02-12 13:14:51 -08:00
Andrew Kelley
e2fccd8dd5 musl: remove macro redefinitions of malloc 2026-02-12 13:14:51 -08:00
Andrew Kelley
6ccabbd4e5 std: brk allocator for single-threaded mode 2026-02-12 13:14:51 -08:00
Andrew Kelley
6744160211 zig libc: implement malloc 2026-02-12 13:14:51 -08:00
Andrew Kelley
5c59a46238 std.heap.PageAllocator: fix not respecting alignments
in remap and resize, alignments larger than page size were incorrectly ignored.
2026-02-12 13:14:51 -08:00
Andrew Kelley
0a61eca22c bump max_rss for module tests 2026-02-12 13:14:51 -08:00
Jacob Young
251f54d1d7 crash_report: finish reverting panic changes 2026-02-12 13:13:45 -05:00
Alex Rønne Petersen
381e231468 Merge pull request 'fix(codegen/llvm): teach llvm to not dllexport hidden exports' (#31180) from GasInfinity/zig:fix-hidden-dllexport into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31180
Reviewed-by: Alex Rønne Petersen <alex@alexrp.com>
2026-02-12 08:36:15 +01:00
Meghan Denny
13f31bb3c3 std/c: glibc has supported arc4random_buf since 2.36 2026-02-11 15:29:51 -08:00
Andrew Kelley
b600b6e5e0 std.posix: remove close function 2026-02-11 23:37:31 +01:00
Andrew Kelley
ea30f86113 bump maxrss for compiler_rt, libc, and c-abi tests 2026-02-11 23:37:31 +01:00
Andrew Kelley
ba293eb820 Revert "compiler: override debug_io in release + evented mode"
This reverts commit 6840326711.

The commit bungled deinitialization in main.
2026-02-11 10:44:04 -08:00
Pivok
d4217e2119 zig libc: exp10, exp10f, pow10, pow10f (#31163)
See #30978.

Commands i run:
```
$ stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib

$ stage4/bin/zig build test-libc -Dlibc-test-path=../../libc-test -Dtest-filter=exp10 -fqemu -fwasmtime --summary line
Build Summary: 725/737 steps succeeded (12 skipped)
```

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31163
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: Pivok <pivoc@protonmail.com>
Co-committed-by: Pivok <pivoc@protonmail.com>
2026-02-11 19:39:40 +01:00
GasInfinity
a6f64096a1
chore(test/standalone): test linking libc in a shared library 2026-02-11 15:48:18 +01:00
GasInfinity
87fa61bdd1
fix(codegen/llvm): teach llvm to not dllexport hidden exports 2026-02-11 10:51:26 +01:00
Andrew Kelley
96bd268c8c zig libc: simplify implementation
- use symbol export helper
- move all declarations from common.zig into c.zig
- correct documentation
- delete dead code
2026-02-11 07:58:11 +01:00
Andrew Kelley
6840326711 compiler: override debug_io in release + evented mode
to avoid a dependency on std.Io.Threaded in such case
2026-02-11 00:27:06 +01:00
Jacob Young
7369008d8c Io.IoUring: implement some thread pool options and other cleanup 2026-02-10 23:45:48 +01:00
Khitiara
e314dadb01 Allow overriding std.Io at a namespace level.
This should only be used when the fundamental types break down, e.g. on freestanding or when adding support for a non-posix OS, where std.Io.File.Handle is set to void.
2026-02-10 21:07:53 +01:00
Andrew Kelley
bf1b9318a9 Merge pull request 'compiler_rt: common -> compiler_rt' (#31169) from compiler-rt-cleanup-2 into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31169
2026-02-10 20:28:28 +01:00
Andrew Kelley
7fbeeca924 Merge pull request 'Linux 6.19' (#31165) from alexrp/zig:linux-6.19 into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31165
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-02-10 05:29:00 +01:00
Andrew Kelley
2372c68ae8 cmake: remove compiler rt source listings 2026-02-09 20:11:39 -08:00
Andrew Kelley
74608293af compiler_rt: common -> compiler_rt
use the "symbol" helper function in all exports

move all declarations from common.zig to compiler_rt.zig

flatten the tree structure somewhat (move contents of tiny files into
parent files)

No functional changes.
2026-02-09 20:03:15 -08:00
Andrew Kelley
6c7814fabd Merge pull request 'Autodoc: display line numbers in source code display' (#31155) from nektro/fork-zig:nektro-patch-54643 into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31155
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-02-10 01:43:12 +01:00
Andrew Kelley
b607b0c27a Merge pull request 'IoUring: update to new Io APIs' (#31158) from io-uring-update into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31158
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-02-10 00:43:51 +01:00
Alex Rønne Petersen
fcf0fc225a
std.Target: update max Linux version to 6.19 2026-02-09 23:54:30 +01:00
Alex Rønne Petersen
7af9882c6d
libc: update Linux headers to 6.19 2026-02-09 23:54:30 +01:00
Alex Rønne Petersen
80db2e0b8b
std.os.linux: update syscalls for 6.19 2026-02-09 23:54:30 +01:00
Alex Rønne Petersen
bc282a6389
generate_linux_syscalls: add loongarch32 2026-02-09 23:54:30 +01:00
Alex Rønne Petersen
81ef502f08
generate_linux_syscalls: add hexagon abi name 2026-02-09 23:54:30 +01:00
Alex Rønne Petersen
65c073b147
generate_linux_syscalls: update usage text 2026-02-09 23:46:19 +01:00
Andrew Kelley
04c180c8e5 compiler_rt: partial cleanup
introduce `symbol` helper function and partially migrate to using it
2026-02-09 20:04:17 +01:00
Nils Koch
6473dc22fc std.ArrayList: Fix compile error when @sizeOf(T) == 0 2026-02-09 19:59:09 +01:00
Jacob Young
7e8ee985e2 tracy: add fiber integration 2026-02-09 10:47:21 -05:00
Jacob Young
f2cbc1912b tracy: replace namedFrame with traceNamed
It is not valid to use frames here because multiple compilations may run
concurrently, and a frame with a given name must stop before starting
again.
2026-02-09 10:47:21 -05:00
Jacob Young
a28d57292f IoUring: update to new Io APIs 2026-02-09 10:47:21 -05:00
Jacob Young
b48599c549 Sema: fix crash compiling an evented compiler 2026-02-09 02:24:56 -05:00
Jacob Young
2961cf1dac tracy: update API 2026-02-09 02:24:56 -05:00
Pivok
f1b2554023 libzigc: hypotf, hypotl (#31150)
Implements hypotf and hypotl for libzigc #30978.

Continuation of #31104

Commands i run:

```
$ stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib

$ stage4/bin/zig build test-libc -Dlibc-test-path=../../libc-test -Dtest-filter=hypotf -fqemu -fwasmtime --summary line
Build Summary: 365/369 steps succeeded (4 skipped)

$ stage4/bin/zig build test-modules -Dtest-target-filter=windows -Dtest-filter=hypotf --summary line
Build Summary: 53/101 steps succeeded (48 skipped)
```

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31150
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: Pivok <pivoc@protonmail.com>
Co-committed-by: Pivok <pivoc@protonmail.com>
2026-02-09 07:59:40 +01:00
antme0
fb18f2096a Allow build.zig scripts to define module definition files (.def) when building win32 dlls. 2026-02-09 07:58:13 +01:00
Meghan Denny
c99b43e3da ArrayList.writer() removed in 57dbc9e74a 2026-02-08 21:24:22 -08:00
Meghan Denny
e4438a58ae fatal removed in b745a96d20 2026-02-08 21:24:05 -08:00
Sam K
6c63926333 Autodoc: display line numbers in source code display 2026-02-08 19:26:48 -08:00
Alex Rønne Petersen
f061c0dc28
ci: disable loongarch64-linux
https://codeberg.org/ziglang/zig/issues/30800
2026-02-08 23:32:18 +01:00
Ben Buhse
52a6242443 std.os.linux: add F_SEAL constants to F struct
Add the missing F_SEAL_SEAL, F_SEAL_SHRINK, F_SEAL_GROW, F_SEAL_WRITE,
F_SEAL_FUTURE_WRITE, and F_SEAL_EXEC constants used with
F.ADD_SEALS/F.GET_SEALS for memfd file sealing. These are defined in the
Linux kernel at include/uapi/linux/fcntl.h.

The FreeBSD equivalents already exist in std.c (freebsd.F),
but the Linux side was missing them.
2026-02-08 02:11:20 +01:00
angus
703df73f38 initialize mutex correctly in kqueue.zig 2026-02-07 14:19:29 +00:00
Jacob Young
b5bd494606 std.Threaded: replace more kernel32 functions with ntdll 2026-02-07 00:02:50 -05:00
Andrew Kelley
12cb5b9285 Merge pull request 'ability to override packages locally' (#31138) from fork-cli into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31138
2026-02-07 02:46:47 +01:00
Andrew Kelley
355c626001 fetch: delete legacy hash functionality
This also removes a unit test that violates project policy of having
binary artifacts as test data when they can be created during the test
instead.
2026-02-06 15:25:05 -08:00
Andrew Kelley
6f18aca09e main: fix cleanup of forks 2026-02-06 15:11:06 -08:00
Andrew Kelley
b24b0479f6 fetch: fix missing check for build.zig existence 2026-02-06 15:10:54 -08:00
Andrew Kelley
9f3b60b23a fetch: ensure that forks are actually used 2026-02-06 14:29:45 -08:00
Andrew Kelley
9d02562717 zig build: don't add --fork to build runner args 2026-02-06 14:12:52 -08:00
Andrew Kelley
632d1fb948 fetch: fix manifest memory management 2026-02-06 14:03:43 -08:00
Andrew Kelley
5f453b45d3 Package: fix Hash.projectId decoding 2026-02-06 14:03:09 -08:00
Andrew Kelley
699063c5a0 fetch: implement the fork override 2026-02-06 13:38:03 -08:00
Andrew Kelley
e661e78256 store the Manifest in the fork set 2026-02-06 13:21:13 -08:00
Andrew Kelley
3d33735d73 zig build: add --fork CLI argument
closes #31124
2026-02-06 12:36:29 -08:00
Mathieu Suen
36b65ab59e
Air: add "unwrap" functions for loading extra data 2026-02-06 13:06:49 +00:00
Andrew Kelley
d84a638e8b Merge pull request 'fetch packages into project-local directory' (#31121) from project-local-deps into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31121
2026-02-06 09:41:28 +01:00
Andrew Kelley
d8171e8a2e fetch: check global cache for compressed tarball
before remote URL
2026-02-05 17:36:14 -08:00
Andrew Kelley
1f65e7cccc fetch: recompress task integrates with std.Progress 2026-02-05 16:50:41 -08:00
Andrew Kelley
7246eee1e7 std.Progress: add Node.startFmt
convenience method for starting a child node with a formatted string as
a name.
2026-02-05 16:50:41 -08:00
Andrew Kelley
ee21a1f988 fetch: implement recompression
After fetching a package and applying the filter by deleting files that
are not part of the hash, creates a recompressed $GLOBAL_CACHE/p/$PKG_HASH.tar.gz

Checking this cache before fetching network URLs is not yet implemented.
2026-02-05 16:50:41 -08:00
Andrew Kelley
df64a3a368 build: packages now require fingerprint
also the name must be an enum literal.

delete some .tar.gz test data. Test data should be in text form when it
can be, and this could definitely be.
2026-02-05 16:50:41 -08:00
Andrew Kelley
64dc1cdad8 fetch: download to local zig-pkg directory
rather than global cache p/ directory.

closes #14283

does not recompress packages into global cache yet
2026-02-05 16:50:41 -08:00
Andrew Kelley
76d275b20f std.Io.Threaded: flatten some switch cases 2026-02-05 16:30:33 -08:00
Andrew Kelley
387d550b6c compiler: remove btrfs workaround functionality
has been fixed in the kernel code for a while now
2026-02-05 16:30:33 -08:00
bgthompson
076f7e5bd5 removed reduntant @as() from switch in getDaysInMonth 2026-02-05 21:58:35 +01:00
Pivok
d0b39c7f2b libzigc: hypot (#31104)
First time contribution.

Implements hypot for libzigc #30978.

Commands i run:
```
$ stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib

$ stage4/bin/zig build test-libc -Dlibc-test-path=../../libc-test -Dtest-filter=hypot --summary line -fqemu -fwasmtime
Build Summary: 725/737 steps succeeded (12 skipped)
```

I also changed std.math.hypot becuase some libc-tests raised fp exceptions. Example:
```
../../libc-test/src/math/special/hypot.h:8: bad fp exception: RN hypot(0x1p-1074,0x0p+0)=0x1p-1074, want 0 got INEXACT|UNDERFLOW
../../libc-test/src/math/special/hypot.h:9: bad fp exception: RN hypot(0x1p-1074,-0x0p+0)=0x1p-1074, want 0 got INEXACT|UNDERFLOW
```

I also run this command as a quick sanity check:
```
$ stage4/bin/zig build test-std -Dtest-filter=hypot -Dtest-target-filter=x86_64-linux-musl --summary line
Build Summary: 5/5 steps succeeded; 136/136 tests passed
```

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31104
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: Pivok <pivoc@protonmail.com>
Co-committed-by: Pivok <pivoc@protonmail.com>
2026-02-05 21:57:32 +01:00
brickmonster
c38f9336a3 std.os.linux: fix test not building 2026-02-05 21:15:54 +01:00
Ryan Liptak
bcb5218a2b Environ: reinstate null return on = in environment variable keys
Changes an assert back into a conditional to match the behavior of `getPosix`, see https://codeberg.org/ziglang/zig/pulls/31113#issuecomment-10371698 and https://github.com/ziglang/zig/issues/23331.
Note: the conditional has been updated to also return null early on 0-length key lookups, since there's no need to iterate the block in that case.

For `Environ.Map`, validation of keys has been split into two categories: 'put' and 'fetch', each of which are tailored to the constraints that the implementation actually relies upon. Specifically:
- Hashing (fetching) requires the keys to be valid WTF-8 on Windows, but does not rely on any other properties of the keys (attempting to fetch `F\x00=` is not a problem, it just won't be found)
- `create{Posix,Windows}Block` relies on the Map to always have fully valid keys (no NUL, no `=` in an invalid location, no zero-length keys), which means that the 'put' APIs need to validate that incoming keys adhere to those properties.
The relevant assertions are now documented on each of the Map functions.

Also reinstates some test cases in the `env_vars` standalone test. Some of the reinstated tests are effectively just testing the Environ.Map implementation due to how `Environ.contains`, `Environ.getAlloc`, etc are implemented, but that is not inherent to those functions so the tests are still potentially relevant if e.g. `contains` is implemented in terms of `getPosix`/`getWindows` in the future (which is totally possible and maybe a good idea since constructing the whole map is not necessary for looking up one key).
2026-02-05 20:24:31 +01:00
Ivel
fa3228ae42 libc: reimplement swab in Zig (#31130)
This PR replaces the bundled musl swab() implementation with zig's one.

Contributes towards #30978.

It looks like there are not test cases for swab() in test-libc.

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31130
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: Ivel <ivel.santos@proton.me>
Co-committed-by: Ivel <ivel.santos@proton.me>
2026-02-05 20:21:41 +01:00
Jacob Young
c77e7146f5 std.Threaded: replace console kernel32 functions with ntdll 2026-02-05 07:41:25 -05:00
Alex Rønne Petersen
f150759953 Merge pull request 'ci: run test-libc on x86_64-linux-release' (#30221) from alexrp/zig:ci-libc-test into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30221
2026-02-05 13:35:49 +01:00
Andrew Kelley
4c35d53b9a Merge pull request 'std.os.windows: move OpenFile and GetFinalPathNameByHandle into Io.Threaded' (#31111) from windows-open-file-again into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31111
2026-02-05 06:25:38 +01:00
Andrew Kelley
3078a3197b std.Io.Threaded.dirCreateDirWindows: remove unexpected error handling 2026-02-04 16:30:19 -08:00
Andrew Kelley
0e7d00776e std.Io.Threaded: inline OpenFile into dirCreateDirWindows 2026-02-04 16:30:19 -08:00
Andrew Kelley
3a5fff45ec std: move os.windows.OpenFile into Io.Threaded
it needs cancelation integration
2026-02-04 16:30:17 -08:00
Andrew Kelley
2a193a3987 std: move GetFinalPathNameByHandle to Io.Threaded
unfortunately this function calls NtCreateFile so it has to participate
in cancelation
2026-02-04 16:27:13 -08:00
Andrew Kelley
b49dc5eb70 build: bump max_rss for C ABI tests on Windows 2026-02-04 16:24:48 -08:00
Andrew Kelley
fcef9905ae Merge pull request 'std.Progress: implement inter-process progress reporting for windows' (#31113) from threaded-win-cleanup into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31113
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-02-05 01:24:18 +01:00
Jacob Young
71156aff80 std.Progress: implement ipc resource cleanup 2026-02-04 15:20:10 -05:00
Alex Rønne Petersen
c3edf0ba64
Merge branch 'netbsd-ci' 2026-02-04 20:44:45 +01:00
Alex Rønne Petersen
012be3efd7
Revert "ci: temporarily disable x86_64-netbsd while I investigate failures"
This reverts commit 99ec1ee353.
2026-02-04 20:44:37 +01:00
Alex Rønne Petersen
06879041ac
link.Lld: disable parallel linking on NetBSD host
To work around NetBSD 10.1 malloc bugs.
2026-02-04 20:44:37 +01:00
Matthew Lugg
a816f9e245
std.Io.Threaded: use _lwp_park correctly for real this time? 2026-02-04 20:44:37 +01:00
Matthew Lugg
fcdde3e4c7
std.Io.Threaded: gracefully handle race leading to ESRCH in unpark() 2026-02-04 20:44:37 +01:00
Jacob Young
ffc6da29e3 std.Io.Threaded: implement and cleanup windows codepaths 2026-02-04 14:15:41 -05:00
Alex Rønne Petersen
fce7878a91
test: disable hexagon-linux-musl C ABI tests for now
https://gitlab.com/qemu-project/qemu/-/issues/3291
2026-02-04 11:11:39 +01:00
Andrew Kelley
d45f9aca14 std.Thread: delete Mutex.Recursive
Replaced by the lockStderr functions of std.Io. Trying to make
`std.process.stderr_thread_mutex` be a bridge across different Io
implementations didn't work in practice.
2026-02-03 20:46:25 -08:00
Andrew Kelley
d1e01e9431 Merge pull request 'std.Io.Threaded: Windows *cannot* spuriously unpark, and introduce ParkingMutex' (#31102) from parking-futex-parking-mutex into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31102
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-02-04 05:06:17 +01:00
Matthew Lugg
6d6532dd9e
Io.Threaded: add ParkingMutex, and deal with spurious unparks on NetBSD
We can't use Io.Mutex in parking_futex; instead, we need a simple
parking-based mutex implementation. That's fairly simple to do.

Also deal with spurious unparks on NetBSD, where they *can* happen (as
opposed to Windows, where they cannot).
2026-02-03 22:50:35 +00:00
Matthew Lugg
7c08f77efa
Revert "std.Io.Threaded: spurious unparks are possible"
It turns out that at least on Windows, spurious unparks are *not*
possible, and in fact triggering them breaks some RTL synchronization
primitives. For instance, if you have a pending unpark going into a
contended `RtlEnterCriticalSection` call, it will never unblock. In
other words, the Windows API worked exactly how I thought it did, and
it's only the NetBSD/Illumos one which is dumb. This is actually exactly
why Windows 8 introduced the parking API despite alertable sleeps being
a thing!

This commit doesn't yet deal with making NetBSD work, nor does it even
compile I imagine. The next commit will fix everything back up.

This reverts commit c518593e97.
2026-02-03 22:47:19 +00:00
Matthew Lugg
56a43fb86f
Revert "std.Io.Threaded: work around parking futex bug"
This reverts commit 5312063138.
2026-02-03 22:38:28 +00:00
Andrew Kelley
1ab5a58474 std.Io.Threaded: handle errors from clockResolution 2026-02-03 12:00:14 -08:00
rpkak
184c8f9545 std.heap.PageAllocator: align hint 2026-02-03 20:27:28 +01:00
Alex Rønne Petersen
e9b442db5a llvm: fix C ABI integer promotion for more targets
Also stop pretending that this function handles _BitInt types correctly.

Handling 32-bit integers on MIPS properly is blocked on: https://github.com/llvm/llvm-project/issues/179088
2026-02-03 20:21:52 +01:00
Alex Rønne Petersen
2fce12b42a test: improve logic for generating stack trace test combinations 2026-02-03 20:19:15 +01:00
Andrew Kelley
e5e4602b18 Merge pull request 'std: finish moving time to Io interface' (#31086) from time into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31086
2026-02-03 20:16:18 +01:00
Ivel
7aae7dd3f4 libzigc: pow 2026-02-03 20:14:22 +01:00
Alex Rønne Petersen
6ce0dd1a81
ci: run test-libc on x86_64-linux-debug-llvm and x86_64-linux-release 2026-02-03 17:19:16 +01:00
Alex Rønne Petersen
02599bccb5
build: bump test-libc max_rss to 3_500_000_000
error: memory usage peaked at 3.11GB (3105054720 bytes), exceeding the declared upper bound of 2.90GB (2900000000 bytes)
2026-02-03 17:19:03 +01:00
Andrew Kelley
fe5da36aa3 std.Io make Clock.resolution fallible 2026-02-03 01:02:48 -08:00
Andrew Kelley
11476d83c9 stage1: add wasi_snapshot_preview1_clock_res_get to wasi.c 2026-02-02 23:14:06 -08:00
Andrew Kelley
922ab8b8bc std: finish moving time to Io interface
Importantly, adds ability to get Clock resolution, which may be zero.
This allows error.Unexpected and error.ClockUnsupported to be removed
from timeout and clock reading error sets.
2026-02-02 23:02:31 -08:00
Andrew Kelley
e7e700334d Merge pull request 'std.Thread sync primitives roundup' (#31084) from sync-cleanup into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31084
2026-02-03 07:52:02 +01:00
Andrew Kelley
4c4e9d054e std.Io: add RwLock and Semaphore sync primitives
and restore usage by std.debug.SelfInfo.Elf
2026-02-02 20:18:14 -08:00
Andrew Kelley
550da1b676 std: migrate remaining sync primitives to Io
- delete std.Thread.Futex
- delete std.Thread.Mutex
- delete std.Thread.Semaphore
- delete std.Thread.Condition
- delete std.Thread.RwLock
- delete std.once

std.Thread.Mutex.Recursive remains... for now. it will be replaced with
a special purpose mechanism used only by panic logic.

std.Io.Threaded exposes mutexLock and mutexUnlock for the advanced case
when you need to call them directly.
2026-02-02 18:57:17 -08:00
Andrew Kelley
255aeb57b2 std: introduce atomic.Mutex and use it in heap.SmpAllocator
This allocator implementation uses only lock-free operations.
2026-02-02 18:36:40 -08:00
Andrew Kelley
e9eadee006 Merge pull request 'std.Io.Threaded: sever dependency on std.Thread Mutex and Condition' (#31096) from severance into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31096
2026-02-03 03:30:42 +01:00
Andrew Kelley
5312063138 std.Io.Threaded: work around parking futex bug
This commit should be reverted - it's testing a hypothesis that Windows
is deadlocking due to bug in the implementation of
std.Io.Threaded.parking_futex
2026-02-02 14:25:27 -08:00
Andrew Kelley
eb74e23e7b std.Io.Threaded: sever dependency on std.Thread Mutex and Condition 2026-02-02 14:18:04 -08:00
Andrew Kelley
c2d4806d65 Merge pull request 'std.Thread: remove redundant sync APIs ResetEvent and WaitGroup' (#31088) from sync-cleanup-smaller into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31088
2026-02-02 23:14:05 +01:00
Krzysztof Antonowski
1cd3af43fd std.Io.Threaded: implement CPU-based clocks on Windows (#31093)
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31093
Co-authored-by: Krzysztof Antonowski <krzysztofantonowski@proton.me>
Co-committed-by: Krzysztof Antonowski <krzysztofantonowski@proton.me>
2026-02-02 22:19:19 +01:00
Andrew Kelley
b71e593df4 Merge pull request 'Add process.Child.Cwd, use it for cwd and remove cwd_dir field' (#31090) from squeek502/zig:unify-child-cwd into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31090
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-02-02 19:56:40 +01:00
Andrew Kelley
633eb247ab std.Io.Event: fix single-threaded implementation 2026-02-02 10:44:50 -08:00
Ryan Liptak
05346e123b Add process.Child.Cwd, use it for cwd and remove cwd_dir field
The user must now explicitly choose between inheriting the current CWD, passing a path for the CWD, or passing a Dir for the CWD.
2026-02-02 01:41:35 -08:00
Tom Winter
83abd73801 Windows: Support directory handle for cwd instead of string for Child.process
This implementation is a bit of a hacky workaround, as we use a ntdll
API to grab the full path of the directory handle. As far as I can tell
this might be the only solution to the problem, as
kernel32.CreateProcessW takes a directory path as a string only.

I might be wrong though as haven't researched the problem thoroughly.
2026-02-02 01:21:11 -08:00
Andrew Kelley
b191e50be5 std.Thread: remove ResetEvent and WaitGroup
* std.Thread.ResetEvent -> Io.Event
* std.Thread.WaitGroup -> Io.Group
2026-02-02 00:09:48 -08:00
Andrew Kelley
60ac4e78eb std.Io.Mutex: fix tryLock
`@cmpxchgWeak` can return the expected value sometimes.
2026-02-02 00:09:48 -08:00
Jake Greenfield
aacf8ce03d Use MultiReader in zig std 2026-02-01 22:22:47 -05:00
Andrew Kelley
37d14a4f3b Merge pull request 'libzigc: cbrt, cbrtf' (#31078) from jeffective/zig:jeff/libzigc-cbrt into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31078
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-02-01 20:03:57 +01:00
Andrew Kelley
171459f678 Merge pull request 'libzigc: round, roundf' (#31075) from jeffective/zig:jeff/libzigc-round into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31075
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-02-01 20:02:06 +01:00
Andrew Kelley
59073484ba std.Io: add ioctl / DeviceIoControlFile API 2026-02-01 01:08:01 -08:00
Jeff Anderson
4aadb5e4a5 libzigc: cbrtf 2026-02-01 00:09:54 -08:00
Jeff Anderson
0aae9768aa libzigc: cbrt 2026-02-01 00:09:45 -08:00
Andrew Kelley
e5454ff780 Merge pull request 'std.Io: move fileWriteStreaming to Operation' (#31065) from more-poll into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31065
2026-02-01 07:56:09 +01:00
Andrew Kelley
cc442d24ab std.Io: move fileWriteStreaming to Operation
This serves as an example to contributors of how to move VTable
functions to becoming an Operation, thereby enabling Batch API and
timeouts.
2026-01-31 22:53:28 -08:00
Andrew Kelley
9bd648bd40 std.Io.Operation: support non-fallible results 2026-01-31 22:52:00 -08:00
Jeff Anderson
379d128cba libzigc: roundf 2026-01-31 18:18:29 -08:00
Andrew Kelley
3abc96a601 std.Io: add test for batchAwaitAsync
and make it always work for all targets including WASI

This function guarantees no additional failure modes introduced.
2026-02-01 02:49:36 +01:00
Jeff Anderson
69a95571ed libzigc: round 2026-01-31 17:26:17 -08:00
kj4tmp@gmail.com
e60ba21114 libzigc: roundl 2026-02-01 00:59:35 +01:00
Andrew Kelley
2b19134c86 Merge pull request 'std.Io: introduce batching and operations API, satisfying the "poll" use case' (#30743) from poll into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30743
2026-01-31 12:07:31 +01:00
Andrew Kelley
5ccc2ea85d
std: IoUring test handles EINTR 2026-01-31 09:36:40 +01:00
Alex Rønne Petersen
da95409f31 Merge pull request 'llvm: handle packed structs in C ABI integer promotion' (#31062) from alexrp/zig:packed-struct-cconv-fix into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31062
2026-01-31 07:09:19 +01:00
Andrew Kelley
9646801bed std: fix Preopens compilation error 2026-01-30 22:06:33 -08:00
Andrew Kelley
14e1e5f6d8 std: IoUring test handles EINTR 2026-01-30 22:03:44 -08:00
Andrew Kelley
43866f7439 build.zig: bump max_rss
encountered error: memory usage peaked at 0.66GB (656060416 bytes),
exceeding the declared upper bound of 0.64GB (639565414 bytes)
2026-01-30 22:03:39 -08:00
Andrew Kelley
b6f4bb91c4 std.Io: add documentation to Batch 2026-01-30 22:03:33 -08:00
Andrew Kelley
25aef0dd87 std.Io.Threaded: rework file reading to observe nonblocking flag
- batchAwaitAsync does blocking reads with NtReadFile (no APC, no event)
  when the nonblocking flag is unset, but still takes advantage of
  APCs when nonblocking flag is set.
- batchAwaitConcurrent returns error.ConcurrencyUnavailable when it
  encounters a file_read_streaming operation on a file in blocking mode.
- fileReadStreaming avoids pointlessly checking sync cancelation status
  when nonblocking flag is set, uses an APC with a done flag, and waits
  on that value to change in NtDelayExecution before returning.
- fix incorrect use of NtCancelIoFile (ntdll function prototype was
  wrong, leading to misuse)
2026-01-30 22:03:14 -08:00
Andrew Kelley
39a6d5d1c5 std.Io.File: add non-blocking flag
On Windows, we need to know ahead of time whether a file was opened in
synchronous mode or asynchronous mode. There may be advantages to
tracking this state for POSIX operating systems as well.
2026-01-30 22:03:14 -08:00
Andrew Kelley
62c97b745d std.Io.Threaded: stop checking bytes read with END_OF_FILE 2026-01-30 22:03:14 -08:00
Jacob Young
2674acdb77 Io.Batch: implement alternate API 2026-01-30 22:03:14 -08:00
Andrew Kelley
a520355e4c std.process: simplify RunError set 2026-01-30 22:03:14 -08:00
Andrew Kelley
a41ee5994d std.Build.Step: evalZigProcess handles EndOfStream
and a happy little info log when the process needs to be restarted
2026-01-30 22:03:14 -08:00
Andrew Kelley
866ee4f1c5 std.Io.Threaded: handle TIMEOUT from NtDelayExceution 2026-01-30 22:03:14 -08:00
Matthew Lugg
f8828e543a std.Build: fully upgrade Step.Run to std.Io timing (and fix a typo) 2026-01-30 22:03:14 -08:00
Matthew Lugg
c2679feaaa std.Io.Threaded: fix ntdll timeouts on Windows 2026-01-30 22:03:14 -08:00
Andrew Kelley
8f8aa8346a std.Io.Threaded: ntReadFileResult handles EOF + bytes available 2026-01-30 22:03:14 -08:00
Andrew Kelley
4dd7fe90a2 std.Io.Threaded: compress ntReadFile logic
Just use the ntstatus field rather than an additional enum
2026-01-30 22:03:14 -08:00
Andrew Kelley
3320e6a1ae std.Io.Threaded.batchWait better fix for any_done
It is legal to call batchWait with already completed operations in the
ring. In such case, we need to avoid waiting in the syscall. The
any_done flag was a poor way of tracking state we already have: whether
the completion queue is empty.

This problem affects the posix poll implementation as well.

Thanks again to jacobly for finding the problem.
2026-01-30 22:03:14 -08:00
Andrew Kelley
d770e14e00 std.Io.Threaded.batchWaitWindows: eager result sets any_done true
Thanks jacobly for finding the bug
2026-01-30 22:03:14 -08:00
Andrew Kelley
7a13d57916 std.Io.Threaded: add missing check for pending status in batchCancel 2026-01-30 22:03:14 -08:00
Andrew Kelley
687123a85e std.process.run: use Io.File.MultiReader
and delete the special-cased function
2026-01-30 22:03:14 -08:00
Andrew Kelley
b2816f2698 build.zig: only-c implies no-lib 2026-01-30 22:03:14 -08:00
Andrew Kelley
6a1fd3c69d std.Io.File.MultiReader: make checkAnyError exclude EndOfStream 2026-01-30 22:03:14 -08:00
Andrew Kelley
8a80b54640 std: remove error.BrokenPipe from file reads, add error.EndOfStream
and make reading file streaming allowed to return 0 byte reads.
According to Microsoft documentation, on Windows it is possible to get
0-byte reads from pipes when 0-byte writes are made.
2026-01-30 22:03:14 -08:00
Andrew Kelley
fdf1ee973e std.Io.Threaded: move the NtDelayExecution later in batchWait
also guard against receiving SUCCESS with 0 byte read

ms docs say that pipes can do this if there is a 0 byte write
2026-01-30 22:03:14 -08:00
Andrew Kelley
2fb224cb84 std.Io.Threaded: fix bad use of AlertableSyscall
The defer would cause two problems:
1. keeping the state active during call to NtCancelIoFile
2. invalid state transition. after canceled is returned from
   checkCancel, new status is already canceled. calling finish after
   that is illegal.
2026-01-30 22:03:14 -08:00
Andrew Kelley
efa502a1cd std.Build.Step.Run: gracefully handle test runner misbehavior
specifically if it misbehaves after sending a message header but not the
body
2026-01-30 22:03:14 -08:00
Andrew Kelley
523aa213c9 std.Io.Threaded: batchWait and batchCancel for Windows 2026-01-30 22:03:14 -08:00
Andrew Kelley
37316a3cf6 std.Io.Threaded: resolve merge conflicts 2026-01-30 22:03:14 -08:00
Andrew Kelley
276ca77bf0 build: adjust max_rss for behavior tests
observed error: memory usage peaked at 0.70GB (699138048 bytes),
exceeding the declared upper bound of 0.66GB (659809075 bytes)
2026-01-30 22:03:14 -08:00
Andrew Kelley
ec74d650fe incr-check: update to std.Io.File.MultiReader
from std.Io.poll
2026-01-30 22:03:14 -08:00
Andrew Kelley
a901ea23b0 update doctest API usage 2026-01-30 22:03:14 -08:00
Andrew Kelley
15ca46d1e7 std.Io.Threaded: fix compilation error on some systems 2026-01-30 22:03:14 -08:00
Andrew Kelley
a4d438562d std.Io.Threaded: fix compilation failures on Windows
it's still broken as hell tho
2026-01-30 22:03:14 -08:00
Andrew Kelley
54241bc770 tools: update for std.process API changes 2026-01-30 22:03:14 -08:00
Andrew Kelley
9134430387 std.Io.Threaded: fix batchWait impl 2026-01-30 22:03:14 -08:00
Andrew Kelley
68a34df025 std.Io.Threaded: fix error set 2026-01-30 22:03:14 -08:00
Andrew Kelley
372e8e54d3 compiler: update for std.Io.File.MultiReader API 2026-01-30 22:03:14 -08:00
Andrew Kelley
dd0153b91b std.Io.operate: fix bogus catch
this used to have a different error set. just goes to show you how
useful switching on error set is even when there is only 1 prong
2026-01-30 22:03:14 -08:00
Andrew Kelley
e56563ce3f std.Io.File.MultiReader: implementation fixes 2026-01-30 22:03:14 -08:00
Andrew Kelley
12cfc96e1b std: update rest of build runner to new File.MultiReader API 2026-01-30 22:03:14 -08:00
Andrew Kelley
20cadd60aa std.Io.File: introduce MultiReader
Concurrently read from multiple file streams, eliminating risk of
deadlocking.
2026-01-30 22:03:14 -08:00
Andrew Kelley
a0c2645948 std.Io.Threaded: delete dead code 2026-01-30 22:03:14 -08:00
Andrew Kelley
78a1476475 Build.WebServer: update concurrency API usage 2026-01-30 22:03:14 -08:00
Jacob Young
8146ccfecc Io: add ring to Batch API 2026-01-30 22:03:14 -08:00
Andrew Kelley
0a379513af std.Io.Threaded: super broken Windows impl of batch
this is a cry for help
2026-01-30 22:03:14 -08:00
Andrew Kelley
23d25dbb9e std.process.Child.collectOutput: change back to other impl
this one avoids calling poll() more than necessary
2026-01-30 22:03:14 -08:00
Andrew Kelley
642f329ac9 std.Io: exploring a different batch API proposal 2026-01-30 22:03:14 -08:00
Andrew Kelley
e2a266e744 Revert "std.process.Child: rewrite using concurrent"
This reverts commit 76e1ba8f490812c6e2ebf6f6becd89a71275d21e.
2026-01-30 22:03:13 -08:00
Andrew Kelley
87408f8add std.process.Child: rewrite using concurrent
I plan to immediately revert this, but here's a commit for posterity
2026-01-30 22:03:13 -08:00
Andrew Kelley
b996675dcf fix error set 2026-01-30 22:03:13 -08:00
Andrew Kelley
e0d06b40e3 std.Io.Threaded: set poll_buffer_len to 32
reasoning is that polling with large amount of operations will be rarely
done with std.Io.Threaded. However this still provides the opportunity
to provide concurrency for any real world use cases that need it.
2026-01-30 22:03:13 -08:00
Andrew Kelley
6a7fe61d74 std.Io.Threaded.operate: handle poll buffer exceeded 2026-01-30 22:03:13 -08:00
Andrew Kelley
93f5c99149 std.Io.Threaded.operate: handle cancelation and poll errors 2026-01-30 22:03:13 -08:00
Andrew Kelley
05064e1281 std.Io: simplify operate function
- no timeout
- no n_wait
- infallible
2026-01-30 22:03:13 -08:00
Andrew Kelley
0a0ecc4fb1 std.Io: proof-of-concept "operations" API
This commit shows a proof-of-concept direction for std.Io.VTable to go,
which is to have general support for batching, timeouts, and
non-blocking.

I'm not sure if this is a good idea or not so I'm putting it up for
scrutiny.

This commit introduces `std.Io.operate`, `std.Io.Operation`, and
implements it experimentally for `FileReadStreaming`.

In `std.Io.Threaded`, the implementation is based on poll().

This commit shows how it can be used in `std.process.run` to collect
both stdout and stderr in a single-threaded program using
`std.Threaded.Io`.

It also demonstrates how to upgrade code that was previously using
`std.Io.poll` (*not* integrated with the interface!) using concurrency.
This may not be ideal since it makes the build runner no longer support
single-threaded mode. There is still a needed abstraction for
conveniently reading multiple File streams concurrently without
io.concurrent, but this commit demonstrates that such an API can be
built on top of the new `std.Io.operate` functionality.
2026-01-30 22:03:13 -08:00
Andrew Kelley
bd4b6d8b14 std.Io: delete the poll API 2026-01-30 22:03:13 -08:00
Jacob Young
90890fcb5c Io.Threaded: fix UAF-induced crashes during asynchronous operations
When `NtReadFile` returns `SUCCESS`, the APC routine still runs when
next alertable, which was previously clobbering an out of scope `done`.
Instead of adding an extra syscall to the success path, avoid all APC
side effects, allowing instant completions to return immediately.
2026-01-30 22:03:13 -08:00
Andrew Kelley
9862518797 std.Io.Threaded: fix NtDelayExecution delay interval 2026-01-30 22:03:13 -08:00
Andrew Kelley
11b0a504df std.Io.Threaded: handle some more error codes from NtReadFile 2026-01-30 22:03:13 -08:00
Andrew Kelley
6d9e6e2c38 std.Io.Threaded: avoid extra fields of Thread
As mlugg pointed out those race when a thread finishes an operation just
after it is canceled and then that thread to picks up another task,
resulting in these fields being potentially overwritten.

This updates fileReadStreaming on Windows to handle being alerted, and
then manage its own cancelation of the file I/O.
2026-01-30 22:03:13 -08:00
Andrew Kelley
a933d7a6f8 std.Io.Threaded: don't pass null to NtDelayExecution
Windows returns ACCESS_VIOLATION if you do that.
2026-01-30 22:03:13 -08:00
Andrew Kelley
e705ad8302 std.Io.Threaded: implement APC cancelation
specifically the call to NtCancelIoFileEx
2026-01-30 22:03:13 -08:00
Andrew Kelley
1e3072ec46 std.Io.Threaded: introduce Thread.InterruptMethod
implements APC cancelation except for the actual call to NtCancelIoFileEx
2026-01-30 22:03:13 -08:00
Andrew Kelley
5580257596 std.Io.Threaded: add some temporary, choice panics 2026-01-30 22:03:13 -08:00
Andrew Kelley
8827488fcd std: back out the flags field of Io.File
For now, let us refrain from putting the sync mode into the Io.File
struct, and document that to do concurrent batch operations, any Windows
file handles must be in asynchronous mode. The consequences for
violating this requirement is neither illegal behavior, nor an error,
but that concurrency is lost. In other words, deadlock might occur. This
prevents the addition of flags field.

partial revert of 2faf14200f58ee72ec3a13e894d765f59e6483a9
2026-01-30 22:03:13 -08:00
Andrew Kelley
cb7be96644 std.Io: give File a nonblocking bit on Windows
This tracks whether it is a file opened in synchronous mode, or
something that supports APC.

This will be needed in order to know whether concurrent batch operations
on the file should return error.ConcurrencyUnavailable, or use APC to
complete the batch.

This patch also switches to using NtCreateFile directly in
std.Io.Threaded for dirCreateFile, as well as NtReadFile for
fileReadStreaming, making it handle files opened in synchronous mode as
well as files opened in asynchronous mode.
2026-01-30 22:03:13 -08:00
Justus Klausecker
c7c4e8d802 Sema: harden switch logic against undef IB
Most places where `undefined` was previously (intentionally) passed across
function calls now use `Air.Inst.Ref.none` instead to ensure that these
`undefined` references don't accidentally outlive the `switch` logic they
belong to.
2026-01-31 06:36:07 +01:00
Alex Rønne Petersen
7c68ab1d10
std.os.linux: add MAP.DROPPABLE
Introduced in Linux 6.11.
2026-01-31 00:08:35 +01:00
Alex Rønne Petersen
cbe38f771c
std.Io.Threaded: consider EOPNOTSUPP to be programmer error in createFileMap()
Not doing so was hiding bugs (e.g. on s390x-linux).
2026-01-31 00:08:34 +01:00
Alex Rønne Petersen
c6538b70f5
llvm: handle packed structs in C ABI integer promotion 2026-01-31 00:08:32 +01:00
mercenary
fa988e88ed zstd.Decompress: smarter rebase when discarding (#30891)
The call to `rebase` in `discardIndirect` and `discardDirect` was inappropriate. As `rebase` expects the `capacity` parameter to exclude the sliding window, this call was asking for ANOTHER `d.window_len` bytes. This was impossible to fulfill with a buffer smaller than 2*`d.window_len`, and caused [#25764](https://github.com/ziglang/zig/issues/25764).

This PR adds a basic test to do a discard (which does trigger [#25764](https://github.com/ziglang/zig/issues/25764)), and rebases only as much as is required to make the discard succeed ([or no rebase at all](https://github.com/ziglang/zig/issues/25764#issuecomment-3484716253)). That means: ideally rebase to fit `limit`, or if the buffer is too small, as much as possible.

I must say, `discardDirect` does not make much sense to me, but I replaced it anyway. `rebaseForDiscard` works fine with `d.reader.buffer.len == 0`. Let me know if anything should be changed.

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30891
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: mercenary <mercenary@noreply.codeberg.org>
Co-committed-by: mercenary <mercenary@noreply.codeberg.org>
2026-01-30 20:19:19 +01:00
Andrew Kelley
aa38f07c51 Merge pull request 'add std.Io.net.Socket.createPair + handful of std.posix removals' (#31056) from std.posix-removals into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31056
2026-01-30 14:30:25 +01:00
Andrew Kelley
6a3226c43c std.Io: add net.Socket.createPair
and remove the following from std.posix:
- socketpair
- fcntl
2026-01-30 02:07:26 -08:00
Andrew Kelley
0c67d9ebde std.posix: goodbye gettimeofday 2026-01-30 01:58:49 -08:00
Andrew Kelley
36eb8dec98 std.posix: goodbye to some functions
- fstat
- inotify_init1
- inotify_add_watch, inotify_add_watchZ
- inotify_rm_watch
- sysctlbynameZ
2026-01-30 01:58:49 -08:00
Andrew Kelley
e7e168727e std.posix: goodbye connect, eventfd 2026-01-30 01:58:49 -08:00
rpkak
b9819fce69 Io.Threaded: limit copy_file_range len to prevent EOVERFLOW 2026-01-30 08:19:50 +01:00
Andrew Kelley
380ea6fb5e Merge pull request 'Compilation: make libzigc share zcu if possible' (#31037) from GasInfinity/zig:libc-share-zcu into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31037
2026-01-30 08:16:39 +01:00
Andrew Kelley
377bb8f237 Merge pull request 'std: migrate getcwd to Io' (#31047) from getcwd into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31047
2026-01-30 06:38:08 +01:00
lzm-build
ccd82ae7cc Add f16, f80 and f128 support for atan 2026-01-30 06:20:14 +01:00
Pablo Alessandro Santos Hugen
ad0458f582 std.Build: Fix wrong error enum
Signed-off-by: Pablo Alessandro Santos Hugen <phugen@redhat.com>
2026-01-30 06:19:49 +01:00
Brandon Black
ecb9ddf267 Threaded.sleepPosix: fix libc error handling
Confusingly, the POSIX spec for clock_nanosleep() says it returns
*positive* error values directly and does not touch `errno`. Not
detecting EINTR properly here was breaking the cancellation of
threads blocked in this call when linking libc.
2026-01-30 06:19:31 +01:00
Andrew Kelley
b1d1806fef std.process: currentDir -> currentPath
In Zig standard library, Dir means an open directory handle. path
represents a file system identifier string. This function is better
named after "current path" than "current dir". "get" and "working" are
superfluous.
2026-01-29 18:47:58 -08:00
Andrew Kelley
0a37ad2ec4 std.Io.File: handle DISK_FULL on windows 2026-01-29 18:40:56 -08:00
Andrew Kelley
3cc5dda756 fix RtlGetCurrentDirectory_U parameter
it's the byte length not number of wchars
2026-01-29 18:40:56 -08:00
Andrew Kelley
649aaf4814 std: migrate getcwd to Io
progress towards #30150
2026-01-29 18:40:55 -08:00
Andrew Kelley
9b415761dd std.os.windows: delete unused APIs
Intention is to go through std.Io for these things.
2026-01-30 03:39:46 +01:00
Andrew Kelley
5571c08e66 add behavior test for i96 operations 2026-01-29 19:57:36 +01:00
Andrew Kelley
4d6f4e9cfd behavior: add coverage for extern struct field overalignment 2026-01-29 19:56:46 +01:00
GasInfinity
ed93f0d70f
fix(libzigc): always apply strong linkage, even when testing
* libzigc may be linked into a different test compilation

Co-authored-by: Matthew Lugg <mlugg@mlugg.co.uk>
2026-01-29 10:39:38 +01:00
GasInfinity
e7baa09ce4
feat(Compilation): make libzigc share zcu if possible 2026-01-29 10:31:56 +01:00
Andrew Kelley
37a9ca7163 Merge pull request 'std: finish moving os.windows.ReadLink logic to Io.Threaded' (#31044) from windows-OpenFile into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31044
2026-01-29 08:40:37 +01:00
Andrew Kelley
18c6abc0ba std: finish moving os.windows.ReadLink logic to Io.Threaded
- remove error.SharingViolation from all error sets since it has the
  same meaning as FileBusy
- add error.FileBusy to CreateFileAtomicError and ReadLinkError
- update dirReadLinkWindows to use NtCreateFile and NtFsControlFile and
  integrate with cancelation properly.
- move windows CTL_CODE constants to the proper namespace
- delete os.windows.ReadLink
2026-01-28 17:02:17 -08:00
Andrew Kelley
5774248041 std.os.windows: delete unused CreateSymbolicLink 2026-01-28 15:33:04 -08:00
lzm-build
757ec185f0 Add f16, f80 and f128 support for acos and asin (#30997)
The software impl of `acos` and `asin` depends on the `sqrt` op. Since support for `sqrt` in `f16`, `f80`, and `f128` has been added, the impl of `acos` and `asin` for `f16`, `f80`, and `f128` is now being supplemented.

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30997
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: lzm-build <3575188313@qq.com>
Co-committed-by: lzm-build <3575188313@qq.com>
2026-01-28 23:33:35 +01:00
Andrew Kelley
3b10383114 std.meta: delete declList
dubious. if people want this logic they should take responsibility for
it in their own code.
2026-01-28 00:43:20 -08:00
Krzysztof Wolicki
204fa8959a Make functions on EnumMap always take a pointer to avoid copies of big EnumMaps 2026-01-28 03:13:37 +01:00
llogick
11c3b4bd41 Fix std.process.run leaking memory if child.wait returned an error 2026-01-28 03:12:00 +01:00
Alex Rønne Petersen
0f51f663f0
musl: update some hexagon headers from the quic fork 2026-01-27 23:24:57 +01:00
just_some_entity
06cf86abeb Fix BootServices.locateHandleLen() (#30877)
Fixes https://codeberg.org/ziglang/zig/issues/30876

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30877
Reviewed-by: linus <mail@linusgroh.de>
Co-authored-by: just_some_entity <entity@jsentity.dev>
Co-committed-by: just_some_entity <entity@jsentity.dev>
2026-01-27 23:09:51 +01:00
Ryan Liptak
1655a666d5 windows_resources standalone test: Load a resource and check its data
Just a potential way to catch regressions and to ensure the resources actually make it into the binary correctly.
2026-01-27 20:48:59 +01:00
Ryan Liptak
29b7214027 Disentangle from error.CurrentWorkingDirectoryUnlinked
This error is actually only ever directly returned from `std.posix.getcwd` (and only on POSIX systems, so never on Windows). Its inclusion in almost all of the error sets its currently found in is a leftover from when `std.fs.path.resolve` called `std.process.getCwdAlloc` (https://github.com/ziglang/zig/issues/13613).
2026-01-27 20:48:25 +01:00
Andrew Kelley
3729a53eec Merge pull request 'libc: use common implementations for linux syscalls' (#30993) from GasInfinity/zig:libc-musl-syscalls into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30993
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-01-27 07:48:58 +01:00
Alex Rønne Petersen
5652288e5d
zig fmt
oops
2026-01-27 07:05:14 +01:00
Alex Rønne Petersen
f7df723a91
Merge branch 'prefer-io-futex' 2026-01-27 05:37:40 +01:00
Alex Rønne Petersen
2c7d3c8007
std.debug: use debug_io for the futex in waitForOtherThreadToFinishPanicking 2026-01-27 05:37:01 +01:00
Alex Rønne Petersen
d4d210fb37
std.Build.WebServer: use Io futex operations instead of std.Thread.Futex 2026-01-27 05:37:01 +01:00
Robert Ancell
0af79e7b8c std.mem.readVarInt: Fix type name in doc comment (#31007)
Code used `ReturnType`, comment used `T` (which is what is used in similar functions).

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31007
Co-authored-by: Robert Ancell <robert.ancell@gmail.com>
Co-committed-by: Robert Ancell <robert.ancell@gmail.com>
2026-01-27 05:29:51 +01:00
Pablo Alessandro Santos Hugen
951ab1b18b std.Build.Step.Compile: pass target by pointer to isLibC*LibName 2026-01-27 05:29:04 +01:00
Alex Rønne Petersen
519f1eb361
musl: zero fp/lr registers in _start() and clone() on hexagon 2026-01-27 05:23:31 +01:00
Brian Orora
4e3fadd90e std.heap.DebugAllocator: fix account total_requested_bytes on resizeSmall 2026-01-27 00:09:48 +01:00
GasInfinity
73ed351022 fix(libzigc): export mincore 2026-01-27 00:06:18 +01:00
Carmen
5e9c484745 std.Io.Reader.takeStruct: dont assert buffer capacity is sizeOf(T) 2026-01-27 00:05:42 +01:00
Jay Petacat
97986184ca langref: Add table of largest integer types that can coerce to floats
Add vertical margin to the `.table-wrapper` class so that there's space
between the table and the test figures. It does not affect any of the
existing tables because the margin collapses with the adjacent `<p>`.
2026-01-26 23:52:30 +01:00
Andrew Kelley
1b235540c1 Revert "Io.Threaded: remove WSA_FLAG_OVERLAPPED from socket call"
The stated reason for this commit was cancelation didn't work. On
further review, we know why cancelation didn't work, and recent
enhancements on master branch make it easy to make it work.

Meanwhile, not using overlapped means that multiple threads cannot use
the same open socket handle. I also added line comments to explain the
choice in this revert commit.

This reverts commit fd3657bf8c.

closes #31011
reopens #30865
2026-01-26 14:16:28 -08:00
Andrew Kelley
5eb55ba866 Merge pull request 'compiler: use Io.MemoryMap' (#30961) from use-mmap into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30961
2026-01-26 22:58:01 +01:00
Alex Rønne Petersen
8d4b8ab6a5 Merge pull request 'glibc 2.43' (#31005) from alexrp/zig:glibc-2.43 into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31005
2026-01-26 18:42:37 +01:00
jsentity
b4c86c850d Fix std.uefi.protocol.DevicePath.next() and add utility function isEnd() (#30887)
Fix for https://codeberg.org/ziglang/zig/issues/30884 and https://codeberg.org/ziglang/zig/issues/30885

Co-authored-by: jsentity <jsentity@noreply.codeberg.org>
Co-committed-by: jsentity <jsentity@noreply.codeberg.org>
2026-01-26 11:41:22 +01:00
Alex Rønne Petersen
ff8dbd010f
libc: update glibc crt0 code to 2.43 2026-01-26 05:56:54 +01:00
Alex Rønne Petersen
e4058f2c27
libc: update glibc abilists to 2.43 2026-01-26 05:56:54 +01:00
Alex Rønne Petersen
49afd7eee0
libc: update glibc headers to 2.43 2026-01-26 05:56:54 +01:00
Alex Rønne Petersen
f6ed859cb0
std.zig.target: update glibc triples for loongarch64 targets 2026-01-26 05:56:53 +01:00
Michael Dusan
f186809caf
std: impl process.totalSystemMemory for netbsd 2026-01-25 13:03:22 -05:00
Frank Denis
8709f53d44 crypto.ff: allow seamless chaining regardless of representation (#30913)
Finite field elements can be in regular or Montgomery form, and
chaining different operations use to require manual and error-prone
conversions.

Now:

- `add`, `sub` and `mul` convert the second operand to match the
first operand's form
- `sq` and `pow` preserve the input's Montgomery form
- `toPrimitive` and `toBytes` return `UnexpectedRepresentation` if
the element is in Montgomery form, preventing incorrect serialization

This is fully backwards compatible and allows seamless chaining of
operations regardless of their representation.
2026-01-25 17:42:01 +01:00
Alex Rønne Petersen
99ec1ee353
ci: temporarily disable x86_64-netbsd while I investigate failures 2026-01-24 21:08:20 +01:00
GasInfinity
9cf34a8d81
feat(libzigc): move over some linux syscalls
* does not move all of them, only those which map almost 1:1
* also removes their musl implementation
2026-01-24 20:41:15 +01:00
GasInfinity
b430cd62e4
feat(std.os.linux): add some missing syscalls 2026-01-24 20:41:15 +01:00
GasInfinity
d5c3bf25dc
feat(std.c): add _Exit 2026-01-24 20:41:15 +01:00
Andrew Kelley
a2ea36a517 zig libc: modify errno helper to eliminate @intCast
The vast majority of libc functions return `c_int` for the return value,
when setting errno. This utility function is for those cases.

Other cases can hand-roll the logic, or additional helpers can be added.
2026-01-24 20:18:18 +01:00
Alex Rønne Petersen
9d63dfaa81
link.Lld: give better exit status information for the lld child process
It's not nice to just throw away useful information.
2026-01-24 18:30:55 +01:00
Alex Rønne Petersen
cf48041b55 std.Thread.Condition: use pthread_cond_t impl when OS has no futex primitive
Same principle as #30835.
2026-01-24 16:44:55 +01:00
Lukas Lalinsky
5f950884a1 std.c: add IPPROTO_RAW for Darwin platforms
IPPROTO_RAW (255) was missing from the Darwin/macOS IPPROTO struct,
even though it is defined in system headers and supported by the platform.
This is a commonly used protocol for raw IP sockets.
2026-01-24 12:26:00 +01:00
Alex Rønne Petersen
1b544f447a Merge pull request 'enable thumb-windows-gnu module tests' (#30968) from alexrp/zig:windows-pic into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30968
2026-01-24 02:09:41 +01:00
Andrew Kelley
5c42193b17 std.Io.Threaded: rework cancelation
Now it can handle sync cancelation and alertable cancelation on Windows.

Also fix the API of NtCancelIoFileEx
2026-01-23 12:59:36 -08:00
Alex Rønne Petersen
e437efd601
test: enable thumb-windows-gnu module tests
We use long calls for these just like thumb*-linux-* to prevent range issues as
the binaries grow larger over time.

We also need function and data sections due to the many __stack_chk_guard
references within the std test binary; without these options, the linker is not
able to insert range thunks in between functions because the std binary just has
one giant .text section that's opaque to the linker.

closes https://codeberg.org/ziglang/zig/issues/30923
2026-01-23 21:16:03 +01:00
Alex Rønne Petersen
c699bb8134
zig cc: don't bother passing -fPIC to Clang for Windows and UEFI targets
It's completely ignored anyway, by design, for compatibility reasons.
2026-01-23 21:16:03 +01:00
Alex Rønne Petersen
909159ad8e
compiler: don't enforce PIC for x86-windows and thumb-windows
Only x86_64-windows and aarch64-windows actually require PIC.
2026-01-23 21:16:01 +01:00
Alex Rønne Petersen
20fae334ac
compiler: UEFI does not support dynamic linking 2026-01-23 19:50:51 +01:00
Alex Rønne Petersen
2774436a83
ci: bump riscv64-linux-debug timeout by 1 hour 2026-01-23 16:17:47 +01:00
Andrew Kelley
499ba5d55c compiler: use Io.MemoryMap
Also make setLength return error.OperationUnsupported when it cannot be
done atomically.
2026-01-22 21:25:53 -08:00
Andrew Kelley
193c747b03 link.MappedFile: refactor std.Io -> Io 2026-01-22 21:25:53 -08:00
Andrew Kelley
1badb2a840 std.Io.Threaded: dirCreateFileWindows uses NtCreateFile directly 2026-01-22 18:08:13 -08:00
InKryption
305fd06756 Build: check if dynamic lib installed for symlinks
If the library isn't actually installed, `generated_bin` will be null,
causing this to panic about a missing dependency for itself; checking
for this state avoids this.
2026-01-22 22:28:28 +01:00
bartimaeusnek
37288e53ae std.zig.system.loongarch: implement individual cpu feature bit tests (#30915)
closes #30902

Co-authored-by: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com>
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30915
Reviewed-by: Alex Rønne Petersen <alex@alexrp.com>
Co-authored-by: bartimaeusnek <bartimaeusnek@noreply.codeberg.org>
Co-committed-by: bartimaeusnek <bartimaeusnek@noreply.codeberg.org>
2026-01-22 19:18:47 +01:00
Alex Rønne Petersen
c8edfbe1d5 Merge pull request 'enable x86_64-netbsd CI' (#30889) from alexrp/zig:netbsd-ci into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30889
2026-01-22 13:38:05 +01:00
Chadwain Holness
fd3657bf8c Io.Threaded: remove WSA_FLAG_OVERLAPPED from socket call 2026-01-22 03:39:00 +01:00
Andrew Kelley
4b2eae32f1 Merge pull request 'libc: use common implementation for sys/utsname.h' (#30904) from GasInfinity/zig:libc-uname into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30904
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-01-22 02:23:52 +01:00
Alex Rønne Petersen
200fb7c2ac
test-libc: disable raise-race.c 2026-01-21 18:51:02 +01:00
Alex Rønne Petersen
34aa1bb94f
test-libc: enable loongarch64-linux-muslsf 2026-01-21 17:53:38 +01:00
Alex Rønne Petersen
3245eddcb1
musl: fix typo in 171b104640 2026-01-21 17:53:11 +01:00
Alex Rønne Petersen
953ca759c2
ci: disable incremental tests
Too much flakiness across the board: https://codeberg.org/ziglang/zig/issues?q=&type=all&sort=relevance&labels=747060&state=open&milestone=0&project=0&assignee=0&poster=0
2026-01-21 17:21:05 +01:00
Alex Rønne Petersen
7337946875
ci: enable x86_64-netbsd in the workflow 2026-01-21 17:21:05 +01:00
Alex Rønne Petersen
85580951a7
ci: add x86_64-netbsd scripts 2026-01-21 17:21:03 +01:00
Alex Rønne Petersen
b7a4756e1d
langref: disable @cImport tests on NetBSD
https://github.com/Vexu/arocc/issues/960
2026-01-21 16:42:45 +01:00
Alex Rønne Petersen
eb3f16db5e
test: clarify that self_exe_symlink fails on NetBSD due to bad F_GETPATH
closes https://codeberg.org/ziglang/zig/issues/30841
2026-01-21 16:42:17 +01:00
Alex Rønne Petersen
9f33c339c7
std.fs.test: fix file operations on directories on NetBSD
As noted earlier in this test, reading directories does not fail on NetBSD.
2026-01-21 16:42:02 +01:00
Matthew Lugg
35a191ec1c
std.Io.Threaded: fix futex timeout race handling 2026-01-21 16:41:55 +01:00
Alex Rønne Petersen
a3ea3bd31d
std: NetBSD doesn't have a reliable F_GETPATH
It can fail arbitrarily with ENOENT if the kernel happens to not have the FD in
its name cache. That makes it useless for our purposes.

closes https://codeberg.org/ziglang/zig/issues/30843
2026-01-21 16:41:51 +01:00
Michael Dusan
32f977a4b7
std.fs.test: fix tests using Dir.realPath
* add fn isRealPathSupported
* incorporate into tests that depends on Dir.realPath
2026-01-21 16:41:37 +01:00
Alex Rønne Petersen
fc59f0e7f0
std.Io.test: skip atime check in setTimestamps on NetBSD 2026-01-21 16:41:30 +01:00
GasInfinity
1ab6bf59a6
feat(libzigc): add common linux errno syscall helper 2026-01-21 12:02:08 +01:00
Mathias Lafeldt
2207c62bb5 MachO: fix dynamic lookup of undefined symbols at runtime
Ensures `MH_NOUNDEFS` is not set when dynamic lookup is enabled for
undefined symbols via `linker_allow_shlib_undefined`.
2026-01-21 00:31:21 +01:00
Andrew Kelley
7cbe05cbd4 Merge pull request 'std.os.linux: add some missing syscalls' (#30899) from brickmonster/zig:syscalls into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30899
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-01-21 00:28:40 +01:00
GasInfinity
4f652fb4e3
feat(libzigc): use common implementations for sys/utsname.h
* and remove their musl/wasi implementation
2026-01-21 00:06:42 +01:00
GasInfinity
9d3e9054a7
feat(std.c): add wasi definition for utsname 2026-01-21 00:06:42 +01:00
GasInfinity
f67d21f736
chore(libc/musl): remove unused ffs impls
* forgot to remove them in the previous PR
2026-01-21 00:06:42 +01:00
brickmonster
8042096bca std.os.linux: add some missing syscalls 2026-01-20 18:30:45 +00:00
rpkak
e6ac1b77f0
libzigc: test and fix acos 2026-01-20 18:02:15 +01:00
brickmonster
62ce228b37 std.os.linux: fix some compilation errors 2026-01-20 16:09:49 +00:00
Andrew Kelley
c857fce05b langref: refine the underscore prefix section
more assertive yet less judgemental
2026-01-19 14:17:00 -08:00
Daggerfall-is-the-best-TES-game
21fc85f035 Add acos to ziglibc (#30888)
Since this is my first time contributing I wanted to keep it simple and I added just one function
I tested with
```bash
stage3/bin/zig build -p stage4 -Dno-lib -Dno-langref -Denable-llvm=true --search-prefix ~/repos/zig-boostrap/out/native-linux-musl-baseline/
stage4/bin/zig build test-libc -Dlibc-test-path=../libc-test -Dtest-target-filter=x86_64-linux-musl
```
and the tests passed.
I'm planning on doing more once I get the hang of it.

Co-authored-by: david <davidc.fried@gmail.com>
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30888
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: Daggerfall-is-the-best-TES-game <daggerfall-is-the-best-tes-game@noreply.codeberg.org>
Co-committed-by: Daggerfall-is-the-best-TES-game <daggerfall-is-the-best-tes-game@noreply.codeberg.org>
2026-01-19 22:43:57 +01:00
Michael Dusan
a8002a8564
build: avoid pkg-config when statically linking LLVM
Fixes stage4 build on NetBSD with pkg-config installed.
2026-01-19 13:16:33 +01:00
Alex Rønne Petersen
ac793232ee
test: skip non-libc module tests for targets that require or default to libc
We were just creating duplicate work and breaking -Dskip-libc.
2026-01-19 13:16:25 +01:00
Alex Rønne Petersen
b1b234daa0
test: disable self_exe_symlink standalone test on NetBSD
https://codeberg.org/ziglang/zig/issues/30841
2026-01-19 13:16:16 +01:00
Alex Rønne Petersen
016255ad09
test: disable an error trace test on optimized x86_64-netbsd 2026-01-19 13:16:11 +01:00
Alex Rønne Petersen
c71d32d14a
std.c.netbsd: change type of _ksiginfo.signo to std.c.SIG 2026-01-19 13:16:03 +01:00
Alex Rønne Petersen
fb66d7712c
std.c: fix W functions for NetBSD
I'm not sure where the old logic came from but it certainly didn't match NetBSD
10.1 system headers, and was causing the build system to see incorrect exit
status information for processes that were expected to crash (e.g. SIGABRT).
2026-01-19 13:15:57 +01:00
Alex Rønne Petersen
4e99f095ae
ci: avoid github.run_id in concurrency.group
https://codeberg.org/Codeberg/Community/issues/2318
2026-01-19 06:14:44 +01:00
jsentity
27e8d05ee8 Fix protocol.DevicePath.next() (#30883)
fix for https://codeberg.org/ziglang/zig/issues/30882

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30883
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: jsentity <jsentity@noreply.codeberg.org>
Co-committed-by: jsentity <jsentity@noreply.codeberg.org>
2026-01-18 21:42:34 +01:00
Andrew Kelley
d2dda0737b std.Io.Threaded: sendmmsg can return EACCES 2026-01-18 21:40:15 +01:00
Andrew Kelley
4cc3e1c05e Merge pull request 'libc: use common implementations for string.h and strings.h' (#30872) from GasInfinity/zig:libc-string(s) into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30872
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-01-18 21:39:45 +01:00
Alex Rønne Petersen
114ea92c09
ci: bump riscv64-linux-release timeout by 1 hour
This one was right on the edge and finally hit a timeout: https://codeberg.org/ziglang/zig/actions/runs/996/jobs/9/attempt/1
2026-01-18 15:33:47 +01:00
GasInfinity
d6b3dd25a0
chore(libzigc): document libc target checks 2026-01-18 00:26:42 +01:00
Andrew Kelley
e5dc5a6eb5 langref: refrain from underscore prefixes 2026-01-17 14:32:14 -08:00
Andrew Kelley
041701416b langref: all logic manages state 2026-01-17 13:57:14 -08:00
GasInfinity
f0649dd978
feat(libzigc): use common implementations for strings.h and string.h
* forwards all functions to their equivalent `std`
* removes their musl, wasi-libc and mingw implementations
2026-01-17 22:37:29 +01:00
GasInfinity
06d05decae
feat(libzigc): add wcstok and reuse more std.mem code
* also makes `wcpncpy`/`wcsncpy` pad the buffer with zeroes as required
  by the standard
2026-01-17 21:42:40 +01:00
GasInfinity
3d8b0e3324
feat(std.ascii): add boundedOrderIgnoreCaseZ 2026-01-17 21:42:38 +01:00
GasInfinity
26de7a3513
feat(std.mem): add boundedOrderZ 2026-01-17 21:42:32 +01:00
Alex Rønne Petersen
27685bcf20 std.c: fix O constants for FreeBSD
closes https://codeberg.org/ziglang/zig/issues/30861
2026-01-17 12:13:20 +01:00
Andrew Kelley
d417441f4f Merge pull request 'libc: use common implementations for wchar.h' (#30850) from GasInfinity/zig:libc-wchar into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30850
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-01-17 00:58:01 +01:00
murtaza
b5770541bd testing: ability to read environment variables from unit tests 2026-01-17 00:40:22 +01:00
Andrew Kelley
790d28d6cd std.testing: delete refAllDeclsRecursive
suggested alternatives:
- actual tests
- explicitly list the decls
- compile an example application that uses the API
- stop worrying about dead code
- refAllDecls (non recursive) in each file

Don't fight the laziness, embrace it.

closes #23608
closes #30813
2026-01-16 12:34:42 -08:00
Alex Rønne Petersen
081888286b
musl: patch riscv bits/fenv.h for soft float 2026-01-16 13:29:34 +01:00
Alex Rønne Petersen
171b104640
musl: patch loongarch bits/fenv.h for soft float
This change was missed in 1f7ee99b35.
2026-01-16 13:25:21 +01:00
Alex Rønne Petersen
65a4dbc503
ci: don't limit concurrency on push events 2026-01-16 11:57:56 +01:00
Alex Rønne Petersen
f2beea3b8f
std.os.linux.IoUring.test: disable accept_direct on RISC-V
https://codeberg.org/ziglang/zig/issues/30854
2026-01-16 11:40:19 +01:00
Alex Rønne Petersen
ceba095cb1
ci: re-enable riscv64-linux jobs on master pushes 2026-01-16 04:22:47 +01:00
Andrew Kelley
84261222b4 Merge pull request 'introduce std.Io.File.MemoryMap API' (#30840) from mmap into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30840
2026-01-16 03:59:31 +01:00
GasInfinity
e3309aaf4f
fix(libzigc): workaround LLVM bug
* looks like we get stuck inside this loop? 2078da43e2/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp (L245-L298)
2026-01-16 01:58:35 +01:00
Andrew Kelley
7b21fd7244 std.Io.Threaded: fix memory mapping on windows
- set protection flags properly
- handle when mapping fails after unmapping
2026-01-15 14:18:21 -08:00
Andrew Kelley
d2585e68a7 std.Io.Threaded: use NtExtendSection in fileMemoryMapSetLength
is this a good idea? not sure yet. reverting in the next commit
2026-01-15 14:18:21 -08:00
Andrew Kelley
de347dd6a9 std.Io.Threaded: add missing free in MemoryMap.setLength 2026-01-15 14:18:21 -08:00
Andrew Kelley
7ff6bcc111 std.Io.Threaded: track unaligned mapping length on Windows 2026-01-15 14:18:21 -08:00
Andrew Kelley
b2776d097d std.Io.Threaded: implement MemoryMap.setLength for Windows 2026-01-15 14:18:20 -08:00
Andrew Kelley
8527ec9c7b std.Io.Threaded: implement mmap fallback for Windows 2026-01-15 14:18:20 -08:00
Andrew Kelley
3c708b19fe disable test due to wasmtime bug
tracked by #20747
2026-01-15 14:18:20 -08:00
Andrew Kelley
2b01764d86 std: fix handling of EBADF error code
In the context of read/write it's ambiguous, means file was opened
without read/write respectively.
2026-01-15 14:18:20 -08:00
Andrew Kelley
cb37a5c1fb std.Io.Threaded: fix fileReadPositional error.IsDir for wasi 2026-01-15 14:18:20 -08:00
Andrew Kelley
08a33c0671 std: workaround for #30842 2026-01-15 14:18:20 -08:00
Andrew Kelley
470d0dd9c6 link: add some errors to the Dwarf.UpdateError mega error set 2026-01-15 14:18:20 -08:00
Andrew Kelley
c4df980ac2 std.fs: fix test cases regarding error.IsDir on WASI
why were we testing for shitty behavior?
2026-01-15 14:18:20 -08:00
Andrew Kelley
e70def70ec std.Io.Threaded: passing memory mapping tests on wasm32-wasi 2026-01-15 14:18:20 -08:00
Andrew Kelley
c917f619f0 std: fix compilation failures on various targets 2026-01-15 14:18:20 -08:00
Andrew Kelley
eb163361d9 std.Io.File.MemoryMap: add some alignment type safety 2026-01-15 14:18:20 -08:00
Andrew Kelley
4821898432 std.Io.File.MemoryMap API tuning
- remove file_size parameter from MemoryMap.write
- remove requirement for mapping length to be aligned
- align allocated fallback memory
- add unit test for std.Io.Threaded.disable_memory_mapping = true
- add unit test for MemoryMap.setLength
2026-01-15 14:18:20 -08:00
Andrew Kelley
bed7bc37c4 std.File.MemoryMap updates
- change offset to u64
- make len non-optional
- make write take a file_size parameter
- std.Io.Threaded: introduce disable_memory_mapping flag to force it to
  take the fallback path.

Additionally:

- introduce BlockSize to File.Stat. On Windows, based on cached call to
  NtQuerySystemInformation. On unsupported OS's, set to 1.
- support File.NLink on Windows. this was available the whole time, we
  just didn't see the field at first.
- remove EBADF / INVALID_HANDLE from reading/writing file error sets
2026-01-15 14:18:20 -08:00
Andrew Kelley
a70e006157 std: add unit test for memory mapping 2026-01-15 14:18:20 -08:00
Andrew Kelley
5a7dc4b0fa std.Io: introduce File.MemoryMap
by defining the pointer contents to only be synchronized after explicit
sync points, makes it legal to have a fallback implementation based on
file operations while still supporting a handful of use cases for memory
mapping.

furthermore, it makes it legal for evented I/O implementations to use
evented file I/O for the sync points rather than memory mapping.

not yet done:
- implement checking the length when options.len is null
- some windows impl work
- some wasi impl work
- unit tests
- integration with compiler
2026-01-15 14:18:20 -08:00
Vladislav Shabanov
63f345a75a link.MachO: support sdata4 pointer encoding (#30846)
Fixes https://codeberg.org/ziglang/zig/issues/30669

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30846
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: Vladislav Shabanov <vshabanov88@gmail.com>
Co-committed-by: Vladislav Shabanov <vshabanov88@gmail.com>
2026-01-15 19:48:16 +01:00
Vadym Prodan
eaa3a4299b link/MachO: enhance unwind info size calculation and add page size handling 2026-01-15 19:45:17 +01:00
GasInfinity
e22bf480aa
feat(libzigc): use common implementation for wchar.h
* but does not fully implement it (missing locale/unicode tables)
* also removes their musl/mingw implementation
2026-01-15 18:01:20 +01:00
Matthew Lugg
4f16e80cea std: halve the number of mutexes per mutex
On NetBSD and Illumos, we were using the `std.Thread.Futex`-based
implementation of `std.Thread.Mutex`. But since futex is not a primitive
on these targets, the implementation of `std.Thread.Futex` was based on
pthread primitives, including `pthread_mutex_t`. This had the amusing
consequence that locking a contended mutex on NetBSD would actually
perform 2 mutex locks, 2 mutex unlocks, and 1 condition wait; likewise,
unlocking a contended mutex would perform 2 mutex locks, 2 mutex
unlocks, and 1 condition signal. Having read some cutting-edge studies,
I have concluded that this is a slightly suboptimal approach. Instead,
let's just use pthread mutexes directly in this case; that's an
obviously better idea.

In the future, I think we can probably entirely remove our usages of
pthread sync primitives---no platform actually treats them as the base
primitives. Of the platforms which std has any meaningful support for
today, most support futexes, and the exceptions (NetBSD and Illumos)
support a thread parking API. We can implement futex and/or mutex on top
of thread parking and drop the pthread dependency entirely.
2026-01-15 05:28:11 +01:00
Matthew Lugg
c518593e97 std.Io.Threaded: spurious unparks are possible
Apparently the thread parking APIs on Windows and NetBSD aren't as good
as I thought---or, at least, the way they're *used* makes them not as
good. It's perfectly possible to use these APIs in a way where you don't
trigger spurious wakeups, but standard primitives (SRWLOCK on Windows,
pthread bits on NetBSD) are perfectly happy to leave pending unparks
sitting around, meaning in practice you have to assume spurious unparks
are possible. This brings me great sadness... but we soldier on!
2026-01-15 01:38:09 +01:00
Brandon Black
6b733537ab Io.Select: add fn concurrent 2026-01-14 18:25:49 -06:00
Brandon Black
376320a5e9 Io.Select: do not swallow error.Canceled of task 2026-01-14 18:25:00 -06:00
Brandon Black
46fcf22630 Io.Select: docs nits 2026-01-14 18:23:45 -06:00
GasInfinity
4df6119335 feat(libzigc): avoid division/multiplication in drand48 and erand48 2026-01-14 23:48:07 +01:00
Alex Rønne Petersen
0f35174807
compiler: remove -exported_symbols_list from zig build-exe --help
It's only supported by zig cc -Wl,...
2026-01-14 21:33:04 +01:00
Alex Rønne Petersen
3471ad1c67
ci: bump s390x-linux timeouts by 1 hour
Once in a while, these VMs get slightly slower due to heavy load from other VMs
on the host machine, causing the jobs to time out. This is a very rare
occurrence, but we do need to account for it.
2026-01-14 21:32:39 +01:00
Antti Harju
f695ca08e3 zig cc: Add support for -exported_symbols_list (#30628)
Resolves [unsupported linker arg: `-exported_symbols_list`](https://github.com/ziglang/zig/issues/24662)

This PR has been tested with https://github.com/anttiharju/compare-changes/pull/117 (via commits like 75b17b948e) where the `zig cc` ([via this wrapper](791129d401/.cargo/zcc/aarch64-apple-darwin.sh)) successfully builds a macOS binary (build would fail with zig 0.15.2):

Co-authored-by: Gunnar Wagenknecht <gunnar@wagenknecht.org>
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30628
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: Antti Harju <anttiharju@noreply.codeberg.org>
Co-committed-by: Antti Harju <anttiharju@noreply.codeberg.org>
2026-01-14 19:16:05 +01:00
Andrew Kelley
b99dc12ece Merge pull request 'libc: use common rand and *rand48 implementations' (#30826) from GasInfinity/zig:libc-rand into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30826
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-01-14 19:10:00 +01:00
GasInfinity
e10a325410
feat(libzigc): implement the drand48 family
* also remove their musl implementation
2026-01-14 13:14:33 +01:00
GasInfinity
d0c8fd2ce9
feat(std.Random): add a linear congruent generator 2026-01-14 12:48:09 +01:00
GasInfinity
ad3828db45
feat(libzigc): use common rand implementations
* also remove their musl implementation
2026-01-14 12:47:58 +01:00
Ryan Liptak
9d1a39c50f resinator: Sync with upstream
No functional differences, just some shuffling things around and the removal of the now-obsolete `utils.openFileNotDir`.
2026-01-14 01:04:24 +01:00
Alex Rønne Petersen
3da6e67199
std.Io.test: disable Group.concurrent on linux w/o libc
https://codeberg.org/ziglang/zig/issues/30096
2026-01-13 21:27:53 +01:00
Meghan Denny
7ea3842549 cli: add --test-execve option 2026-01-13 20:45:46 +01:00
Ryan Liptak
2301f2ecdf NtSetInformationFile: remove const from FileInformation buffer param
When targeting x86-windows, this parameter referring to read-only memory can result in an ACCESS_VIOLATION error, and this has been seen when using FILE_DISPOSITION_INFORMATION_EX. It's unclear how exactly this ACCESS_VIOLATION is occurring, though, as the memory does not actually change before/after the call.

Closes https://codeberg.org/ziglang/zig/issues/30802
2026-01-13 20:45:38 +01:00
Sertonix
47cc233f22 aro: define arch macros for riscv
Fixes some test failure:

test
+- test-standalone
   +- standalone_test_cases
      +- standalone_test_cases.glibc_compat
         +- CheckObject
            +- compile exe native-linux-gnu.2.38 Debug native-linux-gnu.2.38 64 errors
test/standalone/glibc_compat/glibc_runtime_check.zig:11:18: error: C import failed
const c_malloc = @cImport(
                 ^~~~~~~~
referenced by:
    checkReallocarray: test/standalone/glibc_compat/glibc_runtime_check.zig:46:27
    main: test/standalone/glibc_compat/glibc_runtime_check.zig:112:26
    4 reference(s) hidden; use '-freference-trace=6' to see all references
error: translation failure
build/stage3/lib/zig/libc/include/riscv-linux-gnu/bits/wordsize.h:22:3: error: unsupported ABI
2026-01-13 20:01:52 +01:00
Alex Rønne Petersen
9dd2716229
std.crypto.kangarootwelve: disable more flaky tests
https://codeberg.org/ziglang/zig/issues/30676
2026-01-13 09:19:08 +01:00
Matthew Lugg
85cac9e5b6 std: use sigaltstack for default segfault handler
This allows stack overflows to print stack traces. The size of the
sigaltstack (and whether it is actually set) can be configured by
setting `std.Options.signal_stack_size`.

The default value for the signal stack size was chosen experimentally by
doubling the value required to get stack traces on stack overflow with
the self-hosted x86_64 backend. While some targets may typically use
more stack space than x86_64-linux, the self-hosted x86_64 backend is
quite wasteful with stack at the moment, making it a fair benchmark.
Executables produced by the LLVM backend should have lower stack usage.
2026-01-13 07:24:49 +01:00
Frank Denis
be84d7cb9b Fix benchmarks after the randomness changes 2026-01-13 07:04:51 +01:00
Jay Petacat
d86e8b7795 std.mem.sliceTo: Return slice with sentinel from unbounded pointers
Commit dec1163fbb removed sentinels from the returned slice for C
pointers. Since C pointers have no bounds, we know that it'll keep
scanning until it finds `end` (or crash trying). The same is also true
of many-item pointers without a sentinel (e.g. `[*]T`), so I added
support for those too.
2026-01-13 06:19:14 +01:00
Justus Klausecker
044ba3e0b0 Sema: fix single-range switch prong capture (for real this time)
e2338edb47 didn't *quite* do it, the call sites of all switch prong related
functions now have to do their part too and be a little more precise about
what kind of prong they're currently analyzing.

Also removes some unused/unnecessary stuff.
2026-01-13 06:03:07 +01:00
Alex Rønne Petersen
4fcf6507f9 Merge pull request 'Fix wasi-libc miscompilations and make std.Io compile on Emscripten' (#30796) from castholm/zig:retrim-libc-fat into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30796
Reviewed-by: Alex Rønne Petersen <alex@alexrp.com>
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-01-13 06:00:24 +01:00
GasInfinity
65092d6e4c fix(libzigc): properly handle EOF in ctype
* EOF is defined as a negative integer, thus it doesn't fit in an `u8`!
2026-01-13 05:58:41 +01:00
GasInfinity
8e69ab8a31 fix(libzigc): negative bases are also invalid 2026-01-13 05:58:13 +01:00
Andrew Kelley
7e4c386f6a Merge pull request 'link/MachO: fix eh_frame handling on macOS' (#30768) from vprodan/zig:fix-macos-eh-frame into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30768
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-01-13 04:27:12 +01:00
Carl Åstholm
0a8e8e67d7 Misc. std.Io fixes for WASI and Emscripten
- Corrects WASI `UTIME_*` definitions now that the libc build has been
  fixed (see previous commit), and adds the corresponding definitions
  for Emscripten which were missing.
- Fixes `dirReadUnimplemented()`, which didn't compile.
- Prevents a dependency on `pthread_kill` from being pulled in in
  single-threaded Emscripten builds, where it isn't defined.

With these changes, Emscripten can now participate in juicy main.
2026-01-12 22:38:21 +01:00
Carl Åstholm
6376103b23 wasi-libc: De-deduplicate erroneously removed headers
05d8b565ad deduplicated wasi-libc headers
that are identical to upstream musl, but because some public headers
match the same `#include <>` patterns as private headers, this resulted
in unmodified upstream musl headers sometimes getting prioritized when
compiling wasi-libc, resulting in incorrect definitions. For example,
`UTIME_OMIT` is supposed to be -2 on WASI, but became 0x3ffffffe.

The restored headers were sourced from
<c89896107d>
which is the same revision as the most recent wasi-libc sync
07cc32b004.
2026-01-12 22:33:29 +01:00
Alex Rønne Petersen
f1267e02c4
std.http.test: disable tests on openbsd
https://codeberg.org/ziglang/zig/issues/30806
2026-01-12 18:44:32 +01:00
Alex Rønne Petersen
b671baee1a
ci: cut down the amount of stuff being run on riscv64-linux 2026-01-12 18:35:49 +01:00
Vadym Prodan
e835b864e8 link/MachO: fix eh_frame handling on macOS
Fixes several issues with eh_frame generation and unwind info on macOS:

* Fix FDE address calculation by including atom_offset
* Store and use pc_range (function size) from FDE for coverage checks
* Avoid creating null unwind records for addresses already covered by
  DWARF FDEs, allowing unwinder to properly fall back to DWARF info
* Remove incorrect addend adjustment in personality pointer calculation
2026-01-12 11:31:04 +01:00
Vadym Prodan
05b15e8bdb link/MachO: Add correct section flags (S_COALESCED, S_ATTR_NO_TOC,
S_ATTR_STRIP_STATIC_SYMS, S_ATTR_LIVE_SUPPORT) to __eh_frame section
  to match platform conventions
2026-01-12 11:31:04 +01:00
Bingwu Zhang
fc517bd01c Compilation: fix incorrect saved buf count
Change-Id: Ib2a2ffcb6224e571fed1151e687d8a8efe0bb95b
2026-01-12 11:21:54 +01:00
Andrew Kelley
545982c029 Merge pull request 'A few Windows fixes' (#30757) from squeek502/zig:windows-misc-fixes into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30757
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-01-12 00:59:10 +01:00
GasInfinity
514f6e589c feat(libzigc): use common integer ato* and strto* implementations
* also removes their musl implementation
2026-01-12 00:55:11 +01:00
Justus Klausecker
e2338edb47 Sema: fix single-range switch prong capture
This kind of capture cannot always be comptime-known, assuming so caused
access of undefined memory during payload capture analysis!
2026-01-11 20:22:32 +01:00
mlugg
76dd39d531 Merge pull request 'frontend: rewrite switch logic' (#30776) from justusk/zig:have-you-tried-switching-it-off-and-on-again into master
Resolves: https://codeberg.org/ziglang/zig/issues/30660
Resolves: https://codeberg.org/ziglang/zig/issues/30606
Resolves: https://codeberg.org/ziglang/zig/issues/30157
Resolves: https://codeberg.org/ziglang/zig/issues/30154
Resolves: https://codeberg.org/ziglang/zig/issues/30153
Resolves: https://github.com/ziglang/zig/issues/25644
Resolves: https://github.com/ziglang/zig/issues/25632
Resolves: https://github.com/ziglang/zig/issues/24789
Resolves: https://github.com/ziglang/zig/issues/24152
Resolves: https://github.com/ziglang/zig/issues/24128
Resolves: https://github.com/ziglang/zig/issues/24126
Resolves: https://github.com/ziglang/zig/issues/23973
Resolves: https://github.com/ziglang/zig/issues/23156
Resolves: https://github.com/ziglang/zig/issues/23123
Resolves: https://github.com/ziglang/zig/issues/22138
Resolves: https://github.com/ziglang/zig/issues/21772
Resolves: https://github.com/ziglang/zig/issues/18087
Resolves: https://github.com/ziglang/zig/issues/15237

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30776
Reviewed-by: Matthew Lugg <mlugg@mlugg.co.uk>
2026-01-11 19:44:24 +01:00
Matthew Lugg
01546e68cd
compiler: handle switch rewrite review feedback 2026-01-11 14:37:28 +00:00
Matthew Lugg
3a4a7d2ca3
Sema: minor cleanup (the second) 2026-01-11 14:37:27 +00:00
Matthew Lugg
9a225456cb
Sema: minor cleanup 2026-01-11 14:37:27 +00:00
Matthew Lugg
ed1268d0e6
Zir: simplify '_' prong of 'switch' statements 2026-01-11 14:37:27 +00:00
Matthew Lugg
8ec4c5cb13
Sema: evaluate switch items at comptime 2026-01-11 14:34:19 +00:00
Justus Klausecker
078e100573
wasm: fix getting pointer type instead of error union type for is_err_ptr 2026-01-11 11:37:18 +00:00
Justus Klausecker
dbfeade221
Sema: better switch_block_err_union result location if operand has wrong type
also fixes related test case and makes it run everywhere, not just on x86_64-linux!
2026-01-11 11:37:18 +00:00
Justus Klausecker
2e99c3042e
test: add some more switch regression tests
switch evaluation order, switch lazy value resolution
2026-01-11 11:37:18 +00:00
Justus Klausecker
2479966df2
Sema: fix integration with Io.Threaded 2026-01-11 11:37:18 +00:00
Justus Klausecker
5a376d97d4
langref: document new switch features
- switch on tagged union with runtime-captured tag
- switch on errors special cases
2026-01-11 11:37:17 +00:00
Justus Klausecker
0b3b536f18
test: re-enable packed struct field type behavior test
With new code courtesy of mlugg
2026-01-11 11:37:17 +00:00
Justus Klausecker
bce7e7a52b
AstGen: Re-allow labeled break from loop else block targeting its label
This fixes a regression from a couple of commits ago; breaking from the
`else` block of a loop to the loop's tag should be allowed when explicitly
targeting the label by name.
2026-01-11 11:37:17 +00:00
Justus Klausecker
39ca03e515
test: disable packed struct field type behavior test
This test was previously masked by a bug which prevented its evaluation.
Skipping it for now.
2026-01-11 11:37:17 +00:00
Justus Klausecker
b79bd31356
Sema: rework switch_block[_ref/_err_union] logic
This commit aims to simplify and de-duplicate the logic required for
semantically analyzing `switch` expressions.

The core logic has been moved to `analyzeSwitchBlock`, `resolveSwitchBlock`
and `finishSwitchBlock` and has been rewritten around the new iterator-based
API exposed by `Zir.UnwrappedSwitchBlock`.

All validation logic and switch prong item resolution have been moved to
`validateSwitchBlock`, which produces a `ValidatedSwitchBlock` containing
all the necessary information for further analysis.

`Zir.UnwrappedSwitchBlock`, `ValidatedSwitchBlock` and `SwitchOperand`
replace `SwitchProngAnalysis` while adding more flexibility, mainly for
better integration with `switch_block_err_union`.

`analyzeSwitchBlock` has an explicit code path for OPV types which lowers
them to either a `block`-`br` or a `loop`-`repeat` construct instead of a
switch. Backends expect `switch` to actually have an operand that exists
at runtime, so this is a bug fix and avoids further special cases in the
rest of the switch logic.
`resolveSwitchBlock` and `finishSwitchBr` exclusively deal with operands
which can have more than one value, at comptime and at runtime respectively.

This commit also reworks `RangeSet` to be an unmanaged container and adds
`Air.SwitchBr.BranchHints` to offload some complexity from Sema to there
and save a few bytes of memory in the process.

Additionally, some new features have been implemented:
- decl literals and everything else requiring a result type (`@enumFromInt`!)
  may now be used as switch prong items
- union tag captures are now allowed for all prongs, not just `inline` ones
- switch prongs may contain errors which are not in the error set being
  switched on, if these prongs contain `=> comptime unreachable`

and some bugs have been fixed:
- lots of issues with switching on OPV types are now fixed
- the rules around unreachable `else` prongs when switching on errors now
  apply to *any* switch on an error, not just to `switch_block_err_union`,
  and are applied properly based on the AST
- switching on `void` no longer requires an `else` prong unconditionally
- lazy values are properly resolved before any comparisons with prong items
- evaluation order between all kinds of switch statements is now the same,
  with or without label
2026-01-11 11:37:17 +00:00
Justus Klausecker
d94137d23f
src/Type: make doc comments prettier :) 2026-01-11 11:37:17 +00:00
Justus Klausecker
6e35138901
all: prefer else => |e| return e, over else => return err,
When switching on an error, using the captured value instead of the original
one is always preferable since its error set has been narrowed to only
contain errors which haven't already been handled by other switch prongs.

The subsequent commits will disallow this form as an unreachable `else` prong.
2026-01-11 11:37:17 +00:00
Justus Klausecker
9e949f95c1
Sema: enhance comptime is_non_err resolution
This makes `is_non_err` and `unwrap_errunion_err[_ptr]` friendlier towards
being emitted into comptime blocks. Also, `analyzeIsNonErr` now actually
attempts to do something at comptime.
2026-01-11 11:37:17 +00:00
Justus Klausecker
5b00e24b6e
frontend: rework switch ZIR
Moved to a more linear layout which lends itself well to exposing an iterator.
Consumers of this iterator now just have to keep track of an index into a
homogenous sequence of bodies.

The new ZIR layout also enables giving switch prong items result locations
by storing the bodies of all items inside of the switch encoding itself.
There are some deliberate exceptions to this: enum literals and error values
are directly encoded as strings and number literals are resolved to comptime
values outside of the switch block. These special encodings exist to save
space and can easily be resolved during semantic analysis.

This commit also re-implements `AstGen` and `print_zir` for switch based on
the new layout and adds some additional information to the ZIR text repr.
Notably `switchExprErrUnion` has been merged into `switchExpr` to reduce
code duplication.

The rules around allowing an unreachable `else` prong in error switches are
also refined by this commit, and enforced properly based on the actual AST.
The special cases are listed exhaustively below:

`else => unreachable,`
`else => return,`
`else => |e| return e,` (where `e` is any identifier)

Additionally `{...} => comptime unreachable,` prongs are marked to support
future features (refer to next couple of commits).

Also fixes 'value with comptime-only type depends on runtime control flow'
error for labeled error switch statements by surrounding the entire expr
with a common block to break to (see previous commits for details).
2026-01-11 11:37:16 +00:00
Justus Klausecker
00d4f3c001
Liveness: improve logging 2026-01-11 11:37:16 +00:00
Justus Klausecker
42dea36ce9
llvm: fix jump table gen for labeled switch with single else prong
Avoids a null unwrap if there are no cases with explicit values present
while trying to construct a jump table for a labeled switch statement.
2026-01-11 11:37:16 +00:00
Justus Klausecker
d840bb5118
AstGen: improve ergonomics of Scope
Adds `Scope.Unwrapped`, a simple union of pointers to already-casted scopes
with `Scope.Tag` as its tag enum. This pairs very nicely with labeled switch
and gets rid of almost every `scope.cast(...).?`, improving developer QOL :)
2026-01-11 11:37:16 +00:00
Justus Klausecker
e0108dec54
AstGen: allow labels to provide separate break and continue targets
Enhances `GenZir` to allow labels to provide separate `break` and `continue`
target blocks and adds some more information on continue targets to
communicate whether the target is a switch block or cannot be targeted by
`continue` at all.

The main motivation is enabling this:
```
const result: u32 = operand catch |err| label: switch (err) {
    else => continue :label error.MyError,
    error.MyError => break :label 1,
};
```
to be lowered to something like this:
```
%1 = block({
  %2 = is_non_err(%operand)
  %3 = condbr(%2, {
    %4 = err_union_payload_unsafe(%operand)
    %5 = break(%1, result) // targets enclosing `block`
  }, {
    %6 = err_union_code(%operand)
    %7 = switch_block(%6,
      else => {
        %8 = switch_continue(%7, "error.MyError") // targets `switch_block`
      },
      "error.MyError" => {
        %9 = break(%1, @one) // targets enclosing `block`
      },
    )
    %10 = break(%1, @void_value)
  })
})
```
which makes the non-error case and all breaks from switch prongs, but not
continues from switch prongs, peers.

This is required to avoid the problems described in gh#11957 for labeled
switches without having to introduce a fairly complex special case to the
`switch_block_err_union` logic. Since this construct is very rare in practice,
introducing this additional complexity just to save a few ZIR bytes is
likely not worth it, so the simplified lowering described above will be
used instead.

As a nice bonus, AstGen can now also detect a `continue` trying to target
a labeled block and emit an appropriate error message.
2026-01-11 11:37:16 +00:00
David Rubin
aa2b178029
disallow switch case capture discards
Previously Zig allowed you to write something like,
```zig
switch (x) {
    .y => |_| {
```

This seems a bit strange because in other cases, such as when
capturing the tag in a switch case,
```zig
switch (x) {
    .y => |_, _| {
```
this produces an error.

The only usecase I can think of for the previous behaviour is
if you wanted to assert that all union payloads are able
to coerce,
```zig
const X = union(enum) { y: u8, z: f32 };

switch (x) {
    .y, .z => |_| {
```

This will compile-error with the `|_|` and pass without it.

I don't believe this usecase is strong enough to keep the current
behaviour; it was never used in the Zig codebase and I cannot
find a single usage of this behaviour in the real world, searching
through Sourcegraph.
2026-01-11 11:37:16 +00:00
Ryan Liptak
4cf7dc22fa Expand the errors that act as "sym links can't be created" on Windows
Previously, the errors that are now mapped to AccessDenied, PermissionDenied, and FileSystem were all mapped to AccessDenied.
2026-01-11 02:08:18 -08:00
Ryan Liptak
b4831403c9 fileRead functions: handle INVALID_FUNCTION on Windows and map it to error.IsDir
INVALID_FUNCTION may be possible in other scenarios as well, but it is verifiably returned when the handle refers to a directory.
2026-01-11 02:08:18 -08:00
Ryan Liptak
d08098861f Fix RENAME_INFORMATION.toBuffer returning sizes below the minimum recognized size
Passing a length below 24 to NtSetInformationFile results in INFO_LENGTH_MISMATCH, so always return at least 24 for the buffer length.
2026-01-11 02:07:49 -08:00
Alex Rønne Petersen
c434599134 Merge pull request 'std.process: add PermissionDenied to ProtectMemoryError (for OpenBSD)' (#30781) from alexrp/zig:openbsd-mprotect-immutable into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30781
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-01-11 09:43:01 +01:00
Alex Rønne Petersen
4e806f2521
build: bump test-libc max_rss to 2_496_066_355 2026-01-11 05:55:46 +01:00
Alex Rønne Petersen
e8a6e58f9d
std.process: fix some page size assumptions in lockMemory/protectMemory tests
Makes the tests work on hexagon and loongarch.
2026-01-11 03:07:45 +01:00
Alex Rønne Petersen
c002b96f17
Revert "ci: bump loongarch64-linux timeouts by 1 hour"
This reverts commit 867501d9d2.

It seems that the increased run time was a result of the regressed
test-incremental step and that we are now back to normal.
2026-01-11 00:51:37 +01:00
Alex Rønne Petersen
fe0b2ab9df
ci: temporarily remove riscv64-linux while I investigate its performance issues 2026-01-11 00:13:28 +01:00
Jay Petacat
484cc15366 Sema: Allow small integer types to coerce to floats
If the float can store all possible values of the integer without
rounding, coercion is allowed. The integer's precision must be less than
or equal to the float's significand precision.

Closes #18614
2026-01-10 22:19:20 +01:00
Andrew Kelley
5082e85de9 Merge pull request 'libc: use compiler_rt/libzigc for some math functions and add some libc-tests' (#30767) from rpkak/zig:libc-compiler_rt-math into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30767
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-01-10 22:15:32 +01:00
nash1111
9a7f14354e crypto: correct checkHostName docs about wildcard matching 2026-01-10 22:11:52 +01:00
Jakub Konka
f3db3a087e std: ignore -fmacro-prefix-map flag when parsing NIX_CFLAGS_COMPILE
Since we ignore this flag in `clang_options_data.zig`, it makes
sense to ignore it for Nix as well. One thing I've been thinking about
is if it would make sense to somehow use `clang_options_data.zig` as
source of truth for handling Nix cflags too rather than slap more
hard-coded escape hatches.
2026-01-10 22:04:00 +01:00
Alex Rønne Petersen
9acfd167fa
std.process: add PermissionDenied to ProtectMemoryError (for OpenBSD)
See EPERM notes on https://man.openbsd.org/mprotect.2.
2026-01-10 21:04:20 +01:00
InKryption
707823abdb
fix semantic UAFs in std.Io.Threaded 2026-01-10 17:43:33 +01:00
Andrew Kelley
ec25b13848 Merge pull request 'std: move memory locking and memory protection to process' (#30758) from mmap into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30758
2026-01-10 04:14:48 +01:00
rpkak
08d37d6e14
compiler_rt: fix sqrtf implementation; libc: remove sqrt implementations 2026-01-10 00:09:54 +01:00
rpkak
813ae89208
libc -> libzigc: copysign 2026-01-10 00:09:54 +01:00
rpkak
aa7dac9739
libc: remove fmin/fmax implementations 2026-01-10 00:09:54 +01:00
rpkak
a2861a6c8d
libc: remove fmod implementations 2026-01-10 00:09:54 +01:00
rpkak
9dd32d5e65
libc: remove some more log implementations 2026-01-10 00:09:54 +01:00
rpkak
b94a65ed40
test-libc: run some math tests 2026-01-10 00:09:54 +01:00
Andrew Kelley
4d6d2922b8 std: move memory locking and memory protection to process
and introduce type safety for posix.PROT (mmap, mprotect)

progress towards #6600
2026-01-09 13:52:00 -08:00
Andrew Kelley
9aaecde63f build: bump freebsd max_rss
error: memory usage peaked at 0.75GB (751378432 bytes), exceeding the
declared upper bound of 0.74GB (743802470 bytes)
2026-01-09 13:52:00 -08:00
Andrew Kelley
5e242f0551 Merge pull request 'libc: use common ctype.h implementation' (#30763) from GasInfinity/zig:libc-ascii-ctype into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30763
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-01-09 22:38:06 +01:00
Andrew Kelley
721bdb6256 Merge pull request 'crypto.scrypt: accept an std.Io parameter instead of direct entropy' (#30738) from jedisct1/zig:scryptfixes into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30738
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-01-09 09:39:35 +01:00
Andrew Kelley
7c0b42ba0c Merge pull request 'crypto.ed25519.Signer: get an std.io parameter rather than entropy' (#30736) from jedisct1/zig:edsigned into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30736
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-01-09 09:38:44 +01:00
Linus Groh
27039a014c std.c: Make clock_nanosleep available on serenity
Follow-up to https://codeberg.org/ziglang/zig/pulls/30746.

The TIMER_ABSTIME value was adjusted to match other systems in
https://github.com/SerenityOS/serenity/pull/26543.
2026-01-09 09:37:49 +01:00
Kevin Primm
b929078dac std.Io.Threaded: Raise specific error when DNS lookup returns no A/AAAA records
closes #25948
2026-01-08 20:44:47 -08:00
Jon Parise
efe649b13e std.Io.net: make HostName.validate RFC 1123-compliant
The implementation of HostName.validate was too generous. It considered
strings like ".example.com", "exa..mple.com", and "-example.com" to be
valid hostnames, which is incorrect according to RFC 1123 (the currently
accepted standard).

Reviewed-on: https://github.com/ziglang/zig/pull/25710
2026-01-08 20:40:32 -08:00
Matthew Lugg
6069161a51 link.Wasm: reserve sufficient capacity for @tagName function code
Resolves: https://codeberg.org/ziglang/zig/issues/30748
2026-01-09 03:49:24 +01:00
Matthew Lugg
aebd84b525 build runner: refactor step evaluation logic
The previous logic was made really messy by the fact that upon entry to
the step eval worker, the step may not be ready to run, we may be racing
with other workers doing the same check, and we had already acquired our
RSS requirement even though we might not run. It also required iterating
all dependencies each time we were called to check whether we were even
ready to run yet.

A much better strategy is for each step to have an atomic counter
representing how many of its dependencies are yet to complete. When a
step completes (successfully or otherwise), it decrements this value for
all of its dependants, and if it drops any to 0, it schedules that step
to run. This means each step is scheduled exactly once, and only when
all of its dependencies have finished, reducing redundant checks and
hence contention. If the step being scheduled needs to claim RSS which
isn't available, then it is instead added to `memory_blocked_steps`,
which is iterated by the step worker after a step with an RSS claim
finishes.

This logic is more concise than before, simpler to understand, generally
more efficient, and fixes a bug in the RSS tracking. Also, as a nice
side effect, it should also play a little bit nicer with `Io.Threaded`'s
scheduling strategy, because we no longer spawn extremely short-lived
tasks all the time as we previously did.

Resolves: https://codeberg.org/ziglang/zig/issues/30742
2026-01-09 03:16:39 +01:00
GasInfinity
6abb1dcd35
feat(libzigc): add common ctype implementation
* implements all functions in the standard `ctype.h` header
* also removes their musl implementations
2026-01-09 02:51:29 +01:00
Luna Schwalbe
04e73d03bd android: detect native ABI and API level correctly
ABI detection previously did not take into account the non-standard
directory structure of Android. This has been fixed.

The API level is detected by running `getprop ro.build.version.sdk`,
since we don't want to depend on bionic, and reading system properties
ourselves is not trivially possible.
2026-01-09 02:47:13 +01:00
Khitiara
e8af0f2cc0 Fix format on uefi guid type, was hitting unreachable 2026-01-09 02:42:22 +01:00
GasInfinity
e558e64ca0
feat(std.ascii): add isGraphical and isPunctuation 2026-01-09 02:27:31 +01:00
GasInfinity
7f6eab2704 feat(libzigc): add nan, nanf, nanl and bsearch
* also remove musl implementation
2026-01-09 00:26:20 +01:00
Andrew Kelley
ecea8cc16d std.Io.Threaded: refactor some error handling 2026-01-08 13:35:47 -08:00
Andrew Kelley
09028bac29 std.Io.Threaded: fix init for single-threaded 2026-01-08 12:36:41 -08:00
Andrew Kelley
20baf049aa std.Io: add doc comments 2026-01-08 12:36:07 -08:00
Andrew Kelley
70af303a2b std.Io: move some decls around
This file has changed a lot since the previous release, and I resisted
the urge to do this until the conflicts would be minimized.
2026-01-08 12:35:57 -08:00
Andrew Kelley
b0570b807f Merge pull request 'std.Io.Threaded: clock_nanosleep is not linux-only' (#30746) from clock_nanosleep into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30746
2026-01-08 21:00:36 +01:00
Andrew Kelley
1face9ad78 std.c.SIG: make it non-exhaustive
54a84964f8 did this for std.os.linux.SIG
but I neglected to also do it for std.c.SIG
2026-01-08 20:52:42 +01:00
Alex Rønne Petersen
d1be8b138e Merge pull request 'enable x86_64-openbsd CI' (#30733) from alexrp/zig:openbsd-ci into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30733
2026-01-08 12:35:11 +01:00
Ian Johnson
ac91799332 std.meta.hasUniqueRepresentation: consider enum tag type
Closes #30731
2026-01-08 09:24:12 +01:00
Andrew Kelley
6f7968f165 Merge branch "remove many std.posix functions"
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30741
2026-01-08 00:19:12 -08:00
Alex Rønne Petersen
cc38acfea3
ci: skip incremental tests on loongarch64-linux
https://codeberg.org/ziglang/zig/issues/30748
2026-01-08 07:01:57 +01:00
Andrew Kelley
130fc7ef75 std.c: use {} rather than void for absent functions 2026-01-07 21:13:16 -08:00
Andrew Kelley
4319c8924e std.Io.Threaded: clock_nanosleep is not linux-only
clock_nanosleep is specified by POSIX but not implemented on these
hereby shamed operating systems:
* macOS
* OpenBSD (which defines TIMER_ABSTIME for some reason...?)
2026-01-07 21:13:16 -08:00
moriazoso
514b103edb std.Io.Threaded: correctly initialize PosixAddress/WsaAddress from sockaddr (#30722)
Resolves ziglang/zig#30672 - UB caused by `std.Io.Threaded.netLookupFallible` incorrectly initializing `PosixAddress`/`WsaAddress` from `*sockaddr`.

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30722
Co-authored-by: moriazoso <greysonmurray.dev@gmail.com>
Co-committed-by: moriazoso <greysonmurray.dev@gmail.com>
2026-01-08 06:01:44 +01:00
Andrew Kelley
6a5bb3ede3 std: find a better home for the "preopens" concept 2026-01-08 05:06:31 +01:00
pentuppup
d2d8b969a1 fix redundant safety checks being emitted for slicing 2026-01-08 05:05:39 +01:00
Bingwu Zhang
cdaf279314 link.Elf2: fix incorrect expected node length
Change-Id: Iba9c4bf2cfa4ff1b82dd5f0828c57711f238f1bf
2026-01-08 04:54:49 +01:00
Bingwu Zhang
8d06d8dca2 link.Elf: allow multiple relocs at the same location
RISC-V and LoongArch ELF psABIs define a kind of
RELAX relocations which are expected to have a normal
relocation at the same address.

Change-Id: I5737bfcfd3e5041fb6ab7d193c9fc57eeca1eec8
2026-01-08 04:53:16 +01:00
Andrew Kelley
ce89006035 std.Io.Kqueue: fix bitrot 2026-01-07 18:00:36 -08:00
Andrew Kelley
c0092f5394 std.Io: expose Kqueue and IoUring directly 2026-01-07 17:33:07 -08:00
Andrew Kelley
cbd75b484f std.posix: remove recvfrom, recvmsg
see #6600
2026-01-07 17:33:07 -08:00
Andrew Kelley
d96d735338 posix: remove send, sendto, sendmsg
see #6600
2026-01-07 17:33:07 -08:00
Andrew Kelley
791baefff2 goodbye posix.nanosleep
see #6600
2026-01-07 17:33:07 -08:00
Andrew Kelley
45b931a23f goodbye posix.fork
see #6600

nobody should be using fork anyway, especially Redis
2026-01-07 17:33:07 -08:00
Andrew Kelley
3961fe3de9 std: move posix.kevent to Io.Kqueue 2026-01-07 17:33:07 -08:00
Andrew Kelley
2c6304efc7 std: move posix.kqueue to Io.Kqueue.createFileDescriptor 2026-01-07 17:33:07 -08:00
Andrew Kelley
be0a4dc299 goodbye posix.fstatat
see #6600
2026-01-07 17:33:07 -08:00
Andrew Kelley
829afe98d1 std.posix: remove getsockopt, getsockoptError
see #6600
2026-01-07 17:33:07 -08:00
Andrew Kelley
02c260dd06 goodbye posix.getsockname
see #6600
2026-01-07 17:33:07 -08:00
Andrew Kelley
1b43f27a91 std.posix: delete epoll APIs
see #6600
2026-01-07 17:33:07 -08:00
Andrew Kelley
55ad03e261 goodbye posix.accept
see #6600
2026-01-07 17:33:06 -08:00
Andrew Kelley
c89df809b9 goodbye posix.listen
see #6600
2026-01-07 17:33:06 -08:00
Andrew Kelley
4a49546f59 goodbye posix.bind
see #6600
2026-01-07 17:33:06 -08:00
Andrew Kelley
ed4dfdcff0 goodbye posix.shutdown
see #6600
2026-01-07 17:33:06 -08:00
Andrew Kelley
d10a730480 goodbye posix.socket
see #6600
2026-01-07 17:33:06 -08:00
Andrew Kelley
ceae9600e3 std.posix: remove setuid, seteuid, setgid, setegid, getuid, etc
applications and libraries should reach for the lower level APIs instead
2026-01-07 17:33:06 -08:00
Andrew Kelley
213ef95346 goodbye posix.open
see #6600
2026-01-07 17:33:06 -08:00
Andrew Kelley
2f372b3dc0 goodbye posix.write
see #6600
2026-01-07 17:33:06 -08:00
Andrew Kelley
520397b48f tests: delete redundant cases
These were originally supposed to be incremental test cases but have
long since been made redundant.
2026-01-07 17:33:06 -08:00
Andrew Kelley
7248b4a4e4 std.fs: deprecate base64 APIs
100% of std.fs is now deprecated.
2026-01-07 17:33:06 -08:00
Andrew Kelley
c44e12dcd3 std: find a better home for the "preopens" concept 2026-01-07 17:33:06 -08:00
David Rubin
938efe4aab compiler-rt: fix f80 ceil/floor optimization
Our implementation did the classic add-sub rounding trick `(y = x +/- C =+ C - x)`
with `C = 1 / eps(T) = 2^(mantissa - 1)`. This approach only works for values whose
magnitude is below the rounding capacity of the constant. For a 64-bit mantissa
(like f80 has), `C = 2^63` only rounds for `|x| < 2^63`. Before we allowed this to
be ran on `e < bias + 64` aka `|x| < 2^64`. And because it isn't large enough,
we lose a bit to rounding.

For reference, the musl implementation does the same thing, using `mantissa - 1`:
https://git.musl-libc.org/cgit/musl/tree/src/math/ceill.c#n18
where `LDBL_MANT_DIG` is 64 for `long double` on x86.

This commit also combines the floor and ceil implementations into one generic one.
2026-01-08 00:45:52 +01:00
Steven Casper
52e0f78706 byteSwapAllFieldsAligned: use std.mem.Alignment API (#30724)
Following up on #30571

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30724
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: Steven Casper <sebastiancasper3@gmail.com>
Co-committed-by: Steven Casper <sebastiancasper3@gmail.com>
2026-01-08 00:44:08 +01:00
Frank Denis
cd8f0aa4ca Add signerWithBaseNonce 2026-01-07 23:02:46 +01:00
Frank Denis
22380c78b1 crypto.ed25519.Signer: get an std.io parameter rather than entropy
This is consistent with what all other similar functions now do,
and is less dangerous.
2026-01-07 23:02:24 +01:00
Frank Denis
3ee092536e Allow the salt to be passed as a parameter in bcrypt 2026-01-07 22:44:37 +01:00
Frank Denis
4a29a6e432 Add scrypt.createWithSalt 2026-01-07 23:14:37 +01:00
Frank Denis
2153759a22 crypto.scrypt: accept an std.Io parameter instead of direct entropy
Safer, and consistent with what is being done in other similar
functions.
2026-01-07 23:01:38 +01:00
GasInfinity
335c0fcba1 feat(libzigc): add div, ldiv, lldiv and imaxdiv
* also remove musl implementation
2026-01-07 21:53:40 +01:00
Andrew Kelley
62d6bbc7dc Merge pull request 'std.Io: implement entropy (randomness)' (#30709) from random into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30709
2026-01-07 20:04:26 +01:00
Andrew Kelley
006afece53 std.crypto.tls.Client.Options: expose entropy_len 2026-01-07 11:03:37 -08:00
Andrew Kelley
5d0929c40d std.Io.Threaded.randomSecure: eliminate dead code 2026-01-07 11:03:37 -08:00
Andrew Kelley
5e5b328dac test-standalone: update cases from posix.getrandom 2026-01-07 11:03:37 -08:00
Andrew Kelley
1ddae8585a std.Io.Threaded: add procfs fallback for fileHardLink
oof what a clunky set of functionality we have here
2026-01-07 11:03:37 -08:00
Andrew Kelley
7e8c7e5696 std.Io: fix AT_SYMLINK_FOLLOW flags
hard linking has the backwards default, which uses a different flag
2026-01-07 11:03:37 -08:00
Andrew Kelley
ee574f665c std.Io.Dir: introduce renamePreserve and use it in File.Atomic.link
breaking change: the error for renaming over a non-empty directory now
returns error.DirNotEmpty rather than error.PathAlreadyExists.
2026-01-07 11:03:37 -08:00
Andrew Kelley
8e1850e277 std.Io.Threaded: tweak logic for use_dev_urandom 2026-01-07 11:03:37 -08:00
Andrew Kelley
61cb5e4af9 compiler: fix unit tests 2026-01-07 11:03:37 -08:00
Andrew Kelley
0529fe3411 std.Io.Threaded: fix implementation of getRandomFd 2026-01-07 11:03:37 -08:00
Andrew Kelley
1eddc1737c std: add test coverage for Io.File.Atomic.link 2026-01-07 11:03:37 -08:00
Andrew Kelley
a136890acc std.Io.random: clarify doc comments 2026-01-07 11:03:37 -08:00
Andrew Kelley
e23bec700c build: delete some wrong max_rss values
these aren't even checking the correct target, it's checking based on
the host so when cross compiling the numbers don't even make sense.
2026-01-07 11:03:37 -08:00
Andrew Kelley
90f0d7d0da std.Io.Threaded: implement random seed fallback for WASI 2026-01-07 11:03:37 -08:00
Andrew Kelley
7bd033275e std.Io.Threaded: implement Windows random seed fallback 2026-01-07 11:03:37 -08:00
Andrew Kelley
1f1381a866 update API usage of std.crypto.random to io.random 2026-01-07 11:03:36 -08:00
Andrew Kelley
81a35a86ea std.Io: introduce random and randomSecure
and use a thread-local CSPRNG for the former.
2026-01-07 11:03:36 -08:00
Andrew Kelley
e3e9c7c33c std.Build.Step.Compile: take advantage of std lib atomic files 2026-01-07 11:03:36 -08:00
Andrew Kelley
2f639a45b4 std.Io.Threaded: implement windows random with \Device\CNG 2026-01-07 11:03:36 -08:00
Andrew Kelley
42ca9e5d8e std.Build: remove no longer needed workaround
now that definitions of networking addresses are arch-independent
2026-01-07 11:03:36 -08:00
Andrew Kelley
3bc22dbd94 std.Build.Step.Options: exploit Io.File.Atomic 2026-01-07 11:03:36 -08:00
Andrew Kelley
816565dd07 std: move entropy to Io 2026-01-07 11:03:36 -08:00
Alex Rønne Petersen
867501d9d2
ci: bump loongarch64-linux timeouts by 1 hour
https://codeberg.org/ziglang/zig/actions/runs/611/jobs/5/attempt/1
2026-01-07 16:04:46 +01:00
Matthew Lugg
cd963ba38d Io.Threaded: fix bad assertion
Resolves: https://codeberg.org/ziglang/zig/issues/30717
2026-01-07 11:27:21 +01:00
Alex Rønne Petersen
046386295f
ci: enable x86_64-openbsd in the workflow 2026-01-07 05:42:50 +01:00
Alex Rønne Petersen
7c239b048a
ci: add x86_64-openbsd scripts 2026-01-07 05:42:50 +01:00
Alex Rønne Petersen
4f8cfcbbfd
test: disable libfuzzer standalone test on OpenBSD
https://codeberg.org/ziglang/zig/issues/30728
2026-01-07 05:42:50 +01:00
Alex Rønne Petersen
4296ed9c42
test: skip self_exe_symlink on OpenBSD
realPath is unsupported.
2026-01-07 05:42:49 +01:00
Alex Rønne Petersen
bb46709762
test: disable an error trace test on optimized x86_64-openbsd 2026-01-07 05:42:49 +01:00
Alex Rønne Petersen
9db475de70
std.fs.test: skip executablePath and openExecutable on OpenBSD
processExecutablePath() is unsupported.
2026-01-07 05:06:12 +01:00
Alex Rønne Petersen
28b83e3b02
compiler: recognize and ignore -rpath-link linker option
The option should probably still be implemented properly at some point, but LLD
has ignored this for years and nobody seems to mind, so just do the same for
now.

This unblocks using zig cc with CMake on OpenBSD, among other use cases.

ref https://github.com/ziglang/zig/issues/18713
2026-01-07 02:25:10 +01:00
mlugg
1bef876636 Merge pull request 'std.Thread: mask all signals before unmapping stack' (#30713) from detached-thread-exit-signal-race into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30713
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-01-07 01:11:25 +01:00
GasInfinity
fa625e878f feat(libzigc): add qsort
* also remove musl implementation
2026-01-07 00:06:57 +01:00
Alex Rønne Petersen
6412aebc90
compiler: fix build 2026-01-06 23:58:30 +01:00
ptrstr
764764465b std.os.emscripten: make emscripten_run_script_string return optional
Signed-off-by: ptrstr <ptrstr@protonmail.com>
2026-01-06 23:49:29 +01:00
Andrew Kelley
5e002910df Merge pull request '@extern: add support for SPIR-V locations and descriptors' (#30570) from ashpil/zig:extern-bindings-locations into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30570
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-01-06 23:44:10 +01:00
pentuppup
c475f1fcd5 Ast: disallow bit alignment on many-item and C pointers 2026-01-06 23:40:01 +01:00
David Rubin
8b71ec6db7 crypto: correctly disallow non-digits in time
Previously these functions made the assumption that
when performing a  on the input digits,
there could be no collisions between the less
significant digits being larger than '9', and the
upper digits being small enough to get past the
 checks.

Now we perform a correct check across all of the
digits to ensure they're in between '0'-'9', at
a minimal cost, since all digits are checked in
parallel.
2026-01-06 23:37:43 +01:00
Kristoffer
9c55776d25 std.crypto: mem.trimLeft -> mem.trimStart 2026-01-06 23:28:01 +01:00
Alex Rønne Petersen
b5df5391aa Merge pull request 'enable powerpc64le-linux CI' (#30704) from alexrp/zig:powerpc64le into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30704
2026-01-06 21:16:47 +01:00
Alex Rønne Petersen
43a8e9ee80
ci: enable powerpc64le-linux 2026-01-06 21:15:38 +01:00
Alex Rønne Petersen
63eb395729
ci: build test stage3 on powerpc64le-linux with long calls
Necessary to work around this:

    error: ld.lld: /home/ci/.cache/act/f23fdcb74e58cd75/hostexecutor/zig-global-cache/o/c67e3042d116da0f73d3129d377044bf/libc++abi.a(/home/ci/.cache/act/f23fdcb74e58cd75/hostexecutor/zig-global-cache/o/61dd7765ab891b4db54a5e49b8ab8c86/cxa_thread_atexit.o):(function __cxa_thread_atexit: .text.__cxa_thread_atexit+0x40): relocation R_PPC64_REL24_NOTOC out of range: -251925824 is not in [-33554432, 33554431]; references '__cxa_thread_atexit_impl'
        note: referenced by cxa_thread_atexit.cpp:116 (/home/ci/.cache/act/f23fdcb74e58cd75/hostexecutor/lib/libcxxabi/src/cxa_thread_atexit.cpp:116)
        note: defined in /home/ci/.cache/act/f23fdcb74e58cd75/hostexecutor/zig-global-cache/o/c67e3042d116da0f73d3129d377044bf/libc++abi.a(/home/ci/.cache/act/f23fdcb74e58cd75/hostexecutor/zig-global-cache/o/61dd7765ab891b4db54a5e49b8ab8c86/cxa_thread_atexit.o)

This is only a problem for now because we link libLLVM; once we start invoking
llc instead, we won't need this workaround anymore.
2026-01-06 21:15:38 +01:00
Alex Rønne Petersen
64f5ef8880
ci: add powerpc64le-linux scripts 2026-01-06 21:15:38 +01:00
Alex Rønne Petersen
6a1fecea67
build: bump max_rss for test-behavior on powerpc64le-linux to 627_431_833 2026-01-06 21:15:35 +01:00
Alex Rønne Petersen
7daf0b6f46
build: use -ffunction-sections -fdata-sections for the Zig compiler on PowerPC
It has been observed in practice on powerpc64(le)-linux that zig.o (in various
stages and build modes) is large enough that the +/- 32MB branch range of
PowerPC is insufficient to reach from one end of the code section to the other.
With LLVM 21, this leads to silent miscompiles that then crash at runtime. With
LLVM 22, it will at least lead to branch range errors that fail the compilation,
but that gets us no closer to a working compiler.

By using these options, we give the linker much greater flexibility to move code
and data around to satisfy these range constraints; without them, the linker is
not allowed to split up the huge code and data sections of zig.o to do so.

Similar issues have also been observed on powerpc-linux (32-bit), hexagon-linux,
and some variations of mips(64)(el)-linux. But let's be conservative for now;
those other targets can be added to the condition later.

As a data point to support this change, it's worth noting that LLD started
enabling these options for LTO precisely because the resulting large compilation
units ran into these range issues. In some abstract sense, Zig can be seen as
doing a limited form of "LTO" in the frontend, so it's not surprising that we
would hit the same issues.
2026-01-06 21:15:02 +01:00
Alex Rønne Petersen
a996a75e06
compiler: make all Zig-provided libraries use -ffunction-sections -fdata-sections
We already did this for some of them; this just makes us consistent. Doing this
gives the linker more flexibility to rearrange code/data, but more importantly,
allows --gc-sections to get rid of all the unused code, which is a real concern
for these libraries in particular.
2026-01-06 21:15:02 +01:00
Alex Rønne Petersen
312b231da9
ci: bump riscv64-linux timeouts by a further 2 hours
See 962903e0fa.
2026-01-06 21:00:03 +01:00
Alex Rønne Petersen
219624111b
build: bump max_rss for zig exe to 7_900_000_000
Needed for riscv64-linux. Overkill for everything else, but: e19c686c22.
2026-01-06 20:55:23 +01:00
Alex Rønne Petersen
018da9662d
build: bump max_rss for test-std on riscv64-linux to 4_052_670_054 2026-01-06 20:54:21 +01:00
Alex Rønne Petersen
378b4d3d3a
build: bump max_rss for test-behavior on riscv64-linux to 827_043_430 2026-01-06 20:54:06 +01:00
Alex Rønne Petersen
e226df2ed5 Merge pull request 'add OpenBSD libc cross-compilation support' (#30064) from alexrp/zig:openbsd into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30064
Reviewed-by: Andrew Kelley <andrewrk@noreply.codeberg.org>
2026-01-06 16:12:54 +01:00
Matthew Lugg
be0a77efd2
std: re-enable some disabled tests
I believe these tests may have been flaky as a result of the bug fixed
in the previous commit. A big hint is that they were all crashing with
SIGSEGV with no stack trace. I suspect that some lingering SIGIOs from
cancelations were being delivered to a thread after its `munmap` call,
which was happening because the test runner called `Io.Threaded.deinit`
to cause all of the (detached) worker threads to exit.

If this passes, I'll re-run the x86_64-linux CI jobs on this commit a
few times before merge to try and be sure there are no lingering
failures.

Resolves: https://codeberg.org/ziglang/zig/issues/30096
Resolves: https://codeberg.org/ziglang/zig/issues/30592
Resolves: https://codeberg.org/ziglang/zig/issues/30682
2026-01-06 11:15:47 +00:00
Matthew Lugg
073ef0f393
std.Thread: mask all signals before unmapping stack
As the comment explains, if a signal were to arrive between a detached
thread's `munmap` and `exit` calls, the signal handler would immediately
trigger SIGSEGV due to the stack being unmapped. To solve this, we need
to block all signals before entering this logic. The musl implementation
which this logic was ported from does this exact thing; that logic was
just lost when porting.

Notably, this would lead to a crash with no stack trace, because the
SIGSEGV handler would itself crash due to the missing stack.
2026-01-06 11:15:33 +00:00
Matthew Lugg
1111655131
std: block cancelation in default panic and segfault handlers
It doesn't make any sense for a task to be canceled while it's
panicking.

As a happy accident, this also solves some cases where safety panics in
`Io.Threaded` would cause stack traces not to print due to invalid
thread-local state: when cancelation is blocked, `Io.Threaded` doesn't
consult said thread-local state at all. For instance, try inserting a
panic just after a call to `Syscall.start()` in `Io.Threaded`, and then
call the `Io` function in question from a `concurrent` task. Before this
PR, the stack trace fails to print, because the panic handler sees the
thread-local cancelation state in an unexpected state, leading to a
recursive panic. After this PR, the stack trace prints fine.
2026-01-06 10:50:45 +00:00
Alex Rønne Petersen
9d08eba2e1
std.crypto.argon2: skip flaky argon2d test
https://codeberg.org/ziglang/zig/issues/30074
2026-01-06 10:02:09 +01:00
Alex Rønne Petersen
b0da914ae6
std.crypto.argon2: disable flaky phc format hasher test
https://codeberg.org/ziglang/zig/issues/30682
2026-01-06 10:01:16 +01:00
Alex Rønne Petersen
d757d5e6b2 Merge pull request 'some CI script improvements' (#30177) from alexrp/zig:ci-stuff into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30177
2026-01-06 09:56:15 +01:00
Alex Rønne Petersen
435b8411b5 ci: update to qemu 10.2.0 2026-01-06 09:55:09 +01:00
Andrew Kelley
c906f7d2e7 Merge pull request 'std: rework atomic file / temp file API' (#30686) from std.Io.File.Atomic into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30686
2026-01-06 05:32:16 +01:00
Andrew Kelley
06130c5e61 std.Io.Threaded: set O_DIRECTORY along with O_TMPFILE 2026-01-05 20:31:31 -08:00
Andrew Kelley
f9a5b34e67 std.Io.Threaded: fix compilation on s390x, hexagon, or1k, m68k
Apparently the O_TMPFILE flag is split across two bits on these
architectures and missing on m68k.
2026-01-05 20:28:58 -08:00
Andrew Kelley
3859250c4d std.Io.Threaded: only linux supports fileHardLink 2026-01-05 20:28:58 -08:00
Andrew Kelley
39605bd6bc compiler: update to new createFileAtomic API 2026-01-05 20:28:58 -08:00
Andrew Kelley
4365b0df88 std.Io.Threaded: add File.hardLink 2026-01-05 20:28:58 -08:00
Andrew Kelley
81bfd28974 std.Io.Dir: rework atomic file 2026-01-05 20:28:58 -08:00
Michael Dusan
6ab1159e81 netbsd: use correct symbol for lwp_park 2026-01-06 05:27:54 +01:00
Andrew Kelley
d3d6761e43 std: depend on NtDll rather than advapi32.dll for entropy 2026-01-05 12:16:54 -08:00
Ryan Liptak
52141fe85f standalone tests: Delete all ad hoc TmpDir instances, use the build system instead 2026-01-05 20:41:18 +01:00
Alex Rønne Petersen
b318ee6cda
ci: pass -Dskip-openbsd on x86_64-freebsd and x86_64-linux-debug(-llvm) 2026-01-05 16:50:46 +01:00
Alex Rønne Petersen
00dc4d000f
test: add openbsd targets to module test matrix 2026-01-05 16:50:46 +01:00
Alex Rønne Petersen
25e348973a
std.zig.target: add openbsd libc support 2026-01-05 16:50:46 +01:00
Alex Rønne Petersen
a78f891d05
compiler: support building openbsd crt0 and stub shared libraries
closes #2878
2026-01-05 16:50:46 +01:00
Alex Rønne Petersen
00e6895bde
compiler: don't error on explicit link_libc=false on requiresLibC() targets
There are various reasons why one might want to still create libc-less
compilations on these targets. Case in point: Compiling our bundled crt0 for
OpenBSD.

We will still default to linking libc on these targets, though.
2026-01-05 16:50:46 +01:00
Alex Rønne Petersen
d0ad76c03c
update_openbsd_libc: add tool for updating openbsd libc startup code 2026-01-05 16:50:44 +01:00
Alex Rønne Petersen
50422d5c37 Merge pull request 'libc: remove most symbols already present in compiler_rt' (#30648) from mercenary/zig:2879-rt into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30648
Reviewed-by: Andrew Kelley <andrewrk@noreply.codeberg.org>
Reviewed-by: Alex Rønne Petersen <alex@alexrp.com>
2026-01-05 15:49:55 +01:00
Alex Rønne Petersen
6f2e7afc30
ci: build stage4 and run behavior tests with it on aarch64-macos-debug
We do this in most other debug jobs, so seems sensible to do here too.
2026-01-05 15:41:16 +01:00
Alex Rønne Petersen
faa485e630
ci: build stage4 and run behavior tests with it on x86_64-linux-debug(-llvm)
This was removed in 125a9aa82b. But now that our
x86_64-linux machines have had their resources properly allocated, resulting in
runs taking 1-3 hours rather than 4-8, we can add this back.
2026-01-05 15:41:16 +01:00
Alex Rønne Petersen
4d3a847cd1
libc: add openbsd libc startup code for 7.8 2026-01-05 14:52:48 +01:00
Alex Rønne Petersen
9f16886536
compiler: define ___OpenBSD and OpenBSDX_Y when targeting openbsd libc 2026-01-05 14:52:48 +01:00
Alex Rønne Petersen
2c42b85529
std.zig.target: handle openbsd libc names 2026-01-05 14:52:48 +01:00
Alex Rønne Petersen
395145d3b0
std.zig.LibCDirs: add openbsd support 2026-01-05 14:52:48 +01:00
Alex Rønne Petersen
504de5c887
std.Target: bump baseline openbsd version from 7.7 to 7.8
Since this is the first version we support cross-compiling for.
2026-01-05 14:52:48 +01:00
Alex Rønne Petersen
39bb452d96
std.Target: factor arch/abi into openbsd minimum version logic 2026-01-05 14:52:48 +01:00
Alex Rønne Petersen
32b250109f
std.Target: add isOpenBSDLibC() 2026-01-05 14:52:48 +01:00
Alex Rønne Petersen
de13923d69
libc: add openbsd 7.8 abilists 2026-01-05 14:52:48 +01:00
Alex Rønne Petersen
66d97267c7
libc: add openbsd 7.8 headers
This excludes all headers in /usr/include/dev because that directory is bonkers
huge (18M). We can add these on an as-needed basis.
2026-01-05 14:52:48 +01:00
Alex Rønne Petersen
834ac8122b
process_headers: add openbsd support 2026-01-05 14:52:48 +01:00
Alex Rønne Petersen
962903e0fa
ci: bump riscv64-linux timeouts by 2 hours
Fixing this perf regression is tracked by: https://codeberg.org/ziglang/zig/issues/30595
2026-01-05 12:54:27 +01:00
Alex Rønne Petersen
ccc78252f1
std.Io.test: disable flaky recancel test on linux w/o libc
https://codeberg.org/ziglang/zig/issues/30592
2026-01-05 12:52:25 +01:00
Alex Rønne Petersen
bbacf42837
std.Io.test: disable flaky Group.concurrent test on linux w/o libc
https://codeberg.org/ziglang/zig/issues/30096
2026-01-05 12:52:18 +01:00
Michael Dusan
31a6e83a7c openbsd: fix Io.Threaded bitrot 2026-01-05 11:28:57 +01:00
Gregory Mullen
29b9e24df7 add tls.ExtensionType.quic_transport_parameters = 57 2026-01-05 11:26:17 +01:00
Jacob Young
ac64c75876 Dwarf: implement pointers to more comptime values
Closes #30600
Closes #30602
2026-01-05 11:24:48 +01:00
Andrew Kelley
8669898819 disable flaky test: aarch64-macos stage3/4 nondeterminism check
tracked by #30687
2026-01-04 23:43:19 -08:00
Andrew Kelley
435cd6f129 Merge pull request 'std.Build: adjust temp files API' (#30683) from std.Build-temp into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30683
2026-01-05 06:02:25 +01:00
Jake Greenfield
8e091047b5 std.Io.Threaded: fix Windows env var mapping
Windows environment variables are case-insensitive, so the special Wtf16
comparison needs to be used, or PATH/PATHEXT might be missed.
2026-01-04 23:32:36 -05:00
Andrew Kelley
c8ecfad41a build runner: clean up tmp dirs 2026-01-04 17:46:44 -08:00
Andrew Kelley
b4dbe483a7 std.Build: adjust temp files API
Remove the RemoveDir step with no replacement. This step had no valid
purpose. Mutating source files? That should be done with
UpdateSourceFiles step. Deleting temporary directories? That required
creating the tmp directories in the configure phase which is broken.
Deleting cached artifacts? That's going to cause problems.

Similarly, remove the `Build.makeTempPath` function. This was used to
create a temporary path in the configure place which, again, is the
wrong place to do it.

Instead, the WriteFile step has been updated with more functionality:

tmp mode: In this mode, the directory will be placed inside "tmp" rather
than "o", and caching will be skipped. During the `make` phase, the step
will always do all the file system operations, and on successful build
completion, the dir will be deleted along with all other tmp
directories. The directory is therefore eligible to be used for
mutations by other steps. `Build.addTempFiles` is introduced to
initialize a WriteFile step with this mode.

mutate mode: The operations will not be performed against a freshly
created directory, but instead act against a temporary directory.
`Build.addMutateFiles` is introduced to initialize a WriteFile step with
this mode.

`Build.tmpPath` is introduced, which is a shortcut for
`Build.addTempFiles` followed by `WriteFile.getDirectory`.

* give Cache a gpa rather than arena because that's what it asks for
2026-01-04 17:23:45 -08:00
rpkak
8109766927
compiler_rt: fix exp, exp2, log, log10 and log2
the log update is a port of the current version from musl
2026-01-04 19:23:43 +01:00
Andrew Kelley
e3b7cad81e std.heap.DebugAllocator: disable already flaky test
tracked by #22731

counterpart to ef1ddbe2f0
2026-01-04 07:29:35 -08:00
Andrew Kelley
de25a6ffee Merge pull request 'std: delete os.environ, os.argv, add new parameter to main, move process API to std.Io' (#30644) from juice into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30644
2026-01-04 09:28:33 +01:00
Andrew Kelley
ef1ddbe2f0 std.heap.DebugAllocator: disable already flaky test
tracked by #22731
2026-01-04 00:27:09 -08:00
Andrew Kelley
420a9aed4c build: bump freebsd max_rss
solves error: memory usage peaked at 1.10GB (1102852096 bytes),
exceeding the declared upper bound of 1.06GB (1060217241 bytes)
2026-01-04 00:27:09 -08:00
Andrew Kelley
9eb3b54eb5 std.Io.Threaded: revert making reading fork child status cancelable
this caused the build runner to crash sometimes, not sure why yet
2026-01-04 00:27:09 -08:00
Andrew Kelley
854c076ff7 std.Io.Threaded: improve posix spawning
* avoid unreachable when the OS does something unexpected
* make waiting for the fork/exec error report cancelable
2026-01-04 00:27:09 -08:00
Andrew Kelley
fa315b1060 std.Io.Threaded: improve posix process creation
* cache /dev/null after opening
* make opening /dev/null cancelable
* avoid unreachable even when OS does something unexpected
2026-01-04 00:27:09 -08:00
Andrew Kelley
2c22c3dabf std.Io.Threaded: make processReplace cancelable
In between each attempt to call execve() on a particular file path, it
will check cancelation before trying the next PATH.
2026-01-04 00:27:09 -08:00
Andrew Kelley
08d8b412e9 std.Io.Threaded: more robust windows process creation error handling 2026-01-04 00:27:09 -08:00
Andrew Kelley
f072313e1e std.Io.Threaded: delete dead comment
The problem it talked about is solved now that the direct call to
dirOpenDirWindows makes sense in this context.
2026-01-04 00:27:09 -08:00
Andrew Kelley
0317e95aad std.posix: delete some mkdir functions
These are handled by Io.Dir now. This is part of an effort to eliminate
error.OperationCanceled from the std lib. Also an effort to delete
all std.posix functions.
2026-01-04 00:27:09 -08:00
Andrew Kelley
2b326d27d5 std.Io.Threaded: improve various Windows logic
* cache nul handle for child process execution
* make opening the nul file integrate properly with cancelation
* replace all calls to SleepEx to parking_sleep.sleep instead, making
  them properly cancelable. These sleeps are workarounds for Windows
  kernel bugs. Now you can even cancel while waiting for kernel bug
  workarounds!
2026-01-04 00:27:09 -08:00
Andrew Kelley
be977e1934 std.Io.Threaded: integrate with new cancel mechanism 2026-01-04 00:27:09 -08:00
Andrew Kelley
ff67f70cf9 start: tweak default allocator choices
On wasm targets, when libc is linked, we have to go through libc.
2026-01-04 00:27:09 -08:00
Andrew Kelley
5b9e6a2b2d compiler: fix wasi compilation 2026-01-04 00:27:09 -08:00
Andrew Kelley
e19c686c22 build: bump max_rss for zig
this was exceeded on CI. this value is not meant to be so precisely
tweaked per OS and arch
2026-01-04 00:27:09 -08:00
Andrew Kelley
e23d980e11 std.process.Environ: skip BE createMapWide test coverage
it would be good to fix this but master branch doesn't have coverage
either. one thing at a time.
2026-01-04 00:27:09 -08:00
Andrew Kelley
e2c04a4651 fix some windows compilation errors 2026-01-04 00:27:09 -08:00
Andrew Kelley
2fee64ceb0 update init template for new main API 2026-01-04 00:27:09 -08:00
Andrew Kelley
0b856d12a0 build: remove freebsd max_rss special casing
error: memory usage peaked at 6.05GB (6047436800 bytes), exceeding the
declared upper bound of 6.04GB (6044158771 bytes)

This value isn't meant to be OS-specific anyway.
2026-01-04 00:27:09 -08:00
Andrew Kelley
88dd682155 Compilation: revert bad code transformation
I added `unreachable` in this branch based on a misunderstanding of the
original control flow.
2026-01-04 00:27:09 -08:00
Andrew Kelley
dd7be75f7c std.process: add missing error.OperationUnsupported 2026-01-04 00:27:09 -08:00
Andrew Kelley
e55fa3d525 fix two standalone tests on windows 2026-01-04 00:27:09 -08:00
Andrew Kelley
baa49e5929 std.Io.Threaded: implement processReplace 2026-01-04 00:27:09 -08:00
Andrew Kelley
08cc9e8d59 std.Io.Threaded: std.process -> process 2026-01-04 00:27:09 -08:00
Andrew Kelley
84da158afb test-stack-traces: update to new main API 2026-01-04 00:27:09 -08:00
Andrew Kelley
b32a38ad27 build: fix file system watching compilation on macOS 2026-01-04 00:27:09 -08:00
Andrew Kelley
1070c2a71a rename env_map to environ_map
For naming consistency with `std.process.Environ.Map`.
2026-01-04 00:27:09 -08:00
Andrew Kelley
f25de4c7a2 fix native path lookup on macOS 2026-01-04 00:27:08 -08:00
Andrew Kelley
17c7a339d8 incr-check: update to new APIs 2026-01-04 00:27:08 -08:00
Andrew Kelley
c6b75b61b7 std: fix child processes on riscv32-linux 2026-01-04 00:27:08 -08:00
Andrew Kelley
d97e4ca0d1 documentation should be descriptive not prescriptive 2026-01-04 00:27:08 -08:00
Andrew Kelley
77087f6f31 langref: update to new main API 2026-01-04 00:27:08 -08:00
Andrew Kelley
4afed3e9ef test-standalone: update the rest of the cases to new API 2026-01-04 00:27:08 -08:00
Andrew Kelley
e149c0e2aa std.Build.Step.Run: fix wrong environment passed 2026-01-04 00:27:08 -08:00
Andrew Kelley
af164b3f3c std.Build.Step.Run: no need to sort the environment
since we now use ArrayHashMap, the order is deterministic, and in fact,
observable by applications.
2026-01-04 00:27:08 -08:00
Andrew Kelley
ca5c5ade5f std.Options: work around not lazy enough compiler 2026-01-04 00:27:08 -08:00
Andrew Kelley
bf74827ddb test-standalone: update more cases to new main API 2026-01-04 00:27:08 -08:00
Andrew Kelley
1b56686012 test-standalone: update cases to new main API 2026-01-04 00:27:08 -08:00
Andrew Kelley
f2cf7b538f std.Io.Threaded: fix the child process error fd mechanism 2026-01-04 00:27:08 -08:00
Andrew Kelley
0ca83dd9d2 start: fix compilation with -lc on windows 2026-01-04 00:27:08 -08:00
Andrew Kelley
85fe35d246 compiler: fix -Denable-llvm compilation failures 2026-01-04 00:27:08 -08:00
Andrew Kelley
f28802a9c6 zig libc: fix subcommand
This branch regressed the child process "run" mechanism because it
didn't pass the correct stdin, stdout, stderr values to process.spawn

Fixed now.
2026-01-04 00:27:08 -08:00
Andrew Kelley
960c512efd compiler: update std lib API usage 2026-01-04 00:27:08 -08:00
Andrew Kelley
a6f519c20f std.process.Args: make toSlice require arena allocation
this simplifies the implementation, allows specializing it, and allows
deleting the corresponding free function. In practice this is how it is
always used anyway.
2026-01-04 00:27:08 -08:00
Andrew Kelley
1ccc87363a std: fixes for WASI 2026-01-04 00:27:08 -08:00
Andrew Kelley
50e185b718 start: tweak allocator choice
Favor DebugAllocator in Debug mode, even when linking libc. Prevent use
of smp_allocator when single_threaded
2026-01-04 00:27:08 -08:00
Andrew Kelley
0362d9f321 start: make leaks into warnings
I think it will be less confusing if memory leak checking doesn't change
the return code of the process.
2026-01-04 00:27:08 -08:00
Andrew Kelley
60447ea97c std: fix windows compilation errors 2026-01-04 00:27:08 -08:00
Andrew Kelley
08447ca47e std.fs.path: make relative a pure function
Instead of querying the operating system for current working directory
and environment variables, this function now accepts those things as
inputs.
2026-01-04 00:27:08 -08:00
Andrew Kelley
b64491f2d6 compiler_rt: ensure no std.Io used when not testing 2026-01-04 00:27:08 -08:00
Andrew Kelley
f9585ad01f update tests and tools to new main API 2026-01-04 00:27:08 -08:00
Andrew Kelley
9009ab2495 std.Io.Threaded: make environ init non-optional
and argv0 on systems that need it too.

fixes surprising behavior for applications that forget to initialize the
environment field.
2026-01-04 00:27:08 -08:00
Andrew Kelley
de8c4cd64e compiler: update to new std.process APIs 2026-01-04 00:27:08 -08:00
Andrew Kelley
f612464331 compiler: delete DarwinPosixSpawn
if this is reintroduced it will need to be part of the std.Io
implementation
2026-01-04 00:27:08 -08:00
Andrew Kelley
69d07472a1 std lib tests passing on linux 2026-01-04 00:27:08 -08:00
Andrew Kelley
3e6d6150d9 std.process.Environ: fix compile errors on POSIX 2026-01-04 00:27:08 -08:00
Andrew Kelley
384bfc5f99 std.Progress: go through Io interface for parent IPC mechanism
and fix start code
2026-01-04 00:27:08 -08:00
Andrew Kelley
42988fc5f4 std.process.Environ.Block: enhance type safety 2026-01-04 00:27:08 -08:00
Andrew Kelley
b85524d0c8 std.process.Environ: fix contains function 2026-01-04 00:27:08 -08:00
Andrew Kelley
32af0f6154 std: move child process APIs to std.Io
this gets the build runner compiling again on linux

this work is incomplete; it only moves code around so that environment
variables can be wrangled properly. a future commit will need to audit
the cancelation and error handling of this moved logic.
2026-01-04 00:27:08 -08:00
Andrew Kelley
d6a1e73142 std: start wrangling environment variables and process args
this commit is unfinished. It marks a spot where I wanted to start
moving child process stuff below the std.Io.VTable
2026-01-04 00:27:07 -08:00
Rue04
86a9a9048e std.MultiArrayList: add *Bounded variants and initCapacity
Because I accidentially squished two commit and can't figure out how to separate them
again, this also
- standardizes some doc-comments
- makes a slight change to `std.ArrayList`'s `initCapacity`'s doc-comment
2026-01-04 03:05:34 +01:00
Matthew Lugg
0cbaaa5eb9 std.Thread: stop clobbering syscall args
TL;DR: "r" considered harmful.

If LLVM chose registers badly, the inline asm which cleans up a thread
on Linux could, on all architectures other than x86_64, clobber either
`munmap` argument with the other argument *or* with the syscall number.
This would cause munmap to return EINVAL, and we would literally *never*
free the thread memory, which isn't ideal.

As it turns out, this was happening on MIPS, and was the cause of the
failures we've recently been seeing for that target: QEMU genuinely was
running out of memory (or at least, the virtualized address space was
getting too fragmented to map many contiguous pages). I've therefore
re-enabled a test which was disabled due to that flakiness.

This bug was accidentally fixed for x86_64 back in 2022 (see 59e33b447),
which probably helped it to go unnoticed for as long as it did!

Resolves: https://codeberg.org/ziglang/zig/issues/30216
2026-01-04 01:35:27 +01:00
Andrew Kelley
a0a982f0ea std.crypto.kangarootwelve: disable flaky test
tracked by #30676
2026-01-03 16:27:09 -08:00
mlugg
8226d706e2 Merge pull request 'std.Io.Threaded: performance enhancements, bugfixes, and better Windows and NetBSD support' (#30634) from std.Io.Threaded-groups-2 into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30634
Reviewed-by: Andrew Kelley <andrewrk@noreply.codeberg.org>
Resolves: https://codeberg.org/ziglang/zig/issues/30049
2026-01-03 21:33:46 +01:00
Matthew Lugg
4de33579d8
incr-check: make sure to always show the target
Change the log implementation to prepend the current target and update
to all logs which happen during an update.

Makes progress on https://github.com/ziglang/zig/issues/22510, but does
not fully resolve it.
2026-01-03 15:45:11 +00:00
Matthew Lugg
b3c498454b
codegen.wasm: fix 64-bit saturating shl
Previously, 64-bit '<<|' operations were emitting 64-bit shifts with one
64-bit operand and one 32-bit operand, which is illegal. Instead, as in
the lowering for regular shifts, we need to cast the RHS in this case.
2026-01-03 15:45:11 +00:00
Matthew Lugg
f7f0b9d28f
std.http.test: fix memory leaks on OOM 2026-01-03 15:45:11 +00:00
Matthew Lugg
3bb2f7b84e
std.Io.net: don't swallow 'error.Canceled'
This was missed when updating to the new group cancelation API, and
caused illegal behavior in many cases (the condition was simply that a
DNS query returned a second result before a connection was successfully
established).
2026-01-03 15:45:11 +00:00
Matthew Lugg
f306a9f84a
std: rebase fixups and cancelation changes
This commit includes some API changes which I agreed with Andrew as a
follow-up to the recent `Io.Group` changes:

* `Io.Group.await` *does* propagate cancelation to group tasks; it then
  waits for them to complete, and *also* returns `error.Canceled`. The
  assertion that group tasks handle `error.Canceled` "correctly" means
  this behavior is loosely analagous to how awaiting a future works. The
  important thing is that the semantics of `Group.await` and
  `Future.await` are similar, and `error.Canceled` will always be
  visible to the caller (assuming correct API usage).

* `Io.Group.awaitUncancelable` is removed.

* `Future.await` calls `recancel` only if the "child" task (the future
  being awaited) did not acknowledge cancelation. If it did, then it is
  assumed that the future will propagate `error.Canceled` through
  `await` as needed.
2026-01-03 15:45:11 +00:00
Matthew Lugg
b8a09bcbd9
std.Io.Group: tweak documentation and vtable API 2026-01-03 15:45:11 +00:00
Matthew Lugg
2c395e326f
std.Io.Threaded: always use robust cancelation
As of this branch, the performance impact of robust cancelation is now
negligible (and in fact entirely unmeasurable in almost all cases), so
there is no good reason to not enable it in all cases. The performance
issues before were primarily down to a typo in the robust cancelation
logic which resulted in every canceled syscall potentially being sent
hundreds of signals in quick succession, because the delay between
signals started out at 1ns instead of 1us!
2026-01-03 15:45:10 +00:00
Matthew Lugg
f27134d671
std.Io: more tests 2026-01-03 15:45:10 +00:00
Matthew Lugg
e57c557ad4
std.Io.Threaded: hugely improve Windows and NetBSD support
The most interesting thing here is the replacement of the pthread futex
implementation with an implementation based on thread park/unpark APIs.
Thread parking tends to be the primitive provided by systems which do
not have a futex primitive, such as NetBSD, so this implementation is
far more efficient than the pthread one. It is also useful on Windows,
where `RtlWaitOnAddress` is itself a userland implementation based on
thread park/unpark; we can implement it ourselves including support for
features which Windows' implementation lacks, such as cancelation and
waking a number of waiters with 1<n<infinity.

Compared to the pthread implementation, this thread-parking-based one
also supports full robust cancelation. Thread parking also turns out to
be useful for implementing `sleep`, so is now used for that on Windows
and NetBSD.

This commit also introduces proper cancelation support for most Windows
operations. The most notable omission right now is DNS lookups through
`GetAddrInfoEx`, just because they're a little more work due to having
a unique cancelation mechanism---but the machinery is all there, so I'll
finish gluing it together soon.

As of this commit, there are very few parts of `Io.Threaded` which do
not support full robust cancelation. The only ones which actually really
matter (because they could block for a prolonged period of time) are DNS
lookups on Windows (as discussed above) and futex waits on WASM.
2026-01-03 15:45:10 +00:00
Matthew Lugg
a1d4120fd9
std.Io.Threaded: update to new internal syscall API 2026-01-03 15:45:10 +00:00
Matthew Lugg
0da5d5f150
std.Io.Threaded: rework cancelation and groups
The goal of this internal refactor is to fix some bugs in cancelation
and allow group tasks to clean up their own resources eagerly. The
latter will become a guarantee of the `std.Io` interface, which is
important so that groups can be used to "detach" tasks.

This commit changes the API which POSIX system calls use internally (the
functions formerly called `beginSyscall` etc), but does not update the
usage sites yet.
2026-01-03 15:45:07 +00:00
Matthew Lugg
04226193cc
Revert "Use mmap std.heap.page_allocator impl when compiling for Wasm + libc"
This reverts commit c9fa8e46df.

This commit was failing CI checks. This failure was unfortunately not
noticed before merge, due in part to the build runner bug fixed in the
last commit.
2026-01-03 14:52:17 +00:00
Matthew Lugg
d024d9f005
std.Build: crashes in the test runner are fatal errors 2026-01-03 14:52:11 +00: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
mercenary
eab93d3574 libc: remove log/f, log2/f and log10/f
These symbols are already provided by compiler_rt
2026-01-01 15:25:40 +01:00
mercenary
814b1e9a58 libc: remove fmod, fmodf and fmodl
These symbols are already provided by compiler_rt
2026-01-01 15:18:44 +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
mercenary
bffd5c5112 libc: remove exp2 and exp2f
These symbols are already provided by compiler_rt
2025-12-30 18:27:19 +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
mercenary
1c05823ff8 libc: remove exp and expf
These symbols are already provided by compiler_rt
2025-12-29 15:55:18 +01:00
mercenary
5e4aefd2a6 libc: remove bcmp
This symbol is already provided by compiler_rt
2025-12-29 15:54:04 +01: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
Andrew Kelley
252c4e57c6 std.Progress: fix compilation on Windows
by using std.Io.File.readStreaming rather than posix.read
2025-12-26 19:58:56 -08:00
Andrew Kelley
28810f5e3d std.Io.File: add readStreaming
I resisted adding this because it's generally better to create a
File.Reader instead, but we do need a simple wrapper around the vtable
function, and there are use cases for it such as std.Progress.
2025-12-26 19:58:56 -08:00
Andrew Kelley
f160d5f979 std.Io.Threaded: implement file writing for Windows 2025-12-26 19:58:56 -08:00
Andrew Kelley
feeed922e1 std.Io.net: disable flaky test on mipsel 2025-12-26 19:58:56 -08:00
Ryan Liptak
58f0c8cfed Fix logic for detecting zero buffer capacity in fileReadStreamingWindows/fileReadPositionalWindows 2025-12-26 19:58:56 -08:00
Andrew Kelley
eb29737d5d std.Io.Threaded: more efficient statx mask check 2025-12-26 19:58:56 -08:00
Andrew Kelley
6dcf951391 std.Io.Threaded: error instead of assert for statx
when statx fails to return some of the requested fields
2025-12-26 19:58:56 -08:00
Andrew Kelley
2e9415d8a0 std.Io.Threaded: fix missing @memcpy in realPathPosix for FreeBSD 2025-12-26 19:58:56 -08:00
Andrew Kelley
0dbcf97551 std.Io.Threaded: fix resource leak in dirRealPathFilePosix
it should unconditionally close the opened file descriptor, not only on
error.
2025-12-26 19:58:56 -08:00
Andrew Kelley
eb0d5b1377 std.testing: use debug Io instance in expectEqualSlices 2025-12-26 19:58:56 -08:00
Andrew Kelley
28639bd6d7 std: prevent testing.io from use outside tests 2025-12-26 19:58:56 -08:00
Andrew Kelley
b0691df5ba test_runner: fix simple runner compilation 2025-12-26 19:58:56 -08:00
Andrew Kelley
0126e71903 build.zig: adjust max_rss for zig libc
this isn't meant to be a precisely measured thing that is different per
operating system. it's meant to have some room for growth but not too
much.
2025-12-26 19:58:56 -08:00
Andrew Kelley
8d96d7d219 remove test for nonexistent API 2025-12-26 19:58:56 -08:00
Andrew Kelley
dc1d27a646 std.Io.Threaded: more verbose TODO panic messages 2025-12-26 19:58:56 -08:00
Andrew Kelley
d7bf0dab82 link.Wasm: fix incremental update crash
Description of problem:

- wasm linker does GC in flush()
- it has the mechanism where it tracks the end index of a bunch of
  ArrayHashMap before flush() and after flush, shrinkRetainingCapacity()
  them to restore them to pre-flush() state
- this includes `functions`, which contains `__divti3`
- flush() notices the call to `__divti3` and calls markFunctionImport(),
  but that function does nothing on a second update because `alive` is
  already set to `true` so it incorrectly skips adding the intrinsic
  back to `functions`

I tried to remember why I thought it was OK to use this `alive` flag
which is state that's not being restored after flush(). If I remember
correctly, I was just leaving the code how it was before, with the plan
to change the data layout after encountering this exact problem.

However, I found a solution that doesn't require changing data layout,
and still takes advantage of the 1-bit-per-symbol data layout.
2025-12-26 19:58:56 -08:00
Andrew Kelley
3ad9a6a604 incr-check: more general --debug-log CLI 2025-12-26 19:58:56 -08:00
Andrew Kelley
a7d2cb7045 test-incremental: ignore .swp files 2025-12-26 19:58:56 -08:00
Andrew Kelley
66da6773eb build: make test-incremental respect -Dtest-filter 2025-12-26 19:58:56 -08:00
Andrew Kelley
b243e8f8cc std: integrate DebugAllocator with terminal mode
by adding a new std.Option for log.terminalMode

this is an alternative to the approach that was deleted in
aa57793b68
2025-12-26 19:58:56 -08:00
Andrew Kelley
a72c411fdb disable self-hosted aarch64 tests
These can be re-enabled when the assertion failures in the backend are
fixed, which does not need to block this branch.
2025-12-26 19:58:56 -08:00
Andrew Kelley
315bc10a0c std.Io.Threaded: dirRealPathFilePosix use libc realpath sometimes
When linking libc, and the directory is the cwd.

This avoids bugs on FreeBSD.
2025-12-24 12:57:18 -08:00
Andrew Kelley
02e560d9ef build.zig: adjust max_rss for unit tests
this isn't meant to be a precisely measured thing that is different per
operating system. it's meant to have some room for growth but not too
much.
2025-12-24 11:37:51 -08:00
Andrew Kelley
6f4e93f0dd std.Io.Threaded: wasi does not support processExecutablePath 2025-12-24 00:55:27 -08:00
Andrew Kelley
ace08ba642 std.Io.Threaded: prevent 0-byte file writes
these cause EINVAL on darwin and are generally a wasted syscall.

and remove a bogus error from File.Writer.Error.
2025-12-23 23:46:43 -08:00
Andrew Kelley
a901e92413 std.Io.Threaded: implement process executable path on darwin 2025-12-23 23:31:47 -08:00
Andrew Kelley
2708a3c1ac fix the guess number game example 2025-12-23 22:40:17 -08:00
Andrew Kelley
c9a609a61a test-cases: disable self-hosted aarch64 backend coverage 2025-12-23 22:15:12 -08:00
Andrew Kelley
6dbc95fb1f update test cases 2025-12-23 22:15:12 -08:00
Andrew Kelley
fa79d34674 std: add changing cur dir back
There's a good argument to not have this in the std lib but it's more
work to remove it than to leave it in, and this branch is already
20,000+ lines changed.
2025-12-23 22:15:12 -08:00
Andrew Kelley
98e9716c08 std: fix compilation on NetBSD 2025-12-23 22:15:12 -08:00
Andrew Kelley
7788fd6233 update test API usage 2025-12-23 22:15:12 -08:00
Andrew Kelley
b45984ec80 test-incremental: respect the wine, qemu, etc build flags 2025-12-23 22:15:12 -08:00
Andrew Kelley
669dae140c test-standalone: fix most compilation errors 2025-12-23 22:15:12 -08:00
Andrew Kelley
0870f17501 fix aro and resinator compilation errors 2025-12-23 22:15:12 -08:00
Andrew Kelley
c05e2720a1 tools: fix compilation errors 2025-12-23 22:15:12 -08:00
Andrew Kelley
7a09d579b5 CLI: lock stderr while running jit cmd 2025-12-23 22:15:12 -08:00
Andrew Kelley
60e90adbcf compiler: add missing end() for root std.Progress nodes
otherwise the progress task prevents main() from returning
2025-12-23 22:15:12 -08:00
Andrew Kelley
bd6acbf7da std.Io: minor cleanups to futex and event
mainly avoid an unnecessary `@ptrCast`
2025-12-23 22:15:12 -08:00
Andrew Kelley
6ece10f63d update test-link to new std.Io API 2025-12-23 22:15:12 -08:00
Andrew Kelley
e9da2783ce std.Io.Threaded: add a workaround for self-hosted wasm backend
Tracked by #30575
2025-12-23 22:15:12 -08:00
Andrew Kelley
691afee786 langref: fix build failure 2025-12-23 22:15:12 -08:00
Andrew Kelley
33e302d67a update remaining calls to std.Io.Threaded.init 2025-12-23 22:15:12 -08:00
Andrew Kelley
187d0a692d compiler: handle cancelation from finishPrelinkQueue 2025-12-23 22:15:12 -08:00
Andrew Kelley
7c1236e267 std: different way of doing some options
to avoid dependency loops
2025-12-23 22:15:12 -08:00
Andrew Kelley
9aee45be97 fix "zig std" compilation errors 2025-12-23 22:15:12 -08:00
Andrew Kelley
9158d3b281 std: remove ability to override Io.File.Permissions
This is causing another compiler dependency loop. I'll tackle these
overrides separately.
2025-12-23 22:15:12 -08:00
Andrew Kelley
c98157a3c9 std.Io.Threaded: implement environment variable scanning 2025-12-23 22:15:12 -08:00
Andrew Kelley
0992f1204e std.debug: delete nosuspend blocks
now that the application can choose an Io implementation these might
actually suspend.
2025-12-23 22:15:12 -08:00
Andrew Kelley
78c4fcfcd8 std.debug.lockStderr: cancel protection rather than recancel
because we need to return the value
2025-12-23 22:15:12 -08:00
Andrew Kelley
3c2f5adf41 std: integrate Io.Threaded with environment variables
* std.option allows overriding the debug Io instance
* if the default is used, start code initializes environ and argv0

also fix some places that needed recancel(), thanks mlugg!

See #30562
2025-12-23 22:15:12 -08:00
Andrew Kelley
86e9e32cf0 std.Io: fix missing try in waitTimeout 2025-12-23 22:15:12 -08:00
Andrew Kelley
a29d79313a std.Io.Threaded: accept argv and environ on init
This is needed unfortunately for OpenBSD and Haiku for process
executable path.

I made it so that you can omit the options usually, but you get a
compile error if you omit the options on those targets.
2025-12-23 22:15:12 -08:00
Michael Dusan
60481b8223 std.Io: trim terminating NUL from exe path on BSDs 2025-12-23 22:15:12 -08:00
Andrew Kelley
1132e329d3 std.Io.Threaded: fix up processExecutablePath OpenBSD
* policy is to always handle EINTR from all syscalls
* assert the result of realpath
* don't ignore errors from realpath
* hard-code path separators for code simplicity
2025-12-23 22:15:11 -08:00
Michael Dusan
7014976d3d openbsd: avoid error.OperationUnsupported
- realPathPosix does not support OpenBSD
- change processExecutablePath OpenBSD section to use std.c.realpath
2025-12-23 22:15:11 -08:00
Michael Dusan
8fdfeb624d openbsd: fix OS version detection
- do not include resulting nullz from sysctl MIB fetch
- fixes bug: "7.8<NULL>" is a std.Target.Query.parseVersion error
2025-12-23 22:15:11 -08:00
Michael Dusan
90bc371f56 openbsd: use Io.Dir.realPathFileAbsolute 2025-12-23 22:15:11 -08:00
Michael Dusan
486ed907f7 dragonfly: define std.c.nlink_t 2025-12-23 22:15:11 -08:00
Andrew Kelley
70e19ea353 update more "realpath" callsites 2025-12-23 22:15:11 -08:00
Ryan Liptak
51a6f3a525 Update a few more callsites for std.Io changes 2025-12-23 22:15:11 -08:00
Ryan Liptak
8968d75fb1 fileStat needs read permissions on Windows 2025-12-23 22:15:11 -08:00
Ryan Liptak
bb788cd392 dirOpenFileWtf16: Disallow opening directories when requesting write permissions
This matches the behavior of POSIX
2025-12-23 22:15:11 -08:00
Ryan Liptak
e442a0ecc2 Dir.readFile/readFileAlloc: take advantage of .allow_directory = false on Windows
Since we know the read will fail for directories, we can take advantage
of Windows being able to fail with IsDir during open to avoid needing to
wait until the read to find out about the directory-ness of the file.
2025-12-23 22:15:11 -08:00
Ryan Liptak
ad08117e9d Fix sizing of buffer/reservation size for dirReadWindows 2025-12-23 22:15:11 -08:00
Andrew Kelley
fd0c324cb0 std.debug: fix simple_panic 2025-12-23 22:15:11 -08:00
Andrew Kelley
debf307594 update all incremental tests to new std API
they're still not passing on windows for some reason though
2025-12-23 22:15:11 -08:00
Andrew Kelley
77d2ad8c92 std: consolidate all instances of std.Io.Threaded into a singleton
It's better to avoid references to this global variable, but, in the
cases where it's needed, such as in std.debug.print and collecting stack
traces, better to share the same instance.
2025-12-23 22:15:11 -08:00
Andrew Kelley
50c585227e fix compilation of incr-check 2025-12-23 22:15:11 -08:00
Andrew Kelley
7d955274bb update the init templates to new std API 2025-12-23 22:15:11 -08:00
Andrew Kelley
2e4a6c88b5 compiler: fix test-unit compilation failures 2025-12-23 22:15:11 -08:00
Andrew Kelley
99f25bfc23 std.Io: implement directory reading for WASI 2025-12-23 22:15:11 -08:00
Andrew Kelley
98f05a0f53 compiler: update calls to realpath 2025-12-23 22:15:11 -08:00
Andrew Kelley
7423d6a404 fix "hello world"
14K -> 57K
2025-12-23 22:15:11 -08:00
Andrew Kelley
e41342af83 std.Io.Threaded: reinstate fchmodat fallback
Stephen Gregoratto (original author of the fallback) says:

I read through both libcs again to compare:

Musl:
- `stat` path. Check error.
- If path is a symlink, return `OPNOTSUPP`.
- `openat` path as `O_PATH|O_NOFOLLOW|O_CLOEXEC`. Return `OPNOTSUPP` if we got `ELOOP`.
- Build procfs filename.
- `stat` procfs file.
- If procfs file is a symlink, return `OPNOTSUPP`.
- close path fd.

Glibc:
- open path as `O_PATH|O_NOFOLLOW|O_CLOEXEC`.
- fstatat path fd.
- If path is a symlink, return `OPNOTSUPP`.
- Build procfs filename.
- chmod procfs filename. Return `OPNOTSUPP` if we got `ENOENT`.
- close path fd.

I prefer glibc since you open the path first, which avoids a possible
TOCTOU race.
2025-12-23 22:15:11 -08:00
Andrew Kelley
64de4a7371 std.Io.Threaded: remove handling of ECANCELED
The only known situation in which this occurs is when using musl with
the undocumented extension PTHREAD_CANCEL_MASKED, causing the next
syscall to return ECANCELED.

However zig std lib does not use this mechanism, even when targeting
musl libc because it would require each async task to be on a fresh
pthread.

For the same reason, if third party code were to cause ECANCELED to be
returned from any of these syscalls, it would cause subsequent tasks to
be incorrectly canceled since they cannot be rearmed.

Thus, this Io implementation cannot handle this error code correctly,
expecting never to receive it.
2025-12-23 22:15:11 -08:00
Andrew Kelley
a8088306f6 std: rename other Dir "make" functions to "create" 2025-12-23 22:15:11 -08:00
Andrew Kelley
6e0c7ed865 std: rename makeDir to createDir for consistency with createFile 2025-12-23 22:15:11 -08:00
Andrew Kelley
52ba2a4c72 std.Io.Threaded: don't assume dirents are aligned
Linux kernel seems to do it but qemu user mode seems not to.
2025-12-23 22:15:11 -08:00
Andrew Kelley
6cfd2df695 don't skip test for closed issue 2025-12-23 22:15:11 -08:00
Andrew Kelley
bf81666beb std.fs.test: don't try to test nonexistent API 2025-12-23 22:15:11 -08:00
Andrew Kelley
88110139fe std.Io.Threaded: fix NetBSD compilation 2025-12-23 22:15:11 -08:00
Andrew Kelley
4025af9c05 std.Io.Threaded: fix fchmodat on linux with libc 2025-12-23 22:15:11 -08:00
Andrew Kelley
6aa31cedb7 std.Io.Dir.Reader: fix min_buffer_len on 32-bit linux
dirents64 still uses 8 byte alignment on 32-bit systems
2025-12-23 22:15:11 -08:00
Andrew Kelley
3e624e17a4 std: fix compilation errors on FreeBSD 2025-12-23 22:15:11 -08:00
Andrew Kelley
405db921dc std: fix compilation targeting WASI 2025-12-23 22:15:11 -08:00
Andrew Kelley
1381f9f612 std.debug: fix printLineFromFile
by using streamDelimiter and discardDelimiter functions that don't
depend on the buffer size being large enough
2025-12-23 22:15:11 -08:00
Andrew Kelley
ac11b82738 std.Io.Threaded: fix splat buffer calculations 2025-12-23 22:15:11 -08:00
Andrew Kelley
d060cb8cd6 std: fix test "max file name component lengths" 2025-12-23 22:15:11 -08:00
Andrew Kelley
002d444964 std: fix Io.Dir.min_buffer_len on Linux 2025-12-23 22:15:11 -08:00
Andrew Kelley
018e34271f std.fs.test: fix rebase conflicts 2025-12-23 22:15:11 -08:00
Ryan Liptak
3431f45031 std: Enough fixes to get things compiling on Windows 2025-12-23 22:15:11 -08:00
Ryan Liptak
1136d36362 windows: Remove BadPathName from error set of GetFinalPathNameByHandle
These validations are really only checking for kernel/mount manager
bugs, so an assert seems more appropriate.
2025-12-23 22:15:11 -08:00
Andrew Kelley
07c4ea2de0 all comments are notes, and use doc comments where possible 2025-12-23 22:15:11 -08:00
Ryan Liptak
edcbd7ed2c os.windows: Add comment explaining why we don't need a separate EX definition for RENAME_INFORMATION 2025-12-23 22:15:10 -08:00
Ryan Liptak
b6cde02322 fs tests: Remove references to readLinkW which no longer exists 2025-12-23 22:15:10 -08:00
Ryan Liptak
f96ef9780a SelfInfo.Windows: a few fixes for std.Io 2025-12-23 22:15:10 -08:00
Andrew Kelley
2f30b0f44d std.Progress.start: handle cancelation from isTty
It's important not to swallow error.Canceled. We don't have recancel()
yet but that will be a way to "rearm" cancelation after handling it so
that it is not ignored.
2025-12-23 22:15:10 -08:00
Ryan Liptak
406950f756 std.process: Fix executableDirPath functions 2025-12-23 22:15:10 -08:00
Ryan Liptak
8767a9a6d1 testFilenameLimits: Fix collision with dir and filename 2025-12-23 22:15:10 -08:00
Andrew Kelley
c1b9c46319 std.Io: introduce path_only to File.OpenFlags 2025-12-23 22:15:10 -08:00
Andrew Kelley
f27bd87ade std.Io.Threaded: allow length-0 file writes
At first I thought about keeping this as an assertion but I can see this
being useful if you already know how many bytes to read and you are
filling the end of the buffer.

This also more closely mirrors POSIX APIs.
2025-12-23 22:15:10 -08:00
Andrew Kelley
6f00157e1e std: fix "open smoke test" by passing allow_directory option 2025-12-23 22:15:10 -08:00
Andrew Kelley
47a2e8026f std.Io.Threaded: fix dirDeleteDir when not empty 2025-12-23 22:15:10 -08:00
Andrew Kelley
651ff9f9ee std.Io.Threaded: implement dirHardLink 2025-12-23 22:15:10 -08:00
Andrew Kelley
7ce5ee2e92 std: update remaining unit tests for std.Io API changes 2025-12-23 22:15:10 -08:00
Andrew Kelley
21d0264c61 std.dynamic_library: use a global static single threaded Io
See #30150
2025-12-23 22:15:10 -08:00
Andrew Kelley
8632a28ca9 std: add support for realpath on file handle
and rename OperationNotSupported to OperationUnsupported
2025-12-23 22:15:10 -08:00
Andrew Kelley
9bbb8e0d8e std.posix: make nlink_t on unsupported systems u0
instead of void
2025-12-23 22:15:10 -08:00
Ryan Liptak
f078c7138f std: Update/fix some usages/implementations of std.Io APIs 2025-12-23 22:15:10 -08:00
Ryan Liptak
1edae601a1 Test Dir.Reader.min_buffer_len via "max file name component lengths" test 2025-12-23 22:15:10 -08:00
Andrew Kelley
3466056478 std.Io.Dir.CopyFileOptions: rename override_permissions
to more simply `permissions`.

In master branch this was `override_mode`.
2025-12-23 22:15:10 -08:00
Andrew Kelley
d8b1cc953e std.Io.Dir.renameAbsolute: consistent parameter order 2025-12-23 22:15:10 -08:00
Andrew Kelley
e205b13ffb std.os.linux.IoUring: update for new fs API
and split out tests into a separate file
2025-12-23 22:15:10 -08:00
Andrew Kelley
b4bfd501ae std: move some tests from posix to fs 2025-12-23 22:15:10 -08:00
Andrew Kelley
f3723b42e1 std.Io: add unimplemented hard link API to File and Dir 2025-12-23 22:15:10 -08:00
Andrew Kelley
446c145ca8 std.Io.Threaded: fix compilation errors on posix 2025-12-23 22:15:10 -08:00
Ryan Liptak
a2416c685a Implement dirReadWindows 2025-12-23 22:15:10 -08:00
Ryan Liptak
d72983da44 File.OpenFlags: Add allow_directory and default it to true
This is one way of addressing/closing https://github.com/ziglang/zig/issues/16738

Previously, there was a mismatch between the default behaviors on Windows vs other platforms, where Windows was implicitly using .NON_DIRECTORY_FILE for its `openFile` implementation which caused `error.IsDir` when opening a directory, while on other platforms there is no equivalent flag for the `open` syscall. This meant that `openFile` on a path of a directory would fail on Windows but succeed on other platforms.

Adding `allow_directory` to `File.OpenFlags` serves two purposes:

1. It provides a cross-platform way to get the `.NON_DIRECTORY_FILE` behavior in the most efficient available way for the platform (on Windows, no extra syscalls are required, on other systems, an extra `fstat` is required)
2. It allows `statFile` to be implemented on top of `openFile` on Windows while still allowing `statFile` to work on directory paths. Before this commit, `statFile` on a directory path on Windows failed with `error.IsDir`

Note: The second purpose could have been addressed in different ways (bespoke call to NtCreateFile in the `statFile` implementation to avoid passing `NON_DIRECTORY_FILE`, or just never pass `NON_DIRECTORY_FILE` in the `openFile` implementation), so the first purpose is the more relevant/motivating force behind this change.

The default being `true` is intended to cut down on the number of syscalls as much as possible when using the default flags.
2025-12-23 22:15:10 -08:00
Andrew Kelley
1264469a41 compiler: fix build from source on macOS 2025-12-23 22:15:10 -08:00
Andrew Kelley
54865e0483 compiler: fix compilation when linking libc 2025-12-23 22:15:10 -08:00
Andrew Kelley
a5b719e9eb compiler: fix build failures from std.Io-fs 2025-12-23 22:15:10 -08:00
Andrew Kelley
608145c2f0 fix more fallout from locking stderr 2025-12-23 22:15:10 -08:00
Andrew Kelley
aa57793b68 std: rework locking stderr 2025-12-23 22:15:09 -08:00
Andrew Kelley
97f106f949 std.Io: fix dir iteration on macOS 2025-12-23 22:15:09 -08:00
Andrew Kelley
22afd168d9 fix build runner compilation errors on macOS 2025-12-23 22:15:09 -08:00
Andrew Kelley
9407ad8516 std.c.utimensat: add const 2025-12-23 22:15:09 -08:00
Andrew Kelley
16bd2e137e compiler: fix most compilation errors from std.fs changes 2025-12-23 22:15:09 -08:00
Andrew Kelley
4458e423bf link.MappedFile: update statx usage 2025-12-23 22:15:09 -08:00
Andrew Kelley
2a40c1b556 std.Io.Threaded: update call to statx 2025-12-23 22:15:09 -08:00
Andrew Kelley
f82e7dfbc0 std.os.linux: move statx docs to proper location 2025-12-23 22:15:09 -08:00
Andrew Kelley
1925e0319f update lockStderrWriter sites
use the application's Io implementation where possible. This correctly
makes writing to stderr cancelable, fallible, and participate in the
application's event loop. It also removes one more hard-coded
dependency on a secondary Io implementation.
2025-12-23 22:15:09 -08:00
Andrew Kelley
ec56696503 std.process.cleanExit: take an Io parameter
In case exit(0) will be called, this provides the opportunity for the
application's Io instance to be the one to clear the terminal in case
std.Progress or similar was used.
2025-12-23 22:15:09 -08:00
Andrew Kelley
e68ae8d7a1 update uses of std.debug.lockStdErr 2025-12-23 22:15:09 -08:00
Andrew Kelley
54e4a3456c link: update to new file system APIs 2025-12-23 22:15:09 -08:00
Andrew Kelley
22b0eea3c0 std.Io.Dir: improve realPath documentation 2025-12-23 22:15:09 -08:00
Andrew Kelley
6484101f78 update occurences of std.fs.openDirAbsolute 2025-12-23 22:15:09 -08:00
Andrew Kelley
1ed845e1f6 update occurences of setEndPos to setLength 2025-12-23 22:15:09 -08:00
Andrew Kelley
16f8af1b9a compiler: update various code to new fs API 2025-12-23 22:15:09 -08:00
Andrew Kelley
e1cf753db7 std: update fchmodat tests 2025-12-23 22:15:09 -08:00
Andrew Kelley
68621afd2e std.tar: update fs API calls to take io argument 2025-12-23 22:15:09 -08:00
Andrew Kelley
0e230993d5 std.Io.Dir: add setFilePermissions and setFileOwner 2025-12-23 22:15:09 -08:00
Andrew Kelley
c4cefd6835 std.Build.Step.Run: restore Color.inherit logic 2025-12-23 22:15:09 -08:00
Andrew Kelley
91fa252cf2 std.Io: implement dir reading for BSDs 2025-12-23 22:15:09 -08:00
Andrew Kelley
94ef56ee26 std.Io.Dir: fix walking
* Make Io.Dir.Reader lower level, accepting a buffer.
* Make Io.Dir.Iterator higher level, requesting only one Entry with
  every call to `next`.
2025-12-23 22:15:09 -08:00
Andrew Kelley
7bc0166b7c std.Io: implement dirRead for Linux
unfortunately, Io.Dir.SelectiveWalker is copying the iterator which
has multiple problems
2025-12-23 22:15:09 -08:00
Andrew Kelley
b042e93522 std: update tty config references in the build system 2025-12-23 22:15:09 -08:00
Andrew Kelley
7837d975dc std: save terminal escape stripping for later 2025-12-23 22:15:09 -08:00
Andrew Kelley
95b0399d1b std: finish implementing futexWait with timer 2025-12-23 22:15:09 -08:00
Andrew Kelley
3a6e15449b std.Io: add ResetEvent based on futexes
and add futex to the vtable. A future commit may make the other sync
primitives based on futexes.
2025-12-23 22:15:09 -08:00
Andrew Kelley
ffcbd48a12 std: rework TTY detection and printing
This commit sketches an idea for how to deal with detection of file
streams as being terminals.

When a File stream is a terminal, writes through the stream should have
their escapes stripped unless the programmer explicitly enables terminal
escapes. Furthermore, the programmer needs a convenient API for
intentionally outputting escapes into the stream. In particular it
should be possible to set colors that are silently discarded when the
stream is not a terminal.

This commit makes `Io.File.Writer` track the terminal mode in the
already-existing `mode` field, making it the appropriate place to
implement escape stripping.

`Io.lockStderrWriter` returns a `*Io.File.Writer` with terminal
detection already done by default. This is a higher-level application
layer stream for writing to stderr.

Meanwhile, `std.debug.lockStderrWriter` also returns a `*Io.File.Writer`
but a lower-level one that is hard-coded to use a static single-threaded
`std.Io.Threaded` instance. This is the same instance that is used for
collecting debug information and iterating the unwind info.
2025-12-23 22:15:09 -08:00
Andrew Kelley
78d262d96e std: WIP: debug-level stderr writing 2025-12-23 22:15:09 -08:00
Andrew Kelley
03526c59d4 std.debug: fix printLineFromFile 2025-12-23 22:15:09 -08:00
Andrew Kelley
5b436d2c51 build_runner compiling again 2025-12-23 22:15:08 -08:00
Andrew Kelley
90f7259ef1 std.Progress: use a global static Io instance
This decision should be audited and discussed.

Some factors:
* Passing an Io instance into start.
* Avoiding reference to global static instance if it won't be used, so
  that it doesn't bloat the executable.
* Being able to use std.debug.print, and related functionality when
  debugging std.Io instances and std.Progress.
2025-12-23 22:15:08 -08:00
Andrew Kelley
bee8005fe6 std.heap.DebugAllocator: never detect TTY config
instead, allow the user to set it as a field.

this fixes a bug where leak printing and error printing would run tty
config detection for stderr, and then emit a log, which is not necessary
going to print to stderr.

however, the nice defaults are gone; the user must explicitly assign the
tty_config field during initialization or else the logging will not have
color.

related: https://github.com/ziglang/zig/issues/24510
2025-12-23 22:15:08 -08:00
Andrew Kelley
4a53e5b0b4 fix a handful of compilation errors related to std.fs migration 2025-12-23 22:15:08 -08:00
Andrew Kelley
ebdbbd20ac update makeDir() sites to specify permissions 2025-12-23 22:15:08 -08:00
Andrew Kelley
3725f72293 update std.process.Child.run occurences to use io 2025-12-23 22:15:08 -08:00
Andrew Kelley
9e3bda5eff tests: close() -> close(io) 2025-12-23 22:15:08 -08:00
Andrew Kelley
a91c6dc71d test: std.fs.File -> std.Io.File 2025-12-23 22:15:08 -08:00
Andrew Kelley
1dcfc8787e update all readFileAlloc() to accept Io instance 2025-12-23 22:15:08 -08:00
Andrew Kelley
4be8be1d2b update all rename() to rename(io) 2025-12-23 22:15:08 -08:00
Andrew Kelley
4218344dd3 std.Build.Cache: remove readSmallFile and writeSmallFile
These were to support optimizations involving detecting when to avoid
calling into LLD, which are no longer implemented.
2025-12-23 22:15:08 -08:00
Andrew Kelley
950d18ef69 update all access() to access(io) 2025-12-23 22:15:08 -08:00
Andrew Kelley
314c906dba std.debug: simplify printLineFromFile 2025-12-23 22:15:08 -08:00
Andrew Kelley
9ccd68de0b std: move abort and exit from posix into process
and delete the unit tests that called fork()

no forking allowed in the std lib, including unit tests, except to implement child process spawning.
2025-12-23 22:15:08 -08:00
Andrew Kelley
7f5bb118d4 std.Io: make all the close functions batched 2025-12-23 22:15:08 -08:00
Andrew Kelley
6f46570958 link.MachO: update parallel hasher to std.Io 2025-12-23 22:15:08 -08:00
Andrew Kelley
181ac08459 std.Io.Threaded: add missing fileLength implementation 2025-12-23 22:15:08 -08:00
Andrew Kelley
9f4d40b1f9 update all stat() to stat(io) 2025-12-23 22:15:08 -08:00
Andrew Kelley
264d714321 update all openDir() sites to accept io instance 2025-12-23 22:15:08 -08:00
Andrew Kelley
f53248a409 update all std.fs.cwd() to std.Io.Dir.cwd() 2025-12-23 22:15:08 -08:00
Andrew Kelley
9169983159 std.fs: migrate most of the API elsewhere 2025-12-23 22:15:08 -08:00
Andrew Kelley
877032ec6a std: reorganize realpath and process executable APIs 2025-12-23 22:15:08 -08:00
Andrew Kelley
8328de24f1 update all occurrences of openFile to receive an io instance 2025-12-23 22:15:08 -08:00
Andrew Kelley
dd1d15b72a update all occurrences of std.fs.Dir to std.Io.Dir 2025-12-23 22:15:08 -08:00
Andrew Kelley
3204fb7569 update all occurrences of std.fs.File to std.Io.File 2025-12-23 22:15:07 -08:00
Andrew Kelley
1b1fb7fab6 std.crypo.tls: delete unused import 2025-12-23 22:15:07 -08:00
Andrew Kelley
aafddc2ea1 update all occurrences of close() to close(io) 2025-12-23 22:15:07 -08:00
Andrew Kelley
eab354b2f5 std.Io.Threaded: import File and Dir 2025-12-23 22:15:07 -08:00
Andrew Kelley
72b76077ab std: fix some surface level compilation errors
And boldly remove preadv, pwritev, readv, writev, pread, pwrite from
std.posix.
2025-12-23 22:15:07 -08:00
Andrew Kelley
ba999d608c std: extract sendfile/copy_file_range from Io.File.Writer
and move it into std.Io.Threaded (below the VTable)
2025-12-23 22:15:07 -08:00
Andrew Kelley
814480db7c std: all File functions moved to std.Io 2025-12-23 22:15:07 -08:00
Andrew Kelley
d1d2c37af2 std: all Dir functions moved to std.Io 2025-12-23 22:15:07 -08:00
Andrew Kelley
81214278ca std.Io.Threaded: implement dirStat 2025-12-23 22:15:07 -08:00
Andrew Kelley
89bda60d28 std.Io.Threaded: implement makePath 2025-12-23 22:15:07 -08:00
Stephen Gregoratto
c3f2de5e51 Linux: Update syscall list for 6.17
The 6.17 kernel added[1] syscalls for getting/setting certain file flags
and attributes. It's meant to be a more extensible replacement for these
ioctl's:

- `FS_IOC_GETFLAGS`/`FS_IOC_SETFLAGS`.
- `FS_IOC_FSGETXATTR`/`FS_IOC_FSSETXATTR`.

The definitions of these calls are as follows:

```zig
const file_attr = extern struct {
    /// Extended flags that apply to this file. (get/set).
    xflags: u64,
    /// Preferred extent allocation size, in bytes. (get/set).
    extsize: u32,
    /// One of:
    /// - The number of data extents in this file.
    /// - If `FS_IOC_FSGETXATTRA` is set, the number of extended attribute events in the file.
    /// (get)
    nextents: u32,
    /// Project Identifier (get/set).
    projid: u32,
    /// Preferred extent allocation size for CoW operations, in bytes (get/set).
    cowextsize: u32,
};

// size=@sizeOf(file_attr)
fn file_getattr(dirfd: fd_t, path: [*:0], fattr: *file_attr, size: usize, at_flags: u32) {}
fn file_setattr(dirfd: fd_t, path: [*:0], fattr: *file_attr, size: usize, at_flags: u32) {}
```

Users need to set/check `xflags` with the `FS_XFLAG` flags defined in
`linux/fs.h`. `ioctl_xfs_fsgetxattr(2)` has more information about the
type of information one can retrieve.

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=57fcb7d930d8f00f383e995aeebdcd2b416a187a
2025-12-24 13:10:38 +11:00
Andrew Kelley
985a3565c6 Merge pull request 'Replace uses of std.Thread.Pool with std.Io, and remove std.Thread.Pool' (#30557) from compiler-std.Io into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30557
Reviewed-by: Andrew Kelley <andrewrk@noreply.codeberg.org>
2025-12-22 20:09:34 +01:00
ashpil
0ea79c85b2
remove std.gpu.(binding|location)
with the extern changes, they are no longer necessary
2025-12-22 10:00:35 -08:00
ashpil
24e7500c33
@extern: add support for spir-v locations and descriptors 2025-12-22 10:00:35 -08:00
Mason Remaley
3af842f0e8 Fixes enums.fromInt failing at compile time on in range but invalid values 2025-12-22 14:19:18 +01:00
pyk
b346090ed2 add PERF_EVENT_IOC_ID
The value is derived from the following:

```
std.os.linux.IOCTL.IOR('$', 7, u64);
```

Signed-off-by: pyk <pyk@noreply.codeberg.org>
2025-12-22 14:16:06 +01:00
Matthew Lugg
23e5a17187
std: delete Thread.Pool in favour of Io 2025-12-22 12:55:16 +00:00
Matthew Lugg
18bc7e802f
compiler: replace thread pool with std.Io
Eliminate the `std.Thread.Pool` used in the compiler for concurrency and
asynchrony, in favour of the new `std.Io.async` and `std.Io.concurrent`
primitives.

This removes the last usage of `std.Thread.Pool` in the Zig repository.
2025-12-22 12:55:16 +00:00
Matthew Lugg
9ae4e38ca2
tools: replace thread pool with std.Io 2025-12-22 12:47:38 +00:00
Matthew Lugg
2046e0f4be
std.Io.Threaded: fix group closure leak
More tasks could be added to the group at any time before it completes,
so it's not valid to look at the `token` passed in here.

There's also a related bug in `Threaded`, which is that tasks spawned in
a group after it is canceled will not observe that cancelation, but that
is a more complex bug which needs some deeper design changes.
2025-12-22 12:47:38 +00:00
Matthew Lugg
4772f1a9f4
std.Io: make it safe to call Group.async within a group task 2025-12-22 11:54:57 +00:00
Matthew Lugg
49f17237b0
compiler,std: remove a handful of redundant discards
I'm embarrassed to say I didn't realise until a few days ago that you
could omit the `_` capture for `if`/`while` on `E!void`...
2025-12-22 11:54:57 +00:00
Alex Rønne Petersen
aa0249d74e Merge pull request 'std.ascii: rename indexOf functions to find' (#30101) from adria/zig:indexof-find into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30101
Reviewed-by: Andrew Kelley <andrewrk@noreply.codeberg.org>
Reviewed-by: mlugg <mlugg@noreply.codeberg.org>
2025-12-22 12:50:46 +01:00
Doug Coleman
6b9125cbe6 build_runner: fix race condition in dispatch_deps capacity reservation
Move ensureUnusedCapacity inside the mutex call to prevent
a race condition where other worker threads could append to
memory_blocked_steps between checking the length and iterating.

repro branch: https://codeberg.org/erg/zig/src/branch/fix-30014-repro
check out that branch, and depending on if you have the fix-30014 patch or not,
it will either race condition or succeed

Fixes #30014
2025-12-21 20:11:05 -06:00
mlugg
8c5f731afb Merge pull request 'Some std.Io goodies' (#30235) from std.Io-misc into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30235
Reviewed-by: Andrew Kelley <andrewrk@noreply.codeberg.org>
2025-12-21 14:50:58 +01:00
Matthew Lugg
67eed99550
std.Io.Queue: introduce closure and fix a bug
Queues can now be "closed". A closed queue cannot have more elements
appended with `put`, and blocked calls to `put` will immediately unblock
having failed to append some elements. Calls to `get` will continue to
succeed as long as the queue buffer is non-empty, but will then never
block; already-blocked calls to `get` will unblock.

All queue get/put operations can now return `error.Closed` to indicate
that the queue has been closed. For bulk get/put operations, they may
add/receive fewer elements than the minimum requested *if* the queue was
closed or the calling task was canceled. In that case, if any elements
were already added/received, they are returned first, and successive
calls will return `error.Closed` or `error.Canceled`.

Also, fix a bug where `Queue.get` could deadlock because it incorrectly
blocked until the given buffer was *filled*.

Resolves: #30141
2025-12-21 13:07:04 +00:00
Matthew Lugg
fa7e818e14
std.Io: add new cancelation APIs
Also, better document how cancelation actually works.
2025-12-21 13:07:04 +00:00
Matthew Lugg
9bf65f6e05
std.Io.Threaded: replace ResetEvent with Io.Event 2025-12-21 13:07:04 +00:00
Matthew Lugg
0649f96da3
std.Io: introduce Event implemented using futex 2025-12-21 13:07:03 +00:00
Matthew Lugg
b4ee54b580
std.Io: reimplement Mutex and Condition atop futex
This work was partially cherry-picked from Andrew's WIP std.fs branch.
However, I also analyzed and simplified the Mutex and Condition
implementations, and brought them in line with modern Zig style.

Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2025-12-21 13:07:03 +00:00
Matthew Lugg
6ed5b62050
std.Io: introduce futex primitives
Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2025-12-21 13:07:03 +00:00
Matthew Lugg
330e295bc4
mailmap: add some addresses used by the Codeberg UI 2025-12-21 13:07:03 +00:00
Matthew Lugg
5611779f39
Sema: fix nested error union coercions
Previously, `E1!void` failed to coerce to `E2!E1!void` because it tried
to coerce the `E1` error to an `E2` if comptime-known and refused to
attempt any other coercion. This is a strange language rule with no
clear justification, and breaks real use cases (such as calling `getOne`
on an `Io.Queue(E!T)`). Instead, only error *sets* should try to coerce
to an "error" value of an error union type.
2025-12-21 13:07:03 +00:00
Matthew Lugg
3f08073f7d
x86_64: hack around more OPV bugs
I would just fix this in Sema if it were easy to do so, but this is more
like a (minor) AIR data design issue than a straightforward Sema bug.
2025-12-21 13:07:00 +00:00
Alex Rønne Petersen
b27bdd5af0 libc: add back freebsd bsm headers
Accidentally removed in #30135.
2025-12-21 03:54:17 +01:00
Prokop Randáček
442592855c change placeholder pattern in deduplicated type errors 2025-12-20 08:06:59 +01:00
Andrew Kelley
5fa7f13082 Merge pull request 'Windows: Avoid ever-expanding DeviceIoControl error set, handle NOT_A_REPARSE_POINT in ReadLink' (#30186) from squeek502/zig:win-deviceiocontrol into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30186
2025-12-19 18:50:27 +01:00
Alex Rønne Petersen
f9419c81cf
build: bump test-c-abi max_rss to 2_389_779_251 on x86_64-linux 2025-12-18 13:01:35 +01:00
Alex Rønne Petersen
a6c22c5edb
std.os.linux.test: disable fallocate on mips64*-linux-*abin32
https://codeberg.org/ziglang/zig/issues/30220
2025-12-18 12:56:28 +01:00
Alex Rønne Petersen
6b77bb3f91
build: bump test-compiler-rt max_rss to 978_463_129 on x86_64-linux 2025-12-18 11:42:42 +01:00
Alex Rønne Petersen
0437decca9
std.http.test: disable redirect to different connection on mips*-linux w/o libc
https://codeberg.org/ziglang/zig/issues/30216
2025-12-18 01:46:31 +01:00
Mick Sayson
fc78a61c4c Prevent register clobbering on x86_64 threadlocal access
On the x86_64 self hosted backend, thread locals are accessed through
__tls_get_addr on PIC. Usually this goes through a fast path which does
not lose any registers, however in some cases (notably any dlopened
library on my machine) this can take a slow path which calls out to C
ABI functions

Catch this case and backup registers as necessary

Fix a few other ones while we're here. Credit to mlugg

Fixes #30183
2025-12-17 15:33:10 +01:00
Alex Rønne Petersen
b9eefe17af
test: fix up c3ee8078b4
Oops, accidentally didn't run the tests for 32-bit powerpc.
2025-12-16 09:01:51 +01:00
Alex Rønne Petersen
00903d35b1
std.Target: openbsd's landisk port is only little endian 2025-12-16 06:27:25 +01:00
Alex Rønne Petersen
447d6a0dd3
test: remove some nonsensical openbsd targets from llvm_targets 2025-12-16 06:25:32 +01:00
Alex Rønne Petersen
b675223eb5
std: disable tests that depend on getFdPath on openbsd 2025-12-16 06:25:27 +01:00
Alex Rønne Petersen
215b250e6b
std.posix.test: fix sigset tests on openbsd (no rt signals) 2025-12-16 06:25:21 +01:00
Alex Rønne Petersen
da9733d441
compiler-rt: implement __clear_cache() for arm/mips64-openbsd 2025-12-16 06:25:15 +01:00
Alex Rønne Petersen
914005105e
std.fs: fix build error in selfExePath() on openbsd 2025-12-16 06:25:10 +01:00
Alex Rønne Petersen
707e389f38
std.Io.Threaded: apply netbsd todo hacks to openbsd
https://codeberg.org/ziglang/zig/issues/30063
2025-12-16 06:25:07 +01:00
Alex Rønne Petersen
18db762bb8
std.c: openbsd does not have SIGRTMIN/SIGRTMAX 2025-12-16 06:24:58 +01:00
Alex Rønne Petersen
56add8374c
std.c: remove comptime asserts of siginfo_t size
These serve no purpose other than to verify that the compiler is doing layout
correctly, and this is clearly not the place for that.
2025-12-16 06:24:54 +01:00
Alex Rønne Petersen
672ce9e919
compiler-rt: export __stack_chk_fail as __stack_smash_handler on openbsd 2025-12-16 06:24:49 +01:00
Alex Rønne Petersen
0564f83978
std.zig.target: remove two unused consts 2025-12-16 06:24:24 +01:00
Alex Rønne Petersen
00220a5ea1
build: add max_rss values observed on powerpc64le-linux 2025-12-16 06:23:20 +01:00
Alex Rønne Petersen
9f58931193
std.http: disable all tests on non-Debug powerpc64
https://github.com/llvm/llvm-project/issues/171879
2025-12-16 06:23:14 +01:00
Alex Rønne Petersen
647866dd63
std.math: disable hypot tests on non-Debug powerpc64
https://github.com/llvm/llvm-project/issues/171869
2025-12-16 06:23:11 +01:00
Alex Rønne Petersen
423d117251
test: skip bitcast nan float does not modify signaling bit on powerpc
This fails on a pwr10 machine.
2025-12-16 06:23:06 +01:00
Alex Rønne Petersen
c3ee8078b4
test: skip some C ABI vector tests on powerpc
These fail on a pwr10 machine.
2025-12-16 06:23:01 +01:00
Alex Rønne Petersen
eaae3f936b
test: limit invalid_tail_call to x86_64-linux
Targets that don't support tail calls will see:

    /home/ci/zig/.zig-cache/o/35dbe82c8e4d49ae5b7d630329568133/tmp.zig:5:5: error: unable to perform tail call: compiler backend 'stage2_llvm' does not support tail calls on target architecture 'powerpc64le' with the selected CPU feature flags

So just run this test on a known-good target.
2025-12-16 06:22:51 +01:00
Alex Rønne Petersen
f36949ead3
test: disable an error trace test on optimized powerpc64le 2025-12-16 06:22:46 +01:00
Alex Rønne Petersen
d5e3c8a2aa
compiler-rt: disable extenddftf2 test on powerpc
This fails on a pwr10 machine.
2025-12-16 06:22:40 +01:00
Alex Rønne Petersen
9373a963a1
langref: work around powerpc LLVM miscompilation in runtime_shrExact_overflow
https://github.com/ziglang/zig/issues/24304
2025-12-16 06:22:33 +01:00
Andrew Kelley
80b5917fad Merge pull request 'Bigint improvements' (#30100) from unplanned/zig:bigint-improvements into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30100
Reviewed-by: jedisct1 <jedisct1@noreply.codeberg.org>
2025-12-15 01:05:50 +01:00
Linus Groh
648c1c5d28 libc: Update macOS headers to SDK 26.2 2025-12-14 20:35:07 +00:00
Ryan Liptak
36cb5ea5f4 windows.ReadLink: handle NOT_A_REPARSE_POINT and add test 2025-12-14 07:12:38 -08:00
Ryan Liptak
ea7512084b Make windows.DeviceIoControl return NTSTATUS instead of a Zig error
The number of possible errors in the theoretical error set of this function is very large, while each individual call to the function is only concerned with a (potentially small) subset of those errors that are specific to the control code being used. This commit makes the callers determine which statuses they are interested in to avoid an ever-ballooning error set and ever-growing switch cases at each call site that throw away most of those errors.
2025-12-14 07:12:38 -08:00
Alex Rønne Petersen
2f2b097576 Merge pull request 'Linux: Nuke Stat bits in favour of Statx' (#30122) from The-King-of-Toasters/zig:statx into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30122
Reviewed-by: Alex Rønne Petersen <alex@alexrp.com>
2025-12-14 05:25:29 +01:00
Stephen Gregoratto
aec7bfb092 Linux: Dedupe generic decls
Commit #fc7a5f2 moved many of the `_t` types up a level, but didn't
remove them from arch_bits. Since `Stat` is gone, all but `time_t` can
be removed.
2025-12-14 01:41:47 +01:00
Stephen Gregoratto
6216922a9d Linux: Nuke Stat bits in favour of statx
Maintaining the POSIX `stat` bits for Zig is a pain. The order and
bit-length of members differ between all architectures, and int types
can be signed or unsigned. The libcs deal with this by introducing the
own version of `struct stat` and copying the kernel structure members to
it. In the case of glibc, they did it twice thanks to the largefile
transition!

In practice, the project needs to maintain three versions of `struct
stat`:
- What the kernel defines.
- What musl wants for `struct stat`.
- What glibc wants for `struct stat64`. Make sure to use `fstatat64`!

This isn't as simple as running `zig translate-c`. In #21440 I had to:
- Compile toolchains for each arch+glibc/musl combo.
- Create a test `fstat` program with/without `FILE_OFFSET_BITS=64`.
- Dump the value for `struct stat`.
- Stare at `std.os.linux`/`std.c` and cry.
- Add some missing padding.

The fact that so many target checks in the `linux` and `posix` tests
exist is most likely due to writing to padding bits and failing later.

The solution to this madness is `statx(2)`:
- It takes a single structure that is the same for all arches AND libcs.
- It uses a custom timestamp format, but it is 64-bit ready.
- It gives the same info as `fstatat(2)` and more!
- Unlike `fstatat(2)`, you can request a subset of the info required
  based on passing a mask.

It's so good that modern Linux arches (e.g. riscv) don't even implement
`stat`, with the libcs using a generic `struct stat` and copying from
`struct statx`.

Therefore, this commit rips out all the `stat` bits from `std.os.linux`
and `std.c`. `std.posix.Stat` is now `void`, and calling
`std.posix.*stat` is an compile-time error. A wrapper around `statx` has
been added to `std.os.linux`, and callers have been upgraded to use it.
Tests have also been updated to use `statx` where possible.

While I was here, I converted the mask and file attributes to be packed
struct bitfields. A nice side effect is checking that you actually
recieved the members you asked for via `Statx.mask`, which I have used
by adding `assert`s at specific callsites.
2025-12-14 01:41:47 +01:00
Stephen Gregoratto
ff3fd950a7 Linux: Update Statx structure
Also removes the blank lines between members, and a comptime sizeOf
check.
2025-12-14 01:41:47 +01:00
Jacob Young
c13857e504 windows: type safety improvements and more ntdll functions 2025-12-12 01:58:21 -05:00
Alex Rønne Petersen
27e5047a88
musl: add nop after b to __dlsym in powerpc64 ldso code
https://www.openwall.com/lists/musl/2025/12/12/1
2025-12-12 02:10:41 +01:00
Alex Rønne Petersen
1add36403a
musl: add nop after bl to start_c in powerpc64 crt code
https://www.openwall.com/lists/musl/2025/12/11/4
2025-12-12 00:52:07 +01:00
Alex Rønne Petersen
c1daad3d68
aro: define _CALL_ELF to 2 for powerpc64(le) 2025-12-12 00:52:00 +01:00
Alex Rønne Petersen
abc8ddcfa9
llvm: fix aliases not having linkage, visibility, etc set 2025-12-10 15:40:30 +01:00
Alex Rønne Petersen
2da956b84a
build: bump compiler max_rss to 6_664_025_702 on x86_64-linux 2025-12-10 00:07:25 +01:00
Andrew Kelley
1608e31ca1 std: disable flaky tests
tracked by https://codeberg.org/ziglang/zig/issues/30141
2025-12-09 10:58:55 -08:00
jedisct1
d27c804d9f Merge pull request 'crypto.mlkem: return J(z||c) on implicit rejection' (#30155) from jedisct1/zig:mlkemrej into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30155
2025-12-09 16:28:14 +01:00
jedisct1
60a9a7e085 Merge pull request 'crypto: add missing sha2 arm early clobber' (#30152) from sinon/zig:arm-sha2-clobber into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30152
2025-12-09 10:44:55 +01:00
Frank Denis
a0e9130b89 crypto.mlkem: return J(z||c) on implicit rejection
The ML-KEM decapsulation was returning z directly when implicit
rejection was triggered, but FIPS 203 specifies it should return
J(z || c) = SHAKE256(z || c).
2025-12-09 00:55:59 +01:00
David Rubin
ae21089b97
crypto: add missing sha2 arm early clobber 2025-12-09 00:41:23 +04:00
Alex Rønne Petersen
7f36c4c7d3 Merge pull request 'add FreeBSD 15 libc support' (#30135) from alexrp/zig:freebsd-15 into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30135
2025-12-08 15:42:05 +01:00
pentuppup
c2aeef04e5 sema: remove special case check in is_non_err 2025-12-08 14:59:55 +01:00
Alex Rønne Petersen
5d96a58f1d
build: bump test-compiler-rt max_rss to 868_445_388 on x86_64-linux 2025-12-07 11:28:06 +01:00
Alex Rønne Petersen
81c52fd621
std.Target: bump max freebsd version to 15.0 2025-12-07 09:48:19 +01:00
Alex Rønne Petersen
5b8545e4d9
libc: update headers from freebsd 15 2025-12-07 09:32:28 +01:00
Alex Rønne Petersen
c1862ce642
drop support for powerpc-freebsd-eabihf
FreeBSD 15 dropped this target. It also dropped x86-freebsd-none, but since that
target remains buildable and usable with the 32-bit compat layer, we keep it for
now.
2025-12-07 09:29:54 +01:00
Alex Rønne Petersen
51f62ea918
libc: update startup code from freebsd 15 2025-12-07 09:18:38 +01:00
Alex Rønne Petersen
2f20ee373b
libc: deal with freebsd 15 changes (new libsys, libutil sover) 2025-12-07 09:18:35 +01:00
Alex Rønne Petersen
6906460d56
libc: add freebsd 15 abilists file 2025-12-07 09:18:19 +01:00
Pavel Verigo
bf58a3bc08 stage2_wasm: revival, enabling tests 2025-12-07 07:21:15 +01:00
Pavel Verigo
cc099afca5 sema: fix error_return_trace_index handling in zirCondBr 2025-12-07 07:20:59 +01:00
Alex Rønne Petersen
a21d9408a3
build: bump test-zigc max_rss to 871_883_161 on x86_64-linux 2025-12-07 04:04:06 +01:00
Matthew Lugg
b5ff96b4d2 std.heap: remove raw_c_allocator
After https://codeberg.org/ziglang/zig/pulls/30103, `raw_c_allocator` is
redundant. It existed to avoid overhead when you could assert that all
of your `Allocator` usage was going to be compatible with the C `malloc`
API, but the standard `c_allocator` is now able to avoid that overhead
*in the case* that your usage is compatible (and use the less efficient
path in the rare case where it's not), so there's no need for the raw
version anymore. Leaving it in `std.heap` at this point seems like it
would just be a footgun.
2025-12-06 22:08:40 +01:00
Matthew Lugg
db15df5daa
build_runner: don't dim the tree line of reused step
This was presumably unintentional, as the old behavior looked quite odd
when you noticed it. All of the line-drawing characters ought to be the
same color; only the step name/status is dimmed when a step is "reused"
(i.e. appears multiple times in the tree).
2025-12-06 14:22:47 +00:00
Matthew Lugg
65922a2d43
std: make stack unwinding faster on macOS
https://github.com/ziglang/zig/issues/26027#issuecomment-3571227050
tracked some bad performance in `DebugAllocator` on macOS down to a
function in dyld which `std.debug.SelfInfo` was calling into. It turns
out `dladdr`'s symbol lookup logic is horrendously slow (looking at its
source code, it appears to be doing a *linear scan* over all symbols in
the image?!). However, we don't actually need the symbol, so we want to
try and avoid this logic.

Luckily, dyld has more precise APIs for what we need! Unluckily, Apple,
in their infinite wisdom, decided they should be deprecated in favour of
`dladdr`, despite the latter being several times slower (and by "several
times", I have measured a 50x slowdown on repeated calls to `dladdr`
compared to the other API). But luckily again, the deprecated APIs are
still exposed.

So, after a careful analysis of the situation (reading dyld code and
cursing Apple engineers), I think it makes sense to just use these
deprecated APIs for now. If they ever go away, we can write our own
cache for this data to bypass Apple's awfully slow code, but I suspect
these functions will stick around for the foreseeable future.

Uh, and if `_dyld_get_image_header_containing_address` goes away,
there's also `dyld_image_header_containing_address`, which is a
seemingly identical function, exported by dyld just the same, but with a
separate (functionally identical) implementation, and not documented in
the public header file. Apple work in mysterious ways, I guess.
2025-12-06 10:41:42 +00:00
Alex Rønne Petersen
621e1d7b1e
Compilation: fix appendFileSystemInput race between main thread and C object workers
Co-authored-by: Matthew Lugg <mlugg@mlugg.co.uk>
2025-12-06 09:54:43 +01:00
pentuppup
28c5cc390c detect comptime var references in asm input/output and improve errors 2025-12-06 09:42:51 +01:00
mlugg
dbb4c8d151 Merge pull request 'Remove things deprecated during the 0.15 release cycle' (#30018) from linus/zig:remove-deprecated-stuff into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30018
2025-12-06 08:51:15 +01:00
Alex Rønne Petersen
d41c16930d Merge pull request 'link: support --dependency-file linker option' (#30073) from alexrp/zig:elf-depfile into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30073
Reviewed-by: mlugg <mlugg@noreply.codeberg.org>
2025-12-06 08:32:25 +01:00
Alex Rønne Petersen
1e616096d4
build: bump test-zigc max_rss to 767_483_904 on x86_64-linux 2025-12-06 01:51:01 +01:00
Matthew Lugg
4ce7b57e86 std.heap: rework c_allocator
The main goal here was to avoid allocating padding and header space if
`malloc` already guarantees the alignment we need via `max_align_t`.
Previously, the compiler was using `std.heap.raw_c_allocator` as its GPA
in some cases depending on `std.c.max_align_t`, but that's pretty
fragile (it meant we had to encode our alignment requirements into
`src/main.zig`!). Perhaps more importantly, that solution is
unnecessarily restrictive: since Zig's `Allocator` API passes the
`Alignment` not only to `alloc`, but also to `free` etc, we are able to
use a different strategy depending on its value. So `c_allocator` can
simply compare the requested align to `Alignment.of(std.c.max_align_t)`,
and use a raw `malloc` call (no header needed!) if it will guarantee a
suitable alignment (which, in practice, will be true the vast majority
of the time).

So in short, this makes `std.heap.c_allocator` more memory efficient,
and probably removes any incentive to use `std.heap.raw_c_allocator`.

I also refactored the `c_allocator` implementation while doing this,
just to neaten things up a little.
2025-12-06 00:16:33 +01:00
Matthew Lugg
ea94ac52c5
std.debug: skip manage resources correctly with cbe 2025-12-05 15:10:58 +01:00
Adrià Arrufat
02c5f05e2f std: replace usages of std.mem.indexOf with std.mem.find 2025-12-05 14:31:27 +01:00
Adrià Arrufat
1a420a8dca std.ascii: rename indexOf functions to find
This aligns with the recent changes in std.mem.find
2025-12-05 14:31:27 +01:00
Aidan Welch
032e3c9254 std.Io.Timestamp: when creating a Clock.Timestamp actually set .raw instead of the non-existant .nanoseconds 2025-12-05 14:14:01 +01:00
Luna Schwalbe
adc5a39de2 Change github links to codeberg 2025-12-05 14:12:39 +01:00
Loris Cro
58e3c2cefd make Io.net.sendMany compile 2025-12-05 11:50:04 +01:00
Alex Rønne Petersen
d22231c039
Compilation: track indirect file system inputs from clang's depfile
Co-authored-by: Matthew Lugg <mlugg@mlugg.co.uk>
2025-12-05 11:22:10 +01:00
Alex Rønne Petersen
38415911c1
compiler: handle -Xlinker args similarly to -Wl args 2025-12-05 11:04:51 +01:00
Alex Rønne Petersen
34f88722cd
compiler: support --dependency-file linker option
closes https://github.com/ziglang/zig/issues/22213
2025-12-05 11:04:48 +01:00
Alex Rønne Petersen
4724774433
ci: apply workaround for #22213 to x86_64-linux scripts
This should be reverted on the next CI tarballs update.
2025-12-05 07:32:43 +01:00
Alex Rønne Petersen
c166bb36f6
ci: reduce x86_64-linux timeouts
These excessive timeouts should no longer be necessary with the recent tuning of
job capacity and maxrss on these machines.
2025-12-04 20:52:34 +01:00
Alex Rønne Petersen
78cba86928
ci: set maxrss from $ZSF_MAX_RSS if provided by the runner
All of our runners now define this. When running a CI script locally, this will
not be set, so we default to 0, aka "all available system memory".
2025-12-04 20:06:48 +01:00
Alex Rønne Petersen
2728eb5d5e
build: adjust max_rss on a per-CI-host basis
This avoids pessimizing concurrency on all machines due to e.g. the macOS
machine having high memory usage across the board due to 16K page size.

This also adds max_rss to test-unit and test-c-abi since those tend to eat a
decent chunk of memory too.
2025-12-04 20:06:12 +01:00
unplanned
688af04725 math.big: stronger asserts to reduce risks of aliasing 2025-12-04 10:28:42 +01:00
unplanned
73e82332d0 big.Mutable.setString optimization and simplification 2025-12-04 10:28:31 +01:00
Alex Rønne Petersen
44543800a5
std.process.Child: enable rusage collection for dragonfly, netbsd, openbsd 2025-12-04 03:46:36 +01:00
Alex Rønne Petersen
2659fadb95
std.c: add rusage for dragonfly, netbsd, openbsd 2025-12-04 03:46:36 +01:00
Alex Rønne Petersen
9eed87f93e
std.process.Child: enable rusage collection for freebsd, illumos, serenity 2025-12-04 03:46:36 +01:00
Alex Rønne Petersen
e270c97ed1
ci: don't skip release mode tests on x86_64-windows-debug
pulsar is much faster than george so we don't need to do this anymore.
2025-12-04 03:46:36 +01:00
Alex Rønne Petersen
c21ce53494
ci: skip spirv and wasm tests on x86_64-freebsd
These are already built and run on x86_64-linux.
2025-12-04 03:46:36 +01:00
Alex Rønne Petersen
e2a9e568b4
build: add -Dskip-spirv and -Dskip-wasm options 2025-12-04 03:46:35 +01:00
Alex Rønne Petersen
ad9a5187ac
build: add some missing darwin tags 2025-12-04 03:46:35 +01:00
unplanned
c6a1444864 std.math.big.int.int_test: replace mem.eql by expectEqualSlices 2025-12-04 01:12:50 +01:00
unplanned
ded4e12559 big.Const.dump: fixed error 2025-12-04 01:12:34 +01:00
jedisct1
d73fbcc3ae Merge pull request 'Argon2: use the std.Io interface' (#30084) from jedisct1/zig:argon2 into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30084
2025-12-03 12:18:09 +01:00
Zihad
cb115cf73a std.process.ArgIteratorWasi: fix no-args deinit 2025-12-03 08:35:24 +01:00
Alex Rønne Petersen
be9649f4ea
ci: set a sensible maxrss in x86_64-windows scripts 2025-12-03 00:24:58 +01:00
Frank Denis
6fe95c28cf Argon2: use the std.Io interface
Also reduce the memory required by tests.

4GB for every test is way too much and doesn't provide much benefits
in testing the algorithms.
2025-12-02 23:03:52 +01:00
Andrew Kelley
52ad126bb4 Merge pull request 'std.Io.Threaded: rework cancellation' (#30033) from cancellation into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30033
2025-12-02 17:58:29 +01:00
Andrew Kelley
bb3f56d5d5 std.Io.Threaded: separate out ECANCELED handling again
If ECANCELED occurs, it's from pthread_cancel which will *permanently*
set that thread to be in a "canceling" state, which means the cancel
cannot be ignored. That means it cannot be retried, like EINTR. It must
be acknowledged.
2025-12-01 19:17:52 -08:00
Andrew Kelley
cf82064ebc std.Io.Threaded: don't use pthread_cancel with musl
It doesn't support setting the "canceled" status to false, so once a
thread has been canceled, all operations on the thread start permanently
failing.
2025-12-01 19:17:52 -08:00
Andrew Kelley
bf0ffc45b9 std.Io.Threaded: musl: handle ECANCELED same as EINTR
Otherwise the pthread_cancel can affect unrelated tasks.
2025-12-01 19:17:52 -08:00
Andrew Kelley
54a84964f8 std.os.linux: SIG enum is non-exhaustive 2025-12-01 19:17:52 -08:00
Andrew Kelley
57f5de5b77 std.Io.Threaded: use the correct mmsghdr struct 2025-12-01 19:17:52 -08:00
Andrew Kelley
103467fa6c std.Io.Threaded: make is_musl linux-only 2025-12-01 19:17:52 -08:00
David Rubin
85053a6a36 link.Elf: implement aarch64 relocation 2025-12-01 19:17:52 -08:00
Andrew Kelley
c4f5dda135 std.Io.Threaded: re-introduce retry logic behind config 2025-12-01 19:17:52 -08:00
Andrew Kelley
de87bad4c3 std.Io.Threaded: don't solve the cancel race after all
Unfortunately, trying again until the cancellation request is
acknowledged has been observed to incur a large amount of overhead,
and usually strong cancellation guarantees are not needed, so the
race condition is not handled here. Users who want to avoid this
have this menu of options instead:
* Use no libc, in which case Zig std lib can avoid the race (tracking
  issue: https://codeberg.org/ziglang/zig/issues/30049)
* Use musl libc
* Use `std.Io.Evented`. But this is not implemented yet. Tracked by
  - https://codeberg.org/ziglang/zig/issues/30050
  - https://codeberg.org/ziglang/zig/issues/30051

glibc + threaded is the only problematic combination.
2025-12-01 19:17:52 -08:00
Andrew Kelley
144206856e std.Io.Threaded: fix compilation for riscv32-linux 2025-12-01 19:17:52 -08:00
Andrew Kelley
9e981c3ae5 std.os.linux: delete unnecessary @compileError
Without this, it already fails to compile with a sufficiently helpful
error message.
2025-12-01 19:17:52 -08:00
Andrew Kelley
39ac40209b std.Io.Threaded: use musl's beautiful pthread_cancel semantics 2025-12-01 19:17:52 -08:00
Andrew Kelley
d60760d61e std.Io.Threaded: tune requestCancel
On a heavily loaded Linux 6.17.5, I observed a maximum of 20 attempts
not acknowledged before the timeout (including exponential backoff) was
sufficient, despite the heavy load.

The time wasted here sleeping is mitigated by the fact that, later on,
the system will likely wait for the canceled task, causing it to
indefinitely yield until the canceled task finishes, and the task must
acknowledge the cancel before it proceeds to that point.
2025-12-01 19:17:52 -08:00
Andrew Kelley
29e418cbfb std.Io.Threaded: fix the cancellation race
Now, before a syscall is entered, beginSyscall is called, which may
return error.Canceled. After syscall returns, whether error or success,
endSyscall is called. If the syscall returns EINTR then checkCancel is
called.

`cancelRequested` is removed from the std.Io VTable for now, with plans
to replace it with a more powerful API that allows protection against
cancellation requests.

closes #25751
2025-12-01 19:17:52 -08:00
rpkak
95f93a0b28 std.zig.Ast: count addrspace tokens correctly
Before this PR this

```zig
const namespace = struct {
    extern const num: u8 addrspace(.generic);
};
// comment
```

got formatted to this

```zig
const namespace = struct {
    extern const num: u8 addrspace(.generic);
(
```

Co-authored-by: rpkak <rpkak@noreply.codeberg.org>
Co-committed-by: rpkak <rpkak@noreply.codeberg.org>
2025-12-01 12:56:11 +01:00
jedisct1
1d1e2b7780 Merge pull request 'std.crypto.aes: expose the inverse MixColumns operation' (#30052) from jedisct1/zig:invmixcolumns into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30052
2025-12-01 11:16:26 +01:00
fn ⌃ ⌥
bfe3317059 Return a usize from @abs if given an isize
Also:
- `c_ushort` for `c_short`
- `c_uint` for `c_int`
- `c_ulong` for `c_long`
- `c_ulonglong` for `c_longlong`
2025-11-29 21:09:08 +01:00
mlugg
44e99edd7a Merge pull request 'Sema: initialize OPV comptime allocs correctly' (#30043) from reify-empty-struct into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30043
2025-11-29 20:21:30 +01:00
Nikolay Govorov
a0289d0cce std.posix.accept: handle non-listening socket EINVAL 2025-11-29 19:57:59 +01:00
Frank Denis
5e00a0c9b5 std.crypto.aes: expose the inverse MixColumns operation
The inverse MixColumns operation is already used internally for
AES decryption, but it wasn’t exposed in the public API because
it didn’t seem necessary at the time.

Since then, several new AES-based block ciphers and permutations
(such as Vistrutah and Areion) have been developed, and they require
this operation to be implementable in Zig.
Since then, new interesting AES-based block ciphers and permutations
(Vistrutah, Areion, etc). have been invented, and require that
operation to be implementable in Zig.
2025-11-29 19:25:22 +01:00
Alex Rønne Petersen
7d9ad992ab
issue templates: update issue labels to match the actual org labels 2025-11-29 19:02:04 +01:00
Matthew Lugg
8f5db19791
Sema: initialize OPV comptime allocs correctly
This was caused a `[0]std.builtin.Type.StructField.Attributes` to be
considered `undefined`, even though that type is OPV so should prefer
its OPV `.{}` over `undefined`.

Resolves: #30039
2025-11-29 11:55:36 +00:00
Matthew Lugg
e52232cd57
print_zir: fix typo 2025-11-29 11:55:26 +00:00
Alex Rønne Petersen
a38220376e
Revert "ci: apply workaround for #22213 to x86_64-linux scripts"
This reverts commit a8f9b5dc06.
2025-11-28 22:57:33 +01:00
Alex Rønne Petersen
a8f9b5dc06
ci: apply workaround for #22213 to x86_64-linux scripts 2025-11-28 22:06:46 +01:00
Alex Rønne Petersen
713716770e
README: github -> codeberg for some links 2025-11-28 18:29:05 +01:00
Andrew Kelley
e19c61a16e issue templates: use anchors in URLs 2025-11-28 07:38:24 -08:00
jedisct1
e6d19a07d2 Merge pull request 'std.crypto: add hybrid post-quantum/traditional key encapsulation' (#30010) from jedisct1/zig:hybridkem into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30010
2025-11-28 09:10:20 +01:00
Linus Groh
39fa831947 std: Remove a handful of things deprecated during the 0.15 release cycle
- std.Build.Step.Compile.root_module mutators -> std.Build.Module
- std.Build.Step.Compile.want_lto -> std.Build.Step.Compile.lto
- std.Build.Step.ConfigHeader.getOutput -> std.Build.Step.ConfigHeader.getOutputFile
- std.Build.Step.Run.max_stdio_size -> std.Build.Step.Run.stdio_limit
- std.enums.nameCast -> @field(E, tag_name) / @field(E, @tagName(tag))
- std.Io.tty.detectConfig -> std.Io.tty.Config.detect
- std.mem.trimLeft -> std.mem.trimStart
- std.mem.trimRight -> std.mem.trimEnd
- std.meta.intToEnum -> std.enums.fromInt
- std.meta.TagPayload -> @FieldType(U, @tagName(tag))
- std.meta.TagPayloadByName -> @FieldType(U, tag_name)
2025-11-27 20:17:04 +00:00
Linus Groh
8545836a4d Remove legacy asm clobbers syntax handling 2025-11-27 20:16:03 +00:00
Alex Rønne Petersen
fbafbd4262
ci: pin actions/checkout to current ziglang/checkout@HEAD 2025-11-27 21:07:58 +01:00
Purple
7af412b6b4 Update std.zig.system.NativePaths.detect to support some more flags on NixOS like environment.
Basically detect `-idirafter` flag in `NIX_CFLAGS_COMPILE` and treat it like `-isystem`, also detect `NIX_CFLAGS_LINK` environment variable and treat it like the `NIX_LDFLAGS` .

Reference:
74eefb4210/pkgs/build-support/build-fhsenv-chroot/env.nix (L83)
2025-11-27 20:49:55 +01:00
Andrew Kelley
e427ba9cd5 std.sort.partitionPoint: faster implementation (#30005)
Migrated from https://github.com/ziglang/zig/pull/21419

Co-authored-by: Jonathan Hallstrom <lmj.hallstrom@gmail.com>
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30005
2025-11-27 20:48:54 +01:00
Nico Elbers
03a3269d48
Optimize Reader.takeLeb128
Rewrite `Reader.takeLeb128` to not use `takeMultipleOf7Leb128` and
instead:
 * Use byte aligned integers
 * Turn the main reading loop into an inlined loop of static length
 * Special case small integers (<= 7 bits)

Notably signed and unsigned 32 bit integers have 5x to 12x(!)
performance improvement.

Outside of that:
For u8, u16 and u64 performance increases ~1.5x to ~6x
For i8, i16 and i64 performance increases ~1.5x to ~3.5x

For integers with bit multiples of 7 performance is roughly equal within the
margin or error.

Also expand on test coverage

Microbenchmark: https://zigbin.io/242cb1
2025-11-27 15:46:35 +01:00
Nico Elbers
ceba9572ef
Optimize Writer.writeLeb128
Rewrite `writeLeb128` to no longer use `writeMultipleOf7Leb128` and instead:
 * Make use of byte aligned ints
 * Special case small numbers (fitting inside 7 bits)

Amongst u8, u16, u32 and u64 performance gains are between ~1.5x and ~2x
Amongst i8, i16, i32 ane i64 perfromance gains are between ~2x and >4x

Additinally add test coverage for written encodings

Microbenchmark: https://zigbin.io/7ed5fe
2025-11-27 15:46:16 +01:00
Frank Denis
ca96d853ff std.crypto: add hybrid post-quantum/traditional key encapsulation
Hybrid KEMs combine a post-quantum secure KEM with a traditional
elliptic curve Diffie-Hellman key exchange.

The hybrid construction provides security against both classical and quantum
adversaries: even if one component is broken, the combined scheme remains
secure as long as the other component holds.

The implementation follows the IETF CFRG draft specification for concrete
hybrid KEMs:

https://datatracker.ietf.org/doc/draft-irtf-cfrg-concrete-hybrid-kems/
2025-11-27 12:10:17 +01:00
Frank Denis
854774d468 http.requestHasBody: a PUT response can have a body
HEAD/TRACE are bodyless, but PUT responses are body-capable
per RFC 7231.
2025-11-26 20:08:14 -08:00
Jacob Young
a1827d5977 x86_64: fix abi of a struct that partially fits in registers
Closes #26035
2025-11-27 05:05:59 +01: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 b34a13da38.

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 d54fbc0123.

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 4b593a6c24.

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

This reverts commit ee4df4ad3e.

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

This reverts commit bf9082518c.

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

This reverts commit 95c76b1b4a.
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 2cdafe9106.
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 0f71a9291a 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 16185f66f1.

Which was fixed by d000574380.

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 16c18b835e.

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 (dba1bf9353), 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 d53cc5e5b2
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 c55e83eab1.

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 6de339d5d3 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 a73f246b29.
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 fcfdf99122.

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 69007f0961 but accidentally reverted in 7bf740ee71
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 1d764c1fdf

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 1d764c1fdf

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 27aba2d776.

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 95bdb0c1c6 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 d9cd4d0876.

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: 0700ec35bd
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 ed7ff0b693.
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
ed7ff0b693.
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
41e1cd185b and then removed in
50a336fff8, but brought back in
711bf55eaa for Decl in the compiler
frontend, and then the last reference to it was eliminated in
548a087faf 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 5ce8e9325b
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 ac42eaaadd, reversing
changes made to 9fa2394f8c.

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 6b6e336e07 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 f4ed35f800.

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 530cc2c111.

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 dd1de18f96.

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 b4fd57a9c1.

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 092352ec63
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 f2a3ac7c05.

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
8290 changed files with 791661 additions and 476164 deletions

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/#no-language-proposals
- 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/#strict-no-llm-no-ai-policy

303
.forgejo/workflows/ci.yaml Normal file
View file

@ -0,0 +1,303 @@
name: ci
on:
pull_request:
push:
branches:
- master
workflow_dispatch:
# This cancels older workflow runs on pull requests while ensuring that there
# are no concurrency limits on pushes and manual workflow dispatches.
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
permissions:
contents: read
jobs:
aarch64-freebsd-debug:
runs-on: [self-hosted, aarch64-freebsd]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/aarch64-freebsd-debug.sh
timeout-minutes: 300
aarch64-freebsd-release:
runs-on: [self-hosted, aarch64-freebsd]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/aarch64-freebsd-release.sh
timeout-minutes: 240
aarch64-linux-debug:
runs-on: [self-hosted, aarch64-linux]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
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: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/aarch64-linux-release.sh
timeout-minutes: 120
aarch64-netbsd-debug:
runs-on: [self-hosted, aarch64-netbsd]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/aarch64-netbsd-debug.sh
timeout-minutes: 300
aarch64-netbsd-release:
runs-on: [self-hosted, aarch64-netbsd]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/aarch64-netbsd-release.sh
timeout-minutes: 240
aarch64-macos-debug:
runs-on: [self-hosted, aarch64-macos]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
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: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
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: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
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: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/loongarch64-linux-release.sh
timeout-minutes: 180
powerpc64le-linux-debug:
runs-on: [self-hosted, powerpc64le-linux]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/powerpc64le-linux-debug.sh
timeout-minutes: 360
powerpc64le-linux-release:
runs-on: [self-hosted, powerpc64le-linux]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/powerpc64le-linux-release.sh
timeout-minutes: 240
riscv64-linux-debug:
if: github.event_name != 'pull_request'
runs-on: [self-hosted, riscv64-linux]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/riscv64-linux-debug.sh
timeout-minutes: 660
riscv64-linux-release:
if: github.event_name != 'pull_request'
runs-on: [self-hosted, riscv64-linux]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/riscv64-linux-release.sh
timeout-minutes: 540
s390x-linux-debug:
runs-on: [self-hosted, s390x-linux]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/s390x-linux-debug.sh
timeout-minutes: 360
s390x-linux-release:
runs-on: [self-hosted, s390x-linux]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/s390x-linux-release.sh
timeout-minutes: 300
x86_64-freebsd-debug:
runs-on: [self-hosted, x86_64-freebsd]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
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: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
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: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/x86_64-linux-debug.sh
timeout-minutes: 180
x86_64-linux-debug-llvm:
runs-on: [self-hosted, x86_64-linux]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/x86_64-linux-debug-llvm.sh
timeout-minutes: 360
x86_64-linux-release:
runs-on: [self-hosted, x86_64-linux]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/x86_64-linux-release.sh
timeout-minutes: 360
x86_64-netbsd-debug:
runs-on: [self-hosted, x86_64-netbsd]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/x86_64-netbsd-debug.sh
timeout-minutes: 120
x86_64-netbsd-release:
runs-on: [self-hosted, x86_64-netbsd]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/x86_64-netbsd-release.sh
timeout-minutes: 120
x86_64-openbsd-debug:
runs-on: [self-hosted, x86_64-openbsd]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/x86_64-openbsd-debug.sh
timeout-minutes: 120
x86_64-openbsd-release:
runs-on: [self-hosted, x86_64-openbsd]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/x86_64-openbsd-release.sh
timeout-minutes: 120
x86_64-windows-debug:
runs-on: [self-hosted, x86_64-windows]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
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: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: ci/x86_64-windows-release.ps1
timeout-minutes: 180

2
.gitattributes vendored
View file

@ -15,6 +15,8 @@ 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

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,10 +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
- name: Copilot and Other LLMs
about: Please do not use GitHub Copilot or any other LLM to write an issue.
url: https://github.com/ziglang/zig/wiki/Writing-Issues-with-Copilot-and-Other-LLMs

View file

@ -1,35 +0,0 @@
name: ci-pr-riscv64-linux
on:
pull_request:
types:
- labeled
- opened
- reopened
- synchronize
- unlabeled
concurrency:
# Cancels pending runs when a PR gets updated.
group: riscv64-linux-${{ github.head_ref || github.run_id }}-${{ github.actor }}
cancel-in-progress: true
permissions:
# Sets permission policy for `GITHUB_TOKEN`
contents: read
jobs:
riscv64-linux-debug:
if: contains(github.event.pull_request.labels.*.name, 'ci-riscv64-linux')
timeout-minutes: 420
runs-on: [self-hosted, Linux, riscv64]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Test
run: sh ci/riscv64-linux-debug.sh
riscv64-linux-release:
if: contains(github.event.pull_request.labels.*.name, 'ci-riscv64-linux')
timeout-minutes: 420
runs-on: [self-hosted, Linux, riscv64]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Test
run: sh ci/riscv64-linux-release.sh

View file

@ -1,117 +0,0 @@
name: ci
on:
pull_request:
push:
branches:
- master
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: 540
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-debug-llvm:
timeout-minutes: 540
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-llvm.sh
x86_64-linux-release:
timeout-minutes: 540
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:
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:
runs-on: [self-hosted, Linux, aarch64]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Test
run: sh ci/aarch64-linux-release.sh
riscv64-linux-debug:
if: github.event_name == 'push'
timeout-minutes: 420
runs-on: [self-hosted, Linux, riscv64]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Test
run: sh ci/riscv64-linux-debug.sh
riscv64-linux-release:
if: github.event_name == 'push'
timeout-minutes: 420
runs-on: [self-hosted, Linux, riscv64]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Test
run: sh ci/riscv64-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

@ -2,10 +2,16 @@ Adam Goertz <adambgoertz@gmail.com>
Ali Chraghi <alichraghi@proton.me> <alichraghi@pm.me>
Andrea Orru <andrea@orru.io> <andreaorru1991@gmail.com>
Andrew Kelley <andrew@ziglang.org> <superjoe30@gmail.com>
Andrew Kelley <andrew@ziglang.org> <andrewrk@noreply.codeberg.org>
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>
@ -17,6 +23,7 @@ Felix "xq" Queißner <xq@random-projects.net> <git@masterq32.de>
Felix "xq" Queißner <xq@random-projects.net> <git@mq32.de>
Felix "xq" Queißner <xq@random-projects.net> <git@random-projects.net>
Frank Denis <124872+jedisct1@users.noreply.github.com> <github@pureftpd.org>
Frank Denis <124872+jedisct1@users.noreply.github.com> <jedisct1@noreply.codeberg.org>
Garrett Beck <garrettlennoxbeck@gmail.com> <138411610+garrettlennoxbeck@users.noreply.github.com>
Gaëtan S <blaxoujunior@gmail.com>
GalaxyShard <dominic.adragna@byteroach.com>
@ -26,6 +33,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 +46,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>
@ -48,6 +57,7 @@ Marc Tiehuis <marc@tiehu.is> <marctiehuis@gmail.com>
Mason Remaley <mason@anthropicstudios.com>
Mason Remaley <mason@anthropicstudios.com> <MasonRemaley@users.noreply.github.com>
Matthew Lugg <mlugg@mlugg.co.uk>
Matthew Lugg <mlugg@mlugg.co.uk> <mlugg@noreply.codeberg.org>
Meghan Denny <hello@nektro.net>
Meghan Denny <hello@nektro.net> <meghan@bun.sh>
Michael Bartnett <michael.bartnett@gmail.com> <michaelbartnett@users.noreply.github.com>
@ -69,6 +79,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 15)
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.")
@ -133,9 +133,9 @@ else()
set(ZIG_SYSTEM_LIBCXX "stdc++" CACHE STRING "system libcxx name for build.zig")
endif()
find_package(llvm 20)
find_package(clang 20)
find_package(lld 20)
find_package(llvm 21)
find_package(clang 21)
find_package(lld 21)
if(ZIG_STATIC_ZLIB)
if (MSVC)
@ -197,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
@ -206,183 +205,6 @@ set(ZIG_CPP_SOURCES
set(ZIG_STAGE2_SOURCES
"${ZIG_CONFIG_ZIG_OUT}"
lib/compiler_rt.zig
lib/compiler_rt/absv.zig
lib/compiler_rt/absvdi2.zig
lib/compiler_rt/absvsi2.zig
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/addxf3.zig
lib/compiler_rt/arm.zig
lib/compiler_rt/atomics.zig
lib/compiler_rt/aulldiv.zig
lib/compiler_rt/aullrem.zig
lib/compiler_rt/bswap.zig
lib/compiler_rt/ceil.zig
lib/compiler_rt/clear_cache.zig
lib/compiler_rt/cmp.zig
lib/compiler_rt/cmpdf2.zig
lib/compiler_rt/cmpsf2.zig
lib/compiler_rt/cmptf2.zig
lib/compiler_rt/cmpxf2.zig
lib/compiler_rt/common.zig
lib/compiler_rt/comparef.zig
lib/compiler_rt/cos.zig
lib/compiler_rt/count0bits.zig
lib/compiler_rt/divdf3.zig
lib/compiler_rt/divsf3.zig
lib/compiler_rt/divtf3.zig
lib/compiler_rt/divti3.zig
lib/compiler_rt/divxf3.zig
lib/compiler_rt/emutls.zig
lib/compiler_rt/exp.zig
lib/compiler_rt/exp2.zig
lib/compiler_rt/extenddftf2.zig
lib/compiler_rt/extenddfxf2.zig
lib/compiler_rt/extendf.zig
lib/compiler_rt/extendhfsf2.zig
lib/compiler_rt/extendhftf2.zig
lib/compiler_rt/extendhfxf2.zig
lib/compiler_rt/extendsfdf2.zig
lib/compiler_rt/extendsftf2.zig
lib/compiler_rt/extendsfxf2.zig
lib/compiler_rt/extendxftf2.zig
lib/compiler_rt/fabs.zig
lib/compiler_rt/fixdfdi.zig
lib/compiler_rt/fixdfsi.zig
lib/compiler_rt/fixdfti.zig
lib/compiler_rt/fixhfdi.zig
lib/compiler_rt/fixhfsi.zig
lib/compiler_rt/fixhfti.zig
lib/compiler_rt/fixsfdi.zig
lib/compiler_rt/fixsfsi.zig
lib/compiler_rt/fixsfti.zig
lib/compiler_rt/fixtfdi.zig
lib/compiler_rt/fixtfsi.zig
lib/compiler_rt/fixtfti.zig
lib/compiler_rt/fixunsdfdi.zig
lib/compiler_rt/fixunsdfsi.zig
lib/compiler_rt/fixunsdfti.zig
lib/compiler_rt/fixunshfdi.zig
lib/compiler_rt/fixunshfsi.zig
lib/compiler_rt/fixunshfti.zig
lib/compiler_rt/fixunssfdi.zig
lib/compiler_rt/fixunssfsi.zig
lib/compiler_rt/fixunssfti.zig
lib/compiler_rt/fixunstfdi.zig
lib/compiler_rt/fixunstfsi.zig
lib/compiler_rt/fixunstfti.zig
lib/compiler_rt/fixunsxfdi.zig
lib/compiler_rt/fixunsxfsi.zig
lib/compiler_rt/fixunsxfti.zig
lib/compiler_rt/fixxfdi.zig
lib/compiler_rt/fixxfsi.zig
lib/compiler_rt/fixxfti.zig
lib/compiler_rt/float_from_int.zig
lib/compiler_rt/floatdidf.zig
lib/compiler_rt/floatdihf.zig
lib/compiler_rt/floatdisf.zig
lib/compiler_rt/floatditf.zig
lib/compiler_rt/floatdixf.zig
lib/compiler_rt/floatsidf.zig
lib/compiler_rt/floatsihf.zig
lib/compiler_rt/floatsisf.zig
lib/compiler_rt/floatsitf.zig
lib/compiler_rt/floatsixf.zig
lib/compiler_rt/floattidf.zig
lib/compiler_rt/floattihf.zig
lib/compiler_rt/floattisf.zig
lib/compiler_rt/floattitf.zig
lib/compiler_rt/floattixf.zig
lib/compiler_rt/floatundidf.zig
lib/compiler_rt/floatundihf.zig
lib/compiler_rt/floatundisf.zig
lib/compiler_rt/floatunditf.zig
lib/compiler_rt/floatundixf.zig
lib/compiler_rt/floatunsidf.zig
lib/compiler_rt/floatunsihf.zig
lib/compiler_rt/floatunsisf.zig
lib/compiler_rt/floatunsitf.zig
lib/compiler_rt/floatunsixf.zig
lib/compiler_rt/floatuntidf.zig
lib/compiler_rt/floatuntihf.zig
lib/compiler_rt/floatuntisf.zig
lib/compiler_rt/floatuntitf.zig
lib/compiler_rt/floatuntixf.zig
lib/compiler_rt/floor.zig
lib/compiler_rt/fma.zig
lib/compiler_rt/fmax.zig
lib/compiler_rt/fmin.zig
lib/compiler_rt/fmod.zig
lib/compiler_rt/gedf2.zig
lib/compiler_rt/gesf2.zig
lib/compiler_rt/getf2.zig
lib/compiler_rt/gexf2.zig
lib/compiler_rt/int.zig
lib/compiler_rt/int_from_float.zig
lib/compiler_rt/log.zig
lib/compiler_rt/log10.zig
lib/compiler_rt/log2.zig
lib/compiler_rt/modti3.zig
lib/compiler_rt/mulXi3.zig
lib/compiler_rt/muldf3.zig
lib/compiler_rt/mulf3.zig
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
lib/compiler_rt/negsf2.zig
lib/compiler_rt/negtf2.zig
lib/compiler_rt/negv.zig
lib/compiler_rt/negxf2.zig
lib/compiler_rt/os_version_check.zig
lib/compiler_rt/parity.zig
lib/compiler_rt/popcount.zig
lib/compiler_rt/rem_pio2.zig
lib/compiler_rt/rem_pio2_large.zig
lib/compiler_rt/rem_pio2f.zig
lib/compiler_rt/round.zig
lib/compiler_rt/shift.zig
lib/compiler_rt/sin.zig
lib/compiler_rt/sincos.zig
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
lib/compiler_rt/trunc.zig
lib/compiler_rt/truncdfhf2.zig
lib/compiler_rt/truncdfsf2.zig
lib/compiler_rt/truncf.zig
lib/compiler_rt/truncsfhf2.zig
lib/compiler_rt/trunctfdf2.zig
lib/compiler_rt/trunctfhf2.zig
lib/compiler_rt/trunctfsf2.zig
lib/compiler_rt/trunctfxf2.zig
lib/compiler_rt/truncxfdf2.zig
lib/compiler_rt/truncxfhf2.zig
lib/compiler_rt/truncxfsf2.zig
lib/compiler_rt/udivmod.zig
lib/compiler_rt/udivmodei4.zig
lib/compiler_rt/udivmodti4.zig
lib/compiler_rt/udivti3.zig
lib/compiler_rt/umodti3.zig
lib/compiler_rt/unorddf2.zig
lib/compiler_rt/unordsf2.zig
lib/compiler_rt/unordtf2.zig
lib/std/BitStack.zig
lib/std/Build.zig
lib/std/Build/Cache.zig
@ -411,11 +233,6 @@ set(ZIG_STAGE2_SOURCES
lib/std/Target/wasm.zig
lib/std/Target/x86.zig
lib/std/Thread.zig
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
lib/std/ascii.zig
@ -440,17 +257,13 @@ set(ZIG_STAGE2_SOURCES
lib/std/fmt.zig
lib/std/fmt/parse_float.zig
lib/std/fs.zig
lib/std/fs/AtomicFile.zig
lib/std/fs/Dir.zig
lib/std/fs/File.zig
lib/std/fs/get_app_data_dir.zig
lib/std/fs/path.zig
lib/std/hash.zig
lib/std/hash/auto_hash.zig
lib/std/hash/wyhash.zig
lib/std/hash_map.zig
lib/std/heap.zig
lib/std/heap/arena_allocator.zig
lib/std/heap/ArenaAllocator.zig
lib/std/json.zig
lib/std/leb128.zig
lib/std/log.zig
@ -502,7 +315,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/string_literal.zig
lib/std/zig/system.zig
lib/std/zig/system/NativePaths.zig
@ -522,7 +334,6 @@ set(ZIG_STAGE2_SOURCES
src/Builtin.zig
src/Compilation.zig
src/Compilation/Config.zig
src/DarwinPosixSpawn.zig
src/InternPool.zig
src/Package.zig
src/Package/Fetch.zig
@ -537,7 +348,6 @@ set(ZIG_STAGE2_SOURCES
src/Value.zig
src/Zcu.zig
src/Zcu/PerThread.zig
src/clang.zig
src/clang_options.zig
src/clang_options_data.zig
src/codegen.zig
@ -558,6 +368,7 @@ set(ZIG_STAGE2_SOURCES
src/libs/freebsd.zig
src/libs/glibc.zig
src/libs/netbsd.zig
src/libs/openbsd.zig
src/introspect.zig
src/libs/libcxx.zig
src/libs/libtsan.zig
@ -583,7 +394,7 @@ set(ZIG_STAGE2_SOURCES
src/link/Elf/relocatable.zig
src/link/Elf/relocation.zig
src/link/Elf/synthetic_sections.zig
src/link/Goff.zig
src/link/Elf2.zig
src/link/LdScript.zig
src/link/Lld.zig
src/link/MachO.zig
@ -612,13 +423,13 @@ set(ZIG_STAGE2_SOURCES
src/link/MachO/synthetic.zig
src/link/MachO/Thunk.zig
src/link/MachO/uuid.zig
src/link/MappedFile.zig
src/link/Queue.zig
src/link/StringTable.zig
src/link/Wasm.zig
src/link/Wasm/Archive.zig
src/link/Wasm/Flush.zig
src/link/Wasm/Object.zig
src/link/Xcoff.zig
src/link/aarch64.zig
src/link/riscv.zig
src/link/table_section.zig
@ -639,7 +450,6 @@ set(ZIG_STAGE2_SOURCES
src/register_manager.zig
src/target.zig
src/tracy.zig
src/translate_c.zig
src/libs/wasi_libc.zig
)
@ -737,20 +547,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")
@ -772,15 +584,17 @@ if(ZIG_HOST_TARGET_ARCH MATCHES "^arm(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.")
@ -794,6 +608,11 @@ else()
set(ZIG_WASM2C_COMPILE_FLAGS "-std=c99 -O2")
set(ZIG1_COMPILE_FLAGS "-std=c99 -Os")
set(ZIG2_COMPILE_FLAGS "-std=c99 -O0 -fno-sanitize=undefined -fno-stack-protector")
# Must match the condition in build.zig.
if(ZIG_HOST_TARGET_ARCH MATCHES "^(arm|thumb)(eb)?$" OR ZIG_HOST_TARGET_ARCH MATCHES "^powerpc(64)?(le)?$")
set(ZIG1_COMPILE_FLAGS "${ZIG1_COMPILE_FLAGS} -ffunction-sections -fdata-sections")
set(ZIG2_COMPILE_FLAGS "${ZIG2_COMPILE_FLAGS} -ffunction-sections -fdata-sections")
endif()
if(APPLE)
set(ZIG2_LINK_FLAGS "-Wl,-stack_size,0x10000000")
elseif(MINGW)

731
README.md
View file

@ -20,8 +20,8 @@ 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)
* [install from a package manager](https://ziglang.org/learn/getting-started/#managers)
* [bootstrap zig for any target](https://codeberg.org/ziglang/zig-bootstrap)
A Zig installation is composed of two things:
@ -47,7 +47,10 @@ Ensure you have the required dependencies:
* CMake >= 3.15
* System C/C++ Toolchain
* LLVM, Clang, LLD development libraries == 20.x
* LLVM, Clang, LLD development libraries, version 21.x, compiled with the
same system C/C++ toolchain.
- If the system package manager lacks these libraries, or has them misconfigured,
see below for how to build them from source.
Then it is the standard CMake build process:
@ -58,9 +61,9 @@ 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.
Use `CMAKE_PREFIX_PATH` if needed to help CMake find LLVM.
This produces `stage3/bin/zig` which is the Zig compiler built by itself.
## Building from Source without LLVM
@ -76,35 +79,377 @@ This produces a `zig2` executable in the current working directory. This is a
[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 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 assembly files](https://github.com/ziglang/zig/issues/21169)
- 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
Even when built this way, Zig provides an LLVM backend that produces bitcode
files, which may be optimized and 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.
## Building from Source Using Prebuilt Zig
Dependencies:
* A recent prior build of Zig. The exact version required depends on how
recently breaking changes occurred. If the language or std lib changed too
much since this version, then this method of building from source will fail.
* LLVM, Clang, and LLD libraries built using Zig.
The easiest way to obtain both of these artifacts is to use
[zig-bootstrap](https://codeberg.org/ziglang/zig-bootstrap), which creates the
directory `out/zig-$target-$cpu` and `out/$target-$cpu`, to be used as
`$ZIG_PREFIX` and `$LLVM_PREFIX`, respectively, in the following command:
```
"$ZIG_PREFIX/zig" build \
-p stage3 \
--search-prefix "$LLVM_PREFIX" \
--zig-lib-dir "lib" \
-Dstatic-llvm
```
Where `$LLVM_PREFIX` is the path that contains, for example,
`include/llvm/Pass.h` and `lib/libLLVMCore.a`.
This produces `stage3/bin/zig`. See `zig build -h` to learn about the options
that can be passed such as `-Drelease`.
## Building from Source on Windows
### Option 1: Use the Windows Zig Compiler Dev Kit
This one has the benefit that LLVM, LLD, and Clang are built in Release mode,
while your Zig build has the option to be a Debug build. It also works
completely independently from MSVC so you don't need it to be installed.
Determine the URL by
[looking at the CI script](https://codeberg.org/ziglang/zig/src/branch/master/ci/x86_64-windows-debug.ps1#L1-L4).
It will look something like this (replace `$VERSION` with the one you see by
following the above link):
```
https://ziglang.org/deps/zig+llvm+lld+clang-x86_64-windows-gnu-$VERSION.zip
```
This zip file contains:
* An older Zig installation.
* LLVM, LLD, and Clang libraries (.lib and .h files), version 16.0.1, built in Release mode.
* zlib (.lib and .h files), v1.2.13, built in Release mode
* zstd (.lib and .h files), v1.5.2, built in Release mode
#### Option 1a: CMake + [Ninja](https://ninja-build.org/)
Unzip the dev kit and then in cmd.exe in your Zig source checkout:
```bat
mkdir build
cd build
set DEVKIT=$DEVKIT
```
Replace `$DEVKIT` with the path to the folder that you unzipped after
downloading it from the link above. Make sure to use forward slashes (`/`) for
all path separators (otherwise CMake will try to interpret backslashes as
escapes and fail).
Then run:
```bat
cmake .. -GNinja -DCMAKE_PREFIX_PATH="%DEVKIT%" -DCMAKE_C_COMPILER="%DEVKIT%/bin/zig.exe;cc" -DCMAKE_CXX_COMPILER="%DEVKIT%/bin/zig.exe;c++" -DCMAKE_AR="%DEVKIT%/bin/zig.exe" -DZIG_AR_WORKAROUND=ON -DZIG_STATIC=ON -DZIG_USE_LLVM_CONFIG=OFF
```
* Append `-DCMAKE_BUILD_TYPE=Release` for a Release build.
* Append `-DZIG_NO_LIB=ON` to avoid having multiple copies of the lib/ folder.
Finally, run:
```bat
ninja install
```
You now have the `zig.exe` binary at `stage3\bin\zig.exe`.
#### Option 1b: zig build
Unzip the dev kit and then in cmd.exe in your Zig source checkout:
```bat
$DEVKIT\bin\zig.exe build -p stage3 --search-prefix $DEVKIT --zig-lib-dir lib -Dstatic-llvm -Duse-zig-libcxx -Dtarget=x86_64-windows-gnu
```
Replace `$DEVKIT` with the path to the folder that you unzipped after
downloading it from the link above.
Append `-Doptimize=ReleaseSafe` for a Release build.
**If you get an error building at this step**, it is most likely that the Zig
installation inside the dev kit is too old, and the dev kit needs to be
updated. In this case one more step is required:
1. [Download the latest master branch zip file](https://ziglang.org/download/#release-master).
2. Unzip, and try the above command again, replacing the path to zig.exe with
the path to the zig.exe you just extracted, and also replace the lib\zig
folder with the new contents.
You now have the `zig.exe` binary at `stage3\bin\zig.exe`.
### Option 2: Using CMake and Microsoft Visual Studio
This one has the benefit that changes to the language or build system won't
break your dev kit. This option can be used to upgrade a dev kit.
First, build LLVM, LLD, and Clang from source using CMake and Microsoft Visual
Studio (see below for detailed instructions).
Install [Build Tools for Visual Studio
2019](https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019).
Be sure to select "Desktop development with C++" when prompted.
* You must additionally check the optional component labeled **C++ ATL for
v142 build tools**.
Install [CMake](http://cmake.org).
Use [git](https://git-scm.com/) to clone the zig repository to a path with no spaces, e.g. `C:\Users\Andy\zig`.
Using the start menu, run **x64 Native Tools Command Prompt for VS 2019** and execute these commands, replacing `C:\Users\Andy` with the correct value.
```bat
mkdir C:\Users\Andy\zig\build-release
cd C:\Users\Andy\zig\build-release
"c:\Program Files\CMake\bin\cmake.exe" .. -Thost=x64 -G "Visual Studio 16 2019" -A x64 -DCMAKE_PREFIX_PATH=C:\Users\Andy\llvm+clang+lld-20.0.0-x86_64-windows-msvc-release-mt -DCMAKE_BUILD_TYPE=Release
msbuild -p:Configuration=Release INSTALL.vcxproj
```
You now have the `zig.exe` binary at `bin\zig.exe` and you can run the tests:
```bat
bin\zig.exe build test
```
This can take a long time.
Note: In case you get the error "llvm-config not found" (or similar), make sure
that you have **no** trailing slash (`/` or `\`) at the end of the
`-DCMAKE_PREFIX_PATH` value.
## Building LLVM, LLD, and Clang from Source
### Windows
Install [CMake](https://cmake.org/), version 3.20.0 or newer.
[Download LLVM, Clang, and LLD sources](https://releases.llvm.org/download.html#21.0.0)
The downloads from llvm lead to the github release pages, where the source's
will be listed as : `llvm-21.X.X.src.tar.xz`, `clang-21.X.X.src.tar.xz`,
`lld-21.X.X.src.tar.xz`. Unzip each to their own directory. Ensure no
directories have spaces in them. For example:
* `C:\Users\Andy\llvm-21.0.0.src`
* `C:\Users\Andy\clang-21.0.0.src`
* `C:\Users\Andy\lld-21.0.0.src`
Install [Build Tools for Visual Studio
2019](https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019).
Be sure to select "C++ build tools" when prompted.
* You **must** additionally check the optional component labeled **C++ ATL for
v142 build tools**. As this won't be supplied by a default installation of
Visual Studio.
* Full list of supported MSVC versions:
- 2017 (version 15.8) (unverified)
- 2019 (version 16.7)
Install [Python 3.9.4](https://www.python.org). Tick the box to add python to
your PATH environment variable.
#### LLVM
Using the start menu, run **x64 Native Tools Command Prompt for VS 2019** and execute these commands, replacing `C:\Users\Andy` with the correct value. Here is listed a brief explanation of each of the CMake parameters we pass when configuring the build
- `-Thost=x64` : Sets the windows toolset to use 64 bit mode.
- `-A x64` : Make the build target 64 bit .
- `-G "Visual Studio 16 2019"` : Specifies to generate a 2019 Visual Studio project, the best supported version.
- `-DCMAKE_INSTALL_PREFIX=""` : Path that llvm components will being installed into by the install project.
- `-DCMAKE_PREFIX_PATH=""` : Path that CMake will look into first when trying to locate dependencies, should be the same place as the install prefix. This will ensure that clang and lld will use your newly built llvm libraries.
- `-DLLVM_ENABLE_ZLIB=OFF` : Don't build llvm with ZLib support as it's not required and will disrupt the target dependencies for components linking against llvm. This only has to be passed when building llvm, as this option will be saved into the config headers.
- `-DCMAKE_BUILD_TYPE=Release` : Build llvm and components in release mode.
- `-DCMAKE_BUILD_TYPE=Debug` : Build llvm and components in debug mode.
- `-DLLVM_USE_CRT_RELEASE=MT` : Which C runtime should llvm use during release builds.
- `-DLLVM_USE_CRT_DEBUG=MTd` : Make llvm use the debug version of the runtime in debug builds.
##### Release Mode
```bat
mkdir C:\Users\Andy\llvm-21.0.0.src\build-release
cd C:\Users\Andy\llvm-21.0.0.src\build-release
"c:\Program Files\CMake\bin\cmake.exe" .. -Thost=x64 -G "Visual Studio 16 2019" -A x64 -DCMAKE_INSTALL_PREFIX=C:\Users\Andy\llvm+clang+lld-21.0.0-x86_64-windows-msvc-release-mt -DCMAKE_PREFIX_PATH=C:\Users\Andy\llvm+clang+lld-21.0.0-x86_64-windows-msvc-release-mt -
DLLVM_ENABLE_ZLIB=OFF -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_LIBXML2=OFF -DLLVM_USE_CRT_RELEASE=MT
msbuild /m -p:Configuration=Release INSTALL.vcxproj
```
##### Debug Mode
```bat
mkdir C:\Users\Andy\llvm-21.0.0.src\build-debug
cd C:\Users\Andy\llvm-21.0.0.src\build-debug
"c:\Program Files\CMake\bin\cmake.exe" .. -Thost=x64 -G "Visual Studio 16 2019" -A x64 -DCMAKE_INSTALL_PREFIX=C:\Users\andy\llvm+clang+lld-21.0.0-x86_64-windows-msvc-debug -
DLLVM_ENABLE_ZLIB=OFF -DCMAKE_PREFIX_PATH=C:\Users\andy\llvm+clang+lld-21.0.0-x86_64-windows-msvc-debug -DCMAKE_BUILD_TYPE=Debug -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="AVR" -DLLVM_ENABLE_LIBXML2=OFF -DLLVM_USE_CRT_DEBUG=MTd
msbuild /m INSTALL.vcxproj
```
#### LLD
Using the start menu, run **x64 Native Tools Command Prompt for VS 2019** and execute these commands, replacing `C:\Users\Andy` with the correct value.
##### Release Mode
```bat
mkdir C:\Users\Andy\lld-21.0.0.src\build-release
cd C:\Users\Andy\lld-21.0.0.src\build-release
"c:\Program Files\CMake\bin\cmake.exe" .. -Thost=x64 -G "Visual Studio 16 2019" -A x64 -DCMAKE_INSTALL_PREFIX=C:\Users\Andy\llvm+clang+lld-14.0.6-x86_64-windows-msvc-release-mt -DCMAKE_PREFIX_PATH=C:\Users\Andy\llvm+clang+lld-21.0.0-x86_64-windows-msvc-release-mt -DCMAKE_BUILD_TYPE=Release -DLLVM_USE_CRT_RELEASE=MT
msbuild /m -p:Configuration=Release INSTALL.vcxproj
```
##### Debug Mode
```bat
mkdir C:\Users\Andy\lld-21.0.0.src\build-debug
cd C:\Users\Andy\lld-21.0.0.src\build-debug
"c:\Program Files\CMake\bin\cmake.exe" .. -Thost=x64 -G "Visual Studio 16 2019" -A x64 -DCMAKE_INSTALL_PREFIX=C:\Users\andy\llvm+clang+lld-21.0.0-x86_64-windows-msvc-debug -DCMAKE_PREFIX_PATH=C:\Users\andy\llvm+clang+lld-21.0.0-x86_64-windows-msvc-debug -DCMAKE_BUILD_TYPE=Debug -DLLVM_USE_CRT_DEBUG=MTd
msbuild /m INSTALL.vcxproj
```
#### Clang
Using the start menu, run **x64 Native Tools Command Prompt for VS 2019** and execute these commands, replacing `C:\Users\Andy` with the correct value.
##### Release Mode
```bat
mkdir C:\Users\Andy\clang-21.0.0.src\build-release
cd C:\Users\Andy\clang-21.0.0.src\build-release
"c:\Program Files\CMake\bin\cmake.exe" .. -Thost=x64 -G "Visual Studio 16 2019" -A x64 -DCMAKE_INSTALL_PREFIX=C:\Users\Andy\llvm+clang+lld-21.0.0-x86_64-windows-msvc-release-mt -DCMAKE_PREFIX_PATH=C:\Users\Andy\llvm+clang+lld-21.0.0-x86_64-windows-msvc-release-mt -DCMAKE_BUILD_TYPE=Release -DLLVM_USE_CRT_RELEASE=MT
msbuild /m -p:Configuration=Release INSTALL.vcxproj
```
##### Debug Mode
```bat
mkdir C:\Users\Andy\clang-21.0.0.src\build-debug
cd C:\Users\Andy\clang-21.0.0.src\build-debug
"c:\Program Files\CMake\bin\cmake.exe" .. -Thost=x64 -G "Visual Studio 16 2019" -A x64 -DCMAKE_INSTALL_PREFIX=C:\Users\andy\llvm+clang+lld-21.0.0-x86_64-windows-msvc-debug -DCMAKE_PREFIX_PATH=C:\Users\andy\llvm+clang+lld-21.0.0-x86_64-windows-msvc-debug -DCMAKE_BUILD_TYPE=Debug -DLLVM_USE_CRT_DEBUG=MTd
msbuild /m INSTALL.vcxproj
```
### POSIX Systems
This guide will get you both a Debug build of LLVM, and/or a Release build of LLVM.
It intentionally does not require privileged access, using a prefix inside your home
directory instead of a global installation.
#### Release
This is the generally recommended approach.
```
cd ~/Downloads
git clone --depth 1 --branch release/21.x https://github.com/llvm/llvm-project llvm-project-21
cd llvm-project-21
git checkout release/21.x
mkdir build-release
cd build-release
cmake ../llvm \
-DCMAKE_INSTALL_PREFIX=$HOME/local/llvm21-assert \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS="lld;clang" \
-DLLVM_ENABLE_LIBXML2=OFF \
-DLLVM_ENABLE_TERMINFO=OFF \
-DLLVM_ENABLE_LIBEDIT=OFF \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_PARALLEL_LINK_JOBS=1 \
-G Ninja
ninja install
```
#### Debug
This is occasionally needed when debugging Zig's LLVM backend. Here we build
the three projects separately so that LLVM can be in Debug mode while the
others are in Release mode.
```
cd ~/Downloads
git clone --depth 1 --branch release/21.x https://github.com/llvm/llvm-project llvm-project-21
cd llvm-project-21
git checkout release/21.x
# LLVM
mkdir llvm/build-debug
cd llvm/build-debug
cmake .. \
-DCMAKE_INSTALL_PREFIX=$HOME/local/llvm21-debug \
-DCMAKE_PREFIX_PATH=$HOME/local/llvm21-debug \
-DCMAKE_BUILD_TYPE=Debug \
-DLLVM_ENABLE_LIBXML2=OFF \
-DLLVM_ENABLE_TERMINFO=OFF \
-DLLVM_ENABLE_LIBEDIT=OFF \
-DLLVM_PARALLEL_LINK_JOBS=1 \
-G Ninja
ninja install
cd ../..
# LLD
mkdir lld/build-debug
cd lld/build-debug
cmake .. \
-DCMAKE_INSTALL_PREFIX=$HOME/local/llvm21-debug \
-DCMAKE_PREFIX_PATH=$HOME/local/llvm21-debug \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_PARALLEL_LINK_JOBS=1 \
-DCMAKE_CXX_STANDARD=17 \
-G Ninja
ninja install
cd ../..
# Clang
mkdir clang/build-debug
cd clang/build-debug
cmake .. \
-DCMAKE_INSTALL_PREFIX=$HOME/local/llvm21-debug \
-DCMAKE_PREFIX_PATH=$HOME/local/llvm21-debug \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_PARALLEL_LINK_JOBS=1 \
-DLLVM_INCLUDE_TESTS=OFF \
-G Ninja
ninja install
cd ../..
```
Then add to your Zig CMake line that you got from the README.md:
`-DCMAKE_PREFIX_PATH=$HOME/local/llvm21-debug` or
`-DCMAKE_PREFIX_PATH=$HOME/local/llvm21-assert` depending on whether you want
Debug or Release LLVM.
## Contributing
[Donate monthly](https://ziglang.org/zsf/).
[Join a community](https://ziglang.org/community/).
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.
### Make Software With Zig
One of the best ways you can contribute to Zig is to start using it for an
open-source personal project.
@ -113,35 +458,343 @@ 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.
Ideally, such a project will help you to learn new skills and add something
to your personal portfolio at the same time.
### Talk About Zig
Another way to contribute is to write about Zig, speak about Zig at a
conference, or do either of those things for your project which uses Zig.
Programming languages live and die based on the pulse of their ecosystems. The
more people involved, the more we can build great things upon each other's
abstractions.
### Strict No LLM / No AI Policy
No LLMs for issues.
No LLMs for patches / pull requests.
No LLMs for comments on the bug tracker, including translation.
English is encouraged, but not required. You are welcome to post in your native
language and rely on others to have their own translation tools of choice to
interpret your words.
### Find a Contributor Friendly Issue
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.**
[Contributor Friendly](https://codeberg.org/ziglang/zig/issues?labels=741726&state=open)
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
[Proposal: Proposed](https://codeberg.org/ziglang/zig/issues?labels=746937&state=open)
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.
Language proposals are not accepted. Please do not open an issue proposing to
change the Zig language or syntax.
## Community
### Editing Source Code
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.
For a smooth workflow, when building from source, it is recommended to use
CMake with the following settings:
* `-DCMAKE_BUILD_TYPE=Release` - to recompile zig faster.
* `-GNinja` - Ninja is faster and simpler to use than Make.
* `-DZIG_NO_LIB=ON` - Prevents the build system from copying the lib/
directory to the installation prefix, causing zig use lib/ directly from the
source tree instead. Effectively, this makes it so that changes to lib/ do
not require re-running the install command to become active.
After configuration, there are two scenarios:
1. Pulling upstream changes and rebuilding.
- In this case use `git pull` and then `ninja install`. Expected wait:
about 10 minutes.
2. Building from source after making local changes.
- In this case use `stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib`.
Expected wait: about 20 seconds.
This leaves you with two builds of Zig:
* `stage3/bin/zig` - an optimized master branch build. Useful for
miscellaneous activities such as `zig fmt`, as well as for building the
compiler itself after changing the source code.
* `stage4/bin/zig` - a debug build that includes your local changes; useful
for testing and eliminating bugs before submitting a patch.
To reduce time spent waiting for the compiler to build, try these techniques:
* Omit `-Denable-llvm` if you don't need the LLVM backend.
* Use `-Ddev=foo` to build with a reduced feature set for development of
specific features. See `zig build -h` for a list of options.
* Use `--watch -fincremental` to enable incremental compilation. This offers
**near instant rebuilds**.
### Testing
```
stage4/bin/zig build test
```
This command runs the whole test suite, which does a lot of extra testing that
you likely won't always need, and can take upwards of 1 hour. This is what the
CI server runs when you make a pull request.
To save time, you can add the `--help` option to the `zig build` command and
see what options are available. One of the most helpful ones is
`-Dskip-release`. Adding this option to the command above, along with
`-Dskip-non-native`, will take the time down from around 2 hours to about 30
minutes, and this is a good enough amount of testing before making a pull
request.
Another example is choosing a different set of things to test. For example,
`test-std` instead of `test` will only run the standard library tests, and
not the other ones. Combining this suggestion with the previous one, you could
do this:
```
stage4/bin/zig build test-std -Dskip-release
```
This will run only the standard library tests in debug mode for all targets.
It will cross-compile the tests for non-native targets but not run them.
When making changes to the compiler source code, the most helpful test step to
run is `test-behavior`. When editing documentation it is `docs`. You can find
this information and more in the `zig build --help` menu.
#### Directly Testing the Standard Library with `zig test`
This command will run the standard library tests with only the native target
configuration and is estimated to complete in 3 minutes:
```
zig build test-std -Dno-matrix
```
However, one may also use `zig test` directly. From inside the `ziglang/zig` repo root:
```
zig test lib/std/std.zig --zig-lib-dir lib
```
You can add `--test-filter "some test name"` to run a specific test or a subset of tests.
(Running exactly 1 test is not reliably possible, because the test filter does not
exclude anonymous test blocks, but that shouldn't interfere with whatever
you're trying to test in practice.)
Note that `--test-filter` filters on fully qualified names, so e.g. it's possible to run only the `std.json` tests with:
```
zig test lib/std/std.zig --zig-lib-dir lib --test-filter "json."
```
If you used `-Dno-lib` and you are in a `build/` subdirectory, you can omit the
`--zig-lib-dir` argument:
```
stage3/bin/zig test ../lib/std/std.zig
```
#### Testing Non-Native Architectures with QEMU
The Linux CI server additionally has qemu installed and sets `-fqemu`.
This provides test coverage for, e.g. aarch64 even on x86_64 machines. It's
recommended for Linux users to install qemu and enable this testing option
when editing the standard library or anything related to a non-native
architecture.
QEMU packages provided by some system package managers (such as Debian) may be
a few releases old, or may be missing newer targets such as aarch64 and RISC-V.
[ziglang/qemu-static](https://codeberg.org/ziglang/qemu-static) offers static
binaries of the latest QEMU version.
##### Testing Non-Native glibc Targets
Testing foreign architectures with dynamically linked glibc is one step trickier.
This requires enabling `--glibc-runtimes /path/to/glibc/multi/install/glibcs`.
This path is obtained by building glibc for multiple architectures. This
process for me took an entire day to complete and takes up 65 GiB on my hard
drive. The CI server does not provide this test coverage.
[Instructions for producing this path](https://codeberg.org/ziglang/infra/src/branch/master/building-libcs.md#linux-glibc) (just the part with `build-many-glibcs.py`).
It is understood that most contributors will not have these tests enabled.
#### Testing Windows from a Linux Machine with Wine
When developing on Linux, another option is available to you: `-fwine`.
This will enable running behavior tests and std lib tests with Wine. It's
recommended for Linux users to install Wine and enable this testing option
when editing the standard library or anything Windows-related.
#### Testing WebAssembly using wasmtime
If you have [wasmtime](https://wasmtime.dev/) installed, take advantage of the
`-fwasmtime` flag which will enable running WASI behavior tests and std
lib tests. It's recommended for all users to install wasmtime and enable this
testing option when editing the standard library and especially anything
WebAssembly-related.
### Improving Translate-C
`translate-c` is a feature provided by Zig that converts C source code into
Zig source code. It powers the `zig translate-c` command as well as
[@cImport](https://ziglang.org/documentation/master/#cImport), allowing Zig
code to not only take advantage of function prototypes defined in .h files,
but also `static inline` functions written in C, and even some macros.
This feature used to work by using libclang API to parse and semantically
analyze C/C++ files, and then based on the provided AST and type information,
generating Zig AST, and finally using the mechanisms of `zig fmt` to render the
Zig AST to a file.
However, C translation is in a transitional period right now. It used to be
based on Clang, but is now based on Aro:
[Pull Request: update aro and translate-c to latest; delete clang translate-c](https://github.com/ziglang/zig/pull/24497)
Test coverage as well as bug reports have been moved to this repository:
[ziglang/translate-c](https://codeberg.org/ziglang/translate-c/)
In the future, [@cImport will move to the build system](https://github.com/ziglang/zig/issues/20630),
but for now, the translate-c logic is copy-pasted from that project into
[ziglang/zig](https://codeberg.org/ziglang/zig/), powering both `zig translate-c`
and `@cImport`.
Please see the readme of the translate-c project for how to contribute. Once an
issue is resolved (and test coverage added) there, the changes can be
immediately backported to the zig compiler.
Once we fix the problems people are facing from this transition from Clang to
Aro, we can move on to enhancing the translate-c package such that `@cImport`
becomes redundant and can therefore be eliminated from the language.
### Autodoc
Autodoc is an interactive, searchable, single-page web application for browsing
Zig codebases.
An autodoc deployment looks like this:
```
index.html
main.js
main.wasm
sources.tar
```
* `main.js` and `index.html` are static files which live in a Zig installation
at `lib/docs/`.
* `main.wasm` is compiled from the Zig files inside `lib/docs/wasm/`.
* `sources.tar` is all the zig source files of the project.
These artifacts are produced by the compiler when `-femit-docs` is passed.
#### Making Changes
The command `zig std` spawns an HTTP server that provides all the assets
mentioned above specifically for the standard library.
The server creates the requested files on the fly, including rebuilding
`main.wasm` if any of its source files changed, and constructing `sources.tar`,
meaning that any source changes to the documented files, or to the autodoc
system itself are immediately reflected when viewing docs.
This means you can test changes to Zig standard library documentation, as well
as autodocs functionality, by pressing refresh in the browser.
Prefixing the URL with `/debug` results in a debug build of `main.wasm`.
#### Debugging the Zig Code
While Firefox and Safari support are obviously required, I recommend Chromium
for development for one reason in particular:
[C/C++ DevTools Support (DWARF)](https://chromewebstore.google.com/detail/cc++-devtools-support-dwa/pdcpmagijalfljmkmjngeonclgbbannb)
This makes debugging Zig WebAssembly code a breeze.
#### The Sources Tarball
The system expects the top level of `sources.tar` to be the set of modules
documented. So for the Zig standard library you would do this:
`tar cf std.tar std/`. Don't compress it; the idea is to rely on HTTP
compression.
Any files that are not `.zig` source files will be ignored by `main.wasm`,
however, those files will take up wasted space in the tar file. For the
standard library, use the set of files that zig installs to when running `zig
build`, which is the same as the set of files that are provided on
ziglang.org/download.
If the system doesn't find a file named "foo/root.zig" or "foo/foo.zig", it
will use the first file in the tar as the module root.
You don't typically need to create `sources.tar` yourself, since it is lazily
provided by the `zig std` HTTP server as well as produced by `-femit-docs`.
## Testing Zig Code With LLDB
[@jacobly0](https://github.com/jacobly0) maintains a fork of LLDB with Zig support:
https://github.com/jacobly0/llvm-project/tree/lldb-zig
This fork only contains changes for debugging programs compiled by Zig's
self-hosted backends, i.e. `zig build-exe -fno-llvm ...`.
### Building
To build the LLDB fork, make sure you have
[prerequisites](https://lldb.llvm.org/resources/build.html#preliminaries)
installed, and then do something like:
```
$ cmake llvm -G Ninja -B build -DLLVM_ENABLE_PROJECTS="clang;lldb" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_ASSERTIONS=ON -DLLDB_ENABLE_LIBEDIT=ON -DLLDB_ENABLE_PYTHON=ON
$ cmake --build build --target lldb --target lldb-server
```
(You may need to manually [configure
dependencies](https://lldb.llvm.org/resources/build.html#optional-dependencies)
if CMake can't find them.)
Once built, you can run `./build/bin/lldb` and so on.
### Pretty Printers
If you will be debugging the Zig compiler itself, or if you will be debugging
any project compiled with Zig's LLVM backend (not recommended with the LLDB
fork, prefer vanilla LLDB with a version that matches the version of LLVM that
Zig is using), you can get a better debugging experience by using
[`lldb_pretty_printers.py`](https://codeberg.org/ziglang/zig/src/branch/master/tools/lldb_pretty_printers.py).
Put this line in `~/.lldbinit`:
```
command script import /path/to/zig/tools/lldb_pretty_printers.py
```
If you will be using Zig's LLVM backend (again, not recommended with the LLDB
fork), you will also want these lines:
```
type category enable zig.lang
type category enable zig.std
```
If you will be debugging a Zig compiler built using Zig's LLVM backend (again,
not recommended with the LLDB fork), you will also want this line:
```
type category enable zig.stage2
```
Please see the [Community](https://github.com/ziglang/zig/wiki/Community) wiki
page for a public listing of social spaces.

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
@ -141,6 +143,7 @@ int main(int argc, char **argv) {
"pub const skip_non_native = false;\n"
"pub const debug_gpa = false;\n"
"pub const dev = .core;\n"
"pub const io_mode: enum { threaded, evented } = .threaded;\n"
"pub const value_interpret_mode = .direct;\n"
, zig_version);
if (written < 100)

270
build.zig
View file

@ -1,18 +1,21 @@
const std = @import("std");
const builtin = std.builtin;
const tests = @import("test/tests.zig");
const BufMap = std.BufMap;
const mem = std.mem;
const io = std.io;
const fs = std.fs;
const InstallDirectoryOptions = std.Build.InstallDirectoryOptions;
const assert = std.debug.assert;
const DevEnv = @import("src/dev.zig").Env;
const ValueInterpretMode = enum { direct, by_name };
const Io = std.Io;
const zig_version: std.SemanticVersion = .{ .major = 0, .minor = 15, .patch = 0 };
const tests = @import("test/tests.zig");
const DevEnv = @import("src/dev.zig").Env;
const zig_version: std.SemanticVersion = .{ .major = 0, .minor = 16, .patch = 0 };
const stack_size = 46 * 1024 * 1024;
const IoMode = enum { threaded, evented };
const ValueInterpretMode = enum { direct, by_name };
pub fn build(b: *std.Build) !void {
const only_c = b.option(bool, "only-c", "Translate the Zig compiler to C code, with only the C backend enabled") orelse false;
const target = b.standardTargetOptions(.{
@ -27,7 +30,7 @@ pub fn build(b: *std.Build) !void {
const use_zig_libcxx = b.option(bool, "use-zig-libcxx", "If libc++ is needed, use zig's bundled version, don't try to integrate with the system") orelse false;
const test_step = b.step("test", "Run all the tests");
const skip_install_lib_files = b.option(bool, "no-lib", "skip copying of lib/ files and langref to installation prefix. Useful for development") orelse false;
const skip_install_lib_files = b.option(bool, "no-lib", "skip copying of lib/ files and langref to installation prefix. Useful for development") orelse only_c;
const skip_install_langref = b.option(bool, "no-langref", "skip copying of langref to the installation prefix") orelse skip_install_lib_files;
const std_docs = b.option(bool, "std-docs", "include standard library autodocs") orelse false;
const no_bin = b.option(bool, "no-bin", "skip emitting compiler binary") orelse false;
@ -81,23 +84,27 @@ 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 fuzz_only = b.option(bool, "fuzz-only", "Limit test matrix to one target suitable for fuzzing") 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_compile_errors = b.option(bool, "skip-compile-errors", "Main test suite skips compile error tests") 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_spirv = b.option(bool, "skip-spirv", "Main test suite skips targets with spirv32/spirv64 architecture") orelse false;
const skip_wasm = b.option(bool, "skip-wasm", "Main test suite skips targets with wasm32/wasm64 architecture") 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_openbsd = b.option(bool, "skip-openbsd", "Main test suite skips targets with openbsd OS") orelse false;
const skip_windows = b.option(bool, "skip-windows", "Main test suite skips targets with windows OS") orelse false;
const skip_macos = b.option(bool, "skip-macos", "Main test suite skips targets with macos 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;
@ -183,6 +190,7 @@ pub fn build(b: *std.Build) !void {
const strip = b.option(bool, "strip", "Omit debug information");
const valgrind = b.option(bool, "valgrind", "Enable valgrind integration");
const pie = b.option(bool, "pie", "Produce a Position Independent Executable");
const io_mode = b.option(IoMode, "io-mode", "How the compiler performs IO") orelse .threaded;
const value_interpret_mode = b.option(ValueInterpretMode, "value-interpret-mode", "How the compiler translates between 'std.builtin' types and its internal datastructures") orelse .direct;
const value_tracing = b.option(bool, "value-tracing", "Enable extra state tracking to help troubleshoot bugs in the compiler (using the std.debug.Trace API)") orelse false;
@ -202,6 +210,7 @@ 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");
const use_llvm = b.option(bool, "use-llvm", "Use the llvm backend");
exe.use_llvm = use_llvm;
@ -230,6 +239,7 @@ pub fn build(b: *std.Build) !void {
exe_options.addOption(bool, "llvm_has_xtensa", llvm_has_xtensa);
exe_options.addOption(bool, "debug_gpa", debug_gpa);
exe_options.addOption(DevEnv, "dev", b.option(DevEnv, "dev", "Build a compiler with a reduced feature set for development of specific features") orelse if (only_c) .bootstrap else .full);
exe_options.addOption(IoMode, "io_mode", io_mode);
exe_options.addOption(ValueInterpretMode, "value_interpret_mode", value_interpret_mode);
if (link_libc) {
@ -256,12 +266,12 @@ pub fn build(b: *std.Build) !void {
"--git-dir", ".git", // affected by the -C argument
"describe", "--match", "*.*.*", //
"--tags", "--abbrev=9",
}, &code, .Ignore) catch {
}, &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)) {
@ -303,8 +313,10 @@ pub fn build(b: *std.Build) !void {
if (enable_llvm) {
const cmake_cfg = if (static_llvm) null else blk: {
const io = b.graph.io;
const cwd: Io.Dir = .cwd();
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 = cwd.readFileAlloc(io, 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\"", .{});
@ -359,14 +371,22 @@ pub fn build(b: *std.Build) !void {
&[_][]const u8{ tracy_path, "public", "TracyClient.cpp" },
);
const tracy_c_flags: []const []const u8 = &.{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" };
const tracy_c_flags: []const []const u8 = &.{
"-DTRACY_ENABLE=1",
"-fno-sanitize=undefined",
"-DTRACY_FIBERS",
};
exe.root_module.addIncludePath(.{ .cwd_relative = tracy_path });
exe.root_module.addCSourceFile(.{ .file = .{ .cwd_relative = client_cpp }, .flags = tracy_c_flags });
if (!enable_llvm) {
exe.root_module.linkSystemLibrary("c++", .{ .use_pkg_config = .no });
}
exe.root_module.addCSourceFile(.{
.file = .{ .cwd_relative = client_cpp },
.flags = tracy_c_flags[0..switch (io_mode) {
.threaded => 2,
.evented => 3,
}],
});
exe.root_module.link_libc = true;
exe.root_module.link_libcpp = true;
if (target.result.os.tag == .windows) {
exe.root_module.linkSystemLibrary("dbghelp", .{});
@ -398,6 +418,13 @@ pub fn build(b: *std.Build) !void {
}
const optimization_modes = chosen_opt_modes_buf[0..chosen_mode_index];
const test_only: ?tests.ModuleTestOptions.TestOnly = if (no_matrix)
.default
else if (fuzz_only)
.{ .fuzz = optimize }
else
null;
const fmt_include_paths = &.{ "lib", "src", "test", "tools", "build.zig", "build.zig.zon" };
const fmt_exclude_paths = &.{ "test/cases", "test/behavior/zon" };
const do_fmt = b.addFmt(.{
@ -415,21 +442,21 @@ 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, target, .{
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_spirv = skip_spirv,
.skip_wasm = skip_wasm,
.skip_freebsd = skip_freebsd,
.skip_netbsd = skip_netbsd,
.skip_openbsd = skip_openbsd,
.skip_windows = skip_windows,
.skip_macos = skip_macos,
.skip_darwin = skip_darwin,
.skip_linux = skip_linux,
.skip_llvm = skip_llvm,
.skip_libc = skip_libc,
}, .{
.skip_translate_c = skip_translate_c,
.skip_run_translated_c = skip_run_translated_c,
}, .{
.enable_llvm = enable_llvm,
.llvm_has_m68k = llvm_has_m68k,
@ -453,35 +480,18 @@ pub fn build(b: *std.Build) !void {
.include_paths = &.{},
.skip_single_threaded = skip_single_threaded,
.skip_non_native = skip_non_native,
.test_only = test_only,
.skip_spirv = skip_spirv,
.skip_wasm = skip_wasm,
.skip_freebsd = skip_freebsd,
.skip_netbsd = skip_netbsd,
.skip_openbsd = skip_openbsd,
.skip_windows = skip_windows,
.skip_macos = skip_macos,
.skip_linux = skip_linux,
.skip_llvm = skip_llvm,
.skip_libc = skip_libc,
// 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_extra_targets = test_extra_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_freebsd = skip_freebsd,
.skip_netbsd = skip_netbsd,
.skip_windows = skip_windows,
.skip_macos = skip_macos,
.skip_darwin = skip_darwin,
.skip_linux = skip_linux,
.skip_llvm = skip_llvm,
.skip_libc = skip_libc,
.max_rss = 4_000_000_000,
}));
test_modules_step.dependOn(tests.addModuleTests(b, .{
@ -495,14 +505,19 @@ pub fn build(b: *std.Build) !void {
.include_paths = &.{},
.skip_single_threaded = true,
.skip_non_native = skip_non_native,
.test_only = test_only,
.skip_spirv = skip_spirv,
.skip_wasm = skip_wasm,
.skip_freebsd = skip_freebsd,
.skip_netbsd = skip_netbsd,
.skip_openbsd = skip_openbsd,
.skip_windows = skip_windows,
.skip_macos = skip_macos,
.skip_darwin = skip_darwin,
.skip_linux = skip_linux,
.skip_llvm = skip_llvm,
.skip_libc = true,
.no_builtin = true,
.max_rss = 4_000_000_000,
}));
test_modules_step.dependOn(tests.addModuleTests(b, .{
@ -511,19 +526,24 @@ pub fn build(b: *std.Build) !void {
.test_extra_targets = test_extra_targets,
.root_src = "lib/c.zig",
.name = "zigc",
.desc = "Run the zigc tests",
.desc = "Run the zig libc implementation unit tests",
.optimize_modes = optimization_modes,
.include_paths = &.{},
.skip_single_threaded = true,
.skip_non_native = skip_non_native,
.test_only = test_only,
.skip_spirv = skip_spirv,
.skip_wasm = skip_wasm,
.skip_freebsd = skip_freebsd,
.skip_netbsd = skip_netbsd,
.skip_openbsd = skip_openbsd,
.skip_windows = skip_windows,
.skip_macos = skip_macos,
.skip_darwin = skip_darwin,
.skip_linux = skip_linux,
.skip_llvm = skip_llvm,
.skip_libc = true,
.no_builtin = true,
.max_rss = 4_000_000_000,
}));
test_modules_step.dependOn(tests.addModuleTests(b, .{
@ -537,15 +557,18 @@ pub fn build(b: *std.Build) !void {
.include_paths = &.{},
.skip_single_threaded = skip_single_threaded,
.skip_non_native = skip_non_native,
.test_only = test_only,
.skip_spirv = skip_spirv,
.skip_wasm = skip_wasm,
.skip_freebsd = skip_freebsd,
.skip_netbsd = skip_netbsd,
.skip_openbsd = skip_openbsd,
.skip_windows = skip_windows,
.skip_macos = skip_macos,
.skip_darwin = skip_darwin,
.skip_linux = skip_linux,
.skip_llvm = skip_llvm,
.skip_libc = skip_libc,
// I observed a value of 5605064704 on the M2 CI.
.max_rss = 6165571174,
.max_rss = 8_500_000_000,
}));
const unit_tests_step = b.step("test-unit", "Run the compiler source unit tests");
@ -561,6 +584,7 @@ pub fn build(b: *std.Build) !void {
.use_llvm = use_llvm,
.use_lld = use_llvm,
.zig_lib_dir = b.path("lib"),
.max_rss = 2_500_000_000,
});
if (link_libc) {
unit_tests.root_module.link_libc = true;
@ -568,7 +592,6 @@ pub fn build(b: *std.Build) !void {
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,
@ -579,18 +602,21 @@ 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_wasm = skip_wasm,
.skip_freebsd = skip_freebsd,
.skip_netbsd = skip_netbsd,
.skip_openbsd = skip_openbsd,
.skip_windows = skip_windows,
.skip_macos = skip_macos,
.skip_darwin = skip_darwin,
.skip_linux = skip_linux,
.skip_llvm = skip_llvm,
.skip_release = skip_release,
.max_rss = 3_000_000_000,
}));
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,
@ -628,8 +654,16 @@ 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);
try tests.addIncrementalTests(b, test_incremental_step, test_filters);
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,
.skip_wasm = skip_wasm,
.max_rss = 3_500_000_000,
})) |test_libc_step| test_step.dependOn(test_libc_step);
}
fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
@ -662,6 +696,7 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
exe_options.addOption(u32, "tracy_callstack_depth", 0);
exe_options.addOption(bool, "value_tracing", false);
exe_options.addOption(DevEnv, "dev", .bootstrap);
exe_options.addOption(IoMode, "io_mode", .threaded);
// zig1 chooses to interpret values by name. The tradeoff is as follows:
//
@ -690,14 +725,14 @@ 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 AddCompilerModOptions = struct {
@ -724,13 +759,7 @@ fn addCompilerMod(b: *std.Build, options: AddCompilerModOptions) *std.Build.Modu
.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;
}
@ -738,11 +767,17 @@ fn addCompilerMod(b: *std.Build, options: AddCompilerModOptions) *std.Build.Modu
fn addCompilerStep(b: *std.Build, options: AddCompilerModOptions) *std.Build.Step.Compile {
const exe = b.addExecutable(.{
.name = "zig",
.max_rss = 7_800_000_000,
.max_rss = 7_900_000_000,
.root_module = addCompilerMod(b, options),
});
exe.stack_size = stack_size;
// Must match the condition in CMakeLists.txt.
const function_data_sections = options.target.result.cpu.arch.isArm() or options.target.result.cpu.arch.isPowerPC();
exe.link_function_sections = function_data_sections;
exe.link_data_sections = function_data_sections;
return exe;
}
@ -815,7 +850,7 @@ fn addCmakeCfgOptionsToExe(
};
mod.linkSystemLibrary("unwind", .{});
},
.ios, .macos, .watchos, .tvos, .visionos => {
.driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => {
mod.link_libcpp = true;
},
.windows => {
@ -836,7 +871,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);
},
@ -869,46 +904,48 @@ fn addStaticLlvmOptionsToModule(mod: *std.Build.Module, options: struct {
.flags = &zig_cpp_cflags,
});
const lsl_options: std.Build.Module.LinkSystemLibraryOptions = .{ .use_pkg_config = .no };
for (clang_libs) |lib_name| {
mod.linkSystemLibrary(lib_name, .{});
mod.linkSystemLibrary(lib_name, lsl_options);
}
for (lld_libs) |lib_name| {
mod.linkSystemLibrary(lib_name, .{});
mod.linkSystemLibrary(lib_name, lsl_options);
}
for (llvm_libs) |lib_name| {
mod.linkSystemLibrary(lib_name, .{});
mod.linkSystemLibrary(lib_name, lsl_options);
}
if (options.llvm_has_m68k) for (llvm_libs_m68k) |lib_name| {
mod.linkSystemLibrary(lib_name, .{});
mod.linkSystemLibrary(lib_name, lsl_options);
};
if (options.llvm_has_csky) for (llvm_libs_csky) |lib_name| {
mod.linkSystemLibrary(lib_name, .{});
mod.linkSystemLibrary(lib_name, lsl_options);
};
if (options.llvm_has_arc) for (llvm_libs_arc) |lib_name| {
mod.linkSystemLibrary(lib_name, .{});
mod.linkSystemLibrary(lib_name, lsl_options);
};
if (options.llvm_has_xtensa) for (llvm_libs_xtensa) |lib_name| {
mod.linkSystemLibrary(lib_name, .{});
mod.linkSystemLibrary(lib_name, lsl_options);
};
mod.linkSystemLibrary("z", .{});
mod.linkSystemLibrary("zstd", .{});
mod.linkSystemLibrary("z", lsl_options);
mod.linkSystemLibrary("zstd", lsl_options);
if (mod.resolved_target.?.result.os.tag != .windows or mod.resolved_target.?.result.abi != .msvc) {
// This means we rely on clang-or-zig-built LLVM, Clang, LLD libraries.
mod.linkSystemLibrary("c++", .{});
mod.linkSystemLibrary("c++", lsl_options);
}
if (mod.resolved_target.?.result.os.tag == .windows) {
mod.linkSystemLibrary("version", .{});
mod.linkSystemLibrary("uuid", .{});
mod.linkSystemLibrary("ole32", .{});
mod.linkSystemLibrary("version", lsl_options);
mod.linkSystemLibrary("uuid", lsl_options);
mod.linkSystemLibrary("ole32", lsl_options);
}
}
@ -993,10 +1030,13 @@ const CMakeConfig = struct {
const max_config_h_bytes = 1 * 1024 * 1024;
fn findConfigH(b: *std.Build, config_h_path_option: ?[]const u8) ?[]const u8 {
const io = b.graph.io;
const cwd: Io.Dir = .cwd();
if (config_h_path_option) |path| {
var config_h_or_err = fs.cwd().openFile(path, .{});
var config_h_or_err = cwd.openFile(io, path, .{});
if (config_h_or_err) |*file| {
file.close();
file.close(io);
return path;
} else |_| {
std.log.err("Could not open provided config.h: \"{s}\"", .{path});
@ -1006,13 +1046,13 @@ fn findConfigH(b: *std.Build, config_h_path_option: ?[]const u8) ?[]const u8 {
var check_dir = fs.path.dirname(b.graph.zig_exe).?;
while (true) {
var dir = fs.cwd().openDir(check_dir, .{}) catch unreachable;
defer dir.close();
var dir = cwd.openDir(io, check_dir, .{}) catch unreachable;
defer dir.close(io);
// Check if config.h is present in dir
var config_h_or_err = dir.openFile("config.h", .{});
var config_h_or_err = dir.openFile(io, "config.h", .{});
if (config_h_or_err) |*file| {
file.close();
file.close(io);
return fs.path.join(
b.allocator,
&[_][]const u8{ check_dir, "config.h" },
@ -1023,9 +1063,9 @@ fn findConfigH(b: *std.Build, config_h_path_option: ?[]const u8) ?[]const u8 {
}
// Check if we reached the source root by looking for .git, and bail if so
var git_dir_or_err = dir.openDir(".git", .{});
var git_dir_or_err = dir.openDir(io, ".git", .{});
if (git_dir_or_err) |*git_dir| {
git_dir.close();
git_dir.close(io);
return null;
} else |_| {}
@ -1150,7 +1190,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",
@ -1176,7 +1215,6 @@ const clang_libs = [_][]const u8{
"clangBasic",
"clangEdit",
"clangLex",
"clangARCMigrate",
"clangRewriteFrontend",
"clangRewrite",
"clangCrossTU",
@ -1322,30 +1360,31 @@ const llvm_libs = [_][]const u8{
"LLVMOrcTargetProcess",
"LLVMOrcShared",
"LLVMDWP",
"LLVMDWARFCFIChecker",
"LLVMDebugInfoLogicalView",
"LLVMDebugInfoGSYM",
"LLVMOption",
"LLVMObjectYAML",
"LLVMObjCopy",
"LLVMMCA",
"LLVMMCDisassembler",
"LLVMLTO",
"LLVMPasses",
"LLVMHipStdPar",
"LLVMCFGuard",
"LLVMCoroutines",
"LLVMipo",
"LLVMVectorize",
"LLVMSandboxIR",
"LLVMLinker",
"LLVMInstrumentation",
"LLVMFrontendOpenMP",
"LLVMFrontendOffloading",
"LLVMFrontendOpenACC",
"LLVMFrontendHLSL",
"LLVMFrontendDriver",
"LLVMFrontendAtomic",
"LLVMExtensions",
"LLVMPasses",
"LLVMHipStdPar",
"LLVMCoroutines",
"LLVMCFGuard",
"LLVMipo",
"LLVMInstrumentation",
"LLVMVectorize",
"LLVMSandboxIR",
"LLVMLinker",
"LLVMFrontendOpenMP",
"LLVMFrontendDirective",
"LLVMFrontendAtomic",
"LLVMFrontendOffloading",
"LLVMObjectYAML",
"LLVMDWARFLinkerParallel",
"LLVMDWARFLinkerClassic",
"LLVMDWARFLinker",
@ -1374,7 +1413,9 @@ const llvm_libs = [_][]const u8{
"LLVMDebugInfoPDB",
"LLVMDebugInfoMSF",
"LLVMDebugInfoCodeView",
"LLVMDebugInfoGSYM",
"LLVMDebugInfoDWARF",
"LLVMDebugInfoDWARFLowLevel",
"LLVMObject",
"LLVMTextAPI",
"LLVMMCParser",
@ -1420,6 +1461,8 @@ const llvm_libs_xtensa = [_][]const u8{
};
fn generateLangRef(b: *std.Build) std.Build.LazyPath {
const io = b.graph.io;
const doctest_exe = b.addExecutable(.{
.name = "doctest",
.root_module = b.createModule(.{
@ -1429,17 +1472,18 @@ fn generateLangRef(b: *std.Build) std.Build.LazyPath {
}),
});
var dir = b.build_root.handle.openDir("doc/langref", .{ .iterate = true }) catch |err| {
var dir = b.build_root.handle.openDir(io, "doc/langref", .{ .iterate = true }) catch |err| {
std.debug.panic("unable to open '{f}doc/langref' directory: {s}", .{
b.build_root, @errorName(err),
});
};
defer dir.close();
defer dir.close(io);
var wf = b.addWriteFiles();
b.step("test-docs", "Test code snippets from the docs").dependOn(&wf.step);
var it = dir.iterateAssumeFirstIteration();
while (it.next() catch @panic("failed to read dir")) |entry| {
while (it.next(io) catch @panic("failed to read dir")) |entry| {
if (std.mem.startsWith(u8, entry.name, ".") or entry.kind != .file)
continue;

63
ci/aarch64-freebsd-debug.sh Executable file
View file

@ -0,0 +1,63 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="aarch64-freebsd-none"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.2287+eb3f16db5"
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 ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
--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

69
ci/aarch64-freebsd-release.sh Executable file
View file

@ -0,0 +1,69 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="aarch64-freebsd-none"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.2287+eb3f16db5"
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 ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
--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

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.15.0-dev.233+7c85dc460"
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.
@ -50,13 +44,15 @@ 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 44918199637 \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
-Denable-superhtml
-Denable-superhtml \
--test-timeout 3m
stage3-debug/bin/zig build \
--prefix stage4-debug \

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.15.0-dev.233+7c85dc460"
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.
@ -50,13 +44,15 @@ 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 44918199637 \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
-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 \

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.15.0-dev.233+7c85dc460"
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,24 @@ 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 \
--maxrss ${ZSF_MAX_RSS:-0} \
--zig-lib-dir "$PWD/../lib" \
-Denable-macos-sdk \
-Dstatic-llvm \
-Dskip-non-native \
--search-prefix "$PREFIX"
-Dskip-test-incremental \
--search-prefix "$PREFIX" \
--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

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.15.0-dev.233+7c85dc460"
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,17 +39,20 @@ 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"
-Dskip-test-incremental \
--search-prefix "$PREFIX" \
--test-timeout 2m
# Ensure that stage3 and stage4 are byte-for-byte identical.
stage3-release/bin/zig build \
--maxrss ${ZSF_MAX_RSS:-0} \
--prefix stage4-release \
-Denable-llvm \
-Dno-lib \
@ -68,6 +63,7 @@ stage3-release/bin/zig build \
-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
# https://codeberg.org/ziglang/zig/issues/30687
#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

63
ci/aarch64-netbsd-debug.sh Executable file
View file

@ -0,0 +1,63 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="aarch64-netbsd-none"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.2287+eb3f16db5"
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 ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
--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

69
ci/aarch64-netbsd-release.sh Executable file
View file

@ -0,0 +1,69 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="aarch64-netbsd-none"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.2287+eb3f16db5"
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 ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
--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

View file

@ -1,10 +1,11 @@
$TARGET = "$($Env:ARCH)-windows-gnu"
$ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.15.0-dev.233+7c85dc460"
$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"
$ZIG = "$PREFIX_PATH\bin\zig.exe"
$ZIG_LIB_DIR = "$(Get-Location)\lib"
$ZSF_MAX_RSS = if ($Env:ZSF_MAX_RSS) { $Env:ZSF_MAX_RSS } else { 0 }
if (!(Test-Path "..\$ZIG_LLVM_CLANG_LLD_NAME.zip")) {
Write-Output "Downloading $ZIG_LLVM_CLANG_LLD_URL"
@ -22,14 +23,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.
@ -62,11 +55,14 @@ CheckLastExitCode
Write-Output "Main test suite..."
& "stage3-release\bin\zig.exe" build test docs `
--maxrss $ZSF_MAX_RSS `
--zig-lib-dir "$ZIG_LIB_DIR" `
--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.

65
ci/loongarch64-linux-debug.sh Executable file
View file

@ -0,0 +1,65 @@
#!/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 ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
-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

71
ci/loongarch64-linux-release.sh Executable file
View file

@ -0,0 +1,71 @@
#!/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 ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
-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

67
ci/powerpc64le-linux-debug.sh Executable file
View file

@ -0,0 +1,67 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="powerpc64le-linux-musl"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.1594+9fa433d71"
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 ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
-Dtarget=native-native-musl \
-Dcpu=native+longcall \
--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

73
ci/powerpc64le-linux-release.sh Executable file
View file

@ -0,0 +1,73 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="powerpc64le-linux-musl"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.1594+9fa433d71"
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 ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
-Dtarget=native-native-musl \
-Dcpu=native+longcall \
--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

View file

@ -5,20 +5,14 @@
set -x
set -e
ARCH="$(uname -m)"
TARGET="$ARCH-linux-musl"
TARGET="riscv64-linux-musl"
MCPU="spacemit_x60"
CACHE_BASENAME="zig+llvm+lld+clang-riscv64-linux-musl-0.15.0-dev.929+31e46be74"
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"
# 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.
@ -49,14 +43,12 @@ 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-asm-link test-llvm-ir \
--maxrss 68719476736 \
stage3-debug/bin/zig build test-modules test-c-abi \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-single-threaded \
-Dskip-compile-errors \
-Dskip-translate-c \
-Dskip-run-translated-c \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib"
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m

View file

@ -5,20 +5,14 @@
set -x
set -e
ARCH="$(uname -m)"
TARGET="$ARCH-linux-musl"
TARGET="riscv64-linux-musl"
MCPU="spacemit_x60"
CACHE_BASENAME="zig+llvm+lld+clang-riscv64-linux-musl-0.15.0-dev.929+31e46be74"
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"
# 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.
@ -49,14 +43,12 @@ 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-asm-link test-llvm-ir \
--maxrss 68719476736 \
stage3-release/bin/zig build test-modules test-c-abi \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-single-threaded \
-Dskip-compile-errors \
-Dskip-translate-c \
-Dskip-run-translated-c \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib"
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m

66
ci/s390x-linux-debug.sh Executable file
View file

@ -0,0 +1,66 @@
#!/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 ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
-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

72
ci/s390x-linux-release.sh Executable file
View file

@ -0,0 +1,72 @@
#!/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 ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
-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

69
ci/x86_64-freebsd-debug.sh Executable file
View file

@ -0,0 +1,69 @@
#!/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 ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-spirv \
-Dskip-wasm \
-Dskip-linux \
-Dskip-netbsd \
-Dskip-openbsd \
-Dskip-windows \
-Dskip-darwin \
-Dskip-test-incremental \
--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

75
ci/x86_64-freebsd-release.sh Executable file
View file

@ -0,0 +1,75 @@
#!/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 ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-spirv \
-Dskip-wasm \
-Dskip-linux \
-Dskip-netbsd \
-Dskip-openbsd \
-Dskip-windows \
-Dskip-darwin \
-Dskip-test-incremental \
--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

38
ci/x86_64-linux-debug-llvm.sh Normal file → Executable file
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.15.0-dev.233+7c85dc460"
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-10.0.2/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-v42.0.1-x86_64-linux:$HOME/deps/qemu-linux-x86_64-10.2.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
@ -40,7 +34,10 @@ cmake .. \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-DZIG_EXTRA_BUILD_ARGS="-Duse-llvm=true" \
-GNinja
-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.
@ -55,16 +52,31 @@ stage3-debug/bin/zig build \
-Dno-lib
stage3-debug/bin/zig build test docs \
--maxrss 21000000000 \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dlldb=$HOME/deps/lldb-zig/Debug-e0a42bb34/bin/lldb \
-Dlibc-test-path=$HOME/deps/libc-test-f2bac77 \
-fqemu \
-fwasmtime \
-Dstatic-llvm \
-Dskip-freebsd \
-Dskip-netbsd \
-Dskip-openbsd \
-Dskip-windows \
-Dskip-macos \
-Dskip-darwin \
-Dskip-test-incremental \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
-Denable-superhtml
-Denable-superhtml \
--test-timeout 12m
stage3-debug/bin/zig build \
--prefix stage4-debug \
-Duse-llvm \
-Denable-llvm \
-Dno-lib \
-Dtarget=$TARGET \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-debug/bin/zig version)"
stage4-debug/bin/zig test ../test/behavior.zig

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.15.0-dev.233+7c85dc460"
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-10.0.2/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-v42.0.1-x86_64-linux:$HOME/deps/qemu-linux-x86_64-10.2.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
@ -39,7 +33,10 @@ cmake .. \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja
-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.
@ -54,17 +51,30 @@ stage3-debug/bin/zig build \
-Dno-lib
stage3-debug/bin/zig build test docs \
--maxrss 21000000000 \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dlldb=$HOME/deps/lldb-zig/Debug-e0a42bb34/bin/lldb \
-fqemu \
-fwasmtime \
-Dstatic-llvm \
-Dskip-freebsd \
-Dskip-netbsd \
-Dskip-openbsd \
-Dskip-windows \
-Dskip-macos \
-Dskip-darwin \
-Dskip-llvm \
-Dskip-test-incremental \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
-Denable-superhtml
-Denable-superhtml \
--test-timeout 10m
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

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.15.0-dev.233+7c85dc460"
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-10.0.2/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-v42.0.1-x86_64-linux:$HOME/deps/qemu-linux-x86_64-10.2.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
@ -45,7 +39,10 @@ cmake .. \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja
-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.
@ -60,15 +57,18 @@ stage3-release/bin/zig build \
-Dno-lib
stage3-release/bin/zig build test docs \
--maxrss 21000000000 \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dlldb=$HOME/deps/lldb-zig/Release-e0a42bb34/bin/lldb \
-Dlibc-test-path=$HOME/deps/libc-test-f2bac77 \
-fqemu \
-fwasmtime \
-Dstatic-llvm \
-Dskip-test-incremental \
-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 \
@ -102,7 +102,10 @@ cmake .. \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
unset CC
unset CXX

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.15.0-dev.233+7c85dc460"
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

63
ci/x86_64-netbsd-debug.sh Executable file
View file

@ -0,0 +1,63 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="x86_64-netbsd-none"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.2287+eb3f16db5"
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 ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
--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

69
ci/x86_64-netbsd-release.sh Executable file
View file

@ -0,0 +1,69 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="x86_64-netbsd-none"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.2287+eb3f16db5"
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 ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
--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

63
ci/x86_64-openbsd-debug.sh Executable file
View file

@ -0,0 +1,63 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="x86_64-openbsd-none"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.2051+28b83e3b0"
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 ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
--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

69
ci/x86_64-openbsd-release.sh Executable file
View file

@ -0,0 +1,69 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="x86_64-openbsd-none"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.2051+28b83e3b0"
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 ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
--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

View file

@ -1,19 +1,9 @@
$TARGET = "$($Env:ARCH)-windows-gnu"
$ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.15.0-dev.233+7c85dc460"
$TARGET = "x86_64-windows-gnu"
$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"
$PREFIX_PATH = "$($Env:USERPROFILE)\deps\zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
$ZIG = "$PREFIX_PATH\bin\zig.exe"
$ZIG_LIB_DIR = "$(Get-Location)\lib"
if (!(Test-Path "$PREFIX_PATH.zip")) {
Write-Output "Downloading $ZIG_LLVM_CLANG_LLD_URL"
Invoke-WebRequest -Uri "$ZIG_LLVM_CLANG_LLD_URL" -OutFile "$PREFIX_PATH.zip"
Write-Output "Extracting..."
Add-Type -AssemblyName System.IO.Compression.FileSystem ;
[System.IO.Compression.ZipFile]::ExtractToDirectory("$PREFIX_PATH.zip", "$PREFIX_PATH\..")
}
$ZSF_MAX_RSS = if ($Env:ZSF_MAX_RSS) { $Env:ZSF_MAX_RSS } else { 0 }
function CheckLastExitCode {
if (!$?) {
@ -22,14 +12,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.
@ -42,7 +24,7 @@ Set-Location -Path 'build-debug'
# CMake gives a syntax error when file paths with backward slashes are used.
# Here, we use forward slashes only to work around this.
& cmake .. `
cmake .. `
-GNinja `
-DCMAKE_INSTALL_PREFIX="stage3-debug" `
-DCMAKE_PREFIX_PATH="$($PREFIX_PATH -Replace "\\", "/")" `
@ -61,49 +43,50 @@ ninja install
CheckLastExitCode
Write-Output "Main test suite..."
& "stage3-debug\bin\zig.exe" build test docs `
stage3-debug\bin\zig build test docs `
--maxrss $ZSF_MAX_RSS `
--zig-lib-dir "$ZIG_LIB_DIR" `
--search-prefix "$PREFIX_PATH" `
-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..."
& "stage3-debug\bin\zig.exe" test `
..\test\behavior.zig `
--zig-lib-dir "$ZIG_LIB_DIR" `
-ofmt=c `
-femit-bin="test-x86_64-windows-msvc.c" `
--test-no-exec `
-target x86_64-windows-msvc `
-lc
CheckLastExitCode
& "stage3-debug\bin\zig.exe" build-obj `
stage3-debug\bin\zig build-obj `
--zig-lib-dir "$ZIG_LIB_DIR" `
-ofmt=c `
-OReleaseSmall `
--name compiler_rt `
-femit-bin="compiler_rt-x86_64-windows-msvc.c" `
--dep build_options `
-target x86_64-windows-msvc `
-Mroot="..\lib\compiler_rt.zig" `
-Mbuild_options="config.zig"
-lc `
..\lib\compiler_rt.zig
CheckLastExitCode
Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
stage3-debug\bin\zig test `
--zig-lib-dir "$ZIG_LIB_DIR" `
-ofmt=c `
-femit-bin="behavior-x86_64-windows-msvc.c" `
--test-no-exec `
-target x86_64-windows-msvc `
-lc `
..\test\behavior.zig
CheckLastExitCode
Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools" `
Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
CheckLastExitCode
Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools" `
-DevCmdArguments '-arch=x64 -no_logo' `
-StartInPath $(Get-Location)
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 /I..\lib /W3 /Z7 behavior-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /link /nologo /debug /subsystem:console kernel32.lib ntdll.lib libcmt.lib ws2_32.lib
CheckLastExitCode
& .\test-x86_64-windows-msvc.exe
.\behavior-x86_64-windows-msvc
CheckLastExitCode

View file

@ -1,19 +1,9 @@
$TARGET = "$($Env:ARCH)-windows-gnu"
$ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.15.0-dev.233+7c85dc460"
$TARGET = "x86_64-windows-gnu"
$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"
$PREFIX_PATH = "$($Env:USERPROFILE)\deps\zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
$ZIG = "$PREFIX_PATH\bin\zig.exe"
$ZIG_LIB_DIR = "$(Get-Location)\lib"
if (!(Test-Path "$PREFIX_PATH.zip")) {
Write-Output "Downloading $ZIG_LLVM_CLANG_LLD_URL"
Invoke-WebRequest -Uri "$ZIG_LLVM_CLANG_LLD_URL" -OutFile "$PREFIX_PATH.zip"
Write-Output "Extracting..."
Add-Type -AssemblyName System.IO.Compression.FileSystem ;
[System.IO.Compression.ZipFile]::ExtractToDirectory("$PREFIX_PATH.zip", "$PREFIX_PATH\..")
}
$ZSF_MAX_RSS = if ($Env:ZSF_MAX_RSS) { $Env:ZSF_MAX_RSS } else { 0 }
function CheckLastExitCode {
if (!$?) {
@ -22,14 +12,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.
@ -42,7 +24,7 @@ Set-Location -Path 'build-release'
# CMake gives a syntax error when file paths with backward slashes are used.
# Here, we use forward slashes only to work around this.
& cmake .. `
cmake .. `
-GNinja `
-DCMAKE_INSTALL_PREFIX="stage3-release" `
-DCMAKE_PREFIX_PATH="$($PREFIX_PATH -Replace "\\", "/")" `
@ -61,17 +43,20 @@ ninja install
CheckLastExitCode
Write-Output "Main test suite..."
& "stage3-release\bin\zig.exe" build test docs `
stage3-release\bin\zig.exe build test docs `
--maxrss $ZSF_MAX_RSS `
--zig-lib-dir "$ZIG_LIB_DIR" `
--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.
Write-Output "Build and compare stage4..."
& "stage3-release\bin\zig.exe" build `
stage3-release\bin\zig.exe build `
--prefix stage4-release `
-Denable-llvm `
-Dno-lib `
@ -89,39 +74,38 @@ Compare-Object (Get-Content stage3-release\bin\zig.exe) (Get-Content stage4-rele
CheckLastExitCode
Write-Output "Build x86_64-windows-msvc behavior tests using the C backend..."
& "stage3-release\bin\zig.exe" test `
..\test\behavior.zig `
--zig-lib-dir "$ZIG_LIB_DIR" `
-ofmt=c `
-femit-bin="test-x86_64-windows-msvc.c" `
--test-no-exec `
-target x86_64-windows-msvc `
-lc
CheckLastExitCode
& "stage3-release\bin\zig.exe" build-obj `
stage3-release\bin\zig.exe build-obj `
--zig-lib-dir "$ZIG_LIB_DIR" `
-ofmt=c `
-OReleaseSmall `
--name compiler_rt `
-femit-bin="compiler_rt-x86_64-windows-msvc.c" `
--dep build_options `
-target x86_64-windows-msvc `
-Mroot="..\lib\compiler_rt.zig" `
-Mbuild_options="config.zig"
-lc `
..\lib\compiler_rt.zig
CheckLastExitCode
Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
stage3-release\bin\zig.exe test `
--zig-lib-dir "$ZIG_LIB_DIR" `
-ofmt=c `
-femit-bin="behavior-x86_64-windows-msvc.c" `
--test-no-exec `
-target x86_64-windows-msvc `
-lc `
..\test\behavior.zig
CheckLastExitCode
Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools" `
Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
CheckLastExitCode
Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools" `
-DevCmdArguments '-arch=x64 -no_logo' `
-StartInPath $(Get-Location)
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 /I..\lib /W3 /Z7 behavior-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /link /nologo /debug /subsystem:console kernel32.lib ntdll.lib libcmt.lib ws2_32.lib
CheckLastExitCode
& .\test-x86_64-windows-msvc.exe
.\behavior-x86_64-windows-msvc
CheckLastExitCode

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.20
libclang-cpp.so.20.1
clang-cpp-20.0
clang-cpp200
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,23 +9,23 @@
find_path(LLD_INCLUDE_DIRS NAMES lld/Common/Driver.h
HINTS ${LLVM_INCLUDE_DIRS}
PATHS
/usr/lib/llvm-20/include
/usr/local/llvm200/include
/usr/local/llvm20/include
/usr/local/opt/lld@20/include
/opt/homebrew/opt/lld@20/include
/home/linuxbrew/.linuxbrew/opt/lld@20/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-20.0 lld200 lld NAMES_PER_DIR
find_library(LLD_LIBRARY NAMES lld-21.0 lld210 lld NAMES_PER_DIR
HINTS ${LLVM_LIBDIRS}
PATHS
/usr/lib/llvm-20/lib
/usr/local/llvm200/lib
/usr/local/llvm20/lib
/usr/local/opt/lld@20/lib
/opt/homebrew/opt/lld@20/lib
/home/linuxbrew/.linuxbrew/opt/lld@20/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})
@ -36,12 +36,12 @@ else()
HINTS ${LLVM_LIBDIRS}
PATHS
${LLD_LIBDIRS}
/usr/lib/llvm-20/lib
/usr/local/llvm200/lib
/usr/local/llvm20/lib
/usr/local/opt/lld@20/lib
/opt/homebrew/opt/lld@20/lib
/home/linuxbrew/.linuxbrew/opt/lld@20/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-20 llvm-config-20.0 llvm-config200 llvm-config20 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-20.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 20 OR "${LLVM_CONFIG_VERSION}" VERSION_EQUAL 21 OR "${LLVM_CONFIG_VERSION}" VERSION_GREATER 21)
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 20.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 20.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 20.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)
@ -315,30 +315,31 @@ 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(LLVMSandboxIR)
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(LLVMFrontendAtomic)
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)
@ -367,7 +368,9 @@ else()
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)

View file

@ -128,6 +128,7 @@
}
.table-wrapper {
width: 100%;
margin: 1em auto;
overflow-x: auto;
}
@ -317,7 +318,7 @@
<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.1/">0.14.1</a> |
<a href="https://ziglang.org/documentation/0.15.0/">0.15.0</a> |
<a href="https://ziglang.org/documentation/0.15.2/">0.15.2</a> |
master
</nav>
<nav aria-labelledby="table-of-contents">
@ -421,8 +422,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#}
@ -438,6 +438,25 @@
{#header_close#}
{#header_close#}
{#header_open|Identifiers#}
<p>
Identifiers must start with an alphabetic character or underscore and may be followed
by any number of alphanumeric characters or underscores.
They must not overlap with any keywords. See {#link|Keyword Reference#}.
</p>
{#header_open|String Identifier Syntax#}
<p>
If a name that does not fit these requirements is needed, such as for
linking with external libraries, the {#syntax#}@""{#endsyntax#} syntax
may be used.
</p>
{#code|identifiers.zig#}
{#header_close#}
{#header_close#}
{#header_open|Values#}
{#code|values.zig#}
@ -639,7 +658,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">
@ -963,6 +982,9 @@
humans and computers to do when reading code, and creates more optimization opportunities.
</p>
<p>
Variables are never allowed to shadow {#link|Identifiers#} from an outer scope.
</p>
<p>
The {#syntax#}extern{#endsyntax#} keyword or {#link|@extern#} builtin function can be used to link against a variable that is exported
from another object. The {#syntax#}export{#endsyntax#} keyword or {#link|@export#} builtin function
can be used to make a variable available to other objects at link time. In both cases,
@ -970,22 +992,6 @@
</p>
{#see_also|Exporting a C Library#}
{#header_open|Identifiers#}
<p>
Variable identifiers are never allowed to shadow identifiers from an outer scope.
</p>
<p>
Identifiers must start with an alphabetic character or underscore and may be followed
by any number of alphanumeric characters or underscores.
They must not overlap with any keywords. See {#link|Keyword Reference#}.
</p>
<p>
If a name that does not fit these requirements is needed, such as for linking with external libraries, the {#syntax#}@""{#endsyntax#} syntax may be used.
</p>
{#code|identifiers.zig#}
{#header_close#}
{#header_open|Container Level Variables#}
<p>
{#link|Container|Containers#} level variables have static lifetime and are order-independent and lazily analyzed.
@ -1969,6 +1975,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:
@ -2454,7 +2468,8 @@ or
{#header_open|Tagged union#}
<p>Unions can be declared with an enum tag type.
This turns the union into a <em>tagged</em> union, which makes it eligible
to use with {#link|switch#} expressions.
to use with {#link|switch#} expressions. When switching on tagged unions,
the tag value can be obtained using an additional capture.
Tagged unions coerce to their tag type: {#link|Type Coercion: Unions and Enums#}.
</p>
{#code|test_tagged_union.zig#}
@ -2496,6 +2511,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#}
@ -2586,6 +2602,13 @@ or
{#header_close#}
{#header_open|Switching on Errors#}
<p>
When switching on errors, some special cases are allowed to simplify generic programming patterns:
</p>
{#code|test_switch_on_errors.zig#}
{#header_close#}
{#header_open|Labeled switch#}
<p>
When a switch statement is labeled, it can be referenced from a
@ -2651,12 +2674,13 @@ or
{#code|test_inline_else.zig#}
<p>
When using an inline prong switching on an union an additional
capture can be used to obtain the union's enum tag value.
When using an inline prong switching on an union an additional capture
can be used to obtain the union's enum tag value at comptime, even though
its payload might only be known at runtime.
</p>
{#code|test_inline_switch_union_tag.zig#}
{#see_also|inline while|inline for#}
{#see_also|inline while|inline for|Tagged union#}
{#header_close#}
{#header_close#}
@ -3016,7 +3040,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#}
@ -3441,6 +3465,52 @@ void do_a_thing(struct Foo *foo) {
</p>
{#code|test_integer_widening.zig#}
{#header_close#}
{#header_open|Type Coercion: Int to Float#}
<p>
{#link|Integers#} coerce to {#link|Floats#} if every possible integer value can be stored in the float
without rounding (i.e. the integer's precision does not exceed the float's significand precision).
Larger integer types that cannot be safely coerced must be explicitly casted with {#link|@floatFromInt#}.
</p>
<div class="table-wrapper">
<table>
<thead>
<tr>
<th scope="col">Float Type</th>
<th scope="col">Largest Integer Types</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">{#syntax#}f16{#endsyntax#}</th>
<td>{#syntax#}i12{#endsyntax#} and {#syntax#}u11{#endsyntax#}</td>
</tr>
<tr>
<th scope="row">{#syntax#}f32{#endsyntax#}</th>
<td>{#syntax#}i25{#endsyntax#} and {#syntax#}u24{#endsyntax#}</td>
</tr>
<tr>
<th scope="row">{#syntax#}f64{#endsyntax#}</th>
<td>{#syntax#}i54{#endsyntax#} and {#syntax#}u53{#endsyntax#}</td>
</tr>
<tr>
<th scope="row">{#syntax#}f80{#endsyntax#}</th>
<td>{#syntax#}i65{#endsyntax#} and {#syntax#}u64{#endsyntax#}</td>
</tr>
<tr>
<th scope="row">{#syntax#}f128{#endsyntax#}</th>
<td>{#syntax#}i114{#endsyntax#} and {#syntax#}u113{#endsyntax#}</td>
</tr>
<tr>
<th scope="row">{#syntax#}c_longdouble{#endsyntax#}</th>
<td>Varies by target</td>
</tr>
</tbody>
</table>
</div>
{#code|test_int_to_float_coercion.zig#}
{#code|test_failed_int_to_float_coercion.zig#}
{#header_close#}
{#header_open|Type Coercion: Float to Int#}
<p>
@ -3715,9 +3785,9 @@ void do_a_thing(struct Foo *foo) {
<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>
@ -3831,9 +3901,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>
@ -4888,8 +4958,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
@ -5747,41 +5817,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>
@ -6277,10 +6381,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#}.
@ -6290,7 +6390,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#}.
@ -6313,14 +6413,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#}
@ -6355,17 +6459,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
@ -6996,8 +7089,7 @@ WebAssembly.instantiate(typedArray, {
The result is 3{#end_shell_samp#}
{#header_close#}
{#header_open|WASI#}
<p>Zig's support for WebAssembly System Interface (WASI) is under active development.
Example of using the standard library and reading command line arguments:</p>
<p>Zig standard library has first-class support for WebAssembly System Interface.</p>
{#code|wasi_args.zig#}
{#shell_samp#}$ wasmtime wasi_args.wasm 123 hello
@ -7059,6 +7151,7 @@ coding style.
<li>Data</li>
<li>Context</li>
<li>Manager</li>
<li>State</li>
<li>utils, misc, or somebody's initials</li>
</ul>
<p>Everything is a value, all types are data, everything is context, all logic manages state.
@ -7084,6 +7177,31 @@ coding style.
cannot be any more specific without being incorrect.</p>
{#header_close#}
{#header_open|Refrain from Underscore Prefixes#}
<p>In some programming languages, it is common to prefix identifiers with
underscores {#syntax#}_like_this{#endsyntax#} to avoid keyword
collisions, name collisions, or indicate additional metadata associated with usage of the
identifier, such as: privacy, existence of complex data invariants, exclusion from
semantic versioning, or context-specific type reflection meaning.
</p>
<p>In Zig, there are no private fields, and this style guide recommends
against pretending otherwise. Instead, fields should be named carefully
based on their semantics and documentation should indicate how to use
fields without violating data invariants. If a field is not subject to
the same semantic versioning rules as everything else, the exception
should be noted in the {#link|Doc Comments#}.
</p>
<p>As for {#link|type reflection|@typeInfo#}, it is less error prone and
more maintainable to use the type system than to make field names
meaningful.</p>
<p>Regarding name collisions, an underscore is insufficient to explain
the difference between the two otherwise identical names. If there's no
danger in getting them mixed up, then this guide recommends more verbose
names at outer scopes and more abbreviated names at inner scopes.</p>
<p>Finally, keyword collisions are better avoided via
{#link|String Identifier Syntax#}.</p>
{#header_close#}
{#header_open|Whitespace#}
<ul>
<li>
@ -7107,10 +7225,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
@ -7149,8 +7269,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,
@ -7804,11 +7923,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
@ -7837,7 +7956,6 @@ Statement
/ KEYWORD_errdefer Payload? BlockExprStatement
/ IfStatement
/ LabeledStatement
/ SwitchExpr
/ VarDeclExprStatement
ComptimeStatement
@ -7848,7 +7966,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)
@ -7902,7 +8020,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
@ -7952,7 +8070,6 @@ PrimaryTypeExpr
/ KEYWORD_anyframe
/ KEYWORD_unreachable
/ STRINGLITERAL
/ SwitchExpr
ContainerDecl <- (KEYWORD_extern / KEYWORD_packed)? ContainerDeclAuto
@ -7965,6 +8082,7 @@ IfTypeExpr <- IfPrefix TypeExpr (KEYWORD_else Payload? TypeExpr)?
LabeledTypeExpr
<- BlockLabel Block
/ BlockLabel? LoopTypeExpr
/ BlockLabel? SwitchExpr
LoopTypeExpr <- KEYWORD_inline? (ForTypeExpr / WhileTypeExpr)
@ -8134,7 +8252,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)?
@ -8154,8 +8272,6 @@ AsmOutputList <- (AsmOutputItem COMMA)* AsmOutputItem?
AsmInputList <- (AsmInputItem COMMA)* AsmInputItem?
StringList <- (STRINGLITERAL COMMA)* STRINGLITERAL?
ParamDeclList <- (ParamDecl COMMA)* ParamDecl?
ExprList <- (Expr COMMA)* Expr?
@ -8202,7 +8318,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
@ -8212,46 +8328,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

View file

@ -17,7 +17,7 @@ pub fn main() !void {
.maximum = 0.20,
};
const category = threshold.categorize(0.90);
try std.fs.File.stdout().writeAll(@tagName(category));
std.log.info("category: {t}", .{category});
}
const std = @import("std");

View file

@ -2,9 +2,6 @@ pub const CallModifier = enum {
/// Equivalent to function call syntax.
auto,
/// Equivalent to async keyword used with function call syntax.
async_kw,
/// Prevents tail call optimization. This guarantees that the return
/// address will point to the callsite, as opposed to the callsite's
/// callsite. If the call is otherwise required to be tail-called
@ -17,7 +14,7 @@ pub const CallModifier = enum {
/// Asserts that the function call will not suspend. This allows a
/// non-async function to call an async function.
no_async,
no_suspend,
/// Guarantees that the call will be generated with tail call optimization.
/// If this is not possible, a compile error is emitted instead.

View file

@ -4,6 +4,7 @@ const c = @cImport({
@cInclude("stdio.h");
});
pub fn main() void {
if (@import("builtin").os.tag == .netbsd) return; // https://github.com/Vexu/arocc/issues/960
_ = c.printf("hello\n");
}

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

@ -35,7 +35,7 @@ fn charToDigit(c: u8) u8 {
test "parse u64" {
const result = try parseU64("1234", 10);
try std.testing.expect(result == 1234);
try std.testing.expectEqual(1234, result);
}
// test

View file

@ -1,7 +1,7 @@
const std = @import("std");
pub fn main() !void {
try std.fs.File.stdout().writeAll("Hello, World!\n");
pub fn main(init: std.process.Init) !void {
try std.Io.File.stdout().writeStreamingAll(init.io, "Hello, World!\n");
}
// exe=succeed

View file

@ -1,4 +1,4 @@
const expect = @import("std").testing.expect;
const expectEqual = @import("std").testing.expectEqual;
test "attempt to swap array elements with array initializer" {
var arr: [2]u32 = .{ 1, 2 };
arr = .{ arr[1], arr[0] };
@ -6,8 +6,8 @@ test "attempt to swap array elements with array initializer" {
// arr[0] = arr[1];
// arr[1] = arr[0];
// So this fails!
try expect(arr[0] == 2); // succeeds
try expect(arr[1] == 1); // fails
try expectEqual(2, arr[0]); // succeeds
try expectEqual(1, arr[1]); // fails
}
// test_error=

View file

@ -7,7 +7,7 @@ pub fn main() void {
const y = @shrExact(x, 2);
std.debug.print("value: {}\n", .{y});
if (builtin.cpu.arch.isRISCV() and builtin.zig_backend == .stage2_llvm) @panic("https://github.com/ziglang/zig/issues/24304");
if ((builtin.cpu.arch.isPowerPC() or 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

@ -1,11 +1,11 @@
const std = @import("std");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
test "no runtime side effects" {
var data: i32 = 0;
const T = @TypeOf(foo(i32, &data));
try comptime expect(T == i32);
try expect(data == 0);
try comptime expectEqual(i32, T);
try expectEqual(0, data);
}
fn foo(comptime T: type, ptr: *T) T {

View file

@ -1,13 +1,13 @@
const std = @import("std");
const Allocator = std.mem.Allocator;
const expect = std.testing.expect;
const expectEqualStrings = std.testing.expectEqualStrings;
test "using an allocator" {
var buffer: [100]u8 = undefined;
var fba = std.heap.FixedBufferAllocator.init(&buffer);
const allocator = fba.allocator();
const result = try concat(allocator, "foo", "bar");
try expect(std.mem.eql(u8, "foobar", result));
try expectEqualStrings("foobar", result);
}
fn concat(allocator: Allocator, a: []const u8, b: []const u8) ![]u8 {

View file

@ -1,11 +1,11 @@
const std = @import("std");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
test "allowzero" {
var zero: usize = 0; // var to make to runtime-known
_ = &zero; // suppress 'var is never mutated' error
const ptr: *allowzero i32 = @ptrFromInt(zero);
try expect(@intFromPtr(ptr) == 0);
try expectEqual(0, @intFromPtr(ptr));
}
// test

View file

@ -1,5 +1,6 @@
const std = @import("std");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
test "fully anonymous struct" {
try check(.{
@ -11,11 +12,11 @@ test "fully anonymous struct" {
}
fn check(args: anytype) !void {
try expect(args.int == 1234);
try expect(args.float == 12.34);
try expectEqual(1234, args.int);
try expectEqual(12.34, args.float);
try expect(args.b);
try expect(args.s[0] == 'h');
try expect(args.s[1] == 'i');
try expectEqual('h', args.s[0]);
try expectEqual('i', args.s[1]);
}
// test

View file

@ -1,5 +1,5 @@
const std = @import("std");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
const Number = union {
int: i32,
@ -9,8 +9,8 @@ const Number = union {
test "anonymous union literal syntax" {
const i: Number = .{ .int = 42 };
const f = makeNumber();
try expect(i.int == 42);
try expect(f.float == 12.34);
try expectEqual(42, i.int);
try expectEqual(12.34, f.float);
}
fn makeNumber() Number {

View file

@ -1,4 +1,4 @@
const expect = @import("std").testing.expect;
const expectEqual = @import("std").testing.expectEqual;
const assert = @import("std").debug.assert;
const mem = @import("std").mem;
@ -29,7 +29,7 @@ test "iterate over an array" {
for (message) |byte| {
sum += byte;
}
try expect(sum == 'h' + 'e' + 'l' * 2 + 'o');
try expectEqual('h' + 'e' + 'l' * 2 + 'o', sum);
}
// modifiable array
@ -39,8 +39,8 @@ test "modify an array" {
for (&some_integers, 0..) |*item, i| {
item.* = @intCast(i);
}
try expect(some_integers[10] == 10);
try expect(some_integers[99] == 99);
try expectEqual(10, some_integers[10]);
try expectEqual(99, some_integers[99]);
}
// array concatenation works if the values are known
@ -91,8 +91,8 @@ const Point = struct {
};
test "compile-time array initialization" {
try expect(fancy_array[4].x == 4);
try expect(fancy_array[4].y == 8);
try expectEqual(4, fancy_array[4].x);
try expectEqual(8, fancy_array[4].y);
}
// call a function to initialize an array
@ -104,9 +104,9 @@ fn makePoint(x: i32) Point {
};
}
test "array initialization with function calls" {
try expect(more_points[4].x == 3);
try expect(more_points[4].y == 6);
try expect(more_points.len == 10);
try expectEqual(3, more_points[4].x);
try expectEqual(6, more_points[4].y);
try expectEqual(10, more_points.len);
}
// test

View file

@ -1,4 +1,4 @@
const expect = @import("std").testing.expect;
const expectEqual = @import("std").testing.expectEqual;
const expectEqualSlices = @import("std").testing.expectEqualSlices;
test "basic slices" {
@ -12,14 +12,14 @@ test "basic slices" {
try expectEqualSlices(i32, slice, alt_slice);
try expect(@TypeOf(slice) == []i32);
try expect(&slice[0] == &array[0]);
try expect(slice.len == array.len);
try expectEqual([]i32, @TypeOf(slice));
try expectEqual(&array[0], &slice[0]);
try expectEqual(array.len, slice.len);
// If you slice with comptime-known start and end positions, the result is
// a pointer to an array, rather than a slice.
const array_ptr = array[0..array.len];
try expect(@TypeOf(array_ptr) == *[array.len]i32);
try expectEqual(*[array.len]i32, @TypeOf(array_ptr));
// You can perform a slice-by-length by slicing twice. This allows the compiler
// to perform some optimisations like recognising a comptime-known length when
@ -28,13 +28,13 @@ test "basic slices" {
_ = &runtime_start;
const length = 2;
const array_ptr_len = array[runtime_start..][0..length];
try expect(@TypeOf(array_ptr_len) == *[length]i32);
try expectEqual(*[length]i32, @TypeOf(array_ptr_len));
// Using the address-of operator on a slice gives a single-item pointer.
try expect(@TypeOf(&slice[0]) == *i32);
try expectEqual(*i32, @TypeOf(&slice[0]));
// Using the `ptr` field gives a many-item pointer.
try expect(@TypeOf(slice.ptr) == [*]i32);
try expect(@intFromPtr(slice.ptr) == @intFromPtr(&slice[0]));
try expectEqual([*]i32, @TypeOf(slice.ptr));
try expectEqual(@intFromPtr(slice.ptr), @intFromPtr(&slice[0]));
// Slices have array bounds checking. If you try to access something out
// of bounds, you'll get a safety check failure:
@ -47,8 +47,8 @@ test "basic slices" {
const empty1 = &[0]u8{};
// If the type is known you can use this short hand:
const empty2: []u8 = &.{};
try expect(empty1.len == 0);
try expect(empty2.len == 0);
try expectEqual(0, empty1.len);
try expectEqual(0, empty2.len);
// A zero-length initialization can always be used to create an empty slice, even if the slice is mutable.
// This is because the pointed-to data is zero bits long, so its immutability is irrelevant.

View file

@ -1,5 +1,5 @@
const std = @import("std");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
const BitField = packed struct {
a: u3,
@ -9,13 +9,13 @@ const BitField = packed struct {
test "offsets of non-byte-aligned fields" {
comptime {
try expect(@bitOffsetOf(BitField, "a") == 0);
try expect(@bitOffsetOf(BitField, "b") == 3);
try expect(@bitOffsetOf(BitField, "c") == 6);
try expectEqual(0, @bitOffsetOf(BitField, "a"));
try expectEqual(3, @bitOffsetOf(BitField, "b"));
try expectEqual(6, @bitOffsetOf(BitField, "c"));
try expect(@offsetOf(BitField, "a") == 0);
try expect(@offsetOf(BitField, "b") == 0);
try expect(@offsetOf(BitField, "c") == 0);
try expectEqual(0, @offsetOf(BitField, "a"));
try expectEqual(0, @offsetOf(BitField, "b"));
try expectEqual(0, @offsetOf(BitField, "c"));
}
}

View file

@ -1,7 +1,7 @@
const expect = @import("std").testing.expect;
const expectEqual = @import("std").testing.expectEqual;
test "noinline function call" {
try expect(@call(.auto, add, .{ 3, 9 }) == 12);
try expectEqual(12, @call(.auto, add, .{ 3, 9 }));
}
fn add(a: i32, b: i32) i32 {

View file

@ -12,7 +12,7 @@ const AllocationError = error{
test "coerce subset to superset" {
const err = foo(AllocationError.OutOfMemory);
try std.testing.expect(err == FileOpenError.OutOfMemory);
try std.testing.expectEqual(FileOpenError.OutOfMemory, err);
}
fn foo(err: AllocationError) FileOpenError {

View file

@ -1,10 +1,10 @@
const std = @import("std");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
test "coercing large integer type to smaller one when value is comptime-known to fit" {
const x: u64 = 255;
const y: u8 = x;
try expect(y == 255);
try expectEqual(255, y);
}
// test

View file

@ -1,12 +1,12 @@
const std = @import("std");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
test "coerce to optionals wrapped in error union" {
const x: anyerror!?i32 = 1234;
const y: anyerror!?i32 = null;
try expect((try x).? == 1234);
try expect((try y) == null);
try expectEqual(1234, (try x).?);
try expectEqual(null, (try y));
}
// test

View file

@ -1,12 +1,12 @@
const std = @import("std");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
test "coerce to optionals" {
const x: ?i32 = 1234;
const y: ?i32 = null;
try expect(x.? == 1234);
try expect(y == null);
try expectEqual(1234, x.?);
try expectEqual(null, y);
}
// test

View file

@ -1,5 +1,7 @@
const std = @import("std");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
const expectEqualStrings = std.testing.expectEqualStrings;
const expectEqualSlices = std.testing.expectEqualSlices;
// You can assign constant pointers to arrays to a slice with
// const modifier on the element type. Useful in particular for
@ -7,48 +9,48 @@ const expect = std.testing.expect;
test "*const [N]T to []const T" {
const x1: []const u8 = "hello";
const x2: []const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
try expect(std.mem.eql(u8, x1, x2));
try expectEqualStrings(x1, x2);
const y: []const f32 = &[2]f32{ 1.2, 3.4 };
try expect(y[0] == 1.2);
try expectEqual(1.2, y[0]);
}
// Likewise, it works when the destination type is an error union.
test "*const [N]T to E![]const T" {
const x1: anyerror![]const u8 = "hello";
const x2: anyerror![]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
try expect(std.mem.eql(u8, try x1, try x2));
try expectEqualStrings(try x1, try x2);
const y: anyerror![]const f32 = &[2]f32{ 1.2, 3.4 };
try expect((try y)[0] == 1.2);
try expectEqual(1.2, (try y)[0]);
}
// Likewise, it works when the destination type is an optional.
test "*const [N]T to ?[]const T" {
const x1: ?[]const u8 = "hello";
const x2: ?[]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
try expect(std.mem.eql(u8, x1.?, x2.?));
try expectEqualStrings(x1.?, x2.?);
const y: ?[]const f32 = &[2]f32{ 1.2, 3.4 };
try expect(y.?[0] == 1.2);
try expectEqual(1.2, y.?[0]);
}
// In this cast, the array length becomes the slice length.
test "*[N]T to []T" {
var buf: [5]u8 = "hello".*;
const x: []u8 = &buf;
try expect(std.mem.eql(u8, x, "hello"));
try expectEqualStrings("hello", x);
const buf2 = [2]f32{ 1.2, 3.4 };
const x2: []const f32 = &buf2;
try expect(std.mem.eql(f32, x2, &[2]f32{ 1.2, 3.4 }));
try expectEqualSlices(f32, &[2]f32{ 1.2, 3.4 }, x2);
}
// Single-item pointers to arrays can be coerced to many-item pointers.
test "*[N]T to [*]T" {
var buf: [5]u8 = "hello".*;
const x: [*]u8 = &buf;
try expect(x[4] == 'o');
try expectEqual('o', x[4]);
// x[5] would be an uncaught out of bounds pointer dereference!
}
@ -56,7 +58,7 @@ test "*[N]T to [*]T" {
test "*[N]T to ?[*]T" {
var buf: [5]u8 = "hello".*;
const x: ?[*]u8 = &buf;
try expect(x.?[4] == 'o');
try expectEqual('o', x.?[4]);
}
// Single-item pointers can be cast to len-1 single-item arrays.
@ -64,14 +66,14 @@ test "*T to *[1]T" {
var x: i32 = 1234;
const y: *[1]i32 = &x;
const z: [*]i32 = y;
try expect(z[0] == 1234);
try expectEqual(1234, z[0]);
}
// 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');
try expectEqual('o', buf2[4]);
}
// test

View file

@ -1,11 +1,11 @@
const std = @import("std");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
test "coercion to error unions" {
const x: anyerror!i32 = 1234;
const y: anyerror!i32 = error.Failure;
try expect((try x) == 1234);
try expectEqual(1234, (try x));
try std.testing.expectError(error.Failure, y);
}

View file

@ -1,5 +1,5 @@
const std = @import("std");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
const Tuple = struct { u8, u8 };
test "coercion from homogeneous tuple to array" {

View file

@ -1,5 +1,5 @@
const std = @import("std");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
const E = enum {
one,
@ -28,22 +28,22 @@ const U2 = union(enum) {
test "coercion between unions and enums" {
const u = U{ .two = 12.34 };
const e: E = u; // coerce union to enum
try expect(e == E.two);
try expectEqual(E.two, e);
const three = E.three;
const u_2: U = three; // coerce enum to union
try expect(u_2 == E.three);
try expectEqual(E.three, u_2);
const u_3: U = .three; // coerce enum literal to union
try expect(u_3 == E.three);
try expectEqual(E.three, u_3);
const u_4: U2 = .a; // coerce enum literal to union with inferred enum tag type.
try expect(u_4.tag() == 1);
try expectEqual(1, u_4.tag());
// 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);
//try expectEqual(2, u_5.tag());
}
// test

View file

@ -1,4 +1,4 @@
const expect = @import("std").testing.expect;
const expectEqual = @import("std").testing.expectEqual;
const CmdFn = struct {
name: []const u8,
@ -32,9 +32,9 @@ fn performFn(comptime prefix_char: u8, start_value: i32) i32 {
}
test "perform fn" {
try expect(performFn('t', 1) == 6);
try expect(performFn('o', 0) == 1);
try expect(performFn('w', 99) == 99);
try expectEqual(6, performFn('t', 1));
try expectEqual(1, performFn('o', 0));
try expectEqual(99, performFn('w', 99));
}
// test

View file

@ -8,7 +8,7 @@ fn max(comptime T: type, a: T, b: T) T {
}
}
test "try to compare bools" {
try @import("std").testing.expect(max(bool, false, true) == true);
try @import("std").testing.expectEqual(true, max(bool, false, true));
}
// test

View file

@ -1,4 +1,4 @@
const expect = @import("std").testing.expect;
const expectEqual = @import("std").testing.expectEqual;
test "comptime @ptrFromInt" {
comptime {
@ -6,8 +6,8 @@ test "comptime @ptrFromInt" {
// ptr is never dereferenced.
const ptr: *i32 = @ptrFromInt(0xdeadbee0);
const addr = @intFromPtr(ptr);
try expect(@TypeOf(addr) == usize);
try expect(addr == 0xdeadbee0);
try expectEqual(usize, @TypeOf(addr));
try expectEqual(0xdeadbee0, addr);
}
}

View file

@ -1,4 +1,4 @@
const expect = @import("std").testing.expect;
const expectEqual = @import("std").testing.expectEqual;
test "comptime pointers" {
comptime {
@ -6,7 +6,7 @@ test "comptime pointers" {
const ptr = &x;
ptr.* += 1;
x += 1;
try expect(ptr.* == 3);
try expectEqual(3, ptr.*);
}
}

View file

@ -1,5 +1,5 @@
const std = @import("std");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
test "comptime vars" {
var x: i32 = 1;
@ -8,8 +8,8 @@ test "comptime vars" {
x += 1;
y += 1;
try expect(x == 2);
try expect(y == 2);
try expectEqual(2, x);
try expectEqual(2, y);
if (y != 2) {
// This compile error never triggers because y is a comptime variable,

View file

@ -31,7 +31,7 @@ fn sum(numbers: []const i32) i32 {
}
test "variable values" {
try @import("std").testing.expect(sum_of_first_25_primes == 1060);
try @import("std").testing.expectEqual(1060, sum_of_first_25_primes);
}
// test

View file

@ -2,8 +2,8 @@ var y: i32 = add(10, x);
const x: i32 = add(12, 34);
test "container level variables" {
try expect(x == 46);
try expect(y == 56);
try expectEqual(46, x);
try expectEqual(56, y);
}
fn add(a: i32, b: i32) i32 {
@ -11,6 +11,6 @@ fn add(a: i32, b: i32) i32 {
}
const std = @import("std");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
// test

View file

@ -1,5 +1,5 @@
const std = @import("std");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
const print = std.debug.print;
fn deferExample() !usize {
@ -9,14 +9,14 @@ fn deferExample() !usize {
defer a = 2;
a = 1;
}
try expect(a == 2);
try expectEqual(2, a);
a = 5;
return a;
}
test "defer basics" {
try expect((try deferExample()) == 5);
try expectEqual(5, (try deferExample()));
}
// test

View file

@ -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

@ -1,12 +1,12 @@
const std = @import("std");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
test {
const a = {};
const b = void{};
try expect(@TypeOf(a) == void);
try expect(@TypeOf(b) == void);
try expect(a == b);
try expectEqual(void, @TypeOf(a));
try expectEqual(void, @TypeOf(b));
try expectEqual(a, b);
}
// test

View file

@ -1,5 +1,6 @@
const std = @import("std");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
const Color = enum {
auto,
@ -10,7 +11,7 @@ const Color = enum {
test "enum literals" {
const color1: Color = .auto;
const color2 = Color.auto;
try expect(color1 == color2);
try expectEqual(color1, color2);
}
test "switch using enum literals" {

View file

@ -1,4 +1,6 @@
const expect = @import("std").testing.expect;
const expectEqual = @import("std").testing.expectEqual;
const expectEqualStrings = @import("std").testing.expectEqualStrings;
const mem = @import("std").mem;
// Declare an enum.
@ -20,9 +22,9 @@ const Value = enum(u2) {
// Now you can cast between u2 and Value.
// The ordinal value starts from 0, counting up by 1 from the previous member.
test "enum ordinal value" {
try expect(@intFromEnum(Value.zero) == 0);
try expect(@intFromEnum(Value.one) == 1);
try expect(@intFromEnum(Value.two) == 2);
try expectEqual(0, @intFromEnum(Value.zero));
try expectEqual(1, @intFromEnum(Value.one));
try expectEqual(2, @intFromEnum(Value.two));
}
// You can override the ordinal value for an enum.
@ -32,9 +34,9 @@ const Value2 = enum(u32) {
million = 1000000,
};
test "set enum ordinal value" {
try expect(@intFromEnum(Value2.hundred) == 100);
try expect(@intFromEnum(Value2.thousand) == 1000);
try expect(@intFromEnum(Value2.million) == 1000000);
try expectEqual(100, @intFromEnum(Value2.hundred));
try expectEqual(1000, @intFromEnum(Value2.thousand));
try expectEqual(1000000, @intFromEnum(Value2.million));
}
// You can also override only some values.
@ -46,11 +48,11 @@ const Value3 = enum(u4) {
e,
};
test "enum implicit ordinal values and overridden values" {
try expect(@intFromEnum(Value3.a) == 0);
try expect(@intFromEnum(Value3.b) == 8);
try expect(@intFromEnum(Value3.c) == 9);
try expect(@intFromEnum(Value3.d) == 4);
try expect(@intFromEnum(Value3.e) == 5);
try expectEqual(0, @intFromEnum(Value3.a));
try expectEqual(8, @intFromEnum(Value3.b));
try expectEqual(9, @intFromEnum(Value3.c));
try expectEqual(4, @intFromEnum(Value3.d));
try expectEqual(5, @intFromEnum(Value3.e));
}
// Enums can have methods, the same as structs and unions.
@ -84,7 +86,7 @@ test "enum switch" {
Foo.number => "this is a number",
Foo.none => "this is a none",
};
try expect(mem.eql(u8, what_is_it, "this is a number"));
try expectEqualStrings(what_is_it, "this is a number");
}
// @typeInfo can be used to access the integer tag type of an enum.
@ -95,18 +97,18 @@ const Small = enum {
four,
};
test "std.meta.Tag" {
try expect(@typeInfo(Small).@"enum".tag_type == u2);
try expectEqual(u2, @typeInfo(Small).@"enum".tag_type);
}
// @typeInfo tells us the field count and the fields names:
test "@typeInfo" {
try expect(@typeInfo(Small).@"enum".fields.len == 4);
try expect(mem.eql(u8, @typeInfo(Small).@"enum".fields[1].name, "two"));
try expectEqual(4, @typeInfo(Small).@"enum".fields.len);
try expectEqualStrings(@typeInfo(Small).@"enum".fields[1].name, "two");
}
// @tagName gives a [:0]const u8 representation of an enum value:
test "@tagName" {
try expect(mem.eql(u8, @tagName(Small.three), "three"));
try expectEqualStrings(@tagName(Small.three), "three");
}
// test

View file

@ -1,4 +1,4 @@
const expect = @import("std").testing.expect;
const expectEqual = @import("std").testing.expectEqual;
test "error union" {
var foo: anyerror!i32 = undefined;
@ -10,10 +10,10 @@ test "error union" {
foo = error.SomeError;
// Use compile-time reflection to access the payload type of an error union:
try comptime expect(@typeInfo(@TypeOf(foo)).error_union.payload == i32);
try comptime expectEqual(i32, @typeInfo(@TypeOf(foo)).error_union.payload);
// Use compile-time reflection to access the error set type of an error union:
try comptime expect(@typeInfo(@TypeOf(foo)).error_union.error_set == anyerror);
try comptime expectEqual(anyerror, @typeInfo(@TypeOf(foo)).error_union.error_set);
}
// test

View file

@ -0,0 +1,8 @@
test "integer type is too large for implicit cast to float" {
var int: u25 = 123;
_ = &int;
const float: f32 = int;
_ = float;
}
// test_error=

View file

@ -1,4 +1,4 @@
const expect = @import("std").testing.expect;
const expectEqual = @import("std").testing.expectEqual;
fn fibonacci(index: u32) u32 {
//if (index < 2) return index;
@ -6,7 +6,7 @@ fn fibonacci(index: u32) u32 {
}
test "fibonacci" {
try comptime expect(fibonacci(7) == 13);
try comptime expectEqual(13, fibonacci(7));
}
// test_error=overflow of integer type

View file

@ -1,4 +1,4 @@
const expect = @import("std").testing.expect;
const expectEqual = @import("std").testing.expectEqual;
fn fibonacci(index: u32) u32 {
if (index < 2) return index;
@ -7,10 +7,10 @@ fn fibonacci(index: u32) u32 {
test "fibonacci" {
// test fibonacci at run-time
try expect(fibonacci(7) == 13);
try expectEqual(13, fibonacci(7));
// test fibonacci at compile-time
try comptime expect(fibonacci(7) == 13);
try comptime expectEqual(13, fibonacci(7));
}
// test

View file

@ -1,4 +1,5 @@
const std = @import("std");
const expectEqual = std.testing.expectEqual;
const Point = struct {
x: u32,
@ -8,23 +9,20 @@ const Point = struct {
};
test "field access by string" {
const expect = std.testing.expect;
var p = Point{ .x = 0, .y = 0 };
@field(p, "x") = 4;
@field(p, "y") = @field(p, "x") + 1;
try expect(@field(p, "x") == 4);
try expect(@field(p, "y") == 5);
try expectEqual(4, @field(p, "x"));
try expectEqual(5, @field(p, "y"));
}
test "decl access by string" {
const expect = std.testing.expect;
try expect(@field(Point, "z") == 1);
try expectEqual(1, @field(Point, "z"));
@field(Point, "z") = 2;
try expect(@field(Point, "z") == 2);
try expectEqual(2, @field(Point, "z"));
}
// test

View file

@ -3,8 +3,8 @@ const math = std.math;
const testing = std.testing;
test "fn reflection" {
try testing.expect(@typeInfo(@TypeOf(testing.expect)).@"fn".params[0].type.? == bool);
try testing.expect(@typeInfo(@TypeOf(testing.tmpDir)).@"fn".return_type.? == testing.TmpDir);
try testing.expectEqual(bool, @typeInfo(@TypeOf(testing.expect)).@"fn".params[0].type.?);
try testing.expectEqual(testing.TmpDir, @typeInfo(@TypeOf(testing.tmpDir)).@"fn".return_type.?);
try testing.expect(@typeInfo(@TypeOf(math.Log2Int)).@"fn".is_generic);
}

View file

@ -1,15 +1,15 @@
const expect = @import("std").testing.expect;
const expectEqual = @import("std").testing.expectEqual;
fn addFortyTwo(x: anytype) @TypeOf(x) {
return x + 42;
}
test "fn type inference" {
try expect(addFortyTwo(1) == 43);
try expect(@TypeOf(addFortyTwo(1)) == comptime_int);
try expectEqual(43, addFortyTwo(1));
try expectEqual(comptime_int, @TypeOf(addFortyTwo(1)));
const y: i64 = 2;
try expect(addFortyTwo(y) == 44);
try expect(@TypeOf(addFortyTwo(y)) == i64);
try expectEqual(44, addFortyTwo(y));
try expectEqual(i64, @TypeOf(addFortyTwo(y)));
}
// test

View file

@ -1,4 +1,4 @@
const expect = @import("std").testing.expect;
const expectEqual = @import("std").testing.expectEqual;
test "for basics" {
const items = [_]i32{ 4, 5, 3, 4, 0 };
@ -12,22 +12,22 @@ test "for basics" {
}
sum += value;
}
try expect(sum == 16);
try expectEqual(16, sum);
// To iterate over a portion of a slice, reslice.
for (items[0..1]) |value| {
sum += value;
}
try expect(sum == 20);
try expectEqual(20, sum);
// To access the index of iteration, specify a second condition as well
// as a second capture value.
var sum2: i32 = 0;
for (items, 0..) |_, i| {
try expect(@TypeOf(i) == usize);
try expectEqual(usize, @TypeOf(i));
sum2 += @as(i32, @intCast(i));
}
try expect(sum2 == 10);
try expectEqual(10, sum2);
// To iterate over consecutive integers, use the range syntax.
// Unbounded range is always a compile error.
@ -35,7 +35,7 @@ test "for basics" {
for (0..5) |i| {
sum3 += i;
}
try expect(sum3 == 10);
try expectEqual(10, sum3);
}
test "multi object for" {
@ -50,7 +50,7 @@ test "multi object for" {
count += i + j;
}
try expect(count == 21);
try expectEqual(21, count);
}
test "for reference" {
@ -62,9 +62,9 @@ test "for reference" {
value.* += 1;
}
try expect(items[0] == 4);
try expect(items[1] == 5);
try expect(items[2] == 3);
try expectEqual(4, items[0]);
try expectEqual(5, items[1]);
try expectEqual(3, items[2]);
}
test "for else" {
@ -79,10 +79,10 @@ test "for else" {
sum += value.?;
}
} else blk: {
try expect(sum == 12);
try expectEqual(12, sum);
break :blk sum;
};
try expect(result == 12);
try expectEqual(12, result);
}
// test

View file

@ -1,5 +1,5 @@
const std = @import("std");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
test "nested break" {
var count: usize = 0;
@ -9,7 +9,7 @@ test "nested break" {
break :outer;
}
}
try expect(count == 1);
try expectEqual(1, count);
}
test "nested continue" {
@ -21,7 +21,7 @@ test "nested continue" {
}
}
try expect(count == 8);
try expectEqual(8, count);
}
// test

View file

@ -1,7 +1,7 @@
const std = @import("std");
const builtin = @import("builtin");
const native_arch = builtin.cpu.arch;
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
// Functions are declared like this
fn add(a: i8, b: i8) i8 {
@ -57,8 +57,8 @@ fn doOp(fnCall: Call2Op, op1: i8, op2: i8) i8 {
}
test "function" {
try expect(doOp(add, 5, 6) == 11);
try expect(doOp(sub2, 5, 6) == -1);
try expectEqual(11, doOp(add, 5, 6));
try expectEqual(-1, doOp(sub2, 5, 6));
}
// test

View file

@ -1,5 +1,5 @@
const std = @import("std");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
comptime {
asm (
@ -14,7 +14,7 @@ comptime {
extern fn my_func(a: i32, b: i32) i32;
test "global assembly" {
try expect(my_func(12, 34) == 46);
try expectEqual(46, my_func(12, 34));
}
// test

Some files were not shown because too many files have changed in this diff Show more