zig icon indicating copy to clipboard operation
zig copied to clipboard

Missing `<sys/timex.h>` on MacOS

Open plajjan opened this issue 2 years ago • 0 comments

Zig Version

0.10.1

Steps to Reproduce and Observed Behavior

<sys/timex.h> is seemingly missing in the zig provided libc includes for macos while it is present on Linux.

Simple test program test_timex.c:

#include <sys/timex.h>

On Linux this compiles just fine

kll@Boxy:~/kod$ zig build-obj test_timex.c -lc
kll@Boxy:~/kod$

While on MacOS I get

kll@mbp:~/kod$ zig build-obj test_timex.c -lc
error(compilation): clang failed with stderr: test_timex.c:1:10: fatal error: 'sys/timex.h' file not found

test_timex.c:1:1: error: unable to build C object: clang exited with code 1

It works with the stock CC on Mac:

kll@mbp:~/kod$ cc -c test_timex.c -o test_timex

Looking in the headers shipped with zig I see timex.h is present for Linux but not Mac:

kll@Boxy:~/kod/zig$ find . -name timex.h
./lib/libc/include/generic-glibc/sys/timex.h
./lib/libc/include/generic-glibc/bits/timex.h
./lib/libc/include/generic-musl/sys/timex.h
./lib/libc/include/any-linux-any/linux/timex.h
./lib/libc/include/wasm-wasi-musl/sys/timex.h
./lib/libc/glibc/sysdeps/unix/sysv/linux/sys/timex.h
./lib/libc/glibc/sysdeps/unix/sysv/linux/include/sys/timex.h
./lib/libc/glibc/sysdeps/unix/sysv/linux/bits/timex.h
./lib/libc/musl/include/sys/timex.h
./lib/libc/wasi/libc-top-half/musl/include/sys/timex.h

timex.h is available on my MacOS system at /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/timex.h. If I merely copy that into my zig lib/libc/include/any-amcos-any/sys/timex.h, I can compile my program:

kll@Boxy:~/kod/zig$ cp /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/timex.h zig/lib/libc/include/any-macos-any/sys/
kll@Boxy:~/kod/zig$ cd ..
kll@Boxy:~/kod/$ zig build-obj test_timex.c -lc
kll@Boxy:~/kod/$ ls test_timex.o
test_timex.o
kll@Boxy:~/kod/$ 

Is this just an omission, can we add it in to the headers shipped with zig? Or am I missing something on how to use zig?

Expected Behavior

Compilation to work on MacOS the same way it does on Linux!

plajjan avatar Mar 08 '23 10:03 plajjan