第二部份 Cross Compile Rust Program Using Docker
(1) 在 Windows 下安裝及運行 Docker Desktop for Windows (https://docs.docker.com/desktop/install/windows-install/)
(2) 下載測試遊戲源代碼於 https://github.com/C14L/termsnake/archive/refs/heads/master.zip
(3) 解壓master.zip 於例如 C:\Users\user\Downloads
(4) 創建 Dockerfile 檔案於 例如 C:\Users\user\Downloads 如下內容- FROM rust:latest
-
- RUN apt update && apt upgrade -y
- RUN apt install -y g++-mingw-w64-x86-64
-
- RUN rustup target add x86_64-pc-windows-gnu
- RUN rustup toolchain install stable-x86_64-pc-windows-gnu
-
- WORKDIR /app
-
- CMD ["cargo", "build", "--target", "x86_64-pc-windows-gnu"]
複製代碼 (5) 使用 command prompt 建立 Docker Image- cd C:\Users\user\Downloads
- docker build . -t rust_cross_compile/windows
複製代碼 (6) 建立 Docker Image後 compile rust 程式- cd C:\Users\user\Downloads\master\termsnake-master
- docker run --rm -v C:\Users\user\Downloads\master\termsnake-master:/app rust_cross_compile/windows
複製代碼 (7) compile 成功後, 試運行- cd C:\Users\user\Downloads\master\termsnake-master
- cd target\x86_64-pc-windows-gnu\debug
- termsnake.exe
複製代碼 |