Skip to content

Commit 42376b0

Browse files
benwtrentbreskeby
andauthored
This partially simplifies the local native vec testing, more work to be done (#137904)
* This partially simplifies the local native vec testing, more work to be done * Adding logic to copy built native lib * iter * Update libs/simdvec/native/build.gradle Co-authored-by: Rene Groeschke <[email protected]> --------- Co-authored-by: Rene Groeschke <[email protected]>
1 parent 18b882b commit 42376b0

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

libs/native/libraries/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ dependencies {
5252
libs "org.elasticsearch:zstd:${zstdVersion}:linux-aarch64"
5353
libs "org.elasticsearch:zstd:${zstdVersion}:linux-x86-64"
5454
libs "org.elasticsearch:zstd:${zstdVersion}:windows-x86-64"
55-
libs "org.elasticsearch:vec:${vecVersion}@zip" // temporarily comment this out, if testing a locally built native lib
55+
// if testing locally, its assumed that the custom compiled binaries are copied to the correct directory
56+
// See `simdvec/native/build.gradle` for details on how to compile locally
57+
if (System.getenv("LOCAL_VEC_BINARY_OS") == null){
58+
libs "org.elasticsearch:vec:${vecVersion}@zip"
59+
}
5660
}
5761

5862
def extractLibs = tasks.register('extractLibs', Copy) {

libs/simdvec/native/build.gradle

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ var os = org.gradle.internal.os.OperatingSystem.current()
2020
// docker run 9c9f36564c148b275aeecc42749e7b4580ded79dcf51ff6ccc008c8861e7a979 > build/libs/vec/shared/$arch/libvec.so
2121
//
2222
// To run tests and benchmarks on a locally built libvec,
23-
// 1. Temporarily comment out the download in libs/native/library/build.gradle
24-
// libs "org.elasticsearch:vec:${vecVersion}@zip"
25-
// 2. Copy your locally built libvec binary, e.g.
23+
// 1. Set the LOCAL_VEC_BINARY_OS environment variable to any value to skip downloading the binary, e.g.
24+
// export LOCAL_VEC_BINARY_OS=darwin
25+
// 2. Copy your locally built libvec binary (assumes from the repo root), e.g.
2626
// cp libs/simdvec/native/build/libs/vec/shared/aarch64/libvec.dylib libs/native/libraries/build/platform/darwin-aarch64/libvec.dylib
2727
//
2828
// Look at the disassemble:
@@ -129,3 +129,24 @@ tasks.register('buildSharedLibrary') {
129129
throw new GradleException("Unsupported platform: " + platformName)
130130
}
131131
}
132+
133+
tasks.register('buildSharedLibraryAndCopy') {
134+
description = 'Assembles native shared library for the host architecture and copies to libs/native/libraries/build/platform/'
135+
// check if `LOCAL_VEC_BINARY_OS` is set, if not throw an error to prevent accidental overwrites
136+
if (System.getenv("LOCAL_VEC_BINARY_OS") == null){
137+
throw new GradleException("LOCAL_VEC_BINARY_OS is set, skipping copy to prevent overwriting local binary.")
138+
}
139+
dependsOn "buildSharedLibrary"
140+
doLast {
141+
// output dir is lowercased System.getenv("LOCAL_VEC_BINARY_OS") and arch
142+
// we must translate platformName to match expected arch naming
143+
def copyArch = platformName.equals("amd64") ? "x64" : platformName
144+
def outputDir = file("../../native/libraries/build/platform/" + System.getenv("LOCAL_VEC_BINARY_OS").toLowerCase() + "-" + copyArch)
145+
copy {
146+
from layout.buildDirectory.dir('output')
147+
into outputDir
148+
duplicatesStrategy = 'INCLUDE'
149+
}
150+
println "Copied built libvec to " + outputDir.toString()
151+
}
152+
}

0 commit comments

Comments
 (0)