Skip to content

Commit 83659fa

Browse files
authored
Use wasi-sdk 20 pre-release for tests with threads (#2021)
`wasi-sdk-20` pre-release can be used to avoid building `wasi-libc` to enable threads. It's not possible to use `wasi-sdk-20` pre-release on Ubuntu 20.04 because of incompatibility with the glibc version: ```bash /opt/wasi-sdk/bin/clang: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by /opt/wasi-sdk/bin/clang) ```
1 parent 23e9a35 commit 83659fa

File tree

7 files changed

+50
-58
lines changed

7 files changed

+50
-58
lines changed

.github/workflows/compilation_on_android_ubuntu.yml

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,13 @@ jobs:
337337
- os: ubuntu-20.04
338338
wasi_sdk_release: "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-19/wasi-sdk-19.0-linux.tar.gz"
339339
wabt_release: "https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-ubuntu.tar.gz"
340+
wasi_sdk_folder_name: "wasi-sdk-19.0"
341+
wasi_sysroot_option: "-DWASI_SYSROOT=`pwd`/../../../core/deps/wasi-libc/sysroot"
340342
- os: ubuntu-22.04
341-
wasi_sdk_release: "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-19/wasi-sdk-19.0-linux.tar.gz"
343+
wasi_sdk_release: "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20%2Bthreads/wasi-sdk-20.0.threads-linux.tar.gz"
342344
wabt_release: "https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-ubuntu.tar.gz"
345+
wasi_sdk_folder_name: "wasi-sdk-20.0+threads"
346+
wasi_sysroot_option: ""
343347
steps:
344348
- name: checkout
345349
uses: actions/checkout@v3
@@ -349,7 +353,7 @@ jobs:
349353
cd /opt
350354
sudo wget ${{ matrix.wasi_sdk_release }}
351355
sudo tar -xzf wasi-sdk-*.tar.gz
352-
sudo mv wasi-sdk-19.0 wasi-sdk
356+
sudo mv ${{ matrix.wasi_sdk_folder_name }} wasi-sdk
353357
354358
- name: download and install wabt
355359
run: |
@@ -359,6 +363,7 @@ jobs:
359363
sudo mv wabt-1.0.31 wabt
360364
361365
- name: build wasi-libc (needed for wasi-threads)
366+
if: matrix.os == 'ubuntu-20.04'
362367
run: |
363368
mkdir wasi-libc
364369
cd wasi-libc
@@ -431,15 +436,22 @@ jobs:
431436
run: |
432437
cd samples/wasi-threads
433438
mkdir build && cd build
434-
cmake -DWASI_SYSROOT=`pwd`/../../../core/deps/wasi-libc/sysroot ..
439+
cmake ${{ matrix.wasi_sysroot_option }} ..
435440
cmake --build . --config Release --parallel 4
436441
./iwasm wasm-apps/no_pthread.wasm
437442
438443
test:
439-
needs: [build_iwasm, build_llvm_libraries_on_ubuntu_2004, build_wamrc]
440-
runs-on: ubuntu-20.04
444+
needs:
445+
[
446+
build_iwasm,
447+
build_llvm_libraries_on_ubuntu_2004,
448+
build_llvm_libraries_on_ubuntu_2204,
449+
build_wamrc
450+
]
451+
runs-on: ${{ matrix.os }}
441452
strategy:
442453
matrix:
454+
os: [ubuntu-20.04, ubuntu-22.04]
443455
running_mode:
444456
[
445457
"classic-interp",
@@ -457,12 +469,21 @@ jobs:
457469
$THREADS_TEST_OPTIONS,
458470
$WASI_TEST_OPTIONS,
459471
]
460-
wasi_sdk_release:
461-
[
462-
"https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-19/wasi-sdk-19.0-linux.tar.gz",
463-
]
464-
llvm_cache_key:
465-
["${{ needs.build_llvm_libraries_on_ubuntu_2004.outputs.cache_key }}"]
472+
include:
473+
- os: ubuntu-20.04
474+
llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2004.outputs.cache_key }}
475+
wasi_sdk_release: "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-19/wasi-sdk-19.0-linux.tar.gz"
476+
wabt_release: "https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-ubuntu.tar.gz"
477+
wasi_sdk_folder_name: "wasi-sdk-19.0"
478+
wasi_sysroot_option: "WASI_SYSROOT_OPTION='--sysroot ../../../../../core/deps/wasi-libc/sysroot'"
479+
ubuntu_version: "20.04"
480+
- os: ubuntu-22.04
481+
llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }}
482+
wasi_sdk_release: "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20%2Bthreads/wasi-sdk-20.0.threads-linux.tar.gz"
483+
wabt_release: "https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-ubuntu.tar.gz"
484+
wasi_sdk_folder_name: "wasi-sdk-20.0+threads"
485+
wasi_sysroot_option: ""
486+
ubuntu_version: "22.04"
466487
exclude:
467488
# uncompatiable modes and features
468489
# classic-interp and fast-interp don't support simd
@@ -503,10 +524,10 @@ jobs:
503524
cd /opt
504525
sudo wget ${{ matrix.wasi_sdk_release }}
505526
sudo tar -xzf wasi-sdk-*.tar.gz
506-
sudo mv wasi-sdk-19.0 wasi-sdk
527+
sudo mv ${{ matrix.wasi_sdk_folder_name }} wasi-sdk
507528
508529
- name: build wasi-libc (needed for wasi-threads)
509-
if: matrix.test_option == '$WASI_TEST_OPTIONS'
530+
if: matrix.os == 'ubuntu-20.04' && matrix.test_option == '$WASI_TEST_OPTIONS'
510531
run: |
511532
mkdir wasi-libc
512533
cd wasi-libc
@@ -557,12 +578,12 @@ jobs:
557578

558579
- name: Build WASI thread tests
559580
if: matrix.test_option == '$WASI_TEST_OPTIONS'
560-
run: WASI_SYSROOT=../../../../../core/deps/wasi-libc/sysroot bash build.sh
581+
run: ${{ matrix.wasi_sysroot_option }} bash build.sh
561582
working-directory: ./core/iwasm/libraries/lib-wasi-threads/test/
562583

563584
- name: build socket api tests
564585
if: matrix.test_option == '$WASI_TEST_OPTIONS'
565-
run: WASI_SYSROOT=../../../../../core/deps/wasi-libc/sysroot bash build.sh
586+
run: ${{ matrix.wasi_sysroot_option }} bash build.sh
566587
working-directory: ./core/iwasm/libraries/lib-socket/test/
567588

568589
- name: run tests
@@ -577,7 +598,7 @@ jobs:
577598
# Add another apt repository as some packages cannot
578599
# be downloaded with the github default repository
579600
sudo curl -sSL https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc &&
580-
sudo apt-add-repository https://packages.microsoft.com/ubuntu/20.04/prod &&
601+
sudo apt-add-repository https://packages.microsoft.com/ubuntu/${{ matrix.ubuntu_version }}/prod &&
581602
sudo apt-get update &&
582603
sudo apt install -y g++-multilib lib32gcc-9-dev
583604

.github/workflows/compilation_on_macos.yml

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ jobs:
249249
os: [macos-latest]
250250
wasi_sdk_release:
251251
[
252-
"https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-19/wasi-sdk-19.0-macos.tar.gz",
252+
"https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20%2Bthreads/wasi-sdk-20.0.threads-macos.tar.gz",
253253
]
254254
wabt_release:
255255
[
@@ -264,7 +264,7 @@ jobs:
264264
cd /opt
265265
sudo wget ${{ matrix.wasi_sdk_release }}
266266
sudo tar -xzf wasi-sdk-*.tar.gz
267-
sudo mv wasi-sdk-19.0 wasi-sdk
267+
sudo mv wasi-sdk-20.0+threads wasi-sdk
268268
269269
- name: download and install wabt
270270
run: |
@@ -273,22 +273,6 @@ jobs:
273273
sudo tar -xzf wabt-1.0.31-*.tar.gz
274274
sudo mv wabt-1.0.31 wabt
275275
276-
- name: build wasi-libc (needed for wasi-threads)
277-
run: |
278-
mkdir wasi-libc
279-
cd wasi-libc
280-
git init
281-
# "Rename thread_spawn import" commit on main branch
282-
git fetch https://github.com/WebAssembly/wasi-libc \
283-
8f5275796a82f8ecfd0833a4f3f444fa37ed4546
284-
git checkout FETCH_HEAD
285-
make \
286-
AR=/opt/wasi-sdk/bin/llvm-ar \
287-
NM=/opt/wasi-sdk/bin/llvm-nm \
288-
CC=/opt/wasi-sdk/bin/clang \
289-
THREAD_MODEL=posix
290-
working-directory: core/deps
291-
292276
- name: Build Sample [basic]
293277
run: |
294278
cd samples/basic
@@ -339,6 +323,6 @@ jobs:
339323
run: |
340324
cd samples/wasi-threads
341325
mkdir build && cd build
342-
cmake -DWASI_SYSROOT=`pwd`/../../../core/deps/wasi-libc/sysroot ..
326+
cmake ..
343327
cmake --build . --config Release --parallel 4
344328
./iwasm wasm-apps/no_pthread.wasm

core/iwasm/libraries/lib-socket/test/build.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@
33
# Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved.
44
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55

6-
set -ueo pipefail
6+
set -eo pipefail
77
CC="${CC:=/opt/wasi-sdk/bin/clang}"
88
files=("tcp_udp.c" "nslookup.c")
9-
WASI_SYSROOT=${WASI_SYSROOT:=~/dev/wasi-libc/sysroot}
109

1110
for file in "${files[@]}"
1211
do
1312
echo $file
1413
$CC \
14+
$WASI_SYSROOT_OPTION \
1515
--target=wasm32-wasi-threads \
1616
-I../inc \
17-
--sysroot $WASI_SYSROOT \
1817
../src/wasi/wasi_socket_ext.c -pthread -ftls-model=local-exec \
1918
-Wl,--allow-undefined \
2019
-Wl,--strip-all,--no-entry \

core/iwasm/libraries/lib-wasi-threads/test/build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
#
77

8+
set -eo pipefail
89
CC=${CC:=/opt/wasi-sdk/bin/clang}
9-
WASI_SYSROOT=${WASI_SYSROOT:=~/dev/wasi-libc/sysroot}
1010
WAMR_DIR=../../../../..
1111

1212
for test_c in *.c; do
1313
test_wasm="$(basename $test_c .c).wasm"
1414

1515
echo "Compiling $test_c to $test_wasm"
1616
$CC \
17-
--sysroot $WASI_SYSROOT \
17+
$WASI_SYSROOT_OPTION \
1818
-target wasm32-wasi-threads \
1919
-pthread -ftls-model=local-exec \
2020
-z stack-size=32768 \

samples/wasi-threads/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@ include(CheckPIESupported)
77

88
project(wasi_threads_sample)
99

10-
if (NOT DEFINED WASI_SYSROOT)
11-
message (WARNING "Custom sysroot with threads enabled is required to build wasi threads samples.
12-
Please note that current wasi-sdk doesn't ship with threads enabled.
13-
Run cmake command with -DWASI_SYSROOT=/path/to/sysroot/with/threads to compile samples.")
14-
return ()
15-
endif ()
16-
1710
################ runtime settings ################
1811
string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
1912
if (APPLE)

samples/wasi-threads/README.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
# "WASI threads" sample introduction
22

3-
Currently, since the `wasi-sdk` does not have thread support in the latest release, make sure to have [wasi-libc](https://github.com/WebAssembly/wasi-libc) installed. Build it with threads enabled, e.g.
4-
5-
```shell
6-
make \
7-
AR=/opt/wasi-sdk/bin/llvm-ar \
8-
NM=/opt/wasi-sdk/bin/llvm-nm \
9-
CC=/opt/wasi-sdk/bin/clang \
10-
THREAD_MODEL=posix
11-
```
3+
To run the sample, `wasi-sdk` >= 20 is required.
124

135
## Build and run the samples
146

157
```shell
168
$ mkdir build
179
$ cd build
18-
$ cmake -DWASI_SYSROOT=/path/to/wasi-libc/sysroot ..
10+
$ cmake ..
1911
$ make
2012
...
2113
$ ./iwasm wasm-apps/no_pthread.wasm

samples/wasi-threads/wasm-apps/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ if (NOT DEFINED WASI_SDK_DIR)
1111
set (WASI_SDK_DIR "/opt/wasi-sdk")
1212
endif ()
1313

14-
set (CMAKE_SYSROOT "${WASI_SYSROOT}")
14+
if (DEFINED WASI_SYSROOT)
15+
set (CMAKE_SYSROOT "${WASI_SYSROOT}")
16+
endif ()
17+
1518
set (CMAKE_C_COMPILER "${WASI_SDK_DIR}/bin/clang")
1619
set (CMAKE_ASM_COMPILER "${WASI_SDK_DIR}/bin/clang")
1720
set (CMAKE_EXE_LINKER_FLAGS "-target wasm32-wasi-threads")

0 commit comments

Comments
 (0)