-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sc
270 lines (239 loc) · 8.08 KB
/
build.sc
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
import $ivy.`io.github.alexarchambault.mill::mill-native-image::0.1.20-2`
import $ivy.`io.github.alexarchambault.mill::mill-native-image-upload:0.1.20-2`
import $file.publish, publish.{finalPublishVersion, publishSonatype => publishSonatype0}
import io.github.alexarchambault.millnativeimage.NativeImage
import io.github.alexarchambault.millnativeimage.upload.Upload
import mill._, scalalib._
import java.io.File
object Deps {
object Versions {
def jsoniterScala = "2.13.7"
}
def bouncycastle = ivy"org.bouncycastle:bcpg-jdk15on:1.68"
def caseApp = ivy"com.github.alexarchambault::case-app:2.1.0-M13"
def coursierPublish = ivy"io.get-coursier.publish::publish:0.1.0"
def expecty = ivy"com.eed3si9n.expecty::expecty:0.15.4"
def jsoniterCore =
ivy"com.github.plokhotnyuk.jsoniter-scala::jsoniter-scala-core:${Versions.jsoniterScala}"
def jsoniterMacros =
ivy"com.github.plokhotnyuk.jsoniter-scala::jsoniter-scala-macros:${Versions.jsoniterScala}"
def munit = ivy"org.scalameta::munit:0.7.29"
def osLib = ivy"com.lihaoyi::os-lib:0.8.1"
def svm = ivy"org.graalvm.nativeimage:svm:$graalVmVersion"
def graalVmVersion = "22.0.0"
def graalVmId = s"graalvm-java17:$graalVmVersion"
def csDockerVersion = "2.1.0-M5-18-gfebf9838c"
}
object Scala {
def scala213 = "2.13.8"
}
def ghOrg = "VirtuslabRnD"
def ghName = "scala-cli-signing"
trait ScalaCliSigningPublish extends PublishModule {
import mill.scalalib.publish._
def pomSettings = PomSettings(
description = artifactName(),
organization = "org.virtuslab.scala-cli.signing",
url = s"https://github.com/$ghOrg/$ghName",
licenses = Seq(License.`Apache-2.0`),
versionControl = VersionControl.github(ghOrg, ghName),
developers = Seq(
Developer("alexarchambault", "Alex Archambault", "https://github.com/alexarchambault")
)
)
def publishVersion = finalPublishVersion()
}
object shared extends ScalaModule with ScalaCliSigningPublish {
def scalaVersion = Scala.scala213
def ivyDeps = super.ivyDeps() ++ Seq(
Deps.jsoniterCore,
Deps.jsoniterMacros,
Deps.osLib
)
}
object `cli-options` extends ScalaModule with ScalaCliSigningPublish {
def scalaVersion = Scala.scala213
def ivyDeps = super.ivyDeps() ++ Seq(
Deps.caseApp
)
def moduleDeps = Seq(
shared
)
}
trait CliNativeImage extends NativeImage {
def nativeImagePersist = System.getenv("CI") != null
def nativeImageGraalVmJvmId = Deps.graalVmId
def nativeImageName = "scala-cli-signing"
def nativeImageClassPath = cli.runClasspath()
def nativeImageMainClass = T {
cli.mainClass().getOrElse(sys.error("no main class found"))
}
def nativeImageOptions = super.nativeImageOptions() ++ Seq(
"--no-fallback",
"--rerun-class-initialization-at-runtime=org.bouncycastle.jcajce.provider.drbg.DRBG$Default,org.bouncycastle.jcajce.provider.drbg.DRBG$NonceAndIV"
)
def nameSuffix = ""
def copyToArtifacts(directory: String = "artifacts/") = T.command {
val _ = Upload.copyLauncher(
nativeImage().path,
directory,
"scala-cli-signing",
compress = true,
suffix = nameSuffix
)
}
}
object cli extends ScalaModule with ScalaCliSigningPublish { self =>
def scalaVersion = Scala.scala213
def ivyDeps = super.ivyDeps() ++ Seq(
Deps.bouncycastle,
Deps.caseApp,
Deps.coursierPublish, // we can probably get rid of that one
Deps.svm
)
def moduleDeps = Seq(
`cli-options`
)
def mainClass = Some("scala.cli.signing.ScalaCliSigning")
object `base-image` extends CliNativeImage
object `static-image` extends CliNativeImage {
private def helperImageName = "scala-cli-signing-musl"
def nativeImageDockerParams = T {
buildHelperImage()
Some(
NativeImage.linuxStaticParams(
s"$helperImageName:latest",
s"https://github.com/coursier/coursier/releases/download/v${Deps.csDockerVersion}/cs-x86_64-pc-linux.gz"
)
)
}
def buildHelperImage = T {
os.proc("docker", "build", "-t", helperImageName, ".")
.call(cwd = os.pwd / "project" / "musl-image", stdout = os.Inherit)
()
}
def writeNativeImageScript(scriptDest: String, imageDest: String = "") = T.command {
buildHelperImage()
super.writeNativeImageScript(scriptDest, imageDest)()
}
def nameSuffix = "-static"
}
object `mostly-static-image` extends CliNativeImage {
def nativeImageDockerParams = Some(
NativeImage.linuxMostlyStaticParams(
"ubuntu:18.04", // TODO Pin that
s"https://github.com/coursier/coursier/releases/download/v${Deps.csDockerVersion}/cs-x86_64-pc-linux.gz"
)
)
def nameSuffix = "-mostly-static"
}
}
def tmpDirBase = T.persistent {
PathRef(T.dest / "working-dir")
}
trait CliTests extends ScalaModule {
def testLauncher: T[PathRef]
def cliKind: T[String]
def scalaVersion = Scala.scala213
def prefix = "integration-"
private def updateRef(name: String, ref: PathRef): PathRef = {
val rawPath = ref.path.toString.replace(
File.separator + name + File.separator,
File.separator
)
PathRef(os.Path(rawPath))
}
private def mainArtifactName = T(artifactName())
def modulesPath = T {
val name = mainArtifactName().stripPrefix(prefix)
val baseIntegrationPath = os.Path(millSourcePath.toString.stripSuffix(name))
val p = os.Path(
baseIntegrationPath.toString.stripSuffix(baseIntegrationPath.baseName)
)
PathRef(p)
}
def sources = T.sources {
val mainPath = PathRef(modulesPath().path / "integration" / "src" / "main" / "scala")
super.sources() ++ Seq(mainPath)
}
def resources = T.sources {
val mainPath = PathRef(modulesPath().path / "integration" / "src" / "main" / "resources")
super.resources() ++ Seq(mainPath)
}
trait Tests extends super.Tests {
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.expecty,
Deps.munit
)
def testFramework = "munit.Framework"
def forkArgs = super.forkArgs() ++ Seq("-Xmx512m", "-Xms128m")
def forkEnv = super.forkEnv() ++ Seq(
"SIGNING_CLI" -> testLauncher().path.toString,
"SIGNING_CLI_KIND" -> cliKind(),
"SIGNING_CLI_TMP" -> tmpDirBase().path.toString
)
def sources = T.sources {
val name = mainArtifactName().stripPrefix(prefix)
super.sources().flatMap { ref =>
Seq(updateRef(name, ref), ref)
}
}
def resources = T.sources {
val name = mainArtifactName().stripPrefix(prefix)
super.resources().flatMap { ref =>
Seq(updateRef(name, ref), ref)
}
}
}
}
object integration extends Module {
object jvm extends CliTests {
def testLauncher = cli.launcher()
def cliKind = "jvm"
object test extends Tests
}
object native extends CliTests {
def testLauncher = cli.`base-image`.nativeImage()
def cliKind = "native"
object test extends Tests
}
object static extends CliTests {
def testLauncher = cli.`static-image`.nativeImage()
def cliKind = "native-static"
object test extends Tests
}
object `mostly-static` extends CliTests {
def testLauncher = cli.`mostly-static-image`.nativeImage()
def cliKind = "native-mostly-static"
object test extends Tests
}
}
object ci extends Module {
def upload(directory: String = "artifacts/") = T.command {
val version = finalPublishVersion()
val path = os.Path(directory, os.pwd)
val launchers = os.list(path).filter(os.isFile(_)).map { path =>
path.toNIO -> path.last
}
val ghToken = Option(System.getenv("UPLOAD_GH_TOKEN")).getOrElse {
sys.error("UPLOAD_GH_TOKEN not set")
}
val (tag, overwriteAssets) =
if (version.endsWith("-SNAPSHOT")) ("launchers", true)
else ("v" + version, false)
Upload.upload(
"VirtuslabRnD",
"scala-cli-signing",
ghToken,
tag,
dryRun = false,
overwrite = overwriteAssets
)(launchers: _*)
}
def publishSonatype(tasks: mill.main.Tasks[PublishModule.PublishData]) = T.command {
publishSonatype0(
data = define.Target.sequence(tasks.value)(),
log = T.ctx().log
)
}
}