-
Notifications
You must be signed in to change notification settings - Fork 16
/
moonbit.public.Dockerfile
97 lines (71 loc) · 2.73 KB
/
moonbit.public.Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# Build rvlinux
FROM ubuntu:24.04 AS rvlinux-build
# Install libriscv
RUN apt-get update
RUN apt-get install -y gcc g++ make git cmake python3 python3-pip
WORKDIR /root/
RUN git clone https://github.com/lynzrand/libriscv.git
WORKDIR /root/libriscv/emulator
RUN ./build.sh --native --64 -b -v
# output at .build/rvlinux
FROM ubuntu:24.04 as moonbit-build
RUN apt-get update
RUN apt-get install -y curl tar xz-utils wget git jq binutils
# Install nodejs
RUN wget https://nodejs.org/dist/v22.10.0/node-v22.10.0-linux-x64.tar.xz -O /tmp/node-v22.10.0-linux-x64.tar.xz \
&& tar -xJf /tmp/node-v22.10.0-linux-x64.tar.xz -C /usr/local --strip-components=1 \
&& rm /tmp/node-v22.10.0-linux-x64.tar.xz
RUN mkdir -p /root/.zig /root/.moon/bin /root/bin
# Install MoonBit toolchain
RUN curl -fsSL https://cli.moonbitlang.cn/install/unix.sh | bash
# Install zig toolchain
RUN curl -fsSL https://ziglang.org/download/0.13.0/zig-linux-x86_64-0.13.0.tar.xz | tar -xJf - -C /root/.zig --strip-components 1
# Install wasm-tools
RUN wget https://github.com/bytecodealliance/wasm-tools/releases/download/v1.219.1/wasm-tools-1.219.1-x86_64-linux.tar.gz -O /tmp/wasm-tools.tar.gz \
&& tar -xzf /tmp/wasm-tools.tar.gz -C /root/bin --strip-components=1 \
&& rm /tmp/wasm-tools.tar.gz
# Copy libriscv emulator
COPY --from=rvlinux-build /root/libriscv/emulator/.build /root/libriscv/emulator/.build
# Add ~/.moon/bin and ~/.zig to PATH
ENV PATH="/root/libriscv/emulator/.build:/root/.moon/bin:/root/bin:/root/.zig:${PATH}"
RUN moon update
# Zig build environment
FROM moonbit-build AS zig-build
COPY ./riscv_rt /root/riscv_rt
WORKDIR /root/riscv_rt
RUN zig build
# Build example implementation
FROM moonbit-build as example-build
WORKDIR /app
# No example implementation provided in public repository
# COPY . .
# RUN moon build
# Pre-install common build dependencies
WORKDIR /tmp
RUN moon new foo
WORKDIR /tmp/foo
RUN moon add moonbitlang/x
RUN moon add Yoorkin/ArgParser
RUN moon add Yoorkin/trie
RUN moon check
FROM moonbit-build
COPY --from=zig-build /root/riscv_rt/zig-out/lib/libmincaml.a /riscv_rt/libmincaml.a
# Check MoonBit version
RUN moon version --all
# Check Zig version
RUN zig version
# Check node version
RUN node --version
# Prebuild libc
RUN echo "int main() { return 0; }" > /tmp/main.c
RUN zig build-exe -target riscv64-linux -femit-bin=/tmp/main /tmp/main.c -fno-strip -mcpu=baseline_rv64
RUN rm /tmp/main.c /tmp/main
# Check libriscv version
RUN rvlinux --help
# Check wasm-tools version
RUN wasm-tools --version
## Copy example implementation
# Not copied due to being public repository
# COPY --from=example-build /app/target/wasm-gc/release/build/bin/bin.wasm /example/bin.wasm
# Copy dependency cache
COPY --from=example-build /root/.moon /root/.moon