Skip to content

Commit 73c953a

Browse files
committed
Add flag for whether patches should be committed
Signed-off-by: John Mazanec <jmazane@amazon.com>
1 parent c35f6ad commit 73c953a

9 files changed

+40
-53
lines changed

.github/workflows/CI.yml

+5-23
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ jobs:
3838
with:
3939
submodules: true
4040

41-
# Setup git user so that patches for native libraries can be applied and committed
42-
- name: Setup git user
43-
run: |
44-
su `id -un 1000` -c 'git config --global user.name "github-actions[bot]"'
45-
su `id -un 1000` -c 'git config --global user.email "github-actions[bot]@users.noreply.github.com"'
46-
4741
- name: Setup Java ${{ matrix.java }}
4842
uses: actions/setup-java@v1
4943
with:
@@ -56,10 +50,10 @@ jobs:
5650
if lscpu | grep -i avx2
5751
then
5852
echo "avx2 available on system"
59-
su `id -un 1000` -c "whoami && java -version && ./gradlew build"
53+
su `id -un 1000` -c "whoami && java -version && ./gradlew build -Dbuild.lib.commit_patches=false"
6054
else
6155
echo "avx2 not available on system"
62-
su `id -un 1000` -c "whoami && java -version && ./gradlew build -Dsimd.enabled=false"
56+
su `id -un 1000` -c "whoami && java -version && ./gradlew build -Dsimd.enabled=false -Dbuild.lib.commit_patches=false"
6357
fi
6458
6559
@@ -81,12 +75,6 @@ jobs:
8175
- name: Checkout k-NN
8276
uses: actions/checkout@v1
8377

84-
# Setup git user so that patches for native libraries can be applied and committed
85-
- name: Setup git user
86-
run: |
87-
git config --global user.name "github-actions[bot]"
88-
git config --global user.email "github-actions[bot]@users.noreply.github.com"
89-
9078
- name: Setup Java ${{ matrix.java }}
9179
uses: actions/setup-java@v1
9280
with:
@@ -102,10 +90,10 @@ jobs:
10290
if sysctl -n machdep.cpu.features machdep.cpu.leaf7_features | grep -i AVX2
10391
then
10492
echo "avx2 available on system"
105-
./gradlew build
93+
./gradlew build -Dbuild.lib.commit_patches=false
10694
else
10795
echo "avx2 not available on system"
108-
./gradlew build -Dsimd.enabled=false
96+
./gradlew build -Dsimd.enabled=false -Dbuild.lib.commit_patches=false
10997
fi
11098
11199
Build-k-NN-Windows:
@@ -121,12 +109,6 @@ jobs:
121109
- name: Checkout k-NN
122110
uses: actions/checkout@v1
123111

124-
# Setup git user so that patches for native libraries can be applied and committed
125-
- name: Setup git user
126-
run: |
127-
git config --global user.name "github-actions[bot]"
128-
git config --global user.email "github-actions[bot]@users.noreply.github.com"
129-
130112
- name: Setup Java ${{ matrix.java }}
131113
uses: actions/setup-java@v1
132114
with:
@@ -165,5 +147,5 @@ jobs:
165147
166148
- name: Run build
167149
run: |
168-
./gradlew.bat build -D'simd.enabled=false'
150+
./gradlew.bat build -D'simd.enabled=false' -D'build.lib.commit_patches=false'
169151

.github/workflows/backwards_compatibility_tests_workflow.yml

+4-16
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ jobs:
3636
- name: Checkout k-NN
3737
uses: actions/checkout@v1
3838

39-
# Setup git user so that patches for native libraries can be applied and committed
40-
- name: Setup git user
41-
run: |
42-
git config --global user.name "github-actions[bot]"
43-
git config --global user.email "github-actions[bot]@users.noreply.github.com"
44-
4539
- name: Setup Java ${{ matrix.java }}
4640
uses: actions/setup-java@v1
4741
with:
@@ -80,13 +74,13 @@ jobs:
8074
name: Run k-NN Restart-Upgrade BWC Tests from BWCVersion-${{ matrix.bwc_version }} to OpenSearch Version-${{ matrix.opensearch_version }} on Windows
8175
run: |
8276
echo "Running restart-upgrade backwards compatibility tests ..."
83-
./gradlew :qa:restart-upgrade:testRestartUpgrade -D'tests.bwc.version=${{ matrix.bwc_version }}'
77+
./gradlew :qa:restart-upgrade:testRestartUpgrade -D'tests.bwc.version=${{ matrix.bwc_version }}' -D'build.lib.commit_patches=false'
8478
8579
- if: startsWith(matrix.os,'ubuntu')
8680
name: Run k-NN Restart-Upgrade BWC Tests from BWCVersion-${{ matrix.bwc_version }} to OpenSearch Version-${{ matrix.opensearch_version }} on Ubuntu
8781
run: |
8882
echo "Running restart-upgrade backwards compatibility tests ..."
89-
./gradlew :qa:restart-upgrade:testRestartUpgrade -Dtests.bwc.version=$BWC_VERSION_RESTART_UPGRADE
83+
./gradlew :qa:restart-upgrade:testRestartUpgrade -Dtests.bwc.version=$BWC_VERSION_RESTART_UPGRADE -Dbuild.lib.commit_patches=false
9084
9185
9286
Rolling-Upgrade-BWCTests-k-NN:
@@ -106,12 +100,6 @@ jobs:
106100
- name: Checkout k-NN
107101
uses: actions/checkout@v1
108102

109-
# Setup git user so that patches for native libraries can be applied and committed
110-
- name: Setup git user
111-
run: |
112-
git config --global user.name "github-actions[bot]"
113-
git config --global user.email "github-actions[bot]@users.noreply.github.com"
114-
115103
- name: Setup Java ${{ matrix.java }}
116104
uses: actions/setup-java@v1
117105
with:
@@ -150,10 +138,10 @@ jobs:
150138
name: Run k-NN Rolling-Upgrade BWC Tests from BWCVersion-${{ matrix.bwc_version }} to OpenSearch Version-${{ matrix.opensearch_version }} on Windows
151139
run: |
152140
echo "Running rolling-upgrade backwards compatibility tests ..."
153-
./gradlew :qa:rolling-upgrade:testRollingUpgrade -D'tests.bwc.version=${{ matrix.bwc_version }}'
141+
./gradlew :qa:rolling-upgrade:testRollingUpgrade -D'tests.bwc.version=${{ matrix.bwc_version }}' -D'build.lib.commit_patches=false'
154142
155143
- if: startsWith(matrix.os,'ubuntu')
156144
name: Run k-NN Rolling-Upgrade BWC Tests from BWCVersion-${{ matrix.bwc_version }} to OpenSearch Version-${{ matrix.opensearch_version }} on Ubuntu
157145
run: |
158146
echo "Running rolling-upgrade backwards compatibility tests ..."
159-
./gradlew :qa:rolling-upgrade:testRollingUpgrade -Dtests.bwc.version=$BWC_VERSION_ROLLING_UPGRADE
147+
./gradlew :qa:rolling-upgrade:testRollingUpgrade -Dtests.bwc.version=$BWC_VERSION_ROLLING_UPGRADE -Dbuild.lib.commit_patches=false

.github/workflows/test_security.yml

+1-6
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ jobs:
3737
uses: actions/checkout@v1
3838
with:
3939
submodules: true
40-
# Setup git user so that patches for native libraries can be applied and committed
41-
- name: Setup git user
42-
run: |
43-
su `id -un 1000` -c 'git config --global user.name "github-actions[bot]"'
44-
su `id -un 1000` -c 'git config --global user.email "github-actions[bot]@users.noreply.github.com"'
4540

4641
- name: Setup Java ${{ matrix.java }}
4742
uses: actions/setup-java@v1
@@ -52,4 +47,4 @@ jobs:
5247
# switching the user, as OpenSearch cluster can only be started as root/Administrator on linux-deb/linux-rpm/windows-zip.
5348
run: |
5449
chown -R 1000:1000 `pwd`
55-
su `id -un 1000` -c "whoami && java -version && ./gradlew integTest -Dsecurity.enabled=true -Dsimd.enabled=true"
50+
su `id -un 1000` -c "whoami && java -version && ./gradlew integTest -Dsecurity.enabled=true -Dsimd.enabled=true -Dbuild.lib.commit_patches=false"

DEVELOPER_GUIDE.md

+7
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,13 @@ If you want to make a custom patch on JNI library
237237
3. Place the patch file under `jni/patches`
238238
4. Make a change in `jni/CmakeLists.txt`, `.github/workflows/CI.yml` to apply the patch during build
239239

240+
By default, in the cmake build system, these patches will be applied and committed to the native libraries. In order to
241+
successfully make the commits the `user.name` and `user.email` git configurations need to be setup. If you cannot set
242+
these in your environment, you can disable committing the changes to the library by passing gradle this flag:
243+
`build.lib.commit_patches=false`. For example, `gradlew build -Dbuild.lib.commit_patches=false`. If the patches are
244+
not committed, then the full library build process will run each time `cmake` is invoked. In a development environment,
245+
it is recommended to setup the user git configuration to avoid this cost.
246+
240247
### Enable SIMD Optimization
241248
SIMD(Single Instruction/Multiple Data) Optimization is enabled by default on Linux and Mac which boosts the performance
242249
by enabling `AVX2` on `x86 architecture` and `NEON` on `ARM64 architecture` while building the Faiss library. But to enable SIMD, the underlying processor

build.gradle

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ buildscript {
1818
opensearch_group = "org.opensearch"
1919
isSnapshot = "true" == System.getProperty("build.snapshot", "true")
2020
simd_enabled = System.getProperty("simd.enabled", "true")
21+
// Flag to determine whether cmake build system should apply patches and commit. In automated build environments
22+
// set this to false. In dev environments, set to true
23+
commit_lib_patches = System.getProperty("build.lib.commit_patches", "true")
2124

2225
version_tokens = opensearch_version.tokenize('-')
2326
opensearch_build = version_tokens[0] + '.0'
@@ -303,10 +306,10 @@ task cmakeJniLib(type:Exec) {
303306
workingDir 'jni'
304307
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
305308
dependsOn windowsPatches
306-
commandLine 'cmake', '.', "-G", "Unix Makefiles", "-DKNN_PLUGIN_VERSION=${opensearch_version}", "-DBLAS_LIBRARIES=$rootDir\\src\\main\\resources\\windowsDependencies\\libopenblas.dll", "-DLAPACK_LIBRARIES=$rootDir\\src\\main\\resources\\windowsDependencies\\libopenblas.dll", "-DSIMD_ENABLED=${simd_enabled}"
309+
commandLine 'cmake', '.', "-G", "Unix Makefiles", "-DKNN_PLUGIN_VERSION=${opensearch_version}", "-DBLAS_LIBRARIES=$rootDir\\src\\main\\resources\\windowsDependencies\\libopenblas.dll", "-DLAPACK_LIBRARIES=$rootDir\\src\\main\\resources\\windowsDependencies\\libopenblas.dll", "-DSIMD_ENABLED=${simd_enabled}", "-DCOMMIT_LIB_PATCHES=${commit_lib_patches}"
307310
}
308311
else {
309-
commandLine 'cmake', '.', "-DKNN_PLUGIN_VERSION=${opensearch_version}", "-DSIMD_ENABLED=${simd_enabled}"
312+
commandLine 'cmake', '.', "-DKNN_PLUGIN_VERSION=${opensearch_version}", "-DSIMD_ENABLED=${simd_enabled}", "-DCOMMIT_LIB_PATCHES=${commit_lib_patches}"
310313
}
311314
}
312315

jni/CMakeLists.txt

+12
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ else()
3131
set(CONFIG_ALL OFF)
3232
endif ()
3333

34+
# `git am` will create commits from the patches in the native libraries. This is ideal for development envs
35+
# because it prevents full lib rebuild everytime cmake is run. However, for build systems that will run the
36+
# build workflow once, it can cause issues because git commits require that the user and the user's email be set.
37+
# See https://github.com/opensearch-project/k-NN/issues/1651. So, we provide a flag that allows users to select between
38+
# the two
39+
if(NOT DEFINED COMMIT_LIB_PATCHES OR ${COMMIT_LIB_PATCHES} STREQUAL true)
40+
set(GIT_PATCH_COMMAND am)
41+
else()
42+
set(GIT_PATCH_COMMAND apply)
43+
endif()
44+
45+
3446
# Set OS specific variables
3547
if (${CMAKE_SYSTEM_NAME} STREQUAL Darwin)
3648
set(CMAKE_MACOSX_RPATH 1)

jni/cmake/init-faiss.cmake

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ find_path(PATCH_FILE NAMES 0001-Custom-patch-to-support-multi-vector.patch 0002-
1818
# If it exists, apply patches
1919
if (EXISTS ${PATCH_FILE})
2020
message(STATUS "Applying custom patches.")
21-
execute_process(COMMAND git am --3way ${CMAKE_CURRENT_SOURCE_DIR}/patches/faiss/0001-Custom-patch-to-support-multi-vector.patch WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/external/faiss ERROR_VARIABLE ERROR_MSG RESULT_VARIABLE RESULT_CODE)
22-
execute_process(COMMAND git am --3way ${CMAKE_CURRENT_SOURCE_DIR}/patches/faiss/0002-Enable-precomp-table-to-be-shared-ivfpq.patch WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/external/faiss ERROR_VARIABLE ERROR_MSG RESULT_VARIABLE RESULT_CODE)
21+
execute_process(COMMAND git ${GIT_PATCH_COMMAND} --3way ${CMAKE_CURRENT_SOURCE_DIR}/patches/faiss/0001-Custom-patch-to-support-multi-vector.patch WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/external/faiss ERROR_VARIABLE ERROR_MSG RESULT_VARIABLE RESULT_CODE)
22+
execute_process(COMMAND git ${GIT_PATCH_COMMAND} --3way ${CMAKE_CURRENT_SOURCE_DIR}/patches/faiss/0002-Enable-precomp-table-to-be-shared-ivfpq.patch WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/external/faiss ERROR_VARIABLE ERROR_MSG RESULT_VARIABLE RESULT_CODE)
2323
if(RESULT_CODE)
2424
message(FATAL_ERROR "Failed to apply patch:\n${ERROR_MSG}")
2525
endif()

jni/cmake/init-nmslib.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ find_path(PATCH_FILE NAMES 0001-Initialize-maxlevel-during-add-from-enterpoint-l
1818
# If it exists, apply patches
1919
if (EXISTS ${PATCH_FILE})
2020
message(STATUS "Applying custom patches.")
21-
execute_process(COMMAND git am --3way ${CMAKE_CURRENT_SOURCE_DIR}/patches/nmslib/0001-Initialize-maxlevel-during-add-from-enterpoint-level.patch WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/external/nmslib ERROR_VARIABLE ERROR_MSG RESULT_VARIABLE RESULT_CODE)
21+
execute_process(COMMAND git ${GIT_PATCH_COMMAND} --3way ${CMAKE_CURRENT_SOURCE_DIR}/patches/nmslib/0001-Initialize-maxlevel-during-add-from-enterpoint-level.patch WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/external/nmslib ERROR_VARIABLE ERROR_MSG RESULT_VARIABLE RESULT_CODE)
2222

2323
if(RESULT_CODE)
2424
message(FATAL_ERROR "Failed to apply patch:\n${ERROR_MSG}")

scripts/build.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ fi
118118

119119
# Build k-NN lib and plugin through gradle tasks
120120
cd $work_dir
121-
./gradlew build --no-daemon --refresh-dependencies -x integTest -x test -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER
122-
./gradlew :buildJniLib -Dsimd.enabled=false
121+
./gradlew build --no-daemon --refresh-dependencies -x integTest -x test -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER -Dbuild.lib.commit_patches=false
122+
./gradlew :buildJniLib -Dsimd.enabled=false -Dbuild.lib.commit_patches=false
123123

124124
if [ "$PLATFORM" != "windows" ] && [ "$ARCHITECTURE" = "x64" ]; then
125125
echo "Building k-NN library after enabling AVX2"
126-
./gradlew :buildJniLib -Dsimd.enabled=true
126+
./gradlew :buildJniLib -Dsimd.enabled=true -Dbuild.lib.commit_patches=false
127127
fi
128128

129129
./gradlew publishPluginZipPublicationToZipStagingRepository -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER

0 commit comments

Comments
 (0)