mirror of
https://github.com/fluencelabs/aqua.git
synced 2024-12-04 22:50:18 +00:00
chore: add code to run aqua (#886)
* add code to run aqua * delete aqua-cli * Apply suggestions from code review --------- Co-authored-by: InversionSpaces <InversionSpaces@vivaldi.net>
This commit is contained in:
parent
1e2e35ee88
commit
404d5ffae2
@ -1,18 +1,40 @@
|
||||
package aqua.api
|
||||
import cats.effect.{IO, IOApp}
|
||||
import aqua.backend.js.JavaScriptBackend
|
||||
|
||||
import aqua.api.TargetType.TypeScriptType
|
||||
import aqua.backend.ts.TypeScriptBackend
|
||||
import aqua.api.TargetType.JavaScriptType
|
||||
import aqua.compiler.AquaCompiled
|
||||
import aqua.files.FileModuleId
|
||||
|
||||
import cats.data.Chain
|
||||
import cats.data.Validated.{Invalid, Valid}
|
||||
import cats.effect.{IO, IOApp}
|
||||
import fs2.io.file.{Files, Path}
|
||||
import fs2.{Stream, text}
|
||||
|
||||
object Test extends IOApp.Simple {
|
||||
|
||||
override def run: IO[Unit] = {
|
||||
val input =
|
||||
"""func getNumber(number: u32) -> u32:
|
||||
| <- number
|
||||
|""".stripMargin
|
||||
APICompilation.compileString(input, Nil, AquaAPIConfig(targetType = JavaScriptType), JavaScriptBackend()).map {
|
||||
res =>
|
||||
println(res)
|
||||
}
|
||||
APICompilation
|
||||
.compilePath(
|
||||
"./aqua-src/antithesis.aqua",
|
||||
"./aqua" :: Nil,
|
||||
AquaAPIConfig(targetType = TypeScriptType),
|
||||
TypeScriptBackend(false, "IFluenceClient$$")
|
||||
)
|
||||
.flatMap {
|
||||
case Valid(res) =>
|
||||
val content = res.get(0).get.compiled.head.content
|
||||
val targetPath = Path("./target/antithesis.ts")
|
||||
|
||||
Stream.emit(content)
|
||||
.through(text.utf8.encode)
|
||||
.through(Files[IO].writeAll(targetPath))
|
||||
.attempt
|
||||
.compile
|
||||
.last.flatMap(_ => IO.delay(println(s"File: ${targetPath.absolute.normalize}")))
|
||||
case Invalid(e) =>
|
||||
IO.delay(println(e))
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
50
build.sbt
50
build.sbt
@ -38,56 +38,6 @@ val commons = Seq(
|
||||
|
||||
commons
|
||||
|
||||
lazy val cli = crossProject(JSPlatform, JVMPlatform)
|
||||
.withoutSuffixFor(JVMPlatform)
|
||||
.crossType(CrossType.Pure)
|
||||
.in(file("cli/cli"))
|
||||
.enablePlugins(GraalVMNativeImagePlugin)
|
||||
.settings(commons)
|
||||
.settings(
|
||||
Compile / mainClass := Some("aqua.AquaCli"),
|
||||
graalVMNativeImageOptions ++= Seq(
|
||||
"--no-fallback",
|
||||
"--diagnostics-mode",
|
||||
"--initialize-at-build-time",
|
||||
"--initialize-at-run-time=scala.util.Random$",
|
||||
"-H:-DeleteLocalSymbols",
|
||||
"-H:+PreserveFramePointer",
|
||||
"-H:+ReportExceptionStackTraces",
|
||||
"-H:+DashboardHeap",
|
||||
"-H:+DashboardCode",
|
||||
"-H:+DashboardPointsTo",
|
||||
"-H:+DashboardAll"
|
||||
) ++ sys.env
|
||||
.get("COMPILE_STATIC")
|
||||
.filter(_.trim.toLowerCase() == "true")
|
||||
.map(_ => Seq("--static"))
|
||||
.getOrElse(Seq.empty),
|
||||
libraryDependencies ++= Seq(
|
||||
"com.monovore" %%% "decline" % declineV,
|
||||
"com.monovore" %%% "decline-effect" % declineV
|
||||
)
|
||||
)
|
||||
.dependsOn(compiler, `backend-air`, `backend-ts`, io, definitions, logging, constants, `aqua-run`)
|
||||
|
||||
lazy val cliJS = cli.js
|
||||
.settings(
|
||||
Compile / fastOptJS / artifactPath := baseDirectory.value / "../../cli-npm" / "aqua.js",
|
||||
Compile / fullOptJS / artifactPath := baseDirectory.value / "../../cli-npm" / "aqua.js",
|
||||
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.ESModule)),
|
||||
scalaJSUseMainModuleInitializer := true
|
||||
)
|
||||
.dependsOn(`js-exports`, `js-imports`)
|
||||
|
||||
lazy val cliJVM = cli.jvm
|
||||
.settings(
|
||||
Compile / run / mainClass := Some("aqua.AquaCli"),
|
||||
assembly / mainClass := Some("aqua.AquaCli"),
|
||||
assembly / assemblyJarName := "aqua-" + version.value + ".jar",
|
||||
libraryDependencies ++= Seq(
|
||||
)
|
||||
)
|
||||
|
||||
lazy val `aqua-run` = crossProject(JSPlatform, JVMPlatform)
|
||||
.withoutSuffixFor(JVMPlatform)
|
||||
.crossType(CrossType.Pure)
|
||||
|
Loading…
Reference in New Issue
Block a user