Skip to content

Commit

Permalink
Copy Java native dependencies directly into classpath (#9787)
Browse files Browse the repository at this point in the history
Eliminates the intermediate copy of the native libraries for the Java bindings into target/native-deps, instead copying libcudf.so and libcudfjni.so directly into the classpath resources.  This eliminates the need to search target/native-deps at runtime when the native libraries are not in the classpath in the case of running tests before the jar is built.

Authors:
  - Jason Lowe (https://github.com/jlowe)

Approvers:
  - Robert (Bobby) Evans (https://github.com/revans2)

URL: #9787
  • Loading branch information
jlowe authored Nov 30, 2021
1 parent 554ac81 commit 20d6723
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
7 changes: 2 additions & 5 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,6 @@
<include>LICENSE</include>
</includes>
</resource>
<resource>
<directory>${project.build.directory}/native-deps/</directory>
</resource>
</resources>
<pluginManagement>
<plugins>
Expand Down Expand Up @@ -499,14 +496,14 @@
<executions>
<execution>
<id>copy-native-libs</id>
<phase>validate</phase>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<overwrite>true</overwrite>
<skip>${skipNativeCopy}</skip>
<outputDirectory>${project.build.directory}/native-deps/${os.arch}/${os.name}</outputDirectory>
<outputDirectory>${project.build.outputDirectory}/${os.arch}/${os.name}</outputDirectory>
<resources>
<resource>
<directory>${native.build.path}</directory>
Expand Down
11 changes: 2 additions & 9 deletions java/src/main/java/ai/rapids/cudf/NativeDepsLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ public static synchronized void loadNativeDeps() {

/**
* Allows other libraries to reuse the same native deps loading logic. Libraries will be searched
* for under ${os.arch}/${os.name}/ in the class path using the class loader for this class. It
* will also look for the libraries under ./target/native-deps/${os.arch}/${os.name} to help
* facilitate testing while building.
* for under ${os.arch}/${os.name}/ in the class path using the class loader for this class.
* <br/>
* Because this just loads the libraries and loading the libraries themselves needs to be a
* singleton operation it is recommended that any library using this provide their own wrapper
Expand Down Expand Up @@ -203,12 +201,7 @@ private static File createFile(String os, String arch, String baseName) throws I
File loc;
URL resource = loader.getResource(path);
if (resource == null) {
// It looks like we are not running from the jar, or there are issues with the jar
File f = new File("./target/native-deps/" + path);
if (!f.exists()) {
throw new FileNotFoundException("Could not locate native dependency " + path);
}
resource = f.toURI().toURL();
throw new FileNotFoundException("Could not locate native dependency " + path);
}
try (InputStream in = resource.openStream()) {
loc = File.createTempFile(baseName, ".so");
Expand Down

0 comments on commit 20d6723

Please sign in to comment.