Skip to content

Commit

Permalink
Merge pull request #2261 from tgodzik/add-native
Browse files Browse the repository at this point in the history
Add support for Scala Native 0.4.0
  • Loading branch information
tgodzik committed Mar 3, 2021
2 parents b513eec + 7e12cb5 commit 2db5f93
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ jobs:
- "++2.12.12 testsJVM/test"
- "++2.12.13 testsJVM/test"
- "++2.12.13 testsJS/test"
- "++2.12.13 testsNative/test"
- "++2.13.1 testsJVM/test"
- "++2.13.2 testsJVM/test"
- "++2.13.3 testsJVM/test"
- "++2.13.4 testsJVM/test"
- "++2.13.5 testsJVM/test"
- "++2.13.5 testsJS/test"
- "++2.13.5 testsNative/test"
- "++2.13.5 download-scala-library testsJVM/slow:test"
- "communitytest/test"
- "mima"
Expand Down
35 changes: 29 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ val commonJsSettings = Seq(
}
)

lazy val nativeSettings = Seq(
crossScalaVersions := List(LatestScala213, LatestScala212),
nativeConfig ~= {
_.withMode(scalanative.build.Mode.releaseFast)
}
)

/* ======================== SEMANTICDB ======================== */
lazy val semanticdbScalacCore = project
.in(file("semanticdb/scalac/library"))
Expand Down Expand Up @@ -135,7 +142,7 @@ lazy val metac = project
.dependsOn(semanticdbScalacPlugin)

/* ======================== SCALAMETA ======================== */
lazy val common = crossProject(JSPlatform, JVMPlatform)
lazy val common = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.in(file("scalameta/common"))
.settings(
publishableSettings,
Expand All @@ -146,8 +153,9 @@ lazy val common = crossProject(JSPlatform, JVMPlatform)
.jsSettings(
commonJsSettings
)
.nativeSettings(nativeSettings)

lazy val trees = crossProject(JSPlatform, JVMPlatform)
lazy val trees = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.in(file("scalameta/trees"))
.settings(
publishableSettings,
Expand Down Expand Up @@ -175,9 +183,10 @@ lazy val trees = crossProject(JSPlatform, JVMPlatform)
.jsSettings(
commonJsSettings
)
.nativeSettings(nativeSettings)
.dependsOn(common) // NOTE: tokenizers needed for Tree.tokens when Tree.pos.isEmpty

lazy val parsers = crossProject(JSPlatform, JVMPlatform)
lazy val parsers = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.in(file("scalameta/parsers"))
.settings(
publishableSettings,
Expand All @@ -194,14 +203,17 @@ lazy val parsers = crossProject(JSPlatform, JVMPlatform)
commonJsSettings,
scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule) }
)
.nativeSettings(nativeSettings)
.dependsOn(trees)

def mergedModule(projects: File => List[File]): List[Setting[_]] = List(
unmanagedSourceDirectories.in(Compile) ++= {
val base = baseDirectory.in(ThisBuild).value
val isNative = platformDepsCrossVersion.value == ScalaNativeCrossVersion.binary
val isJS = SettingKey[Boolean]("scalaJSUseMainModuleInitializer").?.value.isDefined
val platform =
if (isJS) "js"
else if (isNative) "native"
else "jvm"
val scalaBinary = "scala-" + scalaBinaryVersion.value
projects(base).flatMap { project =>
Expand All @@ -214,7 +226,7 @@ def mergedModule(projects: File => List[File]): List[Setting[_]] = List(
}
)

lazy val scalameta = crossProject(JSPlatform, JVMPlatform)
lazy val scalameta = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.in(file("scalameta/scalameta"))
.settings(
publishableSettings,
Expand Down Expand Up @@ -245,6 +257,7 @@ lazy val scalameta = crossProject(JSPlatform, JVMPlatform)
.jsSettings(
commonJsSettings
)
.nativeSettings(nativeSettings)
.dependsOn(parsers)

/* ======================== TESTS ======================== */
Expand Down Expand Up @@ -321,7 +334,7 @@ lazy val testkit = project
)
.dependsOn(scalameta.jvm)

lazy val tests = crossProject(JSPlatform, JVMPlatform)
lazy val tests = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.in(file("tests"))
.configs(Slow, All)
.settings(
Expand All @@ -346,6 +359,13 @@ lazy val tests = crossProject(JSPlatform, JVMPlatform)
commonJsSettings,
scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule) }
)
.nativeSettings(
nativeSettings,
nativeConfig ~= {
_.withMode(scalanative.build.Mode.debug)
.withLinkStubs(true)
}
)
.enablePlugins(BuildInfoPlugin)
.dependsOn(scalameta)

Expand Down Expand Up @@ -559,6 +579,8 @@ lazy val protobufSettings = Def.settings(
val scalapbVersion =
if (scalaBinaryVersion.value == "2.11") {
"0.9.7"
} else if (scalaVersion.value == "2.13.0" || scalaVersion.value == "2.13.1") {
"0.10.11"
} else {
scalapb.compiler.Version.scalapbVersion
}
Expand Down Expand Up @@ -616,7 +638,8 @@ lazy val publishableSettings = Def.settings(
// val isJVM = platformDepsCrossVersion.value == CrossVersion.binary
val isJVM = {
val isJS = platformDepsCrossVersion.value == ScalaJSCrossVersion.binary
!isJS
val isNative = platformDepsCrossVersion.value == ScalaNativeCrossVersion.binary
!isJS && !isNative
}
if (isJVM) {
previousVersion.map { previousVersion =>
Expand Down
6 changes: 5 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.0")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0")

addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.1")
libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.10.11"
libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.11.0-M5"

libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value

Expand All @@ -17,10 +17,14 @@ addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.6.1")

addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.0.0")

addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.0.0")

addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.5.0")

addSbtPlugin("org.scala-debugger" % "sbt-jdi-tools" % "1.1.1")

addSbtPlugin("org.scalameta" % "sbt-munit" % "0.7.22")

addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.2.18")

addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.0")
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package scala.meta.internal
package inputs

import scala.collection.mutable
import scala.collection.concurrent.TrieMap
import scala.meta.inputs._
import scala.meta.Dialect
import scala.meta.tokens.Tokens
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import java.nio.charset.Charset
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.util.stream.Collectors
import scala.meta.io.AbsolutePath
import scala.meta.io.AbsolutePath
import scala.meta.io.AbsolutePath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,22 @@ object TreeSyntax {
}
looksLikePatVar && thisLocationAlsoAcceptsPatVars
}
// soft keywords might need to be written with backquotes in some places
/* Soft keywords might need to be written with backquotes in some places.
* Previously used match clause fails due to:
* https://github.com/scala-native/scala-native/issues/2187
* instead we went with if clause to work around the issue.
*/
def isEscapableSoftKeyword(t: Name, parent: Tree): Boolean = {
t.value match {
case "extension" if dialect.allowExtensionMethods =>
parent.is[Term.Apply] || parent.is[Term.ApplyUsing]
case "inline" if dialect.allowInlineMods =>
parent.is[Term.Apply] || parent.is[Term.ApplyUsing] || parent.is[Term.ApplyInfix]
case "*" if dialect.allowStarWildcardImport =>
parent.is[Importee]
case _ =>
false
}
if (t.value == "extension" && dialect.allowExtensionMethods)
parent.is[Term.Apply] || parent.is[Term.ApplyUsing]
else if (t.value == "inline" && dialect.allowInlineMods)
parent.is[Term.Apply] || parent.is[Term.ApplyUsing] || parent.is[Term.ApplyInfix]
else if (t.value == "*" && dialect.allowStarWildcardImport)
parent.is[Importee]
else
false
}

def isAmbiguousInParent(t: Tree, parent: Tree): Boolean = {
t match {
case t: Term.Name =>
Expand Down

0 comments on commit 2db5f93

Please sign in to comment.