$30 off During Our Annual Pro Sale. View Details »

Rust meets Mobile

Keith Smiley
November 07, 2022

Rust meets Mobile

2022 BazelCon talk about using bazel to build rust libraries for iOS and Android

Keith Smiley

November 07, 2022
Tweet

More Decks by Keith Smiley

Other Decks in Programming

Transcript

  1. Rust meets
    Mobile
    Keith Smiley (he/him)
    Principal Engineer, Lyft
    @SmileyKeith

    View Slide

  2. Sharing code on
    mobile

    View Slide

  3. Why rust?

    View Slide

  4. Rust + bazel

    View Slide

  5. rust_library(
    name = "foo",
    srcs = ["foo.rs"],
    )
    swift_library(
    name = "main",
    srcs = ["main.swift"],
    deps = [":foo"],
    )
    ios_application(...)
    Shouldn't this work?

    View Slide

  6. --platforms=//:ios_arm64

    View Slide

  7. bazel#7260

    View Slide

  8. platform_mappings

    View Slide

  9. flags:
    --cpu=arm64-v8a
    --crosstool_top=//external:android/crosstool
    //:android_aarch64
    --cpu=ios_arm64
    --apple_platform_type=ios
    //:ios_arm64
    ...

    View Slide

  10. Undefined symbols for architecture arm64:
    "___rust_alloc", referenced from:
    ...
    "___rust_alloc_error_handler", referenced from:
    ...
    ...
    rules_rust#1238 / rust#73632

    View Slide

  11. Who does the
    linking?

    View Slide

  12. How do I use it?

    View Slide

  13. #[no_mangle]
    pub extern fn print_something_from_rust() {
    println!("Ferris says hello!");
    }
    #[no_mangle]
    pub extern fn get_a_value_from_rust() -> i32 {
    42
    }
    extern void print_something_from_rust(void);
    extern int32_t get_a_value_from_rust(void);

    View Slide

  14. #[no_mangle]
    pub extern "system" fn Java_com_example_androidapp_JniShim_getValue() ->
    i32 {
    get_a_value_from_rust()
    }
    package com.example.androidapp;
    public class JniShim {
    public static native int getValue();
    }

    View Slide

  15. dtolnay/cxx
    rust-lang/rust-bindgen

    View Slide

  16. Future areas of
    improvement

    View Slide

  17. Developer
    Experience

    View Slide

  18. Future rust mobile
    support

    View Slide

  19. Was it worth it?

    View Slide

  20. keith/bazel-rust-mobile-demo

    View Slide

  21. - bazel#11454
    - bazel#15041
    - bazel#15248
    - bazel#15462
    - bazel#7260
    - cargo-raze#484
    - cargo-raze#489
    - rules_rust#1186
    - rules_rust#1238
    - rules_rust#1259
    - rules_rust#1271
    - rules_rust#1276
    - rules_rust#1290
    - rules_rust#1304
    - rules_rust#1362
    - rules_rust#1372
    - rules_rust#1401
    - rules_rust#1462
    - rules_rust#1541
    - rules_rust#1545
    - rules_rust#1546
    - rules_rust#1573
    - rules_rust#1576
    - rust#73632

    View Slide

  22. Thank you!
    twitter.com/SmileyKeith

    View Slide