From 483164c333c5399f192cca56064d2050ed6b59ca Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Mon, 2 Mar 2026 14:19:52 +0000 Subject: [PATCH] Replace cesu8 with simd_cesu8 (consistent with jni 0.22.2) The `cesu8` crate hasn't been updated for 10 years where as the `simd_cesu8` crate is more actively maintained and is expected to have better performance in all conditions: This change is consistent with the `jni` crate which switched to using `simd_cesu8` in the 0.22.2 release - so this avoids needing to build two separate crates for mutf8 encoding. This also addresses the current CI issue that comes from incorrectly depending on `cesu8 = "1"` instead of `"1.1.0"` (which adds the java/mutf8 APIs that we used). Previously this went unnoticed because of the `jni` crate pulling in the correct minimum version. --- android-activity/Cargo.toml | 6 +++--- android-activity/src/game_activity/mod.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/android-activity/Cargo.toml b/android-activity/Cargo.toml index d742fd1..c13408b 100644 --- a/android-activity/Cargo.toml +++ b/android-activity/Cargo.toml @@ -21,14 +21,14 @@ rust-version = "1.85.0" # In general it's only the final application crate that needs # to decide on a backend. default = [] -game-activity = [] +game-activity = ["simd_cesu8"] native-activity = [] api-level-30 = ["ndk/api-level-30"] [dependencies] log = "0.4" -cesu8 = "1" -jni = "0.22" +simd_cesu8 = { version = "1.0.1", optional = true } +jni = "0.22.2" ndk-sys = "0.6.0" ndk = { version = "0.9.0", default-features = false } ndk-context = "0.1.1" diff --git a/android-activity/src/game_activity/mod.rs b/android-activity/src/game_activity/mod.rs index 6fe8400..95747c0 100644 --- a/android-activity/src/game_activity/mod.rs +++ b/android-activity/src/game_activity/mod.rs @@ -216,7 +216,7 @@ impl NativeAppGlue { pub fn set_text_input_state(&self, state: TextInputState) { unsafe { let activity = (*self.as_ptr()).activity; - let modified_utf8 = cesu8::to_java_cesu8(&state.text); + let modified_utf8 = simd_cesu8::mutf8::encode(&state.text); let text_length = modified_utf8.len() as i32; let modified_utf8_bytes = modified_utf8.as_ptr(); let ffi_state = ffi::GameTextInputState { @@ -525,7 +525,7 @@ impl AndroidAppInner { let text_modified_utf8: *const u8 = (*state).text_UTF8.cast(); let text_modified_utf8 = std::slice::from_raw_parts(text_modified_utf8, (*state).text_length as usize); - match cesu8::from_java_cesu8(text_modified_utf8) { + match simd_cesu8::mutf8::decode(text_modified_utf8) { Ok(str) => { let len = str.len(); (*out_ptr).text = String::from(str);