From 03b6f0dd8b058801205913458a38cec7b537611f Mon Sep 17 00:00:00 2001 From: jklincn Date: Sat, 20 Jan 2024 15:24:32 +0800 Subject: [PATCH 1/3] chore(Dockerfile): fix rust-toolchain.toml and rewrite Dockerfile --- .dockerignore | 3 +- Dockerfile | 110 ++++++++++++++++++-------------------------- rust-toolchain.toml | 2 +- 3 files changed, 47 insertions(+), 68 deletions(-) diff --git a/.dockerignore b/.dockerignore index df3359dd..8971c06b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,2 @@ -*/* \ No newline at end of file +*/* +!rust-toolchain.toml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 284db4cf..acc2c458 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,85 +1,63 @@ # syntax=docker/dockerfile:1 -# This Dockerfile is adapted from https://github.com/LearningOS/rCore-Tutorial-v3/blob/main/Dockerfile -# with the following major updates: -# - ubuntu 18.04 -> 20.04 -# - qemu 5.0.0 -> 7.0.0 -# - Extensive comments linking to relevant documentation -FROM ubuntu:20.04 + +# Stage 1 Set up QEMU RISC-V +# - https://www.qemu.org/download/ +# - https://wiki.qemu.org/Hosts/Linux#Building_QEMU_for_Linux +# - https://wiki.qemu.org/Documentation/Platforms/RISCV + +FROM ubuntu:20.04 as build_qemu ARG QEMU_VERSION=7.0.0 -ARG HOME=/root -# 0. Install general tools -ARG DEBIAN_FRONTEND=noninteractive -RUN apt-get update && \ - apt-get install -y \ - curl \ - git \ - python3 \ - wget +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 -# 1. Set up QEMU RISC-V -# - https://learningos.github.io/rust-based-os-comp2022/0setup-devel-env.html#qemu -# - https://www.qemu.org/download/ -# - https://wiki.qemu.org/Documentation/Platforms/RISCV -# - https://risc-v-getting-started-guide.readthedocs.io/en/latest/linux-qemu.html - -# 1.1. Download source -WORKDIR ${HOME} RUN wget https://download.qemu.org/qemu-${QEMU_VERSION}.tar.xz && \ - tar xvJf qemu-${QEMU_VERSION}.tar.xz - -# 1.2. Install dependencies -# - https://risc-v-getting-started-guide.readthedocs.io/en/latest/linux-qemu.html#prerequisites -RUN apt-get 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 git \ - ninja-build pkg-config libglib2.0-dev libpixman-1-dev libsdl2-dev - -# 1.3. Build and install from source -WORKDIR ${HOME}/qemu-${QEMU_VERSION} -RUN ./configure --target-list=riscv64-softmmu,riscv64-linux-user && \ + tar xf qemu-${QEMU_VERSION}.tar.xz && \ + cd qemu-${QEMU_VERSION} && \ + ./configure --target-list=riscv64-softmmu,riscv64-linux-user && \ make -j$(nproc) && \ make install -# 1.4. Clean up -WORKDIR ${HOME} -RUN rm -rf qemu-${QEMU_VERSION} qemu-${QEMU_VERSION}.tar.xz +# Stage 2 Lab Environment +FROM ubuntu:20.04 as build -# 1.5. Sanity checking -RUN qemu-system-riscv64 --version && \ - qemu-riscv64 --version +WORKDIR /tmp -# 2. Set up Rust -# - https://learningos.github.io/rust-based-os-comp2022/0setup-devel-env.html#qemu +# 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 + +# 2. Install Rust # - https://www.rust-lang.org/tools/install -# - https://github.com/rust-lang/docker-rust/blob/master/Dockerfile-debian.template - -# 2.1. Install ENV RUSTUP_HOME=/usr/local/rustup \ CARGO_HOME=/usr/local/cargo \ - PATH=/usr/local/cargo/bin:$PATH \ - RUST_VERSION=nightly -RUN set -eux; \ - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o rustup-init; \ - chmod +x rustup-init; \ - ./rustup-init -y --no-modify-path --profile minimal --default-toolchain $RUST_VERSION; \ - rm rustup-init; \ - chmod -R a+w $RUSTUP_HOME $CARGO_HOME; - -# 2.2. Sanity checking -RUN rustup --version && \ - cargo --version && \ - rustc --version + 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 # 3. Build env for labs -# See os1/Makefile `env:` for example. +# See os/Makefile `env:` for example. # This avoids having to wait for these steps each time using a new container. +COPY rust-toolchain.toml rust-toolchain.toml RUN rustup target add riscv64gc-unknown-none-elf && \ - cargo install cargo-binutils --vers ~0.2 && \ - rustup component add rust-src && \ - rustup component add llvm-tools-preview + 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 -# Ready to go -WORKDIR ${HOME} +# Stage 3 Sanity checking +FROM build as test +RUN qemu-system-riscv64 --version && \ + qemu-riscv64 --version && \ + rustup --version && \ + cargo --version && \ + rustc --version \ No newline at end of file diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 3425f948..732feeaa 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -2,4 +2,4 @@ profile = "minimal" # use the nightly version of the last stable toolchain, see channel = "nightly-2023-10-09" -components = ["rust-src", "llvm-tools-preview", "rustfmt", "clippy"] +components = ["rust-src", "llvm-tools", "rustfmt", "clippy"] From 9bab4e16086ebe5032369ab64c820f801a33ee4b Mon Sep 17 00:00:00 2001 From: jklincn Date: Tue, 23 Jan 2024 11:09:05 +0800 Subject: [PATCH 2/3] fix: update Makefile (users don't need to build test stage) --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index bd267f46..ee4d7d1b 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,11 @@ -DOCKER_NAME ?= rcore-tutorial-v3 +DOCKER_TAG ?= rcore-tutorial-v3:latest .PHONY: docker build_docker docker: - docker run --rm -it -v ${PWD}:/mnt -w /mnt ${DOCKER_NAME} bash + docker run --rm -it -v ${PWD}:/mnt -w /mnt --name rcore-tutorial-v3 ${DOCKER_TAG} bash build_docker: - docker build -t ${DOCKER_NAME} . + docker build -t ${DOCKER_TAG} --target build . fmt: cd easy-fs; cargo fmt; cd ../easy-fs-fuse cargo fmt; cd ../os ; cargo fmt; cd ../user; cargo fmt; cd .. From f217e270a6c01404ec48254668bc463102eb22b5 Mon Sep 17 00:00:00 2001 From: jklincn Date: Fri, 26 Jan 2024 12:29:57 +0800 Subject: [PATCH 3/3] fix(Dockerfile): replace security sources mirrors --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index b9bf31b4..30731a7f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,7 @@ FROM ubuntu:20.04 as build_qemu ARG QEMU_VERSION=7.0.0 RUN sed -i 's/archive.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list && \ + sed -i 's/security.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