Skip to content

[types] Take libSystem's types from Apple's headers; MinGW's runtime stays its own - #1352

Merged
gmh5225 merged 1 commit into
devfrom
claude/crt-libsystem-headers
Oct 18, 2026
Merged

gmh5225 merged 1 commit into
devfrom
claude/crt-libsystem-headers

Conversation

@gmh5225

@gmh5225 gmh5225 commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Summary

This follows #1348, which made C and C++ headers take glibc's, bionic's and musl's types from the system's own headers where the compiler has them. It does the same for Apple's libSystem, and stops headers of Windows programs from colliding with MinGW's C runtime.

macOS and iOS programs

  • The Darwin libraries are systems too (HeaderLibrarySystems.def). The probe includes <TargetConditionals.h>, which clang's own TARGET_OS_* definitions answer as well, and tests TARGET_OS_OSX for macOS, or TARGET_OS_IOS without Mac Catalyst for iOS and its simulator.

  • On macOS or iOS, a macOS or iOS program's header takes libSystem's types from Apple's headers. Everywhere else it defines them itself. Before, it defined them everywhere, which collided with Apple's own headers on macOS: 22 errors.

  • generate_darwin_types.py now writes #pragma neverd_header before each type, as the Linux generator does. MacOSX64, MacOSARM64 and IOSARM64 are regenerated.

  • fetch_render_toolchains.py now also:

    • clones Apple's eight projects at the tags the Darwin libraries name;
    • installs their headers as the libraries read them;
    • records what clang takes to read them for each target.

    check_type_renders.py --system-library macos-x64|macos-arm64|ios-arm64 compiles on those installed headers.

Windows programs

  • MinGW's <stdint.h> declares the C runtime's records, tagLC_ID, threadlocaleinfostruct and localeinfo_struct, which the Windows user libraries a program joins also define: the header redefined them under MinGW.
  • The program's own types now take the compiler's prelude names (PreludeNames.def) the way the system's types do: another name for the header's own definitions, which leaves the compiler's name after it.
  • The table gains the Windows C runtimes' names under _WIN32 and MinGW's own under __MINGW32__.

Also

  • Reserved names: a type name that begins with an underscore is reserved at file scope in C, macOS's _opaque_pthread_t among them. A system's such types take another name on other compilers.
  • C++ tags: in C++, a record whose name a routine shares is referred to by its tag (struct stat), as stat() hides it.
  • Shipped library sources: the source a shipped library holds leaves out what only other compilers need, so the Linux libraries lose their member-macro lines.

Verification

A macOS program's header (safety_cases_macho_arm64, which joins libSystem's library), with checks and prototypes:

Compiled on Result
macOS arm64, with Apple's headers as the library read them (C, C as C++, C++) 0 errors
macOS x86-64 (zig), which defines the types itself 0 errors (22 before)
glibc x64 and ARM64 0 errors
MinGW x64 0 errors (2 before)
musl x64 0 errors
MSVC 11 errors: the checks of records with GNU bit-fields, such as the Mach message descriptors

check_type_renders.py

  • The default fixture and WindowsUserX64, WindowsUserX86 and WindowsKernelX64 have no failures. The MinGW compile of their Windows spelling failed 3 checks before.
  • With --system-library:
    • MacOSX64, MacOSARM64, IOSARM64, LinuxX64, LinuxX86 and MuslX64 fail only MSVC's GNU bit-fields;
    • AndroidX64 has no failures;
    • the Darwin libraries' Rust and Go now pass.
  • zig's macOS headers, of another SDK version, differ from the headers the libraries read in a few records, such as vm_statistics64, which the checks report. The checker compiles macOS's own system on the installed headers, and leaves zig's macOS of the same architecture out of the other systems.

Tests

  • New: SessionCAPITest.LibSystemsTypesComeFromApplesHeaders, TypeRender.TheWindowsRuntimesRecordsStayMinGWsUnderMinGW, TypeRender.KeywordBitfieldsAndPartlyNamedParametersRender.
  • NeverDTypesTests (139), NeverDSessionCAPITests (178) and NeverDLocalTypesDebugContextTests (6) pass, with the kernel inputs.

Generation

Limitations

  • iOS: zig holds no iOS headers. The iOS library's own system compiles on Apple's installed headers alone.
  • Microsoft's runtime: its own headers (UCRT) cannot be fetched without its license, so _locale_t and the other names Microsoft's runtime declares are taken from its documented <corecrt.h>, untested against it.
  • MSVC and GNU bit-fields: Microsoft's compilers still cannot lay out GNU's bit-fields, as [types] Take the C library's types from the system's own headers #1348 says.

…stays its own

#1348 took glibc's, bionic's and musl's types from the system's headers.
A macOS or iOS program's header defined libSystem's types everywhere,
which collided with Apple's own headers on macOS.  The Darwin libraries
are systems now: <TargetConditionals.h> tells macOS from iOS, the
regenerated libraries name each type's header, and elsewhere the header
defines them itself, every file-scope name that begins with an underscore
taking another name there.  The fetch script clones Apple's projects at
the libraries' tags and installs their headers, on which the checker
compiles the Darwin libraries' own systems.

A Windows program's records of the C runtime, which the Windows libraries
define and MinGW's <stdint.h> declares too, took no other name under
MinGW, which redefined them: a program's own types take the compiler's
prelude names now as a system's do, and the table gains the Windows C
runtimes' names.  In C++ a record a routine shares the name of goes by its
tag, as stat() hides struct stat.  Rust names the setter of a bit-field
called type set_type, and Go names every parameter where C names some.
@gmh5225
gmh5225 merged commit 08d957d into dev Oct 18, 2026
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.

2 participants