This repository has been archived by the owner on Aug 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
199 lines (164 loc) Β· 5.07 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 2021 Plank
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:Suppress("DSL_SCOPE_VIOLATION")
import io.gitlab.arturbosch.detekt.DetektPlugin
import io.gitlab.arturbosch.detekt.extensions.DetektExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import java.lang.System.getenv
import java.nio.file.Files
import java.nio.file.Paths
import java.util.Properties
plugins {
alias(libs.plugins.kotlin)
alias(libs.plugins.detekt)
alias(libs.plugins.ktlint)
alias(libs.plugins.artifactory)
`maven-publish`
}
repositories {
mavenCentral()
}
allprojects {
apply<DetektPlugin>()
group = "org.plank.llvm4k"
version = "dev"
repositories {
mavenCentral()
}
configure<DetektExtension> {
buildUponDefaultConfig = true
allRules = false
config = files("${rootProject.projectDir}/config/detekt.yml")
baseline = file("${rootProject.projectDir}/config/baseline.xml")
}
}
val localProperties: Properties = rootProject.file("local.properties").let { file ->
val properties = Properties()
if (file.exists()) {
properties.load(file.inputStream())
}
properties
}
val artifactoryUsername: String = localProperties.getProperty("artifactory.username")
?: getenv("ARTIFACTORY_USERNAME").orEmpty()
val artifactoryPassword: String = localProperties.getProperty("artifactory.password")
?: getenv("ARTIFACTORY_PASSWORD").orEmpty()
val hostOs: String = System.getProperty("os.name")
val isMingwX64: Boolean = hostOs.startsWith("Windows")
artifactory {
setContextUrl("https://plank.jfrog.io/artifactory")
publish {
repository {
setRepoKey("default-gradle-dev-local")
setUsername(artifactoryUsername)
setPassword(artifactoryPassword)
setMavenCompatible(true)
}
defaults {
setPublishArtifacts(true)
setPublishPom(true)
publications("jvm", "linuxX64", "mingwX64", "js", "kotlinMultiplatform")
}
}
}
fun locateLlvmConfig(): File {
return getenv("PATH").split(File.pathSeparatorChar)
.map { path ->
if (path.startsWith("'") || path.startsWith("\"")) {
path.substring(1, path.length - 1)
} else {
path
}
}
.map(Paths::get)
.firstOrNull { path -> Files.exists(path.resolve("llvm-config")) }
?.resolve("llvm-config")
?.toFile()
?: error("No suitable version of LLVM was found.")
}
val llvmConfig = localProperties.getProperty("llvm.config")?.let(::File)
?: getenv("LLVM4K_CONFIG")?.let(::File)
?: locateLlvmConfig()
fun cmd(vararg args: String): String {
val command = "${llvmConfig.absolutePath} ${args.joinToString(" ")}"
val process = Runtime.getRuntime().exec(command)
val output = process.inputStream.bufferedReader().readText()
val exitCode = process.waitFor()
if (exitCode != 0) {
error("Command `$command` failed with status code: $exitCode")
}
return output.replace("\n", "")
}
fun String.absolutePath(): String {
return Paths.get(this).toAbsolutePath().toString().replace("\n", "")
}
configure<KotlinMultiplatformExtension> {
explicitApi()
jvm {
withJava()
compilations.all {
kotlinOptions.jvmTarget = "16"
}
testRuns["test"].executionTask.configure {
useJUnitPlatform()
}
}
val linuxX64 = linuxX64("linuxX64")
val mingwX64 = mingwX64("mingwX64")
configure(listOf(linuxX64, mingwX64)) {
val main by compilations.getting
val llvm by main.cinterops.creating {
includeDirs(cmd("--includedir").absolutePath())
}
}
sourceSets {
val commonMain by getting
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val jvmMain by getting {
dependencies {
implementation("org.bytedeco:llvm-platform:13.0.1-1.5.7")
implementation("org.bytedeco:libffi-platform:3.4.2-1.5.7")
implementation("net.java.dev.jna:jna:5.5.0")
}
}
val linuxX64Main by getting
val linuxX64Test by getting
val mingwX64Main by getting
val mingwX64Test by getting
val nativeMain by creating {
dependsOn(commonMain)
linuxX64Main.dependsOn(this)
mingwX64Main.dependsOn(this)
}
val nativeTest by creating {
dependsOn(commonTest)
linuxX64Test.dependsOn(this)
mingwX64Test.dependsOn(this)
}
}
}
afterEvaluate {
val compilation = kotlin.targets["metadata"].compilations["nativeMain"]
compilation.compileKotlinTask.doFirst {
compilation.compileDependencyFiles = compilation.compileDependencyFiles
.filterNot { it.absolutePath.endsWith("klib/common/stdlib") }
.let { files(it) }
}
}