Skip to content
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ live_view_native_jetpack-*.tar

# compiled static assets from test suites
priv/static

# host libs
core-jetpack-desktop-libs/jniLibs/**/*.so
core-jetpack-desktop-libs/jniLibs/**/*.dylib
60 changes: 44 additions & 16 deletions buildSrc/src/main/kotlin/Util.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,47 @@
import org.gradle.api.tasks.testing.Test
import org.gradle.api.GradleException
import org.gradle.kotlin.dsl.withGroovyBuilder
import java.io.File

// TODO The Core-Jetpack project only generates the native platform library files for the
// following architectures (arm, arm64, x86, and x86_64). In order to run the tests in the local
// machine, we need the library for the host machine. For now, this file is being generated by
// adding the "darwin-aarch64" (or "darwin-x86-64" for Intel Macbooks) target, and running the
// following command in the Core-Jetpack project: `./gradlew assembleRelease`.
// The library files are generated at "core/build/rustJniLibs/desktop" directory. The ideal
// solution is release a dependency just for unit tests and declare at the `dependencies` section
// above like:
// `testImplementation "com.github.liveview-native:liveview-native-core-jetpack-host:<version>"`
fun copyDesktopJniLibs(rootDir: File, test: Test) {
val jniLibsForDesktopDir = File("$rootDir/core-jetpack-desktop-libs/jniLibs")

test.systemProperty("java.library.path", jniLibsForDesktopDir.absolutePath)
test.systemProperty("jna.library.path", jniLibsForDesktopDir.absolutePath)
test.classpath = test.classpath.plus(test.project.files(jniLibsForDesktopDir.absolutePath))
}
fun copyDesktopJniLibs(rootDir: File, test: Test, coreVersion: String) {
val currentArch = when {
org.gradle.internal.os.OperatingSystem.current().isMacOsX -> "darwin-aarch64"
org.gradle.internal.os.OperatingSystem.current().isLinux -> "linux-x86-64"
else -> throw GradleException("unsupported OS")
}

val libsDir = File("${rootDir}/build/nativeLibs/$currentArch")
val outputFile = File("${libsDir}/liveview-native-core-$currentArch.jar")

libsDir.mkdirs()

val url = "https://github.com/liveview-native/liveview-native-core/releases/download/$coreVersion/liveview-native-core-$currentArch.jar"

test.ant.withGroovyBuilder {
"get"(
"src" to url,
"dest" to outputFile.absolutePath,
"verbose" to true
)
}

println(outputFile.absolutePath)

if (outputFile.exists()) {
test.classpath += test.project.files(outputFile)

val jniLibsDir = File("${rootDir}/core-jetpack-desktop-libs/jniLibs/$currentArch")
jniLibsDir.mkdirs()

test.project.copy {
from(test.project.zipTree(outputFile))
into(jniLibsDir)
include("*.so", "*.dylib", "*.dll")
}

test.systemProperty("java.library.path", jniLibsDir.absolutePath)
test.systemProperty("jna.library.path", jniLibsDir.absolutePath)
} else {
println("native library JAR not found at ${outputFile.absolutePath}")
}
}
9 changes: 7 additions & 2 deletions client-addons/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ dependencies {
// Configuring Java Lib Path in order to find the native library before running the Unit Tests
tasks.withType<Test>().configureEach {
doFirst {
copyDesktopJniLibs(rootDir, this@configureEach)
val coreVersion = project.extensions.getByType<VersionCatalogsExtension>()
.named("libs")
.findVersion("liveview-native-core-jetpack")
.get()
.toString()
copyDesktopJniLibs(rootDir, this@configureEach, coreVersion)
}
}

Expand All @@ -86,4 +91,4 @@ publishing {
}
}
}
}
}
7 changes: 6 additions & 1 deletion client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,12 @@ tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach
// Configuring Java Lib Path in order to find the native library before running the Unit Tests
tasks.withType<Test>().configureEach {
doFirst {
copyDesktopJniLibs(rootDir, this@configureEach)
val coreVersion = project.extensions.getByType<VersionCatalogsExtension>()
.named("libs")
.findVersion("liveview-native-core-jetpack")
.get()
.toString()
copyDesktopJniLibs(rootDir, this@configureEach, coreVersion)
}
}

Expand Down
Loading