Skip to content

Only enable optimizer in CI #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading