forked from scala-cli/scala-cli-signing
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.sc
295 lines (265 loc) · 9.16 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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
import $ivy.`io.github.alexarchambault.mill::mill-native-image::0.1.26`
import $ivy.`io.github.alexarchambault.mill::mill-native-image-upload:0.1.26`
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.30.9"
}
def bouncycastle = ivy"org.bouncycastle:bcpg-jdk18on:1.78.1"
def caseApp = ivy"com.github.alexarchambault::case-app:2.1.0-M29"
def coursierPublish = ivy"io.get-coursier.publish:publish_2.13:0.1.6"
def expecty = ivy"com.eed3si9n.expecty::expecty:0.16.0"
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:1.0.2"
def osLib = ivy"com.lihaoyi::os-lib:0.10.6"
def svm = ivy"org.graalvm.nativeimage:svm:$graalVmVersion"
def graalVmVersion = "22.3.1"
def graalVmId = s"graalvm-java17:$graalVmVersion"
def csDockerVersion = "2.1.12"
}
object Scala {
def scala213 = "2.13.14"
def scala3 = "3.3.3"
}
def ghOrg = "VirtusLab"
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 Cross[Shared](Scala.scala213, Scala.scala3)
trait Shared extends CrossScalaModule with ScalaCliSigningPublish {
override val crossScalaVersion = crossValue
def ivyDeps = super.ivyDeps() ++ Seq(
Deps.jsoniterCore,
Deps.osLib
)
def compileIvyDeps = super.ivyDeps() ++ Seq(
Deps.jsoniterMacros
)
}
trait CliNativeImage extends NativeImage {
def nativeImagePersist = System.getenv("CI") != null
def nativeImageGraalVmJvmId = Deps.graalVmId
def nativeImageName = "scala-cli-signing"
def nativeImageClassPath = `native-cli`.runClasspath()
def nativeImageMainClass = T {
`native-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 Cross[Cli](Scala.scala213, Scala.scala3)
trait Cli extends CrossScalaModule with ScalaCliSigningPublish {
self =>
override val crossScalaVersion = crossValue
def ivyDeps = super.ivyDeps() ++ Seq(
Deps.bouncycastle,
Deps.caseApp,
Deps.coursierPublish // we can probably get rid of that one
)
def moduleDeps = Seq(
shared()
)
def mainClass = Some("scala.cli.signing.ScalaCliSigning")
}
object `native-cli` extends ScalaModule with ScalaCliSigningPublish { self =>
private def scalaVer = Scala.scala3
def scalaVersion = scalaVer
def ivyDeps = super.ivyDeps() ++ Seq(
Deps.svm
)
def moduleDeps = Seq(
cli(scalaVer)
)
def mainClass = cli(scalaVer).mainClass()
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]
override def scalaVersion = Scala.scala3
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 ScalaTests with TestModule.Munit {
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 `jvm-integration` extends Cross[JvmIntegration](Scala.scala213, Scala.scala3)
trait JvmIntegration extends CrossScalaModule with CliTests { self =>
scalaVersion
override val crossScalaVersion = crossValue
def testLauncher = cli(crossScalaVersion).launcher()
def cliKind = "jvm"
object test extends Tests
}
object `native-integration` extends Module {
object native extends CliTests {
def testLauncher = `native-cli`.`base-image`.nativeImage()
def cliKind = "native"
object test extends Tests
}
object static extends CliTests {
def testLauncher = `native-cli`.`static-image`.nativeImage()
def cliKind = "native-static"
object test extends Tests
}
object `mostly-static` extends CliTests {
def testLauncher = `native-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 -> 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(
ghOrg,
ghName,
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
)
}
def copyJvm(jvm: String = Deps.graalVmId, dest: String = "jvm") = T.command {
import sys.process._
val command = os.proc(
"cs",
"java-home",
"--jvm",
jvm,
"--update",
"--ttl",
"0"
)
val baseJavaHome = os.Path(command.call().out.text().trim, os.pwd)
System.err.println(s"Initial Java home $baseJavaHome")
val destJavaHome = os.Path(dest, os.pwd)
os.copy(baseJavaHome, destJavaHome, createFolders = true)
System.err.println(s"New Java home $destJavaHome")
destJavaHome
}
}