fix: 完善 libyuv 静态库构建

This commit is contained in:
mofeng-git
2026-07-17 23:25:04 +08:00
parent 79b6683817
commit 563c808836
2 changed files with 68 additions and 36 deletions

View File

@@ -86,6 +86,21 @@ fn generate_bindings(cpp_dir: &Path) {
}
fn link_libyuv() {
println!("cargo:rerun-if-env-changed=ONE_KVM_LIBS_PATH");
println!("cargo:rerun-if-env-changed=LIBYUV_STATIC");
// An explicit library root must take precedence over host discovery.
if env::var("ONE_KVM_LIBS_PATH")
.ok()
.is_some_and(|path| !path.trim().is_empty())
{
if link_system() {
return;
}
panic!("libyuv not found under ONE_KVM_LIBS_PATH");
}
// Try vcpkg first
if let Some(vcpkg_installed) = vcpkg_installed_root() {
if link_vcpkg(vcpkg_installed) {
@@ -232,9 +247,13 @@ fn link_system() -> bool {
// Build custom library paths based on target architecture:
// 1. Check ONE_KVM_LIBS_PATH environment variable (explicit override)
// 2. Fall back to architecture-based detection
let custom_lib_path = if let Ok(path) = env::var("ONE_KVM_LIBS_PATH") {
format!("{}/lib", path)
} else {
let explicit_lib_root = env::var("ONE_KVM_LIBS_PATH")
.ok()
.filter(|path| !path.trim().is_empty());
let custom_lib_path = explicit_lib_root
.as_ref()
.map(|path| format!("{}/lib", path))
.unwrap_or_else(|| {
match target_arch.as_str() {
"x86_64" => "/usr/local/lib",
"aarch64" => "/usr/aarch64-linux-gnu/lib",
@@ -242,7 +261,7 @@ fn link_system() -> bool {
_ => "",
}
.to_string()
};
});
// Try common system library paths (custom paths first)
let mut lib_paths: Vec<String> = Vec::new();
@@ -252,7 +271,8 @@ fn link_system() -> bool {
lib_paths.push(custom_lib_path);
}
// Then standard paths
// An explicit root is strict: do not silently fall back to host libraries.
if explicit_lib_root.is_none() {
lib_paths.extend(
[
"/usr/local/lib", // Custom builds
@@ -266,6 +286,7 @@ fn link_system() -> bool {
.iter()
.map(|s| s.to_string()),
);
}
for path in &lib_paths {
let lib_path = Path::new(path);

View File

@@ -1391,4 +1391,15 @@ mod tests {
assert_eq!(converter.dimensions(), (8, 8));
assert_eq!(converter.nv12_buffer().len(), nv12_size(8, 8));
}
#[test]
fn test_bgr24_to_nv12() {
let src = [0u8; 2 * 2 * 3];
let mut dst = [0xffu8; 2 * 2 * 3 / 2];
bgr24_to_nv12(&src, &mut dst, 2, 2).unwrap();
assert_eq!(&dst[..4], &[16, 16, 16, 16]);
assert_eq!(&dst[4..], &[128, 128]);
}
}