Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build-test (documentation) on the host and fix broken doc samples #184

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ jobs:
run: >
cargo ndk -t arm64-v8a doc --no-deps

- name: Tests (host build-testing)
run: |
cargo test -F native-activity -F test
cargo test -F game-activity -F test

format:
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 4 additions & 0 deletions android-activity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ native-activity = []
api-level-30 = ["ndk/api-level-30"]
api-level-33 = ["api-level-30", "ndk/api-level-33"]

# "Internal" feature to allow build-testing this crate for the host
# architecture, needed to make doctests actually compile sample code.
test = ["ndk/test", "ndk-sys/test"]

[dependencies]
log = "0.4"
jni-sys = "0.3"
Expand Down
7 changes: 3 additions & 4 deletions android-activity/src/input/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,12 @@ impl KeyCharacterMap {

/// Get the character that is produced by combining the dead key producing accent with the key producing character c.
///
/// For example, ```get_dead_char('`', 'e')``` returns 'è'. `get_dead_char('^', ' ')` returns '^' and `get_dead_char('^', '^')` returns '^'.
/// For example, ``get_dead_char('`', 'e')`` returns `'è'`. `get_dead_char('^', ' ')` returns `'^'` and `get_dead_char('^', '^')` returns `'^'`.
///
/// # Errors
///
/// Since this API needs to use JNI internally to call into the Android JVM it may return
/// a [`AppError::JavaError`] in case there is a spurious JNI error or an exception
/// is caught.
/// Since this API needs to use JNI internally to call into the Android JVM it may return a
/// [`AppError::JavaError`] in case there is a spurious JNI error or an exception is caught.
pub fn get_dead_char(
&self,
accent_char: char,
Expand Down
27 changes: 14 additions & 13 deletions android-activity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
//! a wider range of devices.
//!
//! Standalone applications based on this crate need to be built as `cdylib` libraries, like:
//! ```
//! ```toml
//! [lib]
//! crate_type=["cdylib"]
//! ```
//!
//! and implement a `#[no_mangle]` `android_main` entry point like this:
//! ```rust
//! ```
//! #[no_mangle]
//! fn android_main(app: AndroidApp) {
//! fn android_main(app: android_activity::AndroidApp) {
//!
//! }
//! ```
Expand Down Expand Up @@ -64,6 +64,7 @@
//! These are undone after `android_main()` returns
//!
//! # Android Extensible Enums
// TODO: Move this to the NDK crate, which now implements this for most of the code?
//!
//! There are numerous enums in the `android-activity` API which are effectively
//! bindings to enums declared in the Android SDK which need to be considered
Expand Down Expand Up @@ -95,7 +96,7 @@
//! For example, here is how you could ensure forwards compatibility with both
//! compile-time and runtime extensions of a `SomeEnum` enum:
//!
//! ```rust
//! ```ignore
//! match some_enum {
//! SomeEnum::Foo => {},
//! SomeEnum::Bar => {},
Expand Down Expand Up @@ -126,7 +127,7 @@

use bitflags::bitflags;

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

#[cfg(all(feature = "game-activity", feature = "native-activity"))]
Expand Down Expand Up @@ -550,10 +551,10 @@
/// between native Rust code and Java/Kotlin code running within the JVM.
///
/// If you use the [`jni`] crate you can wrap this as a [`JavaVM`] via:
/// ```ignore
/// ```no_run
/// # use jni::JavaVM;
/// # let app: AndroidApp = todo!();
/// let vm = unsafe { JavaVM::from_raw(app.vm_as_ptr()) };
/// # let app: android_activity::AndroidApp = todo!();
/// let vm = unsafe { JavaVM::from_raw(app.vm_as_ptr().ast()) };
/// ```
///
/// [`jni`]: https://crates.io/crates/jni
Expand All @@ -565,10 +566,10 @@
/// Returns a JNI object reference for this application's JVM `Activity` as a pointer
///
/// If you use the [`jni`] crate you can wrap this as an object reference via:
/// ```ignore
/// ```no_run
/// # use jni::objects::JObject;
/// # let app: AndroidApp = todo!();
/// let activity = unsafe { JObject::from_raw(app.activity_as_ptr()) };
/// # let app: android_activity::AndroidApp = todo!();
/// let activity = unsafe { JObject::from_raw(app.activity_as_ptr().cast()) };
/// ```
///
/// # JNI Safety
Expand Down Expand Up @@ -725,16 +726,16 @@
/// # Example
/// Code to iterate all pending input events would look something like this:
///
/// ```rust
/// ```
/// match app.input_events_iter() {

Check failure on line 730 in android-activity/src/lib.rs

View workflow job for this annotation

GitHub Actions / build (stable)

cannot find value `app` in this scope

Check failure on line 730 in android-activity/src/lib.rs

View workflow job for this annotation

GitHub Actions / build (stable)

cannot find value `app` in this scope
/// Ok(mut iter) => {
/// loop {
/// let read_input = iter.next(|event| {
/// let handled = match event {
/// InputEvent::KeyEvent(key_event) => {

Check failure on line 735 in android-activity/src/lib.rs

View workflow job for this annotation

GitHub Actions / build (stable)

failed to resolve: use of undeclared type `InputEvent`

Check failure on line 735 in android-activity/src/lib.rs

View workflow job for this annotation

GitHub Actions / build (stable)

failed to resolve: use of undeclared type `InputEvent`
/// // Snip
/// }
/// InputEvent::MotionEvent(motion_event) => {

Check failure on line 738 in android-activity/src/lib.rs

View workflow job for this annotation

GitHub Actions / build (stable)

failed to resolve: use of undeclared type `InputEvent`

Check failure on line 738 in android-activity/src/lib.rs

View workflow job for this annotation

GitHub Actions / build (stable)

failed to resolve: use of undeclared type `InputEvent`
/// // Snip
/// }
/// event => {
Expand Down Expand Up @@ -780,17 +781,17 @@
///
/// Code to handle unicode character mapping as well as combining dead keys could look some thing like:
///
/// ```rust
/// ```
/// let mut combining_accent = None;
/// // Snip
///
/// let combined_key_char = if let Ok(map) = app.device_key_character_map(device_id) {

Check failure on line 788 in android-activity/src/lib.rs

View workflow job for this annotation

GitHub Actions / build (stable)

cannot find value `app` in this scope

Check failure on line 788 in android-activity/src/lib.rs

View workflow job for this annotation

GitHub Actions / build (stable)

cannot find value `device_id` in this scope

Check failure on line 788 in android-activity/src/lib.rs

View workflow job for this annotation

GitHub Actions / build (stable)

cannot find value `app` in this scope

Check failure on line 788 in android-activity/src/lib.rs

View workflow job for this annotation

GitHub Actions / build (stable)

cannot find value `device_id` in this scope
/// match map.get(key_event.key_code(), key_event.meta_state()) {

Check failure on line 789 in android-activity/src/lib.rs

View workflow job for this annotation

GitHub Actions / build (stable)

cannot find value `key_event` in this scope

Check failure on line 789 in android-activity/src/lib.rs

View workflow job for this annotation

GitHub Actions / build (stable)

cannot find value `key_event` in this scope
/// Ok(KeyMapChar::Unicode(unicode)) => {
/// let combined_unicode = if let Some(accent) = combining_accent {
/// match map.get_dead_char(accent, unicode) {
/// Ok(Some(key)) => {
/// info!("KeyEvent: Combined '{unicode}' with accent '{accent}' to give '{key}'");

Check failure on line 794 in android-activity/src/lib.rs

View workflow job for this annotation

GitHub Actions / build (stable)

cannot find macro `info` in this scope

Check failure on line 794 in android-activity/src/lib.rs

View workflow job for this annotation

GitHub Actions / build (stable)

cannot find macro `info` in this scope
/// Some(key)
/// }
/// Ok(None) => None,
Expand All @@ -800,19 +801,19 @@
/// }
/// }
/// } else {
/// info!("KeyEvent: Pressed '{unicode}'");

Check failure on line 804 in android-activity/src/lib.rs

View workflow job for this annotation

GitHub Actions / build (stable)

cannot find macro `info` in this scope

Check failure on line 804 in android-activity/src/lib.rs

View workflow job for this annotation

GitHub Actions / build (stable)

cannot find macro `info` in this scope
/// Some(unicode)
/// };
/// combining_accent = None;
/// combined_unicode.map(|unicode| KeyMapChar::Unicode(unicode))
/// }
/// Ok(KeyMapChar::CombiningAccent(accent)) => {
/// info!("KeyEvent: Pressed 'dead key' combining accent '{accent}'");

Check failure on line 811 in android-activity/src/lib.rs

View workflow job for this annotation

GitHub Actions / build (stable)

cannot find macro `info` in this scope

Check failure on line 811 in android-activity/src/lib.rs

View workflow job for this annotation

GitHub Actions / build (stable)

cannot find macro `info` in this scope
/// combining_accent = Some(accent);
/// Some(KeyMapChar::CombiningAccent(accent))
/// }
/// Ok(KeyMapChar::None) => {
/// info!("KeyEvent: Pressed non-unicode key");

Check failure on line 816 in android-activity/src/lib.rs

View workflow job for this annotation

GitHub Actions / build (stable)

cannot find macro `info` in this scope

Check failure on line 816 in android-activity/src/lib.rs

View workflow job for this annotation

GitHub Actions / build (stable)

cannot find macro `info` in this scope
/// combining_accent = None;
/// None
/// }
Expand Down
Loading