-
Notifications
You must be signed in to change notification settings - Fork 160
[REVIEW] [Java] Option to build fat-jars with native dependencies included #1296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
38dd2b7
9b08099
d293578
9b9454c
91134fe
963d4c7
0e74c22
2bfd452
b8603b4
c35578d
fbbe6bf
2e7c7a4
194a926
0407740
2806b08
75498be
831d135
300628f
7f21109
2db0d0a
a78980c
c1d626f
c237252
938fc09
90ac2a2
1d3500e
80e7572
16a6eee
ea90557
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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} | ||
|
|
||
| # 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 | ||
|
|
@@ -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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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> | ||
|
|
@@ -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> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The version of the |
||
| <executions> | ||
| <execution> | ||
| <id>default-compile</id> | ||
| <phase>compile</phase> | ||
| <goals> | ||
| <goal>compile</goal> | ||
| </goals> | ||
|
|
@@ -134,6 +136,9 @@ | |
| <compileSourceRoot>${project.basedir}/src/main/java22</compileSourceRoot> | ||
| </compileSourceRoots> | ||
| <multiReleaseOutput>true</multiReleaseOutput> | ||
| <excludes> | ||
| <exclude>module-info.java</exclude> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is to avoid errors during the Java 22 build, where |
||
| </excludes> | ||
| </configuration> | ||
| </execution> | ||
| </executions> | ||
|
|
@@ -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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is no longer required. The fat-jar is built using |
||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-jar-plugin</artifactId> | ||
|
|
@@ -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> | ||
| 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> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
|---|---|---|
|
|
@@ -31,6 +31,10 @@ | |
|
|
||
| final class JDKProvider implements CuVSProvider { | ||
|
|
||
| static { | ||
| OptionalNativeDependencyLoader.loadLibraries(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.