Skip to content
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

Add PekkoInlinePlugin #2

Merged
merged 2 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.github.pjfanning.pekkobuild

import sbt._

object PekkoCorePlugin extends AutoPlugin {

override def trigger: PluginTrigger = allRequirements

object autoImport extends PekkoCoreSettings

import autoImport._

override lazy val globalSettings = Seq(
pekkoCoreProject := false
)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.github.pjfanning.pekkobuild

import sbt._

trait PekkoCoreSettings {
lazy val pekkoCoreProject: SettingKey[Boolean] = settingKey("Whether this is the core Pekko project or a Pekko" +
" module. Defaults to false")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* license agreements; and to You under the Apache License, version 2.0:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* This file is part of the Apache Pekko project, derived from Akka.
*/

package com.github.pjfanning.pekkobuild

import com.github.pjfanning.pekkobuild.PekkoCorePlugin.autoImport.pekkoCoreProject
import sbt.plugins.JvmPlugin
import sbt._
import sbt.Keys._

object PekkoInlinePlugin extends AutoPlugin {
override def trigger: PluginTrigger = allRequirements

override def requires: Plugins = JvmPlugin && PekkoCorePlugin

object autoImport extends PekkoInlineSettings

import autoImport._

private def flagsForScala2(coreProject: Boolean) = {
val baseInlineFlags = Seq(
"-opt-inline-from:<sources>",
"-opt:l:inline"
)

if (coreProject)
baseInlineFlags ++ Seq(
// Since the Pekko core project doesn't allow for mixing of different versions,
// i.e. you cannot mix pekko-actor 1.0.0 with pekko-streams 1.0.1 at runtime
// its safe to do inter sbt project inlining.
"-opt-inline-from:org.apache.pekko.**"
)
else baseInlineFlags ++ Seq(
// These are safe to inline even across modules since they are
// wrappers for cross compilation that is stable within Pekko core.
"-opt-inline-from:org.apache.pekko.dispatch.internal.SameThreadExecutionContext**",
"-opt-inline-from:org.apache.pekko.util.OptionConverters**",
"-opt-inline-from:org.apache.pekko.util.FutureConverters**",
"-opt-inline-from:org.apache.pekko.util.FunctionConverters**",
"-opt-inline-from:org.apache.pekko.util.PartialFunction**",
"-opt-inline-from:org.apache.pekko.util.JavaDurationConverters**"
)
}

// Optimizer not yet available for Scala3, see https://docs.scala-lang.org/overviews/compiler-options/optimizer.html
private val flagsForScala3 = Seq()

override lazy val globalSettings = Seq(
pekkoInlineEnabled := !sys.props.contains("pekko.no.inline")
)

override lazy val projectSettings = Seq(Compile / scalacOptions ++= {
if (pekkoInlineEnabled.value) {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, n)) if n == 12 | n == 13 =>
flagsForScala2(pekkoCoreProject.value)
case Some((3, _)) =>
flagsForScala3
}
} else Seq.empty
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.github.pjfanning.pekkobuild

import sbt.{SettingKey, settingKey}

trait PekkoInlineSettings {
lazy val pekkoInlineEnabled: SettingKey[Boolean] = settingKey("Whether to enable the Scala 2 inliner for Pekko modules." +
"Defaults to pekko.no.inline property")
}