-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Naveen <[email protected]>
- Loading branch information
1 parent
9d2bc9d
commit ccb8149
Showing
6 changed files
with
212 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
Index: jni/CMakeLists.txt | ||
<+>UTF-8 | ||
=================================================================== | ||
Description: | ||
We are making the following changes to jni/CMakeLists.txt file to build it on Windows OS | ||
1. Set CXX_COMPILER_VERSION and CMAKE_CXX_FLAGS. | ||
2. Add a new if else case when the CMAKE_SYSTEM_NAME matches Windows and set flags JVM_OS_TYPE, prefix and extension for the target libraries that are built. | ||
3. Replace LIBRARY_OUTPUT_DIRECTORY with RUNTIME_OUTPUT_DIRECTORY, to build the target libraries(opensearchknn_common, opensearchknn_nmslib and opensearchknn_faiss) in the | ||
specified directory at runtime. | ||
4. Comment the TESTS for now because the tests are failing(failing to build jni_tests.exe) if we are building our target libraries as SHARED libraries. | ||
|
||
TODO: Fix the failing JNI TESTS | ||
|
||
=================================================================== | ||
diff --git a/jni/CMakeLists.txt b/jni/CMakeLists.txt | ||
--- a/jni/CMakeLists.txt (revision 78a2b5b2a83db52aded56ab74940a62c94a88b50) | ||
+++ b/jni/CMakeLists.txt (date 1666128659873) | ||
@@ -14,8 +14,10 @@ | ||
set(TARGET_LIB_FAISS opensearchknn_faiss) # faiss JNI | ||
set(TARGET_LIBS "") # Libs to be installed | ||
|
||
+set(CXX_COMPILER_VERSION ${CMAKE_CXX_COMPILER_VERSION}) | ||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD_REQUIRED True) | ||
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive") | ||
|
||
option(CONFIG_FAISS "Configure faiss library build when this is on") | ||
option(CONFIG_NMSLIB "Configure nmslib library build when this is on") | ||
@@ -35,6 +37,11 @@ | ||
elseif(${CMAKE_SYSTEM_NAME} STREQUAL Linux) | ||
set(JVM_OS_TYPE linux) | ||
set(LIB_EXT .so) | ||
+elseif(${CMAKE_SYSTEM_NAME} STREQUAL Windows) | ||
+ set(JVM_OS_TYPE win32) | ||
+ set(LIB_EXT .dll) | ||
+ set(CMAKE_SHARED_LIBRARY_PREFIX "") | ||
+ set(CMAKE_STATIC_LIBRARY_PREFIX "") | ||
else() | ||
message(FATAL_ERROR "Unable to run on system: ${CMAKE_SYSTEM_NAME}") | ||
endif() | ||
@@ -57,7 +64,7 @@ | ||
target_include_directories(${TARGET_LIB_COMMON} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include $ENV{JAVA_HOME}/include $ENV{JAVA_HOME}/include/${JVM_OS_TYPE}) | ||
set_target_properties(${TARGET_LIB_COMMON} PROPERTIES SUFFIX ${LIB_EXT}) | ||
set_target_properties(${TARGET_LIB_COMMON} PROPERTIES POSITION_INDEPENDENT_CODE ON) | ||
-set_target_properties(${TARGET_LIB_COMMON} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/release) | ||
+set_target_properties(${TARGET_LIB_COMMON} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/release) | ||
list(APPEND TARGET_LIBS ${TARGET_LIB_COMMON}) | ||
# ---------------------------------------------------------------------------- | ||
|
||
@@ -79,7 +86,7 @@ | ||
target_include_directories(${TARGET_LIB_NMSLIB} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include $ENV{JAVA_HOME}/include $ENV{JAVA_HOME}/include/${JVM_OS_TYPE} ${CMAKE_CURRENT_SOURCE_DIR}/external/nmslib/similarity_search/include) | ||
set_target_properties(${TARGET_LIB_NMSLIB} PROPERTIES SUFFIX ${LIB_EXT}) | ||
set_target_properties(${TARGET_LIB_NMSLIB} PROPERTIES POSITION_INDEPENDENT_CODE ON) | ||
- set_target_properties(${TARGET_LIB_NMSLIB} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/release) | ||
+ set_target_properties(${TARGET_LIB_NMSLIB} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/release) | ||
|
||
list(APPEND TARGET_LIBS ${TARGET_LIB_NMSLIB}) | ||
endif () | ||
@@ -130,7 +137,7 @@ | ||
target_include_directories(${TARGET_LIB_FAISS} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include $ENV{JAVA_HOME}/include $ENV{JAVA_HOME}/include/${JVM_OS_TYPE} ${CMAKE_CURRENT_SOURCE_DIR}/external/faiss) | ||
set_target_properties(${TARGET_LIB_FAISS} PROPERTIES SUFFIX ${LIB_EXT}) | ||
set_target_properties(${TARGET_LIB_FAISS} PROPERTIES POSITION_INDEPENDENT_CODE ON) | ||
- set_target_properties(${TARGET_LIB_FAISS} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/release) | ||
+ set_target_properties(${TARGET_LIB_FAISS} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/release) | ||
|
||
list(APPEND TARGET_LIBS ${TARGET_LIB_FAISS}) | ||
endif () | ||
@@ -138,51 +145,7 @@ | ||
# --------------------------------------------------------------------------- | ||
|
||
# --------------------------------- TESTS ----------------------------------- | ||
-if (${CONFIG_ALL} STREQUAL ON OR ${CONFIG_TEST} STREQUAL ON) | ||
- # Reference - https://crascit.com/2015/07/25/cmake-gtest/ | ||
- configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt) | ||
- execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" . | ||
- WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/googletest-download" | ||
- ) | ||
- execute_process(COMMAND "${CMAKE_COMMAND}" --build . | ||
- WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/googletest-download" | ||
- ) | ||
- set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) | ||
- | ||
- add_subdirectory("${CMAKE_BINARY_DIR}/googletest-src" | ||
- "${CMAKE_BINARY_DIR}/googletest-build" EXCLUDE_FROM_ALL | ||
- ) | ||
- add_executable( | ||
- jni_test | ||
- tests/faiss_wrapper_test.cpp | ||
- tests/nmslib_wrapper_test.cpp | ||
- tests/test_util.cpp) | ||
- | ||
- target_link_libraries( | ||
- jni_test | ||
- gtest_main | ||
- gmock_main | ||
- faiss | ||
- NonMetricSpaceLib | ||
- OpenMP::OpenMP_CXX | ||
- ${TARGET_LIB_FAISS} | ||
- ${TARGET_LIB_NMSLIB} | ||
- ${TARGET_LIB_COMMON} | ||
- ) | ||
- | ||
- target_include_directories(jni_test PRIVATE | ||
- ${CMAKE_CURRENT_SOURCE_DIR}/tests | ||
- ${CMAKE_CURRENT_SOURCE_DIR}/include | ||
- $ENV{JAVA_HOME}/include | ||
- $ENV{JAVA_HOME}/include/${JVM_OS_TYPE} | ||
- ${CMAKE_CURRENT_SOURCE_DIR}/external/faiss | ||
- ${CMAKE_CURRENT_SOURCE_DIR}/external/nmslib/similarity_search/include | ||
- ${gtest_SOURCE_DIR}/include | ||
- ${gmock_SOURCE_DIR}/include) | ||
|
||
- | ||
- set_target_properties(jni_test PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin) | ||
-endif () | ||
# --------------------------------------------------------------------------- | ||
|
||
# -------------------------------- INSTALL ---------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# | ||
# Copyright OpenSearch Contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
git submodule update --init -- jni/external/nmslib | ||
git submodule update --init -- jni/external/faiss | ||
|
||
git apply patches/windows/CMakeLists.patch --verbose | ||
|
||
# Validating if the CMakeLists patch is applied | ||
echo "Validating if the CMakeLists patch is applied" | ||
type jni/CMakeLists.txt | Select-String "Windows" | ||
|
||
# Replace '_MSC_VER' with '__MINGW32__' | ||
(Get-Content jni/external/faiss/faiss/impl/index_read.cpp).replace('_MSC_VER', '__MINGW32__') | Set-Content jni/external/faiss/faiss/impl/index_read.cpp | ||
(Get-Content jni/external/faiss/faiss/impl/index_write.cpp).replace('_MSC_VER', '__MINGW32__') | Set-Content jni/external/faiss/faiss/impl/index_write.cpp | ||
|
||
# Replace '#include <sys/mman.h>' with | ||
# #ifndef __MINGW32__ | ||
# #include <sys/mman.h> | ||
# #endif | ||
(Get-Content jni/external/faiss/faiss/OnDiskInvertedLists.cpp).replace('#include <sys/mman.h>', "#ifndef __MINGW32__`n#include <sys/mman.h>`n#endif") | Set-Content jni/external/faiss/faiss/OnDiskInvertedLists.cpp |
Binary file not shown.