cctbx / cctbx_project

Computational Crystallography Toolbox
https://cci.lbl.gov/docs/cctbx
Other
218 stars 116 forks source link

dyld[38985]: Library not loaded: @rpath/libc++.1.dylib with conda compilers on MacOS Sonoma Arm64 #936

Closed ndevenish closed 11 months ago

ndevenish commented 11 months ago

Using conda compilers on MacOS Sonoma (Arm64 tested) fails. Running on a fresh Sonoma VM with homebrew-python, homebrew-micromamba, and XCode tools installed.

Looks related to https://github.com/cctbx/cctbx_project/commit/aaf3cd44a411b2e99dcf9abeee09a1d2ede49cb9 and known in DIALS for a couple of weeks in https://github.com/dials/dials/issues/2532

As far as I can tell getting the cctbx bootstrap to accept the conda compilers is a little involved, it seems to ignore the usual methods like $CC and $CXX. --use_environment_flags says that it only reads *FLAGS. The simplest way I could remember/work out was:

# Initialise. The defaults fail because python 3.7 is not available on Mac-Arm
python3 bootstrap.py hot update base --use-conda --python 310
# Install the conda compilers. Micromamba because fresh machine and bootstrap doesn't appear to install conda into the conda environment
micromamba install -yp conda_base/ -c conda-forge compilers
# Bootstrap finds the compilers but can't run them as it doesn't set $PATH, so activate environment
micromamba activate conda_base/
# Run the build using these compilers
python3 bootstrap.py build --use-conda conda_base/ --python 310 --config-flags=--use_conda  --config-flags=--compiler=conda

Gives output:

scons: Reading SConscript files ...
Compiler settings:
  CC:  arm64-apple-darwin20.0.0-clang
  CXX: arm64-apple-darwin20.0.0-clang++
dyld[44901]: Library not loaded: @rpath/libc++.1.dylib
  Referenced from: <AA28CC7E-3CF3-383F-9900-490AE972214E> /Users/nickd/dials/dist_cctbx/build/.sconf_temp/conftest_e73942b1e04111dec1918a18e43ee693_0_af8b7a301806feb994af00dcfdbf7c69
  Reason: no LC_RPATH's found
sh: line 1: 44901 Abort trap: 6           .sconf_temp/conftest_e73942b1e04111dec1918a18e43ee693_0_af8b7a301806feb994af00dcfdbf7c69 > ".sconf_temp/conftest_e73942b1e04111dec1918a18e43ee693_0_af8b7a301806feb994af00dcfdbf7c69.out"

If there is a more direct way to use the conda compilers with the plain cctbx bootstrap, I would be happy to learn it.

Edit:

% micromamba list | grep compiler-rt
  compiler-rt                    15.0.7        hf8d1dfb_1               conda-forge
  compiler-rt_osx-arm64          15.0.7        hf8d1dfb_1               conda-forge
bkpoon commented 11 months ago

You probably need the --config-flags="--use_environment_flags" flag for bootstrap.py. When you activate an environment with the conda compilers packages, environment variables are set for the flags and compilers. Those are needed for bootstrap.py to find the conda compilers.

This command works for me on macOS Sonoma 14.1 and Xcode 15.0.1 after activating the environment.

python bootstrap.py build --use-conda --config-flags="--compiler=conda" --config-flags="--use_environment_flags" --nproc=10 
bkpoon commented 11 months ago

Forgot to add that I tested a new environment. The static environments are old and conda may not update the older packages correctly when you add the compiler packages.

bkpoon commented 11 months ago

Use these commands to make a new environment with new versions.

export PY_VER=3.10
conda devenv -n test --file ./modules/cctbx_project/libtbx/auto_build/conda_envs/cctbx.devenv.yml
conda activate test
conda install -y -c conda-forge boost=1.78 compilers
ndevenish commented 11 months ago

Hmm, will have to have a think how to solve this. We don't want the user to have to manually activate the conda environment between bootstrap base update and bootstrap build, it's not very ergonomic.

OTOH it looks like the only missing flags causing this specific problem is the lack of:

export LDFLAGS=-Wl,-rpath,/Users/nickd/dials/dist_cctbx/conda_base/lib

so perhaps we can just insert that in our bootstrap to make it work again like it used to.

ndevenish commented 11 months ago

Going to try working around this problem by always doing--use_environment_flag https://github.com/dials/dials/pull/2546.

Probably the default shouldn't be "broken", but the bootstrap already is (py37) and this set of steps seems to imply that using conda compilers isn't really a directly supported usecase so ¯\(ツ)/¯.