Skip to content
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

make "gnu" (mingw-w64) the default C ABI on Windows #6565

Closed
andrewrk opened this issue Oct 5, 2020 · 5 comments · Fixed by #8878
Closed

make "gnu" (mingw-w64) the default C ABI on Windows #6565

andrewrk opened this issue Oct 5, 2020 · 5 comments · Fixed by #8878
Labels
accepted This proposal is planned. os-windows proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Oct 5, 2020

Currently if you download Zig on Windows, and then try to build some C code, without MSVC installed, you get an error saying that Zig cannot find or provide a libc. This is a shame because we actually can provide a libc! The magic sauce is -target native-native-gnu which uses mingw-w64 to provide libc.

This proposal is to make -gnu the default on windows rather than -msvc. This C ABI is binary-compatible with MSVC-compiled code, however the header files are not source-compatible with MSVC libc header files. When zig is responsible for compiling all of the C, C++, and Zig code for a given project, then there is 0 downsides to using mingw-w64 as the C ABI. The upsides are huge: no dependency on MSVC being installed. Zig acts as a C and C++ compiler that works out of the box, without MSVC installed.

I discussed this with @mlarouche on IRC and he indicated that it may sometimes be useful to specify -target native-native-msvc but that it does make sense to make the default mingw-w64.

Some more tid bits:

  • the plan is to make it .obj instead of .o always for coff, and to always use .lib (not .a) for libraries, ignoring gnu conventions
  • libc_installation.zig: make it look for msvc only if msvc abi is chosen

Related: #6363

@andrewrk andrewrk added proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. accepted This proposal is planned. os-windows labels Oct 5, 2020
@andrewrk andrewrk added this to the 0.7.0 milestone Oct 5, 2020
andrewrk referenced this issue Oct 5, 2020
See #6552 #6553 #6483

Also fixes a regression introduced in
1d777e9 of not converting an integer to
a string for a command line parameter.
@codehz
Copy link
Contributor

codehz commented Oct 5, 2020

btw, will it support specify exact output filename(including extension but not whole path) in install step?

@andrewrk
Copy link
Member Author

andrewrk commented Oct 5, 2020

Good question. Related: #6325

@RoyiAvital
Copy link

Zig's 0.8 Release Notes says:

Note that mingw-w64 is ABI-compatible with MSVC, so any build artifacts produced by one are consumable by the other. However the respective C header files are not always API-compatible, which is why there is still a use case for overriding the default.

As far as I know, you can't use / it might cause issues to use Static Libraries generated with MinGW64 in MSVC and vice versa.

@andrewrk
Copy link
Member Author

andrewrk commented Jun 5, 2021

As far as I know, you can't use / it might cause issues to use Static Libraries generated with MinGW64 in MSVC and vice versa.

Can you cite your source?

@RoyiAvital
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This proposal is planned. os-windows proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants