Skip to content

Add support for WASILibc module #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 30, 2024
Merged

Add support for WASILibc module #159

merged 4 commits into from
Apr 30, 2024

Conversation

MaxDesiatov
Copy link
Member

@MaxDesiatov MaxDesiatov commented Apr 28, 2024

Quoting the wasi.dev landing page:

The WebAssembly System Interface (WASI) is a group of standard API specifications for software compiled to the W3C WebAssembly (Wasm) standard. WASI is designed to provide a secure standard interface for applications that can be compiled to Wasm from any language, and that may run anywhere—from browsers to clouds to embedded devices.

Currently support for WASI in Swift is based on wasi-libc.

Adding support for wasi-libc mostly amounted to excluding unsupported errnos, adding TLS dictionary storage shim for single-threaded environment, and adding constants in C headers for macros that Clang importer currently doesn't support.

This mostly amounted to excluding unsupported errnos, adding TLS dictionary storage shim for single-threaded environment, and adding constants in C headers for macros that Clang importer currently doesn't support.
@MaxDesiatov MaxDesiatov added the enhancement New feature or request label Apr 28, 2024
@MaxDesiatov MaxDesiatov self-assigned this Apr 28, 2024
@MaxDesiatov
Copy link
Member Author

@swift-ci test

@MaxDesiatov
Copy link
Member Author

MaxDesiatov commented Apr 28, 2024

Adding CI jobs for WASI is currently blocked by swiftlang/swift#72728.

@MaxDesiatov
Copy link
Member Author

@swift-ci test

@MaxDesiatov MaxDesiatov requested a review from milseman April 30, 2024 14:22
@MaxDesiatov
Copy link
Member Author

@swift-ci test

Copy link
Contributor

@kateinoigakukun kateinoigakukun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locally tested and it works well 👍

$ cat Sources/main.swift
import SystemPackage

let message: String = "Hello, world!" + "\n"
let path: FilePath = "/tmp/log"
let fd = try FileDescriptor.open(
  path, .writeOnly, options: [.append, .create], permissions: .ownerReadWrite)
try fd.closeAfter {
  _ = try fd.writeAll(message.utf8)
}
$ swift build --experimental-swift-sdk DEVELOPMENT-SNAPSHOT-2024-04-25-a-wasm32-unknown-wasi
$ wasmtime --dir /tmp .build/debug/Example.wasm
$ cat /tmp/log
Hello, world!

Co-authored-by: Guillaume Lessard <[email protected]>
@MaxDesiatov MaxDesiatov requested a review from glessard April 30, 2024 15:48
Copy link
Contributor

@glessard glessard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Do we have multi-threaded wasi support on swift/main?

@glessard
Copy link
Contributor

@swift-ci please test

@kateinoigakukun
Copy link
Contributor

@glessard Yes, we have multi-threaded wasi target as a separate triple (wasm32-unknown-wasip1-threads) from the non-threaded one (wasm32-unknown-wasi)

@MaxDesiatov
Copy link
Member Author

LGTM. Do we have multi-threaded wasi support on swift/main?

Yes, but that requires a special Swift SDK to be installed from artifacts built by the SwiftWasm org. There's ongoing work to build that on Swift CI directly in swiftlang/swift#72728.

@MaxDesiatov MaxDesiatov merged commit 40b6b0e into main Apr 30, 2024
2 checks passed
@MaxDesiatov MaxDesiatov deleted the maxd/wasi-support branch April 30, 2024 16:11
glessard pushed a commit to glessard/swift-system that referenced this pull request Oct 17, 2024
Quoting the [wasi.dev landing page](https://wasi.dev):
> The WebAssembly System Interface (WASI) is a group of standard API specifications for software compiled to the W3C WebAssembly (Wasm) standard. WASI is designed to provide a secure standard interface for applications that can be compiled to Wasm from any language, and that may run anywhere—from browsers to clouds to embedded devices.

Currently support for WASI in Swift is based on [`wasi-libc`](https://github.com/WebAssembly/wasi-libc).

Adding support for `wasi-libc` mostly amounted to excluding unsupported errnos, adding TLS dictionary storage shim for single-threaded environment, and adding constants in C headers for macros that Clang importer currently doesn't support.

Co-authored-by: Guillaume Lessard <[email protected]>

# Conflicts:
#	Sources/System/FileOperations.swift
#	Sources/System/Internals/Syscalls.swift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants