build: Support environment variables

Only for the include paths.
This commit is contained in:
Luca Barbato 2017-01-02 00:42:53 +00:00
parent e4c858a6f6
commit fa9540fb59
2 changed files with 29 additions and 30 deletions

View File

@ -1,7 +1,17 @@
# NVIDIA Video Codec SDK bindings # NVIDIA Video Codec SDK bindings
[![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
It is a simple [binding][1] and safe abstraction over the [nvidia video codec sdk][2]. It is a simple [binding][1] and safe abstraction over the [nvidia video codec sdk][2].
## Building
The bindings are generated using the headers and libraries that ought to be present in the system.
By default the headers are looked up on `/opt/cuda/include` and `/opt/nvidia-video-codec` and the libraries are assumed to be present in the default path (and provided by the driver).
It is possible to override the search paths for the headers by setting the environment variables `CUDA_INCLUDE_PATH` and `NVIDIA_VIDEO_CODEC_INCLUDE_PATH`.
## TODO ## TODO
- [ ] support cuda - [ ] support cuda

View File

@ -1,9 +1,9 @@
extern crate libbindgen; extern crate libbindgen;
// use std::env; use std::env;
use std::path::Path;
use std::fs::OpenOptions; use std::fs::OpenOptions;
use std::io::Write; use std::io::Write;
use std::path::PathBuf;
fn format_write(builder: libbindgen::Builder, output: &str) { fn format_write(builder: libbindgen::Builder, output: &str) {
let s = builder.generate() let s = builder.generate()
@ -30,11 +30,17 @@ fn common_builder() -> libbindgen::Builder {
.raw_line("#![allow(non_upper_case_globals)]") .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),
}
}
fn main() { fn main() {
// let out_dir = env::var("OUT_DIR").unwrap(); let cuda_include = find_dir("/opt/cuda/include", "CUDA_INCLUDE_PATH");
// TODO make them params and try to figure them out as default let nvc_include = find_dir("/opt/nvidia-video-codec/",
let cuda_include = "/opt/cuda/include"; "NVIDIA_VIDEO_CODEC_INCLUDE_PATH");
let nvc_include = "/opt/nvidia-video-codec/";
// TODO support windows // TODO support windows
println!("cargo:rustc-link-lib=dylib={}", "cuda"); println!("cargo:rustc-link-lib=dylib={}", "cuda");
@ -43,39 +49,22 @@ fn main() {
let cuda_builder = common_builder() let cuda_builder = common_builder()
.clang_arg(format!("-I{}", cuda_include)) .clang_arg(format!("-I{}", cuda_include.to_string_lossy()))
.header(Path::new(cuda_include).join("cuda.h").to_str().unwrap()); .header(cuda_include.join("cuda.h").to_string_lossy());
// Manually fix the comment so rustdoc won't try to pick them // Manually fix the comment so rustdoc won't try to pick them
format_write(cuda_builder, "src/ffi/cuda.rs"); format_write(cuda_builder, "src/ffi/cuda.rs");
let cuvid_builder = common_builder() let cuvid_builder = common_builder()
.clang_arg(format!("-I{}", nvc_include)) .clang_arg(format!("-I{}", nvc_include.to_string_lossy()))
.clang_arg(format!("-I{}", cuda_include)) .clang_arg(format!("-I{}", cuda_include.to_string_lossy()))
.header(Path::new(nvc_include).join("nvcuvid.h").to_str().unwrap()); .header(nvc_include.join("nvcuvid.h").to_string_lossy());
println!("{:?}", cuvid_builder);
format_write(cuvid_builder, "src/ffi/cuvid.rs"); format_write(cuvid_builder, "src/ffi/cuvid.rs");
let nvenc_builder = common_builder() let nvenc_builder = common_builder()
.clang_arg(format!("-I{}", nvc_include)) .clang_arg(format!("-I{}", nvc_include.to_string_lossy()))
.header(Path::new(nvc_include).join("nvEncodeAPI.h").to_str().unwrap()); .header(nvc_include.join("nvEncodeAPI.h").to_string_lossy());
format_write(nvenc_builder, "src/ffi/nvenc.rs"); format_write(nvenc_builder, "src/ffi/nvenc.rs");
} }
// let s = cuda_gen.generate()
// .unwrap()
// .to_string()
// .replace("**", "*");
//
// let mut file = OpenOptions::new()
// .write(true)
// .truncate(true)
// .create(true)
// .open("src/ffi/cuda.rs")
// .unwrap();
//
// let _ = file.write(s.as_bytes());
//