Skip to content

Commit 568254d

Browse files
authored
[Native] Gradle-related tweaks to improve handling of the simdvec native library (#144539)
This PR introduces a couple of changes related to native libraries build; In the script used to build and publish the native vec library, force gradle to rebuild native intermediate files to ensure a clean and up-to-date binary. Under some conditions, we ended with object files that were not at the latest version. Probably these were extreme conditions (locally built libraries, experimenting different solutions), but better be safe. The library is tiny and takes seconds to build anyway. Update gradle build files of benchmarks and KnnIndexTester to explicitly depend on native-libraries. Most of the code in benchmarks and KnnIndexTester depends on the native simdvec library, and it happened in the past that we unknowingly run with older, not updated versions of the library. In particular, we want the :libs:native:native-libraries:extractLibs to appear in the task graph for both :benchmarks:run and :qa:vector:checkVec.
1 parent b50a0e6 commit 568254d

5 files changed

Lines changed: 13 additions & 6 deletions

File tree

benchmarks/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ dependencies {
6363
}
6464
expression(project(path: ':modules:lang-expression', configuration: 'zip'))
6565
painless(project(path: ':modules:lang-painless', configuration: 'zip'))
66-
nativeLib(project(':libs:native'))
66+
nativeLib(project(path: ':libs:native:native-libraries', configuration: 'default'))
6767
api "org.openjdk.jmh:jmh-core:$versions.jmh"
6868
annotationProcessor "org.openjdk.jmh:jmh-generator-annprocess:$versions.jmh"
6969
// Dependencies of JMH
@@ -99,7 +99,7 @@ tasks.named("run").configure {
9999
dependsOn "copyExpression", "copyPainless", configurations.nativeLib
100100
systemProperty 'plugins.dir', "${buildDir}/plugins"
101101
systemProperty 'tests.index', "${buildDir}/index"
102-
systemProperty 'es.nativelibs.path', TestUtil.getTestLibraryPath(file("../libs/native/libraries/build/platform/").toString())
102+
systemProperty 'es.nativelibs.path', providers.provider { TestUtil.getTestLibraryPath(configurations.nativeLib.asPath) }
103103
}
104104

105105
tasks.named('test').configure {

libs/simdvec/native/Dockerfile.aarch64

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ RUN apt-get update
44
RUN apt-get install -y gcc g++ openjdk-21-jdk
55
COPY . /workspace
66
WORKDIR /workspace
7-
RUN ./gradlew --quiet --console=plain clean buildSharedLibrary
7+
RUN ./gradlew --quiet --no-build-cache --console=plain clean buildSharedLibrary
88
RUN strip --strip-unneeded build/output/libvec.so
99

1010
CMD ["cat", "build/output/libvec.so"]

libs/simdvec/native/Dockerfile.amd64

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ RUN apt-get update
44
RUN apt-get install -y gcc g++ openjdk-21-jdk
55
COPY . /workspace
66
WORKDIR /workspace
7-
RUN ./gradlew --quiet --console=plain clean buildSharedLibrary
7+
RUN ./gradlew --quiet --no-build-cache --console=plain clean buildSharedLibrary
88
RUN strip --strip-unneeded build/output/libvec.so
99

1010
CMD ["cat", "build/output/libvec.so"]

libs/simdvec/native/publish_vec_binaries.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ if curl -sS -I --fail --location "${ARTIFACTORY_REPOSITORY}/org/elasticsearch/ve
3030
fi
3131

3232
echo 'Building Darwin binary...'
33-
./gradlew --quiet --console=plain clean vecAarch64SharedLibrary
33+
./gradlew --quiet --console=plain --no-build-cache clean vecAarch64SharedLibrary
3434

3535
echo 'Building Linux binary...'
3636
mkdir -p build/libs/vec/shared/aarch64/

qa/vector/build.gradle

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import org.elasticsearch.gradle.VersionProperties
1414
apply plugin: 'elasticsearch.java'
1515
apply plugin: 'elasticsearch.build'
1616

17+
configurations {
18+
nativeLib
19+
}
20+
1721

1822
tasks.named("dependencyLicenses").configure {
1923
mapping from: /lucene-.*/, to: 'lucene'
@@ -86,6 +90,8 @@ dependencies {
8690
}
8791
}
8892

93+
nativeLib(project(path: ':libs:native:native-libraries', configuration: 'default'))
94+
8995
testImplementation project(":libs:x-content")
9096
testImplementation project(":test:framework")
9197
}
@@ -205,7 +211,8 @@ tasks.register("checkVec", JavaExec) {
205211
// Configure logging to console
206212
systemProperty "es.logger.out", "console"
207213
systemProperty "es.logger.level", "INFO" // Change to DEBUG if needed
208-
systemProperty 'es.nativelibs.path', TestUtil.getTestLibraryPath(file("../../libs/native/libraries/build/platform/").toString())
214+
dependsOn configurations.nativeLib
215+
systemProperty 'es.nativelibs.path', providers.provider { TestUtil.getTestLibraryPath(configurations.nativeLib.asPath) }
209216
jvmArgs '-Xms16g', '-Xmx16g', '-Djava.util.concurrent.ForkJoinPool.common.parallelism=8', '-XX:+UnlockDiagnosticVMOptions', '-XX:+DebugNonSafepoints', '-XX:+HeapDumpOnOutOfMemoryError'
210217
if (buildParams.getRuntimeJavaVersion().map { it.majorVersion.toInteger() }.get() >= 21) {
211218
jvmArgs '--add-modules=jdk.incubator.vector', '--enable-native-access=ALL-UNNAMED'

0 commit comments

Comments
 (0)