Skip to content

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

@andrewrk

Description

@andrewrk

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThis proposal is planned.os-windowsMicrosoft WindowsproposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions