How zig decides which bundled libc include dirs to include for `@cImport`

there’s a bunch of libc folder in the <zig installation>/lib/libc/include I presume zig decides at least the top level directory(the platform specific) by checking the std.Target but say the target is a linux platform it will choose any-linux-any directory and my @cImport headers are trying to
import “time.h” header, it’s like in

<zig installation>
  -> lib
      -> libc
           -> include
               -> any-linux-any
                   -> linux
                       ->time.h

so in the any-linux-any directory you’ve to go one sub-directory(linux) deeper to get to that header, i am interested on how zig decides that when to go to one sub-directory/many sub-directory deeper after choosing the platform specific include directory. any reference in the zig source regarding it would be helpful.

These directories are described a bit in this blog post (scroll down to libc):
https://andrewkelley.me/post/zig-cc-powerful-drop-in-replacement-gcc-clang.html

I think it is just part of the tooling, the folders are generated in a specific way and once a specific libc is needed (I think) the different pieces are copied together again to generate a “normal” source. There also were different videos where Andrew / Loris talked about this but I currently don’t remember the specific links, maybe somebody else has them.

Normally you shouldn’t have to fiddle with these directories directly, except when you add a new libc version, you then would use the tool that generates the directories. And there is a tool / some code (somewhere) that uses those directories to build a libc when it is needed.

2 Likes