Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
38dd2b7
WIP: Fat jar with native libs.
mythrocks Aug 18, 2025
9b08099
WIP: Added resources plugin to package native libs.
mythrocks Aug 19, 2025
d293578
WIP: Fixed pom.xml to optionally build the native jars.
mythrocks Aug 19, 2025
9b9454c
Support different CUDA versions in different profiles.
mythrocks Aug 19, 2025
91134fe
More descriptive assembly file name.
mythrocks Aug 19, 2025
963d4c7
Converged assembly files.
mythrocks Aug 20, 2025
0e74c22
Can build for different CUDA versions.
mythrocks Aug 26, 2025
2bfd452
mvn clean verify
mythrocks Aug 26, 2025
b8603b4
Fixed compiler order issue.
mythrocks Aug 26, 2025
c35578d
Added auto-detection of platform.
mythrocks Aug 27, 2025
fbbe6bf
Fixed manifests for fat jars.
mythrocks Aug 27, 2025
2e7c7a4
Added library loader for explicit library loads, for included native …
mythrocks Aug 27, 2025
194a926
Moved dependency loader to a separate class.
mythrocks Aug 28, 2025
0407740
Removed rapids-logger from native deps.
mythrocks Aug 28, 2025
2806b08
Merge remote-tracking branch 'origin/branch-25.10' into fat-jar-fixed…
mythrocks Aug 28, 2025
75498be
Merge branch 'branch-25.10' into fat-jar-fixed-compile
mythrocks Sep 2, 2025
831d135
Merge branch 'branch-25.10' into fat-jar-fixed-compile
mythrocks Sep 2, 2025
300628f
Added librapids_logger.so to fat jar.
mythrocks Sep 3, 2025
7f21109
Merge remote-tracking branch 'origin/branch-25.10' into fat-jar-fixed…
mythrocks Sep 3, 2025
2db0d0a
Add contents of docker-build/ from #1264.
mythrocks Sep 4, 2025
a78980c
Switched artifact classifiers to match the uname output.
mythrocks Sep 4, 2025
c1d626f
README.md for the docker build.
mythrocks Sep 4, 2025
c237252
README.md tweaks.
mythrocks Sep 5, 2025
938fc09
Merge branch 'branch-25.10' into fat-jar-fixed-compile
mythrocks Sep 5, 2025
90ac2a2
Switching java22 back to the "compile" phase.
mythrocks Sep 8, 2025
1d3500e
Review comments: Naming convention, plus final-ize data member.
mythrocks Sep 8, 2025
80e7572
Review: Corrected repo for rocky8.
mythrocks Sep 9, 2025
16a6eee
Review: Better defaults for build.sh.
mythrocks Sep 9, 2025
ea90557
Merge branch 'branch-25.10' into fat-jar-fixed-compile
mythrocks Sep 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions java/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@ set -e -u -o pipefail
ARGS="$*"
NUMARGS=$#

CURDIR=$(cd "$(dirname "$0")"; pwd)
VERSION="25.10.0" # Note: The version is updated automatically when ci/release/update-version.sh is invoked
GROUP_ID="com.nvidia.cuvs"

# Identify CUDA major version.
CUDA_VERSION_FROM_NVCC=$(nvcc --version | grep -oP 'release [0-9]+' | awk '{print $2}')
CUDA_MAJOR_VERSION=${CUDA_VERSION_FROM_NVCC:-12}
Comment on lines +14 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CUDA_VERSION_FROM_NVCC=$(nvcc --version | grep -oP 'release [0-9]+' | awk '{print $2}')
CUDA_MAJOR_VERSION=${CUDA_VERSION_FROM_NVCC:-12}
CUDA_MAJOR_VERSION=$(nvcc --version | grep -oP 'release [0-9]+' | awk '{print $2}')

Any reason to have two variables here? My inclination would be to error out if the inner expression fails. The pipefail setting at the top of the script takes care of propagating the status.


# Identify architecture.
ARCH=$(uname -m)

BUILD_PROFILE="$ARCH-cuda$CUDA_MAJOR_VERSION"

if [ -z "${CMAKE_PREFIX_PATH:=}" ]; then
CMAKE_PREFIX_PATH="$(pwd)/../cpp/build"
export CMAKE_PREFIX_PATH
Expand All @@ -33,12 +41,12 @@ fi

# Build the java layer
if [ -z ${LD_LIBRARY_PATH+x} ]
then export LD_LIBRARY_PATH=${CURDIR}/../cpp/build
else export LD_LIBRARY_PATH=${CURDIR}/../cpp/build:${LD_LIBRARY_PATH}
then export LD_LIBRARY_PATH=$CMAKE_PREFIX_PATH
else export LD_LIBRARY_PATH=$CMAKE_PREFIX_PATH:${LD_LIBRARY_PATH}
Comment on lines +44 to +45
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was changed so that we don't make assumptions on the build paths.

When building Java artifacts for cuda12 or cuda13, I would like the option of putting the binaries in cpp/build/cuda12 and cpp/build/cuda13. This way, we don't lose progress when we switch environments.

In #1264, the Java build will look like:

# First, build libcuvs.so.
LIBCUVS_BUILD_DIR=`pwd`/cpp/build/cuda13 build.sh libcuvs
# Next, build Java, using the libraries built above.
CMAKE_PREFIX_PATH=`pwd`/cpp/build/cuda13 build.sh java

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I recommend C++ builds be installed before being used downstream, instead of being used from the build directory. Ensure that downstream projects only use public API....

fi

export LD_LIBRARY_PATH=${CURDIR}/../cpp/build:${LD_LIBRARY_PATH}
cd cuvs-java
mvn verify "${MAVEN_VERIFY_ARGS[@]}" \
mvn clean verify "${MAVEN_VERIFY_ARGS[@]}" -P "$BUILD_PROFILE" \
&& mvn install:install-file -Dfile=./target/cuvs-java-$VERSION.jar -DgroupId=$GROUP_ID -DartifactId=cuvs-java -Dversion=$VERSION -Dpackaging=jar \
&& mvn install:install-file -Dfile=./target/cuvs-java-$VERSION-"$BUILD_PROFILE".jar -DgroupId=$GROUP_ID -DartifactId=cuvs-java -Dversion=$VERSION -Dclassifier="$BUILD_PROFILE" -Dpackaging=jar \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, and thank you for keeping the slim jar too!

&& cp pom.xml ./target/
198 changes: 174 additions & 24 deletions java/cuvs-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<maven.compiler.source>22</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<native.build.path>${project.build.directory}/../../../cpp/build</native.build.path>
</properties>

<distributionManagement>
Expand Down Expand Up @@ -108,10 +109,11 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<version>3.11.0</version>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version of the maven-compiler-plugin had to be dropped to 3.11, to avoid build errors where Java22 might be built ahead of Java21.

<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
Expand All @@ -134,6 +136,9 @@
<compileSourceRoot>${project.basedir}/src/main/java22</compileSourceRoot>
</compileSourceRoots>
<multiReleaseOutput>true</multiReleaseOutput>
<excludes>
<exclude>module-info.java</exclude>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

module-info.java is skipped only for the Java22 build. It's already built as part of the Java21 compile step.

This is to avoid errors during the Java 22 build, where module-info.class from Java 21 is clobbered.

</excludes>
</configuration>
</execution>
</executions>
Expand All @@ -155,29 +160,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<mergeManifestMode>merge</mergeManifestMode>
<archiverConfig>
<duplicateBehavior>add</duplicateBehavior>
</archiverConfig>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
Comment on lines -158 to -180
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer required.

The fat-jar is built using maven-resources-plugin.

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down Expand Up @@ -277,4 +259,172 @@
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>x86_64-cuda12</id>
<activation>
<property>
<name>cuda.version</name>
<value>12</value>
</property>
</activation>
<properties>
<native.classifier>x86_64-cuda12</native.classifier>
<native.lib.path>${native.build.path}/cuda12</native.lib.path>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>copy-native-libs</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<overwrite>true</overwrite>
<outputDirectory>${project.build.directory}/native-libs/${os.arch}/${os.name}</outputDirectory>
<resources>
<resource>
<directory>${native.lib.path}</directory>
<includes>
<include>libcuvs.so</include>
<include>libcuvs_c.so</include>
</includes>
</resource>
<resource>
<directory>${native.lib.path}/_deps/rmm-build</directory>
<includes>
<include>librmm.so</include>
</includes>
</resource>
<resource>
<directory>${native.lib.path}/_deps/rapids_logger-build</directory>
<includes>
<include>librapids_logger.so</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<descriptors>
<descriptor>src/assembly/native-with-deps.xml</descriptor>
</descriptors>
<archive>
<manifestEntries>
<Multi-Release>true</Multi-Release>
<addClasspath>true</addClasspath>
<mainClass>com.nvidia.cuvs.examples.CagraExample</mainClass>
</manifestEntries>
</archive>
</configuration>
<executions>
<execution>
<id>assemble-native</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>x86_64-cuda13</id>
<activation>
<property>
<name>cuda.version</name>
<value>13</value>
</property>
</activation>
<properties>
<native.classifier>x86_64-cuda13</native.classifier>
<native.lib.path>${native.build.path}/cuda13</native.lib.path>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>copy-native-libs</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<overwrite>true</overwrite>
<outputDirectory>${project.build.directory}/native-libs/${os.arch}/${os.name}</outputDirectory>
<resources>
<resource>
<directory>${native.lib.path}</directory>
<includes>
<include>libcuvs.so</include>
<include>libcuvs_c.so</include>
</includes>
</resource>
<resource>
<directory>${native.lib.path}/_deps/rmm-build</directory>
<includes>
<include>librmm.so</include>
</includes>
</resource>
<resource>
<directory>${native.lib.path}/_deps/rapids_logger-build</directory>
<includes>
<include>librapids_logger.so</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<descriptors>
<descriptor>src/assembly/native-with-deps.xml</descriptor>
</descriptors>
<archive>
<manifestEntries>
<Multi-Release>true</Multi-Release>
<addClasspath>true</addClasspath>
<mainClass>com.nvidia.cuvs.examples.CagraExample</mainClass>
</manifestEntries>
</archive>
</configuration>
<executions>
<execution>
<id>assemble-native</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
52 changes: 52 additions & 0 deletions java/cuvs-java/src/assembly/native-with-deps.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/*
* Copyright (c) 2025, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0
http://maven.apache.org/xsd/assembly-2.1.0.xsd">

<id>${native.classifier}</id>
<formats>
<format>jar</format>
</formats>

<includeBaseDirectory>false</includeBaseDirectory>

<!-- Include all dependencies -->
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>

<!-- Include native libraries from separate directory -->
<fileSets>
<fileSet>
<directory>${project.build.directory}/native-libs</directory>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the assembly file that packages native-libraries into the native-jar artifact.

<outputDirectory>/</outputDirectory>
<includes>
<include>**/*</include>
</includes>
</fileSet>
</fileSets>

</assembly>
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@

final class JDKProvider implements CuVSProvider {

static {
OptionalNativeDependencyLoader.loadLibraries();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the call into the optional native-dependency loader.

If the jar includes native dependency libraries, they will be loaded at startup. If not, the load is skipped, and it runs as before (i.e. depending on $LD_LIBRARY_PATH, etc.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to pre-load specific paths? With the conda-pack option, we'd need to force pre-load the bundled libstdc++ library. I'm mentioning this because this looks like it might be the right place to do that pre-loading. If you just rely on LD_LIBRARY_PATH, you would likely end up with the system libstdc++, which will be too old for the conda packages.

}

private static final MethodHandle createNativeDataset$mh = createNativeDatasetBuilder();

static MethodHandle createNativeDatasetBuilder() {
Expand Down
Loading