Skip to content

Commit 05f8ba6

Browse files
neko-kaipshirshov
andauthored
Publish runtime and generate sources for Scala 3 (#398)
* Initial build adaptation for Scala3. Replace ProjectAttributeMacro with izumi MacroParameters * wip * wip * wip * Port IRT Runtime to Scala 3; use Match Types as type projections workaround to minimize changes and support Http4sContext type scala/scala3#13416 * Add scala-java-time dependency for Scala.js test on Scala 3 * Add project/build.properties to generated SBT projects Add sbt workaround for circe-derivation/circe-core old versions into generated SBT projects Use semiauto encoder for circe when sbt.scalaVersion > 3 FIXME: disable AnyVals on Scala 3 because circe deriver on 3 doesn't support AnyVals: `class Struct is not a generic product because it is a value class` Re-enable AnyVals on Scala 3 - generate manual codec for AnyVals on Scala 3 Add sbt version to Scala build manifest Add Scala 3 keywords to keywords list Update scalameta, print source with Scala 3 Dialect to fix escaping of `export` and other keywords Fix Scala 3 warning: final case object -> case object --------- Co-authored-by: Pavel Shirshov <[email protected]>
1 parent d2e74ae commit 05f8ba6

File tree

46 files changed

+820
-353
lines changed

Some content is hidden

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

46 files changed

+820
-353
lines changed

.build.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ set -xe
77
# and https://github.com/sbt/sbt/pull/3995/files
88
# TL;DR strict aggregation in sbt is broken; this is a workaround
99

10+
function scala3 {
11+
echo "Using Scala 3..."
12+
VERSION_COMMAND="++ $SCALA3"
13+
}
14+
1015
function scala213 {
1116
echo "Using Scala 2.13..."
1217
VERSION_COMMAND="++ $SCALA213"
@@ -80,6 +85,7 @@ function init {
8085
export IZUMI_VERSION=$(cat version.sbt | sed -r 's/.*\"(.*)\".**/\1/' | sed -E "s/SNAPSHOT/build."${CI_BUILD_UNIQ_SUFFIX}"/")
8186
export SCALA212=$(cat project/Deps.sc | grep 'val scala212 ' | sed -r 's/.*\"(.*)\".**/\1/')
8287
export SCALA213=$(cat project/Deps.sc | grep 'val scala213 ' | sed -r 's/.*\"(.*)\".**/\1/')
88+
export SCALA3=$(cat project/Deps.sc | grep 'val scala300 ' | sed -r 's/.*\"(.*)\".**/\1/')
8389

8490
printenv
8591
}
@@ -109,6 +115,10 @@ case $i in
109115
scala212
110116
;;
111117

118+
3*)
119+
scala3
120+
;;
121+
112122
coverage)
113123
coverage
114124
;;
@@ -130,7 +140,7 @@ case $i in
130140
;;
131141

132142
*)
133-
echo "Unknown option"
143+
echo "Unknown option: ${i}"
134144
exit 1
135145
;;
136146
esac

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
matrix:
1717
java: [ '11' ]
18-
scala: [ '2.12', '2.13']
18+
scala: [ '2.12', '2.13', '3.2' ]
1919
steps:
2020
- uses: 7mind/github-env@main
2121
with:
@@ -68,7 +68,7 @@ jobs:
6868
strategy:
6969
matrix:
7070
java: [ '11' ]
71-
scala: [ '2.12', '2.13']
71+
scala: [ '2.12', '2.13', '3.2' ]
7272
steps:
7373
- uses: 7mind/github-env@main
7474
with:

build.sbt

Lines changed: 337 additions & 46 deletions
Large diffs are not rendered by default.

idealingua-v1/idealingua-v1-compiler/src/main/scala/izumi/idealingua/compiler/CommandlineIDLCompiler.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ object CommandlineIDLCompiler {
3434

3535
val conf = parseArgs(args)
3636

37-
3837
val results = Seq(
3938
initDir(conf),
4039
runCompilations(izumiVersion, conf),
@@ -49,7 +48,7 @@ object CommandlineIDLCompiler {
4948
private def runPublish(conf: IDLCArgs): Boolean = {
5049
if (conf.publish && conf.languages.nonEmpty) {
5150
conf.languages.foreach { lang =>
52-
val manifest = toOption(conf, Map.empty)(lang).manifest
51+
val manifest = toOptions(conf, Map.empty)(lang).manifest
5352
publishLangArtifacts(conf, lang, manifest) match {
5453
case Left(err) => throw err
5554
case _ => ()
@@ -103,10 +102,10 @@ object CommandlineIDLCompiler {
103102
}
104103
}
105104

106-
private def runCompilations(izumiVersion: String, conf: IDLCArgs) = {
105+
private def runCompilations(izumiVersion: String, conf: IDLCArgs): Boolean = {
107106
if (conf.languages.nonEmpty) {
108107
log.log("Reading manifests...")
109-
val toRun = conf.languages.map(toOption(conf, Map("common.izumiVersion" -> izumiVersion)))
108+
val toRun = conf.languages.map(toOptions(conf, Map("common.izumiVersion" -> izumiVersion)))
110109
log.log("Going to compile:")
111110
log.log(toRun.niceList())
112111
log.log("")
@@ -136,7 +135,6 @@ object CommandlineIDLCompiler {
136135
} else {
137136
false
138137
}
139-
140138
}
141139

142140
private def runCompiler(target: Path, loaded: Timed[UnresolvedDomains], option: UntypedCompilerOptions): Unit = {
@@ -175,7 +173,7 @@ object CommandlineIDLCompiler {
175173
IDLCArgs.parseUnsafe(args)
176174
}
177175

178-
private def toOption(conf: IDLCArgs, env: Map[String, String])(lopt: LanguageOpts): UntypedCompilerOptions = {
176+
private def toOptions(conf: IDLCArgs, env: Map[String, String])(lopt: LanguageOpts): UntypedCompilerOptions = {
179177
val lang = IDLLanguage.parse(lopt.id)
180178
val exts = getExt(lang, lopt.extensions)
181179

idealingua-v1/idealingua-v1-compiler/src/main/scala/izumi/idealingua/compiler/IDLCArgs.scala

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ object IDLCArgs {
5151
final val overlayVersionFile = arg("overlay-version", "v", "version file", "<path>")
5252
final val define = arg("define", "d", "define value", "const.name=value")
5353
final val publish = flag("publish", "p", "build and publish generated code")
54-
55-
5654
}
5755

5856
object LP extends ParserDef {
@@ -65,7 +63,7 @@ object IDLCArgs {
6563
final val define = arg("define", "d", "define value", "const.name=value")
6664
}
6765

68-
object IP extends ParserDef {}
66+
object IP extends ParserDef
6967

7068
def parseUnsafe(args: Array[String]): IDLCArgs = {
7169
val parsed = new CLIParserImpl().parse(args) match {
@@ -102,7 +100,7 @@ object IDLCArgs {
102100
val overlay = parameters.findValue(P.overlayDir).asPath.getOrElse(root.resolve("overlay"))
103101
val overlayVersion = parameters.findValue(P.overlayVersionFile).asPath
104102
val publish = parameters.hasFlag(P.publish)
105-
val defines = parseDefs(parameters)
103+
val defines = parseDefs(parameters, P.define)
106104

107105
val internalRoles = Seq("init", "help")
108106

@@ -114,7 +112,7 @@ object IDLCArgs {
114112
val target = parameters.findValue(LP.target).asPath
115113
val manifest = parameters.findValue(LP.manifest).asFile
116114
val credentials = parameters.findValue(LP.credentials).asFile
117-
val defines = parseDefs(parameters)
115+
val defines = parseDefs(parameters, LP.define)
118116
val extensions = parameters.findValue(LP.extensionSpec).map(_.value.split(',')).toList.flatten
119117

120118
LanguageOpts(
@@ -142,8 +140,8 @@ object IDLCArgs {
142140
)
143141
}
144142

145-
private def parseDefs(parameters: RawEntrypointParams): Map[String, String] = {
146-
parameters.findValues(LP.define).map {
143+
private def parseDefs(parameters: RawEntrypointParams, argDef: ParserDef.ArgDef): Map[String, String] = {
144+
parameters.findValues(argDef).map {
147145
v =>
148146
val parts = v.value.split('=')
149147
parts.head -> parts.tail.mkString("=")

idealingua-v1/idealingua-v1-core/src/main/scala/izumi/idealingua/model/publishing/BuildManifest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package izumi.idealingua.model.publishing
22

3-
import izumi.idealingua.`macro`.ProjectAttributeMacro
3+
import izumi.fundamentals.platform.build.MacroParameters
44
import izumi.idealingua.model.publishing.BuildManifest._
55

66
trait BuildManifest {
@@ -67,7 +67,7 @@ object BuildManifest {
6767
licenses = List(License("MIT", MFUrl("https://opensource.org/licenses/MIT"))),
6868
website = MFUrl("http://project.website"),
6969
copyright = "Copyright (C) Test Inc.",
70-
izumiVersion = ProjectAttributeMacro.extractSbtProjectVersion().getOrElse("UNSET-IZUMI-VERSION"),
70+
izumiVersion = MacroParameters.artifactVersion().getOrElse("UNSET-IZUMI-VERSION"),
7171
)
7272
}
7373

idealingua-v1/idealingua-v1-core/src/main/scala/izumi/idealingua/model/publishing/manifests/ScalaBuildManifest.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ case class SbtOptions(
1414
projectNaming: ProjectNamingRule,
1515
enableScalaJs: Boolean,
1616
scalaVersion: Option[String],
17+
sbtVersion: Option[String],
1718
)
1819

1920
object SbtOptions {
@@ -22,6 +23,7 @@ object SbtOptions {
2223
projectNaming = ProjectNamingRule.example,
2324
enableScalaJs = true,
2425
scalaVersion = None,
26+
sbtVersion = None,
2527
)
2628
}
2729
}

idealingua-v1/idealingua-v1-model/src/main/scala/izumi/idealingua/macro/ProjectAttributeMacro.scala

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package izumi.idealingua.model.common
22

3-
sealed trait StreamDirection {
4-
5-
}
3+
sealed trait StreamDirection
64

75
object StreamDirection {
8-
final case object ToServer extends StreamDirection
9-
final case object ToClient extends StreamDirection
6+
case object ToServer extends StreamDirection
7+
case object ToClient extends StreamDirection
108
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package izumi.idealingua.runtime.rpc
2+
3+
package object http4s {
4+
5+
/**
6+
* This is a workaround that replaces usages of type projections with Match Types on Scala 3.
7+
*
8+
* See: https://github.com/lampepfl/dotty/issues/13416
9+
*/
10+
type GetBiIO[C <: Http4sContext] = { type l[+E, +A] = C#BiIO[E, A] }
11+
type GetMonoIO[C <: Http4sContext] = { type l[+A] = C#BiIO[Throwable, A] }
12+
13+
type GetMaterializedStream[C <: Http4sContext] = C#MaterializedStream
14+
type GetRequestContext[C <: Http4sContext] = C#RequestContext
15+
type GetClientContext[C <: Http4sContext] = C#ClientContext
16+
type GetMethodContext[C <: Http4sContext] = C#MethodContext
17+
type GetClientMethodContext[C <: Http4sContext] = C#ClientMethodContext
18+
type GetClientId[C <: Http4sContext] = C#ClientId
19+
}

0 commit comments

Comments
 (0)