【问题标题】:Unable to build the library using cargo lipo --release无法使用 cargo lipo --release 构建库
【发布时间】:2021-06-11 22:14:03
【问题描述】:

无法使用 cargo lipo --release 构建库

我正在尝试使用 rust 为 ios 目标创建一个跨平台库。我正在关注这篇文章(Building and Deploying a Rust library on iOS)。 *注意:我遵循相同的步骤,我的项目结构也看起来相同 *

完成代码和项目设置后,最后一步是构建库。当我尝试使用cargo lipo --release 构建库时。它抛出这个错误:

[ERROR cargo_lipo] No library target found for "my-project-name"

另外,请注意,我只能安装对两个平台的支持。 (aarch64-apple-iosx86_64-apple-darwin)。我认为原因是他们有dropped the support for 32-bit architectures

所以,当我跑步时 rustup target add aarch64-apple-ios armv7-apple-ios armv7s-apple-ios x86_64-apple-ios i386-apple-ios.

它抛出错误:error: component 'rust-std' for target 'armv7-apple-ios' is unavailable for download for channel stable


Cargo.toml

[package]
name = "rustylib"
version = "0.1.0"
edition = "2018"
crate-type = ["staticlib", "cdylib"]

rustylib.rs

#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

char *hello(const char *to);

void hello_release(char *s);

项目结构的其余部分是通常的 rust 代码。

rustupshow 的输出

默认主机:x86_64-apple-darwin rustup 主页:/Users/my-username/.rustup

已安装的工具链

stable-x86_64-apple-darwin

nightly-x86_64-apple-darwin(默认)

活动工具链的安装目标

aarch64-apple-ios

x86_64-apple-darwin

活动工具链

nightly-x86_64-apple-darwin(默认)

rustc 1.52.0-nightly (acca81892 2021-03-13)

操作系统和锈

Rust:rustc 1.50.0 (cb75ad5db 2021-02-10)

操作系统:macOS Bug Sur (11.2.3)

Xcode 和命令行工具:12.4

【问题讨论】:

    标签: ios rust rust-cargo


    【解决方案1】:

    您的 Cargo.toml 错误。

    如果您查看您在问题中链接的指南,您会看到 crate-type 必须位于 [lib] 标记下方,如下所示:

    [package]
    name = "greetings"
    version = "0.1.1"
    authors = ["fluffyemily <fluffyemily@mozilla.com>"]
    description = "Example static library project built for iOS"
    publish = false
    
    [lib]
    name = "greetings"
    crate-type = ["staticlib", "cdylib"]
    

    此外,您的代码默认情况下必须在 cargo/src/lib.rs 中,如文档中所述(而不是在 rustylib.rs 中)。

    您可以从命令行运行cargo new rustylib --lib 来创建所有样板,因此您只需在[lib][lib] 部分添加依赖项和crate-type

    编辑

    我认为还有一个问题: 您在rustylib.rs 文件中输入了C 代码,这无法正常工作。我认为您打算做的是创建 C 桥,在您链接的指南中称为 cargo/src/greetings.h

    【讨论】:

    • 这是toml。说真的,从没想过我会犯这么愚蠢的错误。我急于让它运行。非常感谢!
    • 没问题。偶尔发生在我们所有人身上......
    猜你喜欢
    • 2017-03-06
    • 2019-07-16
    • 1970-01-01
    • 1970-01-01
    • 2019-04-07
    • 2011-09-13
    • 2023-04-02
    • 2017-05-07
    • 1970-01-01
    相关资源
    最近更新 更多