Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for handling vendor link types differently per platform #345

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.gradle.platform.base.PlatformContainer

@CompileStatic
class WPINativeJsonDepRules extends RuleSource {

@Mutate
void addJsonLibraries(NativeDepsSpec libs, final PlatformContainer platformContainer, final ExtensionContainer extensionContainer) {
def wpi = extensionContainer.getByType(WPIExtension)
Expand All @@ -29,7 +30,6 @@ class WPINativeJsonDepRules extends RuleSource {
wpi.deps.vendor.dependencies.each { WPIVendorDepsExtension.JsonDependency dep ->
dep.cppDependencies.each { WPIVendorDepsExtension.CppArtifact cpp ->

String linkSuff = cpp.sharedLibrary ? '' : 'static'
String name = dep.uuid + cpp.libName
String mavenbase = "${cpp.groupId}:${cpp.artifactId}:${WPIVendorDepsExtension.getVersion(cpp.version, wpi)}"
String config = cpp.configuration ?: "native_${dep.uuid}"
Expand Down Expand Up @@ -70,59 +70,86 @@ class WPINativeJsonDepRules extends RuleSource {
String buildType = buildKind.contains('debug') ? 'debug' : 'release'
String binaryConfig = config + buildKind

if (cpp.binaryPlatforms != null) {
if (cpp.binaryPlatforms.contains(NativePlatforms.roborio)) {
def platform = 'linuxathena'
libs.create("${name}_${platform}${buildKind}".toString(), NativeLib, { NativeLib lib ->
common(lib)
lib.targetPlatforms = [platform]
lib.libraryName = "${name}_binaries"

lib.buildType = buildType

if (cpp.sharedLibrary) {
lib.sharedMatchers = ["**/*${cpp.libName}*.so".toString()]
lib.dynamicMatchers = lib.sharedMatchers
} else {
lib.staticMatchers.add("**/*${cpp.libName}*.a".toString())
}
lib.maven = "$mavenbase:${platform}${linkSuff}debug@zip"
// It can't be 'config' otherwise missing libs break even if not used!
lib.configuration = "${binaryConfig}_${platform}".toString()
} as Action<NativeLib>)
}
boolean sharedContainsRio = cpp.sharedBinaryPlatforms.contains(NativePlatforms.roborio)
boolean staticContainsRio = cpp.staticBinaryPlatforms.contains(NativePlatforms.roborio)

if (sharedContainsRio || staticContainsRio) {
def platform = 'linuxathena'
libs.create("${name}_${platform}${buildKind}".toString(), NativeLib, { NativeLib lib ->
common(lib)
lib.targetPlatforms = [platform]
lib.libraryName = "${name}_binaries"

lib.buildType = buildType

String linkSuff = ''

for (String p : cpp.binaryPlatforms) {
// Skip athena, as it is specially handled
if (p.contains(NativePlatforms.roborio)) {
continue
if (sharedContainsRio) {
lib.sharedMatchers = ["**/*${cpp.libName}*.so".toString()]
lib.dynamicMatchers = lib.sharedMatchers
} else {
lib.staticMatchers.add("**/*${cpp.libName}*.a".toString())
linkSuff = 'static'
}
// DON'T REMOVE THIS!
// I know it's a redundant variable, but it's actually required. Groovy sucks with variable
// lifetime, so if you remove this, platform as read inside of the action for libs.create
// will only equal the last registered platform. The action is delegated and the variable is
// overridden before the action is called, but groovy is too dumb to realize that itself.
String platform = p
libs.create("${name}_${platform}${buildKind}".toString(), NativeLib, { NativeLib lib ->
common(lib)
lib.targetPlatforms = [platform]
lib.libraryName = "${name}_binaries"

lib.buildType = buildType

lib.staticMatchers = ["**/*${cpp.libName}*.lib".toString()]
if (cpp.sharedLibrary) {
lib.sharedMatchers = ["**/*${cpp.libName}*.so".toString(), "**/*${cpp.libName}*.dylib".toString()]

lib.dynamicMatchers = lib.sharedMatchers + "**/${cpp.libName}*.dll".toString()
} else {
lib.staticMatchers.add("**/*${cpp.libName}*.a".toString())
}
lib.maven = "$mavenbase:$platform$linkSuff$buildKind@zip"
// It can't be 'config' otherwise missing libs break even if not used!
lib.configuration = "${binaryConfig}_${platform}".toString()
} as Action<NativeLib>)
lib.maven = "$mavenbase:${platform}${linkSuff}debug@zip"
// It can't be 'config' otherwise missing libs break even if not used!
lib.configuration = "${binaryConfig}_${platform}".toString()
} as Action<NativeLib>)
}

for (String p : cpp.sharedBinaryPlatforms) {
// Skip athena, as it is specially handled
if (p.contains(NativePlatforms.roborio)) {
continue
}
// DON'T REMOVE THIS!
// I know it's a redundant variable, but it's actually required. Groovy sucks with variable
// lifetime, so if you remove this, platform as read inside of the action for libs.create
// will only equal the last registered platform. The action is delegated and the variable is
// overridden before the action is called, but groovy is too dumb to realize that itself.
String platform = p
libs.create("${name}_${platform}${buildKind}".toString(), NativeLib, { NativeLib lib ->
common(lib)
lib.targetPlatforms = [platform]
lib.libraryName = "${name}_binaries"

lib.buildType = buildType

lib.staticMatchers = ["**/*${cpp.libName}*.lib".toString()]
lib.sharedMatchers = ["**/*${cpp.libName}*.so".toString(), "**/*${cpp.libName}*.dylib".toString()]

lib.dynamicMatchers = lib.sharedMatchers + "**/${cpp.libName}*.dll".toString()
lib.maven = "$mavenbase:$platform$buildKind@zip"
// It can't be 'config' otherwise missing libs break even if not used!
lib.configuration = "${binaryConfig}_${platform}".toString()
} as Action<NativeLib>)
}

for (String p : cpp.staticBinaryPlatforms) {
// Skip athena, as it is specially handled
if (p.contains(NativePlatforms.roborio)) {
continue
}
// DON'T REMOVE THIS!
// I know it's a redundant variable, but it's actually required. Groovy sucks with variable
// lifetime, so if you remove this, platform as read inside of the action for libs.create
// will only equal the last registered platform. The action is delegated and the variable is
// overridden before the action is called, but groovy is too dumb to realize that itself.
String platform = p
libs.create("${name}_${platform}${buildKind}".toString(), NativeLib, { NativeLib lib ->
common(lib)
lib.targetPlatforms = [platform]
lib.libraryName = "${name}_binaries"

lib.buildType = buildType

lib.staticMatchers = ["**/*${cpp.libName}*.lib".toString()]
lib.staticMatchers.add("**/*${cpp.libName}*.a".toString())

lib.maven = "$mavenbase:${platform}static$buildKind@zip"
// It can't be 'config' otherwise missing libs break even if not used!
lib.configuration = "${binaryConfig}_${platform}".toString()
} as Action<NativeLib>)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,17 @@ public class WPIVendorDepsExtension {
dependencies.each { JsonDependency dep ->
if (!isIgnored(ignore, dep)) {
dep.cppDependencies.each { CppArtifact cpp ->
if (cpp.sharedBinaryPlatforms == null) {
cpp.sharedBinaryPlatforms = new String[0];
}
if (cpp.staticBinaryPlatforms == null) {
cpp.staticBinaryPlatforms = new String[0];
}
if (cpp.headerClassifier != null)
dds.add(new DelegatedDependencySet(dep.uuid + cpp.libName + "_headers", bin, dse, cpp.skipInvalidPlatforms))
if (cpp.sourcesClassifier != null)
dds.add(new DelegatedDependencySet(dep.uuid + cpp.libName + "_sources", bin, dse, cpp.skipInvalidPlatforms))
if (cpp.binaryPlatforms != null && cpp.binaryPlatforms.length > 0)
if (cpp.sharedBinaryPlatforms.length > 0 || cpp.staticBinaryPlatforms.length > 0)
dds.add(new DelegatedDependencySet(dep.uuid + cpp.libName + "_binaries", bin, dse, cpp.skipInvalidPlatforms))
}
}
Expand Down Expand Up @@ -208,10 +214,9 @@ public class WPIVendorDepsExtension {

String headerClassifier
String sourcesClassifier
String[] binaryPlatforms
String[] sharedBinaryPlatforms
String[] staticBinaryPlatforms
boolean skipInvalidPlatforms

boolean sharedLibrary
}

static class JsonDependency {
Expand Down