Contents

Contents

在 MacOS 上提速 Rust 编译

Contents

MacOS 下使用编译型语言开发时,编译耗时很久,最近在搞一些 Rust 相关的东西时,发现了问题根源,在此做个记录

TLDR:由 MacOS XProtect 单线程扫描机制造成阻塞,将日常开发工具添加到系统设置 - 隐私和安全性 - 开发者工具中,避免由这些工具产生的二进制文件被 XProtect 扫描即可

XProtect 会在这些时机检测恶意内容:

  • App 首次启动时
  • App 变化时(在文件系统中)
  • XProtect 签名更新时

换句话说,XProtect 会在每个可执行程序首次运行时进行恶意内容检测。对于从互联网下载的文件来说很合理,但是如果程序是你自己编译出来的,那就不合理了,而且在 Rust 开发过程中,编译过程会产生大量中间临时脚本、文件等,所以会对 Rust 编译造成显著影响

那么,解决方法是什么?

在 Zed 编辑器的 官方文档 中有提到这个问题,并且提供了链接 cargo-nextest 的 官方文档,其中就给出了解决方案

How to add your terminal to Developer Tools

  1. Run sudo spctl developer-mode enable-terminal in your terminal.
  2. Go to System Preferences, and then to Security & Privacy.
  3. Under the Privacy tab, an item called Developer Tools should be present. Navigate to it.
  4. Ensure that your terminal is listed and enabled. If you’re using a third-party terminal like iTerm, be sure to add it to the list. (You may have to click the lock in the bottom-left corner and authenticate.)
  5. Restart your terminal.
20251226130504707

按照这种方法,把日常使用的工具都加入这个开发者工具配置即可,实测效果非常明显 🎉🎉🎉