Skip to content

Commit fe171bc

Browse files
authored
Fix various codebase rots (stale CI, new Rust lints, broken MSRV checks by transitive dependency upgrades) (#164)
* game_activity/ffi: Drop cfg for inexistant `target_arch = "armv7"` [Rust 1.80 from July 25th 2024] points out that `armv7` is not a known, valid value for the `target_arch` cfg variable. This is confirmed by the docs not listing it either: https://doc.rust-lang.org/reference/conditional-compilation.html#target_arch Hence drop this entirely, and rely purely on `target_arch = "arm"`. [Rust 1.80 from July 25th 2024]: https://blog.rust-lang.org/2024/07/25/Rust-1.80.0.html * Fix `unexpected-cfgs` by adding `api-level-30` feature and removing `test` Some code copied from the NDK carried over the respective `feature` `cfg` guards, without ever adding the feature to the `[features]` list in `Cargo.toml`. Now that Rust detects these mishaps, we can fix it by removing `test` (bindings don't seem to be run-tested) and reexpose `ConfigurationRef::screen_round()` which was behind a previously unsettable `feature = "api-level-30"`. Also remove `unsafe impl Send/Sync for ConfigurationRef` since the upstream `ndk` already declares `Configuration` to be `Send` and `Sync`, and `RwLock` and `Arc` carry that through. * native_activity: Fix clippy lints around `NativeActivityGlue` not `SendSync` and unwritten `redraw_needed` field * CI: Remove deprecated/unmaintained `actions-rs` toolchain setup The `actions-rs` containers haven't been maintained and updated for years and don't need to: GitHub's actions environment already comes fully loaded with a complete `stable` Rust installation with the standard tools (in this case `rustfmt`). Remove the remaining toolchain setup (which was already replaced with `hecrj/setup-rust-action` elsewhere) to get rid of ancient Node 12 deprecation warnings. * Bump dependency patch-versions to fix `-Zminimal-versions` and MSRV check Use `-Zminimal-versions` in our MSRV check. This not only ensures our minimum version bounds are actually solid and tested (even if they may be a bit conservative at times, i.e. we could allow older versions except for the crates that are bumped in this patch which were explicitly build-tested), it also allows us to use this as a base for the MSRV test, and preempt us from failing it whenever a (transitive!) dependency bumps its MSRV beyond ours in a *semver-compatible* release. * Elide redundant `impl` block lifetimes following stricter Rust 1.83 lint Rust now points out that `impl<'a> (Trait for) Struct<'a>` is superfluous whenever `'a` is not used anywhere else in the `impl` block.
1 parent 0d29930 commit fe171bc

File tree

11 files changed

+60
-49
lines changed

11 files changed

+60
-49
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ jobs:
2121
steps:
2222
- uses: actions/checkout@v4
2323

24+
# Downgrade all dependencies to their minimum version, both to ensure our
25+
# minimum version bounds are correct and buildable, as well as to satisfy
26+
# our MSRV check when arbitrary dependencies bump their MSRV beyond our
27+
# MSRV in a patch-release.
28+
# This implies that downstream consumers can only rely on our MSRV when
29+
# downgrading various (transitive) dependencies.
30+
- uses: hecrj/setup-rust-action@v2
31+
with:
32+
rust-version: nightly
33+
if: ${{ matrix.rust-version != 'stable' }}
34+
- name: Downgrade dependencies
35+
run: cargo +nightly generate-lockfile -Zminimal-versions
36+
if: ${{ matrix.rust-version != 'stable' }}
37+
2438
- uses: hecrj/setup-rust-action@v2
2539
with:
2640
rust-version: ${{ matrix.rust-version }}
@@ -87,13 +101,6 @@ jobs:
87101
steps:
88102
- uses: actions/checkout@v4
89103

90-
- uses: actions-rs/toolchain@v1
91-
with:
92-
profile: minimal
93-
toolchain: stable
94-
override: true
95-
components: rustfmt
96-
97104
- name: Format
98105
run: cargo fmt --all -- --check
99106
working-directory: android-activity

android-activity/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ rust-version = "1.69.0"
2727
default = []
2828
game-activity = []
2929
native-activity = []
30+
api-level-30 = ["ndk/api-level-30"]
3031

3132
[dependencies]
3233
log = "0.4"
@@ -35,15 +36,15 @@ cesu8 = "1"
3536
jni = "0.21"
3637
ndk-sys = "0.6.0"
3738
ndk = { version = "0.9.0", default-features = false }
38-
ndk-context = "0.1"
39+
ndk-context = "0.1.1"
3940
android-properties = "0.2"
4041
num_enum = "0.7"
4142
bitflags = "2.0"
42-
libc = "0.2"
43+
libc = "0.2.139"
4344
thiserror = "1"
4445

4546
[build-dependencies]
46-
cc = { version = "1.0", features = ["parallel"] }
47+
cc = { version = "1.0.42", features = ["parallel"] }
4748

4849
[package.metadata.docs.rs]
4950
targets = [

android-activity/src/config.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ use ndk::configuration::{
66
ScreenSize, Touchscreen, UiModeNight, UiModeType,
77
};
88

9-
/// A (cheaply clonable) reference to this application's [`ndk::configuration::Configuration`]
9+
/// A runtime-replacable reference to [`ndk::configuration::Configuration`].
1010
///
11-
/// This provides a thread-safe way to access the latest configuration state for
12-
/// an application without deeply copying the large [`ndk::configuration::Configuration`] struct.
11+
/// # Warning
1312
///
14-
/// If the application is notified of configuration changes then those changes
15-
/// will become visible via pre-existing configuration references.
13+
/// The value held by this reference **will change** with every [`super::MainEvent::ConfigChanged`]
14+
/// event that is raised. You should **not** [`Clone`] this type to compare it against a
15+
/// "new" [`super::AndroidApp::config()`] when that event is raised, since both point to the same
16+
/// internal [`ndk::configuration::Configuration`] and will be identical.
1617
#[derive(Clone)]
1718
pub struct ConfigurationRef {
1819
config: Arc<RwLock<Configuration>>,
@@ -28,8 +29,6 @@ impl PartialEq for ConfigurationRef {
2829
}
2930
}
3031
impl Eq for ConfigurationRef {}
31-
unsafe impl Send for ConfigurationRef {}
32-
unsafe impl Sync for ConfigurationRef {}
3332

3433
impl fmt::Debug for ConfigurationRef {
3534
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

android-activity/src/game_activity/ffi.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,14 @@ use jni_sys::*;
1616
use libc::{pthread_cond_t, pthread_mutex_t, pthread_t};
1717
use ndk_sys::{AAssetManager, AConfiguration, ALooper, ALooper_callbackFunc, ANativeWindow, ARect};
1818

19-
#[cfg(all(
20-
any(target_os = "android", feature = "test"),
21-
any(target_arch = "arm", target_arch = "armv7")
22-
))]
19+
#[cfg(all(any(target_os = "android"), target_arch = "arm"))]
2320
include!("ffi_arm.rs");
2421

25-
#[cfg(all(any(target_os = "android", feature = "test"), target_arch = "aarch64"))]
22+
#[cfg(all(any(target_os = "android"), target_arch = "aarch64"))]
2623
include!("ffi_aarch64.rs");
2724

28-
#[cfg(all(any(target_os = "android", feature = "test"), target_arch = "x86"))]
25+
#[cfg(all(any(target_os = "android"), target_arch = "x86"))]
2926
include!("ffi_i686.rs");
3027

31-
#[cfg(all(any(target_os = "android", feature = "test"), target_arch = "x86_64"))]
28+
#[cfg(all(any(target_os = "android"), target_arch = "x86_64"))]
3229
include!("ffi_x86_64.rs");

android-activity/src/game_activity/input.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ pub(crate) struct PointerImpl<'a> {
263263
index: usize,
264264
}
265265

266-
impl<'a> PointerImpl<'a> {
266+
impl PointerImpl<'_> {
267267
#[inline]
268268
pub fn pointer_index(&self) -> usize {
269269
self.index
@@ -333,7 +333,7 @@ impl<'a> Iterator for PointersIterImpl<'a> {
333333
}
334334
}
335335

336-
impl<'a> ExactSizeIterator for PointersIterImpl<'a> {
336+
impl ExactSizeIterator for PointersIterImpl<'_> {
337337
fn len(&self) -> usize {
338338
self.count - self.next_index
339339
}
@@ -740,7 +740,7 @@ impl<'a> KeyEvent<'a> {
740740
}
741741
}
742742

743-
impl<'a> KeyEvent<'a> {
743+
impl KeyEvent<'_> {
744744
/// Flags associated with this [`KeyEvent`].
745745
///
746746
/// See [the NDK docs](https://developer.android.com/ndk/reference/group/input#akeyevent_getflags)

android-activity/src/game_activity/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl<'a> StateSaver<'a> {
8484
pub struct StateLoader<'a> {
8585
app: &'a AndroidAppInner,
8686
}
87-
impl<'a> StateLoader<'a> {
87+
impl StateLoader<'_> {
8888
pub fn load(&self) -> Option<Vec<u8>> {
8989
unsafe {
9090
let app_ptr = self.app.native_app.as_ptr();
@@ -722,7 +722,7 @@ impl<'a> InputBuffer<'a> {
722722
}
723723
}
724724

725-
impl<'a> Drop for InputBuffer<'a> {
725+
impl Drop for InputBuffer<'_> {
726726
fn drop(&mut self) {
727727
unsafe {
728728
ffi::android_app_clear_motion_events(self.ptr.as_ptr());
@@ -801,7 +801,7 @@ pub(crate) struct InputIteratorInner<'a> {
801801
text_event_checked: bool,
802802
}
803803

804-
impl<'a> InputIteratorInner<'a> {
804+
impl InputIteratorInner<'_> {
805805
pub(crate) fn next<F>(&mut self, callback: F) -> bool
806806
where
807807
F: FnOnce(&input::InputEvent) -> InputStatus,
@@ -943,7 +943,7 @@ pub unsafe extern "C" fn _rust_glue_entry(native_app: *mut ffi::android_app) {
943943
// code to look up non-standard Java classes.
944944
android_main(app);
945945
})
946-
.unwrap_or_else(|panic| log_panic(panic));
946+
.unwrap_or_else(log_panic);
947947

948948
// Let JVM know that our Activity can be destroyed before detaching from the JVM
949949
//

android-activity/src/input.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ pub struct InputIterator<'a> {
912912
pub(crate) inner: crate::activity_impl::InputIteratorInner<'a>,
913913
}
914914

915-
impl<'a> InputIterator<'a> {
915+
impl InputIterator<'_> {
916916
/// Reads and handles the next input event by passing it to the given `callback`
917917
///
918918
/// `callback` should return [`InputStatus::Unhandled`] for any input events that aren't directly
@@ -932,7 +932,7 @@ pub struct Pointer<'a> {
932932
pub(crate) inner: PointerImpl<'a>,
933933
}
934934

935-
impl<'a> Pointer<'a> {
935+
impl Pointer<'_> {
936936
#[inline]
937937
pub fn pointer_index(&self) -> usize {
938938
self.inner.pointer_index()
@@ -1026,7 +1026,7 @@ impl<'a> Iterator for PointersIter<'a> {
10261026
}
10271027
}
10281028

1029-
impl<'a> ExactSizeIterator for PointersIter<'a> {
1029+
impl ExactSizeIterator for PointersIter<'_> {
10301030
fn len(&self) -> usize {
10311031
self.inner.len()
10321032
}

android-activity/src/lib.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,9 @@ pub enum MainEvent<'a> {
268268
/// input focus.
269269
LostFocus,
270270

271-
/// Command from main thread: the current device configuration has changed.
272-
/// You can get a copy of the latest [`ndk::configuration::Configuration`] by calling
273-
/// [`AndroidApp::config()`]
271+
/// Command from main thread: the current device configuration has changed. Any
272+
/// reference gotten via [`AndroidApp::config()`] will automatically contain the latest
273+
/// [`ndk::configuration::Configuration`].
274274
#[non_exhaustive]
275275
ConfigChanged {},
276276

@@ -617,7 +617,14 @@ impl AndroidApp {
617617
self.inner.read().unwrap().create_waker()
618618
}
619619

620-
/// Returns a (cheaply clonable) reference to this application's [`ndk::configuration::Configuration`]
620+
/// Returns a **reference** to this application's [`ndk::configuration::Configuration`].
621+
///
622+
/// # Warning
623+
///
624+
/// The value held by this reference **will change** with every [`MainEvent::ConfigChanged`]
625+
/// event that is raised. You should **not** [`Clone`] this type to compare it against a
626+
/// "new" [`AndroidApp::config()`] when that event is raised, since both point to the same
627+
/// internal [`ndk::configuration::Configuration`] and will be identical.
621628
pub fn config(&self) -> ConfigurationRef {
622629
self.inner.read().unwrap().config()
623630
}

android-activity/src/native_activity/glue.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,14 @@ pub struct WaitableNativeActivityState {
8181
pub cond: Condvar,
8282
}
8383

84+
// SAFETY: ndk::NativeActivity is also SendSync.
85+
unsafe impl Send for WaitableNativeActivityState {}
86+
unsafe impl Sync for WaitableNativeActivityState {}
87+
8488
#[derive(Debug, Clone)]
8589
pub struct NativeActivityGlue {
8690
pub inner: Arc<WaitableNativeActivityState>,
8791
}
88-
unsafe impl Send for NativeActivityGlue {}
89-
unsafe impl Sync for NativeActivityGlue {}
9092

9193
impl Deref for NativeActivityGlue {
9294
type Target = WaitableNativeActivityState;
@@ -223,7 +225,6 @@ pub struct NativeActivityState {
223225
/// Set as soon as the Java main thread notifies us of an
224226
/// `onDestroyed` callback.
225227
pub destroyed: bool,
226-
pub redraw_needed: bool,
227228
pub pending_input_queue: *mut ndk_sys::AInputQueue,
228229
pub pending_window: Option<NativeWindow>,
229230
}
@@ -370,7 +371,6 @@ impl WaitableNativeActivityState {
370371
thread_state: NativeThreadState::Init,
371372
app_has_saved_state: false,
372373
destroyed: false,
373-
redraw_needed: false,
374374
pending_input_queue: ptr::null_mut(),
375375
pending_window: None,
376376
}),

android-activity/src/native_activity/input.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct MotionEvent<'a> {
1515
ndk_event: ndk::event::MotionEvent,
1616
_lifetime: PhantomData<&'a ndk::event::MotionEvent>,
1717
}
18-
impl<'a> MotionEvent<'a> {
18+
impl MotionEvent<'_> {
1919
pub(crate) fn new(ndk_event: ndk::event::MotionEvent) -> Self {
2020
Self {
2121
ndk_event,
@@ -248,7 +248,7 @@ pub(crate) struct PointerImpl<'a> {
248248
ndk_pointer: ndk::event::Pointer<'a>,
249249
}
250250

251-
impl<'a> PointerImpl<'a> {
251+
impl PointerImpl<'_> {
252252
#[inline]
253253
pub fn pointer_index(&self) -> usize {
254254
self.ndk_pointer.pointer_index()
@@ -303,7 +303,7 @@ impl<'a> Iterator for PointersIterImpl<'a> {
303303
}
304304
}
305305

306-
impl<'a> ExactSizeIterator for PointersIterImpl<'a> {
306+
impl ExactSizeIterator for PointersIterImpl<'_> {
307307
fn len(&self) -> usize {
308308
self.ndk_pointers_iter.len()
309309
}
@@ -319,7 +319,7 @@ pub struct KeyEvent<'a> {
319319
ndk_event: ndk::event::KeyEvent,
320320
_lifetime: PhantomData<&'a ndk::event::KeyEvent>,
321321
}
322-
impl<'a> KeyEvent<'a> {
322+
impl KeyEvent<'_> {
323323
pub(crate) fn new(ndk_event: ndk::event::KeyEvent) -> Self {
324324
Self {
325325
ndk_event,

0 commit comments

Comments
 (0)