-
Notifications
You must be signed in to change notification settings - Fork 9
feat(wasi): add wasm32-wasi as a compile target #13
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
Open
rioam2
wants to merge
3
commits into
msvetkin:main
Choose a base branch
from
rioam2:rioam2/add-wasm32-wasi-target
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 | ||
|
|
||
| - name: Install wasmtime CLI | ||
| shell: bash | ||
| run: | | ||
| curl https://wasmtime.dev/install.sh -sSf | bash | ||
| sudo cp ~/.wasmtime/bin/wasmtime /usr/bin/wasmtime |
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,15 @@ | ||
| 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 \ | ||
| libc++abi-17-dev libclang-rt-17-dev | ||
| for f in /usr/lib/llvm-*/bin/*; do sudo ln -sf "$f" /usr/bin; done |
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 |
|---|---|---|
|
|
@@ -12,11 +12,11 @@ jobs: | |
| { os: ubuntu-latest, preset: x64-linux-gcc-dynamic }, | ||
| { os: ubuntu-latest, preset: x86-linux-gcc-dynamic }, | ||
| { os: ubuntu-latest, preset: x64-linux-clang-dynamic }, | ||
| { os: ubuntu-latest, preset: x86-linux-clang-dynamic }, | ||
| { os: macos-latest, preset: x64-darwin-gcc-dynamic }, | ||
| { os: macos-latest, preset: x64-darwin-clang-dynamic }, | ||
| { os: windows-latest, preset: x64-windows-msvc-dynamic }, | ||
| { os: windows-latest, preset: x64-windows-clang-dynamic }, | ||
| { os: ubuntu-latest, preset: wasm32-wasi-clang-static }, | ||
| ] | ||
|
|
||
| steps: | ||
|
|
@@ -37,3 +37,11 @@ jobs: | |
| shell: bash | ||
| run: | | ||
| cmake --workflow --preset ${{matrix.target.preset}} | ||
|
|
||
| - name: Upload vcpkg error logs | ||
| if: failure() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: logs-${{matrix.target.preset}} | ||
| path: | | ||
| /usr/local/share/vcpkg/**/*.log | ||
|
Contributor
Author
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. Not necessary for this PR, but adds a nice way to debug issues in CI. |
||
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,13 @@ | ||
| { | ||
| "version": 6, | ||
| "configurePresets": [ | ||
| { | ||
| "name": "wasi-sdk", | ||
| "hidden": true, | ||
| "cacheVariables": { | ||
| "VCPKG_CHAINLOAD_TOOLCHAIN_FILE": "${sourceDir}/cmake/toolchains/wasi-sdk.toolchain.cmake", | ||
| "CMAKE_CROSSCOMPILING_EMULATOR": "wasmtime" | ||
| } | ||
| } | ||
| ] | ||
| } |
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 @@ | ||
| { | ||
| "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" | ||
| } | ||
| ], | ||
| "testPresets": [ | ||
| { | ||
| "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" | ||
| }, | ||
| { | ||
| "type": "test", | ||
| "name": "wasm32-wasi-clang-static" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
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,14 @@ | ||
| include(FetchContent) | ||
|
|
||
| set(FETCHCONTENT_FULLY_DISCONNECTED_OLD ${FETCHCONTENT_FULLY_DISCONNECTED}) | ||
| set(FETCHCONTENT_FULLY_DISCONNECTED OFF) | ||
| FetchContent_Declare( | ||
| wasi_sdk_toolchain | ||
| SOURCE_DIR "${CMAKE_BINARY_DIR}/_deps/wasi-sdk" | ||
| GIT_REPOSITORY https://github.com/rioam2/wasi-sdk-toolchain.git | ||
| GIT_TAG wasi-sdk-23 | ||
| ) | ||
| FetchContent_MakeAvailable(wasi_sdk_toolchain) | ||
| set(FETCHCONTENT_FULLY_DISCONNECTED ${FETCHCONTENT_FULLY_DISCONNECTED_OLD}) | ||
|
|
||
| include("${wasi_sdk_toolchain_SOURCE_DIR}/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
| 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}/../../toolchains/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
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,16 @@ | ||
| # SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| add_@cpp_pt_cmake@_executable(wasm) | ||
|
|
||
| target_sources(${@cpp_pt_cmake@_executable_target} PRIVATE | ||
| src/interface.cpp | ||
| ) | ||
|
|
||
| target_link_libraries(${@cpp_pt_cmake@_executable_target} | ||
| PRIVATE | ||
| @cpp_pt_name@::@cpp_pt_module@ | ||
| ) | ||
|
|
||
| set_target_properties(${@cpp_pt_cmake@_executable_target} PROPERTIES OUTPUT_NAME "lib@cpp_pt_module@.wasm") | ||
| target_link_options(${@cpp_pt_cmake@_executable_target} PRIVATE -nostartfiles -Wl,--no-entry) |
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,35 @@ | ||
| #include "@cpp_pt_name@/@cpp_pt_module@/@cpp_pt_module_header@.hpp" | ||
|
|
||
| #include <fmt/core.h> | ||
|
|
||
| #include <cstdlib> | ||
| #include <cstring> | ||
| #include <string> | ||
|
|
||
| // Memory management exports | ||
| extern "C" __attribute__((export_name("wasm_malloc"))) void* wasm_malloc(size_t nbytes) { | ||
| return std::malloc(nbytes); | ||
| } | ||
|
|
||
| extern "C" __attribute__((export_name("wasm_free"))) void wasm_free( | ||
| void* ptr) { | ||
| return std::free(ptr); | ||
| } | ||
|
|
||
| // Exported WASM functions | ||
| extern "C" __attribute__((export_name("version"))) uint8_t* version() { | ||
| std::string version = @cpp_pt_name@::@cpp_pt_module@::version(); | ||
| uint8_t* versionPointer = (uint8_t*)wasm_malloc(version.length()); | ||
| std::memcpy(versionPointer, version.c_str(), version.length()); | ||
| return versionPointer; | ||
| } | ||
|
|
||
| // This is the WASM module's initialization entrypoint. It should be called | ||
| // before running any other exported function because it initializes implicit | ||
| // global/static resources. This is only required in library/reactor mode of | ||
| // WebAssembly. Read more here: | ||
| // https://wasmcloud.com/blog/webassembly-patterns-command-reactor-library#the-reactor-pattern | ||
| extern "C" void __wasm_call_ctors(); | ||
| extern "C" __attribute__((export_name("_start"))) void _start() { | ||
| __wasm_call_ctors(); | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was removed from
.github/ci.yamlin 5efee87, so I removed it here in.github/workflows/ci.yamlas well. It fails due to missinglibc++abion x86