From ce15106eb0b7011fc1fd8ded48f876499120a633 Mon Sep 17 00:00:00 2001 From: Charlie Somerville Date: Fri, 1 May 2020 23:05:51 +1000 Subject: [PATCH 1/2] refactor eval_configure --- build.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/build.rs b/build.rs index 592b510..47cf67e 100644 --- a/build.rs +++ b/build.rs @@ -5,6 +5,7 @@ use std::collections::HashSet; use std::convert::AsRef; use std::path::{PathBuf, Path}; use std::string::ToString; +use std::process::Command; use tar::Archive; use flate2::read::GzDecoder; @@ -244,19 +245,15 @@ fn build() { configure_flags.push("--disable-debug"); configure_flags.push("--disable-stripping"); } - let eval_configure = |flags: Vec<&str>| { - let flags = flags.join(" "); - std::process::Command::new("sh") - .arg("-c") - .arg(&format!( - "cd {path} && ./configure {flags}", - path=source_path.to_str().expect("PathBuf to str"), - flags=flags, - )) + + let eval_configure = |flags: &[&str]| { + Command::new("./configure") + .current_dir(&source_path) + .args(flags) .output() - .expect(&format!("ffmpeg configure script")) + .expect("ffmpeg configure script") }; - let result = eval_configure(configure_flags.clone()); + let result = eval_configure(&configure_flags); if !result.status.success() { let stderr = String::from_utf8(result.stderr).expect("invalid str"); let stdout = String::from_utf8(result.stdout).expect("invalid str"); @@ -267,7 +264,7 @@ fn build() { // MAYBE RETRY (USE CRIPPLED BUILD) if nasm_yasm_issue { configure_flags.push("--disable-x86asm"); - let result = eval_configure(configure_flags); + let result = eval_configure(&configure_flags); if !result.status.success() { let stderr = String::from_utf8(result.stderr).expect("invalid str"); let stdout = String::from_utf8(result.stdout).expect("invalid str"); From 1f315aa21d85a7111bf3f3101e7fe7c5bf22f6f1 Mon Sep 17 00:00:00 2001 From: Charlie Somerville Date: Fri, 1 May 2020 23:42:22 +1000 Subject: [PATCH 2/2] add x264-dev as an optional dependency gated by 'x264' feature --- Cargo.toml | 8 +++++++- build.rs | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 41 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..2b33ab1 100644 --- a/build.rs +++ b/build.rs @@ -1,5 +1,6 @@ #![allow(unused)] +use std::env; use std::iter::FromIterator; use std::collections::HashSet; use std::convert::AsRef; @@ -239,15 +240,46 @@ 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 x264_libs = env::var_os("DEP_X264_LIBS").unwrap(); + println!("cargo:rustc-link-search=native={}", x264_libs.to_str().expect("PathBuf to str")); + println!("cargo:rustc-link-lib=static=x264"); + + 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()