Skip to content

Commit 43b0f4e

Browse files
amysparkBackport Bot
authored and
Backport Bot
committed
Add workaround for linking against macOS SDK's relocatable dylibs
See rust-lang/cargo#5077 (comment) and rust-lang/rust#127100 Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1538>
1 parent a369f9e commit 43b0f4e

File tree

5 files changed

+55
-0
lines changed

5 files changed

+55
-0
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ windows = { version = "0.58", features=["Win32_Graphics_Direct3D11",
5656
cocoa = "0.25"
5757
objc = "0.2.7"
5858

59+
[target.'cfg(target_os = "macos")'.build-dependencies]
60+
system-deps = "7"
61+
62+
[package.metadata.system-deps]
63+
"gstreamer-1.0" = "1.14"
64+
5965
[build-dependencies]
6066
gl_generator = { version = "0.14", optional = true }
6167

examples/build.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,22 @@ fn generate_gl_bindings() {}
1919
fn main() {
2020
println!("cargo:rerun-if-changed=build.rs");
2121
generate_gl_bindings();
22+
23+
// https://github.com/rust-lang/cargo/issues/5077#issuecomment-1284482987
24+
#[cfg(all(not(docsrs), target_os = "macos"))]
25+
match system_deps::Config::new().probe() {
26+
Ok(deps) => {
27+
let usr = std::path::Path::new("/usr/lib");
28+
let usr_local = std::path::Path::new("/usr/local/lib");
29+
for dep in deps.all_link_paths() {
30+
if dep != &usr && dep != &usr_local {
31+
println!("cargo:rustc-link-arg=-Wl,-rpath,{:?}", dep.as_os_str());
32+
}
33+
}
34+
}
35+
Err(s) => {
36+
println!("cargo:warning={s}");
37+
std::process::exit(1);
38+
}
39+
}
2240
}

tutorials/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ futures = "0.3"
2323
cocoa = "0.25"
2424
objc = "0.2.7"
2525

26+
[target.'cfg(target_os = "macos")'.build-dependencies]
27+
system-deps = "7"
28+
29+
[package.metadata.system-deps]
30+
"gstreamer-1.0" = "1.14"
31+
2632
[[bin]]
2733
name = "basic-tutorial-13"
2834
required-features = ["termion"]

tutorials/build.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#[cfg(docsrs)]
2+
fn main() {} // prevent linking libraries to avoid documentation failure
3+
4+
// https://github.com/rust-lang/cargo/issues/5077#issuecomment-1284482987
5+
#[cfg(not(docsrs))]
6+
fn main() {
7+
#[cfg(target_os = "macos")]
8+
match system_deps::Config::new().probe() {
9+
Ok(deps) => {
10+
let usr = std::path::Path::new("/usr/lib");
11+
let usr_local = std::path::Path::new("/usr/local/lib");
12+
for dep in deps.all_link_paths() {
13+
if dep != &usr && dep != &usr_local {
14+
println!("cargo:rustc-link-arg=-Wl,-rpath,{:?}", dep.as_os_str());
15+
}
16+
}
17+
}
18+
Err(s) => {
19+
println!("cargo:warning={s}");
20+
std::process::exit(1);
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)