-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sbt
169 lines (142 loc) · 5.13 KB
/
build.sbt
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
import sbtassembly.AssemblyPlugin.defaultUniversalScript
import java.nio.file.{Paths, Files}
import scala.sys.process._
val scala3Version = "3.3.1"
// Scala options
ThisBuild / scalacOptions := Seq(
"-language:implicitConversions", // allow implicit conversions
"-deprecation", // emit warning and location for usages of deprecated APIs
"-explain", // explain errors in more detail
"-explain-types", // explain type errors in more detail
"-feature", // emit warning for features that should be imported explicitly
"-unchecked", // enable warnings where generated code depends on assumptions
)
// Java options
ThisBuild / javacOptions ++= Seq(
"-encoding",
"UTF-8",
)
// Java options for assembly
lazy val assemblyJavaOpts = Seq(
"-Xms1g",
"-Xmx3g",
"-XX:ReservedCodeCacheSize=512m",
"-Dfile.encoding=utf8",
)
// assembly setting
ThisBuild / assemblyPrependShellScript := Some(
assemblyJavaOpts.map("JAVA_OPTS=\"" + _ + " $JAVA_OPTS\"") ++
defaultUniversalScript(shebang = false),
)
// automatic reload build.sbt
Global / onChangedBuildSource := ReloadOnSourceChanges
// Metals requires the semanticdb compiler plugin
Global / semanticdbEnabled := true
// T2 project
val buildFHElibs = taskKey[Unit]("Build FHE libraries")
buildFHElibs := {
val s: TaskStreams = streams.value
val log = s.log
val baseDir = baseDirectory.value.getAbsolutePath
val T2baseDir = s"$baseDir/src/main/java/T2-FHE-Compiler-and-Benchmarks"
val processLogger = new ProcessLogger {
def out(s: => String): Unit = log.info(s)
def err(s: => String): Unit = log.error(s)
def buffer[T](f: => T): T = f
}
log.info("Clone FHE libraries")
val cloneScript = s"$T2baseDir/.circleci/clone_libs.sh"
Process(cloneScript, new File(T2baseDir)).!(processLogger)
log.info("Build FHE libraries")
val buildScript = s"$T2baseDir/.circleci/build_libs.sh"
Process(buildScript, new File(T2baseDir)).!(processLogger)
}
val buildT2 =
taskKey[Unit]("Build the T2 project and copy the JAR to Scala project")
buildT2 := {
val s: TaskStreams = streams.value
val log = s.log
val baseDir = baseDirectory.value.getAbsolutePath
val T2baseDir = s"$baseDir/src/main/java/T2-FHE-Compiler-and-Benchmarks"
log.info("Running mvn initialize and package")
Process("mvn package -Dmaven.test.skip", new File(T2baseDir)).!
val sourcePath = s"$T2baseDir/target/terminator-compiler-1.0.jar"
val destinationPath = "lib/"
val sourceFile = new File(sourcePath)
val destinationFile = new File(destinationPath)
IO.copyFile(sourceFile, destinationFile / sourceFile.getName)
}
val copyJar = taskKey[Unit]("Copy the compiled JAR to Scala project")
copyJar := {
val s: TaskStreams = streams.value
val log = s.log
val baseDir = baseDirectory.value.getAbsolutePath
val T2baseDir = s"$baseDir/src/main/java/T2-FHE-Compiler-and-Benchmarks"
}
// Generate ProjectSettings.scala to get the project home directory
Compile / sourceGenerators += Def.task {
val file =
(Compile / sourceManaged).value / "settings" / "ProjectSettings.scala"
val content =
s"""
|package settings
|
|object ProjectSettings {
| val projectHome = "${(ThisBuild / baseDirectory).value.getAbsolutePath
.replace("\\", "\\\\")}"
|}
""".stripMargin
IO.write(file, content)
Seq(file)
}.taskValue
Compile / unmanagedSourceDirectories := {
(Compile / scalaSource).value :: (Compile / resourceDirectory).value :: Nil
}
Test / parallelExecution := true
lazy val basicTest = taskKey[Unit]("Launch basic tests")
lazy val advancedTest = taskKey[Unit]("Launch advanced tests")
lazy val binAdvancedTest = taskKey[Unit]("Launch binary advanced tests")
lazy val arithAdvancedTest = taskKey[Unit]("Launch arithmetic advanced tests")
lazy val interpTest = taskKey[Unit]("Launch interpretation tests")
basicTest := (Test / testOnly).toTask(" *BasicTest").value
advancedTest := (Test / testOnly).toTask(" *AdvancedTest").value
binAdvancedTest := (Test / testOnly).toTask(" *BinAdvancedTest").value
arithAdvancedTest := (Test / testOnly).toTask(" *ArithAdvancedTest").value
interpTest := (Test / testOnly).toTask(" *InterpTest").value
lazy val root = project
.in(file("."))
.settings(
name := "FHETest",
version := "0.1.0-SNAPSHOT",
scalaVersion := scala3Version,
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.2.11" % Test,
"org.twc" % "t2" % "1.0" from file(
"lib/terminator-compiler-1.0.jar",
).toURI.toString,
"io.circe" %% "circe-core" % "0.14.1",
"io.circe" %% "circe-generic" % "0.14.1",
"io.circe" %% "circe-parser" % "0.14.1",
),
// set the main class for 'sbt run'
Compile / mainClass := Some("fhetest.FHETest"),
// assembly setting
assembly / test := {},
assembly / assemblyOutputPath := file("bin/fhetest"),
)
// format all files
lazy val format = taskKey[Unit]("format all files")
format := Def
.sequential(
Compile / scalafmtAll,
Compile / scalafmtSbt,
)
.value
// format check all files
lazy val formatCheck = taskKey[Unit]("format check all files")
formatCheck := Def
.sequential(
Compile / scalafmtCheckAll,
Compile / scalafmtSbtCheck,
)
.value