5 个版本
0.1.0-alpha.5 | 2023 年 12 月 15 日 |
---|---|
0.1.0-alpha.4 | 2023 年 4 月 5 日 |
#297 in Cargo 插件
在 swift-package 中使用
37KB
704 行
XCFramework
⚠️ 警告
此功能仍在开发中,尚未准备好使用
用于从 Rust 库构建 Apple XCFrameworks 的 Cargo 插件和库
功能
- 轻松从 Rust 库创建 Apple XCFrameworks
- 集成到 cargo 构建过程。使用与
cargo build
相似的参数运行cargo xcframework
Cargo.toml
中的[package.metadata.xcframework]
部分的配置- 目前支持为 iOS、macOS 和模拟器构建。如有需要,也可以添加 watchOS 和 tvOS。
入门指南
安装
cargoinstall xcframework
如果您需要最新的版本
cargo安装 --githttps://github.com/human-solutions/xcframework
帮助
cargoxcframework --help
有关设置项目,请参阅 示例
配置
构建的 XCFramework 将以 include-dir
目录中 module.modulemap
文件中声明的顶级模块名称命名。
这样的文件通常如下所示
// The XCFramework will be named 'MyModuleName.xcframework'
module MyModuleName {
// a header file in the same directory as the modulemap
header "mylib.h"
export *
}
在 [package.metadata.xcframework]
部分的 Cargo.toml 参数。
# Directory where the `module.modulemap` file and the headers are located.
#
# Note that the modulemap needs to be present in the directory because the
# module name declared in it is used for the framework name.
include-dir = "my-bin-name"
# The library type. Can be staticlib or cdylib
#
# Optional. This is only necessary if both library types are configured in the
# [lib] sections `crate-type` parameter. Overridden by the command line parameter `--lib-type`.
lib-type = "staticlib"
# Whether to zip the resulting XCFramework
#
# Optional. Defaults to true.
zip = true
# Enable Cargo to compile the standard library itself as part of a crate graph compilation.
# If enabled either run with `cargo +nightly xcframework`, set the default toolchain to nightly
# or set run `rustup override set nightly` in the project directory.
#
# Optional. Defaults to false. Requires nightly. Only useful for staticlib's, ignored for cdylibs.
build-std = false
# Whether to build for macOS
#
# Optional. Defaults to false.
macOS = false
# The macOS target triples
#
# Optional. Defaults to ["x86_64-apple-darwin", "aarch64-apple-darwin"].
macOS-targets = ["x86_64-apple-darwin", "aarch64-apple-darwin"]
# Whether to build the simulator targets. Not used when building for macOS.
#
# Optional. Defaults to false
simulators = false
# Whether to build for iOS
#
# Optional. Defaults to false.
iOS = false
# The iOS target triples
#
# Optional. Defaults to ["aarch64-apple-ios"].
iOS-targets = ["aarch64-apple-ios"]
# The iOS simulator target triples. Only used if `simulators` and `iOS` are true.
#
# Optional. Defaults to ["aarch64-apple-ios-sim", "x86_64-apple-ios"]
iOS-simulator-targets = ["aarch64-apple-ios-sim", "x86_64-apple-ios"]
# If there is interest, watchOS and tvOS can be added as well.
目标 iOS 和 macOS 版本可以通过环境变量 MACOSX_DEPLOYMENT_TARGET
和 IPHONEOS_DEPLOYMENT_TARGET
设置。有关默认值,请参阅 apple_base.rs。
依赖关系
~8-16MB
~202K SLoC