1*d4726bddSHONG Yifanload("@build_bazel_rules_android//android:rules.bzl", "android_binary", "android_library") 2*d4726bddSHONG Yifanload("@rules_cc//cc:defs.bzl", "cc_library") 3*d4726bddSHONG Yifanload("@rules_rust//rust:defs.bzl", "rust_library") 4*d4726bddSHONG Yifan 5*d4726bddSHONG Yifanrust_library( 6*d4726bddSHONG Yifan name = "rust_lib", 7*d4726bddSHONG Yifan srcs = ["demo.rs"], 8*d4726bddSHONG Yifan edition = "2018", 9*d4726bddSHONG Yifan) 10*d4726bddSHONG Yifan 11*d4726bddSHONG Yifancc_library( 12*d4726bddSHONG Yifan name = "jni_shim", 13*d4726bddSHONG Yifan srcs = ["android_link_hack.c"], # Required because of https://github.com/bazelbuild/rules_rust/issues/1271 14*d4726bddSHONG Yifan linkopts = [ 15*d4726bddSHONG Yifan "-lm", # Required to avoid dlopen runtime failures unrelated to rust 16*d4726bddSHONG Yifan ], 17*d4726bddSHONG Yifan deps = [":rust_lib"], 18*d4726bddSHONG Yifan alwayslink = True, # Required since JNI symbols appear to be unused 19*d4726bddSHONG Yifan) 20*d4726bddSHONG Yifan 21*d4726bddSHONG Yifanandroid_library( 22*d4726bddSHONG Yifan name = "android_main", 23*d4726bddSHONG Yifan srcs = [ 24*d4726bddSHONG Yifan "AndroidMain.java", 25*d4726bddSHONG Yifan "JniShim.java", 26*d4726bddSHONG Yifan ], 27*d4726bddSHONG Yifan custom_package = "com.example.androidapp", 28*d4726bddSHONG Yifan manifest = "AndroidManifest.xml", 29*d4726bddSHONG Yifan resource_files = ["res/layout/android_main.xml"], 30*d4726bddSHONG Yifan deps = [":jni_shim"], 31*d4726bddSHONG Yifan) 32*d4726bddSHONG Yifan 33*d4726bddSHONG Yifanandroid_binary( 34*d4726bddSHONG Yifan name = "android_app", 35*d4726bddSHONG Yifan custom_package = "com.example.androidapp", 36*d4726bddSHONG Yifan manifest = "AndroidManifest.xml", 37*d4726bddSHONG Yifan deps = [":android_main"], 38*d4726bddSHONG Yifan) 39*d4726bddSHONG Yifan 40*d4726bddSHONG Yifanplatform( 41*d4726bddSHONG Yifan name = "arm64-v8a", 42*d4726bddSHONG Yifan constraint_values = [ 43*d4726bddSHONG Yifan "@platforms//cpu:arm64", 44*d4726bddSHONG Yifan "@platforms//os:android", 45*d4726bddSHONG Yifan ], 46*d4726bddSHONG Yifan) 47