Skip to content

Commit 2c00f7a

Browse files
(reproducibility) add Dockerfile
I had some difficulty setting up the C toolchains, here's everything pinned down as a sanity check ```sh docker build -t example-c-host . docker run example-c-host ``` Co-authored-by: Shelley <shelley@exe.dev>
1 parent c969f56 commit 2c00f7a

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
FROM ubuntu:24.04 AS build
2+
3+
ARG WASMTIME_VERSION=42.0.1
4+
ARG WASI_SDK_VERSION=27
5+
6+
RUN apt-get update && apt-get install -y --no-install-recommends \
7+
gcc libc6-dev curl xz-utils ca-certificates \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
# Install wasmtime C API
11+
RUN curl -sL https://github.com/bytecodealliance/wasmtime/releases/download/v${WASMTIME_VERSION}/wasmtime-v${WASMTIME_VERSION}-x86_64-linux-c-api.tar.xz \
12+
| tar xJ --strip-components=1 -C /usr/local \
13+
&& ldconfig
14+
15+
# Install wasi-sdk (for building the guest component)
16+
RUN curl -sLO https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK_VERSION}/wasi-sdk-${WASI_SDK_VERSION}.0-x86_64-linux.deb \
17+
&& dpkg -i wasi-sdk-${WASI_SDK_VERSION}.0-x86_64-linux.deb \
18+
&& rm wasi-sdk-${WASI_SDK_VERSION}.0-x86_64-linux.deb
19+
20+
# Install wit-bindgen and wasm-tools (pin versions)
21+
ARG WIT_BINDGEN_VERSION=0.53.1
22+
ARG WASM_TOOLS_VERSION=1.245.1
23+
RUN curl -sL https://github.com/bytecodealliance/wit-bindgen/releases/download/v${WIT_BINDGEN_VERSION}/wit-bindgen-${WIT_BINDGEN_VERSION}-x86_64-linux.tar.gz \
24+
| tar xz --strip-components=1 -C /usr/local/bin --wildcards '*/wit-bindgen' \
25+
&& curl -sL https://github.com/bytecodealliance/wasm-tools/releases/download/v${WASM_TOOLS_VERSION}/wasm-tools-${WASM_TOOLS_VERSION}-x86_64-linux.tar.gz \
26+
| tar xz --strip-components=1 -C /usr/local/bin --wildcards '*/wasm-tools'
27+
28+
WORKDIR /src
29+
30+
# Fetch guest source from upstream component-docs
31+
ARG COMPONENT_DOCS_REV=7c1b5a9
32+
RUN curl -sL -o world.wit \
33+
https://raw.githubusercontent.com/bytecodealliance/component-docs/${COMPONENT_DOCS_REV}/component-model/examples/tutorial/wit/adder/world.wit \
34+
&& mkdir -p wit/adder && mv world.wit wit/adder/world.wit
35+
RUN curl -sL -o component.c \
36+
https://raw.githubusercontent.com/bytecodealliance/component-docs/${COMPONENT_DOCS_REV}/component-model/examples/tutorial/c/adder/component.c
37+
38+
# Build the guest component
39+
RUN wit-bindgen c wit/adder/world.wit
40+
RUN /opt/wasi-sdk/bin/wasm32-wasip2-clang \
41+
-o adder.wasm \
42+
-mexec-model=reactor \
43+
component.c adder.c adder_component_type.o
44+
45+
# Build the host
46+
COPY host.c .
47+
RUN gcc -o /usr/local/bin/adder-host host.c -lwasmtime
48+
49+
# Runtime image
50+
FROM ubuntu:24.04
51+
52+
COPY --from=build /usr/local/lib/libwasmtime.so /usr/local/lib/
53+
RUN ldconfig
54+
COPY --from=build /usr/local/bin/adder-host /usr/local/bin/adder-host
55+
COPY --from=build /src/adder.wasm /opt/adder.wasm
56+
57+
ENTRYPOINT ["adder-host"]
58+
CMD ["1", "2", "/opt/adder.wasm"]

0 commit comments

Comments
 (0)