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.
This commit is contained in:
Alex Rønne Petersen
2025-04-10 19:17:29 +02:00
parent ee0ff134e9
commit 1f896c1bf8
15 changed files with 151 additions and 288 deletions

View File

@@ -145,7 +145,7 @@ const test_targets = blk: {
}) catch unreachable,
.use_llvm = false,
.use_lld = false,
.skip_modules = &.{ "c-import", "universal-libc", "std" },
.skip_modules = &.{ "c-import", "zigc", "std" },
},
// https://github.com/ziglang/zig/issues/13623
//.{
@@ -1443,9 +1443,9 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
test_target.use_llvm == false and mem.eql(u8, options.name, "compiler-rt"))
continue;
// TODO get universal-libc tests passing for other self-hosted backends.
// TODO get zigc tests passing for other self-hosted backends.
if (target.cpu.arch != .x86_64 and
test_target.use_llvm == false and mem.eql(u8, options.name, "universal-libc"))
test_target.use_llvm == false and mem.eql(u8, options.name, "zigc"))
continue;
// TODO get std lib tests passing for other self-hosted backends.