compilers/apple: detect Homebrew prefix dynamically #15228
Closed
+60
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix hardcoded Homebrew prefix in Apple compiler OpenMP detection
Summary
Dynamically detects the Homebrew prefix by calling
brew --prefixinstead of hardcoding/usr/localor/opt/homebrewbased on CPU architecture. This allows Meson to work correctly regardless of where Homebrew is installed.Fixes #15191
Changes
mesonbuild/environment.py: Addedget_homebrew_prefix()method that:brew --prefixto detect the actual Homebrew installation locationNonegracefully if Homebrew is not installed or detection failsmesonbuild/compilers/mixins/apple.py: Modifiedopenmp_flags()andopenmp_link_flags()to:env.get_homebrew_prefix()to get the Homebrew prefix dynamically/usr/localfor x86,/opt/homebrewfor ARM) if detection failsBackward Compatibility
The implementation maintains full backward compatibility by falling back to the previous hardcoded behavior when:
brewcommand is not in PATHbrew --prefixfails for any reasonTesting
python3 -m py_compile