Skip to content

Commit

Permalink
build: split publishing of natives and kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
silenium-dev committed Jul 26, 2024
1 parent 2ec5c04 commit 18e8881
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 42 deletions.
4 changes: 2 additions & 2 deletions .github/actions/deploy-ubuntu/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,9 @@ runs:
- name: Publish release
shell: bash
if: "github.event_name == 'release'"
run: ./gradlew build publish -Pffmpeg.gpl=${{ matrix.gpl }} -Pdeploy.version=${{ github.event.release.tag_name }} --console=plain --info --configure-on-demand --parallel --build-cache
run: ./gradlew build publish -Pdeploy.kotlin=false -Pdeploy.native=true -Pffmpeg.gpl=${{ matrix.gpl }} -Pdeploy.version=${{ github.event.release.tag_name }} --console=plain --info --configure-on-demand --parallel --build-cache

- name: Publish snapshot
shell: bash
if: "github.event_name != 'release'"
run: ./gradlew build publish -Pffmpeg.gpl=${{ matrix.gpl }} --console=plain --info --configure-on-demand --parallel --build-cache
run: ./gradlew build publish -Pdeploy.kotlin=false -Pdeploy.native=true -Pffmpeg.gpl=${{ matrix.gpl }} --console=plain --info --configure-on-demand --parallel --build-cache
23 changes: 23 additions & 0 deletions .github/workflows/ffmpeg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,26 @@ jobs:
# steps:
# - uses: actions/checkout@v4
# - uses: ./.github/actions/redeploy
deploy-kotlin:
name: Publish Kotlin artifacts
runs-on: ubuntu-22.04
steps:
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
cache-encryption-key: ${{ inputs.gradle-cache-encryption-key }}
gradle-home-cache-cleanup: true
build-scan-publish: true
build-scan-terms-of-use-url: "https://gradle.com/terms-of-service"
build-scan-terms-of-use-agree: "yes"
add-job-summary-as-pr-comment: on-failure

- name: Publish release
shell: bash
if: "github.event_name == 'release'"
run: ./gradlew build publish -Pdeploy.native=false -Pdeploy.kotlin=true -Pffmpeg.gpl=${{ matrix.gpl }} -Pdeploy.version=${{ github.event.release.tag_name }} --console=plain --info --configure-on-demand --parallel --build-cache

- name: Publish snapshot
shell: bash
if: "github.event_name != 'release'"
run: ./gradlew build publish -Pdeploy.native=false -Pdeploy.kotlin=true -Pffmpeg.gpl=${{ matrix.gpl }} --console=plain --info --configure-on-demand --parallel --build-cache
97 changes: 57 additions & 40 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,52 +32,61 @@ dependencies {
implementation(libs.jni.utils)
}

val withGPL: Boolean = findProperty("ffmpeg.gpl")?.toString()?.toBoolean() ?: false
val deployKotlin = (findProperty("deploy.kotlin") as String?)?.toBoolean() ?: true
val deployNative = (findProperty("deploy.native") as String?)?.toBoolean() ?: true
val withGPL: Boolean = findProperty("ffmpeg.gpl").toString().toBoolean()
val platformExtension = "-gpl".takeIf { withGPL }.orEmpty()
val platform = NativePlatform.platform(platformExtension)

val compileNative by tasks.registering(Exec::class) {
commandLine(
"bash",
layout.projectDirectory.file("cppbuild.sh").asFile.absolutePath,
"-extension", platform.extension,
"-platform", platform.osArch,
"install", "ffmpeg",
)
workingDir(layout.projectDirectory.asFile)
val compileNative = if(deployNative) {
tasks.register<Exec>("compileNative") {
enabled = deployNative
commandLine(
"bash",
layout.projectDirectory.file("cppbuild.sh").asFile.absolutePath,
"-extension", platform.extension,
"-platform", platform.osArch,
"install", "ffmpeg",
)
workingDir(layout.projectDirectory.asFile)

inputs.property("platform", platform)
inputs.files(layout.projectDirectory.files("cppbuild.sh"))
inputs.files(layout.projectDirectory.files("detect-platform.sh"))
inputs.files(layout.projectDirectory.files("ffmpeg/cppbuild.sh"))
inputs.files(layout.projectDirectory.files("ffmpeg/*.patch"))
inputs.files(layout.projectDirectory.files("ffmpeg/*.diff"))
outputs.dir(layout.projectDirectory.dir("ffmpeg/cppbuild/${platform}"))
outputs.cacheIf { true }
}
inputs.property("platform", platform)
inputs.files(layout.projectDirectory.files("cppbuild.sh"))
inputs.files(layout.projectDirectory.files("detect-platform.sh"))
inputs.files(layout.projectDirectory.files("ffmpeg/cppbuild.sh"))
inputs.files(layout.projectDirectory.files("ffmpeg/*.patch"))
inputs.files(layout.projectDirectory.files("ffmpeg/*.diff"))
outputs.dir(layout.projectDirectory.dir("ffmpeg/cppbuild/${platform}"))
outputs.cacheIf { true }
}
} else null

tasks.processResources {
val platform = NativePlatform.platform(platformExtension)
val nativesJar = if (deployNative) {
tasks.register<Jar>("nativesJar") {
val platform = NativePlatform.platform(platformExtension)

from(compileNative.get().outputs.files) {
include("lib/*.so")
include("lib/*.dll")
include("lib/*.dylib")
eachFile {
path = "natives/$platform/$name"
from(compileNative!!.get().outputs.files) {
include("lib/*.so")
include("lib/*.dll")
include("lib/*.dylib")
eachFile {
path = "natives/$platform/$name"
}
into("natives/$platform/")
}
into("natives/$platform/")
}
}
} else null

val zipBuild by tasks.registering(Zip::class) {
from(compileNative.get().outputs.files) {
include("bin/**/*")
include("include/**/*")
include("lib/**/*")
include("share/**/*")
val zipBuild = if (deployNative) {
tasks.register<Zip>("zipBuild") {
from(compileNative!!.get().outputs.files) {
include("bin/**/*")
include("include/**/*")
include("lib/**/*")
include("share/**/*")
}
}
}
} else null

kotlin {
compilerOptions {
Expand All @@ -93,10 +102,18 @@ java {

publishing {
publications {
create<MavenPublication>("native${platform.capitalized}") {
from(components["java"])
artifact(zipBuild)
artifactId = "ffmpeg-natives-${platform}"
if (deployNative) {
create<MavenPublication>("native${platform.capitalized}") {
artifact(nativesJar)
artifact(zipBuild)
artifactId = "ffmpeg-natives-${platform}"
}
}
if (deployKotlin) {
create<MavenPublication>("kotlin") {
from(components["java"])
artifactId = "ffmpeg-natives"
}
}
}

Expand Down

0 comments on commit 18e8881

Please sign in to comment.