2017-06-03 17:51:28 +04:00
|
|
|
extern crate bindgen;
|
2016-12-28 10:30:10 +04:00
|
|
|
|
2017-01-02 04:42:53 +04:00
|
|
|
use std::env;
|
2016-12-28 10:30:10 +04:00
|
|
|
use std::fs::OpenOptions;
|
|
|
|
use std::io::Write;
|
2017-01-02 04:42:53 +04:00
|
|
|
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) {
|
2023-03-28 20:57:22 +04:00
|
|
|
let s = builder
|
|
|
|
.layout_tests(false)
|
|
|
|
// .rustified_non_exhaustive_enum("cudaVideoCodec_enum")
|
|
|
|
.rustified_non_exhaustive_enum("cuvidDecodeStatus_enum")
|
|
|
|
.rustified_non_exhaustive_enum("cudaVideoSurfaceFormat_enum")
|
|
|
|
.rustified_non_exhaustive_enum("cudaVideoDeinterlaceMode_enum")
|
|
|
|
.generate()
|
2016-12-28 10:30:10 +04:00
|
|
|
.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()
|
2023-03-28 20:57:22 +04:00
|
|
|
.constified_enum_module("*")
|
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)]")
|
|
|
|
}
|
|
|
|
|
2017-01-02 04:42:53 +04:00
|
|
|
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() {
|
2017-01-02 04:42:53 +04:00
|
|
|
let cuda_include = find_dir("/opt/cuda/include", "CUDA_INCLUDE_PATH");
|
2023-03-28 20:57:22 +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()
|
2017-01-02 04:42:53 +04:00
|
|
|
.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
|
2017-01-02 07:25:09 +04:00
|
|
|
format_write(cuda_builder, "src/cuda.rs");
|
2016-12-28 10:30:10 +04:00
|
|
|
|
|
|
|
let cuvid_builder = common_builder()
|
2017-01-02 04:42:53 +04:00
|
|
|
.clang_arg(format!("-I{}", nvc_include.to_string_lossy()))
|
|
|
|
.clang_arg(format!("-I{}", cuda_include.to_string_lossy()))
|
2023-03-28 20:57:22 +04:00
|
|
|
.derive_debug(true)
|
2017-01-02 04:42:53 +04:00
|
|
|
.header(nvc_include.join("nvcuvid.h").to_string_lossy());
|
2016-12-28 10:30:10 +04:00
|
|
|
|
2017-01-02 07:25:09 +04:00
|
|
|
format_write(cuvid_builder, "src/cuvid.rs");
|
2016-12-28 10:30:10 +04:00
|
|
|
|
|
|
|
let nvenc_builder = common_builder()
|
2017-01-02 04:42:53 +04:00
|
|
|
.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
|
|
|
|
2017-01-02 07:25:09 +04:00
|
|
|
format_write(nvenc_builder, "src/nvenc.rs");
|
2016-12-28 10:30:10 +04:00
|
|
|
}
|