diff --git a/libs/native/libraries/build.gradle b/libs/native/libraries/build.gradle index 4d94ad6e20c73..afee491bcc7ba 100644 --- a/libs/native/libraries/build.gradle +++ b/libs/native/libraries/build.gradle @@ -52,7 +52,11 @@ dependencies { libs "org.elasticsearch:zstd:${zstdVersion}:linux-aarch64" libs "org.elasticsearch:zstd:${zstdVersion}:linux-x86-64" libs "org.elasticsearch:zstd:${zstdVersion}:windows-x86-64" - libs "org.elasticsearch:vec:${vecVersion}@zip" // temporarily comment this out, if testing a locally built native lib + // if testing locally, its assumed that the custom compiled binaries are copied to the correct directory + // See `simdvec/native/build.gradle` for details on how to compile locally + if (System.getenv("LOCAL_VEC_BINARY_OS") == null){ + libs "org.elasticsearch:vec:${vecVersion}@zip" + } } def extractLibs = tasks.register('extractLibs', Copy) { diff --git a/libs/simdvec/native/build.gradle b/libs/simdvec/native/build.gradle index 157065b9150f9..da36c5086c151 100644 --- a/libs/simdvec/native/build.gradle +++ b/libs/simdvec/native/build.gradle @@ -20,9 +20,9 @@ var os = org.gradle.internal.os.OperatingSystem.current() // docker run 9c9f36564c148b275aeecc42749e7b4580ded79dcf51ff6ccc008c8861e7a979 > build/libs/vec/shared/$arch/libvec.so // // To run tests and benchmarks on a locally built libvec, -// 1. Temporarily comment out the download in libs/native/library/build.gradle -// libs "org.elasticsearch:vec:${vecVersion}@zip" -// 2. Copy your locally built libvec binary, e.g. +// 1. Set the LOCAL_VEC_BINARY_OS environment variable to any value to skip downloading the binary, e.g. +// export LOCAL_VEC_BINARY_OS=darwin +// 2. Copy your locally built libvec binary (assumes from the repo root), e.g. // cp libs/simdvec/native/build/libs/vec/shared/aarch64/libvec.dylib libs/native/libraries/build/platform/darwin-aarch64/libvec.dylib // // Look at the disassemble: @@ -129,3 +129,24 @@ tasks.register('buildSharedLibrary') { throw new GradleException("Unsupported platform: " + platformName) } } + +tasks.register('buildSharedLibraryAndCopy') { + description = 'Assembles native shared library for the host architecture and copies to libs/native/libraries/build/platform/' + // check if `LOCAL_VEC_BINARY_OS` is set, if not throw an error to prevent accidental overwrites + if (System.getenv("LOCAL_VEC_BINARY_OS") == null){ + throw new GradleException("LOCAL_VEC_BINARY_OS is set, skipping copy to prevent overwriting local binary.") + } + dependsOn "buildSharedLibrary" + doLast { + // output dir is lowercased System.getenv("LOCAL_VEC_BINARY_OS") and arch + // we must translate platformName to match expected arch naming + def copyArch = platformName.equals("amd64") ? "x64" : platformName + def outputDir = file("../../native/libraries/build/platform/" + System.getenv("LOCAL_VEC_BINARY_OS").toLowerCase() + "-" + copyArch) + copy { + from layout.buildDirectory.dir('output') + into outputDir + duplicatesStrategy = 'INCLUDE' + } + println "Copied built libvec to " + outputDir.toString() + } +}