Skip to content

build: Add support for WASI in CMake files #31672

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 1 commit into from
May 11, 2020

Conversation

MaxDesiatov
Copy link
Contributor

@MaxDesiatov MaxDesiatov commented May 9, 2020

Add basic support for WebAssembly/WASI builds in CMake files. Important to note that WebAssembly/WASI doesn't fully support dynamic linking yet, so it is disabled for now.

Related to SR-9307.

This is a part of #29465, but includes only the CMake bits that are self-contained.

(cc @compnerd @kateinoigakukun)

elseif(SWIFT_HOST_VARIANT_SDK STREQUAL WASI)
# WASI lacks a true mmap; enabling minimal mmap emulation
# see https://github.com/WebAssembly/wasi-libc/blob/86550c37ab14962233f73413ea0e0c0e57d056d7/libc-top-half/musl/include/sys/mman.h#L3
list(APPEND result "-Wl,wasi-emulated-mman")
Copy link
Member

Choose a reason for hiding this comment

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

I don't think it makes sense to build the toolchain for WASI. Why does the toolchain need to be built for WASI?

Copy link
Contributor

Choose a reason for hiding this comment

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

It makes a huge amount of sense to build the toolchain for WASI (not that anyone has done so today, AFAIK).

For one thing, it would allow you to run the compiler in your browser. Very cool, and a great learning tool. Another use-case would be to bootstrap building the compiler as projects like Swift-driver make progress and more Swift is used in the compiler itself.

@MaxDesiatov MaxDesiatov changed the title Add support for WebAssembly/WASI in CMake files build: Add support for WASI in CMake files May 9, 2020
@MaxDesiatov MaxDesiatov requested a review from compnerd May 9, 2020 19:41
endif()

# Double-check that we're not trying to build a dynamic library for WASM.
if(SWIFTLIB_SINGLE_SDK MATCHES WASM)
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't happen right? Because this is for the toolchain.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It shouldn't, and didn't happen in my practice building it, was written more like an assertion here. I can remove it if you'd like.

Copy link
Member

Choose a reason for hiding this comment

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

Please do, I think that minimizing the CMake logic is preferable.

Copy link
Contributor Author

@MaxDesiatov MaxDesiatov May 10, 2020

Choose a reason for hiding this comment

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

That's cleaned up now.

@compnerd
Copy link
Member

compnerd commented May 9, 2020

Hmm, how are there no changes to the AddSwiftStdlib.cmake?

@MaxDesiatov
Copy link
Contributor Author

Changes to AddSwiftStdlib.cmake are now included.

@MaxDesiatov MaxDesiatov requested a review from compnerd May 9, 2020 20:40
@compnerd
Copy link
Member

@swift-ci please test

@compnerd compnerd merged commit f3da784 into swiftlang:master May 11, 2020
@MaxDesiatov MaxDesiatov deleted the maxd/wasi-sdk branch May 11, 2020 16:32
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.

3 participants