Skip to content

Commit 9e8f0d4

Browse files
authored
Fix static builds (#36)
1 parent 57e7104 commit 9e8f0d4

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ license = "MIT"
99

1010
[dependencies]
1111
ffms2-sys = { path = "./ffms2-sys" }
12-
cfg-if = "1.0"
13-
paste = "1.0"
14-
ffmpeg-the-third = "4.0"
12+
cfg-if = "1.0.4"
13+
paste = "1.0.15"
14+
ffmpeg-the-third = "4.0.1"
1515

1616
[dev-dependencies]
17-
structopt = "0.3"
17+
structopt = "0.3.26"
1818

1919
[workspace]
2020
members = ["ffms2-sys"]

ffms2-sys/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ repository = "https://github.com/rust-av/ffms2-rs"
77
edition = "2021"
88
license = "MIT"
99

10+
[features]
11+
static = []
12+
1013
[build-dependencies]
11-
bindgen = "0.66"
12-
metadeps = "1.1"
14+
bindgen = "0.72.1"
15+
metadeps = "1.1.2"
1316

1417
[package.metadata.pkg-config]
1518
ffms2 = "2.40"

ffms2-sys/build.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ fn format_write(builder: bindgen::Builder) -> String {
1717
}
1818

1919
fn main() {
20+
let use_static = env::var("CARGO_FEATURE_STATIC").is_ok();
21+
2022
// Consider 'FFMS_INCLUDE_DIR' and 'FFMS_LIB_DIR', if pkg-config should not be used.
2123
let headers = env::var("FFMS_INCLUDE_DIR").map(|value| {
2224
// Ensure the include directory is valid
@@ -35,9 +37,10 @@ fn main() {
3537

3638
// Using dynamic library in Windows remains a problem. We have to copy the DLL into a path...
3739
// Problem: If 'FFMS_LIB_DIR' is outside of 'target', it is not considered (https://doc.rust-lang.org/cargo/reference/environment-variables.html).
38-
#[cfg(windows)] {
40+
// Only handle DLL copying for dynamic linking on Windows
41+
#[cfg(windows)]
42+
if !use_static {
3943
let cargo_output_dir = env::var("OUT_DIR").expect("Unable to get OUT_DIR");
40-
// We need to add the file in target/{debug|release as it is included in the PATH: https://doc.rust-lang.org/cargo/reference/environment-variables.html#dynamic-library-paths
4144
let linkable_dll: PathBuf = [cargo_output_dir.as_ref(), "..", "..", "..", "ffms2.dll"].iter().collect();
4245

4346
// Copy the file if it does not exists
@@ -52,7 +55,11 @@ fn main() {
5255
}
5356

5457
// Add the flags for cargo otherwise explicitely added by pkg-config-rs
55-
println!("cargo:rustc-link-lib=dylib=ffms2");
58+
if use_static {
59+
println!("cargo:rustc-link-lib=static=ffms2");
60+
} else {
61+
println!("cargo:rustc-link-lib=dylib=ffms2");
62+
}
5663
println!("cargo:rustc-link-search=native={}", lib_dir.to_string_lossy());
5764

5865
vec![include_dir]

0 commit comments

Comments
 (0)