This is the big one — the Tauri Android app now has a real audio stack
capable of full-duplex VoIP, reusing the proven C++ Oboe bridge from the
legacy wzp-android crate.
Architecture:
- desktop/src-tauri/cpp/ — copies of oboe_bridge.{h,cpp}, oboe_stub.cpp,
and getauxval_fix.c from crates/wzp-android/cpp/. build.rs clones
google/oboe@1.8.1 into OUT_DIR and compiles the bridge + all Oboe
sources as "oboe_bridge" static lib, linking against shared libc++
(static would pull broken libc stubs that SIGSEGV in .so libraries).
- src/oboe_audio.rs — Rust side: an SPSC ring buffer matching the C++
bridge's AtomicI32 layout, plus OboeHandle::start() which returns
(capture_ring, playout_ring, owning_handle). The ring exposes the same
(available / read / write) methods as wzp_client::audio_ring::AudioRing
so CallEngine treats both backends interchangeably.
- src/engine.rs — compiled on every platform now. A cfg-switched type
alias picks wzp_client::audio_ring::AudioRing on desktop and
crate::oboe_audio::AudioRing on Android. The audio setup block has
three branches: VPIO/CPAL on macOS, CPAL on Linux/Windows, Oboe on
Android. Send/recv tasks are identical across platforms.
- src/lib.rs — removes all the "step 3 not done" Android stubs. The
engine module is no longer cfg-gated; connect / disconnect / toggle_mic
/ toggle_speaker / get_status are single implementations used by both
desktop and Android. Identity path resolves via app.path().app_data_dir()
from the Tauri setup() callback (already wired in step 1).
Runtime mic permission:
- scripts/build-tauri-android.sh now injects RECORD_AUDIO + MODIFY_AUDIO_
SETTINGS into gen/android/app/src/main/AndroidManifest.xml after init,
and overwrites MainActivity.kt with a version that calls
ActivityCompat.requestPermissions in onCreate. This is idempotent:
every build re-applies the patches so tauri re-init can't regress them.
Cargo.toml:
- cc is now an unconditional build-dep (build.rs runs on the host, so
target-gating build-deps doesn't work).
- wzp-client is now a dep on every platform. On Android it gets default
features only (no "audio"/"vpio") so CPAL isn't dragged in — oboe_audio
provides the capture/playout rings instead.
- tracing-android is added on Android so tracing events flow into logcat.
build.rs also gained embedded git hash (WZP_GIT_HASH) capture, which is
shown under the fingerprint on the home screen — already committed in
7639aaf, reinstated here alongside the Oboe build logic.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
151 lines
5.7 KiB
Rust
151 lines
5.7 KiB
Rust
use std::path::PathBuf;
|
|
use std::process::Command;
|
|
|
|
fn main() {
|
|
// ─── Embedded git hash ─────────────────────────────────────────────────
|
|
let git_hash = Command::new("git")
|
|
.args(["rev-parse", "--short", "HEAD"])
|
|
.output()
|
|
.ok()
|
|
.filter(|o| o.status.success())
|
|
.and_then(|o| String::from_utf8(o.stdout).ok())
|
|
.map(|s| s.trim().to_string())
|
|
.unwrap_or_else(|| "unknown".into());
|
|
|
|
println!("cargo:rustc-env=WZP_GIT_HASH={git_hash}");
|
|
println!("cargo:rerun-if-changed=../../.git/HEAD");
|
|
println!("cargo:rerun-if-changed=../../.git/refs/heads");
|
|
|
|
// ─── Oboe C++ bridge (Android only) ────────────────────────────────────
|
|
let target = std::env::var("TARGET").unwrap_or_default();
|
|
if target.contains("android") {
|
|
build_oboe_android(&target);
|
|
}
|
|
|
|
tauri_build::build()
|
|
}
|
|
|
|
fn build_oboe_android(target: &str) {
|
|
// Rerun if bridge sources change
|
|
println!("cargo:rerun-if-changed=cpp/oboe_bridge.cpp");
|
|
println!("cargo:rerun-if-changed=cpp/oboe_bridge.h");
|
|
println!("cargo:rerun-if-changed=cpp/oboe_stub.cpp");
|
|
println!("cargo:rerun-if-changed=cpp/getauxval_fix.c");
|
|
|
|
// getauxval_fix: override broken static getauxval from compiler-rt that
|
|
// SIGSEGVs in shared libraries (runs before any app code).
|
|
cc::Build::new()
|
|
.file("cpp/getauxval_fix.c")
|
|
.compile("getauxval_fix");
|
|
|
|
let oboe_dir = fetch_oboe();
|
|
match oboe_dir {
|
|
Some(oboe_path) => {
|
|
println!("cargo:warning=Building with Oboe from {:?}", oboe_path);
|
|
|
|
let mut build = cc::Build::new();
|
|
build
|
|
.cpp(true)
|
|
.std("c++17")
|
|
// Shared libc++ — static pulls broken libc stubs that crash
|
|
// in shared libraries (getauxval, __init_tcb, pthread_create).
|
|
.cpp_link_stdlib(Some("c++_shared"))
|
|
.include("cpp")
|
|
.include(oboe_path.join("include"))
|
|
.include(oboe_path.join("src"))
|
|
.define("WZP_HAS_OBOE", None)
|
|
.file("cpp/oboe_bridge.cpp");
|
|
|
|
add_cpp_files_recursive(&mut build, &oboe_path.join("src"));
|
|
build.compile("oboe_bridge");
|
|
}
|
|
None => {
|
|
println!("cargo:warning=Oboe not found, building with stub");
|
|
cc::Build::new()
|
|
.cpp(true)
|
|
.std("c++17")
|
|
.cpp_link_stdlib(Some("c++_shared"))
|
|
.file("cpp/oboe_stub.cpp")
|
|
.include("cpp")
|
|
.compile("oboe_bridge");
|
|
}
|
|
}
|
|
|
|
// libc++_shared.so must sit next to libwzp_desktop_lib.so in jniLibs —
|
|
// copy it there from the NDK sysroot. Tauri's gradle project expects the
|
|
// jniLibs in gen/android/app/src/main/jniLibs/<abi>/.
|
|
if let Ok(ndk) = std::env::var("ANDROID_NDK_HOME")
|
|
.or_else(|_| std::env::var("NDK_HOME"))
|
|
{
|
|
let (triple, abi) = match target {
|
|
t if t.contains("aarch64") => ("aarch64-linux-android", "arm64-v8a"),
|
|
t if t.contains("armv7") => ("arm-linux-androideabi", "armeabi-v7a"),
|
|
t if t.contains("x86_64") => ("x86_64-linux-android", "x86_64"),
|
|
t if t.contains("i686") => ("i686-linux-android", "x86"),
|
|
_ => ("aarch64-linux-android", "arm64-v8a"),
|
|
};
|
|
let lib_dir = format!(
|
|
"{ndk}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/{triple}"
|
|
);
|
|
println!("cargo:rustc-link-search=native={lib_dir}");
|
|
|
|
let shared_so = format!("{lib_dir}/libc++_shared.so");
|
|
if std::path::Path::new(&shared_so).exists() {
|
|
let manifest = std::env::var("CARGO_MANIFEST_DIR").unwrap_or_default();
|
|
// Tauri mobile layout: gen/android/app/src/main/jniLibs/<abi>/
|
|
let jni_dir = format!("{manifest}/gen/android/app/src/main/jniLibs/{abi}");
|
|
if std::fs::create_dir_all(&jni_dir).is_ok() {
|
|
let _ = std::fs::copy(&shared_so, format!("{jni_dir}/libc++_shared.so"));
|
|
println!("cargo:warning=Copied libc++_shared.so to {jni_dir}");
|
|
}
|
|
}
|
|
}
|
|
|
|
// Oboe requires Android log + OpenSLES backends
|
|
println!("cargo:rustc-link-lib=log");
|
|
println!("cargo:rustc-link-lib=OpenSLES");
|
|
}
|
|
|
|
/// Recursively add all .cpp files from a directory to a cc::Build.
|
|
fn add_cpp_files_recursive(build: &mut cc::Build, dir: &std::path::Path) {
|
|
if !dir.is_dir() {
|
|
return;
|
|
}
|
|
for entry in std::fs::read_dir(dir).unwrap() {
|
|
let entry = entry.unwrap();
|
|
let path = entry.path();
|
|
if path.is_dir() {
|
|
add_cpp_files_recursive(build, &path);
|
|
} else if path.extension().map_or(false, |e| e == "cpp") {
|
|
build.file(&path);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Try to find or fetch Oboe headers + source (v1.8.1).
|
|
fn fetch_oboe() -> Option<PathBuf> {
|
|
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
|
|
let oboe_dir = out_dir.join("oboe");
|
|
|
|
if oboe_dir.join("include").join("oboe").join("Oboe.h").exists() {
|
|
return Some(oboe_dir);
|
|
}
|
|
|
|
let status = Command::new("git")
|
|
.args([
|
|
"clone",
|
|
"--depth=1",
|
|
"--branch=1.8.1",
|
|
"https://github.com/google/oboe.git",
|
|
oboe_dir.to_str().unwrap(),
|
|
])
|
|
.status();
|
|
|
|
match status {
|
|
Ok(s) if s.success() && oboe_dir.join("include").join("oboe").join("Oboe.h").exists() => {
|
|
Some(oboe_dir)
|
|
}
|
|
_ => None,
|
|
}
|
|
}
|