Files
chanora/crates/chanora_bridge/build.rs
EdisonJwa 7966a7c8c6 feat(bridge,android): BridgeEvent::PermissionState + JNI publish hook + c++_shared link
Per SDD-106 §5 add BridgeEvent::PermissionState{permission, state}
with the PermissionStateKind enum (Granted, Denied, PermanentlyDenied,
Unknown). The Kotlin side publishes mid-session permission changes
through a new JNI entry point Java_app_chanora_chanora_1flutter
_MainActivity_publishPermissionState routed by the new
permission_jni.rs module; the Rust audio engine subscribes and
authoritatively clamps the transmit gate (see SDD-106 §6).

Adds crates/chanora_bridge/build.rs to emit
cargo:rustc-link-lib=dylib=c++_shared on Android so libchanora_bridge
.so carries DT_NEEDED libc++_shared.so; this is required by Android
API 24+ per-library linker namespaces to resolve __cxa_pure_virtual
and friends at System.loadLibrary time.

Includes the FRB-regenerated Dart counterparts so each commit is
independently buildable.

Trace: SDD-105, SDD-106 §5, SDD-118 item 6 (extended).
2026-05-18 12:32:01 +08:00

30 lines
1.4 KiB
Rust

//! Build script for `chanora_bridge`.
//!
//! Android-only: emit `cargo:rustc-link-lib=dylib=c++_shared` so the
//! produced `libchanora_bridge.so` cdylib carries a `DT_NEEDED
//! libc++_shared.so` ELF entry. Without this, Android's per-library
//! namespace dynamic linker (API 24+) does NOT auto-resolve
//! C++ runtime symbols like `__cxa_pure_virtual` even when
//! `libc++_shared.so` is co-located in jniLibs/<abi>/ and already
//! loaded into the process via a prior `System.loadLibrary("c++_shared")`.
//!
//! Trace: SDD-105 (AndroidJniBootstrap — the bridge must load cleanly
//! before MainActivity.onCreate continues). Companion to SDD-118 item 6
//! extended (stages libc++_shared.so into jniLibs/<abi>/).
//!
//! Reference: https://developer.android.com/ndk/guides/cpp-support
//! and the namespace-isolation behavior introduced in API 24.
fn main() {
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
if target_os == "android" {
// Dynamic linkage against the NDK shared C++ runtime. The runtime
// .so is provided by the NDK sysroot at link time (cargo-ndk puts
// the per-target sysroot lib dir on the linker search path) and
// staged into jniLibs/<abi>/ at packaging time by the Gradle
// task `:app:copyRustBridgeJniLibs<Profile>` per SDD-118 item 6
// (extended).
println!("cargo:rustc-link-lib=dylib=c++_shared");
}
}