Getting to the compiler "internal" musl header files while compiling .c programs

I am working on getting an extension for a Python package (ruamel.yaml), that is now pre-compiled, distributed as source. The extension currently (still) consists of a couple of C files. I am doing this by making the package’s build depend on a extension package (setuptools-zig) and the ziglang package, both only needed at built time.

After getting this to work on my development machine (macOS arm), the same setup worked on my main server ( Linux Intel). After setting up a new alpine based VM (also on intel), I realised I was missing header files, which I had already installed on development machine and server.

After adding the headers on the alpine VM ( apk add musl-dev) the whole thing compilied and worked on alpine as well. Since the compiler comes with the musl header files I would like to not have that as a requirement for building this extension. How can I force the use of the internal include directories? ( I tried adding -target x86_64-linux-musl explicitly while compiling on Alpine, after removing musl-dev, but that did not work ).

some details:

After installation of ziglang, the compiler is called with

zig build-lib -dynamic -fallow-shlib-undefined -femit-bin=build/lib.linux-x86_64-cpython-312/_ruamel_yaml_ziglib.cpython-312-x86_64-linux-musl.so -I /opt/util/tmp_yamlziglib/include -I /usr/include/python3.12 -I /usr/include -O ReleaseFast _ruamel_yaml_ziglib.c api.c writer.c dumper.c loader.c reader.c scanner.c parser.c emitter.c 

The first -Iin there is not strictly necessary and the second -I is necessary to get at Python.h included by the the sources (those two are provided by the Python extension build system). The -I /usr/include is currently added by setuptools-zigas I found this necessary on Linux.

I can probably find the (temporary) directory where the header files are installed by parsing the output of zig env and then adding another -I option to that. Alternatively I can look into writing a build.zig file and invoke zig build if that is necessary.

Is there some commandline option for build-lib that I am overlooking?

It seems like you’re not actually linking libc. Try adding -lc

2 Likes

Indeed it looks like that enables the internal included paths (as well). I have to test a bit more but it also makes adding -I /usr/include unnecesary

I never would have tried that, as it was not needed to link against libc, to get things working when the headers were available (i.e.musl-dev installed).