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 new publishCIPackages target in Gradle to make it easier to control which targets to build on a given platform #1607

Merged
merged 12 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 11 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
24 changes: 13 additions & 11 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,11 @@ def genAndStashSwigJNI() {
stash includes: 'packages/jni-swig-stub/build/generated/sources/jni/realmc.cpp,packages/jni-swig-stub/build/generated/sources/jni/realmc.h', name: 'swig_jni'
}
def runBuild() {
def buildJvmAbiFlag = "-PcopyJvmABIs=false"
def buildJvmAbiFlag = "-Prealm.kotlin.copyNativeJvmLibs=false"
if (shouldBuildJvmABIs()) {
unstash name: 'linux_so_file'
unstash name: 'win_dll'
buildJvmAbiFlag = "-PcopyJvmABIs=true"
buildJvmAbiFlag = "-Prealm.kotlin.copyNativeJvmLibs=true"
}

withCredentials([
Expand All @@ -385,7 +385,7 @@ def runBuild() {
}
sh """
cd packages
chmod +x gradlew && ./gradlew publishAllPublicationsToTestRepository ${buildJvmAbiFlag} ${signingFlags} --info --stacktrace --no-daemon
chmod +x gradlew && ./gradlew publishCIPackages ${buildJvmAbiFlag} ${signingFlags} --info --stacktrace --no-daemon
"""
}
}
Expand Down Expand Up @@ -724,19 +724,21 @@ def build_jvm_linux(String buildType) {
unstash name: 'swig_jni'
docker.build('jvm_linux', '-f packages/cinterop/src/jvmMain/generic.Dockerfile .').inside {
sh """
cd packages/cinterop/src/jvmMain/
rm -rf linux-build-dir
mkdir linux-build-dir
cd linux-build-dir
cd packages/cinterop
mkdir build
cd build
rm -rf realmLinuxBuild
mkdir realmLinuxBuild
cd realmLinuxBuild
cmake -DCMAKE_BUILD_TYPE=${buildType} \
-DREALM_ENABLE_SYNC=1 \
-DREALM_NO_TESTS=1 \
-DREALM_BUILD_LIB_ONLY=true \
../../jvm
../../src/jvm
make -j8
"""

stash includes:'packages/cinterop/src/jvmMain/linux-build-dir/librealmc.so', name: 'linux_so_file'
stash includes:'packages/cinterop/build/realmLinuxBuild/librealmc.so', name: 'linux_so_file'
}
}

Expand All @@ -757,9 +759,9 @@ def build_jvm_windows(String buildType) {

def cmakeDefinitions = cmakeOptions.collect { k,v -> "-D$k=$v" }.join(' ')
dir('packages') {
bat "cd cinterop\\src\\jvmMain && rmdir /s /q windows-build-dir & mkdir windows-build-dir && cd windows-build-dir && \"${tool 'cmake'}\" ${cmakeDefinitions} ..\\..\\jvm && \"${tool 'cmake'}\" --build . --config Release"
bat "cd cinterop && rmdir /s /q build & mkdir build & cd build && rmdir /s /q realmWindowsBuild & mkdir realmWindowsBuild && cd realmWindowsBuild && \"${tool 'cmake'}\" ${cmakeDefinitions} ..\\..\\src\\jvm && \"${tool 'cmake'}\" --build . --config Release"
}
stash includes: 'packages/cinterop/src/jvmMain/windows-build-dir/Release/realmc.dll', name: 'win_dll'
stash includes: 'packages/cinterop/build/realmWindowsBuild/Release/realmc.dll', name: 'win_dll'
}

def trackBuildMetrics(version) {
Expand Down
130 changes: 130 additions & 0 deletions packages/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,136 @@ allprojects {
}
}

/**
* Task that will build and publish the defined packages to <root>/packages/build/m2-buildrepo`.
* This is mostly suited for CI jobs that wants to build select publications on specific runners.
*
*
* See `gradle.properties` for specific configuration options available to this task.
*
* For local development, using:
*
* ```
* > ./gradlew publishAllPublicationsToTestRepository
* ```
*
* will build and publish all targets available to the builder platform.
*/
tasks.register("publishCIPackages") {
group = "Publishing"
description = "Publish packages that has been configured for this CI node. See `gradle.properties`."

// Figure out which targets are configured. This will impact which sub modules will be published
val availableTargets = setOf(
"iosArm64",
"iosX64",
"jvm",
"macosX64",
"macosArm64",
"android",
"metadata",
"compilerPlugin",
"gradlePlugin"
)

val mainHostTarget: Set<String> = setOf("metadata") // "kotlinMultiplatform"

val isMainHost: Boolean? = if (project.properties.containsKey("realm.kotlin.mainHost")) {
project.properties["realm.kotlin.mainHost"] == "true"
} else {
null
}
cmelchior marked this conversation as resolved.
Show resolved Hide resolved
// Find user configured platforms (if any)
val userTargets: Set<String>? = (project.properties["realm.kotlin.targets"] as String?)
?.split(",")
?.map { it.trim() }
?.filter { it.isNotEmpty() }
?.toSet()
userTargets?.forEach {
if (!availableTargets.contains(it)) {
project.logger.error("Unknown publication: $it")
throw IllegalArgumentException("Unknown publication: $it")
}
}
// Configure which platforms publications we do want to publish
val wantedTargets: Collection<String> = when (isMainHost) {
cmelchior marked this conversation as resolved.
Show resolved Hide resolved
true -> mainHostTarget + (userTargets ?: availableTargets)
false -> userTargets ?: (availableTargets - mainHostTarget)
null -> availableTargets
}

wantedTargets.forEach { target: String ->
when(target) {
"iosArm64" -> {
dependsOn(
":cinterop:publishIosArm64PublicationToTestRepository",
":cinterop:publishIosSimulatorArm64PublicationToTestRepository",
":library-base:publishIosArm64PublicationToTestRepository",
":library-base:publishIosSimulatorArm64PublicationToTestRepository",
":library-sync:publishIosArm64PublicationToTestRepository",
":library-sync:publishIosSimulatorArm64PublicationToTestRepository",
)
}
"iosX64" -> {
dependsOn(
":cinterop:publishIosX64PublicationToTestRepository",
":library-base:publishIosX64PublicationToTestRepository",
":library-sync:publishIosX64PublicationToTestRepository",
)
}
"jvm" -> {
dependsOn(
":jni-swig-stub:publishAllPublicationsToTestRepository",
":cinterop:publishJvmPublicationToTestRepository",
":library-base:publishJvmPublicationToTestRepository",
":library-sync:publishJvmPublicationToTestRepository",
)
}
"macosX64" -> {
dependsOn(
":cinterop:publishMacosX64PublicationToTestRepository",
":library-base:publishMacosX64PublicationToTestRepository",
":library-sync:publishMacosX64PublicationToTestRepository",
)
}
"macosArm64" -> {
dependsOn(
":cinterop:publishMacosArm64PublicationToTestRepository",
":library-base:publishMacosArm64PublicationToTestRepository",
":library-sync:publishMacosArm64PublicationToTestRepository",
)
}
"android" -> {
dependsOn(
":jni-swig-stub:publishAllPublicationsToTestRepository",
":cinterop:publishAndroidReleasePublicationToTestRepository",
":library-base:publishAndroidReleasePublicationToTestRepository",
":library-sync:publishAndroidReleasePublicationToTestRepository",
)
}
"metadata" -> {
dependsOn(
":cinterop:publishKotlinMultiplatformPublicationToTestRepository",
":library-base:publishKotlinMultiplatformPublicationToTestRepository",
":library-sync:publishKotlinMultiplatformPublicationToTestRepository",
)
}
"compilerPlugin" -> {
dependsOn(
":plugin-compiler:publishAllPublicationsToTestRepository",
":plugin-compiler-shaded:publishAllPublicationsToTestRepository"
)
}
"gradlePlugin" -> {
dependsOn(":gradle-plugin:publishAllPublicationsToTestRepository")
}
else -> {
throw IllegalArgumentException("Unsupported target: $target")
}
}
}
}

tasks.register("uploadDokka") {
dependsOn("dokkaHtmlMultiModule")
group = "Release"
Expand Down
Loading