rust - 如何为库指定 macOS 部署目标?
问题描述
我正在为 macOS 构建一个 AU 音频插件,该插件链接到使用 Cargo 编译的静态 Rust 库。我通过 CMake 编译我的插件,并将 macOS 部署目标设置为 10.9。在链接时,我收到大量错误,例如
ld: warning: object file (my/rust/libfoo.a (std-bd716fa574aff005.std.8vdpzfpj-cgu.15.rcgu.o)) was built for newer macOS version (10.15) than being linked (10.9)
运行 MacOS 10.13 的测试人员确认加载插件会导致崩溃。
我还需要为 10.9 的 macOS 部署目标编译 Rust 库,但我该怎么做呢?
我正在编译的库是 resvg,我修改了项目Cargo.toml
以在我自己的 fork 中输出一个静态库,您可以在此处找到。
我调用cargo build --release
并编译了我的静态库。
跑步
otool -l libresvg.a | rg LC_VERSION_MIN_MACOSX -A2 | sort | uniq
输出
cmdsize 16
version 10.15
version 10.7
解决方案
对于 x86 和 x86_64 目标, Rust默认以 macOS 10.7为目标(aarch64 目标为 11.0):
% cargo new --lib demo
% cd demo
% echo '[lib]' >> Cargo.toml
% echo 'crate-type = ["staticlib"]' >> Cargo.toml
% unset MACOSX_DEPLOYMENT_TARGET
% cargo build
# Older versions of macOS and/or x86 and x86_64
% otool -l target/debug/libdemo.a | rg LC_VERSION_MIN_MACOSX -A2 | rg version | sort | uniq -c
198 version 10.7
# Newer versions of macOS and/or aarch64
% otool -l target/debug/libdemo.a | rg LC_BUILD_VERSION -A4 | rg minos | sort | uniq -c
您可以通过指定环境变量来选择支持较新版本:MACOSX_DEPLOYMENT_TARGET
% export MACOSX_DEPLOYMENT_TARGET=10.12
% cargo clean && cargo build
% otool -l target/debug/libdemo.a | rg LC_VERSION_MIN_MACOSX -A2 | rg version | sort | uniq -c
2 version 10.12
196 version 10.7
如果您需要针对10.7之前的版本,我希望您必须重新编译 Rust 标准库本身。
推荐阅读
- google-chrome - 向响应标头添加多个值的方法
- amazon-web-services - cloudformation 多重 if 条件
- python - 如何使用存档获取网页的所有损坏链接?
- android - 无法在自定义 Rom [Android 11 (Rooted-Magisk)] 上执行颤振运行和 adb 安装/卸载
- firebase-cloud-messaging - 生成代码以获取 fcm 推送通知的刷新令牌的范围应该是什么?
- javascript - 如何自动归档输入框并单击搜索按钮?
- json - 获取返回对象类型的 JSON Schema
- java - Qt从java Activity调用c++方法
- .net - .NET 迁移默认为主数据库
- sql - SQL - FROM(子查询)和 WHERE - IN(子查询)之间的区别