mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Reading exported data from shared objects on windows is broken. It requires __declspec(dllimport). However, this is problematic, as we use the same static libraries both from a shared and static context. So we can't just blindly apply dllimport. The linker should have caught this, as data members are exported in a different way. However, due to a bug in native-utils, data member symbols were exposed directly. However, interacting with those data member was completely broken. The only way we can really solve this is to just not use static data members. We're pretty good about this in WPILib itself. However, protobuf is absolutely terrible at this. There are a ton of inline functions that access global data. For the protobuf library itself, we can solve this easily enough. However, for the generated protobuf code, this is much more problematic. The member needed to bypass the global data is private. This means using just the stock protobuf code, this problem is not solvable. But, protobuf generated code has insertion points. Those insertion points let us add our own code into the generated code via a protoc plugin. And it just so happens that an insertion point exists to add extra public methodsto the generated protobuf header. There is also an insertion point to let us add to the cpp file. The methods we need are the getters, for unpacking protobufs. For any protobuf that has a message as a member, we generate a new wpi_x() getter (the existing one is just x(), where x is the field name). We then implement this in the cpp file. A trick we can use is in the cpp file, we can safely call the x() function, as the cpp file is in the same library as the global. Thus we can call that inline method, and not actually need to directly access any internal private state of the protobuf object. TL;DR, all protobuf classes that have messages as fields now have a wpi_x() accessor that must be used instead of x() if you want the code to work on windows. After wpilibsuite/native-utils#212, the bad code will fail to link, rather then just fail at runtime.
171 lines
4.0 KiB
Groovy
171 lines
4.0 KiB
Groovy
apply plugin: 'maven-publish'
|
|
apply plugin: 'java-library'
|
|
apply plugin: 'jacoco'
|
|
apply plugin: 'com.google.protobuf'
|
|
|
|
def baseArtifactId = project.baseId
|
|
def artifactGroupId = project.groupId
|
|
def javaBaseName = "_GROUP_edu_wpi_first_${project.baseId}_ID_${project.baseId}-java_CLS"
|
|
|
|
def outputsFolder = file("$project.buildDir/outputs")
|
|
|
|
task sourcesJar(type: Jar, dependsOn: classes) {
|
|
archiveClassifier = 'sources'
|
|
from sourceSets.main.allSource
|
|
}
|
|
|
|
task javadocJar(type: Jar, dependsOn: javadoc) {
|
|
archiveClassifier = 'javadoc'
|
|
from javadoc.destinationDir
|
|
}
|
|
|
|
task outputJar(type: Jar, dependsOn: classes) {
|
|
archiveBaseName = javaBaseName
|
|
destinationDirectory = outputsFolder
|
|
from sourceSets.main.output
|
|
}
|
|
|
|
task outputSourcesJar(type: Jar, dependsOn: classes) {
|
|
archiveBaseName = javaBaseName
|
|
destinationDirectory = outputsFolder
|
|
archiveClassifier = 'sources'
|
|
from sourceSets.main.allSource
|
|
}
|
|
|
|
task outputJavadocJar(type: Jar, dependsOn: javadoc) {
|
|
archiveBaseName = javaBaseName
|
|
destinationDirectory = outputsFolder
|
|
archiveClassifier = 'javadoc'
|
|
from javadoc.destinationDir
|
|
}
|
|
|
|
artifacts {
|
|
archives sourcesJar
|
|
archives javadocJar
|
|
archives outputJar
|
|
archives outputSourcesJar
|
|
archives outputJavadocJar
|
|
}
|
|
|
|
addTaskToCopyAllOutputs(outputSourcesJar)
|
|
addTaskToCopyAllOutputs(outputJavadocJar)
|
|
addTaskToCopyAllOutputs(outputJar)
|
|
|
|
build.dependsOn outputSourcesJar
|
|
build.dependsOn outputJavadocJar
|
|
build.dependsOn outputJar
|
|
|
|
project(':').libraryBuild.dependsOn build
|
|
|
|
publishing {
|
|
publications {
|
|
|
|
java(MavenPublication) {
|
|
artifact jar
|
|
artifact sourcesJar
|
|
artifact javadocJar
|
|
|
|
artifactId = "${baseArtifactId}-java"
|
|
groupId artifactGroupId
|
|
version wpilibVersioning.version.get()
|
|
}
|
|
}
|
|
}
|
|
|
|
test {
|
|
useJUnitPlatform()
|
|
systemProperty 'junit.jupiter.extensions.autodetection.enabled', 'true'
|
|
testLogging {
|
|
events "failed"
|
|
exceptionFormat "full"
|
|
}
|
|
finalizedBy jacocoTestReport
|
|
}
|
|
|
|
if (project.hasProperty('onlylinuxathena') || project.hasProperty('onlylinuxarm32') || project.hasProperty('onlylinuxarm64') || project.hasProperty('onlywindowsarm64')) {
|
|
test.enabled = false
|
|
}
|
|
|
|
repositories {
|
|
maven {
|
|
url = 'https://frcmaven.wpi.edu/artifactory/ex-mvn'
|
|
}
|
|
//maven.url "https://oss.sonatype.org/content/repositories/snapshots/"
|
|
}
|
|
|
|
sourceSets {
|
|
dev
|
|
}
|
|
|
|
configurations {
|
|
devImplementation.extendsFrom(implementation)
|
|
}
|
|
|
|
tasks.withType(JavaCompile).configureEach {
|
|
options.compilerArgs = [
|
|
'--release',
|
|
'17',
|
|
'-encoding',
|
|
'UTF8',
|
|
"-Werror",
|
|
"-Xlint:all",
|
|
// ignore AutoCloseable warnings
|
|
"-Xlint:-try",
|
|
// ignore missing serialVersionUID warnings
|
|
"-Xlint:-serial",
|
|
// ignore unclaimed annotation warning from annotation processing
|
|
"-Xlint:-processing",
|
|
]
|
|
}
|
|
|
|
dependencies {
|
|
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.1'
|
|
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
|
|
|
devImplementation sourceSets.main.output
|
|
}
|
|
|
|
task run(type: JavaExec) {
|
|
classpath = sourceSets.dev.runtimeClasspath
|
|
|
|
mainClass = project.devMain
|
|
}
|
|
|
|
build.dependsOn devClasses
|
|
|
|
jacoco {
|
|
toolVersion = "0.8.10"
|
|
}
|
|
|
|
jacocoTestReport {
|
|
reports {
|
|
xml.required = true
|
|
html.required = true
|
|
}
|
|
}
|
|
|
|
protobuf {
|
|
protoc {
|
|
artifact = 'com.google.protobuf:protoc:3.21.12'
|
|
}
|
|
plugins {
|
|
wpilib {
|
|
path = rootProject.file("protoplugin/binary/wpiprotoplugin.jar")
|
|
}
|
|
}
|
|
generateProtoTasks {
|
|
all().configureEach { task ->
|
|
task.inputs.file(rootProject.file("protoplugin/binary/wpiprotoplugin.jar"))
|
|
task.plugins {
|
|
wpilib {
|
|
outputSubDir = 'cpp'
|
|
}
|
|
}
|
|
task.builtins {
|
|
cpp {}
|
|
remove java
|
|
}
|
|
}
|
|
}
|
|
}
|