Skip to content

Commit

Permalink
build: fix conditional deploys
Browse files Browse the repository at this point in the history
  • Loading branch information
silenium-dev committed Oct 14, 2024
1 parent 07dc931 commit f002aac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 30 deletions.
6 changes: 4 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ allprojects {

publishing {
publications {
create<MavenPublication>("main") {
from(components["java"])
if (deployKotlin) {
create<MavenPublication>("main") {
from(components["java"])
}
}
}
}
Expand Down
44 changes: 16 additions & 28 deletions native/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import dev.silenium.libs.jni.NativeLoader
import dev.silenium.libs.jni.NativePlatform
import dev.silenium.libs.jni.Platform
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.incremental.createDirectory

buildscript {
Expand All @@ -17,27 +15,24 @@ buildscript {
}

plugins {
alias(libs.plugins.kotlin)
base
`maven-publish`
}

val main: Configuration by configurations.creating

val libName = rootProject.name
val deployNative = (findProperty("deploy.native") as String?)?.toBoolean() ?: true

val withGPL: Boolean = findProperty("ffmpeg.gpl").toString().toBoolean()
val platformExtension = "-gpl".takeIf { withGPL }.orEmpty()
val platformString = findProperty("ffmpeg.platform")?.toString()
val platform = platformString?.let { Platform(it, platformExtension) } ?: NativePlatform.platform(platformExtension)
val platformString = findProperty("deploy.platform")?.toString()
val platform = platformString?.let(Platform::invoke) ?: NativePlatform.platform()

val cmakeExe = findProperty("cmake.executable") as? String ?: "cmake"
val generateMakefile = tasks.register<Exec>("generateMakefile") {
workingDir = layout.buildDirectory.dir("cmake").get().asFile.apply { createDirectory() }
val additionalFlags = mutableListOf(
"-DJAVA_HOME=${System.getProperty("java.home")}",
"-DPROJECT_NAME=${libName}",
"-DFFMPEG_PLATFORM=${platform.osArch}",
"-DFFMPEG_PLATFORM_EXTENSION=${platform.extension}",
"-DFFMPEG_VERSION=${libs.ffmpeg.natives.get().version}",
)
commandLine(
cmakeExe,
Expand All @@ -49,17 +44,14 @@ val generateMakefile = tasks.register<Exec>("generateMakefile") {
inputs.properties(
"JAVA_HOME" to System.getProperty("java.home"),
"PROJECT_NAME" to libName,
"FFMPEG_PLATFORM" to platform.osArch,
"FFMPEG_PLATFORM_EXTENSION" to platform.extension,
"FFMPEG_VERSION" to libs.ffmpeg.natives.get().version,
)
outputs.dir(workingDir)
standardOutput = System.out
}

val compileNative = tasks.register<Exec>("compileNative") {
workingDir = layout.buildDirectory.dir("cmake").get().asFile
commandLine(cmakeExe, "--build", ".", "-j", Runtime.getRuntime().availableProcessors().toString())
commandLine(cmakeExe, "--build", ".")
dependsOn(generateMakefile)

standardOutput = System.out
Expand All @@ -79,14 +71,12 @@ val compileNative = tasks.register<Exec>("compileNative") {
outputs.cacheIf { true }
}

tasks.processResources {
val jar = tasks.register<Jar>("nativeJar") {
dependsOn(compileNative)
// Required for configuration cache
val libName = rootProject.name
val platformString = findProperty("ffmpeg.platform")?.toString()
val withGPL: Boolean = findProperty("ffmpeg.gpl").toString().toBoolean()
val platformExtension = "-gpl".takeIf { withGPL }.orEmpty()
val platform = platformString?.let { Platform(it, platformExtension) } ?: NativePlatform.platform(platformExtension)
val platformString = findProperty("deploy.platform")?.toString()
val platform = platformString?.let(Platform::invoke) ?: NativePlatform.platform()

from(compileNative.get().outputs.files) {
rename {
Expand All @@ -95,19 +85,17 @@ tasks.processResources {
}
}

kotlin {
jvmToolchain(8)
compilerOptions {
jvmTarget = JvmTarget.JVM_1_8
languageVersion = KotlinVersion.KOTLIN_1_7
}
artifacts {
add(main.name, jar)
}

publishing {
publications {
create<MavenPublication>("natives${platform.capitalized}") {
from(components["java"])
artifactId = "$libName-natives-$platform"
if (deployNative) {
create<MavenPublication>("natives${platform.capitalized}") {
artifact(jar)
artifactId = "$libName-natives-$platform"
}
}
}
}

0 comments on commit f002aac

Please sign in to comment.