The app crashed immediately when loading libwzp_android.so because the
cc crate's default dynamic linking produced a runtime dependency on
libc++_shared.so, which was never packaged into the APK.
Adding .cpp_link_stdlib(Some("c++_static")) to build.rs bakes the C++
runtime into libwzp_android.so directly, eliminating the missing .so.
See issues/001-libc++-shared-crash.md for full diagnosis and logcat trace.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
78 lines
2.4 KiB
Rust
78 lines
2.4 KiB
Rust
use std::path::PathBuf;
|
|
|
|
fn main() {
|
|
let target = std::env::var("TARGET").unwrap_or_default();
|
|
|
|
if target.contains("android") {
|
|
// On Android, try to build with Oboe. If Oboe is not available,
|
|
// fall back to the stub (audio will need to be provided via JNI).
|
|
let oboe_dir = fetch_oboe();
|
|
match oboe_dir {
|
|
Some(oboe_path) => {
|
|
println!("cargo:warning=Building with Oboe from {:?}", oboe_path);
|
|
cc::Build::new()
|
|
.cpp(true)
|
|
.std("c++17")
|
|
.cpp_link_stdlib(Some("c++_static"))
|
|
.file("cpp/oboe_bridge.cpp")
|
|
.include("cpp")
|
|
.include(oboe_path.join("include"))
|
|
.define("WZP_HAS_OBOE", None)
|
|
.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++_static"))
|
|
.file("cpp/oboe_stub.cpp")
|
|
.include("cpp")
|
|
.compile("oboe_bridge");
|
|
}
|
|
}
|
|
} else {
|
|
// Non-Android: always use stub
|
|
cc::Build::new()
|
|
.cpp(true)
|
|
.std("c++17")
|
|
.file("cpp/oboe_stub.cpp")
|
|
.include("cpp")
|
|
.compile("oboe_bridge");
|
|
}
|
|
}
|
|
|
|
/// Try to find or fetch Oboe headers.
|
|
/// Returns the path to the Oboe source root (containing include/ directory).
|
|
fn fetch_oboe() -> Option<PathBuf> {
|
|
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
|
|
let oboe_dir = out_dir.join("oboe");
|
|
|
|
// Check if already fetched
|
|
if oboe_dir.join("include").join("oboe").join("Oboe.h").exists() {
|
|
return Some(oboe_dir);
|
|
}
|
|
|
|
// Try to clone Oboe from GitHub
|
|
let status = std::process::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() => {
|
|
if oboe_dir.join("include").join("oboe").join("Oboe.h").exists() {
|
|
Some(oboe_dir)
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
_ => None,
|
|
}
|
|
}
|