-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sbt
76 lines (70 loc) · 2.3 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
import sys.process._
import java.io.File
import sbt.nio.file.FileTreeView
Global / onChangedBuildSource := ReloadOnSourceChanges
val scala3Version = "3.2.2"
val cargoBuild = taskKey[Unit]("cd ./glue; cargo build")
val ejectHeaders = taskKey[Unit]("Generate C headers for FFI")
val fullBuild = taskKey[Unit]("cargoBuild > ejectHeaders")
val glob = settingKey[Map[String, Glob]]("globs")
val path = settingKey[Map[String, String]]("paths")
fork := true
javaOptions += "--enable-preview"
lazy val root = project
.in(file("."))
.settings(
name := "toad",
version := "0.1.0-SNAPSHOT",
scalaVersion := scala3Version,
libraryDependencies += "org.scalameta" %% "munit" % "0.7.29" % Test,
glob := Map(
"java.sources" -> baseDirectory.value.toGlob / "src" / "main" / "java" / ** / "*.java",
"glue.sources" -> baseDirectory.value.toGlob / "glue" / "src" / ** / "*.rs"
),
path := Map(
"glue.base" -> (baseDirectory.value / "glue").toString,
"glue.target" -> (baseDirectory.value / "target" / "glue" / "debug").toString,
"java.classTarget" -> (baseDirectory.value / "target" / "scala-3.2.2" / "classes").toString
),
Test / javaOptions ++= Seq(
"-Djava.library.path=" ++ path.value("glue.target")
),
Compile / doc / javacOptions ++= Seq(
"--enable-preview",
"--release",
"20"
),
Compile / compile / javacOptions ++= Seq(
"--enable-preview",
"--release",
"20",
"-Xlint:unchecked",
"-Xlint:deprecation"
),
ejectHeaders := {
val files =
FileTreeView.default.iterator(glob.value("java.sources")).foldLeft("") {
(s, fd) => s + " " + fd._1.toString
}
val cmd =
Seq(
"javac",
"--enable-preview",
"--release 20",
"-h " + path.value("glue.target"),
"-d " + path.value("java.classTarget"),
files
)
.foldLeft("")((s, a) => s + " " + a)
println(Seq("sh", "-c", cmd) !!)
},
cargoBuild := {
println(Seq("sh", "-c", "cd glue; cargo rustc -- -Awarnings") !!)
},
fullBuild := {
cargoBuild.value
ejectHeaders.value
},
Compile / compile := (Compile / compile dependsOn fullBuild).value,
Compile / compile / watchTriggers += glob.value("glue.sources")
)