File tree Expand file tree Collapse file tree 2 files changed +33
-6
lines changed Expand file tree Collapse file tree 2 files changed +33
-6
lines changed Original file line number Diff line number Diff line change 5
5
# Compiling Rust to Wasm with the LLVM wasm-backend (without Emscripten)
6
6
# https://gist.github.com/LukasKalbertodt/821ab8b85a25f4c54544cc43bed2c39f
7
7
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 \
11
14
# deps
12
15
&& apt-get update \
13
16
&& 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 \
40
43
# clean
41
44
&& apt-get autoclean \
42
45
&& 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
44
47
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}
46
49
47
50
VOLUME ["/work" ]
48
51
WORKDIR /work
49
52
50
- CMD [ "bash" ]
53
+ ENTRYPOINT [ "rust-wasm.sh" ]
Original file line number Diff line number Diff line change
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"
You can’t perform that action at this time.
0 commit comments