Coder Social home page Coder Social logo

uzeyirdestan / bazel-rust-mobile-demo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from keith/bazel-rust-mobile-demo

0.0 0.0 0.0 24 KB

An example repository for using rust on iOS and Android with bazel

License: MIT License

C++ 11.28% C 5.84% Objective-C 4.05% Java 9.72% Rust 4.17% Starlark 64.94%

bazel-rust-mobile-demo's Introduction

bazel-rust-mobile-demo

This is an example repository for how to setup a bazel build that uses rust on iOS and Android. I also did a talk on this at bazelcon.

Usage

You can explore the code, which has some comments around the issues you hit. You can also run each entry point to see them working.

For a standard cc_binary running on your host machine:

$ bazel run normal_binary
...
Ferris says hello!
Some value from rust: 42

For an ios_application (requires running on macOS with Xcode setup):

$ bazel run ios_app
...
com.example.iosapp: 25008
Ferris says hello!
Some value from rust: 42

For an android_application (requires the android SDK and an emulator to be configured):

$ bazel mobile-install android_app --fat_apk_cpu=arm64-v8a --start_app
# View the result in the emulator, or view logs with 'adb logcat'

Notes

  • At the time of writing this setup was tested with bazel 5.1.1
  • The key to targeting the right platforms until the iOS and Android rules natively support bazel platforms is the platform_mappings file, and the platform rules in the BUILD file (docs)
  • If you don't want to use a root platform_mappings file you can pass --platform_mappings=path/to/platform_mappings
  • The rules_rust patch, and android_armeabi platform definition will change with bazel 6.x since bazelbuild/bazel#14982 was fixed
  • When testing Android, depending on your emulator or device you can pass whatever --fat_apk_cpu value you need
  • When testing with iOS you can pass whatever --ios_multi_cpus value you need
  • When using something like this in production you should checkout cxx which helps bridge between rust and C++
  • This example doesn't include it but using cargo-raze works fine for rust dependencies from our testing
  • When using cargo-raze with the arm64 iOS simulator you need this patch for some cases, hopefully it's in a release soon
  • When debugging platform_mappings issues, --toolchain_resolution_debug='.*' is verbose but very useful
  • If you find any other interesting gotchas when setting this up please submit an issue or PR here so we can document them for the community!

bazel-rust-mobile-demo's People

Contributors

keith avatar imwildcat avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.