Skip to content

Commit 8374b8f

Browse files
Fix build for macos (#2397)
* fix paths for libomp on newer homebrew versions auto load java home path on macos update to latest nmslib revision Signed-off-by: Samuel Herman <[email protected]> * make it work for x86_64 mac as well Signed-off-by: Samuel Herman <[email protected]> * remove commented code Signed-off-by: Samuel Herman <[email protected]> * review comments Signed-off-by: Samuel Herman <[email protected]> --------- Signed-off-by: Samuel Herman <[email protected]> Signed-off-by: sam-herman <[email protected]> Co-authored-by: Samuel Herman <[email protected]>
1 parent eecb45c commit 8374b8f

File tree

4 files changed

+53
-10
lines changed

4 files changed

+53
-10
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2626
- Add check to directly use ANN Search when filters match all docs. (#2320)[https://github.com/opensearch-project/k-NN/pull/2320]
2727
- Use one formula to calculate cosine similarity (#2357)[https://github.com/opensearch-project/k-NN/pull/2357]
2828
- Add WithFieldName implementation to KNNQueryBuilder (#2398)[https://github.com/opensearch-project/k-NN/pull/2398]
29+
- Make the build work for M series MacOS without manual code changes and local JAVA_HOME config (#2397)[https://github.com/opensearch-project/k-NN/pull/2397]
2930
### Bug Fixes
3031
* Fixing the bug when a segment has no vector field present for disk based vector search (#2282)[https://github.com/opensearch-project/k-NN/pull/2282]
3132
* Fixing the bug where search fails with "fields" parameter for an index with a knn_vector field (#2314)[https://github.com/opensearch-project/k-NN/pull/2314]

DEVELOPER_GUIDE.md

+15
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,21 @@ export OPENSEARCH_HOME=the directory of opensearch...
143143
export JAVA_LIBRARY_PATH=$JAVA_LIBRARY_PATH:$OPENSEARCH_HOME/plugins/opensearch-knn/lib
144144
```
145145
146+
CMAKE will use as JAVA_HOME environment whatever your gradle is currently using. For example:
147+
```bash
148+
Java home directory found by gradle: /opt/homebrew/Cellar/openjdk@21/21.0.5/libexec/openjdk.jdk/Contents/Home
149+
=======================================
150+
OpenSearch Build Hamster says Hello!
151+
Gradle Version : 8.4
152+
OS Info : Mac OS X 14.4 (aarch64)
153+
JDK Version : 21 (Homebrew JDK)
154+
JAVA_HOME : /opt/homebrew/Cellar/openjdk@21/21.0.5/libexec/openjdk.jdk/Contents/Home
155+
Random Testing Seed : 8AB32A4719AA345E
156+
In FIPS 140 mode : false
157+
=======================================
158+
```
159+
The JAVA_HOME used by gradle will be the default that the project will be using.
160+
146161
#### Environment
147162
148163
Currently, the plugin only supports Linux on x64 and arm platforms.

build.gradle

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
7+
import org.gradle.internal.jvm.Jvm
68
import org.opensearch.gradle.test.RestIntegTestTask
79
import org.opensearch.gradle.testclusters.OpenSearchCluster
810
import org.apache.tools.ant.taskdefs.condition.Os
@@ -336,13 +338,19 @@ task cmakeJniLib(type:Exec) {
336338
args.add("-DAVX512_ENABLED=${avx512_enabled}")
337339
args.add("-DCOMMIT_LIB_PATCHES=${commit_lib_patches}")
338340
args.add("-DAPPLY_LIB_PATCHES=${apply_lib_patches}")
341+
def javaHome = Jvm.current().getJavaHome()
342+
logger.lifecycle("Java home directory used by gradle: $javaHome")
343+
if (Os.isFamily(Os.FAMILY_MAC)) {
344+
environment('JAVA_HOME',javaHome)
345+
}
339346
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
340347
dependsOn windowsPatches
341348
args.add("-G")
342349
args.add("Unix Makefiles")
343350
args.add("-DBLAS_LIBRARIES=$rootDir\\src\\main\\resources\\windowsDependencies\\libopenblas.dll")
344351
args.add("-DLAPACK_LIBRARIES=$rootDir\\src\\main\\resources\\windowsDependencies\\libopenblas.dll")
345352
}
353+
346354
commandLine args
347355
}
348356

jni/cmake/init-faiss.cmake

+29-10
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,37 @@ if(NOT DEFINED APPLY_LIB_PATCHES OR "${APPLY_LIB_PATCHES}" STREQUAL true)
5454
endforeach()
5555
endif()
5656

57-
if (${CMAKE_SYSTEM_NAME} STREQUAL Darwin)
58-
if(CMAKE_C_COMPILER_ID MATCHES "Clang\$")
59-
set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp")
60-
set(OpenMP_C_LIB_NAMES "omp")
61-
set(OpenMP_omp_LIBRARY /usr/local/opt/libomp/lib/libomp.dylib)
62-
endif()
57+
if (APPLE)
58+
message(STATUS "darwin macos detected")
59+
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
60+
message(STATUS "detected Mac with ARM architecture")
61+
if(CMAKE_C_COMPILER_ID MATCHES "Clang\$")
62+
set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp")
63+
set(OpenMP_C_LIB_NAMES "omp")
64+
set(OpenMP_omp_LIBRARY /opt/homebrew/opt/libomp/lib/libomp.dylib)
65+
endif()
66+
67+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang\$")
68+
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I/opt/homebrew/opt/libomp/include")
69+
set(OpenMP_CXX_LIB_NAMES "omp")
70+
set(OpenMP_omp_LIBRARY /opt/homebrew/opt/libomp/lib/libomp.dylib)
71+
endif()
72+
else()
73+
message(STATUS "detected Mac with x86 architecture")
74+
if(CMAKE_C_COMPILER_ID MATCHES "Clang\$")
75+
set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp")
76+
set(OpenMP_C_LIB_NAMES "omp")
77+
set(OpenMP_omp_LIBRARY /usr/local/opt/libomp/lib/libomp.dylib)
78+
endif()
6379

64-
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang\$")
65-
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I/usr/local/opt/libomp/include")
66-
set(OpenMP_CXX_LIB_NAMES "omp")
67-
set(OpenMP_omp_LIBRARY /usr/local/opt/libomp/lib/libomp.dylib)
80+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang\$")
81+
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I/usr/local/opt/libomp/include")
82+
set(OpenMP_CXX_LIB_NAMES "omp")
83+
set(OpenMP_omp_LIBRARY /usr/local/opt/libomp/lib/libomp.dylib)
84+
endif()
6885
endif()
86+
87+
6988
endif()
7089

7190
find_package(ZLIB REQUIRED)

0 commit comments

Comments
 (0)