42 Commits

Author SHA1 Message Date
GasInfinity 61cd38e8ac feat(libzigc): add common implementations of pthread_spin_*
* and remove their mingw, musl and wasi implementations
2026-04-21 09:03:06 +02:00
Alex Rønne Petersen 7ea8f842bc libzigc: move all unit tests from lib/c/ to test/c/
Before:

* test-zigc: run libzigc unit tests (part of test-modules)
* test-libc: run libc-test cases

Now:

* test-libc: run libc API unit tests (part of test-modules)
* test-libc-nsz: run libc-test cases

libc API unit tests (previously referred to as libzigc unit tests) now run for
all supported targets, even those we don't provide libzigc for. The idea is that
this will help us catch bad assumptions in the unit tests, as well as bugs in
other libcs.

I considered this setup:

* test-c: run libc API unit tests (part of test-modules)
* test-libc-nsz: run libc-test cases
* test-libc: both of the above

However, I do not like it because it gives a false sense of security; the full
module and C ABI test suites are still liable to catch libzigc bugs that test-c
and test-libc-nsz might not. So contributors should just run the test steps
outlined in https://codeberg.org/ziglang/zig/issues/30978.

Co-authored-by: rpkak <rpkak@noreply.codeberg.org>
2026-04-17 12:10:37 +02:00
Josh Megnauth 56507ecf98 libzigc: stropts/isastream
`isastream` is an old, deprecated function for the STREAMS framework.
Linux doesn't even support this natively, and so the musl implementation
just returns 0 (not a STREAMS file) for valid file descriptors or -1
(for bad file descriptors).
2026-04-02 15:13:39 +02:00
Josh Megnauth aaba36ff76 libzigc: posix_{fadvise, fallocate}, fallocate
This commit removes `posix_fadvise`, `posix_fallocate`, and `fallocate`
from the bundled musl by forwarding to Zig's wrappers. `musl`'s
implemenation does not use `__syscall_cp`, so I assume trivially
replacing these functions is okay.

For `posix_fadvise`, `musl` notes that the arguments are reordered
for ARM and other architectures. Zig's wrapper already handles this
case.

Contributes toward: #30978
2026-03-14 22:04:43 +01: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 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 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 6744160211 zig libc: implement malloc 2026-02-12 13:14:51 -08: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
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 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 d6b3dd25a0 chore(libzigc): document libc target checks 2026-01-18 00:26:42 +01: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 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
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
David Senoner 9399fcddce libc: use zig isnan and derivates for mingw 2025-08-27 03:58:32 +02:00
David 55848363fd libc: implement common abs for various integer sizes (#23893)
* libc: implement common `abs` for various integer sizes

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

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

* libc: export functions depending on the target libc

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

* remove empty ifs in inttypes

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

* remove empty ifs in stdlib

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

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

---------

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>
2025-05-21 00:57:38 +02:00
David 2c241b263c Introduce common bzero libc implementation. (#23812)
* Introduce common `bzero` libc implementation.

* Update test name according to review

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

* address code review

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

* bzero calling conv to .c

* Apply review

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

---------

Co-authored-by: Linus Groh <mail@linusgroh.de>
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2025-05-10 10:37:21 +02:00
Alex Rønne Petersen 1f896c1bf8 Introduce libzigc for libc function implementations in Zig.
This lays the groundwork for #2879. This library will be built and linked when a
static libc is going to be linked into the compilation. Currently, that means
musl, wasi-libc, and MinGW-w64. As a demonstration, this commit removes the musl
C code for a few string functions and implements them in libzigc. This means
that those libzigc functions are now load-bearing for musl and wasi-libc.

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

I repurposed the existing "universal libc" code to do this. That code hadn't
seen development beyond basic string functions in years, and was only usable-ish
on freestanding. I think that if we want to seriously pursue the idea of Zig
providing a freestanding libc, we should do so only after defining clear goals
(and non-goals) for it. See also #22240 for a similar case.
2025-04-11 17:12:31 +02:00
Linus Groh 79460d4a3e Remove uses of deprecated callconv aliases 2025-03-05 03:01:43 +00:00
Alex Rønne Petersen 9904a3ac9d c: Include Os.Tag.other in the list of freestanding OSs. 2024-11-08 14:56:55 +01:00
Alex Rønne Petersen 9e1dd3dec2 c: Use internal linkage when running tests.
This matches what we do for compiler-rt.
2024-11-08 14:56:25 +01:00
Andrew Kelley 1c45903274 handle _fltused in compiler_rt
so we don't have to do an entire compilation unit for just this silly
symbol
2024-10-23 16:27:39 -07:00
mlugg 6808ce27bd compiler,lib,test,langref: migrate @setCold to @branchHint 2024-08-27 00:44:35 +01:00
mlugg a3a737e9a6 lib,test,tools,doc: update usages of @export 2024-08-27 00:44:35 +01:00
Alex Rønne Petersen f9f8942008 std.os.linux: Move clone() here and stop exporting it. 2024-08-07 01:19:51 -07:00
Andrew Kelley 38e0f049c5 Merge pull request #20389 from alexrp/riscv32
Some `riscv32-linux` porting work
2024-07-29 16:13:35 -07:00
Alex Rønne Petersen f7cebf21c9 c: Handle armeb and thumbeb in clone(). 2024-07-29 13:24:29 -07:00
Alex Rønne Petersen b958225e68 c: Implement clone() for riscv32-linux. 2024-07-29 09:50:09 +02:00
Tristan Ross 9d70d614ae std.builtin: make link mode fields lowercase 2024-03-11 07:09:10 -07:00
Jacob Young 228c956377 std: finish cleanup up asm
This also required implementing the necessary syntax in the x86_64 backend.
2023-07-31 03:49:21 -04:00
Eric Joldasov 0a868dacdd std.cstr: deprecate namespace
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-25 14:51:03 -07:00
Suirad 7f24993772 Add support for mips64/mips64el 2023-02-04 15:19:53 -05:00
Ali Chraghi f5f1f8c666 all: rename i386 to x86 2022-11-04 00:09:27 +03:30
Andrew Kelley ce3ffa5e1b Merge pull request #11747 from Luukdegram/compiler-rt
compiler_rt: Move mem implementations from c.zig
2022-10-17 18:12:22 -04:00
Luuk de Gram f5edaa96dd compiler_rt: Move mem implementations from c.zig
This moves functions that LLVM generates calls to,
to the compiler_rt implementation itself, rather than c.zig.
This is a prerequisite for native backends to link with compiler-rt.
This also allows native backends to generate calls to `memcpy` and the like.
2022-10-15 07:02:38 -07:00
Robin Voetter 86f40d3ff6 zig_libc: do not call abort() on amdgpu 2022-10-12 20:36:15 +02:00
Veikka Tuominen 694fab4848 std: add return address parameter to panic fn 2022-09-20 19:05:00 -07:00
Andrew Kelley 7a941391d8 universal-libc: fix strncmp tests
The specification for this function is that it returns a positive value,
zero, or negative value, not that it returns the difference between
ascii values.
2022-09-12 22:32:15 -07:00
Veikka Tuominen ae7b32eb62 Sema: validate deref operator type and value 2022-07-01 10:22:25 +03:00
Koakuma fb0692334e target: Rename sparcv9 -> sparc64
Rename all references of sparcv9 to sparc64, to make Zig align more with
other projects. Also, added new function to convert glibc arch name to Zig
arch name, since it refers to the architecture as sparcv9.

This is based on the suggestion by @kubkon in PR 11847.
(https://github.com/ziglang/zig/pull/11487#pullrequestreview-963761757)
2022-05-13 16:43:59 -04:00
Andrew Kelley ec95e00e28 flatten lib/std/special and improve "pkg inside another" logic
stage2: change logic for detecting whether the main package is inside
the std package. Previously it relied on realpath() which is not portable.
This uses resolve() which is how imports already work.

 * stage2: fix cleanup bug when creating Module
 * flatten lib/std/special/* to lib/*
   - this was motivated by making main_pkg_is_inside_std false for
     compiler_rt & friends.
 * rename "mini libc" to "universal libc"
2022-05-06 22:41:00 -07:00