forked from angelcam/rust-ac-ffmpeg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
105 lines (84 loc) · 2.63 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
use std::{env, path::PathBuf};
use cc::Build;
use pkg_config::Config;
fn main() {
// skip building native resources during docs.rs builds
if std::env::var("DOCS_RS").is_ok() {
return;
}
let mut build = Build::new();
for dir in ffmpeg_include_dirs() {
build.include(dir);
}
build
.file("src/error.c")
.file("src/logger.c")
.file("src/packet.c")
.file("src/time.c")
.file("src/format/demuxer.c")
.file("src/format/io.c")
.file("src/format/muxer.c")
.file("src/format/stream.c")
.file("src/codec/bsf.c")
.file("src/codec/mod.c")
.file("src/codec/frame.c")
.file("src/codec/audio/resampler.c")
.file("src/codec/video/scaler.c")
.compile("ffwrapper");
link_static("ffwrapper");
for dir in ffmpeg_lib_dirs() {
println!("cargo:rustc-link-search=native={}", dir.to_str().unwrap());
}
let ffmpeg_link_mode = lib_mode("ffmpeg");
link("avcodec", ffmpeg_link_mode);
link("avformat", ffmpeg_link_mode);
link("avutil", ffmpeg_link_mode);
link("swresample", ffmpeg_link_mode);
link("swscale", ffmpeg_link_mode);
}
fn ffmpeg_include_dirs() -> Vec<PathBuf> {
if let Ok(dir) = env::var("FFMPEG_INCLUDE_DIR") {
let dir = PathBuf::from(dir);
if dir.is_dir() {
return vec![dir];
}
}
let lib = Config::new()
.cargo_metadata(false)
.env_metadata(false)
.print_system_libs(false)
.print_system_cflags(false)
.probe("libavcodec")
.expect("Unable to find FFmpeg include dir. You can specify it explicitly by setting the FFMPEG_INCLUDE_DIR environment variable.");
lib.include_paths
}
fn ffmpeg_lib_dirs() -> Vec<PathBuf> {
if let Ok(dir) = env::var("FFMPEG_LIB_DIR") {
let dir = PathBuf::from(dir);
if dir.is_dir() {
return vec![dir];
}
}
let lib = Config::new()
.cargo_metadata(false)
.env_metadata(false)
.print_system_libs(false)
.print_system_cflags(false)
.probe("libavcodec")
.expect("Unable to find FFmpeg lib dir. You can specify it explicitly by setting the FFMPEG_LIB_DIR environment variable.");
lib.link_paths
}
fn link_static(lib: &str) {
link(lib, "static")
}
fn link(lib: &str, mode: &str) {
println!("cargo:rustc-link-lib={}={}", mode, lib);
}
fn lib_mode(lib: &str) -> &'static str {
let kind = env::var(&format!("{}_STATIC", lib.to_uppercase()));
match kind.ok().as_deref() {
Some("0") => "dylib",
Some(_) => "static",
None => "dylib",
}
}