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

Make it configurable which native libs to copy when building #1631

Merged
merged 1 commit into from
Jan 15, 2024
Merged
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
4 changes: 2 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,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 = "-Prealm.kotlin.copyNativeJvmLibs=false"
def buildJvmAbiFlag = "-Prealm.kotlin.copyNativeJvmLibs="
if (shouldBuildJvmABIs()) {
unstash name: 'linux_so_file'
unstash name: 'win_dll'
buildJvmAbiFlag = "-Prealm.kotlin.copyNativeJvmLibs=true"
buildJvmAbiFlag = "-Prealm.kotlin.copyNativeJvmLibs=windows,linux" // Macos is built in-place
}

withCredentials([
Expand Down
61 changes: 38 additions & 23 deletions packages/cinterop/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import org.jetbrains.kotlin.konan.target.KonanTarget
import java.lang.IllegalArgumentException
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
Expand Down Expand Up @@ -413,31 +414,45 @@ val buildJVMSharedLibs: TaskProvider<Task> by tasks.registering {
* mostly useful on CI.
*/
val copyJVMSharedLibs: TaskProvider<Task> by tasks.registering {
val copyJvmABIs = project.hasProperty("realm.kotlin.copyNativeJvmLibs") && project.property("realm.kotlin.copyNativeJvmLibs") == "true"

val copyJvmABIs = project.hasProperty("realm.kotlin.copyNativeJvmLibs")
&& (project.property("realm.kotlin.copyNativeJvmLibs") as String).isNotEmpty()
logger.info("Copy native Realm JVM libraries: $copyJvmABIs")
if (copyJvmABIs) {
// copy MacOS pre-built binaries
project.file("$buildDir/realmMacOsBuild/librealmc.dylib")
.copyTo(project.file("$jvmJniPath/macos/librealmc.dylib"), overwrite = true)
genHashFile(platform = "macos", prefix = "lib", suffix = ".dylib")

// copy Linux pre-built binaries
project.file("$buildDir/realmLinuxBuild/librealmc.so")
.copyTo(project.file("$jvmJniPath/linux/librealmc.so"), overwrite = true)
genHashFile(platform = "linux", prefix = "lib", suffix = ".so")

// copy Window pre-built binaries
project.file("$buildDir/realmWindowsBuild/Release/realmc.dll")
.copyTo(project.file("$jvmJniPath/windows/realmc.dll"), overwrite = true)
genHashFile(platform = "windows", prefix = "", suffix = ".dll")

// Register copied libraries as output
outputs.file(project.file("$jvmJniPath/macos/librealmc.dylib"))
outputs.file(project.file("$jvmJniPath/macos/dynamic_libraries.properties"))
outputs.file(project.file("$jvmJniPath/linux/librealmc.so"))
outputs.file(project.file("$jvmJniPath/linux/dynamic_libraries.properties"))
outputs.file(project.file("$jvmJniPath/windows/realmc.dll"))
outputs.file(project.file("$jvmJniPath/windows/dynamic_libraries.properties"))
val archs = (project.property("realm.kotlin.copyNativeJvmLibs") as String)
.split(",")
.map { it.trim() }
.map { it.toLowerCase() }

archs.forEach { arch ->
when(arch) {
"linux" -> {
// copy Linux pre-built binaries
project.file("$buildDir/realmLinuxBuild/librealmc.so")
.copyTo(project.file("$jvmJniPath/linux/librealmc.so"), overwrite = true)
genHashFile(platform = "linux", prefix = "lib", suffix = ".so")
outputs.file(project.file("$jvmJniPath/linux/librealmc.so"))
outputs.file(project.file("$jvmJniPath/linux/dynamic_libraries.properties"))
}
"macos" -> {
// copy MacOS pre-built binaries
project.file("$buildDir/realmMacOsBuild/librealmc.dylib")
.copyTo(project.file("$jvmJniPath/macos/librealmc.dylib"), overwrite = true)
genHashFile(platform = "macos", prefix = "lib", suffix = ".dylib")
outputs.file(project.file("$jvmJniPath/macos/librealmc.dylib"))
outputs.file(project.file("$jvmJniPath/macos/dynamic_libraries.properties"))
}
"windows" -> {
// copy Window pre-built binaries
project.file("$buildDir/realmWindowsBuild/Release/realmc.dll")
.copyTo(project.file("$jvmJniPath/windows/realmc.dll"), overwrite = true)
genHashFile(platform = "windows", prefix = "", suffix = ".dll")
outputs.file(project.file("$jvmJniPath/windows/realmc.dll"))
outputs.file(project.file("$jvmJniPath/windows/dynamic_libraries.properties"))
}
else -> throw IllegalArgumentException("Unsupported platfor for realm.kotlin.copyNativeJvmLibs: $arch")
}
}
}
}

Expand Down
18 changes: 11 additions & 7 deletions packages/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,18 @@ realm.kotlin.mainHost=true
# when only building docs or compiler/gradle plugins.
realm.kotlin.buildRealmCore=true

# Whether or not to copy pre-built JVM native files into place, making them
# ready to run or package the final JVM JARs.
# Comma-seperated list of pre-built JVM native files that should be copied into place, making them
# ready to run or package into the final JVM JARs.
#
# The prebuilt files must be placed in this location for this to work:
# - MacOS: <root>/packages/cinterop/build/realmMacOsBuild/librealmc.dylib
# - Linux: <root>/packages/cinterop/build/realmWindowsBuild/librealmc.so
# - Windows: <root>/packages/cinterop/build/realmWindowsBuild/Release/realmc.dll
realm.kotlin.copyNativeJvmLibs=false
# If the list is empty, no files are copied, and must instead be built locally.
#
# The following options are allowed and will copy the prebuilt file if it is placed in the defined location.
# If a platform is enabled, but the file doesn't exist, then the build will crash.
#
# - macos: <root>/packages/cinterop/build/realmMacOsBuild/librealmc.dylib
# - linux: <root>/packages/cinterop/build/realmWindowsBuild/librealmc.so
# - windows: <root>/packages/cinterop/build/realmWindowsBuild/Release/realmc.dll
realm.kotlin.copyNativeJvmLibs=

# See https://kotlinlang.org/docs/mpp-publish-lib.html#publish-an-android-library
# Allow the default dependency name to match the client debug build type. Otherwise the client project has to
Expand Down
Loading