Skip to content

Commit

Permalink
Merge pull request #187 from mdedetrich/only-enable-optimizer-in-ci
Browse files Browse the repository at this point in the history
Only enable optimizer in CI
  • Loading branch information
SethTisue authored Aug 22, 2024
2 parents c409c84 + ace58c0 commit db7d705
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/main/scala/ScalaModulePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,26 @@ 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 ++= {
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
}

/**
Expand Down

0 comments on commit db7d705

Please sign in to comment.