-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
provide a libc for windows using mingw-w64 #2868
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
zig can now cross compile hello.c targeting windows
windows.h has files such as pshpack1.h which do #pragma packing, triggering a clang warning. So for this target, this warning is disabled. this commit also improves the error message printed when no libc can be used, printing the "zig triple" rather than the "llvm triple".
|
Yep, that's what the last checkbox item is for. |
* fixed --verbose-cc printing an extra "zig" before the rest of the command line * windows-gnu targets use libfoo.a, foo.o extensions to match mingw conventions.
also zig build handles --verbose and linkSystemLibrary better
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is part of #514, shipping libc for every target. It adds the following libcs available (showing a snippet from
zig targets
here):This is done by shipping the headers from mingw-w64 project,
v6.0.0
(the latest tagged release). In addition to that, zig ships with the mingw-w64 C runtime source files, and lazily builds them from source for the target and then caches the result. When the result is not cached it takes about 60 seconds, which is one of the motivations for #2865.The instructions for updating to a newer mingw-w64 version are in the wiki: https://github.com/ziglang/zig/wiki/Updating-libc-Headers#windows
The total cost in bytes of this new feature is +59 MiB in installation size (+5 MiB in the download tarball size):
I think that's a small price to pay for being able to cross-compile for Windows out-of-the-box. That said, @daurnimator got me thinking about how features like this might be provided in the future with a more minimal zig core. A potential future project, once we have the Zig package manager (#943) would be to have zig packages able to provide a libc for a specific target. That requires the ability to plug into the linker driver. Something to consider for a future project.
With these changes, I can build
hello-world.c
on any machine and producehello-world.exe
:Until #2865 is done, a workaround to see progress is
--verbose-cc
.I took this a step further, and was able to build SDL2 for windows in the zig-sdl repo:
And running it on a Windows machine...
What about the msvc target ABI?
Zig can cross compile Zig code for the windows-msvc target. However, cross compiling C code for this target currently does not work, because the windows.h headers have some kind of incompatibility with clang's C .h headers with the target ABI set to MSVC. I'm not sure whose fault this is - mingw-w64, clang, or both - but a future project would be to send upstream patches to fix this. And then theoretically this same libc can handle both windows-gnu and windows-msvc, since they are in fact ABI-compatible.
Unfortunately we cannot ship microsoft's official windows.h headers due to license restrictions.
What's left to do before merging
#pragma pack alignment
warnings (they simply need to be silenced)x86_64-windows-gnu
to the test matrix