Skip to content

Conversation

@ozgureyilmaz
Copy link
Contributor

Fix bootstrap build failures on macOS due to DYLD_LIBRARY_PATH conflicts

Previously, the Rust bootstrap process set the DYLD_LIBRARY_PATH environment variable on macOS, sometimes including system paths like /usr/local/lib. Because DYLD_LIBRARY_PATH is searched before the default system library locations and uses stem matching, this could cause the dynamic linker to load incorrect library versions.

A specific example is when a system framework (like ImageIO) depends on a library (like libjpeg) that also exists in /usr/local/lib. The presence of /usr/local/lib in DYLD_LIBRARY_PATH would cause /usr/local/lib/libjpeg.dylib to be loaded instead of the version required by ImageIO, leading to runtime errors (as reported in #139400).

This PR fixes the issue by modifying the dylib_path_var helper function (src/bootstrap/src/utils/shared_helpers.rs) to return "DYLD_FALLBACK_LIBRARY_PATH" instead of "DYLD_LIBRARY_PATH" on Apple platforms. DYLD_FALLBACK_LIBRARY_PATH is searched after the standard system paths, resolving the loading conflict while still allowing the build process to find necessary libraries in bootstrap-specific directories.

Fixes #139400

On macOS, the bootstrap process was setting DYLD_LIBRARY_PATH to include
system paths like /usr/local/lib. This caused issues because DYLD_LIBRARY_PATH
is searched *before* the default system library paths using stem matching,
potentially leading to the wrong version of a library being loaded.
@rustbot
Copy link
Collaborator

rustbot commented Apr 19, 2025

r? @clubby789

rustbot has assigned @clubby789.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Apr 19, 2025
@jieyouxu jieyouxu added the O-macos Operating system: macOS label Apr 20, 2025
@ozgureyilmaz ozgureyilmaz deleted the fix-dyld-path-issue branch April 20, 2025 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-macos Operating system: macOS S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problem building 1.86.0 on Darwin due to problematic usage of DYLD_LIBRARY_PATH in bootstrap

4 participants