Skip to content

Commit d9a62e7

Browse files
committed
entrypoint script
1 parent 8b23a22 commit d9a62e7

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

Dockerfile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ LABEL maintainer="OpenGG <[email protected]>"
55
# Compiling Rust to Wasm with the LLVM wasm-backend (without Emscripten)
66
# https://gist.github.com/LukasKalbertodt/821ab8b85a25f4c54544cc43bed2c39f
77

8-
# source
9-
RUN sed -i "s|deb.debian.org|mirrors.ustc.edu.cn|" /etc/apt/sources.list \
10-
&& sed -i "s|security.debian.org|mirrors.ustc.edu.cn/debian-security|" /etc/apt/sources.list \
8+
ADD "rust-wasm.sh" /usr/local/bin/
9+
10+
RUN chmod +x rust-wasm.sh \
11+
# apt source
12+
# && sed -i "s|deb.debian.org|mirrors.ustc.edu.cn|" /etc/apt/sources.list \
13+
# && sed -i "s|security.debian.org|mirrors.ustc.edu.cn/debian-security|" /etc/apt/sources.list \
1114
# deps
1215
&& apt-get update \
1316
&& apt-get install -y git build-essential cmake curl g++ python \
@@ -40,11 +43,11 @@ RUN sed -i "s|deb.debian.org|mirrors.ustc.edu.cn|" /etc/apt/sources.list \
4043
# clean
4144
&& apt-get autoclean \
4245
&& apt-get clean \
43-
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
46+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /rust-wasm
4447

45-
ENV PATH /rust-wasm-bin/llvm/bin:/rust-wasm-bin/binaryen/bin:${PATH}
48+
ENV PATH /root/.cargo/bin:/rust-wasm-bin/llvm/bin:/rust-wasm-bin/binaryen/bin:${PATH}
4649

4750
VOLUME ["/work"]
4851
WORKDIR /work
4952

50-
CMD ["bash"]
53+
ENTRYPOINT [ "rust-wasm.sh" ]

rust-wasm.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
# https://gist.github.com/LukasKalbertodt/821ab8b85a25f4c54544cc43bed2c39f
4+
5+
# Super simple script to compile Rust to wasm. Usage:
6+
# ./rust-wasm.sh foo.rs
7+
8+
if [ -z ${1+x} ]; then
9+
echo "missing argument: rust source file"
10+
exit 1
11+
fi
12+
13+
BASENAME="${1%.rs}"
14+
15+
INPUT="${BASENAME}.rs"
16+
17+
if [ ! -f "${INPUT}" ]; then
18+
echo "File not found: ${INPUT}"
19+
fi
20+
21+
rustc -O --crate-type=lib --emit=llvm-bc -C opt-level=3 "${INPUT}" && \
22+
llc -march=wasm32 "${BASENAME}.bc" && \
23+
s2wasm -o "${BASENAME}.wast" "${BASENAME}.s" && \
24+
wasm-as "${BASENAME}.wast"

0 commit comments

Comments
 (0)