尧图精选

在 macOS 上如何用 Apple container 容器运行 RustPython 的 Linux 测试?

🕒 发布时间:2026/9/14 16:45:45 📁 来源:尧图网络
在 macOS 上如何用 Apple container 容器运行 RustPython 的 Linux 测试【免费下载链接】RustPythonA Python Interpreter written in Rust项目地址: https://gitcode.com/GitHub_Trending/ru/RustPythonRustPython 是用 Rust 编写的 Python 解释器开发过程中需要跑它的 Python 标准库测试套件-m test和 Rust 单元测试。在 macOS 上想获得一个 Linux 环境来执行这些测试时不必搭建虚拟机CONTRIBUTING.md 的 “Testing on Linux from macOS” 小节给出了完整流程——用 Apple 的containerCLI 构建一个 Linux 开发镜像启动一个常驻容器然后在容器内执行测试命令。注意文档给出的 setup 命令固定了--arch arm64且注释明确该配置面向 arm64-only builds禁用 Rosetta 要求因此这套命令对应 Apple 芯片的 Mac。前置条件本地已克隆 RustPython 仓库后续所有命令都在仓库根目录下执行该目录包含Cargo.toml和.devcontainer/Dockerfile系统已安装 Homebrew用于安装containerCLI。开发镜像由 .devcontainer/Dockerfile 构建其基础镜像是FROM rust:bullseye并安装clang也就是说容器内的 Rust 工具链来自这个镜像与宿主机上是否装有 Rust 无关。一次性设置安装 CLI 并构建开发镜像在仓库根目录执行对应文档 “Setup (one-time)”# Install container CLI brew install container # Disable Rosetta requirement for arm64-only builds defaults write com.apple.container.defaults build.rosetta -bool false # Build the development image container build --arch arm64 -t rustpython-dev -f .devcontainer/Dockerfile .三条命令的作用依次是通过 Homebrew 安装containerCLI关闭 arm64-only 构建对 Rosetta 的要求以仓库根目录为构建上下文、按.devcontainer/Dockerfile构建一个名为rustpython-dev的 arm64 开发镜像。这三步只需做一次。启动常驻测试容器镜像就绪后启动一个后台常驻容器用于反复执行命令# Start a persistent container in background (8GB memory, 4 CPUs for compilation) container run -d --name rustpython-test -m 8G -c 4 \ --mount typebind,source$(pwd),target/workspace \ -w /workspace rustpython-dev sleep infinity各参数对应文档注释的说明-d后台启动常驻容器--name rustpython-test容器名后续container exec用它定位容器-m 8G -c 4按文档注释分配 8GB 内存、4 个 CPU用于编译--mount typebind,source$(pwd),target/workspace把当前目录即仓库根目录绑定挂载到容器内的/workspace容器里编译出的产物和读取的源码都指向这份本地目录-w /workspace把工作目录设为/workspacerustpython-dev sleep infinity使用上一步构建的镜像并以sleep infinity保持容器不退出以便随时exec进容器执行命令。在容器内运行测试通过container exec在容器内执行测试。文档给出的示例是运行单个标准库测试模块test_ensurepip对应Lib/test下的同名模块# Run tests inside the container container exec rustpython-test sh -c cargo run --release -- -m test test_ensurepip同一条exec模式可用于执行容器内的任意命令文档中演示的是一条 workspace Rust 单元测试# Run any command container exec rustpython-test sh -c cargo test --workspace如果目标是按文档 “Testing” 一节的标准方式跑 Rust 单元测试应使用带排除项的命令rustpython_wasm、rustpython-venvlauncher、rustpython-capi不在其中测试把上面exec的示例换成container exec rustpython-test sh -c cargo test --workspace --exclude rustpython_wasm --exclude rustpython-venvlauncher --exclude rustpython-capi而rustpython-capi有独立的cargo配置需要进入crates/capi目录单独测试container exec rustpython-test sh -c cd crates/capi cargo test标准库测试-m test支持文档列出的几个选项在容器里同样适用-j n并行测试文档建议线程数尽量等于 CPU 核数不确定时用-j 4或-j 8本容器按文档配置为 4 个 CPU-v打开详细模式test_name指定只跑单个测试模块。例如全量并行container exec rustpython-test sh -c cargo run --release -- -m test -j 4或者按文档示例只跑test_cmath位于Lib/test/test_cmath并输出详细信息container exec rustpython-test sh -c cargo run --release -- -m test test_cmath -v文档没有给出这些测试命令的示例输出是否通过以测试命令自身打印的结果为准加-v可以看到正在运行的测试的更多信息。收尾停止并删除容器文档的说明是 “Stop and remove the container when done”# Stop and remove the container when done container rm -f rustpython-test该命令会强制停止并删除rustpython-test容器。仓库目录是通过 bind mount 映射进容器的删除容器不会影响本地仓库中的源码。限制说明文档中的 setup 命令固定--arch arm64并关闭 arm64-only 构建的 Rosetta 要求文档未提供面向 Intel Mac 的替代流程容器内工具链来自.devcontainer/Dockerfilerust:bullseyeclang构建的rustpython-dev镜像若该 Dockerfile 有变更需要重新执行container build再启动容器本流程覆盖在 macOS 上用containerCLI 跑 RustPython 的 Linux 测试这一任务若要在 macOS 宿主机上直接开发而非容器内环境要求见 CONTRIBUTING.md 的 “Setting up a development environment” 一节。【免费下载链接】RustPythonA Python Interpreter written in Rust项目地址: https://gitcode.com/GitHub_Trending/ru/RustPython创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
上一篇/下一篇内容由系统自动关联 返回资讯列表 →