mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
This adds support for two serialization formats for complex data types: - Protobuf for complex objects with variable length internals that need forward and backward wire compatibility (lower speed, more flexible) - Raw struct (ByteBuffer-style) for fixed-length objects (higher speed, less flexible) Deserialization can be done either by creating a new object (for immutable objects) or overwriting the contents of an existing object (for mutable objects). Implementing classes should provide inner classes that implement the Protobuf or Struct interface (in Java) or specialize the wpi::Protobuf or wpi::Struct struct (in C++). It is possible for classes to implement both. If the class itself does not implement serialization, it's possible for third parties/users to provide an implementation instead. Uses the Google protobuf implementation for C++ and the QuickBuffers alternative protobuf implementation for Java.
131 lines
3.4 KiB
Groovy
131 lines
3.4 KiB
Groovy
import com.hubspot.jinjava.Jinjava;
|
|
import com.hubspot.jinjava.JinjavaConfig;
|
|
|
|
ext {
|
|
useJava = true
|
|
useCpp = true
|
|
baseId = 'wpimath'
|
|
groupId = 'edu.wpi.first.wpimath'
|
|
|
|
nativeName = 'wpimath'
|
|
devMain = 'edu.wpi.first.math.DevMain'
|
|
}
|
|
|
|
apply from: "${rootDir}/shared/jni/setupBuild.gradle"
|
|
|
|
cppHeadersZip {
|
|
from('src/main/native/thirdparty/eigen/include') {
|
|
into '/'
|
|
}
|
|
from('src/main/native/thirdparty/gcem/include') {
|
|
into '/'
|
|
}
|
|
}
|
|
|
|
model {
|
|
components {
|
|
all {
|
|
it.sources.each {
|
|
it.exportedHeaders {
|
|
srcDirs 'src/main/native/include',
|
|
'src/main/native/thirdparty/eigen/include',
|
|
'src/main/native/thirdparty/gcem/include'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
dependencies {
|
|
api "org.ejml:ejml-simple:0.43.1"
|
|
api "com.fasterxml.jackson.core:jackson-annotations:2.15.2"
|
|
api "com.fasterxml.jackson.core:jackson-core:2.15.2"
|
|
api "com.fasterxml.jackson.core:jackson-databind:2.15.2"
|
|
api "us.hebi.quickbuf:quickbuf-runtime:1.3.2"
|
|
}
|
|
|
|
def wpilibNumberFileInput = file("src/generate/GenericNumber.java.jinja")
|
|
def natFileInput = file("src/generate/Nat.java.jinja")
|
|
def wpilibNumberFileOutputDir = file("$buildDir/generated/java/edu/wpi/first/math/numbers")
|
|
def wpilibNatFileOutput = file("$buildDir/generated/java/edu/wpi/first/math/Nat.java")
|
|
def maxNum = 20
|
|
|
|
task generateNumbers() {
|
|
description = "Generates generic number classes from template"
|
|
group = "WPILib"
|
|
|
|
inputs.file wpilibNumberFileInput
|
|
outputs.dir wpilibNumberFileOutputDir
|
|
|
|
doLast {
|
|
if(wpilibNumberFileOutputDir.exists()) {
|
|
wpilibNumberFileOutputDir.delete()
|
|
}
|
|
wpilibNumberFileOutputDir.mkdirs()
|
|
|
|
def config = new JinjavaConfig()
|
|
def jinjava = new Jinjava(config)
|
|
|
|
def template = wpilibNumberFileInput.text
|
|
|
|
for(i in 0..maxNum) {
|
|
def outputFile = new File(wpilibNumberFileOutputDir, "N${i}.java")
|
|
def replacements = new HashMap<String,?>()
|
|
replacements.put("num", i)
|
|
def output = jinjava.render(template, replacements)
|
|
outputFile.write(output)
|
|
}
|
|
}
|
|
}
|
|
|
|
task generateNat() {
|
|
description = "Generates Nat.java"
|
|
group = "WPILib"
|
|
inputs.file natFileInput
|
|
outputs.file wpilibNatFileOutput
|
|
dependsOn generateNumbers
|
|
|
|
doLast {
|
|
if(wpilibNatFileOutput.exists()) {
|
|
wpilibNatFileOutput.delete()
|
|
}
|
|
|
|
def config = new JinjavaConfig()
|
|
def jinjava = new Jinjava(config)
|
|
|
|
def template = natFileInput.text
|
|
|
|
def replacements = new HashMap<String,?>()
|
|
replacements.put("nums", 0..maxNum)
|
|
|
|
def output = jinjava.render(template, replacements)
|
|
wpilibNatFileOutput.write(output)
|
|
}
|
|
}
|
|
|
|
sourceSets.main.java.srcDir "${buildDir}/generated/java"
|
|
compileJava.dependsOn generateNumbers
|
|
compileJava.dependsOn generateNat
|
|
|
|
task unitsHeaders(type: Zip) {
|
|
destinationDirectory = file("$buildDir/outputs")
|
|
archiveBaseName = zipBaseName
|
|
archiveClassifier = "units"
|
|
|
|
from(licenseFile) {
|
|
into '/'
|
|
}
|
|
|
|
ext.includeDirs = [
|
|
project.file('src/main/native/include/units')
|
|
]
|
|
|
|
ext.includeDirs.each {
|
|
from(it) {
|
|
into '/units'
|
|
}
|
|
}
|
|
}
|
|
|
|
addTaskToCopyAllOutputs(unitsHeaders)
|