Skip to content

Commit b7042ed

Browse files
fix: Missing extra libs linker flags (#88)
* fix: Missing extra libs linker flags ffmpeg .mak file can look like this when there are a lot of linked flags for different libraries but now ffmpeg only reads the main EXTRALIBS= while the other libs are ignored. After this change it flat maps over all of the extralibs (I also added support for -L flags) and everything works semlessly ``` EXTRALIBS= ... EXTRALIBS-avdevice=-lm EXTRALIBS-avfilter=-pthread -lm EXTRALIBS-swscale=-lm EXTRALIBS-postproc=-lm EXTRALIBS-avformat=-lm EXTRALIBS-avcodec=-pthread -lm -lmp3lame -lm -L/opt/homebrew/Cellar/x264/r3108/lib -lx264 -L/opt/homebrew/Cellar/x265/3.6/lib -lx265 EXTRALIBS-swresample=-lm EXTRALIBS-avutil=-pthread -lm -framework CoreFoundation -framework CoreVideo -framework CoreMedia EXTRALIBS-ffplay= EXTRALIBS-ffprobe= EXTRALIBS-ffmpeg= EXTRALIBS-cpu_init=-pthread EXTRALIBS-cws2fws= ```
1 parent 9b0634a commit b7042ed

File tree

1 file changed

+44
-13
lines changed

1 file changed

+44
-13
lines changed

build.rs

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ fn build() -> io::Result<()> {
248248
// make it static
249249
configure.arg("--enable-static");
250250
configure.arg("--disable-shared");
251+
configure.arg("--enable-pthreads");
251252

252253
configure.arg("--enable-pic");
253254

@@ -686,20 +687,50 @@ fn main() {
686687
let config_mak = source().join("ffbuild/config.mak");
687688
let file = File::open(config_mak).unwrap();
688689
let reader = BufReader::new(file);
689-
let extra_libs = reader
690+
let extra_linker_args = reader
690691
.lines()
691-
.find(|line| line.as_ref().unwrap().starts_with("EXTRALIBS"))
692-
.map(|line| line.unwrap())
693-
.unwrap();
694-
695-
let linker_args = extra_libs.split('=').last().unwrap().split(' ');
696-
let include_libs = linker_args
697-
.filter(|v| v.starts_with("-l"))
698-
.map(|flag| &flag[2..]);
699-
700-
for lib in include_libs {
701-
println!("cargo:rustc-link-lib={}", lib);
702-
}
692+
.filter_map(|line| {
693+
let line = line.as_ref().ok()?;
694+
695+
if line.starts_with("EXTRALIBS") {
696+
Some(
697+
line.split('=')
698+
.last()
699+
.unwrap()
700+
.split(' ')
701+
.map(|s| s.to_string())
702+
.collect::<Vec<_>>(),
703+
)
704+
} else {
705+
None
706+
}
707+
})
708+
.flatten()
709+
.collect::<Vec<_>>();
710+
711+
extra_linker_args
712+
.iter()
713+
.filter(|flag| flag.starts_with("-l"))
714+
.map(|lib| &lib[2..])
715+
.for_each(|lib| println!("cargo:rustc-link-lib={}", lib));
716+
717+
extra_linker_args
718+
.iter()
719+
.filter(|v| v.starts_with("-L"))
720+
.map(|flag| {
721+
let path = &flag[2..];
722+
if path.starts_with('/') {
723+
PathBuf::from(path)
724+
} else {
725+
source().join(path)
726+
}
727+
})
728+
.for_each(|lib_search_path| {
729+
println!(
730+
"cargo:rustc-link-search=native={}",
731+
lib_search_path.to_str().unwrap()
732+
);
733+
})
703734
}
704735

705736
vec![search().join("include")]

0 commit comments

Comments
 (0)