Apologies for the „broadcasting“ at @Mysterion , @RoelVanderPaal , @agibsonccc and @maki , but I think this might be relevant for everybody who posted in https://forum.byte-welt.net/byte-welt-projekte-projects/jcuda/16951-source-code-jcuda-public-scm.html
I just created Improve deployment of native libraries · Issue #8 · jcuda/jcuda-main · GitHub and started working on this: Most likely, the only way to smoothly deploy JCuda (and eventually, bring it into Maven central) is to pack the natives into JARs, declare these JARs as own artifacts, with classifiers indicating the OS/architecture, and load the natives right from the JARs. There certainly will be the usual Maven-related hassles, but hopefully, it will be worth it
Issues related to this issue (…) can be discussed here.
*** Edit ***
The old (current) approach is based on this layout:
jcuda\
JCudaDriverJNI\
CMakeList.txt
pom.xml
JCudaRuntimeJNI\
CMakeList.txt
pom.xml
JCudaJava\
pom.xml
(omitting JNvrtcJNI here)
The CMakeLists generate the subdirectories for the natives:
jcuda\
JCudaDriverJNI\
CMakeList.txt
nativeLibrary\
JCudaDriver-windows-x86_64.dll
pom.xml
JCudaRuntimeJNI\
CMakeList.txt
nativeLibrary\
JCudaRuntime-windows-x86_64.dll
pom.xml
JCudaJava\
pom.xml
These natives are then declared as artifacts (with classifier ${jcuda.os}-${jcuda.arch}
) by the POMs in the respective JNI folders. The JCudaJava\pom.xml declares dependecies to these artifacts.
The new approach (or at least, an „intermediate state“) is as follows:
The CMake files are updated to write the natives into a subdirectory that is one level higher, disambiguated by the OS and architecture, and contains the natives in a „lib“ subfolder:
jcuda\
JCudaDriverJNI\
CMakeList.txt
pom.xml
JCudaRuntimeJNI\
CMakeList.txt
pom.xml
JCudaJava\
pom.xml
nativeLibraries\
windows\
x86_64\
lib\
JCudaDriver-0.7.5b-windows-x86_64.dll
JCudaRuntime-0.7.5b-windows-x86_64.dll
The JCudaJava\pom.xml contains an additional invocation of the „maven-jar-plugin“:
[xml]
org.apache.maven.plugins
maven-jar-plugin
3.0.2
build_cuda_native_jar
package
jar
${project.groupId}
${project.artifactId}
${project.version}
${jcuda.os}-${jcuda.arch}
…
ativeLibraries${jcuda.os}${jcuda.arch}
lib/JCudaRuntime
lib/JCudaDriver
lib/JNvrtc
[/xml]
This will pick up the natives, and put them into a JAR, which then has the following name and structure
jcuda-0.7.5b-windows-x86_64.jar\
lib\
JCudaDriver-0.7.5b-windows-x86_64.dll
JCudaRuntime-0.7.5b-windows-x86_64.dll
When this JAR is added to the classpath, the natives can be loaded directly from this JAR.
Does this make sense?
Likely: No.
There is another step necessary. The packaging of the natives-JAR should NOT be done by the JCudaJava\pom.xml. (This should ONLY be responsible for the Java JAR).
Instead, the natives-JAR should be created by another POM. This POM should probably refer to the JCudaJava\pom.xml, and be responsible for building the native-JARs.
jcuda\
pom.xml <- The new POM
JCudaDriverJNI\
CMakeList.txt
pom.xml
JCudaRuntimeJNI\
CMakeList.txt
pom.xml
JCudaJava\
pom.xml
So this new POM should build the Java JAR (using the JCudaJava\pom.xml), and pack all available natives into the respective natives-JARs.
Comments, ideas, suggestions?
(I can imagine that the line
<classesDirectory>.. ativeLibraries\${jcuda.os}\${jcuda.arch}</classesDirectory>
makes Maven purists cry - that’s why I’m asking for feedback here…)