A reference repository for development of cross-platform applications and libraries in Rust.
-
Build and run
export RUST_LOG=info # To print hello world message cargo run --bin rust_on_crossplatform
-
Install toolchain for iOS.
rustup target add aarch64-apple-ios
-
Install xcodegen and generate xcode project
cd ios xcodegen
-
Run app on xcode.
-
Install toolchain for Android.
rustup target add aarch64-linux-android
-
Install cargo-apk.
cargo install cargo-apk
-
Install android-sdk (you can build with just the CLI tools) and set
$ANDROID_SDK_ROOT
environment variable. -
Install android-ndk and set
$ANDROID_NDK_ROOT
environment variable. -
Deploy app to Android device.
./deploy.sh
-
Run app on a device.
-
Install node_modules by npm.
npm install
-
Run dev server.
npm start
Rust supports cross-compilation of various platforms. Therefore, it is very easy to build and generate binary files. However, the generation of an executable application requires configuration and build flow depending on the platform.
In an environment that can run Rust as-is, you can build an executable file by defining the main function.
It generates a library (.a or .dylib) from Rust code and link it when building the executable iOS app.
To build to the library, you can specify cdylib
or staticlib
in the crate-type
in Cargo.toml.
To call Rust from Objective-C, you can use cbindgen to create an interface (.h) and include it.
The binaries built in Rust will be linked using the Android NDK. With cargo-apk, it is possible to build an apk file easily. To make the application executable, it is convenient to use ndk-macro. The macro applies the function directly to the main function.
wasm-bindgen makes it easy to communicate with JavaScript and Wasm modules. wasm-pack provides an interface that can be built into wasm and called in JavaScript. In addition, since wasm-pack is highly compatible with webpack, it is possible to use the @wasm-tool/wasm-pack-plugin to incorporate it into webpack build.