From 05bbd8e2a8477e18d5ef77016199cf3a46a53c77 Mon Sep 17 00:00:00 2001 From: Daniele Torelli Date: Wed, 8 May 2024 12:49:49 -0600 Subject: [PATCH] Add golemScalaOutputDirectory --- .../scala/cloud/golem/GolemScalaPlugin.scala | 21 ++++++++++++++++--- .../golem/GolemScalaPluginInternal.scala | 18 +++++++++++----- src/sbt-test/golem-scala/example1/test | 16 +++++++------- src/sbt-test/golem-scala/example2/test | 16 +++++++------- 4 files changed, 47 insertions(+), 24 deletions(-) diff --git a/src/main/scala/cloud/golem/GolemScalaPlugin.scala b/src/main/scala/cloud/golem/GolemScalaPlugin.scala index a4697c0..dd09068 100644 --- a/src/main/scala/cloud/golem/GolemScalaPlugin.scala +++ b/src/main/scala/cloud/golem/GolemScalaPlugin.scala @@ -6,10 +6,25 @@ import sbt.plugins.JvmPlugin object GolemScalaPlugin extends AutoPlugin { object autoImport { - lazy val golemScalaWitPath = settingKey[File]("Path to the wit file") - lazy val golemScalaPackageName = settingKey[String]("Package name") + lazy val golemScalaOutputDirectory = SettingKey[File]( + "golemScalaOutputDirectory", + "Output directory", + KeyRanks.Invisible + ) + lazy val golemScalaWitPath = SettingKey[File]( + "golemScalaWitPath", + "Path to the wit file", + KeyRanks.Invisible + ) + lazy val golemScalaPackageName = SettingKey[String]( + "golemScalaPackageName", + "Package name", + KeyRanks.Invisible + ) lazy val witBindgen = - taskKey[Unit]("Runs golem-scalajs-wit-bindgen to generate WIT bindings") + taskKey[Seq[File]]( + "Runs golem-scalajs-wit-bindgen to generate WIT bindings" + ) lazy val component = taskKey[Unit]("Runs componentize-js on the generated main.js file") } diff --git a/src/main/scala/cloud/golem/GolemScalaPluginInternal.scala b/src/main/scala/cloud/golem/GolemScalaPluginInternal.scala index 108c60e..4d5f282 100644 --- a/src/main/scala/cloud/golem/GolemScalaPluginInternal.scala +++ b/src/main/scala/cloud/golem/GolemScalaPluginInternal.scala @@ -12,30 +12,38 @@ private[golem] object GolemScalaPluginInternal { val scalaMacrosParadise = "2.1.1" } - lazy val baseSettings: Seq[Setting[?]] = + lazy val baseSettings: Seq[Setting[?]] = { Def.settings( + golemScalaOutputDirectory := target.value / "dist", golemScalaWitPath := (ThisBuild / baseDirectory).value / "wit", - golemScalaPackageName := "main", witBindgen := { - val golemScalaWitFullPath = (ThisBuild / baseDirectory).value / golemScalaWitPath.value.getPath / s"${golemScalaPackageName.value}.wit" + val golemScalaWitBindgenOutput = (Compile / sourceManaged).value / "scala" / golemScalaPackageName.value / "Api.scala" + val golemScalaWitFullPath = golemScalaWitPath.value / s"${golemScalaPackageName.value}.wit" import scala.sys.process.* - Seq( + val output = Seq( "bash", "-xc", s"golem-scalajs-wit-bindgen -w $golemScalaWitFullPath -p ${golemScalaPackageName.value}" ).!! + + IO.write(golemScalaWitBindgenOutput, output) + Seq(golemScalaWitBindgenOutput) }, component := { import scala.sys.process.* Seq("bash", "-xc", "npm install").!! Seq("bash", "-xc", "npm run build").!! }, - component := (component dependsOn (Compile / fullLinkJS)).value + component := (component dependsOn (Compile / fullLinkJS)).value, + Compile / sourceGenerators += witBindgen.taskValue ) + } lazy val scalaJsSettings: Seq[Setting[?]] = Def.settings( scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.ESModule) }, + Compile / fullLinkJS / scalaJSLinkerOutputDirectory := golemScalaOutputDirectory.value, + Compile / fastLinkJS / scalaJSLinkerOutputDirectory := golemScalaOutputDirectory.value, libraryDependencies += "cloud.golem" %% "golem-scala-macros" % Versions.macros ) diff --git a/src/sbt-test/golem-scala/example1/test b/src/sbt-test/golem-scala/example1/test index fb5bbf1..a1e038a 100644 --- a/src/sbt-test/golem-scala/example1/test +++ b/src/sbt-test/golem-scala/example1/test @@ -1,12 +1,12 @@ > +clean > +fullLinkJS -$ exists target/scala-2.12/root-opt/main.js -$ exists target/scala-2.12/root-opt/main.js.map -$ exists target/scala-2.13/root-opt/main.js -$ exists target/scala-2.13/root-opt/main.js.map +$ exists target/dist/main.js +$ exists target/dist/main.js.map +$ exists target/dist/main.js +$ exists target/dist/main.js.map > +clean > +fastLinkJS -$ exists target/scala-2.12/root-fastopt/main.js -$ exists target/scala-2.12/root-fastopt/main.js.map -$ exists target/scala-2.13/root-fastopt/main.js -$ exists target/scala-2.13/root-fastopt/main.js.map +$ exists target/dist/main.js +$ exists target/dist/main.js.map +$ exists target/dist/main.js +$ exists target/dist/main.js.map diff --git a/src/sbt-test/golem-scala/example2/test b/src/sbt-test/golem-scala/example2/test index fb5bbf1..a1e038a 100644 --- a/src/sbt-test/golem-scala/example2/test +++ b/src/sbt-test/golem-scala/example2/test @@ -1,12 +1,12 @@ > +clean > +fullLinkJS -$ exists target/scala-2.12/root-opt/main.js -$ exists target/scala-2.12/root-opt/main.js.map -$ exists target/scala-2.13/root-opt/main.js -$ exists target/scala-2.13/root-opt/main.js.map +$ exists target/dist/main.js +$ exists target/dist/main.js.map +$ exists target/dist/main.js +$ exists target/dist/main.js.map > +clean > +fastLinkJS -$ exists target/scala-2.12/root-fastopt/main.js -$ exists target/scala-2.12/root-fastopt/main.js.map -$ exists target/scala-2.13/root-fastopt/main.js -$ exists target/scala-2.13/root-fastopt/main.js.map +$ exists target/dist/main.js +$ exists target/dist/main.js.map +$ exists target/dist/main.js +$ exists target/dist/main.js.map