|
1 |
| -FROM ubuntu:22.04 |
2 |
| -LABEL maintainer="henrybear327@gmail.com" |
| 1 | +FROM sysprog21/rv32emu-gcc as base_gcc |
| 2 | +FROM sysprog21/rv32emu-sail as base_sail |
3 | 3 |
|
4 |
| -# Install packages required for the emulator to compile and execute correctly |
| 4 | +FROM ubuntu:22.04 as final |
| 5 | + |
| 6 | +# Install extra packages for the emulator to compile and execute with full capabilities correctly |
5 | 7 | RUN apt-get update && \
|
6 | 8 | DEBIAN_FRONTEND=noninteractive apt-get install -y \
|
7 |
| - libsdl2-dev libsdl2-mixer-dev python3-pip git |
| 9 | + libsdl2-dev libsdl2-mixer-dev python3-pip git && \ |
| 10 | + rm -rf /var/lib/apt/lists/* |
8 | 11 |
|
9 | 12 | RUN python3 -m pip install git+https://github.com/riscv/riscof
|
10 | 13 |
|
11 | 14 | # set up the timezone
|
12 | 15 | ENV TZ=Asia/Taipei
|
13 | 16 | RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
14 | 17 |
|
15 |
| -# when using apt install gcc-riscv64-unknown-elf, this will cause "unsupported ISA subset 'z'" during compilation |
16 |
| -# thus, we are building from scratch, following the version here -> https://github.com/sysprog21/rv32emu/blob/master/.ci/riscv-toolchain-install.sh |
17 |
| -# for x86, we can optimize this part and take the nightly build directly, but not for aarch64 |
18 |
| -ENV RISCV=/opt/riscv |
19 |
| -ENV PATH=$RISCV/bin:$PATH |
20 |
| -WORKDIR $RISCV |
21 |
| -RUN apt install -y autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev |
22 |
| -RUN git clone --recursive https://github.com/riscv/riscv-gnu-toolchain |
23 |
| -RUN cd riscv-gnu-toolchain && \ |
24 |
| - git checkout tags/2023.10.06 && \ |
25 |
| - ./configure --prefix=/opt/riscv --with-arch=rv32gc --with-abi=ilp32d && \ |
26 |
| - make -j$(nproc) && \ |
27 |
| - make clean |
28 |
| - |
29 |
| -# the default reference emulator is x86-based |
30 |
| -# we need to build it ourselves if we are using it on aarch64 |
31 |
| -# https://riscof.readthedocs.io/en/stable/installation.html#install-plugin-models |
32 |
| -# the above commands are modified to match the current build flow as indicated in the Github CI -> https://github.com/riscv/sail-riscv/blob/master/.github/workflows/compile.yml |
33 |
| -WORKDIR /home/root/ |
34 |
| -RUN apt install -y opam zlib1g-dev pkg-config libgmp-dev z3 device-tree-compiler |
35 |
| -RUN opam init --disable-sandboxing -y |
36 |
| -RUN opam install -y sail |
37 |
| -RUN git clone https://github.com/riscv/sail-riscv.git |
38 |
| -# based on this commit https://github.com/sysprog21/rv32emu/commit/01b00b6f175f57ef39ffd1f4fa6a611891e36df3#diff-3b436c5e32c40ecca4095bdacc1fb69c0759096f86e029238ce34bbe73c6e68f |
39 |
| -# we infer that the sail-riscv binary was taken from commit 9547a30bf84572c458476591b569a95f5232c1c7 |
40 |
| -RUN cd sail-riscv && \ |
41 |
| - git checkout 9547a30bf84572c458476591b569a95f5232c1c7 && \ |
42 |
| - eval $(opam env) && \ |
43 |
| - make && \ |
44 |
| - ARCH=RV32 make |
45 |
| - |
46 | 18 | # copy in the source code
|
47 | 19 | WORKDIR /home/root/rv32emu
|
48 | 20 | COPY . .
|
49 | 21 |
|
| 22 | +# Copy the GNU Toolchain files |
| 23 | +ENV RISCV=/opt/riscv |
| 24 | +ENV PATH=$RISCV/bin:$PATH |
| 25 | +COPY --from=base_gcc /opt/riscv/ /opt/riscv/ |
| 26 | + |
50 | 27 | # replace the emulator (riscv_sim_RV32) with the arch that the container can execute
|
51 | 28 | RUN rm /home/root/rv32emu/tests/arch-test-target/sail_cSim/riscv_sim_RV32
|
52 |
| -RUN cp /home/root/sail-riscv/c_emulator/riscv_sim_RV32 /home/root/rv32emu/tests/arch-test-target/sail_cSim/riscv_sim_RV32 |
53 |
| - |
54 |
| -# clean up apt cache |
55 |
| -RUN rm -rf /var/lib/apt/lists/* |
| 29 | +COPY --from=base_sail /home/root/riscv_sim_RV32 /home/root/rv32emu/tests/arch-test-target/sail_cSim/riscv_sim_RV32 |
0 commit comments