nvidia-video-codec-rs/nvidia-video-codec-sys/build.rs

71 lines
2.1 KiB
Rust
Raw Normal View History

2017-06-03 17:51:28 +04:00
extern crate bindgen;
2016-12-28 10:30:10 +04:00
use std::env;
2016-12-28 10:30:10 +04:00
use std::fs::OpenOptions;
use std::io::Write;
use std::path::PathBuf;
2016-12-28 10:30:10 +04:00
2017-06-03 17:51:28 +04:00
fn format_write(builder: bindgen::Builder, output: &str) {
2016-12-28 10:30:10 +04:00
let s = builder.generate()
.unwrap()
.to_string()
.replace("/**", "/*")
.replace("/*!", "/*");
let mut file = OpenOptions::new()
.write(true)
.truncate(true)
.create(true)
.open(output)
.unwrap();
let _ = file.write(s.as_bytes());
}
2017-06-03 17:51:28 +04:00
fn common_builder() -> bindgen::Builder {
bindgen::builder()
2016-12-28 10:30:10 +04:00
.raw_line("#![allow(dead_code)]")
.raw_line("#![allow(non_camel_case_types)]")
.raw_line("#![allow(non_snake_case)]")
.raw_line("#![allow(non_upper_case_globals)]")
}
fn find_dir(default: &'static str, env_key: &'static str) -> PathBuf {
match env::var_os(env_key) {
Some(val) => PathBuf::from(&val),
_ => PathBuf::from(default),
}
}
2016-12-28 10:30:10 +04:00
fn main() {
let cuda_include = find_dir("/opt/cuda/include", "CUDA_INCLUDE_PATH");
2017-03-15 18:08:27 +04:00
let nvc_include = find_dir("/opt/nvidia-video-codec/include",
"NVIDIA_VIDEO_CODEC_INCLUDE_PATH");
2016-12-28 10:30:10 +04:00
// TODO support windows
println!("cargo:rustc-link-lib=dylib={}", "cuda");
println!("cargo:rustc-link-lib=dylib={}", "nvcuvid");
println!("cargo:rustc-link-lib=dylib={}", "nvidia-encode");
let cuda_builder = common_builder()
.clang_arg(format!("-I{}", cuda_include.to_string_lossy()))
.header(cuda_include.join("cuda.h").to_string_lossy());
2016-12-28 10:30:10 +04:00
// Manually fix the comment so rustdoc won't try to pick them
format_write(cuda_builder, "src/cuda.rs");
2016-12-28 10:30:10 +04:00
let cuvid_builder = common_builder()
.clang_arg(format!("-I{}", nvc_include.to_string_lossy()))
.clang_arg(format!("-I{}", cuda_include.to_string_lossy()))
.header(nvc_include.join("nvcuvid.h").to_string_lossy());
2016-12-28 10:30:10 +04:00
format_write(cuvid_builder, "src/cuvid.rs");
2016-12-28 10:30:10 +04:00
let nvenc_builder = common_builder()
.clang_arg(format!("-I{}", nvc_include.to_string_lossy()))
.header(nvc_include.join("nvEncodeAPI.h").to_string_lossy());
2016-12-28 10:30:10 +04:00
format_write(nvenc_builder, "src/nvenc.rs");
2016-12-28 10:30:10 +04:00
}