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

Cross-compile for Native #700

Merged
merged 5 commits into from
Jul 20, 2022
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
18 changes: 9 additions & 9 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ val root = project.in(file(".")).settings(
mimaFailOnNoPrevious := false,
publish / skip := true,
)
aggregateProjects(core, sbtplugin, functionalTests)
aggregateProjects(core.jvm, core.native, sbtplugin, functionalTests)
Copy link
Contributor Author

@armanbilge armanbilge Jul 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dwijnand this is the new native sub-project. It's essentially the same if you added a new (JVM) module. So release should work the same.

Does that answer your question?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it's a just another jar submitted to Sonatype? And there are no local system requirements? Compilers, libraries, binaries on PATH, etc? No platform, i.e. Mac/Linux/Windows, implications? I'm not thinking about corner cases and bugs, just regular "what adding Scala Native means to library releases" questions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yup, it's just another Jar :) it's filled with "NIR" (native intermediate representation) files that downstream projects can use to build native binaries. But there's nothing platform-specific we need to do here—we're not shipping a binary.


val munit = "org.scalameta" %% "munit" % "0.7.29"
val munit = Def.setting("org.scalameta" %%% "munit" % "1.0.0-M4")

val core = project.settings(
val core = crossProject(JVMPlatform, NativePlatform).crossType(CrossType.Pure).settings(
name := "mima-core",
crossScalaVersions ++= Seq(scala213, scala3),
libraryDependencies += munit % Test,
libraryDependencies += munit.value % Test,
testFrameworks += new TestFramework("munit.Framework"),
MimaSettings.mimaSettings,
apiMappings ++= {
Expand All @@ -58,25 +58,25 @@ val core = project.settings(
.toMap
},

)
).nativeSettings(mimaPreviousArtifacts := Set.empty)

val sbtplugin = project.enablePlugins(SbtPlugin).dependsOn(core).settings(
val sbtplugin = project.enablePlugins(SbtPlugin).dependsOn(core.jvm).settings(
name := "sbt-mima-plugin",
// drop the previous value to drop running Test/compile
scriptedDependencies := Def.task(()).dependsOn(publishLocal, core / publishLocal).value,
scriptedDependencies := Def.task(()).dependsOn(publishLocal, core.jvm / publishLocal).value,
scriptedLaunchOpts += s"-Dplugin.version=${version.value}",
scriptedLaunchOpts += s"-Dsbt.boot.directory=${file(sys.props("user.home")) / ".sbt" / "boot"}",
MimaSettings.mimaSettings,
)

val testFunctional = taskKey[Unit]("Run the functional test")
val functionalTests = Project("functional-tests", file("functional-tests"))
.dependsOn(core)
.dependsOn(core.jvm)
.configs(IntegrationTest)
.settings(
crossScalaVersions += scala213,
libraryDependencies += "io.get-coursier" %% "coursier" % "2.0.16",
libraryDependencies += munit,
libraryDependencies += munit.value,
testFrameworks += new TestFramework("munit.Framework"),
//Test / run / fork := true,
//Test / run / forkOptions := (Test / run / forkOptions).value.withWorkingDirectory((ThisBuild / baseDirectory).value),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.typesafe.tools.mima.lib

import scala.concurrent.Future
import scala.util.{ Failure, Success, Try }

import munit.{ GenericTest, Location }
import munit.Location

object Test {
def apply(label: String, action: => Try[Unit]): Test1 = Test1(label, () => action)
Expand Down Expand Up @@ -59,9 +60,9 @@ object Test1 {

object Tests {
implicit class Ops(private val t: Tests) extends AnyVal {
def munitTests: List[GenericTest[Unit]] = for {
def munitTests: List[munit.Test] = for {
test <- t.tests
} yield new GenericTest(test.label, () => test.unsafeRunTest(), Set.empty, Location.empty)
} yield new munit.Test(test.label, () => Future.successful(test.unsafeRunTest()), Set.empty, Location.empty)
}
}

Expand Down
3 changes: 3 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ resolvers ++= (if (isStaging) List(stagingResolver) else Nil)
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.1.1")
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.0")

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