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

Enable wasi-libc emulation features #777

Conversation

kateinoigakukun
Copy link
Member

@kateinoigakukun kateinoigakukun commented Jul 26, 2024

Those features require explicit macro definitions to be enabled, so add them to the package definition. Only affects WASI builds.

Note that we need explicit #include <mman.h> in the shim header because WASILibc clang module doesn't import mman.h by default (other libc clang modules including Glibc import it by default)

@kateinoigakukun
Copy link
Member Author

@swift-ci test

@kateinoigakukun kateinoigakukun force-pushed the pr-a861a2e8535dab5d7adc4cffea39cafdbfd0cea8 branch from 722f466 to 0b3e0f4 Compare July 26, 2024 14:40
@kateinoigakukun
Copy link
Member Author

@swift-ci test

@kateinoigakukun kateinoigakukun force-pushed the pr-a861a2e8535dab5d7adc4cffea39cafdbfd0cea8 branch from 0b3e0f4 to b10d2ee Compare July 29, 2024 05:33
@kateinoigakukun
Copy link
Member Author

@swift-ci test

@kateinoigakukun kateinoigakukun force-pushed the pr-a861a2e8535dab5d7adc4cffea39cafdbfd0cea8 branch 2 times, most recently from ef1273f to f125402 Compare July 30, 2024 03:48
@kateinoigakukun
Copy link
Member Author

@swift-ci test

@jmschonfeld
Copy link
Contributor

@swift-ci please test

Copy link
Contributor

@jmschonfeld jmschonfeld left a comment

Choose a reason for hiding this comment

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

This LGTM, but before we merge could we do a quick cross-repo test building the toolchain? That way we can test the CMake changes since CI on this repo doesn't (yet) build via CMake

Those features require explicit macro definitions to be enabled, so add
them to the package definition. Only affects WASI builds.
And explain why we need definition checks for `signal.h` and `sys/mman.h`
@kateinoigakukun kateinoigakukun force-pushed the pr-a861a2e8535dab5d7adc4cffea39cafdbfd0cea8 branch from 84cd6be to 2b88072 Compare August 3, 2024 07:42
@kateinoigakukun
Copy link
Member Author

@swift-ci test

@kateinoigakukun
Copy link
Member Author

Ok, confirmed CMake change does not break anything by cross repo CI

@kateinoigakukun kateinoigakukun merged commit c86692f into swiftlang:main Aug 5, 2024
3 checks passed
@kateinoigakukun kateinoigakukun deleted the pr-a861a2e8535dab5d7adc4cffea39cafdbfd0cea8 branch August 5, 2024 17:20
MaxDesiatov pushed a commit that referenced this pull request Aug 5, 2024
* Enable wasi-libc emulation features

Those features require explicit macro definitions to be enabled, so add
them to the package definition. Only affects WASI builds.

* Prefer `TARGET_OS_WASI` over `__wasi__`

And explain why we need definition checks for `signal.h` and `sys/mman.h`

(cherry picked from commit c86692f)
MaxDesiatov added a commit that referenced this pull request Aug 29, 2024
* Add explicit include of `wasi/libc-environ.h` (#786)

This is necessary to get the `__wasilibc_get_environ` function
declaration.

(cherry picked from commit 243066f)

* Add explicit void type parameter to C functions without parameters (#775)

C functions with `()` as parameter list can take any number of
parameters. But WebAssembly requires static signature information for
every function call, so we need to explicitly specify `(void)` to
indicate that the function takes no parameters.

(cherry picked from commit 8f34f38)

* Exclude EREMOTE definition for WASI platform (#778)

WASI does not define the EREMOTE error code.

(cherry picked from commit 6bb5ff7)

* Throw `.featureUnsupported` when attempting to create temp files on WASI (#779)

WASI does not have temp directory concept, and does not provide mktemp
family of functions, so attempting to create a temporary file should be
considered a feature unsupported.

(cherry picked from commit fb11420)

* Fix `operatingSystemVersion` on WASI (#782)

The `operatingSystemVersion` property type is a tuple but the it was
returning an `OperatingSystemVersion` instance on unknown platforms.

(cherry picked from commit a8f1225)

* Guard out extended or fs attributes related code on WASI (#784)

This commit guards out the extended attributes and file system
attributes related code on WASI as WASI does not support these
features. Just return nothing or ignore the set request.

(cherry picked from commit fab7195)

* Guard out user/group related code on WASI (#783)

* Guard out user/group related code on WASI

This change guards out the user/group related code on WASI, as WASI does
not have the concept of users or groups.

* Throw explicit unsupported error if trying to set user or group on WASI

Instead of implicitly ignoring user-given values, we should throw
exception to make it clear that those values cannot be set on WASI.

(cherry picked from commit 0b3974d)

* Skip sticky-bit check in `isDeletableFile` on WASI (#785)

WASI does not surface the sticky bit and getuid, so we cannot check
whether the file is actually deletable before attempting to delete it.

(cherry picked from commit e90b6c3)

* Implement `_copyRegularFile` for WASI without `sendfile` (#787)

WASI doesn't have `sendfile`, so we need to implement the copy in user
space with `read` and `write`. It's not as efficient as `sendfile`, but
it's the best we can do.

(cherry picked from commit 2a6afeb)

* Port `LockedState` and `_ThreadLocal` to WASI without any locking (#780)

(cherry picked from commit aa68eeb)

* Add WASI platform conditions for libc imports and word size (#776)

* Add `import WASILibc` statements to libc import chains

* Declare wasm32 arch as 32-bit environment

* Switch to _pointerBitWidth for architecture checks

This change switches the architecture checks in Data.swift to use the
_pointerBitWidth instead of the arch() checks for consistency with newer
platforms.

(cherry picked from commit c82d167)

* Enable wasi-libc emulation features (#777)

* Enable wasi-libc emulation features

Those features require explicit macro definitions to be enabled, so add
them to the package definition. Only affects WASI builds.

* Prefer `TARGET_OS_WASI` over `__wasi__`

And explain why we need definition checks for `signal.h` and `sys/mman.h`

(cherry picked from commit c86692f)

---------

Co-authored-by: Yuta Saito <[email protected]>
cthielen pushed a commit to cthielen/swift-foundation that referenced this pull request Nov 8, 2024
* Enable wasi-libc emulation features

Those features require explicit macro definitions to be enabled, so add
them to the package definition. Only affects WASI builds.

* Prefer `TARGET_OS_WASI` over `__wasi__`

And explain why we need definition checks for `signal.h` and `sys/mman.h`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants