Skip to content

Commit 019ad63

Browse files
committed
Switch doctests back to native cross-compilation, supported since Rust 1.89
https://blog.rust-lang.org/2025/08/07/Rust-1.89.0/#cross-compiled-doctests
1 parent 87cda3c commit 019ad63

File tree

3 files changed

+29
-22
lines changed

3 files changed

+29
-22
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,15 @@ jobs:
9696
run: >
9797
cargo ndk -t arm64-v8a doc --no-deps
9898
99-
- name: Tests (host build-testing)
99+
- name: Build doctests
100+
# All doctests are set to no_run, because they require running in the
101+
# context of an Android app.
102+
# Only run on stable because cross-compiling doctests is only supported
103+
# since Rust 1.89.
104+
if: ${{ matrix.rust-version == 'stable' }}
100105
run: |
101-
cargo test -F native-activity -F test
102-
cargo test -F game-activity -F test
106+
cargo test --doc -F native-activity --target aarch64-linux-android
107+
cargo ndk -t arm64-v8a -- test --doc -F game-activity
103108
104109
format:
105110
runs-on: ubuntu-latest

android-activity/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ native-activity = []
2828
api-level-30 = ["ndk/api-level-30"]
2929
api-level-33 = ["api-level-30", "ndk/api-level-33"]
3030

31-
# "Internal" feature to allow build-testing this crate for the host
32-
# architecture, needed to make doctests actually compile sample code.
33-
test = ["ndk/test", "ndk-sys/test"]
34-
3531
[dependencies]
3632
log = "0.4"
3733
jni-sys = "0.3"

android-activity/src/lib.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
//! ```
2020
//!
2121
//! and implement a `#[no_mangle]` `android_main` entry point like this:
22-
//! ```
22+
//! ```no_run
2323
//! #[no_mangle]
2424
//! fn android_main(app: android_activity::AndroidApp) {
2525
//!
@@ -132,7 +132,7 @@ use ndk::native_window::NativeWindow;
132132
pub use ndk;
133133
pub use ndk_sys;
134134

135-
#[cfg(all(not(target_os = "android"), not(feature = "test")))]
135+
#[cfg(not(target_os = "android"))]
136136
compile_error!("android-activity only supports compiling for Android");
137137

138138
#[cfg(all(feature = "game-activity", feature = "native-activity"))]
@@ -560,7 +560,7 @@ impl AndroidApp {
560560
/// ```no_run
561561
/// # use jni::JavaVM;
562562
/// # let app: android_activity::AndroidApp = todo!();
563-
/// let vm = unsafe { JavaVM::from_raw(app.vm_as_ptr().ast()) };
563+
/// let vm = unsafe { JavaVM::from_raw(app.vm_as_ptr().cast()) };
564564
/// ```
565565
///
566566
/// [`jni`]: https://crates.io/crates/jni
@@ -732,20 +732,23 @@ impl AndroidApp {
732732
/// # Example
733733
/// Code to iterate all pending input events would look something like this:
734734
///
735-
/// ```
735+
/// ```no_run
736+
/// # use android_activity::{AndroidApp, InputStatus, input::InputEvent};
737+
/// # let app: AndroidApp = todo!();
736738
/// match app.input_events_iter() {
737739
/// Ok(mut iter) => {
738740
/// loop {
739741
/// let read_input = iter.next(|event| {
740742
/// let handled = match event {
741743
/// InputEvent::KeyEvent(key_event) => {
742744
/// // Snip
745+
/// InputStatus::Handled
743746
/// }
744747
/// InputEvent::MotionEvent(motion_event) => {
745-
/// // Snip
748+
/// InputStatus::Unhandled
746749
/// }
747750
/// event => {
748-
/// // Snip
751+
/// InputStatus::Unhandled
749752
/// }
750753
/// };
751754
///
@@ -767,7 +770,7 @@ impl AndroidApp {
767770
///
768771
/// This must only be called from your `android_main()` thread and it may panic if called
769772
/// from another thread.
770-
pub fn input_events_iter(&self) -> Result<input::InputIterator> {
773+
pub fn input_events_iter(&self) -> Result<input::InputIterator<'_>> {
771774
let receiver = {
772775
let guard = self.inner.read().unwrap();
773776
guard.input_events_receiver()?
@@ -787,44 +790,47 @@ impl AndroidApp {
787790
///
788791
/// Code to handle unicode character mapping as well as combining dead keys could look some thing like:
789792
///
790-
/// ```
793+
/// ```no_run
794+
/// # use android_activity::{AndroidApp, input::{InputEvent, KeyEvent, KeyMapChar}};
795+
/// # let app: AndroidApp = todo!();
796+
/// # let key_event: KeyEvent = todo!();
791797
/// let mut combining_accent = None;
792798
/// // Snip
793799
///
794-
/// let combined_key_char = if let Ok(map) = app.device_key_character_map(device_id) {
800+
/// let combined_key_char = if let Ok(map) = app.device_key_character_map(key_event.device_id()) {
795801
/// match map.get(key_event.key_code(), key_event.meta_state()) {
796802
/// Ok(KeyMapChar::Unicode(unicode)) => {
797803
/// let combined_unicode = if let Some(accent) = combining_accent {
798804
/// match map.get_dead_char(accent, unicode) {
799805
/// Ok(Some(key)) => {
800-
/// info!("KeyEvent: Combined '{unicode}' with accent '{accent}' to give '{key}'");
806+
/// println!("KeyEvent: Combined '{unicode}' with accent '{accent}' to give '{key}'");
801807
/// Some(key)
802808
/// }
803809
/// Ok(None) => None,
804810
/// Err(err) => {
805-
/// log::error!("KeyEvent: Failed to combine 'dead key' accent '{accent}' with '{unicode}': {err:?}");
811+
/// eprintln!("KeyEvent: Failed to combine 'dead key' accent '{accent}' with '{unicode}': {err:?}");
806812
/// None
807813
/// }
808814
/// }
809815
/// } else {
810-
/// info!("KeyEvent: Pressed '{unicode}'");
816+
/// println!("KeyEvent: Pressed '{unicode}'");
811817
/// Some(unicode)
812818
/// };
813819
/// combining_accent = None;
814820
/// combined_unicode.map(|unicode| KeyMapChar::Unicode(unicode))
815821
/// }
816822
/// Ok(KeyMapChar::CombiningAccent(accent)) => {
817-
/// info!("KeyEvent: Pressed 'dead key' combining accent '{accent}'");
823+
/// println!("KeyEvent: Pressed 'dead key' combining accent '{accent}'");
818824
/// combining_accent = Some(accent);
819825
/// Some(KeyMapChar::CombiningAccent(accent))
820826
/// }
821827
/// Ok(KeyMapChar::None) => {
822-
/// info!("KeyEvent: Pressed non-unicode key");
828+
/// println!("KeyEvent: Pressed non-unicode key");
823829
/// combining_accent = None;
824830
/// None
825831
/// }
826832
/// Err(err) => {
827-
/// log::error!("KeyEvent: Failed to get key map character: {err:?}");
833+
/// eprintln!("KeyEvent: Failed to get key map character: {err:?}");
828834
/// combining_accent = None;
829835
/// None
830836
/// }

0 commit comments

Comments
 (0)