Skip to content

Instantly share code, notes, and snippets.

@jcaesar
Last active January 18, 2021 00:45
Show Gist options
  • Save jcaesar/0708901856865765889a21fdb6bb2517 to your computer and use it in GitHub Desktop.
Save jcaesar/0708901856865765889a21fdb6bb2517 to your computer and use it in GitHub Desktop.
Rust: build wasm32-wasi binaries through ad-hoc docker
#!/usr/bin/env bash
set -e
echo '
FROM ubuntu:18.04
RUN apt-get update && \
export DEBIAN_FRONTEND=noninteractive && \
apt-get install -yq \
build-essential \
clang \
cmake \
curl \
emscripten \
file \
git \
sudo \
&& \
apt-get clean && rm -rf /var/lib/apt/lists/* && \
useradd rust --user-group --create-home --shell /bin/bash --groups sudo && \
echo "%sudo ALL=(ALL:ALL) NOPASSWD:ALL" >/etc/sudoers.d/nopasswd
USER rust
ENV PATH=/home/rust/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain stable --profile minimal --no-modify-path && \
rustup target add wasm32-wasi && \
rustup target add wasm32-unknown-emscripten
WORKDIR /home/rust/src
' | docker build -t rust-wasi-builder -
exec docker run --rm -ti \
-e http_proxy="${docker_http_proxy:-${http_proxy:-}}" \
-e https_proxy="${docker_https_proxy:-${https_proxy:-}}" \
-v $PWD:/home/rust/src \
-v $PWD/wasm-target:/home/rust/src/target \
-v $PWD/wasm-cache:/home/rust/.cargo/registry \
rust-wasi-builder bash -c '
sudo chown rust:rust target ~/.cargo/registry \
&& env CARGO_NET_GIT_FETCH_WITH_CLI=true cargo build -vvv --release --locked --target=wasm32-wasi
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment