#macos-ios #swift #ios #uniffi #macos #spm

bin+lib cargo-swift

一个 cargo 插件,用于从 Rust 代码轻松构建 Swift 包,用于 iOS 和 macOS 应用程序

21 个不稳定版本 (7 个破坏性版本)

0.8.0 2024年7月30日
0.7.0 2024年3月29日
0.5.1 2023年12月22日
0.5.0 2023年11月3日
0.2.2 2023年2月16日

#53 in Cargo 插件

Download history 21/week @ 2024-05-01 16/week @ 2024-05-08 20/week @ 2024-05-15 22/week @ 2024-05-22 32/week @ 2024-05-29 63/week @ 2024-06-05 49/week @ 2024-06-12 3/week @ 2024-06-19 14/week @ 2024-06-26 30/week @ 2024-07-03 8/week @ 2024-07-10 50/week @ 2024-07-17 746/week @ 2024-07-24 636/week @ 2024-07-31 500/week @ 2024-08-07 578/week @ 2024-08-14

2,491 每月下载量

MIT/Apache

69KB
2K SLoC

cargo-swift

Language: Rust Crates.io Version Dependency Status

Build Publish Examples E2E Tests Clippy Dependencies

一个 cargo 插件,用于从 Rust 代码轻松构建 Swift 包

cargo swift 提供了交互式命令,用于初始化和打包 Rust 库作为 Swift 包,用于 iOS 和 macOS 应用程序。此插件使用 Mozilla 的 UniFFI 在 Swift 和 Rust 之间进行桥接。要了解更多关于使用 UniFFI 的信息,请阅读其 用户指南,但请注意,您可以选择跳过关于生成绑定(第 2.4 节)和构建 Swift 模块(第 10. 和 11. 节)的部分,因为 cargo swift 已经处理了这些内容!

入门

注意 此插件只能在 macOS 上使用,因为此插件正常工作需要专有工具链。

先决条件

安装此插件,只需运行

cargo install cargo-swift

为不同的 UniFFI 版本安装

目前,cargo swift 无法自动检测项目的 UniFFI 版本,因此目前您必须安装与 cargo swift 匹配的版本

UniFFI cargo swift
0.25 0.5
0.26 0.6
0.27 0.7
0.28 0.8

要这样做,请运行

cargo install [email protected] -f  

并将 0.X 替换为您要安装的 cargo swift 版本。

使用 cargo-swift

您可以通过运行以下命令创建一个新的库包

cargo swift init

这会创建一个新的 Rust 库包,其中包含一些样板代码和一些示例,以便快速开始使用 UniFFI。有关完整参考,请参阅 UniFFI 用户指南的此章节

要将之前创建的 Rust 库打包为 Swift 包,请运行

cargo swift package

此命令将交互式提示您输入Swift包名和目标平台。如果所选目标平台缺少某些必需的工具链,cargo swift将询问您是否应自动安装它们。

到此为止!现在您可以通过Swift Package Manager将创建的包包含到iOS或macOS应用中。

配置

目前,配置只能通过命令行参数提供。大多数情况下,默认设置就足够了 - 然而,有时可能需要持久存储配置。您可以在CONFIG-DRAFT.md中找到配置示例。

许可证

Apache-2.0

 Copyright 2023 Antonius Naumann

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       https://apache.ac.cn/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

MIT

MIT License

Copyright (c) 2023 Antonius Naumann

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

依赖项

约9–17MB
约223K SLoC