All Projects → Rightpoint → Rust Universal Template

Rightpoint / Rust Universal Template

Licence: mit
Template for creating Rust libraries with bindings to iOS, Android, WebAssembly and more

Programming Languages

javascript
184084 projects - #8 most used programming language
java
68154 projects - #9 most used programming language
shell
77523 projects
swift
15916 projects
rust
11053 projects

Projects that are alternatives of or similar to Rust Universal Template

Wasmer Java
☕ WebAssembly runtime for Java
Stars: ✭ 152 (+270.73%)
Mutual labels:  wasm, jni
Rustpython
A Python Interpreter written in Rust
Stars: ✭ 10,261 (+24926.83%)
Mutual labels:  wasm
Kiss Fft
A compact FFT library in C with an Android JNI wrapper
Stars: ✭ 27 (-34.15%)
Mutual labels:  jni
Wasmsign
A tool to add and verify digital signatures to/from WASM binaries
Stars: ✭ 31 (-24.39%)
Mutual labels:  wasm
Bionic
** Bionic - An Ionic CLI clone for Blazor projects ** moved to:
Stars: ✭ 28 (-31.71%)
Mutual labels:  wasm
Wasmboy
Game Boy / Game Boy Color Emulator Library, 🎮written for WebAssembly using AssemblyScript. 🚀Demos built with Preact and Svelte. ⚛️
Stars: ✭ 963 (+2248.78%)
Mutual labels:  wasm
Fake Jni
An implementation of the JNI and JVMTI with support for direct interaction between natively registered classes and JVM objects.
Stars: ✭ 20 (-51.22%)
Mutual labels:  jni
Holochain Rust
DEPRECATED. The Holochain framework implemented in rust with a redux style internal state-model.
Stars: ✭ 992 (+2319.51%)
Mutual labels:  wasm
Wasm Sort
WebAssembly sort algorithms compiled by C.
Stars: ✭ 34 (-17.07%)
Mutual labels:  wasm
Cppwasm Book
📚 WebAssembly friendly programming with C/C++ -- Emscripten practice
Stars: ✭ 956 (+2231.71%)
Mutual labels:  wasm
Wasm Check
TypeScript / JavaScript library for detect WebAssembly features in node.js & browser
Stars: ✭ 30 (-26.83%)
Mutual labels:  wasm
Node Wasm
Import and use wasm in node
Stars: ✭ 28 (-31.71%)
Mutual labels:  wasm
Photon
⚡ Rust/WebAssembly image processing library
Stars: ✭ 963 (+2248.78%)
Mutual labels:  wasm
Esta
Interpreted language and bytecode VM of my own design written in Rust [Unmaintained]
Stars: ✭ 28 (-31.71%)
Mutual labels:  wasm
Anyndk
🔥 Android native library, make your development faster and easier. Android各种native库,让你的开发更快更简单
Stars: ✭ 35 (-14.63%)
Mutual labels:  jni
Terrarium Templates
Template and example projects for Fastly Labs Terrarium https://wasm.fastlylabs.com
Stars: ✭ 21 (-48.78%)
Mutual labels:  wasm
Smartcircle
✂️Automatically determine where to crop a circular image out of a rectangular.
Stars: ✭ 29 (-29.27%)
Mutual labels:  wasm
Rhai
Rhai - An embedded scripting language for Rust.
Stars: ✭ 958 (+2236.59%)
Mutual labels:  wasm
Json2excel
Generate excel file from json data
Stars: ✭ 40 (-2.44%)
Mutual labels:  wasm
Rucaja
Calling the JVM from Rust via JNI
Stars: ✭ 35 (-14.63%)
Mutual labels:  jni

Rust Universal Template

Swift 4.1 Rustc Version 1.25+ CircleCI Carthage compatible

Template for creating universal Rust libraries with bindings to iOS/macOS (Swift), Android (Java/JNI), JavaScript (WebAssembly), and more.

Goals

  • [ ] iOS / macOS
    • [x] Swift Framework template
    • [x] Run cargo via Xcode External Build System
    • [x] Carthage support
    • [ ] CocoaPods support
    • [ ] Automated Rust => Swift binding generation
    • [x] Example iOS app
  • [ ] Android / Java
    • [ ] Gradle library template
    • [ ] Automated Rust => Java/JNI binding generation
    • [x] Pure Java example
    • [ ] Example Android app
  • [ ] Web Browsers / JavaScript
    • [ ] JavaScript / WebAssembly template
    • [ ] Automated Rust => JavaScript binding generation (wasm-bindgen)
    • [ ] Example app
  • [ ] General
    • [ ] Automated Rust => C binding generation (cbindgen)
    • [ ] Create cookiecutter template
    • [ ] Documention and examples for best practices when using Rust from other languages

Setup

Install Rust via Rustup:

$ curl https://sh.rustup.rs -sSf | sh

Make sure the Rust binaries are added to your PATH (e.g. inside ~/.profile). This is usually performed automatically for you by rustup.

export PATH="$HOME/.cargo/bin:$PATH"

iOS

Install the iOS targets for your selected toolchain:

$ rustup target add aarch64-apple-ios armv7-apple-ios x86_64-apple-ios i386-apple-ios

Install cargo-lipo for generating universal iOS libraries:

$ cargo install cargo-lipo

Bitcode

If 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.

$ rustup toolchain install nightly
$ rustup target add aarch64-apple-ios armv7-apple-ios x86_64-apple-ios i386-apple-ios --toolchain nightly
$ rustup default nightly

Android

Install Android NDK (tested on version r16b):

$ brew cask install android-ndk

Add ANDROID_NDK_HOME to your bash profile (e.g. ~/.profile):

export ANDROID_NDK_HOME="/usr/local/share/android-ndk"

Install Android Rust targets:

$ rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android

Run 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.

$ ./build-android.sh

Java

To 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.

# Compile Java
$ javac Source/Java/HelloWorld.java
# Generate C header JNI interface
$ javah -classpath Source/Java -d Source/Java HelloWorld

The 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.

$ cargo build --features "java" --release

Finally, we can run our Java code that calls into the Rust code:

$ javac Examples/Java/HelloWorld/Main.java -classpath Source/Java
$ java -Djava.library.path=target/release -classpath "Source/Java:Examples/Java/HelloWorld" Main
Hello, from Rust!!

Install Visual Studio Code (optional)

VS Code offers an IDE-like experiene for developing your Rust code, including some rough LLDB debugging support.

Structure

Source/Rust

The 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.

ExampleObjC.framework

This iOS/macOS framework contains a Objective-C wrapper around the the C interface exposed by example.h.

ExampleSwift.framework

This iOS/macOS framework contains a Swift wrapper around the the C interface exposed by example.h.

Reference

Tools

  • android-rs-glue - Glue between Rust and Android, including cargo-apk command
  • cargo-lipo - Cargo subcommand to automatically create universal libraries for iOS.
  • cbindgen - A project for generating C bindings from Rust code
  • wasm-bindgen - Interoperating JavaScript and Rust
  • rust-bindgen - Automatically generates Rust FFI bindings to C (and some C++) libraries

Examples

Articles

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].