0
votes

Unable to build the library using cargo lipo --release

I am trying to make a cross-platform library using rust for ios target. I am following this article (Building and Deploying a Rust library on iOS). *Note: I followed the same steps and my project structure also looks the same *

After completing the code and project setup the last step is to build the library. When I try to build the library using cargo lipo --release. It throws this error:

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

Also, note that I am only able to install support for two platforms. (aarch64-apple-ios and x86_64-apple-darwin). I think the reason is that they have dropped the support for 32-bit architectures.

So, when I run rustup target add aarch64-apple-ios armv7-apple-ios armv7s-apple-ios x86_64-apple-ios i386-apple-ios.

It throws error: 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);

The rest of the project structure is the usual rust code.

The output of rustup show

Default host: x86_64-apple-darwin rustup home: /Users/my-username/.rustup

installed toolchains

stable-x86_64-apple-darwin

nightly-x86_64-apple-darwin (default)

installed targets for active toolchain

aarch64-apple-ios

x86_64-apple-darwin

active toolchain

nightly-x86_64-apple-darwin (default)

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

OS & Rust

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

OS: macOS Bug Sur (11.2.3)

Xcode & Command line tools: 12.4

1

1 Answers

1
votes

Your Cargo.toml is wrong.

If you look into the guide you linked in your question, you can see, that the crate-type has to be below the [lib] tag like so:

[package]
name = "greetings"
version = "0.1.1"
authors = ["fluffyemily <[email protected]>"]
description = "Example static library project built for iOS"
publish = false

[lib]
name = "greetings"
crate-type = ["staticlib", "cdylib"]

Also your code has to be in cargo/src/lib.rs by default as stated in the document (and not in rustylib.rs).

You can run cargo new rustylib --lib from the command line to create all the boilerplate, so that you only have to add the dependencies and the crate-type in the [lib] section of your Cargo.toml.

Edit

I think there is another problem: You have entered C code in your rustylib.rs file, which can not work. I think what you intended to do, was to create the C bridge, which is called cargo/src/greetings.h in the guide you linked.