forked from Fuyukai/Tinlok
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
199 lines (164 loc) · 5.5 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*
* Copyright (C) 2020-2021 Lura Skye Revuwution.
*
* This file is part of Tinlok.
*
* Tinlok is dually released under the GNU Lesser General Public License,
* Version 3 or later, or the Mozilla Public License 2.0.
*/
@file:Suppress("PropertyName")
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import java.nio.file.Path
plugins {
id("org.jetbrains.kotlin.multiplatform").version("1.6.20-RC").apply(false)
id("com.diffplug.spotless").version("6.0.0").apply(false)
id("com.github.ben-manes.versions").version("0.39.0").apply(false)
id("maven-publish")
}
allprojects {
repositories {
mavenCentral()
mavenLocal()
}
}
// == Architecture detection == //
val ARCH = DefaultNativePlatform.getCurrentArchitecture()
val OS = DefaultNativePlatform.getCurrentOperatingSystem()
val DEFAULT_SEARCH_PATHS = listOf("/usr/lib", "/lib").map { Path.of(it) }
/**
* Determines if the current system is AArch64, or if we have a cross-compiler installed.
*/
fun hasAarch64(): Boolean {
return ARCH.isArm
}
/**
* Determines if the current system is AMD64, or if we have a cross-compiler installed.
*/
fun hasAmd64(): Boolean {
return ARCH.isAmd64
}
/**
* Determines if we are Windows or not.
*/
fun hasWindows(): Boolean {
return OS.isWindows
}
// == End architecture detection == //
subprojects {
// ALL projects get the appropriately tracked version
version = "1.4.1"
// all projects get the group
group = "tf.veriny.tinlok"
apply(plugin = "org.jetbrains.kotlin.multiplatform")
apply(plugin = "com.diffplug.spotless")
apply(plugin = "com.github.ben-manes.versions")
//apply(plugin = "org.jetbrains.dokka")
// core kotlin configuration
// (this is collapsed in my IDE)
configure<KotlinMultiplatformExtension> {
explicitApi = ExplicitApiMode.Strict
// == Linux Targets == //
// = AMD64 = //
linuxX64()
// = AArch64 = //
linuxArm64()
// == Darwin Targets == //
// = OSX (Intel) = //
// macosX64()
// == Windows Targets == //
// = Windows (AMD64) = //
mingwX64()
sourceSets {
val commonMain by getting {
dependencies {
// required to stop intellij from flipping out
implementation(kotlin("stdlib"))
implementation(kotlin("reflect"))
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
// native main sourceset, allows us access to cinterop
// and common posix stuff.
val posixMain by creating {
dependsOn(commonMain)
}
// linux sourcesets all share a sourceset
val linuxMain by creating { dependsOn(posixMain) }
val linuxMainX64 = sourceSets.getByName("linuxX64Main")
linuxMainX64.dependsOn(linuxMain)
val linuxMainArm = sourceSets.getByName("linuxArm64Main")
linuxMainArm.dependsOn(linuxMain)
val mingwX64Main by getting { dependsOn(posixMain) }
all {
languageSettings.apply {
enableLanguageFeature("ContextReceivers")
optIn("kotlin.RequiresOptIn")
}
}
}
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions {
freeCompilerArgs = freeCompilerArgs + "-Xgc=cms"
}
}
configure<com.diffplug.gradle.spotless.SpotlessExtension> {
kotlin {
ktlint().userData(mapOf(
"disabled_rules" to "no-wildcard-imports",
"max-line-length" to "100",
))
target("src/**/kotlin/**")
targetExclude("build/generated/**")
licenseHeaderFile(rootProject.file("gradle/LICENCE-HEADER"))
}
}
// core dokka configuration
// (equally collapsed)
/*tasks.named<DokkaTask>("dokkaHtml") {
dokkaSourceSets {
configureEach {
includeNonPublic.set(true)
}
}
}*/
val linkTasks = tasks.filter { it.name.startsWith("link") }
for (task in linkTasks) {
when {
task.name.endsWith("Arm64") -> {
// disable all arm64 tasks, temporarily
task.enabled = hasAarch64()
}
task.name.endsWith("MingwX64") -> {
task.enabled = false
}
task.name.endsWith("X64") -> {
task.enabled = hasAmd64()
}
}
}
}
val sphinxClean = tasks.register<Exec>("sphinxClean") {
group = "documentation"
workingDir = project.rootDir.resolve("docs")
commandLine("poetry run make clean".split(" "))
}
/*val sphinxCopy = tasks.register<Sync>("sphinxCopy") {
group = "documentation"
dependsOn(tasks.named("dokkaHtmlMultiModule"), clean)
from("${project.buildDir}/dokka/htmlMultiModule")
into("${project.rootDir}/docs/_external/_dokka")
}*/
tasks.register<Exec>("sphinxBuild") {
group = "documentation"
dependsOn(sphinxClean)
workingDir = project.rootDir.resolve("docs")
commandLine("poetry run make html".split(" "))
}