Add macOS package manager search paths for pkg-config (#8)

This commit is contained in:
Mikhail Katychev 2023-03-23 12:11:48 -03:00 committed by GitHub
parent 0d11595259
commit fa2b8d13ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 7 deletions

View File

@ -16,7 +16,7 @@ fn main() {
println!("\tend: {}", chapter.end()); println!("\tend: {}", chapter.end());
for (k, v) in chapter.metadata().iter() { for (k, v) in chapter.metadata().iter() {
println!("\t{}: {}", k, v); println!("\t{k}: {v}");
} }
} }
@ -49,11 +49,11 @@ fn main() {
println!("\tstart: {}", chapter.start()); println!("\tstart: {}", chapter.start());
println!("\tend: {}", chapter.end()); println!("\tend: {}", chapter.end());
for (k, v) in chapter.metadata().iter() { for (k, v) in chapter.metadata().iter() {
println!("\t{}: {}", k, v); println!("\t{k}: {v}");
} }
} }
} }
Err(error) => println!("error: {}", error), Err(error) => println!("error: {error}"),
} }
} }

View File

@ -59,7 +59,7 @@ fn main() -> Result<(), ffmpeg::Error> {
} }
fn save_file(frame: &Video, index: usize) -> std::result::Result<(), std::io::Error> { fn save_file(frame: &Video, index: usize) -> std::result::Result<(), std::io::Error> {
let mut file = File::create(format!("frame{}.ppm", index))?; let mut file = File::create(format!("frame{index}.ppm"))?;
file.write_all(format!("P6\n{} {}\n255\n", frame.width(), frame.height()).as_bytes())?; file.write_all(format!("P6\n{} {}\n255\n", frame.width(), frame.height()).as_bytes())?;
file.write_all(frame.data(0))?; file.write_all(frame.data(0))?;
Ok(()) Ok(())

View File

@ -8,7 +8,7 @@ fn main() -> Result<(), ffmpeg::Error> {
match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) { match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
Ok(context) => { Ok(context) => {
for (k, v) in context.metadata().iter() { for (k, v) in context.metadata().iter() {
println!("{}: {}", k, v); println!("{k}: {v}");
} }
if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) { if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
@ -83,7 +83,7 @@ fn main() -> Result<(), ffmpeg::Error> {
} }
} }
Err(error) => println!("error: {}", error), Err(error) => println!("error: {error}"),
} }
Ok(()) Ok(())
} }

View File

@ -173,7 +173,7 @@ fn main() {
) )
.expect("invalid x264 options string"); .expect("invalid x264 options string");
eprintln!("x264 options: {:?}", x264_opts); eprintln!("x264 options: {x264_opts:?}");
ffmpeg::init().unwrap(); ffmpeg::init().unwrap();
log::set_level(log::Level::Info); log::set_level(log::Level::Info);

View File

@ -399,6 +399,27 @@ fn try_vcpkg(statik: bool) -> Option<Vec<PathBuf>> {
.ok() .ok()
} }
// add well known package manager lib paths us as homebrew (or macports)
#[cfg(target_os = "macos")]
fn add_pkg_config_path() {
use std::path::Path;
let pc_path = pkg_config::get_variable("pkg-config", "pc_path").unwrap();
// append M1 homebrew pkgconfig path
let brew_pkgconfig = cfg!(target_arch = "aarch64")
.then_some("/opt/homebrew/lib/pkgconfig/")
.unwrap_or("/usr/local/homebrew/lib/pkgconfig/"); // x86 as fallback
if !pc_path.to_lowercase().contains(brew_pkgconfig) && Path::new(brew_pkgconfig).is_dir() {
let new_pc_path = env::var("PKG_CONFIG_PATH")
// PKG_CONFIG_PATH="/our/path:$PKG_CONFIG_PATH"
.map(|p| format!("{brew_pkgconfig}:{p}"))
.unwrap_or_else(|_| brew_pkgconfig.to_string());
env::set_var("PKG_CONFIG_PATH", new_pc_path);
}
}
#[cfg(not(target_os = "macos"))]
fn add_pkg_config_path() {}
fn check_features( fn check_features(
include_paths: Vec<PathBuf>, include_paths: Vec<PathBuf>,
infos: &[(&'static str, Option<&'static str>, &'static str)], infos: &[(&'static str, Option<&'static str>, &'static str)],
@ -708,6 +729,7 @@ fn main() {
} }
// Fallback to pkg-config // Fallback to pkg-config
else { else {
add_pkg_config_path();
pkg_config::Config::new() pkg_config::Config::new()
.statik(statik) .statik(statik)
.probe("libavutil") .probe("libavutil")