Skip to content

Commit 87cda3c

Browse files
committed
Build-test (documentation) on the host and fix broken doc samples
1 parent bde1cb3 commit 87cda3c

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ jobs:
9696
run: >
9797
cargo ndk -t arm64-v8a doc --no-deps
9898
99+
- name: Tests (host build-testing)
100+
run: |
101+
cargo test -F native-activity -F test
102+
cargo test -F game-activity -F test
103+
99104
format:
100105
runs-on: ubuntu-latest
101106
steps:

android-activity/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ 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+
3135
[dependencies]
3236
log = "0.4"
3337
jni-sys = "0.3"

android-activity/src/input/sdk.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,12 @@ impl KeyCharacterMap {
284284

285285
/// Get the character that is produced by combining the dead key producing accent with the key producing character c.
286286
///
287-
/// For example, ```get_dead_char('`', 'e')``` returns 'è'. `get_dead_char('^', ' ')` returns '^' and `get_dead_char('^', '^')` returns '^'.
287+
/// For example, ``get_dead_char('`', 'e')`` returns `'è'`. `get_dead_char('^', ' ')` returns `'^'` and `get_dead_char('^', '^')` returns `'^'`.
288288
///
289289
/// # Errors
290290
///
291-
/// Since this API needs to use JNI internally to call into the Android JVM it may return
292-
/// a [`AppError::JavaError`] in case there is a spurious JNI error or an exception
293-
/// is caught.
291+
/// Since this API needs to use JNI internally to call into the Android JVM it may return a
292+
/// [`AppError::JavaError`] in case there is a spurious JNI error or an exception is caught.
294293
pub fn get_dead_char(
295294
&self,
296295
accent_char: char,

android-activity/src/lib.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
//! a wider range of devices.
1414
//!
1515
//! Standalone applications based on this crate need to be built as `cdylib` libraries, like:
16-
//! ```
16+
//! ```toml
1717
//! [lib]
1818
//! crate_type=["cdylib"]
1919
//! ```
2020
//!
2121
//! and implement a `#[no_mangle]` `android_main` entry point like this:
22-
//! ```rust
22+
//! ```
2323
//! #[no_mangle]
24-
//! fn android_main(app: AndroidApp) {
24+
//! fn android_main(app: android_activity::AndroidApp) {
2525
//!
2626
//! }
2727
//! ```
@@ -64,6 +64,7 @@
6464
//! These are undone after `android_main()` returns
6565
//!
6666
//! # Android Extensible Enums
67+
// TODO: Move this to the NDK crate, which now implements this for most of the code?
6768
//!
6869
//! There are numerous enums in the `android-activity` API which are effectively
6970
//! bindings to enums declared in the Android SDK which need to be considered
@@ -95,7 +96,7 @@
9596
//! For example, here is how you could ensure forwards compatibility with both
9697
//! compile-time and runtime extensions of a `SomeEnum` enum:
9798
//!
98-
//! ```rust
99+
//! ```ignore
99100
//! match some_enum {
100101
//! SomeEnum::Foo => {},
101102
//! SomeEnum::Bar => {},
@@ -131,7 +132,7 @@ use ndk::native_window::NativeWindow;
131132
pub use ndk;
132133
pub use ndk_sys;
133134

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

137138
#[cfg(all(feature = "game-activity", feature = "native-activity"))]
@@ -556,10 +557,10 @@ impl AndroidApp {
556557
/// between native Rust code and Java/Kotlin code running within the JVM.
557558
///
558559
/// If you use the [`jni`] crate you can wrap this as a [`JavaVM`] via:
559-
/// ```ignore
560+
/// ```no_run
560561
/// # use jni::JavaVM;
561-
/// # let app: AndroidApp = todo!();
562-
/// let vm = unsafe { JavaVM::from_raw(app.vm_as_ptr()) };
562+
/// # let app: android_activity::AndroidApp = todo!();
563+
/// let vm = unsafe { JavaVM::from_raw(app.vm_as_ptr().ast()) };
563564
/// ```
564565
///
565566
/// [`jni`]: https://crates.io/crates/jni
@@ -571,10 +572,10 @@ impl AndroidApp {
571572
/// Returns a JNI object reference for this application's JVM `Activity` as a pointer
572573
///
573574
/// If you use the [`jni`] crate you can wrap this as an object reference via:
574-
/// ```ignore
575+
/// ```no_run
575576
/// # use jni::objects::JObject;
576-
/// # let app: AndroidApp = todo!();
577-
/// let activity = unsafe { JObject::from_raw(app.activity_as_ptr()) };
577+
/// # let app: android_activity::AndroidApp = todo!();
578+
/// let activity = unsafe { JObject::from_raw(app.activity_as_ptr().cast()) };
578579
/// ```
579580
///
580581
/// # JNI Safety
@@ -731,7 +732,7 @@ impl AndroidApp {
731732
/// # Example
732733
/// Code to iterate all pending input events would look something like this:
733734
///
734-
/// ```rust
735+
/// ```
735736
/// match app.input_events_iter() {
736737
/// Ok(mut iter) => {
737738
/// loop {
@@ -786,7 +787,7 @@ impl AndroidApp {
786787
///
787788
/// Code to handle unicode character mapping as well as combining dead keys could look some thing like:
788789
///
789-
/// ```rust
790+
/// ```
790791
/// let mut combining_accent = None;
791792
/// // Snip
792793
///

0 commit comments

Comments
 (0)