mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-05 03:21:42 +00:00
This commit updates the gradle files to be cleaner. It also builds for the
current platform by default, and only builds tests when building for the current platform. Mac builds and VS2015 builds are fixed. The other big change in this update is the introduction of Debug and Release builds. Debug builds are built with -O0 and -g. Release builds are built with -O2 and -g. For GCC-based builds, the resulting shared object is copied, stripped of debug information, and a debug link is set up to the copied shared object. This allows the release build to clock in at around 600 KB. On Windows, the debug info is already stored in a separate PDB file, so this copy and strip is not necessary. ntcore is being separated out from the rest of allwpilib. All other builds will consume a published maven dependency from this project. There are 4 possible publishing targets now: release, stable, beta, and development. These are specified on the command line via -Prepo=<repo name>. Change-Id: Ie8cb21f910953e09b80a5192317033eb0866cb70
This commit is contained in:
66
toolchains/arm.gradle
Normal file
66
toolchains/arm.gradle
Normal file
@@ -0,0 +1,66 @@
|
||||
def compilerPrefix = 'arm-frc-linux-gnueabi-'
|
||||
model {
|
||||
toolChains {
|
||||
gcc(Gcc) {
|
||||
target("arm"){
|
||||
// We use a custom-built cross compiler with the prefix arm-frc-linux-gnueabi-<util name>
|
||||
// If this ever changes, the prefix will need to be changed here
|
||||
cppCompiler.executable = compilerPrefix + cppCompiler.executable
|
||||
linker.executable = compilerPrefix + linker.executable
|
||||
assembler.executable = compilerPrefix + assembler.executable
|
||||
// Gradle auto-adds the -m32 argument to the linker and compiler. Our compiler only supports
|
||||
// arm, and doesn't understand this flag, so it is removed from both
|
||||
cppCompiler.withArguments { args ->
|
||||
args << '-std=c++1y' << '-Wformat=2' << '-Wall' << '-Wextra' << '-Werror' << '-pedantic'
|
||||
args << '-Wno-psabi' << '-Wno-unused-parameter' << '-fPIC' << '-rdynamic'
|
||||
//TODO: When the compiler allows us to actually call deprecated functions from within
|
||||
// deprecated function, remove this line (this will cause calling deprecated functions
|
||||
// to be treated as a warning rather than an error).
|
||||
args << '-Wno-error=deprecated-declarations'
|
||||
args.remove('-m32')
|
||||
}
|
||||
linker.withArguments { args ->
|
||||
args << '-rdynamic'
|
||||
args.remove('-m32')
|
||||
}
|
||||
staticLibArchiver.executable = compilerPrefix + staticLibArchiver.executable
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ext.setupReleaseDefines = { cppCompiler, linker ->
|
||||
cppCompiler.args '-O2', '-g'
|
||||
}
|
||||
|
||||
ext.setupDebugDefines = { cppCompiler, linker ->
|
||||
cppCompiler.args '-g', '-O0'
|
||||
}
|
||||
|
||||
ext.releaseSetup = { releaseTask ->
|
||||
binaries.withType(SharedLibraryBinarySpec) { binary ->
|
||||
if (!project.hasProperty('debug')) {
|
||||
def library = binary.sharedLibraryFile.absolutePath
|
||||
def debugLibrary = binary.sharedLibraryFile.absolutePath + ".debug"
|
||||
if (project.tasks.findByName("firstObjcopy${binary.name}") == null) {
|
||||
def firstObjcopy = project.tasks.create("firstObjcopy${binary.name}", Exec) { task ->
|
||||
task.commandLine "${compilerPrefix}objcopy", '--only-keep-debug', library, debugLibrary
|
||||
}
|
||||
def strip = project.tasks.create("strip${binary.name}", Exec) { task ->
|
||||
task.commandLine "${compilerPrefix}strip", '-g', library
|
||||
}
|
||||
def secondObjcopy = project.tasks.create("secondObjcopy${binary.name}", Exec) { task ->
|
||||
task.commandLine "${compilerPrefix}objcopy", "--add-gnu-debuglink=$debugLibrary", library
|
||||
}
|
||||
secondObjcopy.dependsOn strip
|
||||
strip.dependsOn firstObjcopy
|
||||
binary.tasks.whenObjectAdded { task ->
|
||||
if (task.name.contains('link')) {
|
||||
firstObjcopy.dependsOn task
|
||||
}
|
||||
}
|
||||
}
|
||||
releaseTask.dependsOn project.tasks.getByName("secondObjcopy${binary.name}")
|
||||
}
|
||||
}
|
||||
}
|
||||
70
toolchains/linux.gradle
Normal file
70
toolchains/linux.gradle
Normal file
@@ -0,0 +1,70 @@
|
||||
model {
|
||||
toolChains {
|
||||
gcc(Gcc) {
|
||||
target('x86') {
|
||||
cppCompiler.withArguments { args ->
|
||||
args << '-std=c++11' << '-Wformat=2' << '-Wall' << '-Wextra' << '-Werror' << '-pedantic'
|
||||
args << '-Wno-psabi' << '-Wno-unused-parameter' << '-fPIC' << '-rdynamic'
|
||||
//TODO: When the compiler allows us to actually call deprecated functions from within
|
||||
// deprecated function, remove this line (this will cause calling deprecated functions
|
||||
// to be treated as a warning rather than an error).
|
||||
args << '-Wno-error=deprecated-declarations'
|
||||
args << '-m32'
|
||||
}
|
||||
linker.withArguments { args ->
|
||||
args << '-rdynamic'
|
||||
args << '-m32'
|
||||
}
|
||||
}
|
||||
target('x64') {
|
||||
cppCompiler.withArguments { args ->
|
||||
args << '-std=c++11' << '-Wformat=2' << '-Wall' << '-Wextra' << '-Werror' << '-pedantic'
|
||||
args << '-Wno-psabi' << '-Wno-unused-parameter' << '-fPIC' << '-rdynamic'
|
||||
//TODO: When the compiler allows us to actually call deprecated functions from within
|
||||
// deprecated function, remove this line (this will cause calling deprecated functions
|
||||
// to be treated as a warning rather than an error).
|
||||
args << '-Wno-error=deprecated-declarations'
|
||||
}
|
||||
linker.withArguments { args ->
|
||||
args << '-rdynamic'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ext.setupReleaseDefines = { cppCompiler, linker ->
|
||||
cppCompiler.args '-O2', '-g'
|
||||
}
|
||||
|
||||
ext.setupDebugDefines = { cppCompiler, linker ->
|
||||
cppCompiler.args '-g', '-O0'
|
||||
}
|
||||
|
||||
ext.releaseSetup = { releaseTask ->
|
||||
binaries.withType(SharedLibraryBinarySpec) { binary ->
|
||||
if (!project.hasProperty('debug')) {
|
||||
def library = binary.sharedLibraryFile.absolutePath
|
||||
def debugLibrary = binary.sharedLibraryFile.absolutePath + ".debug"
|
||||
if (project.tasks.findByName("firstObjcopy${binary.name}") == null) {
|
||||
def firstObjcopy = project.tasks.create("firstObjcopy${binary.name}", Exec) { task ->
|
||||
task.commandLine 'objcopy', '--only-keep-debug', library, debugLibrary
|
||||
}
|
||||
def strip = project.tasks.create("strip${binary.name}", Exec) { task ->
|
||||
task.commandLine 'strip', '-g', library
|
||||
}
|
||||
def secondObjcopy = project.tasks.create("secondObjcopy${binary.name}", Exec) { task ->
|
||||
task.commandLine 'objcopy', "--add-gnu-debuglink=$debugLibrary", library
|
||||
}
|
||||
secondObjcopy.dependsOn strip
|
||||
strip.dependsOn firstObjcopy
|
||||
binary.tasks.whenObjectAdded { task ->
|
||||
if (task.name.contains('link')) {
|
||||
firstObjcopy.dependsOn task
|
||||
}
|
||||
}
|
||||
}
|
||||
releaseTask.dependsOn project.tasks.getByName("secondObjcopy${binary.name}")
|
||||
}
|
||||
}
|
||||
}
|
||||
57
toolchains/mac.gradle
Normal file
57
toolchains/mac.gradle
Normal file
@@ -0,0 +1,57 @@
|
||||
model {
|
||||
toolChains {
|
||||
clang(Clang) {
|
||||
target('x86') {
|
||||
cppCompiler.withArguments { args ->
|
||||
args << '-std=c++11' << '-Wall' << '-Wextra' << '-Werror' << '-pedantic-errors'
|
||||
args << '-Wno-unused-parameter' << '-fPIC' << '-m32'
|
||||
}
|
||||
linker.withArguments { args ->
|
||||
args << '-m32'
|
||||
}
|
||||
}
|
||||
target('x64') {
|
||||
cppCompiler.withArguments { args ->
|
||||
args << '-std=c++11' << '-Wall' << '-Wextra' << '-Werror' << '-pedantic-errors'
|
||||
args << '-Wno-unused-parameter' << '-fPIC'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ext.setupReleaseDefines = { cppCompiler, linker ->
|
||||
cppCompiler.args '-O2'
|
||||
}
|
||||
|
||||
ext.setupDebugDefines = { cppCompiler, linker ->
|
||||
cppCompiler.args '-g', '-O0'
|
||||
}
|
||||
|
||||
ext.releaseSetup = { releaseTask ->
|
||||
binaries.withType(SharedLibraryBinarySpec) { binary ->
|
||||
if (!project.hasProperty('debug')) {
|
||||
def library = binary.sharedLibraryFile.absolutePath
|
||||
def debugLibrary = binary.sharedLibraryFile.absolutePath + ".debug"
|
||||
if (project.tasks.findByName("firstObjcopy${binary.name}") == null) {
|
||||
def firstObjcopy = project.tasks.create("firstObjcopy${binary.name}", Exec) { task ->
|
||||
task.commandLine 'objcopy', '--only-keep-debug', library, debugLibrary
|
||||
}
|
||||
def strip = project.tasks.create("strip${binary.name}", Exec) { task ->
|
||||
task.commandLine 'strip', '-g', library
|
||||
}
|
||||
def secondObjcopy = project.tasks.create("secondObjcopy${binary.name}", Exec) { task ->
|
||||
task.commandLine 'objcopy', "--add-gnu-debuglink=$debugLibrary", library
|
||||
}
|
||||
secondObjcopy.dependsOn strip
|
||||
strip.dependsOn firstObjcopy
|
||||
binary.tasks.whenObjectAdded { task ->
|
||||
if (task.name.contains('link')) {
|
||||
firstObjcopy.dependsOn task
|
||||
}
|
||||
}
|
||||
}
|
||||
releaseTask.dependsOn project.tasks.getByName("secondObjcopy${binary.name}")
|
||||
}
|
||||
}
|
||||
}
|
||||
49
toolchains/windows.gradle
Normal file
49
toolchains/windows.gradle
Normal file
@@ -0,0 +1,49 @@
|
||||
model {
|
||||
toolChains {
|
||||
visualCpp(VisualCpp) {
|
||||
// Workaround for VS2015 adapted from https://github.com/couchbase/couchbase-lite-java-native/issues/23
|
||||
def VS_2015_INCLUDE_DIR = "C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/ucrt"
|
||||
def VS_2015_LIB_DIR = "C:/Program Files (x86)/Windows Kits/10/Lib/10.0.10240.0/ucrt"
|
||||
def VS_2015_INSTALL_DIR = 'C:/Program Files (x86)/Microsoft Visual Studio 14.0'
|
||||
def vsInstallDir = file(VS_2015_INSTALL_DIR)
|
||||
|
||||
// If you ever happen to install and uninstall any other version of VS, Gradle will misdetect the compiler
|
||||
// and linker to run. This fixes that by manually setting the install dir
|
||||
if (vsInstallDir.exists()) {
|
||||
installDir = vsInstallDir
|
||||
}
|
||||
|
||||
eachPlatform {
|
||||
cppCompiler.withArguments { args ->
|
||||
args << '/EHsc' << '/DNOMINMAX' << '/D_SCL_SECURE_NO_WARNINGS' << '/D_WINSOCK_DEPRECATED_NO_WARNINGS'
|
||||
if (file(VS_2015_INCLUDE_DIR).exists()) {
|
||||
args << "/I$VS_2015_INCLUDE_DIR"
|
||||
}
|
||||
}
|
||||
linker.withArguments { args ->
|
||||
if (file(VS_2015_LIB_DIR).exists()) {
|
||||
if (platform.architecture.name == 'x86') {
|
||||
args << "/LIBPATH:$VS_2015_LIB_DIR/x86"
|
||||
} else {
|
||||
args << "/LIBPATH:$VS_2015_LIB_DIR/x64"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ext.setupReleaseDefines = { cppCompiler, linker ->
|
||||
cppCompiler.args '/O2', '/Zi', '/FS'
|
||||
linker.args '/DEF:ntcore.def'
|
||||
}
|
||||
|
||||
ext.setupDebugDefines = { cppCompiler, linker ->
|
||||
cppCompiler.args '/Zi', '/FS'
|
||||
linker.args '/DEBUG', '/DEF:ntcore.def'
|
||||
}
|
||||
|
||||
// This is a noop on Windows. On gcc platforms, we strip the release binary and create a separate
|
||||
// debug library, but Windows already separates debug symbols into a .pdb file.
|
||||
ext.releaseSetup = {}
|
||||
Reference in New Issue
Block a user