diff --git a/CHANGELOG.md b/CHANGELOG.md index 03a757acd..81d4e7bb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Add check to directly use ANN Search when filters match all docs. (#2320)[https://github.com/opensearch-project/k-NN/pull/2320] - Use one formula to calculate cosine similarity (#2357)[https://github.com/opensearch-project/k-NN/pull/2357] - Add WithFieldName implementation to KNNQueryBuilder (#2398)[https://github.com/opensearch-project/k-NN/pull/2398] +- 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] ### Bug Fixes * 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] * 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] diff --git a/DEVELOPER_GUIDE.md b/DEVELOPER_GUIDE.md index 9a6a375c1..7ea8d26de 100644 --- a/DEVELOPER_GUIDE.md +++ b/DEVELOPER_GUIDE.md @@ -143,6 +143,21 @@ export OPENSEARCH_HOME=the directory of opensearch... export JAVA_LIBRARY_PATH=$JAVA_LIBRARY_PATH:$OPENSEARCH_HOME/plugins/opensearch-knn/lib ``` +CMAKE will use as JAVA_HOME environment whatever your gradle is currently using. For example: +```bash +Java home directory found by gradle: /opt/homebrew/Cellar/openjdk@21/21.0.5/libexec/openjdk.jdk/Contents/Home +======================================= +OpenSearch Build Hamster says Hello! + Gradle Version : 8.4 + OS Info : Mac OS X 14.4 (aarch64) + JDK Version : 21 (Homebrew JDK) + JAVA_HOME : /opt/homebrew/Cellar/openjdk@21/21.0.5/libexec/openjdk.jdk/Contents/Home + Random Testing Seed : 8AB32A4719AA345E + In FIPS 140 mode : false +======================================= +``` +The JAVA_HOME used by gradle will be the default that the project will be using. + #### Environment Currently, the plugin only supports Linux on x64 and arm platforms. diff --git a/build.gradle b/build.gradle index 063016d82..72d66abad 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ + +import org.gradle.internal.jvm.Jvm import org.opensearch.gradle.test.RestIntegTestTask import org.opensearch.gradle.testclusters.OpenSearchCluster import org.apache.tools.ant.taskdefs.condition.Os @@ -336,6 +338,11 @@ task cmakeJniLib(type:Exec) { args.add("-DAVX512_ENABLED=${avx512_enabled}") args.add("-DCOMMIT_LIB_PATCHES=${commit_lib_patches}") args.add("-DAPPLY_LIB_PATCHES=${apply_lib_patches}") + def javaHome = Jvm.current().getJavaHome() + logger.lifecycle("Java home directory used by gradle: $javaHome") + if (Os.isFamily(Os.FAMILY_MAC)) { + environment('JAVA_HOME',javaHome) + } if (Os.isFamily(Os.FAMILY_WINDOWS)) { dependsOn windowsPatches args.add("-G") @@ -343,6 +350,7 @@ task cmakeJniLib(type:Exec) { args.add("-DBLAS_LIBRARIES=$rootDir\\src\\main\\resources\\windowsDependencies\\libopenblas.dll") args.add("-DLAPACK_LIBRARIES=$rootDir\\src\\main\\resources\\windowsDependencies\\libopenblas.dll") } + commandLine args } diff --git a/jni/cmake/init-faiss.cmake b/jni/cmake/init-faiss.cmake index 4492d9f45..8243c26aa 100644 --- a/jni/cmake/init-faiss.cmake +++ b/jni/cmake/init-faiss.cmake @@ -54,18 +54,37 @@ if(NOT DEFINED APPLY_LIB_PATCHES OR "${APPLY_LIB_PATCHES}" STREQUAL true) endforeach() endif() -if (${CMAKE_SYSTEM_NAME} STREQUAL Darwin) - if(CMAKE_C_COMPILER_ID MATCHES "Clang\$") - set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp") - set(OpenMP_C_LIB_NAMES "omp") - set(OpenMP_omp_LIBRARY /usr/local/opt/libomp/lib/libomp.dylib) - endif() +if (APPLE) + message(STATUS "darwin macos detected") + if(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64") + message(STATUS "detected Mac with ARM architecture") + if(CMAKE_C_COMPILER_ID MATCHES "Clang\$") + set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp") + set(OpenMP_C_LIB_NAMES "omp") + set(OpenMP_omp_LIBRARY /opt/homebrew/opt/libomp/lib/libomp.dylib) + endif() + + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang\$") + set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I/opt/homebrew/opt/libomp/include") + set(OpenMP_CXX_LIB_NAMES "omp") + set(OpenMP_omp_LIBRARY /opt/homebrew/opt/libomp/lib/libomp.dylib) + endif() + else() + message(STATUS "detected Mac with x86 architecture") + if(CMAKE_C_COMPILER_ID MATCHES "Clang\$") + set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp") + set(OpenMP_C_LIB_NAMES "omp") + set(OpenMP_omp_LIBRARY /usr/local/opt/libomp/lib/libomp.dylib) + endif() - if(CMAKE_CXX_COMPILER_ID MATCHES "Clang\$") - set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I/usr/local/opt/libomp/include") - set(OpenMP_CXX_LIB_NAMES "omp") - set(OpenMP_omp_LIBRARY /usr/local/opt/libomp/lib/libomp.dylib) + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang\$") + set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I/usr/local/opt/libomp/include") + set(OpenMP_CXX_LIB_NAMES "omp") + set(OpenMP_omp_LIBRARY /usr/local/opt/libomp/lib/libomp.dylib) + endif() endif() + + endif() find_package(ZLIB REQUIRED)