|
| 1 | +# syntax=docker/dockerfile:1 |
| 2 | +# This Dockerfile is adapted from https://github.com/LearningOS/rCore-Tutorial-v3/blob/main/Dockerfile |
| 3 | +# with the following major updates: |
| 4 | +# - ubuntu 18.04 -> 20.04 |
| 5 | +# - qemu 5.0.0 -> 7.0.0 |
| 6 | +# - Extensive comments linking to relevant documentation |
| 7 | +FROM ubuntu:20.04 |
| 8 | + |
| 9 | +ARG QEMU_VERSION=7.0.0 |
| 10 | +ARG HOME=/root |
| 11 | + |
| 12 | +# 0. Install general tools |
| 13 | +ARG DEBIAN_FRONTEND=noninteractive |
| 14 | +RUN apt-get update && \ |
| 15 | + apt-get install -y \ |
| 16 | + curl \ |
| 17 | + git \ |
| 18 | + python3 \ |
| 19 | + wget |
| 20 | + |
| 21 | +# 1. Set up QEMU RISC-V |
| 22 | +# - https://learningos.github.io/rust-based-os-comp2022/0setup-devel-env.html#qemu |
| 23 | +# - https://www.qemu.org/download/ |
| 24 | +# - https://wiki.qemu.org/Documentation/Platforms/RISCV |
| 25 | +# - https://risc-v-getting-started-guide.readthedocs.io/en/latest/linux-qemu.html |
| 26 | + |
| 27 | +# 1.1. Download source |
| 28 | +WORKDIR ${HOME} |
| 29 | +RUN wget https://download.qemu.org/qemu-${QEMU_VERSION}.tar.xz && \ |
| 30 | + tar xvJf qemu-${QEMU_VERSION}.tar.xz |
| 31 | + |
| 32 | +# 1.2. Install dependencies |
| 33 | +# - https://risc-v-getting-started-guide.readthedocs.io/en/latest/linux-qemu.html#prerequisites |
| 34 | +RUN apt-get install -y \ |
| 35 | + autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev \ |
| 36 | + gawk build-essential bison flex texinfo gperf libtool patchutils bc \ |
| 37 | + zlib1g-dev libexpat-dev git \ |
| 38 | + ninja-build pkg-config libglib2.0-dev libpixman-1-dev |
| 39 | + |
| 40 | +# 1.3. Build and install from source |
| 41 | +WORKDIR ${HOME}/qemu-${QEMU_VERSION} |
| 42 | +RUN ./configure --target-list=riscv64-softmmu,riscv64-linux-user && \ |
| 43 | + make -j$(nproc) && \ |
| 44 | + make install |
| 45 | + |
| 46 | +# 1.4. Clean up |
| 47 | +WORKDIR ${HOME} |
| 48 | +RUN rm -rf qemu-${QEMU_VERSION} qemu-${QEMU_VERSION}.tar.xz |
| 49 | + |
| 50 | +# 1.5. Sanity checking |
| 51 | +RUN qemu-system-riscv64 --version && \ |
| 52 | + qemu-riscv64 --version |
| 53 | + |
| 54 | +# 2. Set up Rust |
| 55 | +# - https://learningos.github.io/rust-based-os-comp2022/0setup-devel-env.html#qemu |
| 56 | +# - https://www.rust-lang.org/tools/install |
| 57 | +# - https://github.com/rust-lang/docker-rust/blob/master/Dockerfile-debian.template |
| 58 | + |
| 59 | +# 2.1. Install |
| 60 | +ENV RUSTUP_HOME=/usr/local/rustup \ |
| 61 | + CARGO_HOME=/usr/local/cargo \ |
| 62 | + PATH=/usr/local/cargo/bin:$PATH \ |
| 63 | + RUST_VERSION=nightly |
| 64 | +RUN set -eux; \ |
| 65 | + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o rustup-init; \ |
| 66 | + chmod +x rustup-init; \ |
| 67 | + ./rustup-init -y --no-modify-path --profile minimal --default-toolchain $RUST_VERSION; \ |
| 68 | + rm rustup-init; \ |
| 69 | + chmod -R a+w $RUSTUP_HOME $CARGO_HOME; |
| 70 | + |
| 71 | +# 2.2. Sanity checking |
| 72 | +RUN rustup --version && \ |
| 73 | + cargo --version && \ |
| 74 | + rustc --version |
| 75 | + |
| 76 | +# 3. Build env for labs |
| 77 | +# See os1/Makefile `env:` for example. |
| 78 | +# This avoids having to wait for these steps each time using a new container. |
| 79 | +RUN rustup target add riscv64gc-unknown-none-elf && \ |
| 80 | + cargo install cargo-binutils --vers ~0.2 && \ |
| 81 | + rustup component add rust-src && \ |
| 82 | + rustup component add llvm-tools-preview |
| 83 | + |
| 84 | +# Ready to go |
| 85 | +WORKDIR ${HOME} |
0 commit comments