-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Rename macro to WitExport * Rename GolemScalaPlugin to WasmComponentPlugin * Rename directory
- Loading branch information
1 parent
29a798d
commit 680acf0
Showing
18 changed files
with
151 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package cloud.golem | ||
|
||
import sbt.* | ||
import org.scalajs.sbtplugin.ScalaJSPlugin | ||
import sbt.plugins.JvmPlugin | ||
|
||
object WasmComponentPlugin extends AutoPlugin { | ||
object autoImport { | ||
lazy val wasmComponentOutputDirectory = SettingKey[File]( | ||
"wasmComponentOutputDirectory", | ||
"Output directory", | ||
KeyRanks.Invisible | ||
) | ||
lazy val wasmComponentWitPath = SettingKey[File]( | ||
"wasmComponentWitPath", | ||
"Path to the wit file", | ||
KeyRanks.Invisible | ||
) | ||
lazy val wasmComponentPackageName = SettingKey[String]( | ||
"wasmComponentPackageName", | ||
"Package name", | ||
KeyRanks.Invisible | ||
) | ||
lazy val wasmComponentWitBindgen = | ||
taskKey[Seq[File]]( | ||
"Runs golem-scalajs-wit-bindgen to generate WIT bindings" | ||
) | ||
lazy val wasmComponent = | ||
taskKey[Unit]("Runs componentize-js on the generated ScalaJS file") | ||
} | ||
|
||
override def trigger: PluginTrigger = allRequirements | ||
|
||
override def requires: Plugins = JvmPlugin && ScalaJSPlugin | ||
|
||
override lazy val projectSettings: Seq[Setting[?]] = | ||
WasmComponentPluginInternal.baseSettings ++ | ||
WasmComponentPluginInternal.scalaJsSettings ++ | ||
WasmComponentPluginInternal.macroParadiseSettings | ||
} |
89 changes: 89 additions & 0 deletions
89
src/main/scala/cloud/golem/WasmComponentPluginInternal.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package cloud.golem | ||
|
||
import sbt.* | ||
import sbt.Keys.* | ||
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport.* | ||
|
||
private[golem] object WasmComponentPluginInternal { | ||
import WasmComponentPlugin.autoImport.* | ||
|
||
private object Versions { | ||
val macros = "0.1.0" | ||
val scalaMacrosParadise = "2.1.1" | ||
} | ||
|
||
lazy val baseSettings: Seq[Setting[?]] = { | ||
lazy val wasmComponentWitFullPath = | ||
Def | ||
.task( | ||
wasmComponentWitPath.value / s"${wasmComponentPackageName.value}.wit" | ||
) | ||
Def.settings( | ||
wasmComponentOutputDirectory := target.value / "dist", | ||
wasmComponentWitPath := (ThisBuild / baseDirectory).value / "wit", | ||
wasmComponentPackageName := moduleName.value, | ||
wasmComponentWitBindgen := { | ||
if (!wasmComponentWitFullPath.value.exists()) { | ||
sys.error(s""" | ||
|'${wasmComponentWitFullPath.value.getAbsolutePath}' does not exist. | ||
|Make sure 'wasmComponentPackageName' is set correctly in your build.sbt | ||
""".stripMargin) | ||
} else { | ||
val wasmComponentWitBindgenOutput = (Compile / sourceManaged).value / "scala" / wasmComponentPackageName.value / "Api.scala" | ||
import scala.sys.process.* | ||
|
||
val output = Seq( | ||
"bash", | ||
"-xc", | ||
s"golem-scalajs-wit-bindgen -w ${wasmComponentWitFullPath.value} -p ${wasmComponentPackageName.value}" | ||
).!! | ||
|
||
IO.write(wasmComponentWitBindgenOutput, output) | ||
Seq(wasmComponentWitBindgenOutput) | ||
} | ||
}, | ||
wasmComponent := { | ||
import scala.sys.process.* | ||
Seq("bash", "-xc", "npm install").!! | ||
Seq("bash", "-xc", "npm run build").!! | ||
}, | ||
wasmComponent := (wasmComponent dependsOn (Compile / fullLinkJS)).value, | ||
Compile / sourceGenerators += Def.taskIf { | ||
if (wasmComponentWitFullPath.value.exists()) | ||
wasmComponentWitBindgen.value | ||
else { | ||
println( | ||
s""" | ||
|'${wasmComponentWitFullPath.value.getAbsolutePath}' does not exist. | ||
|Make sure 'wasmComponentPackageName' is set correctly in your build.sbt""".stripMargin | ||
) | ||
Nil | ||
} | ||
}.taskValue | ||
) | ||
} | ||
|
||
lazy val scalaJsSettings: Seq[Setting[?]] = | ||
Def.settings( | ||
scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.ESModule) }, | ||
Compile / fullLinkJS / scalaJSLinkerOutputDirectory := wasmComponentOutputDirectory.value, | ||
Compile / fastLinkJS / scalaJSLinkerOutputDirectory := wasmComponentOutputDirectory.value, | ||
libraryDependencies += "cloud.golem" %% "sbt-wasm-component-macros" % Versions.macros | ||
) | ||
|
||
lazy val macroParadiseSettings: Seq[Setting[?]] = Def.settings( | ||
scalacOptions ++= { | ||
if (scalaVersion.value.startsWith("2.13")) Seq("-Ymacro-annotations") | ||
else Nil | ||
}, | ||
libraryDependencies ++= { | ||
if (scalaVersion.value.startsWith("2.12")) { | ||
Seq( | ||
compilerPlugin( | ||
"org.scalamacros" % "paradise" % Versions.scalaMacrosParadise cross CrossVersion.full | ||
) | ||
) | ||
} else Nil | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
3 changes: 2 additions & 1 deletion
3
.../golem-scala/example1/project/plugins.sbt → ...est/scala-js/example1/project/plugins.sbt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...src/main/scala/example/ShoppingCart.scala → ...src/main/scala/example/ShoppingCart.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
3 changes: 2 additions & 1 deletion
3
.../golem-scala/example2/project/plugins.sbt → ...est/scala-js/example2/project/plugins.sbt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...src/main/scala/example/ShoppingCart.scala → ...src/main/scala/example/ShoppingCart.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.