Skip to content

Commit 71884f8

Browse files
committed
[build] Remove statically linked JNI artifacts
1 parent 80c391e commit 71884f8

File tree

6 files changed

+13
-135
lines changed

6 files changed

+13
-135
lines changed

MavenArtifacts.md

+7-34
Original file line numberDiff line numberDiff line change
@@ -14,54 +14,27 @@ The development repository is where development releases of every commit to [mai
1414
## Artifact classifiers
1515
We provide two base types of artifacts.
1616

17-
The first types are Java artifacts. These are usually published as `jar` files. Usually, the actual jar file is published with no classifier. The sources are published with the `-sources` classifier, and the javadocs are published with the `-javadoc` classifier.
18-
19-
The second types are native artifacts. These are usually published as `zip` files (except for the `JNI` artifact types, which are `jar` files. See below for information on this). The `-sources` and `-headers` classifiers contain the sources and headers respectively for the library. Each artifact also contains a classifier for each platform we publish. This platform is in the format `{os}{arch}`. The platform artifact only contains the binaries for a specific platform. In addition, we provide a `-all` classifier. This classifier combines all of the platform artifacts into a single artifact. This is useful for tools that cannot determine what version to use during builds. However, we recommend using the platform specific classifier when possible. Note that the binary artifacts never contain the headers, you always need the `-headers` classifier to get those.
20-
21-
## Artifact Names
22-
23-
WPILib builds four different types of artifacts.
24-
25-
##### C++ Only Libraries
26-
When we publish C++ only libraries, they are published with the base artifact name as their artifact name, with a `-cpp` extension. All dependencies for the library are linked as shared libraries to the binary.
27-
28-
29-
Example:
30-
```
31-
edu.wpi.first.wpilibc:wpilibc-cpp:version:classifier@zip
32-
```
33-
34-
#### Java Only Libraries
35-
When we publish Java only libraries, they are published with the base artifact name as their artifact name, with a `-java` extension.
17+
The first types are Java artifacts. These are usually published as `jar` files. Usually, the actual jar file is published with no classifier. The sources are published with the `-sources` classifier, and the javadocs are published with the `-javadoc` classifier. These artifacts are published with the base artifact name as their artifact ID, with a `-java` extension.
3618

3719
Example:
3820
```
3921
edu.wpi.first.wpilibj:wpilibj-java:version
4022
```
4123

42-
#### C++/Java Libraries without JNI
43-
For libraries that are both C++ and Java, but without a JNI component, the C++ component is published with the `basename-cpp` artifact name, and the Java component is published with the `basename-java` artifact name.
44-
45-
Example:
46-
```
47-
edu.wpi.first.wpiutil:wpiutil-cpp:version:classifier@zip (C++)
48-
edu.wpi.first.wpiutil:wpiutil-java:version (Java)
49-
```
24+
The second types are native artifacts. These are usually published as `zip` files. The `-sources` and `-headers` classifiers contain the sources and headers respectively for the library. Each artifact also contains a classifier for each platform we publish. This platform is in the format `{os}{arch}`. The full list of supported platforms can be found in [native-utils](https://github.com/wpilibsuite/native-utils/blob/main/src/main/java/edu/wpi/first/nativeutils/WPINativeUtilsExtension.java#L94). If the library is built statically, it will have `static` appended to the classifier. Additionally, if the library was built in debug mode, `debug` will be appended to the classifier. The platform artifact only contains the binaries for a specific platform. Note that the binary artifacts never contain the headers, you always need the `-headers` classifier to get those.
5025

51-
#### C++/Java Libraries with JNI
52-
For libraries that are both C++ and Java with a JNI component there are three different artifact names. For Java, the component is published as `basename-java`. For C++, the `basename-cpp` artifact contains the C++ artifacts with all dependencies linked as shared libraries to the binary. These binaries DO contain the JNI entry points. The `basename-jni` artifact contains identical C++ binaries to the `-cpp` artifact, however all of its dependencies are statically linked, and only the JNI and C entry points are exported.
26+
If the library is Java and C++ and has a JNI component, the native artifact will have a shared library containing JNI entrypoints alongside the C++ shared library. This JNI shared library will have a `jni` suffix in the file name.
5327

54-
The `-jni` artifact should only be used in cases where you want to create a self contained Java application where the native artifacts are embedded in the jar. Note in an extraction scenario, extending off of the library is never supported, which is why the C++ entry points are not exposed. The name of the library is randomly generated during extraction. For pretty much all cases, and if you ever want to extend from a native library, you should use the `-cpp` artifacts. GradleRIO uses the `-cpp` artifacts for all platforms, even desktop, for this reason.
28+
Native artifacts are published with the base artifact name as their artifact ID, with a `-cpp` extension.
5529

5630
Example:
5731
```
58-
edu.wpi.first.ntcore:ntcore-cpp:version:classifier@zip (C++)
59-
edu.wpi.first.ntcore:ntcore-jni:version:classifier (JNI jar library)
60-
edu.wpi.first.ntcore:ntcore-java:version (Java)
32+
edu.wpi.first.wpimath:wpimath-cpp:version:classifier@zip
33+
edu.wpi.first.wpimath:wpimath-cpp:version:windowsx86-64staticdebug@zip
6134
```
6235

6336
## Provided Artifacts
64-
This repository provides the following artifacts. Below each artifact is its dependencies. Note if ever using the `-jni` artifacts, no dependencies are needed for native binaries.
37+
This repository provides the following artifacts. Below each artifact is its dependencies.
6538

6639
For C++, if building with static dependencies, the listed order should be the link order in your linker.
6740

apriltag/build.gradle

+2-8
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,8 @@ model {
103103
return
104104
}
105105
it.cppCompiler.define 'WPILIB_EXPORTS'
106-
107-
if (it.component.name == "${nativeName}JNI") {
108-
lib project: ':wpimath', library: 'wpimath', linkage: 'static'
109-
lib project: ':wpiutil', library: 'wpiutil', linkage: 'static'
110-
} else {
111-
lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
112-
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
113-
}
106+
lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
107+
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
114108
}
115109
}
116110
tasks {

cscore/build.gradle

+2-7
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,8 @@ model {
6060
if (!it.buildable || !(it instanceof NativeBinarySpec)) {
6161
return
6262
}
63-
if (it.component.name == "${nativeName}JNI") {
64-
lib project: ':wpinet', library: 'wpinet', linkage: 'static'
65-
lib project: ':wpiutil', library: 'wpiutil', linkage: 'static'
66-
} else {
67-
lib project: ':wpinet', library: 'wpinet', linkage: 'shared'
68-
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
69-
}
63+
lib project: ':wpinet', library: 'wpinet', linkage: 'shared'
64+
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
7065
}
7166
}
7267
}

ntcore/build.gradle

+2-7
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,8 @@ model {
3131
if (!it.buildable || !(it instanceof NativeBinarySpec)) {
3232
return
3333
}
34-
if (it.component.name == "${nativeName}JNI") {
35-
lib project: ':wpinet', library: 'wpinet', linkage: 'static'
36-
lib project: ':wpiutil', library: 'wpiutil', linkage: 'static'
37-
} else {
38-
lib project: ':wpinet', library: 'wpinet', linkage: 'shared'
39-
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
40-
}
34+
lib project: ':wpinet', library: 'wpinet', linkage: 'shared'
35+
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
4136
}
4237
}
4338
}

shared/jni/publish.gradle

-32
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ def baseArtifactId = nativeName
77
def artifactGroupId = "edu.wpi.first.${nativeName}"
88
def zipBaseName = "_GROUP_edu_wpi_first_${nativeName}_ID_${nativeName}-cpp_CLS"
99
ext.zipBaseName = zipBaseName
10-
def jniBaseName = "_GROUP_edu_wpi_first_${nativeName}_ID_${nativeName}-jni_CLS"
1110
def jniCvStaticBaseName = "_GROUP_edu_wpi_first_${nativeName}_ID_${nativeName}-jnicvstatic_CLS"
1211

1312
def licenseFile = file("$rootDir/license.md")
@@ -77,28 +76,6 @@ model {
7776
"${nativeName}JNIShared"
7877
], zipBaseName, Zip, project, includeStandardZipFormat)
7978

80-
def jniTaskList = createComponentZipTasks($.components, ["${nativeName}JNI"], jniBaseName, Jar, project, { task, value ->
81-
value.each { binary ->
82-
if (binary.buildable) {
83-
if (binary instanceof SharedLibraryBinarySpec) {
84-
task.dependsOn binary.tasks.link
85-
def hashFile = new File(binary.sharedLibraryFile.parentFile.absolutePath, "${binary.component.baseName}.hash")
86-
task.outputs.file(hashFile)
87-
task.inputs.file(binary.sharedLibraryFile)
88-
task.from(hashFile) {
89-
into nativeUtils.getPlatformPath(binary)
90-
}
91-
task.doFirst {
92-
hashFile.text = MessageDigest.getInstance("MD5").digest(binary.sharedLibraryFile.bytes).encodeHex().toString()
93-
}
94-
task.from(binary.sharedLibraryFile) {
95-
into nativeUtils.getPlatformPath(binary)
96-
}
97-
}
98-
}
99-
}
100-
})
101-
10279
publications {
10380
cpp(MavenPublication) {
10481
taskList.each {
@@ -111,15 +88,6 @@ model {
11188
groupId artifactGroupId
11289
version wpilibVersioning.version.get()
11390
}
114-
jni(MavenPublication) {
115-
jniTaskList.each {
116-
artifact it
117-
}
118-
119-
artifactId = "${baseArtifactId}-jni"
120-
groupId artifactGroupId
121-
version wpilibVersioning.version.get()
122-
}
12391
}
12492

12593
if (project.hasProperty('cvStaticBuild') && project.getProperty('cvStaticBuild') == true) {

shared/jni/setupBuild.gradle

-47
Original file line numberDiff line numberDiff line change
@@ -145,53 +145,6 @@ model {
145145
}
146146
}
147147
}
148-
"${nativeName}JNI"(JniNativeLibrarySpec) {
149-
if (project.hasProperty('setBaseName')) {
150-
baseName = setBaseName + 'jni'
151-
} else {
152-
baseName = nativeName + 'jni'
153-
}
154-
155-
if (project.hasProperty('skipJniSymbols')) {
156-
checkSkipSymbols = skipJniSymbols
157-
}
158-
159-
enableCheckTask !project.hasProperty('skipJniCheck')
160-
javaCompileTasks << compileJava
161-
jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.roborio)
162-
jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.linuxarm32)
163-
jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.linuxarm64)
164-
sources {
165-
cpp {
166-
source {
167-
srcDirs 'src/main/native/cpp'
168-
if (project.hasProperty('generatedSources')) {
169-
srcDir generatedSources
170-
}
171-
include '**/jni/**/*.cpp'
172-
}
173-
exportedHeaders {
174-
srcDir 'src/main/native/include'
175-
if (project.hasProperty('generatedHeaders')) {
176-
srcDir generatedHeaders
177-
}
178-
include '**/*.h'
179-
}
180-
}
181-
}
182-
binaries.all {
183-
if (it instanceof StaticLibraryBinarySpec) {
184-
it.buildable = false
185-
return
186-
}
187-
if (!project.hasProperty('noWpiutil')) {
188-
lib project: ':wpiutil', library: 'wpiutil', linkage: 'static'
189-
}
190-
if (project.hasProperty('jniSplitSetup')) {
191-
jniSplitSetup(it)
192-
}
193-
}
194-
}
195148
// By default, a development executable will be generated. This is to help the case of
196149
// testing specific functionality of the library.
197150
"${nativeName}Dev"(NativeExecutableSpec) {

0 commit comments

Comments
 (0)