Now Reading
Constructing cross-platform Rust for Internet, Android and iOS – a minimal instance – Andy Balaam’s Weblog

Constructing cross-platform Rust for Internet, Android and iOS – a minimal instance – Andy Balaam’s Weblog

2023-07-09 11:54:29


One of many benefits of writing code in Rust is that it may be re-used somewhere else. Each iOS and Android enable utilizing native libraries inside your apps, and Rust compiles to native. Internet pages can now use WebAssembly (WASM), and Rust can compile to WASM.

So, it must be straightforward, proper?

Effectively, in observe it appears slightly difficult, so I created a small instance undertaking to clarify it to myself, so perhaps it’s useful to you too.

The total code is at gitlab.com/andybalaam/example-rust-bindings, however right here is the final concept:

  • crates/example-rust-bindings – the true Rust code
  • bindings/ffi – uniffi code to construct shared objects for Android and iOS
  • bindings/wasm – wasm_bingen code to construct WASM for Internet
  • examples/example-android – an Android app that generates a Kotlin wrapper, and runs the code within the shared object
  • examples/example-ios – an iOS XCode undertaking the place we generate Swift bindings, so we will name the code within the shared object
  • examples/example-web – an online web page that imports the WASM and runs it

Steps for WASM

Proof that I did this on Web - Firefox showing "This string is from Rust!"

Variation: in case you modify the construct script in bundle.json to name wasm-pack with --target node as a substitute of --target net you possibly can generate code appropriate for utilizing from a NodeJS module.

Steps for Android

Proof that I did this on Android: Android emulator showing a label "This string is from Rust!"

See Also

Steps for iOS


Source Link

What's Your Reaction?
Excited
0
Happy
0
In Love
0
Not Sure
0
Silly
0
View Comments (0)

Leave a Reply

Your email address will not be published.

2022 Blinking Robots.
WordPress by Doejo

Scroll To Top