|
| 1 | +FROM sysprog21/rv32emu-gcc as base_gcc |
| 2 | +FROM sysprog21/rv32emu-sail as base_sail |
| 3 | + |
| 4 | +# for C++20 |
| 5 | +FROM ubuntu:23.10 as final |
| 6 | + |
| 7 | +# https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user#_creating-a-nonroot-user |
| 8 | +# add a non-root user |
| 9 | +ARG USERNAME=sysprog21 |
| 10 | +ARG USER_UID=1001 # NOTICE: 1000 already exists for 23.04 |
| 11 | +ARG USER_GID=$USER_UID |
| 12 | + |
| 13 | +# Create the user |
| 14 | +RUN groupadd --gid $USER_GID $USERNAME && \ |
| 15 | + useradd --uid $USER_UID --gid $USER_GID -m $USERNAME && \ |
| 16 | + # Add sudo support |
| 17 | + apt-get update && \ |
| 18 | + DEBIAN_FRONTEND=noninteractive apt-get install -y sudo && \ |
| 19 | + echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME && \ |
| 20 | + chmod 0440 /etc/sudoers.d/$USERNAME && \ |
| 21 | + rm -rf /var/lib/apt/lists/* |
| 22 | + |
| 23 | +# Set the default user |
| 24 | +USER $USERNAME |
| 25 | + |
| 26 | +# Install extra packages for the emulator to compile and execute with full capabilities correctly |
| 27 | +RUN sudo apt-get update && \ |
| 28 | + DEBIAN_FRONTEND=noninteractive sudo apt-get install -y \ |
| 29 | + python3-pip git clang strace gdb valgrind \ |
| 30 | + vim clang-tidy clang clang-tools libsdl2-dev libsdl2-mixer-dev && \ |
| 31 | + sudo rm -rf /var/lib/apt/lists/* |
| 32 | + |
| 33 | +# NOTICE the use of --break-system-packages |
| 34 | +RUN sudo python3 -m pip install git+https://github.com/riscv/riscof --break-system-packages |
| 35 | + |
| 36 | +# copy in the source code |
| 37 | +WORKDIR /home/$USERNAME/rv32emu |
| 38 | +COPY --chown=$USERNAME:$USERNAME . . |
| 39 | + |
| 40 | +# Copy the GNU Toolchain files |
| 41 | +ENV RISCV=/opt/riscv |
| 42 | +ENV PATH=$RISCV/bin:$PATH |
| 43 | +COPY --chown=$USERNAME:$USERNAME --from=base_gcc /opt/riscv/ /opt/riscv/ |
| 44 | + |
| 45 | +# replace the emulator (riscv_sim_RV32) with the arch that the container can execute |
| 46 | +RUN rm /home/$USERNAME/rv32emu/tests/arch-test-target/sail_cSim/riscv_sim_RV32 |
| 47 | +COPY --chown=$USERNAME:$USERNAME --from=base_sail /home/root/riscv_sim_RV32 /home/$USERNAME/rv32emu/tests/arch-test-target/sail_cSim/riscv_sim_RV32 |
| 48 | + |
| 49 | +# Set the default directory |
| 50 | +WORKDIR /home/$USERNAME/rv32emu |
| 51 | +RUN make distclean |
| 52 | + |
0 commit comments