Skip to content

Commit

Permalink
Add workaround for linking against macOS SDK's relocatable dylibs
Browse files Browse the repository at this point in the history
  • Loading branch information
amyspark authored and GStreamer Marge Bot committed Sep 10, 2024
1 parent 5c39500 commit 7eaf47d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ windows = { version = "0.58", features=["Win32_Graphics_Direct3D11",
cocoa = "0.26"
objc = "0.2.7"

[target.'cfg(target_os = "macos")'.build-dependencies]
system-deps = "7"

[package.metadata.system-deps]
"gstreamer-1.0" = "1.14"

[build-dependencies]
gl_generator = { version = "0.14", optional = true }

Expand Down
18 changes: 18 additions & 0 deletions examples/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,22 @@ fn generate_gl_bindings() {}
fn main() {
println!("cargo:rerun-if-changed=build.rs");
generate_gl_bindings();

// https://github.com/rust-lang/cargo/issues/5077#issuecomment-1284482987
#[cfg(all(not(docsrs), target_os = "macos"))]
match system_deps::Config::new().probe() {
Ok(deps) => {
let usr = std::path::Path::new("/usr/lib");
let usr_local = std::path::Path::new("/usr/local/lib");
for dep in deps.all_link_paths() {
if dep != &usr && dep != &usr_local {
println!("cargo:rustc-link-arg=-Wl,-rpath,{:?}", dep.as_os_str());
}
}
}
Err(s) => {
println!("cargo:warning={s}");
std::process::exit(1);
}
}
}
6 changes: 6 additions & 0 deletions tutorials/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ futures = "0.3"
cocoa = "0.26"
objc = "0.2.7"

[target.'cfg(target_os = "macos")'.build-dependencies]
system-deps = "7"

[package.metadata.system-deps]
"gstreamer-1.0" = "1.14"

[[bin]]
name = "basic-tutorial-13"
required-features = ["termion"]
Expand Down
23 changes: 23 additions & 0 deletions tutorials/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#[cfg(docsrs)]
fn main() {} // prevent linking libraries to avoid documentation failure

// https://github.com/rust-lang/cargo/issues/5077#issuecomment-1284482987
#[cfg(not(docsrs))]
fn main() {
#[cfg(target_os = "macos")]
match system_deps::Config::new().probe() {
Ok(deps) => {
let usr = std::path::Path::new("/usr/lib");
let usr_local = std::path::Path::new("/usr/local/lib");
for dep in deps.all_link_paths() {
if dep != &usr && dep != &usr_local {
println!("cargo:rustc-link-arg=-Wl,-rpath,{:?}", dep.as_os_str());
}
}
}
Err(s) => {
println!("cargo:warning={s}");
std::process::exit(1);
}
}
}

0 comments on commit 7eaf47d

Please sign in to comment.