-
Notifications
You must be signed in to change notification settings - Fork 249
Description
The USearch Python package fails to build from source on Termux (Android aarch64 environment) due to a series of cascading issues related to the static linking of its simsimd submodule and discrepancies in compiler handling of C vs. C++ source files. This makes usearch effectively unbuildable from source on this platform without manual intervention.
Environment:
- Operating System: Termux on Android (
aarch64). - Compiler:
clang(default C compiler),clang++(default C++ compiler) as provided by Termux. - Installation Method:
pip install .from a source checkout.
Detailed Issues and Applied Fixes (for successful compilation on Termux):
-
Issue 1: Uninitialized
simsimdSubmodule- Problem: The
usearchproject relies on thesimsimdlibrary, included as a Git submodule. After cloning theUSearchrepository, thesimsimd/submodule directory is initially empty. TheUSearchbuild process attempts to statically linksimsimd's source code, but the required files are missing. - Symptom: Attempts to
import usearchafter a build (which may succeed in creating an incomplete.sodue to lenient linker flags) result inImportError: dlopen failed: cannot locate symbol "simsimd_uses_dynamic_dispatch". This error also manifested differently at earlier stages (e.g.,AttributeErrorif nosimsimdpackage was present). - Fix Applied: Executed
git submodule update --init --recursivewithin theUSearchproject root to populate thesimsimd/directory with its source code. - Recommendation:
setup.pycould perform a check for submodule initialization and provide a clearer error message early in the build process if missing.
- Problem: The
-
Issue 2: C/C++ Compiler Flag Mismatch During Static Linking
- Problem: After
simsimd's source code is present,usearch'ssetup.pyattempts to compilesimsimd/c/lib.c(a C file) as part of theusearch.compiledextension. Thesetup.pypasses globalcompile_argsthat include C++-specific flags, notably-std=c++17. Termux'sclangcompiler (when used for.cfiles) strictly rejects this flag. - Symptom:
error: invalid argument '-std=c++17' not allowed with 'C' - Attempted Elegant Fix (Failed): Adding
-x c++tocompile_argsinsetup.pydid not work assetuptoolsplaced the flag incorrectly in the build command, leading toclang: warning: '-x c++' after last input file has no effect. - Applied Hacky Fix: Renamed
simsimd/c/lib.ctosimsimd/c/lib.cppand updatedsetup.pyto reference the new.cppfilename. This forces the build system to useclang++(the C++ compiler) for this file, making the-std=c++17flag valid and allowing compilation to proceed. - Recommendation:
setup.pyshould use different compiler flags for C and C++ sources or rely on a more robust mechanism to compile C files as C++.
- Problem: After
-
Issue 3: Missing Standard C++ Header in
simsimd.h- Problem: Even after resolving the C/C++ flag issue, the C++ compilation of
simsimd/c/lib.cppfailed due tosimsimd/include/simsimd/simsimd.husinguint64_twithout explicitly including the necessary<cstdint>header. This is a common point of divergence in how compilers implicitly include or rely on system headers. - Symptom:
error: unknown type name 'uint64_t' - Fix Applied: Added
#include <cstdint>tosimsimd/include/simsimd/simsimd.h. - Recommendation: All headers within
simsimdshould explicitly include any standard headers required for the types they define or use.
- Problem: Even after resolving the C/C++ flag issue, the C++ compilation of
Summary of Fixes Applied for a Successful Build on Termux:
To build USearch from source in Termux (aarch64), the following manual steps were required:
- Initialize Submodules:
git submodule update --init --recursive
- Rename C Source to C++:
mv simsimd/c/lib.c simsimd/c/lib.cpp
- Patch
USearch/setup.py: Update thePybind11Extensionsource list from["python/lib.cpp"]to["python/lib.cpp", "simsimd/c/lib.cpp"]. - Patch
USearch/simsimd/include/simsimd/simsimd.h: Add#include <cstdint>near the top of the file, e.g., after existing includes like"spatial.h". - Install
usearch:pip install . --no-build-isolation
These combined steps finally enabled usearch to build and function correctly in the Termux environment.
The issue is for the unum-cloud/usearch repository.