2022-07-18 07:23:20 +04:00
|
|
|
# syntax=docker/dockerfile:1
|
|
|
|
|
2024-01-20 11:24:32 +04:00
|
|
|
# Stage 1 Set up QEMU RISC-V
|
2022-07-18 07:23:20 +04:00
|
|
|
# - https://www.qemu.org/download/
|
2024-01-20 11:24:32 +04:00
|
|
|
# - https://wiki.qemu.org/Hosts/Linux#Building_QEMU_for_Linux
|
2022-07-18 07:23:20 +04:00
|
|
|
# - https://wiki.qemu.org/Documentation/Platforms/RISCV
|
|
|
|
|
2024-01-20 11:24:32 +04:00
|
|
|
FROM ubuntu:20.04 as build_qemu
|
2022-07-18 07:23:20 +04:00
|
|
|
|
2024-01-20 11:24:32 +04:00
|
|
|
ARG QEMU_VERSION=7.0.0
|
|
|
|
|
|
|
|
RUN sed -i 's/archive.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list && \
|
|
|
|
apt-get update && \
|
|
|
|
DEBIAN_FRONTEND=noninteractive apt-get install -y wget build-essential libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev ninja-build
|
2022-07-18 07:23:20 +04:00
|
|
|
|
2024-01-20 11:24:32 +04:00
|
|
|
RUN wget https://download.qemu.org/qemu-${QEMU_VERSION}.tar.xz && \
|
|
|
|
tar xf qemu-${QEMU_VERSION}.tar.xz && \
|
|
|
|
cd qemu-${QEMU_VERSION} && \
|
|
|
|
./configure --target-list=riscv64-softmmu,riscv64-linux-user && \
|
2022-07-18 07:23:20 +04:00
|
|
|
make -j$(nproc) && \
|
|
|
|
make install
|
|
|
|
|
2024-01-20 11:24:32 +04:00
|
|
|
# Stage 2 Lab Environment
|
|
|
|
FROM ubuntu:20.04 as build
|
2022-07-18 07:23:20 +04:00
|
|
|
|
2024-01-20 11:24:32 +04:00
|
|
|
WORKDIR /tmp
|
2022-07-18 07:23:20 +04:00
|
|
|
|
2024-01-20 11:24:32 +04:00
|
|
|
# 0. Install general tools
|
|
|
|
RUN sed -i 's/archive.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list && \
|
|
|
|
apt-get update && \
|
|
|
|
DEBIAN_FRONTEND=noninteractive apt-get install -y jq curl git python3 wget build-essential \
|
|
|
|
# qemu dependency
|
|
|
|
libglib2.0-0 libfdt1 libpixman-1-0 zlib1g
|
|
|
|
|
|
|
|
# 1. Copy qemu
|
|
|
|
COPY --from=build_qemu /usr/local/bin/* /usr/local/bin
|
2022-07-18 07:23:20 +04:00
|
|
|
|
2024-01-20 11:24:32 +04:00
|
|
|
# 2. Install Rust
|
|
|
|
# - https://www.rust-lang.org/tools/install
|
2022-07-18 07:23:20 +04:00
|
|
|
ENV RUSTUP_HOME=/usr/local/rustup \
|
|
|
|
CARGO_HOME=/usr/local/cargo \
|
2024-01-20 11:24:32 +04:00
|
|
|
PATH=/usr/local/cargo/bin:$PATH
|
|
|
|
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \
|
|
|
|
sh -s -- -y --no-modify-path --profile minimal --default-toolchain nightly
|
2022-07-18 07:23:20 +04:00
|
|
|
|
|
|
|
# 3. Build env for labs
|
2024-01-20 11:24:32 +04:00
|
|
|
# See os/Makefile `env:` for example.
|
2022-07-18 07:23:20 +04:00
|
|
|
# This avoids having to wait for these steps each time using a new container.
|
2024-01-20 11:24:32 +04:00
|
|
|
COPY rust-toolchain.toml rust-toolchain.toml
|
2022-07-18 07:23:20 +04:00
|
|
|
RUN rustup target add riscv64gc-unknown-none-elf && \
|
2024-01-20 11:24:32 +04:00
|
|
|
cargo install toml-cli cargo-binutils && \
|
|
|
|
RUST_VERSION=$(toml get -r rust-toolchain.toml toolchain.channel) && \
|
|
|
|
Components=$(toml get -r rust-toolchain.toml toolchain.components | jq -r 'join(" ")') && \
|
|
|
|
rustup install $RUST_VERSION && \
|
|
|
|
rustup component add --toolchain $RUST_VERSION $Components
|
|
|
|
|
|
|
|
# Stage 3 Sanity checking
|
|
|
|
FROM build as test
|
|
|
|
RUN qemu-system-riscv64 --version && \
|
|
|
|
qemu-riscv64 --version && \
|
|
|
|
rustup --version && \
|
|
|
|
cargo --version && \
|
|
|
|
rustc --version
|