Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 1 | import org.gradle.internal.os.OperatingSystem |
| 2 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 3 | nativeUtils.skipInstallPdb = project.hasProperty('buildServer') |
| 4 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 5 | if (project.hasProperty('ciDebugOnly')) { |
| 6 | toolchainsPlugin.registerReleaseBuildType = false |
| 7 | } |
| 8 | |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 9 | nativeUtils.addWpiNativeUtils() |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 10 | nativeUtils.withCrossRoboRIO() |
| 11 | nativeUtils.withCrossLinuxArm32() |
| 12 | nativeUtils.withCrossLinuxArm64() |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 13 | nativeUtils { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 14 | wpi { |
| 15 | configureDependencies { |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 16 | opencvYear = "frc2024" |
| 17 | googleTestYear = "frc2024" |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame^] | 18 | niLibVersion = "2024.2.1" |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 19 | opencvVersion = "4.8.0-2" |
| 20 | googleTestVersion = "1.14.0-1" |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 21 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 22 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | nativeUtils.wpi.addWarnings() |
| 26 | nativeUtils.wpi.addWarningsAsErrors() |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 27 | |
| 28 | if (project.name != 'wpilibcExamples') { |
| 29 | nativeUtils.wpi.addReleaseSymbolGeneration() |
| 30 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 31 | |
| 32 | nativeUtils.setSinglePrintPerPlatform() |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 33 | nativeUtils.enableSourceLink() |
| 34 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 35 | nativeUtils.wpi.addMacMinimumVersionArg() |
| 36 | |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 37 | nativeUtils.platformConfigs.each { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 38 | if (it.name.contains('osx')) { |
| 39 | it.linker.args << '-Wl,-rpath,\'@loader_path\'' |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 40 | it.linker.args << "-headerpad_max_install_names" |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 41 | } else if (it.name.contains('linux')) { |
| 42 | it.linker.args << '-Wl,-rpath,\'$ORIGIN\'' |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 43 | } |
| 44 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 45 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 46 | // Compress debug info on Linux |
| 47 | nativeUtils.platformConfigs.each { |
| 48 | if (it.name.contains('linux')) { |
| 49 | it.cppCompiler.debugArgs.add("-gz=zlib") |
| 50 | } |
| 51 | } |
| 52 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 53 | // NativeUtils adds the following OpenCV warning suppression for Linux, but not |
| 54 | // for macOS |
| 55 | // https://github.com/opencv/opencv/issues/20269 |
| 56 | nativeUtils.platformConfigs.osxuniversal.cppCompiler.args.add("-Wno-deprecated-anon-enum-enum-conversion") |
| 57 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 58 | nativeUtils.platformConfigs.linuxathena.linker.args.add("-Wl,--fatal-warnings") |
| 59 | |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 60 | model { |
| 61 | components { |
| 62 | all { |
| 63 | nativeUtils.useAllPlatforms(it) |
| 64 | } |
| 65 | } |
| 66 | binaries { |
| 67 | withType(NativeBinarySpec).all { |
| 68 | nativeUtils.usePlatformArguments(it) |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 73 | apply plugin: DisableBuildingGTest |
| 74 | |
| 75 | if (project.hasProperty('buildServer')) { |
| 76 | tasks.withType(org.gradle.nativeplatform.test.tasks.RunTestExecutable) { |
| 77 | def exeFile = file(it.executable) |
| 78 | def folder = exeFile.parentFile |
| 79 | |
| 80 | it.doLast { |
| 81 | folder.deleteDir() |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 86 | ext.appendDebugPathToBinaries = { binaries-> |
| 87 | binaries.withType(StaticLibraryBinarySpec) { |
| 88 | if (it.buildType.name.contains('debug')) { |
| 89 | def staticFileDir = it.staticLibraryFile.parentFile |
| 90 | def staticFileName = it.staticLibraryFile.name |
| 91 | def staticFileExtension = staticFileName.substring(staticFileName.lastIndexOf('.')) |
| 92 | staticFileName = staticFileName.substring(0, staticFileName.lastIndexOf('.')) |
| 93 | staticFileName = staticFileName + 'd' + staticFileExtension |
| 94 | def newStaticFile = new File(staticFileDir, staticFileName) |
| 95 | it.staticLibraryFile = newStaticFile |
| 96 | } |
| 97 | } |
| 98 | binaries.withType(SharedLibraryBinarySpec) { |
| 99 | if (it.buildType.name.contains('debug')) { |
| 100 | def sharedFileDir = it.sharedLibraryFile.parentFile |
| 101 | def sharedFileName = it.sharedLibraryFile.name |
| 102 | def sharedFileExtension = sharedFileName.substring(sharedFileName.lastIndexOf('.')) |
| 103 | sharedFileName = sharedFileName.substring(0, sharedFileName.lastIndexOf('.')) |
| 104 | sharedFileName = sharedFileName + 'd' + sharedFileExtension |
| 105 | def newSharedFile = new File(sharedFileDir, sharedFileName) |
| 106 | |
| 107 | def sharedLinkFileDir = it.sharedLibraryLinkFile.parentFile |
| 108 | def sharedLinkFileName = it.sharedLibraryLinkFile.name |
| 109 | def sharedLinkFileExtension = sharedLinkFileName.substring(sharedLinkFileName.lastIndexOf('.')) |
| 110 | sharedLinkFileName = sharedLinkFileName.substring(0, sharedLinkFileName.lastIndexOf('.')) |
| 111 | sharedLinkFileName = sharedLinkFileName + 'd' + sharedLinkFileExtension |
| 112 | def newLinkFile = new File(sharedLinkFileDir, sharedLinkFileName) |
| 113 | |
| 114 | it.sharedLibraryLinkFile = newLinkFile |
| 115 | it.sharedLibraryFile = newSharedFile |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | ext.createComponentZipTasks = { components, names, base, type, project, func -> |
| 121 | def stringNames = names.collect {it.toString()} |
| 122 | def configMap = [:] |
| 123 | components.each { |
| 124 | if (it in NativeLibrarySpec && stringNames.contains(it.name)) { |
| 125 | it.binaries.each { |
| 126 | if (!it.buildable) return |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 127 | def target = nativeUtils.getPublishClassifier(it) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 128 | if (configMap.containsKey(target)) { |
| 129 | configMap.get(target).add(it) |
| 130 | } else { |
| 131 | configMap.put(target, []) |
| 132 | configMap.get(target).add(it) |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | def taskList = [] |
| 138 | def outputsFolder = file("$project.buildDir/outputs") |
| 139 | configMap.each { key, value -> |
| 140 | def task = project.tasks.create(base + "-${key}", type) { |
| 141 | description = 'Creates component archive for platform ' + key |
| 142 | destinationDirectory = outputsFolder |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 143 | archiveClassifier = key |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 144 | archiveBaseName = '_M_' + base |
| 145 | duplicatesStrategy = 'exclude' |
| 146 | |
| 147 | from(licenseFile) { |
| 148 | into '/' |
| 149 | } |
| 150 | |
| 151 | func(it, value) |
| 152 | } |
| 153 | taskList.add(task) |
| 154 | |
| 155 | project.build.dependsOn task |
| 156 | |
| 157 | project.artifacts { |
| 158 | task |
| 159 | } |
| 160 | addTaskToCopyAllOutputs(task) |
| 161 | } |
| 162 | return taskList |
| 163 | } |
| 164 | |
| 165 | ext.includeStandardZipFormat = { task, value -> |
| 166 | value.each { binary -> |
| 167 | if (binary.buildable) { |
| 168 | if (binary instanceof SharedLibraryBinarySpec) { |
| 169 | task.dependsOn binary.tasks.link |
| 170 | task.from(new File(binary.sharedLibraryFile.absolutePath + ".debug")) { |
| 171 | into nativeUtils.getPlatformPath(binary) + '/shared' |
| 172 | } |
| 173 | def sharedPath = binary.sharedLibraryFile.absolutePath |
| 174 | sharedPath = sharedPath.substring(0, sharedPath.length() - 4) |
| 175 | |
| 176 | task.from(new File(sharedPath + '.pdb')) { |
| 177 | into nativeUtils.getPlatformPath(binary) + '/shared' |
| 178 | } |
| 179 | task.from(binary.sharedLibraryFile) { |
| 180 | into nativeUtils.getPlatformPath(binary) + '/shared' |
| 181 | } |
| 182 | task.from(binary.sharedLibraryLinkFile) { |
| 183 | into nativeUtils.getPlatformPath(binary) + '/shared' |
| 184 | } |
| 185 | } else if (binary instanceof StaticLibraryBinarySpec) { |
| 186 | task.dependsOn binary.tasks.createStaticLib |
| 187 | task.from(binary.staticLibraryFile) { |
| 188 | into nativeUtils.getPlatformPath(binary) + '/static' |
| 189 | } |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 190 | def pdbDir = binary.staticLibraryFile.parentFile |
| 191 | task.from(pdbDir) { |
| 192 | include '*.pdb' |
| 193 | into nativeUtils.getPlatformPath(binary) + '/static' |
| 194 | } |
| 195 | task.from(new File(pdbDir, "SourceLink.json")) { |
| 196 | into nativeUtils.getPlatformPath(binary) + '/static' |
| 197 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 198 | } |
| 199 | } |
| 200 | } |
| 201 | } |