2021-01-18 22:12:57 -05:00
// Configure Native-Utils WPI Plugin
2021-01-16 20:41:47 -08:00
nativeUtils . addWpiNativeUtils ( )
2022-12-16 17:05:23 -08:00
nativeUtils . withCrossRoboRIO ( )
nativeUtils . withCrossLinuxArm32 ( )
nativeUtils . withCrossLinuxArm64 ( )
2021-01-16 20:41:47 -08:00
2021-01-18 22:12:57 -05:00
// Configure WPI dependencies.
nativeUtils . wpi . configureDependencies {
2023-10-25 20:27:56 -04:00
wpiVersion = wpilibVersion
2023-11-22 20:08:23 -05:00
wpimathVersion = wpimathVersion
2024-10-31 02:59:39 -04:00
opencvYear = 'frc' + openCVYear
2023-10-25 20:27:56 -04:00
opencvVersion = openCVversion
2025-12-11 23:53:54 -06:00
niLibVersion = "2026.1.0"
2021-01-16 20:41:47 -08:00
}
2021-01-18 22:12:57 -05:00
// Configure warnings and errors
2021-01-16 20:41:47 -08:00
nativeUtils . wpi . addWarnings ( )
nativeUtils . wpi . addWarningsAsErrors ( )
2023-11-19 15:16:22 -05:00
nativeUtils . setSinglePrintPerPlatform ( )
2021-01-18 22:12:57 -05:00
// Enable builds for all platforms.
2021-01-16 20:41:47 -08:00
model {
components {
all {
nativeUtils . useAllPlatforms ( it )
}
}
binaries {
withType ( NativeBinarySpec ) . all {
nativeUtils . usePlatformArguments ( it )
2024-05-29 17:28:35 -04:00
if ( it . toolChain instanceof GccCompatibleToolChain ) {
it . cppCompiler . args < < "-Wno-deprecated-enum-enum-conversion"
2025-03-14 02:13:51 -04:00
if ( project . hasProperty ( 'withSanitizers' ) ) {
println ( "Adding asan/usan/lsan to " + it )
it . cppCompiler . args < < "-fsanitize=address,undefined,leak" < < "-g"
it . linker . args < < "-fsanitize=address,undefined,leak"
}
2024-05-29 17:28:35 -04:00
}
2021-01-16 20:41:47 -08:00
}
}
}
2023-11-19 15:16:22 -05:00
task copyAllOutputs ( type: Copy ) {
def outputsFolder = file ( "$project.buildDir/outputs" )
2025-10-16 10:22:55 +08:00
destinationDir = outputsFolder
2023-11-19 15:16:22 -05:00
}
ext . addTaskToCopyAllOutputs = { task - >
copyAllOutputs . dependsOn task
copyAllOutputs . inputs . file task . archiveFile
copyAllOutputs . from task . archiveFile
}
2021-01-18 22:12:57 -05:00
// Add debug path to binaries.
ext . appendDebugPathToBinaries = { binaries - >
2021-01-16 20:41:47 -08:00
binaries . withType ( StaticLibraryBinarySpec ) {
if ( it . buildType . name . contains ( 'debug' ) ) {
def staticFileDir = it . staticLibraryFile . parentFile
def staticFileName = it . staticLibraryFile . name
def staticFileExtension = staticFileName . substring ( staticFileName . lastIndexOf ( '.' ) )
staticFileName = staticFileName . substring ( 0 , staticFileName . lastIndexOf ( '.' ) )
staticFileName = staticFileName + 'd' + staticFileExtension
def newStaticFile = new File ( staticFileDir , staticFileName )
it . staticLibraryFile = newStaticFile
}
}
binaries . withType ( SharedLibraryBinarySpec ) {
if ( it . buildType . name . contains ( 'debug' ) ) {
def sharedFileDir = it . sharedLibraryFile . parentFile
def sharedFileName = it . sharedLibraryFile . name
def sharedFileExtension = sharedFileName . substring ( sharedFileName . lastIndexOf ( '.' ) )
sharedFileName = sharedFileName . substring ( 0 , sharedFileName . lastIndexOf ( '.' ) )
sharedFileName = sharedFileName + 'd' + sharedFileExtension
def newSharedFile = new File ( sharedFileDir , sharedFileName )
def sharedLinkFileDir = it . sharedLibraryLinkFile . parentFile
def sharedLinkFileName = it . sharedLibraryLinkFile . name
def sharedLinkFileExtension = sharedLinkFileName . substring ( sharedLinkFileName . lastIndexOf ( '.' ) )
sharedLinkFileName = sharedLinkFileName . substring ( 0 , sharedLinkFileName . lastIndexOf ( '.' ) )
sharedLinkFileName = sharedLinkFileName + 'd' + sharedLinkFileExtension
def newLinkFile = new File ( sharedLinkFileDir , sharedLinkFileName )
it . sharedLibraryLinkFile = newLinkFile
it . sharedLibraryFile = newSharedFile
}
}
}
2021-01-18 22:12:57 -05:00
// Create ZIP tasks for each component.
2021-01-16 20:41:47 -08:00
ext . createComponentZipTasks = { components , names , base , type , project , func - >
2021-01-18 22:12:57 -05:00
def stringNames = names . collect { it . toString ( ) }
2021-01-16 20:41:47 -08:00
def configMap = [ : ]
components . each {
if ( it in NativeLibrarySpec & & stringNames . contains ( it . name ) ) {
it . binaries . each {
if ( ! it . buildable ) return
2023-10-24 23:02:59 -04:00
def target = nativeUtils . getPublishClassifier ( it )
2021-01-16 20:41:47 -08:00
if ( configMap . containsKey ( target ) ) {
configMap . get ( target ) . add ( it )
} else {
configMap . put ( target , [ ] )
configMap . get ( target ) . add ( it )
}
}
}
}
def taskList = [ ]
def outputsFolder = file ( "$project.buildDir/outputs" )
configMap . each { key , value - >
def task = project . tasks . create ( base + "-${key}" , type ) {
description = 'Creates component archive for platform ' + key
destinationDirectory = outputsFolder
2023-10-15 12:17:40 -04:00
archiveClassifier = key
2024-11-23 11:54:00 -05:00
archiveBaseName = base
2021-01-16 20:41:47 -08:00
duplicatesStrategy = 'exclude'
from ( licenseFile ) {
into '/'
}
func ( it , value )
}
taskList . add ( task )
project . build . dependsOn task
2025-10-20 10:45:54 -04:00
// If the zip artifact matches the platform we're building for (either host or whatever the ArchOverride is), and it's a shared library built in release mode, add it to the list of artifacts the project exposes for use
if ( key . contains ( wpilibTools . getPlatformMapper ( ) . getWpilibClassifier ( ) ) & & ! key . contains ( "debug" ) & & ! key . contains ( "static" ) ) {
// For more information, see https://docs.gradle.org/current/userguide/variant_model.html and the outgoingVariants task
project . artifacts . add ( "wpilibNatives" , task )
} else {
project . artifacts {
task
}
2021-01-16 20:41:47 -08:00
}
addTaskToCopyAllOutputs ( task )
}
return taskList
}
2021-01-18 22:12:57 -05:00
// Create the standard ZIP format for the dependencies.
2021-01-16 20:41:47 -08:00
ext . includeStandardZipFormat = { task , value - >
value . each { binary - >
if ( binary . buildable ) {
if ( binary instanceof SharedLibraryBinarySpec ) {
task . dependsOn binary . tasks . link
task . from ( new File ( binary . sharedLibraryFile . absolutePath + ".debug" ) ) {
into nativeUtils . getPlatformPath ( binary ) + '/shared'
}
def sharedPath = binary . sharedLibraryFile . absolutePath
sharedPath = sharedPath . substring ( 0 , sharedPath . length ( ) - 4 )
task . from ( new File ( sharedPath + '.pdb' ) ) {
into nativeUtils . getPlatformPath ( binary ) + '/shared'
}
task . from ( binary . sharedLibraryFile ) {
into nativeUtils . getPlatformPath ( binary ) + '/shared'
}
task . from ( binary . sharedLibraryLinkFile ) {
into nativeUtils . getPlatformPath ( binary ) + '/shared'
}
2021-01-18 22:12:57 -05:00
} else if ( binary instanceof StaticLibraryBinarySpec ) {
2021-01-16 20:41:47 -08:00
task . dependsOn binary . tasks . createStaticLib
task . from ( binary . staticLibraryFile ) {
into nativeUtils . getPlatformPath ( binary ) + '/static'
}
}
}
}
}