Skip to content

Commit 63db253

Browse files
committed
Migrate to the new Golang Gradle plugin
1 parent 39fb57c commit 63db253

File tree

4 files changed

+20
-54
lines changed

4 files changed

+20
-54
lines changed

build.gradle.kts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@
22

33
import com.android.build.gradle.AppExtension
44
import com.android.build.gradle.BaseExtension
5-
import java.net.URL
65
import java.util.*
76

87
buildscript {
98
repositories {
109
mavenCentral()
1110
google()
12-
maven("https://raw.githubusercontent.com/MetaCubeX/maven-backup/main/releases")
1311
}
1412
dependencies {
1513
classpath(libs.build.android)
1614
classpath(libs.build.kotlin.common)
1715
classpath(libs.build.kotlin.serialization)
1816
classpath(libs.build.ksp)
19-
classpath(libs.build.golang)
2017
}
2118
}
2219

20+
plugins {
21+
alias(libs.plugins.golang) apply false
22+
}
23+
2324
subprojects {
2425
repositories {
2526
mavenCentral()

core/build.gradle.kts

Lines changed: 12 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,21 @@
1-
import android.databinding.tool.ext.capitalizeUS
2-
import com.github.kr328.golang.GolangBuildTask
3-
import com.github.kr328.golang.GolangPlugin
1+
import io.github.goooler.golang.tasks.GoCompile.Companion.baseOutputDir as goBaseOutputDir
42

53
plugins {
64
kotlin("android")
75
id("com.android.library")
86
id("kotlinx-serialization")
9-
id("golang-android")
7+
alias(libs.plugins.golang)
108
}
119

1210
val golangSource = file("src/main/golang/native")
1311

14-
golang {
15-
sourceSets {
16-
create("alpha") {
17-
tags.set(listOf("foss","with_gvisor","cmfa"))
18-
srcDir.set(file("src/foss/golang"))
19-
}
20-
create("meta") {
21-
tags.set(listOf("foss","with_gvisor","cmfa"))
22-
srcDir.set(file("src/foss/golang"))
23-
}
24-
all {
25-
fileName.set("libclash.so")
26-
packageName.set("cfa/native")
27-
}
28-
}
12+
go {
13+
buildTags = listOf("foss","with_gvisor","cmfa")
14+
outputFileName = "libclash.so"
15+
packageName = "cfa/native"
2916
}
3017

3118
android {
32-
productFlavors {
33-
all {
34-
externalNativeBuild {
35-
cmake {
36-
arguments("-DGO_SOURCE:STRING=${golangSource}")
37-
arguments("-DGO_OUTPUT:STRING=${GolangPlugin.outputDirOf(project, null, null)}")
38-
arguments("-DFLAVOR_NAME:STRING=$name")
39-
}
40-
}
41-
}
42-
}
43-
4419
externalNativeBuild {
4520
cmake {
4621
path = file("src/main/cpp/CMakeLists.txt")
@@ -57,23 +32,11 @@ dependencies {
5732
implementation(libs.kotlin.serialization.json)
5833
}
5934

60-
afterEvaluate {
61-
tasks.withType(GolangBuildTask::class.java).forEach {
62-
it.inputs.dir(golangSource)
63-
}
64-
}
65-
66-
val abis = listOf("arm64-v8a" to "Arm64V8a", "armeabi-v7a" to "ArmeabiV7a", "x86" to "X86", "x86_64" to "X8664")
67-
6835
androidComponents.onVariants { variant ->
69-
val cmakeName = if (variant.buildType == "debug") "Debug" else "RelWithDebInfo"
70-
71-
abis.forEach { (abi, goAbi) ->
72-
tasks.configureEach {
73-
if (name.startsWith("buildCMake$cmakeName[$abi]")) {
74-
dependsOn("externalGolangBuild${variant.name.capitalizeUS()}$goAbi")
75-
println("Set up dependency: $name -> externalGolangBuild${variant.name.capitalizeUS()}$goAbi")
76-
}
77-
}
78-
}
36+
variant.sources.getByName("go").addStaticSourceDirectory("src/foss/golang")
37+
variant.externalNativeBuild?.arguments?.addAll(
38+
"-DGO_SOURCE:STRING=${golangSource}",
39+
"-DGO_OUTPUT:STRING=${goBaseOutputDir.get().asFile}",
40+
"-DFLAVOR_NAME:STRING=${variant.flavorName.orEmpty()}"
41+
)
7942
}

gradle/libs.versions.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ build-android = { module = "com.android.tools.build:gradle", version = "8.13.2"
1010
build-kotlin-common = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
1111
build-kotlin-serialization = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin" }
1212
build-ksp = { module = "com.google.devtools.ksp:symbol-processing-gradle-plugin", version = "2.3.6" }
13-
build-golang = { module = "com.github.kr328.golang:gradle-plugin", version = "1.0.4" }
1413

1514
kotlin-coroutine = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version = "1.10.2" }
1615
kotlin-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version = "1.10.0" }
@@ -33,3 +32,6 @@ rikkax-multiprocess = { module = "dev.rikka.rikkax.preference:multiprocess", ver
3332
quickie-bundled = { module = "io.github.g00fy2.quickie:quickie-bundled", version = "1.11.0" }
3433
okhttp-client = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
3534
okhttp-interceptor = { module = "com.squareup.okhttp3:logging-interceptor", version.ref = "okhttp" }
35+
36+
[plugins]
37+
golang = "io.github.goooler.golang:0.1.0-SNAPSHOT"

settings.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ include(":hideapi")
99

1010
pluginManagement {
1111
repositories {
12-
mavenLocal()
1312
mavenCentral()
1413
gradlePluginPortal()
14+
maven("https://central.sonatype.com/repository/maven-snapshots/")
1515
}
1616
}

0 commit comments

Comments
 (0)