This repository has been archived by the owner on May 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.gradle.kts
178 lines (158 loc) · 5.02 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import org.jetbrains.kotlin.incremental.deleteRecursivelyOrThrow
import java.nio.file.Paths
import kotlin.io.path.copyTo
buildscript {
extra.apply {
set("sdk_version", "v0.7.1")
set("kotlin_version", "1.7.0")
}
repositories {
google()
mavenCentral()
maven {
url = java.net.URI("https://plugins.gradle.org/m2/")
}
}
dependencies {
classpath("com.android.tools.build:gradle:7.0.4")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${project.extra.get("kotlin_version")}")
classpath("org.mozilla.rust-android-gradle:plugin:0.9.3")
}
}
tasks.create("clean", type = Delete::class) {
delete(rootProject.buildDir)
subprojects.forEach {
it.afterEvaluate {
it.tasks.findByName("clean").let { subCleanTask ->
if (subCleanTask != null) {
dependsOn(subCleanTask)
}
}
}
}
}
val archs = listOf(
"x86_64-linux-android",
"i686-linux-android",
"aarch64-linux-android",
"armv7-linux-androideabi"
)
val root = project.rootProject.rootDir.toPath()
val stage = root.resolve("build").resolve("release")
archs.forEach { arch ->
// TODO: abstract cargo build
tasks.create("build-uplink-$arch") {
description = "build exe for $arch"
doLast {
val pb = ProcessBuilder()
.command(
"cargo",
"ndk",
"--platform",
"23",
"--target",
arch,
"build",
"--release",
"--bin",
"uplink"
)
.directory(File("uplink"))
val process = pb.start()
println(String(process.inputStream.readAllBytes()))
println(String(process.errorStream.readAllBytes()))
if (process.waitFor() != 0) {
throw Exception("cargo build failed")
}
}
}
tasks.create("build-utilities-$arch") {
description = "build utilities for $arch"
doLast {
val pb = ProcessBuilder()
.command(
"cargo",
"ndk",
"--platform",
"23",
"--target",
arch,
"build",
"--release",
)
.directory(root.resolve("utilities").toFile())
val process = pb.start()
println(String(process.inputStream.readAllBytes()))
println(String(process.errorStream.readAllBytes()))
if (process.waitFor() != 0) {
throw Exception("cargo build failed")
}
}
}
task("template-$arch", type = Copy::class) {
description = "copy module template for $arch"
from(root.resolve("module_template"))
into(stage.resolve(arch))
}
task("copy-uplink-$arch", type = Copy::class) {
from(Paths.get("uplink/target/$arch/release/uplink"))
into(stage.resolve(arch).resolve("bin"))
}
task("copy-utilities-$arch", type = Copy::class) {
arrayOf("logrotate", "uplink_watchdog").forEach { utility ->
from(root.resolve(root.resolve(Paths.get("utilities", "target", arch, "release", utility))))
}
into(stage.resolve(arch).resolve("bin"))
}
task("module-dir-$arch") {
description = "create module for $arch"
dependsOn(
"build-uplink-$arch",
"build-utilities-$arch",
"template-$arch",
"copy-uplink-$arch",
"copy-utilities-$arch"
)
}
task("module-$arch") {
description = "module archive for $arch"
dependsOn("module-dir-$arch")
doLast {
// create tar gz of module directory
val pb = ProcessBuilder()
.command(
"tar",
"cf",
"$arch.tar.gz",
"-C",
arch,
".",
)
.directory(stage.toFile())
val process = pb.start()
println(String(process.inputStream.readAllBytes()))
println(String(process.errorStream.readAllBytes()))
// stage.resolve(arch).toFile().deleteRecursivelyOrThrow()
if (process.waitFor() != 0) {
throw Exception("tar failed")
}
}
}
}
tasks.create("copy-lib", type = Copy::class) {
dependsOn("lib:assembleRelease")
from(root.resolve(Paths.get("lib", "build", "outputs", "aar", "uplink-release.aar")))
into(stage)
rename("uplink-release.aar", "uplink_${project.extra.get("sdk_version")}.aar")
}
tasks.create("buildArtifacts") {
dependsOn("clean")
archs.forEach { arch ->
dependsOn("module-$arch")
}
dependsOn("copy-lib")
}
fun<T> trace(value: T) : T {
println(value)
return value
}