use vcpkg to find package
This commit is contained in:
parent
9136b3e3f8
commit
82f2431eb8
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -3574,6 +3574,7 @@ dependencies = [
|
|||||||
"serde 1.0.136",
|
"serde 1.0.136",
|
||||||
"target_build_utils",
|
"target_build_utils",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
"vcpkg",
|
||||||
"webm",
|
"webm",
|
||||||
"winapi 0.3.9",
|
"winapi 0.3.9",
|
||||||
]
|
]
|
||||||
@ -4163,6 +4164,12 @@ dependencies = [
|
|||||||
"getrandom",
|
"getrandom",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "vcpkg"
|
||||||
|
version = "0.2.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vec_map"
|
name = "vec_map"
|
||||||
version = "0.8.2"
|
version = "0.8.2"
|
||||||
|
@ -33,6 +33,7 @@ quest = "0.3"
|
|||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
target_build_utils = "0.3"
|
target_build_utils = "0.3"
|
||||||
bindgen = "0.59"
|
bindgen = "0.59"
|
||||||
|
vcpkg = "0.2"
|
||||||
|
|
||||||
[target.'cfg(target_os = "linux")'.dependencies]
|
[target.'cfg(target_os = "linux")'.dependencies]
|
||||||
dbus = { version = "0.9", optional = true }
|
dbus = { version = "0.9", optional = true }
|
||||||
|
@ -4,40 +4,35 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
fn find_package(name: &str) -> Vec<PathBuf> {
|
fn find_package(name: &str) -> Vec<PathBuf> {
|
||||||
let vcpkg_root = std::env::var("VCPKG_ROOT").unwrap();
|
let library = vcpkg::find_package(name).expect("Failed to find package");
|
||||||
let mut path: PathBuf = vcpkg_root.into();
|
println!("cargo:info={}", library.vcpkg_triplet); //TODO
|
||||||
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
|
let lib_name = name.trim_start_matches("lib").to_string();
|
||||||
let mut target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
|
println!("{}", format!("cargo:rustc-link-lib=static={}", lib_name));
|
||||||
if target_arch == "x86_64" {
|
|
||||||
target_arch = "x64".to_owned();
|
match (
|
||||||
} else if target_arch == "aarch64" {
|
library.link_paths.as_slice(),
|
||||||
target_arch = "arm64".to_owned();
|
library.include_paths.as_slice(),
|
||||||
}
|
) {
|
||||||
let mut target = if target_os == "macos" {
|
([link_search, ..], [include, ..]) => {
|
||||||
"x64-osx".to_owned()
|
|
||||||
} else if target_os == "windows" {
|
|
||||||
"x64-windows-static".to_owned()
|
|
||||||
} else {
|
|
||||||
format!("{}-{}", target_arch, target_os)
|
|
||||||
};
|
|
||||||
if target_arch == "x86" {
|
|
||||||
target = target.replace("x64", "x86");
|
|
||||||
}
|
|
||||||
println!("cargo:info={}", target);
|
|
||||||
path.push("installed");
|
|
||||||
path.push(target);
|
|
||||||
let lib = name.trim_start_matches("lib").to_string();
|
|
||||||
println!("{}", format!("cargo:rustc-link-lib=static={}", lib));
|
|
||||||
println!(
|
println!(
|
||||||
"{}",
|
"{}",
|
||||||
format!(
|
format!("cargo:rustc-link-search={}", link_search.display())
|
||||||
"cargo:rustc-link-search={}",
|
|
||||||
path.join("lib").to_str().unwrap()
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
let include = path.join("include");
|
println!("{}", format!("cargo:include={}", include.display()));
|
||||||
println!("{}", format!("cargo:include={}", include.to_str().unwrap()));
|
}
|
||||||
vec![include]
|
_ => {
|
||||||
|
panic!(
|
||||||
|
"{}",
|
||||||
|
if library.link_paths.is_empty() {
|
||||||
|
"link path not found"
|
||||||
|
} else {
|
||||||
|
"include path not found"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
library.include_paths
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_bindings(
|
fn generate_bindings(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user