Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make a monomorphic and monofunctorial distage-example variants #447

Merged
merged 12 commits into from
Jun 19, 2024
Merged
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Build native app
run: sbt GraalVMNativeImage/packageBin
run: sbt "project leaderboard-bifunctor-tf; GraalVMNativeImage/packageBin"
- name: Check native app
run: ./target/graalvm-native-image/leaderboard :help
run: ./distage-example-bifunctor-tf/target/graalvm-native-image/leaderboard-bifunctor-tf :help
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
Example `distage` project presented at Functional Scala 2019

Features [distage](https://izumi.7mind.io/distage/),
[Bifunctor Tagless Final](https://izumi.7mind.io/bio/),
[ZIO Environment](https://zio.dev) for composing test fixtures,
and [distage-docker](https://izumi.7mind.io/distage/distage-framework-docker) for setting up test containers.

- [distage-example-bifunctor-tf](distage-example-bifunctor-tf). Written in bifunctorial way with [Bifunctor Tagless Final](https://izumi.7mind.io/bio/), using [ZIO 2](https://zio.dev) as a runtime and ZIO Environment with distage-testkit for composing test fixtures.
- [distage-example-monofunctor-tf](distage-example-monofunctor-tf). Written in monofunctorial way with [Cats Core](https://typelevel.org/cats/), using [ZIO 2](https://zio.dev) as a runtime and ZIO Environment with distage-testkit for composing test fixtures.
- [distage-example-monomorphic-cats](distage-example-monomorphic-cats). Written in monomorphic way with [Cats Effect 3](https://typelevel.org/cats-effect/) as a runtime with distage-testkit for composing test fixtures.

To launch tests that require postgres ensure you have a `docker` daemon running in the background.

Use `sbt test` to launch the tests.
Expand Down
196 changes: 122 additions & 74 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ val V = new {
val kindProjector = "0.13.3"
val circeGeneric = "0.14.6"
val graalMetadata = "0.10.1"
val catsEffect = "3.5.4"
}

val Deps = new {
Expand Down Expand Up @@ -42,7 +43,29 @@ val Deps = new {

val catsCore = "org.typelevel" %% "cats-core" % V.catsCore

val catsEffect = "org.typelevel" %% "cats-effect" % V.catsEffect

val graalMetadata = "org.graalvm.buildtools" % "graalvm-reachability-metadata" % V.graalMetadata

val CoreDeps = Seq(
distageCore,
distageRoles,
distageConfig,
logstageSlf4j,
distageDocker,
distageTestkit % Test,
scalatest % Test,
scalacheck % Test,
http4sDsl,
http4sServer,
http4sClient % Test,
http4sCirce,
circeGeneric,
doobie,
doobiePostgres,
doobieHikari,
graalMetadata,
)
}

inThisBuild(
Expand All @@ -58,79 +81,104 @@ inThisBuild(
// that's just for quick experiments with distage snapshots
ThisBuild / resolvers ++= Resolver.sonatypeOssRepos("snapshots")

lazy val leaderboard = project
def makeExampleProject(moduleName: String, dir: String)(deps: Seq[ModuleID]) =
Project(moduleName, file(dir))
.settings(
name := moduleName,
libraryDependencies ++= deps,
libraryDependencies ++= {
if (scalaVersion.value.startsWith("2")) {
Seq(compilerPlugin(Deps.kindProjector))
} else {
Seq.empty
}
},
scalacOptions -= "-Xfatal-warnings",
scalacOptions -= "-Ykind-projector",
scalacOptions -= "-Wnonunit-statement",
scalacOptions ++= {
if (scalaVersion.value.startsWith("2")) {
Seq(
"-Xsource:3",
"-P:kind-projector:underscore-placeholders",
"-Wmacros:after",
)
} else {
Seq(
"-source:3.2",
"-Ykind-projector:underscores",
"-Yretain-trees",
)
}
},
scalacOptions ++= Seq(
s"-Xmacro-settings:product-name=${name.value}",
s"-Xmacro-settings:product-version=${version.value}",
s"-Xmacro-settings:product-group=${organization.value}",
s"-Xmacro-settings:scala-version=${scalaVersion.value}",
s"-Xmacro-settings:scala-versions=${crossScalaVersions.value.mkString(":")}",
s"-Xmacro-settings:sbt-version=${sbtVersion.value}",
s"-Xmacro-settings:git-repo-clean=${git.gitUncommittedChanges.value}",
s"-Xmacro-settings:git-branch=${git.gitCurrentBranch.value}",
s"-Xmacro-settings:git-described-version=${git.gitDescribedVersion.value.getOrElse("")}",
s"-Xmacro-settings:git-head-commit=${git.gitHeadCommit.value.getOrElse("")}",
),
GraalVMNativeImage / mainClass := Some("leaderboard.GenericLauncher"),
graalVMNativeImageOptions ++= Seq(
"--no-fallback",
"-H:+ReportExceptionStackTraces",
"--report-unsupported-elements-at-runtime",
"--enable-https",
"--enable-http",
"-J-Xmx8G",
),
graalVMNativeImageGraalVersion := Some("ol9-java17-22.3.1"),
run / fork := true,
)
.dependsOn(`graal-resources`)
.enablePlugins(GraalVMNativeImagePlugin, UniversalPlugin)

lazy val root = project
.in(file("."))
.settings(
name := "leaderboard",
libraryDependencies ++= Seq(
Deps.distageCore,
Deps.distageRoles,
Deps.distageConfig,
Deps.logstageSlf4j,
Deps.distageDocker,
Deps.distageTestkit % Test,
Deps.scalatest % Test,
Deps.scalacheck % Test,
Deps.http4sDsl,
Deps.http4sServer,
Deps.http4sClient % Test,
Deps.http4sCirce,
Deps.circeGeneric,
Deps.doobie,
Deps.doobiePostgres,
Deps.doobieHikari,
Deps.zio,
Deps.zioCats,
Deps.catsCore,
Deps.graalMetadata,
),
libraryDependencies ++= {
if (scalaVersion.value.startsWith("2")) {
Seq(compilerPlugin(Deps.kindProjector))
} else {
Seq.empty
}
},
scalacOptions -= "-Xfatal-warnings",
scalacOptions -= "-Ykind-projector",
scalacOptions -= "-Wnonunit-statement",
scalacOptions ++= {
if (scalaVersion.value.startsWith("2")) {
Seq(
"-Xsource:3",
"-P:kind-projector:underscore-placeholders",
"-Wmacros:after",
)
} else {
Seq(
"-source:3.2",
"-Ykind-projector:underscores",
"-Yretain-trees",
)
}
},
scalacOptions ++= Seq(
s"-Xmacro-settings:product-name=${name.value}",
s"-Xmacro-settings:product-version=${version.value}",
s"-Xmacro-settings:product-group=${organization.value}",
s"-Xmacro-settings:scala-version=${scalaVersion.value}",
s"-Xmacro-settings:scala-versions=${crossScalaVersions.value.mkString(":")}",
s"-Xmacro-settings:sbt-version=${sbtVersion.value}",
s"-Xmacro-settings:git-repo-clean=${git.gitUncommittedChanges.value}",
s"-Xmacro-settings:git-branch=${git.gitCurrentBranch.value}",
s"-Xmacro-settings:git-described-version=${git.gitDescribedVersion.value.getOrElse("")}",
s"-Xmacro-settings:git-head-commit=${git.gitHeadCommit.value.getOrElse("")}",
),
GraalVMNativeImage / mainClass := Some("leaderboard.GenericLauncher"),
graalVMNativeImageOptions ++= Seq(
"--no-fallback",
"-H:+ReportExceptionStackTraces",
"--report-unsupported-elements-at-runtime",
"--enable-https",
"--enable-http",
"-J-Xmx4G",
),
graalVMNativeImageGraalVersion := Some("ol9-java17-22.3.1"),
run / fork := true,
.aggregate(
`graal-resources`,
`leaderboard-monofunctor-tf`,
`leaderboard-bifunctor-tf`,
`leaderboard-monomorphic-cats`,
)
.enablePlugins(GraalVMNativeImagePlugin, UniversalPlugin) // enabled here for CI purposes

lazy val `graal-resources` = project
.in(file("graal-resources"))
.settings(Compile / resourceDirectory := baseDirectory.value)

lazy val `leaderboard-monofunctor-tf` = makeExampleProject(
moduleName = "leaderboard-monofunctor-tf",
dir = "distage-example-monofunctor-tf",
)(deps =
Deps.CoreDeps ++ Seq(
Deps.zio,
Deps.zioCats,
Deps.catsCore,
)
.enablePlugins(GraalVMNativeImagePlugin, UniversalPlugin)
)

lazy val `leaderboard-bifunctor-tf` = makeExampleProject(
moduleName = "leaderboard-bifunctor-tf",
dir = "distage-example-bifunctor-tf",
)(deps =
Deps.CoreDeps ++ Seq(
Deps.zio,
Deps.zioCats,
Deps.catsCore,
)
)

lazy val `leaderboard-monomorphic-cats` = makeExampleProject(
moduleName = "leaderboard-monomorphic-cats",
dir = "distage-example-monomorphic-cats",
)(deps =
Deps.CoreDeps ++ Seq(
Deps.catsEffect
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
postgres {
jdbcDriver = "org.postgresql.Driver"
url = "jdbc:postgresql://{host}:{port}/postgres"
user = "postgres"
password = "postgres"
host = "localhost"
port = 5432
}

logger {
levels = {}
json = false
}
Loading
Loading