Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for vcpkg #27

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions opus-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ build = "build.rs"
bindgen = "0.59"
metadeps = "1.1"

[target.'cfg(target_env = "msvc")'.build-dependencies]
vcpkg = "0.2.11"

[package.metadata.pkg-config]
opus = "1.3"

Expand Down
34 changes: 31 additions & 3 deletions opus-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,42 @@ fn format_write(builder: bindgen::Builder) -> String {
.replace("/*!", "/*")
}

#[cfg(not(target_env = "msvc"))]
fn try_vcpkg(_statik: bool) -> Option<Vec<PathBuf>> {
None
}

#[cfg(target_env = "msvc")]
fn try_vcpkg(statik: bool) -> Option<Vec<PathBuf>> {
if !statik {
env::set_var("VCPKGRS_DYNAMIC", "1");
}

vcpkg::find_package("opus")
.map_err(|e| {
println!("Could not find ffmpeg with vcpkg: {}", e);
})
.map(|library| library.include_paths)
.ok()
}

fn main() {
let libs = metadeps::probe().unwrap();
let headers = libs.get("opus").unwrap().include_paths.clone();
let mut include_sub_dir = "";
Luni-4 marked this conversation as resolved.
Show resolved Hide resolved
let headers = if let Some(paths) = try_vcpkg(false) {
include_sub_dir = "opus";
paths
} else {
let libs = metadeps::probe().unwrap();
let paths = libs.get("opus").unwrap().include_paths.clone();
paths
};

let mut builder = bindgen::builder().header("data/opus.h");

for header in headers {
builder = builder.clang_arg("-I").clang_arg(header.to_str().unwrap());
builder = builder
.clang_arg("-I")
.clang_arg(header.join(include_sub_dir).to_str().unwrap());
}

// Manually fix the comment so rustdoc won't try to pick them
Expand Down