diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 888e999c9e..e951b054d0 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -637,36 +637,6 @@ tasks: build_targets: - "@rust_toolchains//:all" - "//..." - android_examples_ubuntu2204: - name: Android Examples - platform: ubuntu2204 - working_directory: examples/android - build_flags: - - "--incompatible_enable_android_toolchain_resolution" - - "--android_platforms=//:arm64-v8a" - build_targets: - - "//:android_app" - environment: - # This ndk version matches with rules_android_ndk repo's CI - # https://github.com/bazelbuild/rules_android_ndk/blob/877c68ef34c9f3353028bf490d269230c1990483/.bazelci/presubmit.yml#L37 - # The ndk is installed by this script - # https://github.com/bazelbuild/continuous-integration/blob/ba56013373821feadd9f2eaa6b81eb19528795f0/macos/mac-android.sh - ANDROID_NDK_HOME: /opt/android-ndk-r25b - android_examples_macos: - name: Android Examples - platform: macos_arm64 - working_directory: examples/android - build_flags: - - "--incompatible_enable_android_toolchain_resolution" - - "--android_platforms=//:arm64-v8a" - build_targets: - - "//:android_app" - environment: - # This ndk version matches with rules_android_ndk repo's CI - # https://github.com/bazelbuild/rules_android_ndk/blob/877c68ef34c9f3353028bf490d269230c1990483/.bazelci/presubmit.yml#L42 - # The ndk is installed by this script - # https://github.com/bazelbuild/continuous-integration/blob/ba56013373821feadd9f2eaa6b81eb19528795f0/macos/mac-android.sh - ANDROID_NDK_HOME: /Users/buildkite/android-ndk-r25b ios_examples: name: iOS Examples platform: macos_arm64 diff --git a/examples/android/.bazelrc b/examples/android/.bazelrc deleted file mode 100644 index 07d2887b9c..0000000000 --- a/examples/android/.bazelrc +++ /dev/null @@ -1,84 +0,0 @@ -############################################################################### -## Bazel Configuration Flags -## -## `.bazelrc` is a Bazel configuration file. -## https://bazel.build/docs/best-practices#bazelrc-file -############################################################################### - -# https://bazel.build/reference/command-line-reference#flag--enable_platform_specific_config -common --enable_platform_specific_config - -# Enable the only currently supported report type -# https://bazel.build/reference/command-line-reference#flag--combined_report -coverage --combined_report=lcov - -# Avoid fully cached builds reporting no coverage and failing CI -# https://bazel.build/reference/command-line-reference#flag--experimental_fetch_all_coverage_outputs -coverage --experimental_fetch_all_coverage_outputs - -# Required for some of the tests -# https://bazel.build/reference/command-line-reference#flag--experimental_cc_shared_library -common --experimental_cc_shared_library - -build --@rules_rust//rust/settings:experimental_use_allocator_libraries_with_mangled_symbols=True - -############################################################################### -## Unique configuration groups -############################################################################### - -# Enable use of the nightly toolchains. -build:nightly --@rules_rust//rust/toolchain/channel=nightly - -# Enable rustfmt for all targets in the workspace -build:rustfmt --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect -build:rustfmt --output_groups=+rustfmt_checks - -# Enable clippy for all targets in the workspace -build:clippy --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect -build:clippy --output_groups=+clippy_checks - -# Enable unpretty for all targets in the workspace -build:unpretty --aspects=@rules_rust//rust:defs.bzl%rust_unpretty_aspect -build:unpretty --output_groups=+rust_unpretty - -# `unpretty` requires the nightly toolchain. See tracking issue: -# https://github.com/rust-lang/rust/issues/43364 -build:unpretty --config=nightly - -############################################################################### -## Java configuration -############################################################################### - -common --java_runtime_version=remotejdk_21 - -build --fat_apk_cpu=arm64-v8a --android_crosstool_top=@androidndk//:toolchain - -############################################################################### -## Incompatibility flags -############################################################################### - -# https://github.com/bazelbuild/bazel/issues/8195 -build --incompatible_disallow_empty_glob=true - -# https://github.com/bazelbuild/bazel/issues/12821 -build --nolegacy_external_runfiles - -############################################################################### -## Bzlmod -############################################################################### - -# A configuration for disabling bzlmod. -common:no-bzlmod --noenable_bzlmod --enable_workspace - -# Disable the bzlmod lockfile, so we don't accidentally commit MODULE.bazel.lock -common --lockfile_mode=off - -############################################################################### -## Custom user flags -## -## This should always be the last thing in the `.bazelrc` file to ensure -## consistent behavior when setting flags in that file as `.bazelrc` files are -## evaluated top to bottom. -############################################################################### - -try-import %workspace%/user.bazelrc diff --git a/examples/android/.bazelversion b/examples/android/.bazelversion deleted file mode 100644 index e7fdef7e2e..0000000000 --- a/examples/android/.bazelversion +++ /dev/null @@ -1 +0,0 @@ -8.4.2 diff --git a/examples/android/.gitignore b/examples/android/.gitignore deleted file mode 100644 index 2a3bb2d902..0000000000 --- a/examples/android/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/bazel-* -user.bazelrc diff --git a/examples/android/AndroidMain.java b/examples/android/AndroidMain.java deleted file mode 100644 index 7a27ac040f..0000000000 --- a/examples/android/AndroidMain.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.example.androidapp; - -import android.app.Activity; -import android.os.Bundle; -import android.util.Log; -import android.widget.TextView; - -public class AndroidMain extends Activity { - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.android_main); - - Log.v("Bazel", "Android app launched"); - System.loadLibrary( - "android_app"); // 'android_app' is the name of the native library in this example - Log.v("Bazel", "Value from rust: " + JniShim.getValue()); - - final TextView helloTextView = (TextView) findViewById(R.id.text_view); - helloTextView.setText("Value from rust: " + JniShim.getValue()); - } -} diff --git a/examples/android/AndroidManifest.xml b/examples/android/AndroidManifest.xml deleted file mode 100644 index 03c56a3f96..0000000000 --- a/examples/android/AndroidManifest.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - diff --git a/examples/android/BUILD.bazel b/examples/android/BUILD.bazel deleted file mode 100644 index 73137e9804..0000000000 --- a/examples/android/BUILD.bazel +++ /dev/null @@ -1,46 +0,0 @@ -load("@build_bazel_rules_android//android:rules.bzl", "android_binary", "android_library") -load("@rules_cc//cc:defs.bzl", "cc_library") -load("@rules_rust//rust:defs.bzl", "rust_library") - -rust_library( - name = "rust_lib", - srcs = ["demo.rs"], - edition = "2018", -) - -cc_library( - name = "jni_shim", - srcs = ["android_link_hack.c"], # Required because of https://github.com/bazelbuild/rules_rust/issues/1271 - linkopts = [ - "-lm", # Required to avoid dlopen runtime failures unrelated to rust - ], - deps = [":rust_lib"], - alwayslink = True, # Required since JNI symbols appear to be unused -) - -android_library( - name = "android_main", - srcs = [ - "AndroidMain.java", - "JniShim.java", - ], - custom_package = "com.example.androidapp", - manifest = "AndroidManifest.xml", - resource_files = ["res/layout/android_main.xml"], - deps = [":jni_shim"], -) - -android_binary( - name = "android_app", - custom_package = "com.example.androidapp", - manifest = "AndroidManifest.xml", - deps = [":android_main"], -) - -platform( - name = "arm64-v8a", - constraint_values = [ - "@platforms//cpu:arm64", - "@platforms//os:android", - ], -) diff --git a/examples/android/JniShim.java b/examples/android/JniShim.java deleted file mode 100644 index 801c6d78fc..0000000000 --- a/examples/android/JniShim.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.example.androidapp; - -public class JniShim { - public static native int getValue(); -} diff --git a/examples/android/MODULE.bazel b/examples/android/MODULE.bazel deleted file mode 100644 index 2e8c6f8e4e..0000000000 --- a/examples/android/MODULE.bazel +++ /dev/null @@ -1,88 +0,0 @@ -module( - name = "rules_rust_example_android", - version = "0.0.0", -) - -############################################################################### -# B A Z E L C E N T R A L R E G I S T R Y # https://registry.bazel.build/ -############################################################################### -# https://github.com/bazelbuild/rules_rust/releases -bazel_dep(name = "rules_rust", version = "0.0.0") -local_path_override( - module_name = "rules_rust", - path = "../..", -) - -bazel_dep(name = "platforms", version = "1.0.0") -bazel_dep(name = "rules_cc", version = "0.2.8") -bazel_dep(name = "rules_java", version = "8.13.0") -bazel_dep(name = "rules_jvm_external", version = "6.6") - -maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven") -use_repo(maven, "maven") - -bazel_dep(name = "rules_android", version = "0.6.0", repo_name = "build_bazel_rules_android") -bazel_dep(name = "rules_android_ndk", version = "0.1.3") - -############################################################################### -# T O O L C H A I N S -############################################################################### - -# Rust toolchain -rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") -rust.toolchain( - extra_target_triples = [ - "aarch64-linux-android", - ], -) -use_repo(rust, "rust_toolchains") - -register_toolchains("@rust_toolchains//:all") - -java_toolchains = use_extension("@rules_java//java:extensions.bzl", "toolchains") -use_repo(java_toolchains, "remote_java_tools") -use_repo(java_toolchains, "remote_java_tools_linux") -use_repo(java_toolchains, "remote_java_tools_windows") -use_repo(java_toolchains, "remote_java_tools_darwin_x86_64") -use_repo(java_toolchains, "remote_java_tools_darwin_arm64") - -JDKS = { - # Must match JDK repos defined in remote_jdk21_repos() - "21": [ - "linux", - "linux_aarch64", - "linux_ppc64le", - "linux_s390x", - "macos", - "macos_aarch64", - "win", - "win_arm64", - ], -} - -REMOTE_JDK_REPOS = [ - (("remote_jdk" if version == "8" else "remotejdk") + version + "_" + platform) - for version in JDKS - for platform in JDKS[version] -] - -[ - use_repo( - java_toolchains, - repo + "_toolchain_config_repo", - ) - for repo in REMOTE_JDK_REPOS -] - -[ - register_toolchains("@" + name + "_toolchain_config_repo//:all") - for name in REMOTE_JDK_REPOS -] - -android_ndk_repository_extension = use_extension( - "@rules_android_ndk//:extension.bzl", - "android_ndk_repository_extension", -) -use_repo(android_ndk_repository_extension, "androidndk") - -register_toolchains("@androidndk//:all") diff --git a/examples/android/WORKSPACE.bazel b/examples/android/WORKSPACE.bazel deleted file mode 100644 index ca6c229f09..0000000000 --- a/examples/android/WORKSPACE.bazel +++ /dev/null @@ -1 +0,0 @@ -workspace(name = "rules_rust_example_android") diff --git a/examples/android/android_link_hack.c b/examples/android/android_link_hack.c deleted file mode 100644 index 299e7bdd15..0000000000 --- a/examples/android/android_link_hack.c +++ /dev/null @@ -1,4 +0,0 @@ -// https://github.com/bazelbuild/rules_rust/issues/1271 -extern void android_link_hack(void); - -void call_link_hack(void) { android_link_hack(); } diff --git a/examples/android/demo.rs b/examples/android/demo.rs deleted file mode 100644 index 8d33f18c62..0000000000 --- a/examples/android/demo.rs +++ /dev/null @@ -1,17 +0,0 @@ -#[no_mangle] -pub extern "C" fn android_link_hack() {} - -#[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 -} - -#[no_mangle] -pub extern "system" fn Java_com_example_androidapp_JniShim_getValue() -> i32 { - get_a_value_from_rust() -} diff --git a/examples/android/res/layout/android_main.xml b/examples/android/res/layout/android_main.xml deleted file mode 100644 index 2e27f2f631..0000000000 --- a/examples/android/res/layout/android_main.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - -