From 3d0e0093fb8267ca34163f8d10641f6676cd0dbb Mon Sep 17 00:00:00 2001 From: Charlie Somerville Date: Fri, 1 May 2020 23:42:22 +1000 Subject: [PATCH] add x264-dev as an optional dependency gated by 'x264' feature --- Cargo.toml | 8 +++++++- build.rs | 30 ++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b95e884..d4ceb7d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,13 +11,19 @@ repository = "https://github.com/imager-io/ffmpeg-dev-rs" readme = "README.md" exclude = ["assets", "examples"] +[features] +default = [] +gpl = [] +x264 = ["x264-dev"] + [dependencies] libc = "^0.2" num_cpus = "1.11.1" +x264-dev = { path = "../x264-dev", optional = true } [build-dependencies] tar = "0.4.26" flate2 = "1.0.12" bindgen = "0.51" num_cpus = "1.11.1" -cc = "1.0.46" \ No newline at end of file +cc = "1.0.46" diff --git a/build.rs b/build.rs index 47cf67e..d7a40c6 100644 --- a/build.rs +++ b/build.rs @@ -239,15 +239,41 @@ fn build() { "--disable-doc", "--disable-autodetect", ]; + + let mut pkg_config_path = env::var_os("PKG_CONFIG_PATH"); + + if env::var_os("CARGO_FEATURE_GPL").is_some() { + configure_flags.push("--enable-gpl"); + } + + if env::var_os("CARGO_FEATURE_X264").is_some() { + configure_flags.push("--enable-libx264"); + let mut x264_pkg_config = env::var_os("DEP_X264_PKGCONFIG").unwrap(); + + // append existing pkg_config path - make sure x264's pkgconfig has precedence: + if let Some(path) = pkg_config_path { + x264_pkg_config.push(":"); + x264_pkg_config.push(path); + } + + pkg_config_path = Some(x264_pkg_config); + } + // TRY TO SPEED THIS UP FOR DEV BUILDS if is_debug_mode() && opt_level_eq(0) { configure_flags.push("--disable-optimizations"); - configure_flags.push("--disable-debug"); + configure_flags.push("--enable-debug"); configure_flags.push("--disable-stripping"); } let eval_configure = |flags: &[&str]| { - Command::new("./configure") + let mut configure = Command::new("./configure"); + + if let Some(path) = &pkg_config_path { + configure.env("PKG_CONFIG_PATH", path); + } + + configure .current_dir(&source_path) .args(flags) .output()