Skip to content

Commit

Permalink
Getting a-s and m-c almost working with identical gradle files
Browse files Browse the repository at this point in the history
  • Loading branch information
mhammond committed Jan 16, 2025
1 parent a8e7017 commit 24044d0
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 104 deletions.
9 changes: 8 additions & 1 deletion build-scripts/component-common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ ext.configureUniFFIBindgen = { crateName ->

// Call `uniffi-bindgen` to generate the Kotlin bindings
def generateUniffiBindings = tasks.register("generateUniffiBindings") {
if (gradle.hasProperty("mozconfig")) {
println("XXX - generateUniffiBindings for crate '$crateName' has been disabled while we work out the monorepo.")
println("XXX - this will cause kotlin compilation errors as it tries to find symbols in the uniffi generated code.")
return
}
def megazordNative = configurations.getByName("megazordNative")
doFirst {
def libraryPath = megazordNative.asFileTree.matching {
Expand Down Expand Up @@ -130,7 +135,9 @@ ext.configureUniFFIBindgen = { crateName ->
def compileTask = tasks["compile${variantName}Kotlin"]

compileTask.dependsOn(generateUniffiBindings)
variant.registerJavaGeneratingTask(generateUniffiBindings, megazordNative.singleFile)
if (!gradle.hasProperty("mozconfig")) { // XXX - needs uniffi-bindgen love in m-c
variant.registerJavaGeneratingTask(generateUniffiBindings, megazordNative.singleFile)
}
}
}
}
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ ext.rustTargets += ext.nativeRustTarget
ext.libsRootDir = useDownloadedLibs ? rootProject.buildDir : rootProject.rootDir

subprojects {
group = "org.mozilla.appservices"
apply plugin: 'maven-publish'
// Note we apply some plugins to the subprojects in settings.gradle to help with the m-c migration.

// Kotlin settings applicable to all modules.
afterEvaluate{
Expand Down
180 changes: 94 additions & 86 deletions megazords/full/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
apply plugin: 'com.android.library'
apply plugin: 'org.mozilla.rust-android-gradle.rust-android'
apply plugin: 'kotlin-android'

if (!gradle.hasProperty("mozconfig")) {
apply plugin: 'org.mozilla.rust-android-gradle.rust-android'
}

android {
namespace 'org.mozilla.appservices.full_megazord'

Expand Down Expand Up @@ -69,66 +72,67 @@ dependencies {
}
}

// Extract JNI dispatch libraries from the JAR into a directory, so that we can then package them
// into our own megazord-desktopLibraries JAR.
def extractLibJniDispatch = tasks.register("extractLibJniDispatch", Copy) {
from zipTree(configurations.jna.singleFile).matching {
include "**/libjnidispatch.*"
if (!gradle.hasProperty("mozconfig")) {
// Extract JNI dispatch libraries from the JAR into a directory, so that we can then package them
// into our own megazord-desktopLibraries JAR.
def extractLibJniDispatch = tasks.register("extractLibJniDispatch", Copy) {
from zipTree(configurations.jna.singleFile).matching {
include "**/libjnidispatch.*"
}
into layout.buildDirectory.dir("libjnidispatch").get()
}
into layout.buildDirectory.dir("libjnidispatch").get()
}

def packageLibsForTest = tasks.register("packageLibsForTest", Jar) {
archiveBaseName = "full-megazord-libsForTests"

from extractLibJniDispatch
from layout.buildDirectory.dir("rustJniLibs/desktop")
dependsOn tasks["cargoBuild${rootProject.ext.nativeRustTarget.capitalize()}"]
}
def packageLibsForTest = tasks.register("packageLibsForTest", Jar) {
archiveBaseName = "full-megazord-libsForTests"

def copyMegazordNative = tasks.register("copyMegazordNative", Copy) {
from layout.buildDirectory.dir("rustJniLibs/desktop")
into layout.buildDirectory.dir("megazordNative")
}
from extractLibJniDispatch
from layout.buildDirectory.dir("rustJniLibs/desktop")
dependsOn tasks["cargoBuild${rootProject.ext.nativeRustTarget.capitalize()}"]
}

def copyMegazordNative = tasks.register("copyMegazordNative", Copy) {
from layout.buildDirectory.dir("rustJniLibs/desktop")
into layout.buildDirectory.dir("megazordNative")
}

artifacts {
// Connect task output to the configurations
libsForTests(packageLibsForTest)
megazordNative(copyMegazordNative)
}
artifacts {
// Connect task output to configurations
libsForTests(packageLibsForTest)
megazordNative(copyMegazordNative)
}

cargo {
// The directory of the Cargo.toml to build.
module = '..'
cargo {
// The directory of the Cargo.toml to build.
module = '..'

// The Android NDK API level to target.
apiLevel = rootProject.config.minSdkVersion
// The Android NDK API level to target.
apiLevel = rootProject.config.minSdkVersion

// Where Cargo writes its outputs.
targetDirectory = '../../../target'
// Where Cargo writes its outputs.
targetDirectory = '../../../target'

libname = 'megazord'
libname = 'megazord'

// The Cargo targets to invoke. The mapping from short name to target
// triple is defined by the `rust-android-gradle` plugin.
targets = rootProject.ext.rustTargets
// The Cargo targets to invoke. The mapping from short name to target
// triple is defined by the `rust-android-gradle` plugin.
targets = rootProject.ext.rustTargets

// Perform release builds (which should have debug info, due to
// `debug = true` in Cargo.toml).
profile = "release"
// Perform release builds (which should have debug info, due to
// `debug = true` in Cargo.toml).
profile = "release"

exec = { spec, toolchain ->
rootProject.ext.cargoExec(spec, toolchain)
// Only used in the full megazord (that is, in this project) at build time.
spec.environment("MEGAZORD_VERSION", config.componentsVersion)
}
exec = { spec, toolchain ->
rootProject.ext.cargoExec(spec, toolchain)
// Only used in the full megazord (that is, in this project) at build time.
spec.environment("MEGAZORD_VERSION", config.componentsVersion)
}

extraCargoBuildArguments = rootProject.ext.extraCargoBuildArguments
extraCargoBuildArguments = rootProject.ext.extraCargoBuildArguments

// Add a build-id so that our code works with simpleperf
// https://bugzilla.mozilla.org/show_bug.cgi?id=1937916
generateBuildId = true
// Add a build-id so that our code works with simpleperf
// https://bugzilla.mozilla.org/show_bug.cgi?id=1937916
generateBuildId = true
}
}

afterEvaluate {
Expand All @@ -138,57 +142,61 @@ afterEvaluate {
variant.productFlavors.each {
productFlavor += "${it.name.capitalize()}"
}
def buildType = "${variant.buildType.name.capitalize()}"
tasks["merge${productFlavor}${buildType}JniLibFolders"].dependsOn(tasks["cargoBuild"])
if (!gradle.hasProperty("mozconfig")) {
def buildType = "${variant.buildType.name.capitalize()}"
tasks["merge${productFlavor}${buildType}JniLibFolders"].dependsOn(tasks["cargoBuild"])
}
}
}

apply from: "$appServicesRootDir/publish.gradle"
ext.configurePublish()

afterEvaluate {
publishing {
publications {
// Publish a second package named `full-megazord-libsForTests` to Maven with the
// `libsForTests` output. This contains the same content as our `libsForTests`
// configuration. Publishing it allows the android-components code to depend on it.
libsForTests(MavenPublication) {
artifact tasks['packageLibsForTest']
artifact file("${projectDir}/../DEPENDENCIES.md"), {
extension "LICENSES.md"
}
pom {
groupId = rootProject.config.componentsGroupId
artifactId = "${project.ext.artifactId}-libsForTests"
description = project.ext.description
// For mavenLocal publishing workflow, increment the version number every publish.
version = rootProject.config.componentsVersion + (rootProject.hasProperty('local') ? '-' + rootProject.property('local') : '')
packaging = "jar"

licenses {
license {
name = libLicense
url = libLicenseUrl
}
if (!gradle.hasProperty("mozconfig")) {
afterEvaluate {
publishing {
publications {
// Publish a second package named `full-megazord-libsForTests` to Maven with the
// `libsForTests` output. This contains the same content as our `libsForTests`
// configuration. Publishing it allows the android-components code to depend on it.
libsForTests(MavenPublication) {
artifact tasks['packageLibsForTest']
artifact file("${projectDir}/../DEPENDENCIES.md"), {
extension "LICENSES.md"
}
pom {
groupId = rootProject.config.componentsGroupId
artifactId = "${project.ext.artifactId}-libsForTests"
description = project.ext.description
// For mavenLocal publishing workflow, increment the version number every publish.
version = rootProject.config.componentsVersion + (rootProject.hasProperty('local') ? '-' + rootProject.property('local') : '')
packaging = "jar"

licenses {
license {
name = libLicense
url = libLicenseUrl
}
}

developers {
developer {
name = 'Sync Team'
email = '[email protected]'
developers {
developer {
name = 'Sync Team'
email = '[email protected]'
}
}
}

scm {
connection = libVcsUrl
developerConnection = libVcsUrl
url = libUrl
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
// This is never the publication we want to use when publishing a
// parent project with us as a child `project()` dependency.
alias = true
}
}
}
}
Expand Down
33 changes: 19 additions & 14 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def setupProject(name, projectProps, appServicesRootDir) {

// project(...) gives us a skeleton project that we can't set ext.* on
gradle.beforeProject { project ->
// applying this plugin to our sub-projects here makes life much easier for m-c.
// Once in m-c, we can probably just remove all publishing capabilities from these crates entirely?
project.apply plugin: 'maven-publish'

// However, the "afterProject" listener iterates over every project and gives us the actual project
// So, once we filter for the project we care about, we can set whatever we want
if (project.name == name) {
Expand Down Expand Up @@ -140,18 +144,19 @@ gradle.projectsLoaded { ->
// Wait until root project is "loaded" before we set "config"
// Note that since this is set on "rootProject.ext", it will be "in scope" during the evaluation of all projects'
// gradle files. This means that they can just access "config.<value>", and it'll function properly

gradle.rootProject.ext.config = new Config(
// You can use -Plocal=true to help with mavenLocal publishing workflow.
// It makes a fake version number that's smaller than any published version,
// which can be depended on specifically by the ./build-scripts/substitute-local-appservices.gradle
// but which is unlikely to be depended on by accident otherwise.
calcVersion(buildconfig), // version,
calcGroupId(buildconfig), // componentsGroupId
17, // jvmTargetCompatibility,
35, // compileSdkVersion,
21, // minSdkVersion,
35, // targetSdkVersion,
"27.2.12479018", // ndkVersion - Keep it in sync in TC Dockerfile.
)
if (!gradle.hasProperty("mozconfig")) {
gradle.rootProject.ext.config = new Config(
// You can use -Plocal=true to help with mavenLocal publishing workflow.
// It makes a fake version number that's smaller than any published version,
// which can be depended on specifically by the ./build-scripts/substitute-local-appservices.gradle
// but which is unlikely to be depended on by accident otherwise.
calcVersion(buildconfig), // version,
calcGroupId(buildconfig), // componentsGroupId
17, // jvmTargetCompatibility,
35, // compileSdkVersion,
21, // minSdkVersion,
35, // targetSdkVersion,
"27.2.12479018", // ndkVersion - Keep it in sync in TC Dockerfile.
)
}
}
2 changes: 1 addition & 1 deletion tools/nimbus-gradle-plugin/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def calcVersion(buildconfig) {
}

gradle.projectsLoaded { ->
// XXX - the above probably needs to be upgraded to actually use "config"??
// Wait until root project is "loaded" before we set "config"
// XXX - there's no "config" here. This should be upgraded to use the same mechanism as the other components?
// Note that since this is set on "rootProject.ext", it will be "in scope" during the evaluation of all projects'
// gradle files. This means that they can just access "config.<value>", and it'll function properly
gradle.rootProject.ext.library = [
Expand Down

0 comments on commit 24044d0

Please sign in to comment.