WASILibc module

When porting existing projects from other platforms to SwiftWasm you might stumble upon code that relies on importing a platform-specific C library module directly. It looks like import Glibc on Linux, or import Darwin on Apple platforms. Fortunately, most of the standard C library APIs are available when using SwiftWasm, you just need to use import WASILibc to get access to it. Most probably you want to preserve compatibility with other platforms, thus your imports would look like this:

#if canImport(Darwin)
import Darwin
#elseif canImport(Glibc)
import Glibc
#elseif canImport(WASILibc)
import WASILibc
#endif

Limitations

WebAssembly and WASI provide a constrained environment, which currently does not directly support multi-threading, or filesystem access in the browser. Thus, you should not expect these APIs to work when importing WASILibc. Please be aware of these limitations when porting your code, which also has an impact on what can be supported in the Swift Foundation at the moment.