Mac with latest clang 17 breaks library
For myself and team xcode updating the system to clang 17 breaks this library. These warnings appear during the build. You then get no results and/or incorrect results when searching.
... running bdist_wheel running build running build_py creating build/lib.macosx-15.2-arm64-cpython-311/annoy copying annoy/init.py -> build/lib.macosx-15.2-arm64-cpython-311/annoy copying annoy/init.pyi -> build/lib.macosx-15.2-arm64-cpython-311/annoy copying annoy/py.typed -> build/lib.macosx-15.2-arm64-cpython-311/annoy running build_ext building 'annoy.annoylib' extension creating build/temp.macosx-15.2-arm64-cpython-311/src clang++ -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Users/omitted/.pyenv/versions/3.11.9/envs/omitted/include -I/Users/omitted/.pyenv/versions/3.11.9/include/python3.11 -c src/annoymodule.cc -o build/temp.macosx-15.2-arm64-cpython-311/src/annoymodule.o -D_CRT_SECURE_NO_WARNINGS -fpermissive -O3 -ffast-math -fno-associative-math -DANNOYLIB_MULTITHREADED_BUILD -std=c++14 -mmacosx-version-min=10.12 In file included from src/annoymodule.cc:15: src/annoylib.h:512:12: warning: use of infinity is undefined behavior due to the currently enabled floating-point options [-Wnan-infinity-disabled] 512 | return numeric_limits::infinity(); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/annoylib.h:1378:43: note: in instantiation of function template specialization 'Annoy::Angular::pq_initial_value' requested here 1378 | q.push(make_pair(Distance::template pq_initial_value(), _roots[i])); | ^ src/annoylib.h:1149:5: note: in instantiation of member function 'Annoy::AnnoyIndex<int, float, Annoy::Angular, Annoy::Kiss64Random, Annoy::AnnoyIndexMultiThreadedBuildPolicy>::_get_all_nns' requested here 1149 | _get_all_nns(m->v, n, search_k, result, distances); | ^ src/annoylib.h:888:4: note: in instantiation of member function 'Annoy::AnnoyIndex<int, float, Annoy::Angular, Annoy::Kiss64Random, Annoy::AnnoyIndexMultiThreadedBuildPolicy>::get_nns_by_item' requested here 888 | AnnoyIndex(int f) : _f(f), _seed(Random::default_seed) { | ^ src/annoymodule.cc:155:21: note: in instantiation of member function 'Annoy::AnnoyIndex<int, float, Annoy::Angular, Annoy::Kiss64Random, Annoy::AnnoyIndexMultiThreadedBuildPolicy>::AnnoyIndex' requested here 155 | self->ptr = new AnnoyIndex<int32_t, float, Angular, Kiss64Random, AnnoyIndexThreadedBuildPolicy>(self->f); | ^ In file included from src/annoymodule.cc:15: src/annoylib.h:759:12: warning: use of infinity is undefined behavior due to the currently enabled floating-point options [-Wnan-infinity-disabled] 759 | return numeric_limits::infinity(); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/annoylib.h:1378:43: note: in instantiation of function template specialization 'Annoy::Minkowski::pq_initial_value' requested here 1378 | q.push(make_pair(Distance::template pq_initial_value(), _roots[i])); | ^ src/annoylib.h:1149:5: note: in instantiation of member function 'Annoy::AnnoyIndex<int, float, Annoy::Euclidean, Annoy::Kiss64Random, Annoy::AnnoyIndexMultiThreadedBuildPolicy>::_get_all_nns' requested here 1149 | _get_all_nns(m->v, n, search_k, result, distances); | ^ src/annoylib.h:888:4: note: in instantiation of member function 'Annoy::AnnoyIndex<int, float, Annoy::Euclidean, Annoy::Kiss64Random, Annoy::AnnoyIndexMultiThreadedBuildPolicy>::get_nns_by_item' requested here 888 | AnnoyIndex(int f) : _f(f), _seed(Random::default_seed) { | ^ src/annoymodule.cc:159:21: note: in instantiation of member function 'Annoy::AnnoyIndex<int, float, Annoy::Euclidean, Annoy::Kiss64Random, Annoy::AnnoyIndexMultiThreadedBuildPolicy>::AnnoyIndex' requested here 159 | self->ptr = new AnnoyIndex<int32_t, float, Euclidean, Kiss64Random, AnnoyIndexThreadedBuildPolicy>(self->f); | ^ 2 warnings generated. ...
If you force the wheel to build with clang 16 then the errors go away and everything works as expected:
brew install llvm@16
export CC=/opt/homebrew/opt/llvm@16/bin/clang && export CXX=/opt/homebrew/opt/llvm@16/bin/clang++ && export CPPFLAGS="-I/opt/homebrew/opt/llvm@16/include" && export LDFLAGS="-L/opt/homebrew/opt/llvm@16/lib"
python3 -m pip cache remove annoy
python3 -m pip install "annoy == 1.17.3" --verbose
Source: spotify/annoy