rcore-os / rCore-Tutorial-v3

Let's write an OS which can run on RISC-V in Rust from scratch!
https://rcore-os.github.io/rCore-Tutorial-Book-v3/index.html
GNU General Public License v3.0
1.64k stars 470 forks source link

Rewrite Dockerfile #139

Closed jklincn closed 9 months ago

jklincn commented 9 months ago

138

The image built by the new Dockerfile has been tested by

cd os
make run

···

**************/
Rust user shell
>> usertests

···

34 of sueecssed apps, 9 of failed apps run correctly. 
Usertests passed!

and the results remain the same as before.

wyfcyx commented 9 months ago

That's great! Could you please:

  1. Fix the conflicts and install the gdb as the latest Dockerfile does
  2. Setup the rustup/cargo mirror to tsinghua/ustc by default. This is because, now it still takes a long period of time to install rust.

Thank you!

jklincn commented 9 months ago

It's done.

Tsinghua mirror for rustup may exist some problems. So I use ustc mirror.

Details

According to [website instructions](https://mirrors.tuna.tsinghua.edu.cn/help/rustup/), I set the environment variable. ``` RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup RUSTUP_UPDATE_ROOT=https://mirrors.tuna.tsinghua.edu.cn/rustup/rustup ``` But when I was installing Rust, some errors occurred. ``` 0.729 curl: (22) The requested URL returned error: 404 0.730 rustup: command failed: downloader https://mirrors.tuna.tsinghua.edu.cn/rustup/rustup/dist/x86_64-unknown-linux-gnu/rustup-init /tmp/tmp.bg0230SesP/rustup-init x86_64-unknown-linux-gnu ``` So I set ustc mirror, and there is nothing wrong. ``` RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup ```

About the gdb, I think gdb-multiarch can meet the demand, which can install directly through apt. To maintain compatibility with the existing makefile, I set up a symbolic link.

ln -s /usr/bin/gdb-multiarch /usr/bin/riscv64-unknown-elf-gdb

I conducted the following tests:

By the way, why I use raw command instead of rules in makefile? I think most Docker users are in a Windows environment. Firstly, Windows does not have 'make', and secondly, syntax like '$pwd' is not usable in Windows.

However, the latest commit further simplifies the use of Docker, which can avoid these problems with the makefile. The dev container is great! #134

wyfcyx commented 9 months ago

This error occurred when I tried to make run:

error: failed to run custom build command for `os v0.1.0 (/workspaces/rCore-Tutorial-v3/os)`

Caused by:
  process didn't exit successfully: `/workspaces/rCore-Tutorial-v3/os/target/release/build/os-7e6bed51b1b92f69/build-script-build` (exit status: 1)
  --- stderr
  /workspaces/rCore-Tutorial-v3/os/target/release/build/os-7e6bed51b1b92f69/build-script-build: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /workspaces/rCore-Tutorial-v3/os/target/release/build/os-7e6bed51b1b92f69/build-script-build)
  /workspaces/rCore-Tutorial-v3/os/target/release/build/os-7e6bed51b1b92f69/build-script-build: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by /workspaces/rCore-Tutorial-v3/os/target/release/build/os-7e6bed51b1b92f69/build-script-build)
  /workspaces/rCore-Tutorial-v3/os/target/release/build/os-7e6bed51b1b92f69/build-script-build: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by /workspaces/rCore-Tutorial-v3/os/target/release/build/os-7e6bed51b1b92f69/build-script-build)
warning: build failed, waiting for other jobs to finish...
make: *** [Makefile:60: kernel] Error 101
root@b357e6421778:/workspaces/rCore-Tutorial-v3/os# ldd --version
ldd (Ubuntu GLIBC 2.31-0ubuntu9.14) 2.31
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

It seems that the latest Rust toolchain requires glibc version 2.32. Unfortunately, the version of glibc is 2.31 in our docker environment by default. Maybe we need to upgrade the glibc?

By the way, we still need some network proxy tricks even if we have set the rustup/cargo mirror...

  1. remove proxy in ~/.gitconfig
  2. set network proxy in docker desktop 0125
jklincn commented 9 months ago
  1. Are you using GitHub's workspace? I haven't encountered such errors in my local Docker container.

    Snipaste_2024-01-26_11-45-01

  2. When building without a network proxy, I found that it gets stuck during the download of the QEMU source code package. In such cases, if one insists on using the official download link, there might not be a good solution. Typically, I have two solutions for this: one is to download the package to a server where it can be directly accessed from within China, like Alibaba Cloud Object Storage. The other is to directly provide users with a pre-built image, which can be hosted on Docker Hub (though Docker Hub might need a change of mirror source, but this is very simple).

    image

wyfcyx commented 9 months ago

~It seems that you are not using the devcontainer extension of the vscode to build and run the container. When I tried to do that, the error of glibc version encountered. When I manually build and run the container, the same error encountered. That is weird...~

It works! I forgot to clean the objects compiled in my ubuntu22.04 wsl, making the difference of the glibc version. Thanks to this post.

jklincn commented 9 months ago

Congratulation!