|
| 1 | +# In the first container we want to assemble the `wasi-sysroot` by compiling it |
| 2 | +# from source. This requires a clang 8.0+ compiler with enough wasm support and |
| 3 | +# then we're just running a standard `make` inside of what we clone. |
| 4 | +FROM ubuntu:18.04 as wasi-sysroot |
| 5 | + |
| 6 | +RUN apt-get update && \ |
| 7 | + apt-get install -y --no-install-recommends \ |
| 8 | + ca-certificates \ |
| 9 | + clang \ |
| 10 | + cmake \ |
| 11 | + curl \ |
| 12 | + g++ \ |
| 13 | + git \ |
| 14 | + libc6-dev \ |
| 15 | + libclang-dev \ |
| 16 | + make \ |
| 17 | + ssh \ |
| 18 | + xz-utils |
| 19 | + |
| 20 | +# Fetch clang 8.0+ which is used to compile the wasi target and link our |
| 21 | +# programs together. |
| 22 | +RUN curl http://releases.llvm.org/8.0.0/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz | tar xJf - |
| 23 | +RUN mv /clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04 /wasmcc |
| 24 | + |
| 25 | +# Note that we're using `git reset --hard` to pin to a specific commit for |
| 26 | +# verification for now. The sysroot is currently in somewhat of a state of flux |
| 27 | +# and is expected to have breaking changes, so this is an attempt to mitigate |
| 28 | +# those breaking changes on `libc`'s own CI |
| 29 | +RUN git clone https://github.com/CraneStation/wasi-sysroot && \ |
| 30 | + cd wasi-sysroot && \ |
| 31 | + git reset --hard 320054e84f8f2440def3b1c8700cedb8fd697bf8 |
| 32 | +RUN make -C wasi-sysroot install -j $(nproc) WASM_CC=/wasmcc/bin/clang INSTALL_DIR=/wasi-sysroot |
| 33 | + |
| 34 | +# This is a small wrapper script which executes the actual clang binary in |
| 35 | +# `/wasmcc` and then is sure to pass the right `--sysroot` argument which we |
| 36 | +# just built above. |
| 37 | +COPY docker/wasm32-unknown-wasi/clang.sh /wasi-sysroot/bin/clang |
| 38 | + |
| 39 | +# In the second container we're going to build the `wasmtime` binary which is |
| 40 | +# used to execute wasi executables. This is a standard Rust project so we're |
| 41 | +# just checking out a known revision (which pairs with the sysroot one we |
| 42 | +# downlaoded above) and then we're building it with Cargo |
| 43 | +FROM ubuntu:18.04 as wasmtime |
| 44 | + |
| 45 | +RUN apt-get update && \ |
| 46 | + apt-get install -y --no-install-recommends \ |
| 47 | + ca-certificates \ |
| 48 | + clang \ |
| 49 | + cmake \ |
| 50 | + curl \ |
| 51 | + g++ \ |
| 52 | + git \ |
| 53 | + libclang-dev \ |
| 54 | + make \ |
| 55 | + ssh |
| 56 | + |
| 57 | +RUN curl -sSf https://sh.rustup.rs | sh -s -- -y |
| 58 | +ENV PATH=/root/.cargo/bin:$PATH |
| 59 | + |
| 60 | +RUN apt-get install -y --no-install-recommends python |
| 61 | +RUN git clone https://github.com/CraneStation/wasmtime-wasi wasmtime && \ |
| 62 | + cd wasmtime && \ |
| 63 | + git reset --hard 4fe2d6084e5b5cc74e69a26860f12750df51d339 |
| 64 | +RUN cargo build --release --manifest-path wasmtime/Cargo.toml |
| 65 | + |
| 66 | +# And finally in the last image we're going to assemble everything together. |
| 67 | +# We'll install things needed at runtime for now and then copy over the |
| 68 | +# sysroot/wasmtime artifacts into their final location. |
| 69 | +FROM ubuntu:18.04 |
| 70 | + |
| 71 | +RUN apt-get update && \ |
| 72 | + apt-get install -y --no-install-recommends \ |
| 73 | + gcc \ |
| 74 | + libc6-dev \ |
| 75 | + libxml2 |
| 76 | + |
| 77 | +# Copy over clang we downloaded to link executables ... |
| 78 | +COPY --from=reference-sysroot /wasmcc /wasmcc/ |
| 79 | +# ... and the sysroot we built to link executables against ... |
| 80 | +COPY --from=reference-sysroot /wasi-sysroot/ /wasi-sysroot/ |
| 81 | +# ... and finally wasmtime to actually execute binaries |
| 82 | +COPY --from=wasmtime /wasmtime/target/release/wasmtime /usr/bin/ |
| 83 | + |
| 84 | +# Of note here is our clang wrapper which just executes a normal clang |
| 85 | +# executable with the right sysroot, and then we're sure to turn off the |
| 86 | +# crt-static feature to ensure that the CRT that we're specifying with `clang` |
| 87 | +# is used. |
| 88 | +ENV CARGO_TARGET_WASM32_UNKNOWN_WASI_RUNNER=wasmtime \ |
| 89 | + CARGO_TARGET_WASM32_UNKNOWN_WASI_LINKER=/wasi-sysroot/bin/clang \ |
| 90 | + CC_wasm32_unknown_wasi=/wasi-sysroot/bin/clang \ |
| 91 | + PATH=$PATH:/rust/bin \ |
| 92 | + RUSTFLAGS=-Ctarget-feature=-crt-static |
0 commit comments