I would like to pitch a new module offered by Swift by default. The module would re-export the correct module that contains the POSIX or POSIX-like C standard library for the current platform, if any; it would not be imported by default, but would allow "reasonably cross-platform" code to avoid using lengthy
#if canImport(…) chains to gain access to all possible stdlibs, given that they have different names on different OSs.
For example, the module may be named
CStdlib. It would behave identically to a module whose entire source was:
#if canImport(Darwin) @_exported import Darwin #endif #if canImport(Glibc) @_exported import Glibc #endif #if canImport(CRT) // Win32 @_exported import CRT #endif #if canImport(WASILibc) @_exported import WASILibc #endif
This is not meant to overlap with Swift System; it provides no idiomatic types or harmonization between API, but it would help implementors of Swift System, Foundation and similar libraries reduce code complexity and automatically respond to platform additions as those are upstreamed.
Code that requires work on differences that are OS-specific, such as non-portable API, can still use the OS-specific module names; this does not obviate those.