Skip to content

Commit 9f0eec7

Browse files
committed
Go back to Scala 2.13 due to bug
Ref: scala/scala3#13985 scala/scala3#9013
1 parent 8995c97 commit 9f0eec7

File tree

3 files changed

+62
-48
lines changed

3 files changed

+62
-48
lines changed

backend/src/GreetingApp.scala

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import zhttp.http.middleware.Cors.CorsConfig
1111
* - Does not use the environment
1212
*/
1313
object GreetingApp {
14+
val corsConfig = CorsConfig(
15+
allowedOrigins = _ == "*",
16+
allowedMethods = Some(Set(Method.PUT, Method.DELETE, Method.POST, Method.GET)),
17+
)
18+
1419
def apply(): Http[Any, Nothing, Request, Response] =
1520
Http.collect[Request] {
1621
// GET /greet?name=:name

backend/src/MainApp.scala

+15-15
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,7 @@ import zhttp.http.middleware.Cors.CorsConfig
88
import zhttp.service.Server
99
import zio._
1010

11-
// Create CORS configuration
12-
private val corsConfig =
13-
CorsConfig(
14-
allowedOrigins = _ == "*",
15-
allowedMethods = Some(Set(Method.PUT, Method.DELETE, Method.POST, Method.GET)),
16-
)
17-
18-
object MainApp extends ZIOAppDefault:
11+
object MainApp extends ZIOAppDefault {
1912
def run = console *> server
2013
val console = Console.printLine(s"Server started on http://localhost:${SharedConfig.serverPort}")
2114

@@ -25,11 +18,18 @@ object MainApp extends ZIOAppDefault:
2518
http = HomeApp() ++ GreetingApp(),
2619
)
2720

28-
object HomeApp {
29-
def apply(): Http[Any, Nothing, Request, Response] =
30-
Http.collect[Request] {
31-
// GET /, redirect to /greet
32-
case Method.GET -> !! =>
33-
Response.redirect("/greet")
34-
} @@ cors(corsConfig)
21+
object HomeApp {
22+
val corsConfig = CorsConfig(
23+
allowedOrigins = _ == "*",
24+
allowedMethods = Some(Set(Method.PUT, Method.DELETE, Method.POST, Method.GET)),
25+
)
26+
27+
def apply(): Http[Any, Nothing, Request, Response] =
28+
// Create CORS configuration
29+
Http.collect[Request] {
30+
// GET /, redirect to /greet
31+
case Method.GET -> !! =>
32+
Response.redirect("/greet")
33+
} @@ cors(corsConfig)
34+
}
3535
}

build.sc

+42-33
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ import com.goyeau.mill.scalafix.ScalafixModule
1010
import $ivy.`io.github.davidgregory084::mill-tpolecat::0.3.1`
1111
import io.github.davidgregory084.TpolecatModule
1212

13-
import $ivy.`com.carlosedp::mill-docker-nativeimage::0.1-SNAPSHOT`
13+
import $ivy.`io.github.alexarchambault.mill::mill-native-image::0.1.21`
14+
import io.github.alexarchambault.millnativeimage.NativeImage
15+
16+
import $ivy.`com.carlosedp::mill-docker-nativeimage::0.0.1`
1417
import com.carlosedp.milldockernative.DockerNative
1518

1619
object libVersion {
17-
val scala = "3.2.0"
20+
val scala = "2.13.10"
1821
val scalajs = "1.11.0"
1922
val zio = "2.0.2"
2023
val zhttp = "2.0.0-RC11"
@@ -27,6 +30,8 @@ object libVersion {
2730
trait Common extends ScalaModule with TpolecatModule with ScalafmtModule with ScalafixModule {
2831
override def scalaVersion = libVersion.scala
2932
def scalafixIvyDeps = Agg(ivy"com.github.liancheng::organize-imports:${libVersion.organizeimports}")
33+
override def scalacPluginIvyDeps =
34+
Agg(ivy"org.scalameta:::semanticdb-scalac:4.5.13")
3035
def repositoriesTask = T.task { // Add snapshot repositories in case needed
3136
super.repositoriesTask() ++ Seq("oss", "s01.oss")
3237
.map(r => s"https://$r.sonatype.org/content/repositories/snapshots")
@@ -44,43 +49,14 @@ trait Common extends ScalaModule with TpolecatModule with ScalafmtModule with Sc
4449

4550
// object shared extends Common
4651

47-
object backend extends Common with DockerModule with DockerNative {
52+
object backend extends Common with DockerModule with DockerNative with NativeImage with NativeImageConfig {
4853
// Runtime dependencies
4954
def ivyDeps = super.ivyDeps() ++ Agg(
5055
ivy"dev.zio::zio:${libVersion.zio}",
5156
ivy"io.d11::zhttp:${libVersion.zhttp}",
5257
)
5358

54-
object dockerNative extends DockerNativeConfig {
55-
def nativeImageName = "backend"
56-
def nativeImageGraalVmJvmId = T {
57-
sys.env.getOrElse("GRAALVM_ID", "graalvm-java17:22.2.0")
58-
}
59-
def nativeImageClassPath = runClasspath()
60-
def nativeImageMainClass = "com.carlosedp.zioscalajs.backend.MainApp"
61-
def nativeImageOptions = super.nativeImageOptions() ++ Seq(
62-
"--no-fallback",
63-
"--enable-url-protocols=http,https",
64-
"-Djdk.http.auth.tunneling.disabledSchemes=",
65-
// "--static", // Does not work on MacOS
66-
"--no-fallback",
67-
"--install-exit-handlers",
68-
"--enable-http",
69-
"--initialize-at-run-time=io.netty.channel.DefaultFileRegion",
70-
"--initialize-at-run-time=io.netty.channel.epoll.Native",
71-
"--initialize-at-run-time=io.netty.channel.epoll.Epoll",
72-
"--initialize-at-run-time=io.netty.channel.epoll.EpollEventLoop",
73-
"--initialize-at-run-time=io.netty.channel.epoll.EpollEventArray",
74-
"--initialize-at-run-time=io.netty.channel.kqueue.KQueue",
75-
"--initialize-at-run-time=io.netty.channel.kqueue.KQueueEventLoop",
76-
"--initialize-at-run-time=io.netty.channel.kqueue.KQueueEventArray",
77-
"--initialize-at-run-time=io.netty.channel.kqueue.Native",
78-
"--initialize-at-run-time=io.netty.channel.unix.Limits",
79-
"--initialize-at-run-time=io.netty.channel.unix.Errors",
80-
"--initialize-at-run-time=io.netty.channel.unix.IovArray",
81-
"--allow-incomplete-classpath",
82-
)
83-
59+
object dockerNative extends DockerNativeConfig with NativeImageConfig {
8460
def tags = List("docker.io/carlosedp/zioscalajs-backend")
8561
def exposedPorts = Seq(8080)
8662
}
@@ -99,6 +75,39 @@ object backend extends Common with DockerModule with DockerNative {
9975
}
10076
}
10177

78+
trait NativeImageConfig extends JavaModule with NativeImage {
79+
def nativeImageName = "backend"
80+
def nativeImageClassPath = runClasspath()
81+
def nativeImageGraalVmJvmId = T {
82+
sys.env.getOrElse("GRAALVM_ID", "graalvm-java17:22.2.0")
83+
}
84+
// def nativeImageClassPath = runClasspath()
85+
def nativeImageMainClass = "com.carlosedp.zioscalajs.backend.MainApp"
86+
def nativeImageOptionsDef = Seq(
87+
"--no-fallback",
88+
"--enable-url-protocols=http,https",
89+
"-Djdk.http.auth.tunneling.disabledSchemes=",
90+
"--install-exit-handlers",
91+
"--enable-http",
92+
"--initialize-at-run-time=io.netty.channel.DefaultFileRegion",
93+
"--initialize-at-run-time=io.netty.channel.epoll.Native",
94+
"--initialize-at-run-time=io.netty.channel.epoll.Epoll",
95+
"--initialize-at-run-time=io.netty.channel.epoll.EpollEventLoop",
96+
"--initialize-at-run-time=io.netty.channel.epoll.EpollEventArray",
97+
"--initialize-at-run-time=io.netty.channel.kqueue.KQueue",
98+
"--initialize-at-run-time=io.netty.channel.kqueue.KQueueEventLoop",
99+
"--initialize-at-run-time=io.netty.channel.kqueue.KQueueEventArray",
100+
"--initialize-at-run-time=io.netty.channel.kqueue.Native",
101+
"--initialize-at-run-time=io.netty.channel.unix.Limits",
102+
"--initialize-at-run-time=io.netty.channel.unix.Errors",
103+
"--initialize-at-run-time=io.netty.channel.unix.IovArray",
104+
"--allow-incomplete-classpath",
105+
)
106+
if (System.getProperty("os.name").startsWith("Linux")) {
107+
def nativeImageOptions = nativeImageOptionsDef ++ Seq("--static")
108+
} else nativeImageOptionsDef
109+
}
110+
102111
object frontend extends ScalaJSModule with Common {
103112
def scalaJSVersion = libVersion.scalajs
104113
def ivyDeps = super.ivyDeps() ++ Agg(

0 commit comments

Comments
 (0)