Skip to content

Commit d082419

Browse files
authored
Add a page about WASILibc module (#12)
* Add a page about `WASILibc` module * Refine wording * Refine wording
1 parent e599f09 commit d082419

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- [JavaScript interoperation](getting-started/javascript-interop.md)
1010
- [Swift Foundation](getting-started/foundation.md)
1111
- [Testing your app](getting-started/testing.md)
12+
- [`WASILibc` module](getting-started/libc.md)
1213
- [Examples](examples/index.md)
1314
- [Importing function](examples/importing-function.md)
1415
- [Exporting function](examples/exporting-function.md)

src/getting-started/libc.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# `WASILibc` module
2+
3+
When porting existing projects from other platforms to SwiftWasm you might stumble upon code that
4+
relies on importing a platform-specific [C
5+
library](https://en.wikipedia.org/wiki/C_standard_library) module directly. It looks like `import
6+
Glibc` on Linux, or `import Darwin` on Apple platforms. Fortunately, most of the standard C library
7+
APIs are available when using SwiftWasm, you just need to use `import WASILibc` to get access to it.
8+
Most probably you want to preserve compatibility with other platforms, thus your imports would look
9+
like this:
10+
11+
```swift
12+
#if canImport(Darwin)
13+
import Darwin
14+
#elseif canImport(Glibc)
15+
import Glibc
16+
#elseif canImport(WASILibc)
17+
import WASILibc
18+
#endif
19+
```
20+
21+
## Limitations
22+
23+
WebAssembly and [WASI](https://wasi.dev/) provide a constrained environment, which currently does
24+
not directly support multi-threading, or filesystem access in the browser. Thus, you should not
25+
expect these APIs to work when importing `WASILibc`. Please be aware of these limitations when
26+
porting your code, which also has an impact on what [can be supported in the Swift
27+
Foundation](/getting-started/foundation.md) at the moment.

0 commit comments

Comments
 (0)