{"id":17139948,"url":"https://github.com/wojteklu/rust-to-ios","last_synced_at":"2025-04-13T10:21:48.573Z","repository":{"id":41045323,"uuid":"99552975","full_name":"wojteklu/rust-to-ios","owner":"wojteklu","description":"Example project for building a library for iOS in Rust.","archived":false,"fork":false,"pushed_at":"2019-06-30T17:57:09.000Z","size":5495,"stargazers_count":65,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T01:46:51.724Z","etag":null,"topics":["interoperability","ios","rust","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wojteklu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-07T08:04:11.000Z","updated_at":"2023-09-05T12:33:21.000Z","dependencies_parsed_at":"2022-08-30T21:51:52.501Z","dependency_job_id":null,"html_url":"https://github.com/wojteklu/rust-to-ios","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wojteklu%2Frust-to-ios","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wojteklu%2Frust-to-ios/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wojteklu%2Frust-to-ios/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wojteklu%2Frust-to-ios/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wojteklu","download_url":"https://codeload.github.com/wojteklu/rust-to-ios/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248696232,"owners_count":21147093,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["interoperability","ios","rust","swift"],"created_at":"2024-10-14T20:13:28.902Z","updated_at":"2025-04-13T10:21:48.544Z","avatar_url":"https://github.com/wojteklu.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rust-to-ios\n[![Swift 5.0](https://img.shields.io/badge/swift-5.0-orange.svg?style=flat)](#)\n[![@wojteklu](https://img.shields.io/badge/contact-@wojteklu-blue.svg?style=flat)](https://twitter.com/wojteklu)\n\nExample project for building a library for iOS.\n\n* ✓ sending primitives between Rust and iOS\n* ✓ sending strings between Rust and iOS\n* ✓ giving ownership of a Rust instance to Swift\n\nSetup\n-----\n\n1. Download [rustup](https://www.rustup.rs/) needed to setup Rust for cross-compiling.\n\n    ```sh\n    curl https://sh.rustup.rs -sSf | sh\n    ```\n\n2. Download targets for iOS.\n\n    ```sh\n    rustup target add aarch64-apple-ios armv7-apple-ios armv7s-apple-ios x86_64-apple-ios i386-apple-ios\n    ```\n\n3. Install cargo-lipo to generate the iOS universal library.\n\n    ```sh\n    cargo install cargo-lipo\n    ```\n\nBuilding the library\n--------------------\n\n1. Create a new cargo project.\n\n    ```sh\n    cargo new message\n    ```\n\n2. Update Cargo.toml by adding the [lib] section.\n\n    ```sh\n    [lib]\n    name = \"message\"\n    crate-type = [\"staticlib\"]\n    ```\n\n3. Write the library and [expose its public interface in a C header](https://doc.rust-lang.org/book/first-edition/ffi.html).\n\n4. Build the library.\n\n    ```sh\n    cd message\n\n    cargo lipo --release\n    ```\n\nUsing the library\n-----------------\n\n1. Create the iOS project.\n\n2. Add the C header to allow using the Rust functions from C.\n\n3. Copy `target/universal/release/libmessage.a` to project.\n\n4. Add `libresolv.tbd` to `Linked frameworks and libraries`.\n\n5. Note that `cargo-lipo` does not support bitcode yet. You must set `ENABLE_BITCODE` to `NO`.\n\n## Author\n\nWojtek Lukaszuk [@wojteklu](http://twitter.com/wojteklu)\n\n## License\n\nAvailable under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwojteklu%2Frust-to-ios","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwojteklu%2Frust-to-ios","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwojteklu%2Frust-to-ios/lists"}