google / google/shaderc-rs

dylib not found when running without "cargo run" on macOS Sonoma

Open
#141 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
286
Forks
71
PR merge metrics
No merged PRs in 30d

Description

It looks like macOS Sonoma no longer searches /usr/local/lib by default as a fallback https://developer.apple.com/forums/thread/737920

Setting `DYLD_PRINT_SEARCHING=1` shows dylib resolution

Prior to macOS Sonoma when running my compiled binary directly:

```
dyld[23515]: find path "@rpath/libshaderc_shared.1.dylib"
dyld[23515]: possible path(default fallback): "/usr/local/lib/libshaderc_shared.1.dylib"
dyld[23515]: found: dylib-from-disk: "/usr/local/lib/libshaderc_shared.1.dylib"
```

On macOS Sonoma if using cargo run to start my program:

```
dyld[8143]: find path "@rpath/libshaderc_shared.1.dylib"
dyld[8143]: possible path(DYLD_FRAMEWORK/LIBRARY_FALLBACK_PATH): "<>/target/debug/build/basis-universal-sys-ca27b139e15249c2/out/libshaderc_shared.1.dylib"
...
dyld[8143]: no pseudo-dylibs to search
dyld[8143]: possible path(DYLD_FRAMEWORK/LIBRARY_FALLBACK_PATH): "/usr/local/lib/libshaderc_shared.1.dylib"
dyld[8143]: no pseudo-dylibs to search
dyld[8143]: found: dylib-from-disk: "/usr/local/lib/libshaderc_shared.1.dylib"
```

Note that the path is being set by cargo run https://doc.rust-lang.org/cargo/reference/environment-variables.html#dynamic-library-paths

However, on macOS Sonoma when running my compiled binary directly (not via cargo run)

```
dyld[8135]: find path "@rpath/libshaderc_shared.1.dylib"
dyld[8135]: not found: "@rpath/libshaderc_shared.1.dylib"
```

Adding this in `.cargo/config.toml` allows the binary to resolve the dylib

```
[target.aarch64-apple-darwin]
rustflags = ["-C", "link-arg=-Wl,-rpath,/usr/local/lib"]
```

Unfortunately I'm not sure what the best way forward would be here. Ideally linker flags would not need to be manually added to the project, but on the other hand it's odd to me that a direct path to the install location of the dylib should be specified at build time.

Contributor guide

Open the contributing guide

Research direction

Start with the .cargo/config.toml workaround and compare cargo run with direct execution on macOS Sonoma. Use DYLD_PRINT_SEARCHING=1 to inspect how libshaderc_shared.1.dylib is resolved. Done should provide a project-supported way for compiled binaries to resolve the dylib without requiring per-project linker flags.

Written by the indexing model from the issue text.

Assessment

Tech stack
macos, rust
Domain
build-system, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.