From a2e9c7bdc289491008609a628ae38a1813698271 Mon Sep 17 00:00:00 2001 From: "Frank S. Thomas" Date: Wed, 8 Feb 2023 12:49:44 +0100 Subject: [PATCH 1/3] Build ciris-enumeratum with Scala 3 This PR cross builds ciris-enumeratum with Scala 3: * Scala 3 has been added to the enumeratum's `crossScalaVersions` * The `TypeNameRuntimePlatform` has been splitted for Scala 2 and Scala 3. The Scala 3 implementation has been copied from the refined module. * `-Yretain-trees` was added to the Scala 3 `scalacOptions` to fix test compilation errors: ``` sbt:ciris> enumeratumJVM/test [info] compiling 2 Scala sources to modules/enumeratum/jvm/target/scala-3.2.2/test-classes ... [error] -- Error: modules/enumeratum/shared/src/test/scala/enumeratum/values/CirisValueEnumSpec.scala:216:17 [error] 216 | val values = findValues [error] | ^^^^^^^^^^ [error] | Option -Yretain-trees must be set in scalacOptions. [error] | In SBT settings: [error] | [error] | scalacOptions += "-Yretain-trees" ``` It is expected that this must be set: https://github.com/lloydmeta/enumeratum/blob/1facfdddd9498411ac8eb270cd8089d4b4f4cab0/README.md?plain=1#L28 --- build.sbt | 6 ++++-- .../internal/TypeNameRuntimePlatform.scala | 0 .../internal/TypeNameRuntimePlatform.scala | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) rename modules/enumeratum/shared/src/main/{scala => scala-2}/enumeratum/internal/TypeNameRuntimePlatform.scala (100%) create mode 100644 modules/enumeratum/shared/src/main/scala-3/enumeratum/internal/TypeNameRuntimePlatform.scala diff --git a/build.sbt b/build.sbt index 86b16791..29f9489e 100644 --- a/build.sbt +++ b/build.sbt @@ -127,7 +127,9 @@ lazy val enumeratum = crossProject(JSPlatform, JVMPlatform) ), publishSettings, mimaSettings, - scalaSettings, + scalaSettings ++ Seq( + crossScalaVersions += scala3 + ), testSettings ) .jsSettings(sharedJsSettings) @@ -425,7 +427,7 @@ lazy val scalaSettings = Seq( val scala3ScalacOptions = if (scalaVersion.value.startsWith("3")) { - Seq("-Ykind-projector") + Seq("-Ykind-projector", "-Yretain-trees") } else Seq() commonScalacOptions ++ diff --git a/modules/enumeratum/shared/src/main/scala/enumeratum/internal/TypeNameRuntimePlatform.scala b/modules/enumeratum/shared/src/main/scala-2/enumeratum/internal/TypeNameRuntimePlatform.scala similarity index 100% rename from modules/enumeratum/shared/src/main/scala/enumeratum/internal/TypeNameRuntimePlatform.scala rename to modules/enumeratum/shared/src/main/scala-2/enumeratum/internal/TypeNameRuntimePlatform.scala diff --git a/modules/enumeratum/shared/src/main/scala-3/enumeratum/internal/TypeNameRuntimePlatform.scala b/modules/enumeratum/shared/src/main/scala-3/enumeratum/internal/TypeNameRuntimePlatform.scala new file mode 100644 index 00000000..4528b2eb --- /dev/null +++ b/modules/enumeratum/shared/src/main/scala-3/enumeratum/internal/TypeNameRuntimePlatform.scala @@ -0,0 +1,19 @@ +/* + * Copyright 2017-2023 Viktor Rudebeck + * + * SPDX-License-Identifier: MIT + */ + +package enumeratum.internal + +import scala.quoted._ + +private[internal] trait TypeNameRuntimePlatform { + inline given [A]: TypeName[A] = + ${TypeNameRuntimePlatform.typeName[A]} +} + +private[internal] object TypeNameRuntimePlatform { + final def typeName[A](using t: Type[A], ctx: Quotes): Expr[TypeName[A]] = + '{TypeName[A](${Expr(Type.show[A])})} +} From 8646fc5a9f9665e4fe3870444fe0bea6caa77c06 Mon Sep 17 00:00:00 2001 From: Viktor Lovgren Date: Wed, 8 Feb 2023 16:42:59 +0100 Subject: [PATCH 2/3] Add ciris-enumeratum_3 to unpublished modules --- build.sbt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.sbt b/build.sbt index 29f9489e..4b191af3 100644 --- a/build.sbt +++ b/build.sbt @@ -364,9 +364,9 @@ lazy val publishSettings = lazy val mimaSettings = Seq( mimaPreviousArtifacts := { - val unpublishedModules = Set[String]() + val unpublishedModules = Set[String]("ciris-enumeratum_3") if (publishArtifact.value && !unpublishedModules.contains(moduleName.value)) { - Set(organization.value %% moduleName.value % (ThisBuild / previousStableVersion).value.get) + Set(organization.value % moduleName.value % (ThisBuild / previousStableVersion).value.get) } else Set() }, mimaBinaryIssueFilters ++= { From 6527c58fa5fb860881c6ebca40ea0c7ee8b43c2c Mon Sep 17 00:00:00 2001 From: Viktor Lovgren Date: Wed, 8 Feb 2023 16:44:01 +0100 Subject: [PATCH 3/3] Change to ciris-enumeratum in unpublished modules --- build.sbt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.sbt b/build.sbt index 4b191af3..94bb224b 100644 --- a/build.sbt +++ b/build.sbt @@ -364,9 +364,9 @@ lazy val publishSettings = lazy val mimaSettings = Seq( mimaPreviousArtifacts := { - val unpublishedModules = Set[String]("ciris-enumeratum_3") + val unpublishedModules = Set[String]("ciris-enumeratum") if (publishArtifact.value && !unpublishedModules.contains(moduleName.value)) { - Set(organization.value % moduleName.value % (ThisBuild / previousStableVersion).value.get) + Set(organization.value %% moduleName.value % (ThisBuild / previousStableVersion).value.get) } else Set() }, mimaBinaryIssueFilters ++= {