-
Notifications
You must be signed in to change notification settings - Fork 80
Improve VSAG's compatibility with macOS #1439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @stuBirdFly, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the VSAG project's compatibility with macOS, particularly for Apple Silicon. It addresses various build and linking issues specific to the macOS environment, ensuring that the project can be successfully compiled and tested on Apple's hardware. The changes involve adapting build configurations, resolving library dependencies, and updating type usage across the codebase to align with macOS conventions and prevent compilation errors. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This is a comprehensive pull request that significantly improves macOS compatibility for the project. The systematic refactoring from size_t to uint64_t across the codebase is a major step towards better cross-platform type safety and is well-executed. The CMake build system updates and platform-specific API usage for macOS are also appreciated.
I have two main points of feedback on the CMakeLists.txt changes. My primary concern is the introduction of a hard dependency on Homebrew for finding libraries, which could make the build process less portable for developers using other setups. I've also noted a minor issue with a comment in Chinese that could be translated for consistency. Addressing these points would make this excellent contribution even more robust.
CMakeLists.txt
Outdated
| if (APPLE) | ||
| execute_process( | ||
| COMMAND brew --prefix gcc | ||
| OUTPUT_VARIABLE GCC_PREFIX | ||
| OUTPUT_STRIP_TRAILING_WHITESPACE | ||
| ERROR_QUIET | ||
| ) | ||
| if (GCC_PREFIX) | ||
| link_directories(${GCC_PREFIX}/lib/gcc/current) | ||
| message(STATUS "Added gfortran library path: ${GCC_PREFIX}/lib/gcc/current") | ||
| endif() | ||
|
|
||
| execute_process( | ||
| COMMAND brew --prefix libomp | ||
| OUTPUT_VARIABLE OMP_PREFIX | ||
| OUTPUT_STRIP_TRAILING_WHITESPACE | ||
| ERROR_QUIET | ||
| ) | ||
| if (OMP_PREFIX) | ||
| link_directories(${OMP_PREFIX}/lib) | ||
| include_directories(${OMP_PREFIX}/include) | ||
| message(STATUS "Added libomp library path: ${OMP_PREFIX}/lib") | ||
| endif() | ||
|
|
||
| execute_process( | ||
| COMMAND brew --prefix lapack | ||
| OUTPUT_VARIABLE LAPACK_PREFIX | ||
| OUTPUT_STRIP_TRAILING_WHITESPACE | ||
| ERROR_QUIET | ||
| ) | ||
| if (LAPACK_PREFIX) | ||
| link_directories(${LAPACK_PREFIX}/lib) | ||
| include_directories(${LAPACK_PREFIX}/include) | ||
| message(STATUS "Added LAPACK library path: ${LAPACK_PREFIX}/lib") | ||
| endif() | ||
| endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block introduces a hard dependency on Homebrew by using execute_process with brew. This can make the build process brittle for developers who use other package managers (like MacPorts) or have dependencies installed in different locations. Additionally, the use of link_directories is generally discouraged in modern CMake.
A more robust and portable approach would be to use find_package. For example:
find_package(OpenMP)can locatelibomp.find_package(LAPACK)will find theAccelerateframework on macOS, which aligns with the goal stated in the PR description.
This would make the build system more standard and less dependent on a specific local setup.
CMakeLists.txt
Outdated
|
|
||
| vsag_add_exe_linker_flag (-static-libstdc++) | ||
| vsag_add_shared_linker_flag (-static-libstdc++) | ||
| # Apple 平台使用系统 libc++,不要静态链接 libstdc++ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codecov Report❌ Patch coverage is @@ Coverage Diff @@
## main #1439 +/- ##
==========================================
+ Coverage 91.33% 91.35% +0.02%
==========================================
Files 326 326
Lines 19121 19121
==========================================
+ Hits 17464 17468 +4
+ Misses 1657 1653 -4
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
|
|
||
| #ifdef __APPLE__ | ||
| // macOS 没有 mremap,先取消旧映射再重新 mmap | ||
| munmap(this->start_, old_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in English
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
|
|
||
| #[test] | ||
| fn resize_test() { | ||
| fn reuint64_test() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert this change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
| /// Run Lloyds until max_reps or stopping criterion | ||
| /// If you pass NULL for closest_docs and closest_center, it will NOT return | ||
| /// the results, else it will assume appropriate allocation as closest_docs = | ||
| /// new vec<usize> [num_centers], and closest_center = new size_t[num_points] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert this change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
| } | ||
|
|
||
| float distance_compare_avx512f_f16(const unsigned char *vec1, const unsigned char *vec2, size_t size) | ||
| float distance_compare_avx512f_f16(const unsigned char *vec1, const unsigned char *vec2, uint64_t size) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert changes in this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
| : BaseSearch(tagsFile) | ||
| { | ||
| size_t dimensions, total_points = 0; | ||
| uint64_t dimensions, total_points = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert changes in the restapi/ directory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing the type will cause a build failure.
| auto best_tags = results[0].tags_enabled() ? new std::string[K] : nullptr; | ||
|
|
||
| auto numsearchers = _multi_searcher.size(); | ||
| std::vector<size_t> pos(numsearchers, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert changes in the restapi/ directory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/storage/stream_reader.h
Outdated
| private: | ||
| StreamReader* const reader_impl_{nullptr}; | ||
| vsag::Allocator* allocator_; | ||
| char* buffer_{nullptr}; // Stores the cached content |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
align the comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
| target_link_libraries (unittests | ||
| PRIVATE | ||
| Catch2::Catch2 | ||
| "-Wl,--whole-archive" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this may cause the unittests file to be large?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mainly because macOS doesn't support --whole-archive.
| // limitations under the License. | ||
|
|
||
| #include <fmt/format-inl.h> | ||
| #include <fmt/format.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the reason to use the header file fmt/format.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The macOS linker is stricter—inline functions included in multiple .cpp files will cause duplicate symbol errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
CMakeLists.txt
Outdated
|
|
||
| vsag_add_exe_linker_flag (-static-libstdc++) | ||
| vsag_add_shared_linker_flag (-static-libstdc++) | ||
| # Apple 平台使用系统 libc++,不要静态链接 libstdc++ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment in English
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
CMakeLists.txt
Outdated
| # Add gfortran, OpenMP, and LAPACK library paths for macOS | ||
| if (APPLE) | ||
| execute_process( | ||
| COMMAND brew --prefix gcc | ||
| OUTPUT_VARIABLE GCC_PREFIX | ||
| OUTPUT_STRIP_TRAILING_WHITESPACE | ||
| ERROR_QUIET | ||
| ) | ||
| if (GCC_PREFIX) | ||
| link_directories(${GCC_PREFIX}/lib/gcc/current) | ||
| message(STATUS "Added gfortran library path: ${GCC_PREFIX}/lib/gcc/current") | ||
| endif() | ||
|
|
||
| execute_process( | ||
| COMMAND brew --prefix libomp | ||
| OUTPUT_VARIABLE OMP_PREFIX | ||
| OUTPUT_STRIP_TRAILING_WHITESPACE | ||
| ERROR_QUIET | ||
| ) | ||
| if (OMP_PREFIX) | ||
| link_directories(${OMP_PREFIX}/lib) | ||
| include_directories(${OMP_PREFIX}/include) | ||
| message(STATUS "Added libomp library path: ${OMP_PREFIX}/lib") | ||
| endif() | ||
|
|
||
| execute_process( | ||
| COMMAND brew --prefix lapack | ||
| OUTPUT_VARIABLE LAPACK_PREFIX | ||
| OUTPUT_STRIP_TRAILING_WHITESPACE | ||
| ERROR_QUIET | ||
| ) | ||
| if (LAPACK_PREFIX) | ||
| link_directories(${LAPACK_PREFIX}/lib) | ||
| include_directories(${LAPACK_PREFIX}/include) | ||
| message(STATUS "Added LAPACK library path: ${LAPACK_PREFIX}/lib") | ||
| endif() | ||
| endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this part should move to cmake/ directory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
|
@stuBirdFly please follow this guide to fix the DCO check error: https://github.com/antgroup/vsag/blob/main/CONTRIBUTING.md#developer-certificate-of-origin-dco |
a0a21cb to
76f0d62
Compare
Signed-off-by: stuBirdFly <[email protected]>
Signed-off-by: stuBirdFly <[email protected]>
This MR introduces comprehensive macOS compatibility to the vsag project, enabling successful builds and tests on Apple Silicon (arm64) Macs.
🔧 Key Changes:
Fixed linker issues:
Replaced Linux-specific --whole-archive with macOS-compatible -force_load (or removed where unnecessary).
Resolved duplicate symbol errors from fmt by ensuring consistent static-library usage (removed accidental header-only instantiations).
Resolved missing LAPACKE dependency:
On macOS, linked against the system-provided Accelerate framework instead of liblapacke, which is not available by default.
Updated CMake logic to auto-select Accelerate on APPLE.
Improved compiler detection:
Updated Clang detection to include AppleClang (CMake ID is AppleClang, not Clang).
Ensured correct debug flags (-gdwarf-4) and warning suppressions work on both LLVM Clang and Apple Clang.
Fixed ExternalProject integration:
Adjusted HDF5 and other dependencies to avoid premature include_directories/link_directories that cause “search path not found” warnings on macOS.
Cleaned up duplicate library linking:
Removed redundant static library references (e.g., fmt, roaring, io) to eliminate linker warnings.