|
| 1 | +FROM ubuntu:24.04 |
| 2 | + |
| 3 | +ENV DEBIAN_FRONTEND=noninteractive |
| 4 | + |
| 5 | +# 使用清华源加速 apt |
| 6 | +RUN sed -i 's/archive.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list.d/ubuntu.sources && \ |
| 7 | + sed -i 's/security.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list.d/ubuntu.sources |
| 8 | + |
| 9 | +# 安装基础开发工具和依赖 |
| 10 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 11 | + git build-essential curl wget python3 python3-pip ninja-build cmake \ |
| 12 | + autoconf automake autotools-dev bison flex texinfo gperf libtool patchutils \ |
| 13 | + libtool-bin help2man gawk \ |
| 14 | + pkg-config libglib2.0-dev libpixman-1-dev libsdl2-dev libslirp-dev \ |
| 15 | + libncurses5-dev libreadline-dev libssl-dev sudo tmux unzip xz-utils ca-certificates \ |
| 16 | + gcc-riscv64-linux-gnu g++-riscv64-linux-gnu \ |
| 17 | + libgmp-dev libexpat1-dev fish libmpfr-dev libmpc-dev \ |
| 18 | + lldb \ |
| 19 | + && rm -rf /var/lib/apt/lists/* |
| 20 | + |
| 21 | +# 安装 Python tomli(QEMU 编译需求) |
| 22 | +RUN pip3 install tomli --break-system-packages |
| 23 | + |
| 24 | +# 新建非 root 用户 vscode |
| 25 | +RUN useradd -m -s /bin/bash vscode && \ |
| 26 | + echo "vscode ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers |
| 27 | + |
| 28 | +# 安装 Rust nightly 工具链并设为默认(作为 vscode 用户) |
| 29 | +USER vscode |
| 30 | +ENV CARGO_HOME=/home/vscode/.cargo |
| 31 | +ENV RUSTUP_HOME=/home/vscode/.rustup |
| 32 | +ENV PATH="${CARGO_HOME}/bin:${PATH}" |
| 33 | + |
| 34 | +# 配置 Rust 使用中科大镜像源 |
| 35 | +ENV RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static |
| 36 | +ENV RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup |
| 37 | + |
| 38 | +# 先安装 rustup |
| 39 | +RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain none |
| 40 | + |
| 41 | +# 然后安装指定版本的 nightly |
| 42 | +RUN rustup toolchain install nightly-2025-01-13 && \ |
| 43 | + rustup default nightly-2025-01-13 && \ |
| 44 | + rustup component add rustfmt clippy rust-src rust-analyzer && \ |
| 45 | + rustup target add \ |
| 46 | + riscv64gc-unknown-none-elf \ |
| 47 | + riscv64imac-unknown-none-elf \ |
| 48 | + loongarch64-unknown-linux-gnu \ |
| 49 | + loongarch64-unknown-none \ |
| 50 | + x86_64-unknown-linux-gnu |
| 51 | + |
| 52 | +# 配置 cargo 中科大镜像 |
| 53 | +RUN mkdir -p ${CARGO_HOME} && \ |
| 54 | + echo '[source.crates-io]' > ${CARGO_HOME}/config.toml && \ |
| 55 | + echo 'registry = "https://github.com/rust-lang/crates.io-index"' >> ${CARGO_HOME}/config.toml && \ |
| 56 | + echo 'replace-with = "ustc"' >> ${CARGO_HOME}/config.toml && \ |
| 57 | + echo '' >> ${CARGO_HOME}/config.toml && \ |
| 58 | + echo '[source.ustc]' >> ${CARGO_HOME}/config.toml && \ |
| 59 | + echo 'registry = "git://mirrors.ustc.edu.cn/crates.io-index"' >> ${CARGO_HOME}/config.toml |
| 60 | + |
| 61 | +# 切回 root 编译 QEMU 与 GDB |
| 62 | +USER root |
| 63 | +WORKDIR /root |
| 64 | + |
| 65 | +# 编译安装 QEMU 9.2.1 |
| 66 | +RUN wget https://download.qemu.org/qemu-9.2.1.tar.xz && \ |
| 67 | + tar -xf qemu-9.2.1.tar.xz && cd qemu-9.2.1 && \ |
| 68 | + ./configure --target-list=riscv64-softmmu,riscv64-linux-user,loongarch64-softmmu,loongarch64-linux-user \ |
| 69 | + --enable-sdl --enable-slirp && \ |
| 70 | + make -j$(nproc) && make install && \ |
| 71 | + cd .. && rm -rf qemu-9.2.1* |
| 72 | + |
| 73 | +# 编译安装 GDB 13.1 |
| 74 | +RUN wget https://mirrors.tuna.tsinghua.edu.cn/gnu/gdb/gdb-13.1.tar.xz && \ |
| 75 | + tar -xf gdb-13.1.tar.xz |
| 76 | + |
| 77 | +WORKDIR /root/gdb-13.1 |
| 78 | +RUN mkdir build-loongarch64 && cd build-loongarch64 && \ |
| 79 | + ../configure --prefix=/usr/local --target=loongarch64-unknown-elf --enable-tui=yes && \ |
| 80 | + make -j$(nproc) && make install |
| 81 | + |
| 82 | +WORKDIR /root/gdb-13.1 |
| 83 | +RUN mkdir build-riscv64 && cd build-riscv64 && \ |
| 84 | + ../configure --prefix=/usr/local --target=riscv64-unknown-elf --enable-tui=yes && \ |
| 85 | + make -j$(nproc) && make install |
| 86 | + |
| 87 | +# 设置 vscode 用户工作目录 |
| 88 | +USER vscode |
| 89 | +WORKDIR /workspace |
| 90 | +SHELL ["/bin/fish", "-c"] |
| 91 | +CMD ["fish"] |
0 commit comments