From 02445c8f320981829332ff52c920ed8966f87372 Mon Sep 17 00:00:00 2001 From: Prateek Sunal Date: Fri, 14 Jun 2024 19:19:15 +0530 Subject: [PATCH] fix: try to manually specify ffmpeg header in rust --- mac/Makefile.am | 4 ++-- src/rust/Cargo.lock | 1 + src/rust/Cargo.toml | 1 + src/rust/build.rs | 10 ++++++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/mac/Makefile.am b/mac/Makefile.am index d5e8938f5..a57ca8904 100644 --- a/mac/Makefile.am +++ b/mac/Makefile.am @@ -272,7 +272,7 @@ if HARDSUBX_IS_ENABLED ccextractor_CFLAGS += -DENABLE_HARDSUBX libavcodec_CFLAGS = $(shell pkg-config --cflags libavcodec) libavformat_CFLAGS = $(shell pkg-config --cflags libavformat) -libavutil_CFALGS = $(shell pkg-config --cflags libavutil) +libavutil_CFLAGS = $(shell pkg-config --cflags libavutil) libswscale_CFLAGS = $(shell pkg-config --cflags libswscale) libavcodec_LIBS = $(shell pkg-config --libs libavcodec) libavformat_LIBS = $(shell pkg-config --libs libavformat) @@ -280,7 +280,7 @@ libavutil_LIBS = $(shell pkg-config --libs libavutil) libswscale_LIBS = $(shell pkg-config --libs libswscale) ccextractor_CPPFLAGS+= ${libavcodec_CFLAGS} ccextractor_CPPFLAGS+= ${libavformat_CFLAGS} -ccextractor_CPPFLAGS+= ${libavutil_CFALGS} +ccextractor_CPPFLAGS+= ${libavutil_CFLAGS} ccextractor_CPPFLAGS+= ${libswscale_CFLAGS} AV_LIB = ${libavcodec_LIBS} AV_LIB += ${libavformat_LIBS} diff --git a/src/rust/Cargo.lock b/src/rust/Cargo.lock index 1b692d5b4..0d5aff6dc 100644 --- a/src/rust/Cargo.lock +++ b/src/rust/Cargo.lock @@ -162,6 +162,7 @@ dependencies = [ "log", "num-integer", "palette", + "pkg-config", "rsmpeg", "strum", "strum_macros", diff --git a/src/rust/Cargo.toml b/src/rust/Cargo.toml index 4c9bcad67..2f1a13189 100644 --- a/src/rust/Cargo.toml +++ b/src/rust/Cargo.toml @@ -29,6 +29,7 @@ num-integer = "0.1.45" [build-dependencies] bindgen = "0.64.0" +pkg-config = "0.3.30" [features] hardsubx_ocr = ["rsmpeg", "tesseract-sys", "leptonica-sys"] diff --git a/src/rust/build.rs b/src/rust/build.rs index a099fd568..d262ce91b 100644 --- a/src/rust/build.rs +++ b/src/rust/build.rs @@ -1,3 +1,4 @@ +extern crate pkg_config; use std::env; use std::path::PathBuf; @@ -44,9 +45,18 @@ fn main() { #[cfg(feature = "hardsubx_ocr")] allowlist_types.extend_from_slice(&["AVRational", "AVPacket", "AVFrame"]); + std::env::set_var("PKG_CONFIG_ALLOW_SYSTEM_CFLAGS", "1"); + let library = pkg_config::probe_library("libavcodec").expect("Unable to probe `libavcodec`"); + let mut builder = bindgen::Builder::default() // The input header we would like to generate // bindings for. + .clang_args( + library + .include_paths + .iter() + .map(|path| format!("-I{}", path.to_string_lossy())), + ) .header("wrapper.h"); // enable hardsubx if and only if the feature is on