File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 9
9
- [ JavaScript interoperation] ( getting-started/javascript-interop.md )
10
10
- [ Swift Foundation] ( getting-started/foundation.md )
11
11
- [ Testing your app] ( getting-started/testing.md )
12
+ - [ ` WASILibc ` module] ( getting-started/libc.md )
12
13
- [ Examples] ( examples/index.md )
13
14
- [ Importing function] ( examples/importing-function.md )
14
15
- [ Exporting function] ( examples/exporting-function.md )
Original file line number Diff line number Diff line change
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.
You can’t perform that action at this time.
0 commit comments