-
Notifications
You must be signed in to change notification settings - Fork 9
feat(wasi): add wasm32-wasi as a compile target #9
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
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7c86c15
feat(wasi): add wasm32-wasi compile target
rioam2 6382531
feat(wasi): add vcpkg port overlay for fmt on wasm32-wasi
rioam2 5ef00ba
feat(wasi): add readme documentation for WebAssembly
rioam2 1bf72f5
Merge pull request #1 from rioam2/feat/wasm32-wasi-config
rioam2 5c7bc78
feat(wasi): add wasm subdirectory
rioam2 21e4e10
feat(wasi): add wasm subdirectory
rioam2 980563c
Merge branch 'feat/wasm32-wasi-config'
rioam2 1b6260e
Merge remote-tracking branch 'upstream/main'
rioam2 c9e34c2
chore(cmake): add back x86-linux-clang cmake preset(s)
rioam2 13a36aa
chore(cmake): remove unneeded CXX lc/labi flag for linux/clang
rioam2 cc2c32a
chore(ci): upload vcpkg error logs if cmake fails
rioam2 c5cb7c3
chore(ci): remove unneeded wasm32 runtime builtin loader
rioam2 b943689
chore(vcpkg): remove lc++abi from x86-clang-dynamic triplet
rioam2 d5be3e7
chore(ci): update permissions on clang wasi rtlib directoy
rioam2 3599a9a
chore(ci): remove libc++ and libc++abi on x86
rioam2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| name: "Ubuntu base dependencies" | ||
|
|
||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - name: Install system dependencies | ||
| shell: bash | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y ninja-build wget | ||
| - name: Install CMake | ||
| shell: bash | ||
| run: | | ||
| wget -nv -O ./cmake_install.sh https://github.com/Kitware/CMake/releases/download/v3.28.0-rc5/cmake-3.28.0-rc5-linux-x86_64.sh | ||
| sudo bash ./cmake_install.sh --skip-license --prefix=/usr --exclude-subdir | ||
| rm -f ./cmake_install.sh | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| name: "Ubuntu latest clang" | ||
|
|
||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - name: Install clang/llvm 17 | ||
| shell: bash | ||
| run: | | ||
| sudo apt-add-repository 'deb https://apt.llvm.org/jammy llvm-toolchain-jammy-17 main' | ||
| sudo wget -qO /etc/apt/trusted.gpg.d/llvm.asc https://apt.llvm.org/llvm-snapshot.gpg.key | ||
| sudo apt-get update | ||
| sudo apt-get install -y -t llvm-toolchain-jammy-17 \ | ||
| clang-17 llvm-17 lld-17 lldb-17 libc++-17-dev \ | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it clang-17 minimum supported version? |
||
| libc++abi-17-dev libclang-rt-17-dev | ||
| for f in /usr/lib/llvm-*/bin/*; do sudo ln -sf "$f" /usr/bin; done | ||
| sudo mkdir -p /usr/lib/llvm-17/lib/clang/17/lib/wasi | ||
| sudo chmod 0777 /usr/lib/llvm-17/lib/clang/17/lib/wasi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,5 +9,7 @@ list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") | |
|
|
||
| add_subdirectory(src) | ||
|
|
||
| enable_testing() | ||
| add_subdirectory(tests) | ||
| if (NOT WASI) | ||
| enable_testing() | ||
| add_subdirectory(tests) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the issue with tests? |
||
| endif() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| set(WASI 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "version": 6, | ||
| "configurePresets": [ | ||
| { | ||
| "name": "wasi-sdk", | ||
| "hidden": true, | ||
| "cacheVariables": { | ||
| "VCPKG_CHAINLOAD_TOOLCHAIN_FILE": "${sourceDir}/cmake/wasi-sdk/wasi-sdk.toolchain.cmake", | ||
| "VCPKG_OVERLAY_PORTS": "${sourceDir}/cmake/vcpkg/ports/wasm32-wasi" | ||
| } | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| { | ||
| "version": 6, | ||
| "include": [ | ||
| "base.json", | ||
| "compilers/clang.json", | ||
| "toolchains/wasi-sdk.json" | ||
| ], | ||
| "configurePresets": [ | ||
| { | ||
| "name": "wasm32-wasi-clang-static", | ||
| "inherits": [ | ||
| "base", | ||
| "wasi-sdk", | ||
| "clang" | ||
| ], | ||
| "displayName": "WASM32 WASI clang static libs" | ||
| } | ||
| ], | ||
| "buildPresets": [ | ||
| { | ||
| "name": "wasm32-wasi-clang-static", | ||
| "inherits": "base", | ||
| "configurePreset": "wasm32-wasi-clang-static" | ||
| } | ||
| ], | ||
| "workflowPresets": [ | ||
| { | ||
| "name": "wasm32-wasi-clang-static", | ||
| "steps": [ | ||
| { | ||
| "type": "configure", | ||
| "name": "wasm32-wasi-clang-static" | ||
| }, | ||
| { | ||
| "type": "build", | ||
| "name": "wasm32-wasi-clang-static" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
13 changes: 13 additions & 0 deletions
13
cmake/vcpkg/ports/wasm32-wasi/fmt/001-fix-write-batch.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| diff --git a/CMakeLists.txt b/CMakeLists.txt | ||
| index f21cf45..691a632 100644 | ||
| --- a/CMakeLists.txt | ||
| +++ b/CMakeLists.txt | ||
| @@ -157,7 +157,7 @@ if (MASTER_PROJECT AND CMAKE_GENERATOR MATCHES "Visual Studio") | ||
| join(netfxpath | ||
| "C:\\Program Files\\Reference Assemblies\\Microsoft\\Framework\\" | ||
| ".NETFramework\\v4.0") | ||
| - file(WRITE run-msbuild.bat " | ||
| + file(WRITE ${CMAKE_BINARY_DIR}/run-msbuild.bat " | ||
| ${MSBUILD_SETUP} | ||
| ${CMAKE_MAKE_PROGRAM} -p:FrameworkPathOverride=\"${netfxpath}\" %*") | ||
| endif () |
47 changes: 47 additions & 0 deletions
47
cmake/vcpkg/ports/wasm32-wasi/fmt/002-disable-posix-fd.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| diff --git a/src/os.cc b/src/os.cc | ||
| index 7813c433..b472f0a6 100644 | ||
| --- a/src/os.cc | ||
| +++ b/src/os.cc | ||
| @@ -279,7 +279,7 @@ std::size_t file::write(const void* buffer, std::size_t count) { | ||
| file file::dup(int fd) { | ||
| // Don't retry as dup doesn't return EINTR. | ||
| // http://pubs.opengroup.org/onlinepubs/009695399/functions/dup.html | ||
| - int new_fd = FMT_POSIX_CALL(dup(fd)); | ||
| + int new_fd = -1; | ||
| if (new_fd == -1) | ||
| FMT_THROW(system_error( | ||
| errno, FMT_STRING("cannot duplicate file descriptor {}"), fd)); | ||
| @@ -287,8 +287,7 @@ file file::dup(int fd) { | ||
| } | ||
|
|
||
| void file::dup2(int fd) { | ||
| - int result = 0; | ||
| - FMT_RETRY(result, FMT_POSIX_CALL(dup2(fd_, fd))); | ||
| + int result = -1; | ||
| if (result == -1) { | ||
| FMT_THROW(system_error( | ||
| errno, FMT_STRING("cannot duplicate file descriptor {} to {}"), fd_, | ||
| @@ -297,8 +296,7 @@ void file::dup2(int fd) { | ||
| } | ||
|
|
||
| void file::dup2(int fd, std::error_code& ec) noexcept { | ||
| - int result = 0; | ||
| - FMT_RETRY(result, FMT_POSIX_CALL(dup2(fd_, fd))); | ||
| + int result = -1; | ||
| if (result == -1) ec = std::error_code(errno, std::generic_category()); | ||
| } | ||
|
|
||
| @@ -335,11 +333,11 @@ pipe::pipe() { | ||
| # ifdef _WIN32 | ||
| // Make the default pipe capacity same as on Linux 2.6.11+. | ||
| enum { DEFAULT_CAPACITY = 65536 }; | ||
| - int result = FMT_POSIX_CALL(pipe(fds, DEFAULT_CAPACITY, _O_BINARY)); | ||
| + int result = -1; | ||
| # else | ||
| // Don't retry as the pipe function doesn't return EINTR. | ||
| // http://pubs.opengroup.org/onlinepubs/009696799/functions/pipe.html | ||
| - int result = FMT_POSIX_CALL(pipe(fds)); | ||
| + int result = -1; | ||
| # endif | ||
| if (result != 0) | ||
| FMT_THROW(system_error(errno, FMT_STRING("cannot create pipe"))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| This overlay port is a direct copy from https://github.com/microsoft/vcpkg/tree/master/ports/fmt with modifications to allow compilation on wasm32-wasi as a target by removing POSIX filesystem calls. | ||
rioam2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| vcpkg_from_github( | ||
| OUT_SOURCE_PATH SOURCE_PATH | ||
| REPO fmtlib/fmt | ||
| REF "${VERSION}" | ||
| SHA512 27df90c681ec37e55625062a79e3b83589b6d7e94eff37a3b412bb8c1473f757a8adb727603acc9185c3490628269216843b7d7bd5a3cb37f0029da5d1495ffa | ||
| HEAD_REF master | ||
| PATCHES | ||
| 001-fix-write-batch.patch | ||
| 002-disable-posix-fd.patch | ||
| ) | ||
|
|
||
| vcpkg_cmake_configure( | ||
| SOURCE_PATH "${SOURCE_PATH}" | ||
| OPTIONS | ||
| -DFMT_CMAKE_DIR=share/fmt | ||
| -DFMT_TEST=OFF | ||
| -DFMT_DOC=OFF | ||
| ) | ||
|
|
||
| vcpkg_cmake_install() | ||
| vcpkg_cmake_config_fixup() | ||
| vcpkg_fixup_pkgconfig() | ||
| vcpkg_copy_pdbs() | ||
|
|
||
| if(VCPKG_LIBRARY_LINKAGE STREQUAL dynamic) | ||
| vcpkg_replace_string(${CURRENT_PACKAGES_DIR}/include/fmt/core.h | ||
| "defined(FMT_SHARED)" | ||
| "1" | ||
| ) | ||
| endif() | ||
|
|
||
| file(REMOVE_RECURSE | ||
| "${CURRENT_PACKAGES_DIR}/debug/include" | ||
| "${CURRENT_PACKAGES_DIR}/debug/share" | ||
| ) | ||
|
|
||
| file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") | ||
| vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| The package fmt provides CMake targets: | ||
|
|
||
| find_package(fmt CONFIG REQUIRED) | ||
| target_link_libraries(main PRIVATE fmt::fmt) | ||
|
|
||
| # Or use the header-only version | ||
| find_package(fmt CONFIG REQUIRED) | ||
| target_link_libraries(main PRIVATE fmt::fmt-header-only) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| "name": "fmt", | ||
| "version": "10.2.1", | ||
| "description": "Formatting library for C++. It can be used as a safe alternative to printf or as a fast alternative to IOStreams.", | ||
| "homepage": "https://github.com/fmtlib/fmt", | ||
| "license": "MIT", | ||
| "dependencies": [ | ||
| { | ||
| "name": "vcpkg-cmake", | ||
| "host": true | ||
| }, | ||
| { | ||
| "name": "vcpkg-cmake-config", | ||
| "host": true | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| set(VCPKG_TARGET_ARCHITECTURE wasm32) | ||
| set(VCPKG_LIBRARY_LINKAGE static) | ||
| set(VCPKG_CRT_LINKAGE static) | ||
|
|
||
| set(VCPKG_CMAKE_SYSTEM_NAME WASI) | ||
| set(VCPKG_CMAKE_SYSTEM_VERSION 1) | ||
| set(VCPKG_CMAKE_SYSTEM_PROCESSOR wasm32) | ||
|
|
||
| set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${CMAKE_CURRENT_LIST_DIR}/../../wasi-sdk/wasi-sdk.toolchain.cmake") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| include_guard(GLOBAL) | ||
|
|
||
| cmake_minimum_required(VERSION 3.25) | ||
|
|
||
| get_property(IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE) | ||
|
|
||
| if (IN_TRY_COMPILE) | ||
| return() | ||
| endif() | ||
|
|
||
| unset(IN_TRY_COMPILE) | ||
|
|
||
| # Until Platform/WASI.cmake is upstream we need to inject the path to it | ||
| # into CMAKE_MODULE_PATH. | ||
| list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/..") | ||
|
|
||
| include(${CMAKE_CURRENT_LIST_DIR}/wasi-sdk_bootstrap.cmake) | ||
| wasi_sdk_bootstrap( | ||
| TAG wasi-sdk-21 | ||
| WASI_SYSROOT_OUTPUT CMAKE_SYSROOT | ||
| ) | ||
|
|
||
| set(CMAKE_SYSTEM_NAME WASI) | ||
| set(CMAKE_SYSTEM_VERSION 1) | ||
| set(CMAKE_SYSTEM_PROCESSOR wasm32) | ||
| set(triple wasm32-wasi) | ||
|
|
||
| set(CMAKE_C_COMPILER clang) | ||
| set(CMAKE_CXX_COMPILER clang++) | ||
| set(CMAKE_ASM_COMPILER clang) | ||
| set(CMAKE_AR llvm-ar) | ||
| set(CMAKE_RANLIB llvm-ranlib) | ||
| set(CMAKE_C_COMPILER_TARGET ${triple}) | ||
| set(CMAKE_CXX_COMPILER_TARGET ${triple}) | ||
| set(CMAKE_ASM_COMPILER_TARGET ${triple}) | ||
|
|
||
| # Don't look in the sysroot for executables to run during the build | ||
| set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) | ||
| # Only look in the sysroot (not in the host paths) for the rest | ||
| set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) | ||
| set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) | ||
| set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) | ||
|
|
||
| set(CLANG_DEFAULT_RTLIB "compiler-rt") | ||
| set(LIBCXX_USE_COMPILER_RT "YES") | ||
| set(LIBCXXABI_USE_COMPILER_RT "YES") | ||
|
|
||
| add_compile_options( | ||
| "-stdlib=libc++" | ||
| "-fno-exceptions" | ||
| "-D_WASI_EMULATED_SIGNAL" | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.