{"id":18389326,"url":"https://github.com/rightpoint/rust-universal-template","last_synced_at":"2026-03-03T03:37:25.326Z","repository":{"id":45402446,"uuid":"131749811","full_name":"Rightpoint/rust-universal-template","owner":"Rightpoint","description":"Template for creating Rust libraries with bindings to iOS, Android, WebAssembly and more","archived":false,"fork":false,"pushed_at":"2018-05-10T00:54:37.000Z","size":285,"stargazers_count":58,"open_issues_count":1,"forks_count":1,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-03-22T11:43:17.693Z","etag":null,"topics":["android","ios","java","javascript","jni","rust","swift","wasm"],"latest_commit_sha":null,"homepage":null,"language":"Shell","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/Rightpoint.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":"2018-05-01T18:42:17.000Z","updated_at":"2024-11-23T19:20:42.000Z","dependencies_parsed_at":"2022-07-13T23:00:36.611Z","dependency_job_id":null,"html_url":"https://github.com/Rightpoint/rust-universal-template","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/Rightpoint%2Frust-universal-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rightpoint%2Frust-universal-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rightpoint%2Frust-universal-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rightpoint%2Frust-universal-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Rightpoint","download_url":"https://codeload.github.com/Rightpoint/rust-universal-template/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247583331,"owners_count":20962021,"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":["android","ios","java","javascript","jni","rust","swift","wasm"],"created_at":"2024-11-06T01:42:38.145Z","updated_at":"2026-03-03T03:37:20.281Z","avatar_url":"https://github.com/Rightpoint.png","language":"Shell","readme":"# Rust Universal Template\n\n[![Swift 4.1](https://img.shields.io/badge/Swift-4.1-orange.svg?style=flat)](https://swift.org)\n[![Rustc Version 1.25+](https://img.shields.io/badge/rustc-1.25+-lightgray.svg?style=flat)](https://www.rust-lang.org/en-US/)\n[![CircleCI](https://img.shields.io/circleci/project/github/Raizlabs/rust-universal-template/master.svg)](https://circleci.com/gh/Raizlabs/rust-universal-template)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n\n\nTemplate for creating universal Rust libraries with bindings to iOS/macOS (Swift), Android (Java/JNI), JavaScript (WebAssembly), and more.\n\n## Goals\n\n- [ ] iOS / macOS\n\t- [x] Swift Framework template\n\t- [x] Run `cargo` via Xcode External Build System\n\t- [x] Carthage support\n\t- [ ] CocoaPods support\n\t- [ ] Automated Rust =\u003e Swift binding generation\n\t- [x] Example iOS app\n- [ ] Android / Java\n\t- [ ] Gradle library template\n\t- [ ] Automated Rust =\u003e Java/JNI binding generation\n\t- [x] Pure Java example\n\t- [ ] Example Android app\n- [ ] Web Browsers / JavaScript\n\t- [ ] JavaScript / WebAssembly template\n\t- [ ] Automated Rust =\u003e JavaScript binding generation ([wasm-bindgen](https://github.com/rustwasm/wasm-bindgen))\n\t- [ ] Example app\n- [ ] General\n\t- [ ] Automated Rust =\u003e C binding generation ([cbindgen](https://github.com/eqrion/cbindgen/))\n\t- [ ] Create [cookiecutter](https://github.com/audreyr/cookiecutter) template\n\t- [ ] Documention and examples for best practices when using Rust from other languages\n\n## Setup\n\nInstall Rust via [Rustup](https://rustup.rs/):\n\n```bash\n$ curl https://sh.rustup.rs -sSf | sh\n```\n\nMake sure the Rust binaries are added to your `PATH` (e.g. inside `~/.profile`). This is usually performed automatically for you by `rustup`.\n\n```bash\nexport PATH=\"$HOME/.cargo/bin:$PATH\"\n```\n\n### iOS\n\nInstall the iOS targets for your selected toolchain:\n\n```bash\n$ rustup target add aarch64-apple-ios armv7-apple-ios x86_64-apple-ios i386-apple-ios\n```\n\nInstall `cargo-lipo` for generating universal iOS libraries:\n\n```bash\n$ cargo install cargo-lipo\n```\n\n#### Bitcode\n\nIf you want Bitcode support you'll need to use a Rust nightly 1.2.7+ build (as of 4-27-2018). Unfortunately there still seems to be some issues with Bitcode so it is disabled for now. For more information see issue https://github.com/rust-lang/rust/issues/35968.\n\n```bash\n$ rustup toolchain install nightly\n$ rustup target add aarch64-apple-ios armv7-apple-ios x86_64-apple-ios i386-apple-ios --toolchain nightly\n$ rustup default nightly\n```\n\n\n### Android\n\nInstall [Android NDK](https://developer.android.com/ndk/) (tested on version r16b):\n\n```bash\n$ brew cask install android-ndk\n```\n\nAdd `ANDROID_NDK_HOME` to your bash profile (e.g. `~/.profile`):\n\n```bash\nexport ANDROID_NDK_HOME=\"/usr/local/share/android-ndk\"\n```\n\nInstall Android Rust targets:\n\n```\n$ rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android\n```\n\nRun `build-android.sh`. This will create a standalone NDK toolchain and in the `NDK` directory if needed, and then run `cargo build` for all Android targets.\n\n```\n$ ./build-android.sh\n```\n\n### Java\n\nTo regenerate the Java JNI bindings, you need to first compile the Java with `javac` and then run `javah` to generate a C header. This generated header `HelloWorld.h` shows us the expected method signature for the JNI function.\n\n```bash\n# Compile Java\n$ javac Source/Java/HelloWorld.java\n# Generate C header JNI interface\n$ javah -classpath Source/Java -d Source/Java HelloWorld\n```\n\nThe corresponding Rust source code can be found in `Source/Rust/java/src/lib.rs`. We must first compile it, so the output shared library (`libexample.dylib` on macOS) can be found by Java.\n\n```bash\n$ cargo build --features \"java\" --release\n```\n\nFinally, we can run our Java code that calls into the Rust code:\n\n```bash\n$ javac Examples/Java/HelloWorld/Main.java -classpath Source/Java\n$ java -Djava.library.path=target/release -classpath \"Source/Java:Examples/Java/HelloWorld\" Main\nHello, from Rust!!\n```\n\n### Install Visual Studio Code (optional)\n\nVS Code offers an IDE-like experiene for developing your Rust code, including some rough LLDB debugging support.\n\n* [VS Code](https://code.visualstudio.com/)\n  * [rls-vscode](https://github.com/rust-lang-nursery/rls-vscode) (code completion)\n  * [vscode-lldb](https://github.com/vadimcn/vscode-lldb) (debugging)\n\n## Structure\n\n### `Source/Rust`\n\nThe src folder contains all of our Rust library source code (`.rs`) and a manually created C header file (`example.h`) exporting a few symbols of interest from our Rust code. The build output is a static library called `libexample.a`.\n\n### `ExampleObjC.framework`\n\nThis iOS/macOS framework contains a Objective-C wrapper around the the C interface exposed by `example.h`.\n\n### `ExampleSwift.framework`\n\nThis iOS/macOS framework contains a Swift wrapper around the the C interface exposed by `example.h`.\n\n## Reference\n\n### Tools\n\n* [android-rs-glue](https://github.com/tomaka/android-rs-glue) - Glue between Rust and Android, including `cargo-apk` command\n* [cargo-lipo](https://github.com/TimNN/cargo-lipo) - Cargo subcommand to automatically create universal libraries for iOS.\n* [cbindgen](https://github.com/eqrion/cbindgen/) - A project for generating C bindings from Rust code\n* [wasm-bindgen](https://github.com/rustwasm/wasm-bindgen) - Interoperating JavaScript and Rust\n* [rust-bindgen](https://github.com/rust-lang-nursery/rust-bindgen) - Automatically generates Rust FFI bindings to C (and some C++) libraries\n\n### Examples\n\n* [parity-signer](https://github.com/paritytech/parity-signer) - Rust + React Native (iOS \u0026 Android)\n* [cross-platform-rust](https://github.com/fluffyemily/cross-platform-rust) - Example project showing a Rust library running on iOS and Android\n* [rust-to-ios](https://github.com/wojteklu/rust-to-ios) - Example project for building a library for iOS in Rust.\n* [rust-ios-android](https://github.com/kennytm/rust-ios-android) - Example project for building Rust library for iOS and Android\n* [rust_on_mobile](https://github.com/Geal/rust_on_mobile) - iOS and Android examples\n\n### Articles\n\n* [JavaScript to Rust and Back Again: A wasm-bindgen Tale](https://hacks.mozilla.org/2018/04/javascript-to-rust-and-back-again-a-wasm-bindgen-tale/)\n* [Building and Deploying a Rust library on Android](https://mozilla.github.io/firefox-browser-architecture/experiments/2017-09-21-rust-on-android.html)\n* [Building and Deploying a Rust library on iOS](https://mozilla.github.io/firefox-browser-architecture/experiments/2017-09-06-rust-on-ios.html)\n* [Building for Android](https://github.com/servo/servo/wiki/Building-for-Android) - Servo's Android toolchain setup\n* [Taking Rust everywhere with rustup](https://blog.rust-lang.org/2016/05/13/rustup.html)\n\n## License\n\nMIT","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frightpoint%2Frust-universal-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frightpoint%2Frust-universal-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frightpoint%2Frust-universal-template/lists"}