Revision control

Copy as Markdown

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// This is based off:
import groovy.json.JsonOutput
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'org.mozilla.rust-android-gradle.rust-android'
kotlin {
jvmToolchain(rootProject.ext.build.jvmTargetCompatibility)
}
android {
namespace = "mozilla.telemetry.glean_native"
ndkVersion = rootProject.ext.build.ndkVersion
compileSdkVersion = rootProject.ext.build.compileSdkVersion
defaultConfig {
minSdkVersion rootProject.ext.build['minSdkVersion']
targetSdkVersion rootProject.ext.build['targetSdkVersion']
}
buildTypes {
debug {
// Export our rules in debug, as a consumer might still enable proguard/r8
consumerProguardFiles "$projectDir/proguard-rules-consumer.pro"
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
consumerProguardFiles "$projectDir/proguard-rules-consumer.pro"
}
withoutLib {
initWith release
}
}
// Uncomment to include debug symbols in native library builds.
// packagingOptions { doNotStrip "**/*.so" }
}
cargo {
// The directory of the Cargo.toml to build.
module = '../bundle-android'
// The Android NDK API level to target.
apiLevel = rootProject.ext.build['minSdkVersion']
// Where Cargo writes its outputs.
targetDirectory = '../../target'
// HACK:
// We consume this as libxul.
// Glean is build into libxul from mozilla-central
// and users consume it as part of GeckoView.
// Because UniFFI does not have the option to switch the library to consume,
// except at build time, we use this hack for now.
libname = 'xul'
targets = rootProject.ext.rustTargets
profile = rootProject.ext.cargoProfile
extraCargoBuildArguments = rootProject.ext.extraCargoBuildArguments
}
configurations {
// Libraries for unit tests
//
// This is a JAR file that contains libxul (our renamed libglean_ffi)
// and libjnidispatch built for desktop platforms -- i.e. non-Android.
// These include linux-x86-64, darwin-x86-64, and darwin-aarch64.
// These libraries are needed to run unit tests,
// since the AAR packages only contain libraries for Android.
//
// For libxul, we copy the desktop libs from the
// [rust-android-gradle plugin](https://github.com/mozilla/rust-android-gradle), which is
// configurable via `local.properties`. The official packages are built in taskcluster include
// `linux-x86-64` and `darwin-x86-64` and the list is controlled by
// taskcluster/kinds/module-build/kind.yml
//
// For libjnidispatch, we include all libraries included in the official JAR file.
consumable("forUnitTests")
// Stores the JNA jar file
jna {
canBeConsumed = false
canBeResolved = true
canBeDeclared = true
}
// Native Glean library, this is the one compatible with the user's local machine. We use it
// to run uniffi-bindgen against.
consumable("gleanNative")
}
dependencies {
jna(libs.jna) {
artifact {
type = "jar"
}
}
}
afterEvaluate {
// The `cargoBuild` task isn't available until after evaluation.
android.libraryVariants.all { variant ->
def productFlavor = ""
variant.productFlavors.each {
productFlavor += "${it.name.capitalize()}"
}
def buildType = "${variant.buildType.name.capitalize()}"
tasks["merge${productFlavor}${buildType}JniLibFolders"].dependsOn(tasks["cargoBuild"])
}
}
// Extract JNI dispatch libraries from the JAR into a directory, so that we can then package them
// into our own glean-native-desktopLibraries JAR.
def extractLibJniDispatch = tasks.register("extractLibJniDispatch", Copy) {
from zipTree(configurations.jna.singleFile).matching {
include "**/libjnidispatch.*"
}
into layout.buildDirectory.dir("libjnidispatch").get()
}
def packageLibsForTest = tasks.register("packageLibsForTest", Jar) {
archiveBaseName = "glean-native-forUnitTests"
from extractLibJniDispatch
from layout.buildDirectory.dir("rustJniLibs/desktop")
dependsOn tasks["cargoBuild${rootProject.ext.nativeRustTarget.capitalize()}"]
}
def copyGleanNative = tasks.register("copyGleanNative", Copy) {
from layout.buildDirectory.dir("rustJniLibs/desktop")
into layout.buildDirectory.dir("gleanNative")
}
artifacts {
// Connect task output to configurations
forUnitTests(packageLibsForTest)
gleanNative(copyGleanNative)
}
apply from: "$rootDir/publish.gradle"
ext.configurePublish()
afterEvaluate {
publishing {
publications {
// Publish a second package named `glean-native-forUnitTests` to Maven with the
// `forUnitTests` output. This contains the same content as our `forUnitTests`
// configuration. Publishing it allows the android-components code to depend on it.
forUnitTests(MavenPublication) {
artifact tasks['packageLibsForTest']
artifact file("${rootProject.projectDir}/DEPENDENCIES.md"), {
extension = "LICENSES.md"
}
pom {
groupId = rootProject.ext.library.groupId
artifactId = "${project.ext.artifactId}-forUnitTests"
description = project.ext.description
// For mavenLocal publishing workflow, increment the version number every publish.
version = rootProject.ext.library.version + (rootProject.hasProperty('local') ? '-' + rootProject.property('local') : '')
packaging = "jar"
licenses {
license {
name = libLicense
url = libLicenseUrl
}
}
developers {
developer {
name = 'Sync Team'
email = 'sync-team@mozilla.com'
}
}
scm {
connection = libVcsUrl
developerConnection = libVcsUrl
url = libUrl
}
}
// This is never the publication we want to use when publishing a
// parent project with us as a child `project()` dependency.
alias = true
}
}
}
}