Skip to content

Commit 031498c

Browse files
committed
chore: Add support for wasm32-wasi-pthread target
1 parent 7d409dd commit 031498c

File tree

4 files changed

+44
-7
lines changed

4 files changed

+44
-7
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ jobs:
194194
- name: Test
195195
run: |
196196
wasmtime \
197+
-W threads=y -S threads=y \
197198
--dir ${{github.workspace}}/build.wasi/install::/ \
198199
--dir tests::tests \
199200
${{github.workspace}}/build.wasi/install/usr/bin/cxx.wasm -v tests/manual/source.cc
@@ -205,6 +206,7 @@ jobs:
205206
for i in src/parser/cxx/*.cc src/lsp/cxx/lsp/*.cc src/frontend/cxx/*.cc; do
206207
echo "Parsing $i"
207208
wasmtime \
209+
-W threads=y -S threads=y \
208210
--dir=src::/src \
209211
--dir=build.wasi/_deps::/build.wasi/_deps \
210212
--dir=build.wasi/src/parser::build.wasi/src/parser \

CMakePresets.json

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
"displayName": "emscripten",
2929
"generator": "Ninja",
3030
"binaryDir": "${sourceDir}/build.em",
31+
"toolchainFile": "$env{EMSCRIPTEN_ROOT}/cmake/Modules/Platform/Emscripten.cmake",
3132
"cacheVariables": {
3233
"CMAKE_EXPORT_COMPILE_COMMANDS": "YES",
33-
"CMAKE_TOOLCHAIN_FILE": "$env{EMSCRIPTEN_ROOT}/cmake/Modules/Platform/Emscripten.cmake",
3434
"CMAKE_BUILD_TYPE": "Release",
3535
"CMAKE_INSTALL_PREFIX": "${sourceDir}/build.em/install/usr",
3636
"CMAKE_INTERPROCEDURAL_OPTIMIZATION": "YES",
@@ -48,9 +48,9 @@
4848
"displayName": "wasi",
4949
"generator": "Ninja",
5050
"binaryDir": "${sourceDir}/build.wasi",
51+
"toolchainFile": "$env{WASI_SDK_PATH}/share/cmake/wasi-sdk.cmake",
5152
"cacheVariables": {
5253
"CMAKE_EXPORT_COMPILE_COMMANDS": "YES",
53-
"CMAKE_TOOLCHAIN_FILE": "$env{WASI_SDK_PATH}/share/cmake/wasi-sdk.cmake",
5454
"CMAKE_BUILD_TYPE": "Release",
5555
"CMAKE_INSTALL_PREFIX": "${sourceDir}/build.wasi/install/usr",
5656
"CMAKE_INTERPROCEDURAL_OPTIMIZATION": "YES",
@@ -62,6 +62,11 @@
6262
"lhs": "$env{WASI_SDK_PATH}",
6363
"rhs": ""
6464
}
65+
},
66+
{
67+
"name": "wasi-threads",
68+
"inherits": "wasi",
69+
"toolchainFile": "$env{WASI_SDK_PATH}/share/cmake/wasi-sdk-pthread.cmake"
6570
}
6671
],
6772
"buildPresets": [
@@ -95,6 +100,15 @@
95100
"name": "install-wasi",
96101
"configurePreset": "wasi",
97102
"targets": ["install"]
103+
},
104+
{
105+
"name": "build-wasi-threads",
106+
"configurePreset": "wasi-threads"
107+
},
108+
{
109+
"name": "install-wasi-threads",
110+
"configurePreset": "wasi-threads",
111+
"targets": ["install"]
98112
}
99113
],
100114
"testPresets": [
@@ -109,10 +123,6 @@
109123
{
110124
"name": "emscripten",
111125
"configurePreset": "emscripten"
112-
},
113-
{
114-
"name": "wasi",
115-
"configurePreset": "wasi"
116126
}
117127
],
118128
"workflowPresets": [
@@ -166,6 +176,19 @@
166176
"name": "install-wasi"
167177
}
168178
]
179+
},
180+
{
181+
"name": "wasi-threads",
182+
"steps": [
183+
{
184+
"type": "configure",
185+
"name": "wasi-threads"
186+
},
187+
{
188+
"type": "build",
189+
"name": "install-wasi-threads"
190+
}
191+
]
169192
}
170193
]
171194
}

scripts/cxx-wasmtime.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,18 @@ const cxxWasiPrefixPath = path.join(workspacePath, "build.wasi/install");
2828
const wasmtime = await which("wasmtime");
2929

3030
const cxxArgs = [
31+
"-W",
32+
"threads=y",
33+
"-S",
34+
"threads=y",
3135
`--dir=${cxxWasiPrefixPath}/usr::/usr`,
3236
`--dir=${process.cwd()}::/`,
3337
`${cxxWasiPrefixPath}/usr/bin/cxx.wasm`,
3438
];
3539

3640
try {
3741
const result = await $`${wasmtime} ${cxxArgs} ${process.argv.slice(
38-
3,
42+
3
3943
)}`.quiet();
4044

4145
echo`${result}`;

src/frontend/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ endif()
4545

4646
if (CMAKE_SYSTEM_NAME STREQUAL "WASI")
4747
set_target_properties(cxx PROPERTIES SUFFIX ".wasm")
48+
49+
if (Threads_FOUND)
50+
target_link_options(cxx PRIVATE
51+
"SHELL:-Wl,--import-memory"
52+
"SHELL:-Wl,--export-memory"
53+
"SHELL:-Wl,--max-memory=134217728"
54+
)
55+
endif()
4856
endif()
4957

5058
if(CXX_INTERPROCEDURAL_OPTIMIZATION)

0 commit comments

Comments
 (0)