Skip to content

Commit 6e516f7

Browse files
committed
Merge branch 'ch2' into ch3
2 parents 047a89d + 3495f48 commit 6e516f7

File tree

3 files changed

+74
-55
lines changed

3 files changed

+74
-55
lines changed

Dockerfile

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,90 @@
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
1+
# Reconstructed Dockerfile from docker history
2+
# Base image: Ubuntu 22.04
3+
FROM ubuntu:22.04
84

5+
# Build arguments
6+
ARG RELEASE
7+
ARG LAUNCHPAD_BUILD_ARCH
98
ARG QEMU_VERSION=7.0.0
109
ARG HOME=/root
11-
12-
# 0. Install general tools
1310
ARG DEBIAN_FRONTEND=noninteractive
11+
12+
# Install basic tools
1413
RUN apt-get update && \
1514
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}
15+
curl \
16+
git \
17+
python3 \
18+
wget \
19+
xz-utils
20+
21+
# Set working directory
22+
WORKDIR /root
23+
24+
# Download and extract QEMU
2925
RUN wget https://download.qemu.org/qemu-${QEMU_VERSION}.tar.xz && \
3026
tar xvJf qemu-${QEMU_VERSION}.tar.xz
3127

32-
# 1.2. Install dependencies
33-
# - https://risc-v-getting-started-guide.readthedocs.io/en/latest/linux-qemu.html#prerequisites
28+
# Install QEMU build dependencies
3429
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 libsdl2-dev
30+
autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev \
31+
gawk build-essential bison flex texinfo gperf libtool patchutils bc \
32+
zlib1g-dev libexpat-dev git \
33+
ninja-build pkg-config libglib2.0-dev libpixman-1-dev libsdl2-dev
3934

40-
# 1.3. Build and install from source
41-
WORKDIR ${HOME}/qemu-${QEMU_VERSION}
35+
# Build and install QEMU
36+
WORKDIR /root/qemu-7.0.0
4237
RUN ./configure --target-list=riscv64-softmmu,riscv64-linux-user && \
4338
make -j$(nproc) && \
4439
make install
4540

46-
# 1.4. Clean up
47-
WORKDIR ${HOME}
41+
# Clean up QEMU build files
42+
WORKDIR /root
4843
RUN rm -rf qemu-${QEMU_VERSION} qemu-${QEMU_VERSION}.tar.xz
4944

50-
# 1.5. Sanity checking
45+
# Verify QEMU installation
5146
RUN qemu-system-riscv64 --version && \
5247
qemu-riscv64 --version
5348

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
49+
# Set up Rust environment
6050
ENV RUSTUP_HOME=/usr/local/rustup \
6151
CARGO_HOME=/usr/local/cargo \
62-
PATH=/usr/local/cargo/bin:$PATH \
52+
PATH=/usr/local/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
6353
RUST_VERSION=nightly
54+
55+
# Install Rust
6456
RUN set -eux; \
6557
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o rustup-init; \
6658
chmod +x rustup-init; \
6759
./rustup-init -y --no-modify-path --profile minimal --default-toolchain $RUST_VERSION; \
6860
rm rustup-init; \
6961
chmod -R a+w $RUSTUP_HOME $CARGO_HOME;
7062

71-
# 2.2. Sanity checking
63+
# Verify Rust installation
7264
RUN rustup --version && \
7365
cargo --version && \
7466
rustc --version
7567

7668
# 2.3 Env
7769
RUN cargo install cargo-binutils; \
7870
rustup target add riscv64gc-unknown-none-elf; \
79-
rustup component add rust-src; \
80-
rustup component add llvm-tools-preview; \
81-
rustup component add rustfmt; \
82-
rustup component add clippy;
83-
84-
# 3. Cargo vendor
85-
WORKDIR ${HOME}
86-
COPY os/vendor ./os-vendor
87-
COPY user/vendor ./user-vendor
88-
89-
# Ready to go
90-
WORKDIR ${HOME}
71+
rustup component add rust-src; \
72+
rustup component add llvm-tools-preview; \
73+
rustup component add rustfmt; \
74+
rustup component add clippy;
75+
76+
77+
# Install Rust components and tools for rCore development
78+
RUN rustup default $RUST_VERSION; \
79+
cargo install cargo-binutils; \
80+
rustup target add riscv64gc-unknown-none-elf; \
81+
rustup component add rust-src; \
82+
rustup component add llvm-tools-preview; \
83+
rustup component add rustfmt; \
84+
rustup component add clippy;
85+
86+
# Set working directory
87+
WORKDIR /root
88+
89+
# Default command
90+
CMD ["/bin/bash"]

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
DOCKER_NAME ?= rcore-tutorial-v3
1+
DOCKER_NAME ?= rcore-docker
22
.PHONY: docker build_docker
33

44
docker:
5-
docker run --rm -it -v ${PWD}:/mnt -w /mnt ${DOCKER_NAME} bash
5+
docker run --network host --rm -it -v ${PWD}:/mnt -w /mnt ${DOCKER_NAME} bash
66

77
build_docker:
88
docker build -t ${DOCKER_NAME} .

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,25 @@ $ cd os
3939
$ make run
4040
```
4141

42+
If you want to use docker to build and run, you can use the following command:
43+
```bash
44+
# After clone the `rCore-Tutorial-Test` repository to your local machine, you can use the following command to build and run:
45+
$ make build_docker
46+
$ make docker
47+
```
48+
49+
If you experience network issues when accessing foreign resources such as GitHub in Docker, you can follow the following suggestions according to your stage:
50+
51+
- Docker pull:
52+
1. use proxy: https://docs.docker.com/reference/cli/docker/image/pull/#proxy-configuration
53+
54+
2. use available domestic source (self-search)
55+
56+
- Docker build: use proxy https://docs.docker.com/engine/cli/proxy/#build-with-a-proxy-configuration
57+
58+
- Docker run: use proxy option, related operations are similar to `Docker build`, can refer to the relevant materials by yourself
59+
60+
4261
Notice: $ID is from [1-9]
4362

4463
## Grading

0 commit comments

Comments
 (0)