Skip to content

Commit e81f5ad

Browse files
authored
Make a monomorphic and monofunctorial distage-example variants (#447)
* convert Ladder part to monomorphic style * convert the rest of the service to monomorphic style * move monofuntctor example into separate directory * move bifunctor example into separate directory * add monomorphic example in separate directory * remake tests for monomorphic example * widen CI jobs * few changes to Readme * fix comments from PR review and remove Either * move graal configs to separate sbt module * separate CI graal build step into three independent ones and rename graal-configs -> graal-resources * check only bifunctor variant in GraalVM step in CI
1 parent f81e0b4 commit e81f5ad

File tree

79 files changed

+2256
-79
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+2256
-79
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ jobs:
2121
steps:
2222
- uses: actions/checkout@v2
2323
- name: Build native app
24-
run: sbt GraalVMNativeImage/packageBin
24+
run: sbt "project leaderboard-bifunctor-tf; GraalVMNativeImage/packageBin"
2525
- name: Check native app
26-
run: ./target/graalvm-native-image/leaderboard :help
26+
run: ./distage-example-bifunctor-tf/target/graalvm-native-image/leaderboard-bifunctor-tf :help

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
Example `distage` project presented at Functional Scala 2019
77

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

11+
- [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.
12+
- [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.
13+
- [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.
14+
1315
To launch tests that require postgres ensure you have a `docker` daemon running in the background.
1416

1517
Use `sbt test` to launch the tests.

build.sbt

Lines changed: 122 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ val V = new {
1111
val kindProjector = "0.13.3"
1212
val circeGeneric = "0.14.6"
1313
val graalMetadata = "0.10.1"
14+
val catsEffect = "3.5.4"
1415
}
1516

1617
val Deps = new {
@@ -42,7 +43,29 @@ val Deps = new {
4243

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

46+
val catsEffect = "org.typelevel" %% "cats-effect" % V.catsEffect
47+
4548
val graalMetadata = "org.graalvm.buildtools" % "graalvm-reachability-metadata" % V.graalMetadata
49+
50+
val CoreDeps = Seq(
51+
distageCore,
52+
distageRoles,
53+
distageConfig,
54+
logstageSlf4j,
55+
distageDocker,
56+
distageTestkit % Test,
57+
scalatest % Test,
58+
scalacheck % Test,
59+
http4sDsl,
60+
http4sServer,
61+
http4sClient % Test,
62+
http4sCirce,
63+
circeGeneric,
64+
doobie,
65+
doobiePostgres,
66+
doobieHikari,
67+
graalMetadata,
68+
)
4669
}
4770

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

61-
lazy val leaderboard = project
84+
def makeExampleProject(moduleName: String, dir: String)(deps: Seq[ModuleID]) =
85+
Project(moduleName, file(dir))
86+
.settings(
87+
name := moduleName,
88+
libraryDependencies ++= deps,
89+
libraryDependencies ++= {
90+
if (scalaVersion.value.startsWith("2")) {
91+
Seq(compilerPlugin(Deps.kindProjector))
92+
} else {
93+
Seq.empty
94+
}
95+
},
96+
scalacOptions -= "-Xfatal-warnings",
97+
scalacOptions -= "-Ykind-projector",
98+
scalacOptions -= "-Wnonunit-statement",
99+
scalacOptions ++= {
100+
if (scalaVersion.value.startsWith("2")) {
101+
Seq(
102+
"-Xsource:3",
103+
"-P:kind-projector:underscore-placeholders",
104+
"-Wmacros:after",
105+
)
106+
} else {
107+
Seq(
108+
"-source:3.2",
109+
"-Ykind-projector:underscores",
110+
"-Yretain-trees",
111+
)
112+
}
113+
},
114+
scalacOptions ++= Seq(
115+
s"-Xmacro-settings:product-name=${name.value}",
116+
s"-Xmacro-settings:product-version=${version.value}",
117+
s"-Xmacro-settings:product-group=${organization.value}",
118+
s"-Xmacro-settings:scala-version=${scalaVersion.value}",
119+
s"-Xmacro-settings:scala-versions=${crossScalaVersions.value.mkString(":")}",
120+
s"-Xmacro-settings:sbt-version=${sbtVersion.value}",
121+
s"-Xmacro-settings:git-repo-clean=${git.gitUncommittedChanges.value}",
122+
s"-Xmacro-settings:git-branch=${git.gitCurrentBranch.value}",
123+
s"-Xmacro-settings:git-described-version=${git.gitDescribedVersion.value.getOrElse("")}",
124+
s"-Xmacro-settings:git-head-commit=${git.gitHeadCommit.value.getOrElse("")}",
125+
),
126+
GraalVMNativeImage / mainClass := Some("leaderboard.GenericLauncher"),
127+
graalVMNativeImageOptions ++= Seq(
128+
"--no-fallback",
129+
"-H:+ReportExceptionStackTraces",
130+
"--report-unsupported-elements-at-runtime",
131+
"--enable-https",
132+
"--enable-http",
133+
"-J-Xmx8G",
134+
),
135+
graalVMNativeImageGraalVersion := Some("ol9-java17-22.3.1"),
136+
run / fork := true,
137+
)
138+
.dependsOn(`graal-resources`)
139+
.enablePlugins(GraalVMNativeImagePlugin, UniversalPlugin)
140+
141+
lazy val root = project
62142
.in(file("."))
63-
.settings(
64-
name := "leaderboard",
65-
libraryDependencies ++= Seq(
66-
Deps.distageCore,
67-
Deps.distageRoles,
68-
Deps.distageConfig,
69-
Deps.logstageSlf4j,
70-
Deps.distageDocker,
71-
Deps.distageTestkit % Test,
72-
Deps.scalatest % Test,
73-
Deps.scalacheck % Test,
74-
Deps.http4sDsl,
75-
Deps.http4sServer,
76-
Deps.http4sClient % Test,
77-
Deps.http4sCirce,
78-
Deps.circeGeneric,
79-
Deps.doobie,
80-
Deps.doobiePostgres,
81-
Deps.doobieHikari,
82-
Deps.zio,
83-
Deps.zioCats,
84-
Deps.catsCore,
85-
Deps.graalMetadata,
86-
),
87-
libraryDependencies ++= {
88-
if (scalaVersion.value.startsWith("2")) {
89-
Seq(compilerPlugin(Deps.kindProjector))
90-
} else {
91-
Seq.empty
92-
}
93-
},
94-
scalacOptions -= "-Xfatal-warnings",
95-
scalacOptions -= "-Ykind-projector",
96-
scalacOptions -= "-Wnonunit-statement",
97-
scalacOptions ++= {
98-
if (scalaVersion.value.startsWith("2")) {
99-
Seq(
100-
"-Xsource:3",
101-
"-P:kind-projector:underscore-placeholders",
102-
"-Wmacros:after",
103-
)
104-
} else {
105-
Seq(
106-
"-source:3.2",
107-
"-Ykind-projector:underscores",
108-
"-Yretain-trees",
109-
)
110-
}
111-
},
112-
scalacOptions ++= Seq(
113-
s"-Xmacro-settings:product-name=${name.value}",
114-
s"-Xmacro-settings:product-version=${version.value}",
115-
s"-Xmacro-settings:product-group=${organization.value}",
116-
s"-Xmacro-settings:scala-version=${scalaVersion.value}",
117-
s"-Xmacro-settings:scala-versions=${crossScalaVersions.value.mkString(":")}",
118-
s"-Xmacro-settings:sbt-version=${sbtVersion.value}",
119-
s"-Xmacro-settings:git-repo-clean=${git.gitUncommittedChanges.value}",
120-
s"-Xmacro-settings:git-branch=${git.gitCurrentBranch.value}",
121-
s"-Xmacro-settings:git-described-version=${git.gitDescribedVersion.value.getOrElse("")}",
122-
s"-Xmacro-settings:git-head-commit=${git.gitHeadCommit.value.getOrElse("")}",
123-
),
124-
GraalVMNativeImage / mainClass := Some("leaderboard.GenericLauncher"),
125-
graalVMNativeImageOptions ++= Seq(
126-
"--no-fallback",
127-
"-H:+ReportExceptionStackTraces",
128-
"--report-unsupported-elements-at-runtime",
129-
"--enable-https",
130-
"--enable-http",
131-
"-J-Xmx4G",
132-
),
133-
graalVMNativeImageGraalVersion := Some("ol9-java17-22.3.1"),
134-
run / fork := true,
143+
.aggregate(
144+
`graal-resources`,
145+
`leaderboard-monofunctor-tf`,
146+
`leaderboard-bifunctor-tf`,
147+
`leaderboard-monomorphic-cats`,
148+
)
149+
.enablePlugins(GraalVMNativeImagePlugin, UniversalPlugin) // enabled here for CI purposes
150+
151+
lazy val `graal-resources` = project
152+
.in(file("graal-resources"))
153+
.settings(Compile / resourceDirectory := baseDirectory.value)
154+
155+
lazy val `leaderboard-monofunctor-tf` = makeExampleProject(
156+
moduleName = "leaderboard-monofunctor-tf",
157+
dir = "distage-example-monofunctor-tf",
158+
)(deps =
159+
Deps.CoreDeps ++ Seq(
160+
Deps.zio,
161+
Deps.zioCats,
162+
Deps.catsCore,
135163
)
136-
.enablePlugins(GraalVMNativeImagePlugin, UniversalPlugin)
164+
)
165+
166+
lazy val `leaderboard-bifunctor-tf` = makeExampleProject(
167+
moduleName = "leaderboard-bifunctor-tf",
168+
dir = "distage-example-bifunctor-tf",
169+
)(deps =
170+
Deps.CoreDeps ++ Seq(
171+
Deps.zio,
172+
Deps.zioCats,
173+
Deps.catsCore,
174+
)
175+
)
176+
177+
lazy val `leaderboard-monomorphic-cats` = makeExampleProject(
178+
moduleName = "leaderboard-monomorphic-cats",
179+
dir = "distage-example-monomorphic-cats",
180+
)(deps =
181+
Deps.CoreDeps ++ Seq(
182+
Deps.catsEffect
183+
)
184+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
postgres {
2+
jdbcDriver = "org.postgresql.Driver"
3+
url = "jdbc:postgresql://{host}:{port}/postgres"
4+
user = "postgres"
5+
password = "postgres"
6+
host = "localhost"
7+
port = 5432
8+
}
9+
10+
logger {
11+
levels = {}
12+
json = false
13+
}

0 commit comments

Comments
 (0)