mesonbuild / meson-python

Meson PEP 517 Python build backend
https://mesonbuild.com/meson-python/
MIT License
126 stars 65 forks source link

on Mac, homebrew boost not found #462

Closed robtaylor closed 11 months ago

robtaylor commented 1 year ago

(on a Mac M2) When building outside of meson-python, meson build happily finds homebrew boost:

Checking potential boost root /Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/usr/include/c++
Checking potential boost root /Library/Developer/CommandLineTools/usr/lib/clang/14.0.3
Checking potential boost root /Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/usr
Checking potential boost root /Library/Developer/CommandLineTools/usr
Checking potential boost root /opt/homebrew/Cellar/boost/1.82.0_1
  - potential library dirs: ['/opt/homebrew/Cellar/boost/1.82.0_1/lib']
  - potential include dirs: ['/opt/homebrew/Cellar/boost/1.82.0_1/include']
  - found boost library dir: /opt/homebrew/Cellar/boost/1.82.0_1/lib
  - found boost 1.82.0 include dir: /opt/homebrew/Cellar/boost/1.82.0_1/include

However, inside meson-python, it is not found:

Checking potential boost root /Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/usr/include/c++
Checking potential boost root /Library/Developer/CommandLineTools/usr/lib/clang/14.0.3
Checking potential boost root /Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/usr
Checking potential boost root /Library/Developer/CommandLineTools/usr
Checking potential boost root /usr/local
Checking potential boost root /usr
Run-time dependency Boost found: NO (tried system)

Any ideas what could be causing this?

dnicolodi commented 1 year ago

I don't think that meson-python is doing anything that could affect the boost dependency lookup. Are the meson version used in the two cases exactly the same? If you build with the default pip or build settings, the build happens in an isolated environment where the most recent version of meson (unless pinned by other components) is installed. This may be a different version that the one installed on the system.

To further debug this we would need to look at the meson detailed log for the working and not working case. Meson prints the location of the log file after the error message. To access the log file when using meson-python and building with pip or build you need to explicitly specify a build directory adding -Cbuilddir=something to the command line.

dnicolodi commented 1 year ago

Also, is this a public project that I can use to try to replicate the issue?

robtaylor commented 1 year ago

yep, same version of meson. However it seems homebrew tweaks boost.py for meson:

https://github.com/Homebrew/homebrew-core/blob/9f3bb46766f10551a1e2c8b47af16c3cb91a7c95/Formula/m/meson.rb#L30

Not sure what a good fix for this is :/

dnicolodi commented 1 year ago

You can disable isolated builds, passing the --no-build-isolation command line option to pip. In this way the system meson is used, but you need to install all other build dependencies for the system python. There may be other tricks you can play with environment variables to have meson look for boost in the right place. The only proper fix is to have Homebrew submit their patches upstream.

dnicolodi commented 1 year ago

Looking at this a bit more in detail, it seems that the issue should manifest only with an non-standard HOMEBREW_PREFIX, ie with boost installed somewhere else than in /usr/local/. Can you confirm?

robtaylor commented 1 year ago

On m1/2 brew installs in /opt/homebrew

I’m prepping a patch for meson to also search here if HOMEBREW_PREFIX is set

On Tue, 29 Aug 2023 at 16:04, Daniele Nicolodi @.***> wrote:

Looking at this a bit more in detail, it seems that the issue should manifest only with an non-standard HOMEBREW_PREFIX, ie with boost installed somewhere else than in /usr/local/. Can you confirm?

— Reply to this email directly, view it on GitHub https://github.com/mesonbuild/meson-python/issues/462#issuecomment-1697623783, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAB4O4F7SIFYQZDB2V5QQX3XXYAGRANCNFSM6AAAAAA4CZ6YTQ . You are receiving this because you authored the thread.Message ID: @.***>

dnicolodi commented 1 year ago

On m1/2 brew installs in /opt/homebrew

Interesting. Did the default change for the arm macs or on more recent macOS releases? On the intel macs the default location is /usr/local.

I’m prepping a patch for meson to also search here if HOMEBREW_PREFIX is set

This is most likely the best solution.

robtaylor commented 1 year ago

It came in for M1s, not sure if its now default for all archs.

robtaylor commented 1 year ago

https://github.com/mesonbuild/meson/pull/12170