Skip to content
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

Add partial WASI/Wasm support. #301

Merged
merged 3 commits into from Mar 19, 2024
Merged

Add partial WASI/Wasm support. #301

merged 3 commits into from Mar 19, 2024

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Mar 18, 2024

This PR allows building using the SwiftWasm toolchain from https://swiftwasm.org. As of right now, macro plugins do not build correctly for Wasm, so swift-testing is not usable, but it is buildable!

Testing

A workaround is provided on the jgrynspan/wasi-workaround branch in order to facilitate testing. Check out that branch, then set the environment variable SWT_COMPILER_PLUGIN_ENABLED to 0 when building:

SWT_COMPILER_PLUGIN_ENABLED=0 swift build --triple wasm32-unknown-wasi

The macros target should build except for its main function (which will emit a warning about being unsupported) as should the primary library target. It is not possible to build the testing library's tests yet.

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

This PR allows building using the SwiftWasm toolchain from https://swiftwasm.org.
As of right now, macro plugins do not build correctly for WASM, so swift-testing
is not usable, but it is buildable!

 ## Testing

A workaround is provided on the [jgrynspan/wasi-workaround](https://github.com/apple/swift-testing/tree/jgrynspan/wasi-workaround)
branch in order to facilitate testing. Check out that branch, then set the
environment variable `SWT_COMPILER_PLUGIN_ENABLED` to `0` when building:

```sh
SWT_COMPILER_PLUGIN_ENABLED=0 swift build --triple wasm32-unknown-wasi
```

The macros target should build except for its main function (which will emit a
warning about being unsupported) as should the primary library target. It is not
possible to build the testing library's tests yet.
@grynspan grynspan added enhancement New feature or request wasi/wasm WebAssembly support labels Mar 18, 2024
@grynspan grynspan self-assigned this Mar 18, 2024
@grynspan
Copy link
Contributor Author

@swift-ci please test

@grynspan
Copy link
Contributor Author

@swift-ci please test

@briancroom
Copy link
Contributor

Neat!

@@ -140,7 +140,7 @@ struct FileHandle: ~Copyable, Sendable {
let fd: CInt = -1
#endif

if fd >= 0 {
if Bool(fd >= 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file doesn't build for WASI, however there's a dead-code warning here on platforms where fileno() isn't defined which is redundant in the face of our explicit warning, so this change silences it.

@grynspan
Copy link
Contributor Author

Holding until Yuta can take a look (it's 3AM in Tokyo so it may be a few minutes. 😄)

@grynspan grynspan changed the title Add partial WASI/WASM support. Add partial WASI/Wasm support. Mar 18, 2024
Copy link
Member

@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.

Fantastic! 🎉

[email protected] Show resolved Hide resolved
Sources/Testing/Support/Locked.swift Outdated Show resolved Hide resolved
@grynspan
Copy link
Contributor Author

This PR does not resolve #228 in its entirety, but it's a step toward it.

@grynspan
Copy link
Contributor Author

@swift-ci please test

@grynspan grynspan merged commit fe5a7cd into main Mar 19, 2024
2 checks passed
@grynspan grynspan deleted the jgrynspan/wasi branch March 19, 2024 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wasi/wasm WebAssembly support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants