From 0e55988ae72342823ce3585f1ece97032be767bf Mon Sep 17 00:00:00 2001 From: Matthew de Detrich Date: Tue, 6 Feb 2024 11:41:36 +1100 Subject: [PATCH 1/2] Only enable optimizer in CI --- src/main/scala/ScalaModulePlugin.scala | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/scala/ScalaModulePlugin.scala b/src/main/scala/ScalaModulePlugin.scala index 441a82b..6b47906 100644 --- a/src/main/scala/ScalaModulePlugin.scala +++ b/src/main/scala/ScalaModulePlugin.scala @@ -49,14 +49,19 @@ object ScalaModulePlugin extends AutoPlugin { * Enable `-opt:l:inline`, `-opt:l:project` or `-optimize`, depending on the scala version. */ lazy val enableOptimizer: Setting[_] = Compile / compile / scalacOptions ++= { - val Ver = """(\d+)\.(\d+)\.(\d+).*""".r - val Ver(epic, maj, min) = scalaVersion.value - (epic, maj.toInt, min.toInt) match { - case ("2", m, _) if m < 12 => Seq("-optimize") - case ("2", 12, n) if n < 3 => Seq("-opt:l:project") - case ("2", _, _) => Seq("-opt:l:inline", "-opt-inline-from:" + scalaModuleEnableOptimizerInlineFrom.value) - case ("3", _, _) => Nil // Optimizer not yet available for Scala3, see https://docs.scala-lang.org/overviews/compiler-options/optimizer.html - } + if (insideCI.value) { + val log = sLog.value + val inlineFrom = scalaModuleEnableOptimizerInlineFrom.value + log.info(s"Running in CI, enabling Scala2 optimizer for module: ${name.value} with -opt-inline-from: $inlineFrom") + val Ver = """(\d+)\.(\d+)\.(\d+).*""".r + val Ver(epic, maj, min) = scalaVersion.value + (epic, maj.toInt, min.toInt) match { + case ("2", m, _) if m < 12 => Seq("-optimize") + case ("2", 12, n) if n < 3 => Seq("-opt:l:project") + case ("2", _, _) => Seq("-opt:l:inline", "-opt-inline-from:" + inlineFrom) + case ("3", _, _) => Nil // Optimizer not yet available for Scala3, see https://docs.scala-lang.org/overviews/compiler-options/optimizer.html + } + } else Nil } /** From ace58c039d003e86d7e605e2924b4dc04e483918 Mon Sep 17 00:00:00 2001 From: Seth Tisue Date: Wed, 14 Aug 2024 09:19:26 -0700 Subject: [PATCH 2/2] improve Scaladoc for `enableOptimizer` --- src/main/scala/ScalaModulePlugin.scala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/scala/ScalaModulePlugin.scala b/src/main/scala/ScalaModulePlugin.scala index 6b47906..4945a7d 100644 --- a/src/main/scala/ScalaModulePlugin.scala +++ b/src/main/scala/ScalaModulePlugin.scala @@ -46,7 +46,11 @@ object ScalaModulePlugin extends AutoPlugin { ) /** - * Enable `-opt:l:inline`, `-opt:l:project` or `-optimize`, depending on the scala version. + * Enable `-opt:l:inline`, `-opt:l:project` or `-optimize`, depending on the Scala version. + * + * Note that the optimizer is only enabled in CI and not during local development. + * Thus, for consistent results, release artifacts must only be built on CI -- + * which is the expected norm for Scala modules, anyway. */ lazy val enableOptimizer: Setting[_] = Compile / compile / scalacOptions ++= { if (insideCI.value) {