mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2024-11-25 19:03:35 +04:00
Merge pull request #139 from jklincn/main
This commit is contained in:
parent
4218f5244c
commit
316dd35176
@ -1 +1,2 @@
|
|||||||
*/*
|
*/*
|
||||||
|
!rust-toolchain.toml
|
124
Dockerfile
124
Dockerfile
@ -1,88 +1,72 @@
|
|||||||
# syntax=docker/dockerfile:1
|
# syntax=docker/dockerfile:1
|
||||||
# This Dockerfile is adapted from https://github.com/LearningOS/rCore-Tutorial-v3/blob/main/Dockerfile
|
|
||||||
# with the following major updates:
|
# Stage 1 Build QEMU
|
||||||
# - ubuntu 18.04 -> 20.04
|
# - https://www.qemu.org/download/
|
||||||
# - qemu 5.0.0 -> 7.0.0
|
# - https://wiki.qemu.org/Hosts/Linux#Building_QEMU_for_Linux
|
||||||
# - Extensive comments linking to relevant documentation
|
# - https://wiki.qemu.org/Documentation/Platforms/RISCV
|
||||||
FROM ubuntu:20.04
|
|
||||||
|
FROM ubuntu:20.04 as build_qemu
|
||||||
|
|
||||||
ARG QEMU_VERSION=7.0.0
|
ARG QEMU_VERSION=7.0.0
|
||||||
ARG GDB_VERSION=14.1
|
|
||||||
ARG HOME=/root
|
|
||||||
|
|
||||||
# 0. Install general tools
|
RUN sed -i 's/archive.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list && \
|
||||||
ARG DEBIAN_FRONTEND=noninteractive
|
sed -i 's/security.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list && \
|
||||||
RUN apt-get update && \
|
apt-get update && \
|
||||||
apt-get install -y \
|
DEBIAN_FRONTEND=noninteractive apt-get install -y wget build-essential libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev ninja-build
|
||||||
curl \
|
|
||||||
git \
|
|
||||||
python3 \
|
|
||||||
wget
|
|
||||||
|
|
||||||
# 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 && \
|
RUN wget https://download.qemu.org/qemu-${QEMU_VERSION}.tar.xz && \
|
||||||
tar xvJf qemu-${QEMU_VERSION}.tar.xz
|
tar xf qemu-${QEMU_VERSION}.tar.xz && \
|
||||||
|
cd qemu-${QEMU_VERSION} && \
|
||||||
RUN wget https://ftp.gnu.org/gnu/gdb/gdb-${GDB_VERSION}.tar.xz && \
|
./configure --target-list=riscv64-softmmu,riscv64-linux-user && \
|
||||||
tar xvJf gdb-${GDB_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 \
|
|
||||||
libncurses5-dev python2 python2-dev libreadline-dev tmux
|
|
||||||
|
|
||||||
|
|
||||||
# 1.3. Build and install from source
|
|
||||||
WORKDIR ${HOME}/qemu-${QEMU_VERSION}
|
|
||||||
RUN ./configure --target-list=riscv64-softmmu,riscv64-linux-user && \
|
|
||||||
make -j$(nproc) && \
|
make -j$(nproc) && \
|
||||||
make install
|
make install
|
||||||
|
|
||||||
WORKDIR ${HOME}/gdb-${GDB_VERSION}
|
# Stage 2 Set Lab Environment
|
||||||
RUN ./configure --prefix=/usr/local --target=riscv64-unknown-elf --enable-tui=yes && \
|
FROM ubuntu:20.04 as build
|
||||||
make -j$(nproc) && \
|
|
||||||
make install
|
|
||||||
|
|
||||||
# 1.4. Clean up
|
WORKDIR /tmp
|
||||||
WORKDIR ${HOME}
|
|
||||||
RUN rm -rf qemu-${QEMU_VERSION} qemu-${QEMU_VERSION}.tar.xz ${HOME}/gdb-${GDB_VERSION} gdb-${GDB_VERSION}.tar.xz
|
|
||||||
|
|
||||||
# 1.5. Sanity checking
|
# 2.0. Install general tools
|
||||||
RUN qemu-system-riscv64 --version && \
|
RUN sed -i 's/archive.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list && \
|
||||||
qemu-riscv64 --version
|
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 \
|
||||||
|
# gdb
|
||||||
|
gdb-multiarch
|
||||||
|
|
||||||
# 2. Set up Rust
|
# 2.1. Copy qemu
|
||||||
# - https://learningos.github.io/rust-based-os-comp2022/0setup-devel-env.html#qemu
|
COPY --from=build_qemu /usr/local/bin/* /usr/local/bin
|
||||||
|
|
||||||
|
# 2.2. Install Rust
|
||||||
# - https://www.rust-lang.org/tools/install
|
# - 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 \
|
ENV RUSTUP_HOME=/usr/local/rustup \
|
||||||
CARGO_HOME=/usr/local/cargo \
|
CARGO_HOME=/usr/local/cargo \
|
||||||
PATH=/usr/local/cargo/bin:$PATH \
|
PATH=/usr/local/cargo/bin:$PATH \
|
||||||
RUST_VERSION=nightly
|
RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static \
|
||||||
RUN set -eux; \
|
RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
|
||||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o rustup-init; \
|
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \
|
||||||
chmod +x rustup-init; \
|
sh -s -- -y --no-modify-path --profile minimal --default-toolchain nightly
|
||||||
./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
|
# 2.3. Build env for labs
|
||||||
RUN rustup --version && \
|
# 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 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
|
||||||
|
|
||||||
|
# 2.4. Set GDB
|
||||||
|
RUN ln -s /usr/bin/gdb-multiarch /usr/bin/riscv64-unknown-elf-gdb
|
||||||
|
|
||||||
|
# Stage 3 Sanity checking
|
||||||
|
FROM build as test
|
||||||
|
RUN qemu-system-riscv64 --version && \
|
||||||
|
qemu-riscv64 --version && \
|
||||||
|
rustup --version && \
|
||||||
cargo --version && \
|
cargo --version && \
|
||||||
rustc --version
|
rustc --version && \
|
||||||
|
riscv64-unknown-elf-gdb --version
|
||||||
# Ready to go
|
|
||||||
WORKDIR ${HOME}
|
|
6
Makefile
6
Makefile
@ -1,11 +1,11 @@
|
|||||||
DOCKER_NAME ?= rcore-tutorial-v3
|
DOCKER_TAG ?= rcore-tutorial-v3:latest
|
||||||
.PHONY: docker build_docker
|
.PHONY: docker build_docker
|
||||||
|
|
||||||
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:
|
build_docker:
|
||||||
docker build -t ${DOCKER_NAME} .
|
docker build -t ${DOCKER_TAG} --target build .
|
||||||
|
|
||||||
fmt:
|
fmt:
|
||||||
cd os ; cargo fmt; cd ..
|
cd os ; cargo fmt; cd ..
|
||||||
|
@ -2,5 +2,5 @@
|
|||||||
profile = "minimal"
|
profile = "minimal"
|
||||||
# use the nightly version of the last stable toolchain, see <https://forge.rust-lang.org/>
|
# use the nightly version of the last stable toolchain, see <https://forge.rust-lang.org/>
|
||||||
channel = "nightly-2024-01-18"
|
channel = "nightly-2024-01-18"
|
||||||
components = ["rust-src", "llvm-tools-preview", "rustfmt", "clippy"]
|
components = ["rust-src", "llvm-tools", "rustfmt", "clippy"]
|
||||||
targets = ["riscv64gc-unknown-none-elf"]
|
targets = ["riscv64gc-unknown-none-elf"]
|
Loading…
Reference in New Issue
Block a user