toad-java/build.sbt

77 lines
2.3 KiB
Plaintext
Raw Permalink Normal View History

2023-04-04 22:36:01 +00:00
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")
2023-04-04 22:36:01 +00:00
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,
2023-04-04 22:36:01 +00:00
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"
2023-04-04 22:36:01 +00:00
),
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(
2023-04-17 01:01:54 +00:00
"-Djava.library.path=" ++ path.value("glue.target")
),
Compile / doc / javacOptions ++= Seq(
"--enable-preview",
"--release",
2023-04-11 21:29:23 +00:00
"20"
),
Compile / compile / javacOptions ++= Seq(
"--enable-preview",
"--release",
"20",
"-Xlint:unchecked",
"-Xlint:deprecation"
),
2023-04-04 22:36:01 +00:00
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)
2023-04-04 22:36:01 +00:00
println(Seq("sh", "-c", cmd) !!)
},
cargoBuild := {
2023-04-05 17:08:25 +00:00
println(Seq("sh", "-c", "cd glue; cargo rustc -- -Awarnings") !!)
2023-04-04 22:36:01 +00:00
},
fullBuild := {
cargoBuild.value
ejectHeaders.value
},
Compile / compile := (Compile / compile dependsOn fullBuild).value,
Compile / compile / watchTriggers += glob.value("glue.sources")
)