zig icon indicating copy to clipboard operation
zig copied to clipboard

add OpenBSD libc as a cross compilation target

Open andrewrk opened this issue 6 years ago • 11 comments

Extracted from #514.

This is needed for OpenBSD to become a tier 1 target.

The example set by glibc can be followed.

See also this wiki page: https://github.com/ziglang/zig/wiki/Updating-libc

andrewrk avatar Jul 12 '19 22:07 andrewrk

@andrewrk is that link broken? It leads to a "create new page" for me.

norcalli avatar Dec 23 '19 11:12 norcalli

Is this the right wiki page? https://github.com/ziglang/zig/wiki/Updating-libc

same issue in : #2877 (NetBSD) and #2878 (OpenBSD)

redj avatar Dec 23 '19 17:12 redj

I fixed the link in andrew's comment.

daurnimator avatar Dec 24 '19 02:12 daurnimator

What should I do to add OpenBSD libc? This project can fetch openbsd libc files.

iacore avatar Mar 19 '22 14:03 iacore

@locriacyber, openbsd-ziglibc is getting real libc and headers files. I think what is expected here is to get only functions stubs.

semarie avatar Mar 19 '22 14:03 semarie

not header files? openbsd use clang as the compiler and I think it has its own libc headers. Given how OpenBSD has no ABI guarantee, every version of OpenBSD has its own libc.a libc.so to link with.

iacore avatar Mar 19 '22 14:03 iacore

to build C program (using zig compiler), you need both (libc stubs and header files). to build ZIG program (using zig compiler), you need only libc stubs (assuming no C dependency).

openbsd-ziglibc extracts the whole sets of C headers which are normally installed (~50 Mo for only one OS version and only one architecture).

(and not all architectures are using clang as compiler, but it is another discussion)

semarie avatar Mar 19 '22 14:03 semarie

What do you mean by "libc stubs" in case of OpenBSD? The symbol table of libc?

iacore avatar Mar 19 '22 15:03 iacore

Just stating for the record that, while I will be tackling both #2876 and #2877, it's very unlikely that I'll work on this one. As far as I can tell, OpenBSD has no support whatsoever for building on anything but OpenBSD; on the other hand, I was able to cross-compile both FreeBSD and NetBSD on Linux.

If an OpenBSD user wants to tackle this, however, I'm happy to help with everything but actually building libc.

alexrp avatar May 09 '25 20:05 alexrp

just for reference, at some point I was able to cross compile from Linux (I have not check if it is still working). see https://github.com/semarie/openbsd-ziglibc

it is a shell script (runnable on Linux after few modification), which will download objects/libs files from openbsd server, and create a environment suitable for ZIG_LIBC.

semarie avatar May 18 '25 08:05 semarie

The reason we need to build from source is that, in a release tarball/image, it is nearly impossible to separate the kernel + libc headers from all the other headers coming from various libraries.

alexrp avatar May 18 '25 15:05 alexrp