diff --git a/.gitignore b/.gitignore index 00b88e78..66391ad6 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/buildSrc/src/main/kotlin/Util.kt b/buildSrc/src/main/kotlin/Util.kt index 23bccfa3..783ab518 100644 --- a/buildSrc/src/main/kotlin/Util.kt +++ b/buildSrc/src/main/kotlin/Util.kt @@ -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:"` -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)) -} \ No newline at end of file +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}") + } +} diff --git a/client-addons/build.gradle.kts b/client-addons/build.gradle.kts index 05c1c2e3..366a7d5b 100644 --- a/client-addons/build.gradle.kts +++ b/client-addons/build.gradle.kts @@ -70,7 +70,12 @@ dependencies { // Configuring Java Lib Path in order to find the native library before running the Unit Tests tasks.withType().configureEach { doFirst { - copyDesktopJniLibs(rootDir, this@configureEach) + val coreVersion = project.extensions.getByType() + .named("libs") + .findVersion("liveview-native-core-jetpack") + .get() + .toString() + copyDesktopJniLibs(rootDir, this@configureEach, coreVersion) } } @@ -86,4 +91,4 @@ publishing { } } } -} \ No newline at end of file +} diff --git a/client/build.gradle.kts b/client/build.gradle.kts index 5a2e6d11..14629a59 100755 --- a/client/build.gradle.kts +++ b/client/build.gradle.kts @@ -160,7 +160,12 @@ tasks.withType().configureEach // Configuring Java Lib Path in order to find the native library before running the Unit Tests tasks.withType().configureEach { doFirst { - copyDesktopJniLibs(rootDir, this@configureEach) + val coreVersion = project.extensions.getByType() + .named("libs") + .findVersion("liveview-native-core-jetpack") + .get() + .toString() + copyDesktopJniLibs(rootDir, this@configureEach, coreVersion) } }