-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathContainerfile
134 lines (112 loc) · 2.87 KB
/
Containerfile
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# Build stage: basic development tools
FROM debian:trixie-slim AS builder
RUN apt-get update
RUN apt install -y \
git \
less
# Requirements for RISC-V GCC
RUN apt install -y \
autoconf \
automake \
bc \
bison \
bzip2 \
curl \
libexpat-dev \
flex \
gawk \
g++ \
gperf \
libgmp-dev \
libmpfr-dev \
libtool \
make \
patchutils \
python3 \
texinfo \
zlib1g-dev
# Clone RISC-V GCC
WORKDIR /root/
RUN git clone --depth=1 --branch 2024.04.12 https://github.com/riscv-collab/riscv-gnu-toolchain
# Build RISC-V cross-compiler
WORKDIR /root/riscv-gnu-toolchain/
ENV RISCV=/opt/riscv/
RUN \
mkdir ${RISCV} && \
./configure --prefix=${RISCV} --with-arch=rv32emc --with-abi=ilp32e
RUN make
ENV PATH="${RISCV}/bin:${PATH}"
# Requirements for LLVM
RUN apt install -y \
cmake \
gcc \
ninja-build \
python3
# Clone LLVM
WORKDIR /root/
RUN git clone --depth=1 --branch llvmorg-18.1.4 https://github.com/llvm/llvm-project
# Build LLVM
WORKDIR /root/llvm-project/
ENV LLVM=/opt/llvm/
RUN \
mkdir ${LLVM} && \
cmake -S llvm -B build -G Ninja \
-DCMAKE_INSTALL_PREFIX=${LLVM} \
-DLLVM_ENABLE_PROJECTS="clang;lld" -DCMAKE_BUILD_TYPE=Release
# This will take some 10 min to few hours depending on the resources available on host
RUN ninja -C build install
# Requirements for Rust
RUN apt install -y \
pkg-config \
python3
# Clone the Rust compiler
WORKDIR /opt/
RUN \
git clone --branch 1.77.2 --depth 1 https://github.com/rust-lang/rust && \
cd rust
# Apply patches & configure Rust for build
WORKDIR /opt/rust/
COPY config.toml .
COPY patches .
RUN git config --global user.name "$(git --no-pager log --format=format:'%an' -n 1)" && \
git config --global user.email "$(git --no-pager log --format=format:'%ae' -n 1)" && \
git am --committer-date-is-author-date *.patch
# Build the Rust compiler
RUN ./x build \
library \
src/tools/rust-analyzer \
src/tools/rust-analyzer/crates/proc-macro-srv-cli \
src/tools/rustfmt
# A lean image with only what's necessary
FROM debian:trixie-slim AS minimal
RUN apt-get update
RUN apt install -y \
build-essential
# Copy RISC-V cross-compiler
ENV RISCV=/opt/riscv/
COPY --from=builder ${RISCV} ${RISCV}
ENV PATH="${RISCV}/bin:${PATH}"
# Copy Rust compiler
ENV RUST=/opt/rust/
COPY --from=builder ${RUST} ${RUST}
# Install rustup
RUN apt install -y \
curl
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
# Hook the new compiler into rustup
RUN \
rustup toolchain link rve-stage0 ${RUST}/build/host/stage0-sysroot && \
rustup toolchain link rve-stage1 ${RUST}/build/host/stage1 && \
rustup toolchain link rve ${RUST}/build/host/stage2 && \
rustup default rve
# A more refined image for further development
FROM minimal as devel
# Add optional tools for end-user
RUN apt-get update
RUN apt install -y \
binutils \
git \
tmux \
vim \
zsh