Skip to content

Commit f8ab021

Browse files
authored
Merge pull request #992 from hydai/hydai/update_wasmedge
wasm: use wasmedge library soname in dlopen
2 parents 33ba5e8 + 074cd9a commit f8ab021

File tree

7 files changed

+70
-12
lines changed

7 files changed

+70
-12
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ jobs:
177177
;;
178178
wasmedge-build)
179179
sudo docker build -t wasmedge tests/wasmedge-build
180-
sudo docker run --rm -w /crun -v ${PWD}:/crun wasmedge
180+
sudo docker run --privileged --rm -v /sys/fs/cgroup:/sys/fs/cgroup:rw,rslave -w /crun -v ${PWD}:/crun wasmedge
181181
;;
182182
esac
183183

src/libcrun/handlers/wasmedge.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ libwasmedge_load (void **cookie, libcrun_error_t *err arg_unused)
4444
{
4545
void *handle;
4646

47-
handle = dlopen ("libwasmedge_c.so", RTLD_NOW);
47+
handle = dlopen ("libwasmedge.so.0", RTLD_NOW);
4848
if (handle == NULL)
49-
return crun_make_error (err, 0, "could not load `libwasmedge_c.so`: %s", dlerror ());
49+
return crun_make_error (err, 0, "could not load `libwasmedge.so.0`: %s", dlerror ());
5050
*cookie = handle;
5151

5252
return 0;
@@ -107,7 +107,7 @@ libwasmedge_exec (void *cookie, __attribute__ ((unused)) libcrun_container_t *co
107107
|| WasmEdge_VMRegisterModuleFromFile == NULL || WasmEdge_VMGetImportModuleContext == NULL
108108
|| WasmEdge_ModuleInstanceInitWASI == NULL || WasmEdge_VMRunWasmFromFile == NULL
109109
|| WasmEdge_ResultOK == NULL || WasmEdge_StringCreateByCString == NULL)
110-
error (EXIT_FAILURE, 0, "could not find symbol in `libwasmedge.so`");
110+
error (EXIT_FAILURE, 0, "could not find symbol in `libwasmedge.so.0`");
111111

112112
configure = WasmEdge_ConfigureCreate ();
113113
if (UNLIKELY (configure == NULL))

tests/wasmedge-build/Dockerfile

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
1-
FROM debian:bullseye-slim
2-
ARG WASM_EDGE_VERSION="0.10.0"
1+
FROM fedora:rawhide
2+
ARG WASM_EDGE_VERSION="0.11.0"
33

4-
RUN apt-get update && apt-get install -y make git gcc build-essential pkgconf libtool \
5-
libsystemd-dev libprotobuf-c-dev libcap-dev libseccomp-dev libyajl-dev \
6-
go-md2man autoconf python3 automake curl libc6
4+
# Install the deps for building crun
5+
RUN dnf update -y && dnf install -y make python git gcc automake autoconf libcap-devel \
6+
systemd-devel yajl-devel libseccomp-devel pkg-config \
7+
go-md2man glibc-static python3-libmount libtool buildah podman
78

8-
#ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
9-
RUN rm /etc/ld.so.conf.d/libc.conf
9+
# Install WasmEdge
1010
RUN curl -sSf -o install.sh https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh
11-
RUN bash ./install.sh -p /usr/local -v $WASM_EDGE_VERSION
11+
RUN bash ./install.sh -p /usr/local -v $WASM_EDGE_VERSION
12+
13+
# The hello_wasm contains:
14+
# 1. The example rust application called hello, which will print something to console.
15+
# 2. The Containerfile for building the image including hello.wasm
16+
ADD hello_wasm /hello_wasm
17+
18+
# Install Rust for building wasm application
19+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
20+
SHELL ["/bin/bash", "-c"]
21+
RUN source "$HOME/.cargo/env" && \
22+
rustup target add wasm32-wasi && \
23+
cd /hello_wasm/hello && \
24+
cargo build --release --target wasm32-wasi && \
25+
cp ./target/wasm32-wasi/release/hello.wasm /hello_wasm && \
26+
cd / && \
27+
rm -rf /hello_wasm/hello
1228

1329
COPY run-tests.sh /usr/local/bin
1430

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM scratch
2+
COPY hello.wasm /
3+
CMD ["/hello.wasm"]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "hello"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("{}", "This is from a main function from a wasm module");
3+
}

tests/wasmedge-build/run-tests.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,37 @@
11
#!/bin/bash
22

33
set -e
4+
5+
# Build crun with wasmedge support
46
cd /crun
57

8+
git config --global --add safe.directory /crun
69
git clean -fdx
710
./autogen.sh
811
./configure CFLAGS='-Wall -Wextra -Werror' --with-wasmedge
912
make -j "$(nproc)"
13+
make install
14+
15+
# Remove the installed crun to make sure the built crun is used
16+
rm -rf /usr/bin/crun
17+
ln -s /usr/local/bin/crun /usr/bin/crun
18+
19+
# Test crun is used in podman
20+
if [[ $(podman info | grep SYSTEMD) != *WASM:wasmedge* ]]; then
21+
echo "podman cannot find the built crun with +WASM:wasmedge"
22+
exit 1
23+
fi
24+
25+
# Build hellowasm image
26+
cd /hello_wasm && \
27+
chmod +x ./hello.wasm && \
28+
buildah build --annotation "module.wasm.image/variant=compat-smart" -t hellowasm-image .
29+
30+
# Run hello.wasm with crun
31+
OUTPUT=$(podman run hellowasm-image:latest)
32+
EXPECTED_OUTPUT="This is from a main function from a wasm module"
33+
echo "$OUTPUT"
34+
if [[ "$OUTPUT" != "$EXPECTED_OUTPUT" ]]; then
35+
echo "Run wasm failed. The execution result is not matched"
36+
exit 1
37+
fi

0 commit comments

Comments
 (0)