Skip to content

zig libc: Add -includes option #17133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 14, 2023
Merged

Conversation

squeek502
Copy link
Collaborator

@squeek502 squeek502 commented Sep 12, 2023

If -includes is passed to zig libc, it will print the detected libc include paths for the target and then exit

Examples on Linux:

$ zig libc -includes
/usr/include

$ zig libc -includes -target native-native-musl
/home/ryan/Programming/zig/zig/lib/libc/include/x86_64-linux-musl
/home/ryan/Programming/zig/zig/lib/libc/include/generic-musl
/home/ryan/Programming/zig/zig/lib/libc/include/x86-linux-any
/home/ryan/Programming/zig/zig/lib/libc/include/any-linux-any

$ zig libc -includes -target x86_64-windows
/home/ryan/Programming/zig/zig/lib/libc/include/x86_64-windows-gnu
/home/ryan/Programming/zig/zig/lib/libc/include/generic-mingw
/home/ryan/Programming/zig/zig/lib/libc/include/x86_64-windows-any
/home/ryan/Programming/zig/zig/lib/libc/include/any-windows-any

$ zig libc -includes -target x86_64-windows-msvc
error: no include dirs detected for target x86_64-windows.win8_1...win10_fe-msvc

On Windows:

> zig libc -includes
Programming\Zig\zig\lib\libc\include\x86_64-windows-gnu
Programming\Zig\zig\lib\libc\include\generic-mingw
Programming\Zig\zig\lib\libc\include\x86_64-windows-any
Programming\Zig\zig\lib\libc\include\any-windows-any

> zig libc -includes -target native-native-msvc
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\include
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\shared

> zig libc -includes -target x86_64-linux-musl
Programming\Zig\zig\lib\libc\include\x86_64-linux-musl
Programming\Zig\zig\lib\libc\include\generic-musl
Programming\Zig\zig\lib\libc\include\x86-linux-any
Programming\Zig\zig\lib\libc\include\any-linux-any

Interestingly, it seems the includes distributed with Zig are given as relative paths on Windows when it's possible (depends on CWD)

Motivation

The use case I have in mind for this is for the standalone version of resinator:

  • I want to be able to use zig clang as the first choice for the preprocessor
  • I want to be able to use -nostdinc when using zig clang as the preprocessor, meaning I would need to provide the include paths directly
  • and I want the include dirs to work as outlined in this comment, where it uses the MSVC includes if they are present, and falls back to the mingw includes distributed with Zig if MSVC is not present

This zig libc -includes command will allow me to do everything I want to do. Note, though, that this functionality doesn't necessarily have to be via zig libc, it could be something else if that'd make more sense.

Prints the detected libc include paths for the target and exits
@kubkon
Copy link
Member

kubkon commented Sep 13, 2023

Does it work as expected on macOS too?

@squeek502
Copy link
Collaborator Author

I don't have a Mac to test it with, would appreciate if someone could test it on Mac.

@ehaas
Copy link
Contributor

ehaas commented Sep 13, 2023

Tested on x86_64 macOS 13.5.2:

> ./stage3/bin/zig libc -includes
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include


> ./stage3/bin/zig libc -includes -target x86_64-linux-musl
stage3/lib/zig/libc/include/x86_64-linux-musl
stage3/lib/zig/libc/include/generic-musl
stage3/lib/zig/libc/include/x86-linux-any
stage3/lib/zig/libc/include/any-linux-any

> ./stage3/bin/zig libc -includes -target x86_64-windows
stage3/lib/zig/libc/include/x86_64-windows-gnu
stage3/lib/zig/libc/include/generic-mingw
stage3/lib/zig/libc/include/x86_64-windows-any
stage3/lib/zig/libc/include/any-windows-any

> ./stage3/bin/zig libc -includes -target x86_64-windows-msvc
error: no include dirs detected for target x86_64-windows.win8_1...win10_fe-msvc

@andrewrk andrewrk merged commit 30e1883 into ziglang:master Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants