Skip to content

Commit

Permalink
Update Mill to support Scala Native on Scala 3
Browse files Browse the repository at this point in the history
Scala Native is not supported yet since it's blocked by PPrint
  • Loading branch information
lolgab committed Mar 1, 2022
1 parent 71c0dd1 commit 6ef2c5f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 27 deletions.
41 changes: 21 additions & 20 deletions build.sc
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import mill._, scalalib._, scalajslib._, scalanativelib._, publish._
import mill.scalalib.api.Util.isScala3
import scalalib._
import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.1.1`
import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.1.4`
import de.tobiasroeser.mill.vcs.version.VcsVersion
import $ivy.`com.github.lolgab::mill-mima::0.0.4`
import $ivy.`com.github.lolgab::mill-mima::0.0.9`
import com.github.lolgab.mill.mima._

val scala212 = "2.12.13"
val scala213 = "2.13.4"
val scala3 = "3.0.2"
val scala30 = "3.0.2"
val scala31 = "3.1.1"

val scalaVersions = Seq(scala212, scala213, scala3)
val scala2Versions = scalaVersions.filter(_.startsWith("2."))
val scala2Versions = List(scala212, scala213)

val scalaJSVersions = for {
scalaV <- scalaVersions
scalaV <- scala30 :: scala2Versions
scalaJSV <- Seq("1.5.1")
} yield (scalaV, scalaJSV)

val scalaNativeVersions = for {
scalaV <- scala2Versions
scalaNativeV <- Seq("0.4.0")
scalaNativeV <- Seq("0.4.3")
} yield (scalaV, scalaNativeV)

trait MainArgsPublishModule extends PublishModule with CrossScalaModule with Mima {
Expand Down Expand Up @@ -60,30 +60,31 @@ trait MainArgsPublishModule extends PublishModule with CrossScalaModule with Mim
) ++ Agg(ivy"com.lihaoyi::pprint:0.6.6")
}

def scalaMajor(scalaVersion: String) = if(isScala3(scalaVersion)) "3" else "2"

trait Common extends CrossScalaModule {
def millSourcePath = build.millSourcePath / "mainargs"
def sources = T.sources(
super.sources() ++ Seq(PathRef(millSourcePath / s"src-$platform"))
millSourcePath / "src",
millSourcePath / s"src-$platform",
millSourcePath / s"src-${scalaMajor(scalaVersion())}",
)
def platform: String
}

trait CommonTestModule extends ScalaModule with TestModule.Utest {
def ivyDeps = Agg(ivy"com.lihaoyi::utest::0.7.10")
def sources = T.sources {
val scalaMajor = if(isScala3(scalaVersion())) "3" else "2"
super.sources() ++ Seq(
millSourcePath / "src",
millSourcePath / s"src-$platform",
millSourcePath / s"src-$platform-$scalaMajor"
).map(PathRef(_))
}
def ivyDeps = Agg(ivy"com.lihaoyi::utest::0.7.11")
def sources = T.sources(
millSourcePath / "src",
millSourcePath / s"src-$platform",
millSourcePath / s"src-${scalaMajor(scalaVersion())}",
)
def platform: String
}


object mainargs extends Module {
object jvm extends Cross[JvmMainArgsModule](scalaVersions: _*)
object jvm extends Cross[JvmMainArgsModule](scala30 :: scala2Versions: _*)
class JvmMainArgsModule(val crossScalaVersion: String)
extends Common with ScalaModule with MainArgsPublishModule {
def platform = "jvm"
Expand All @@ -95,7 +96,7 @@ object mainargs extends Module {

object js extends Cross[JSMainArgsModule](scalaJSVersions: _*)
class JSMainArgsModule(val crossScalaVersion: String, crossJSVersion: String)
extends Common with ScalaJSModule with MainArgsPublishModule {
extends Common with MainArgsPublishModule with ScalaJSModule {
def platform = "js"
def scalaJSVersion = crossJSVersion
object test extends Tests with CommonTestModule{
Expand All @@ -105,7 +106,7 @@ object mainargs extends Module {

object native extends Cross[NativeMainArgsModule](scalaNativeVersions: _*)
class NativeMainArgsModule(val crossScalaVersion: String, crossScalaNativeVersion: String)
extends Common with ScalaNativeModule with MainArgsPublishModule {
extends Common with MainArgsPublishModule with ScalaNativeModule {
def scalaNativeVersion = crossScalaNativeVersion
def platform = "native"
object test extends Tests with CommonTestModule{
Expand Down
26 changes: 19 additions & 7 deletions mill
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,39 @@
# This is a wrapper script, that automatically download mill from GitHub release pages
# You can give the required mill version with MILL_VERSION env variable
# If no version is given, it falls back to the value of DEFAULT_MILL_VERSION
DEFAULT_MILL_VERSION=0.9.10
DEFAULT_MILL_VERSION=0.10.0-38-677a10

set -e

if [ -z "$MILL_VERSION" ] ; then
if [ -f ".mill-version" ] ; then
MILL_VERSION="$(head -n 1 .mill-version 2> /dev/null)"
elif [ -f "mill" ] && [ "$BASH_SOURCE" != "mill" ] ; then
elif [ -f "mill" ] && [ "$0" != "mill" ] ; then
MILL_VERSION=$(grep -F "DEFAULT_MILL_VERSION=" "mill" | head -n 1 | cut -d= -f2)
else
MILL_VERSION=$DEFAULT_MILL_VERSION
fi
fi

MILL_DOWNLOAD_PATH="$HOME/.mill/download"
MILL_EXEC_PATH="${MILL_DOWNLOAD_PATH}/$MILL_VERSION"
if [ "x${XDG_CACHE_HOME}" != "x" ] ; then
MILL_DOWNLOAD_PATH="${XDG_CACHE_HOME}/mill/download"
else
MILL_DOWNLOAD_PATH="${HOME}/.cache/mill/download"
fi
MILL_EXEC_PATH="${MILL_DOWNLOAD_PATH}/${MILL_VERSION}"

version_remainder="$MILL_VERSION"
MILL_MAJOR_VERSION="${version_remainder%%.*}"; version_remainder="${version_remainder#*.}"
MILL_MINOR_VERSION="${version_remainder%%.*}"; version_remainder="${version_remainder#*.}"

if [ ! -x "$MILL_EXEC_PATH" ] ; then
mkdir -p $MILL_DOWNLOAD_PATH
if [ ! -s "$MILL_EXEC_PATH" ] ; then
mkdir -p "$MILL_DOWNLOAD_PATH"
if [ "$MILL_MAJOR_VERSION" -gt 0 ] || [ "$MILL_MINOR_VERSION" -ge 5 ] ; then
ASSEMBLY="-assembly"
fi
DOWNLOAD_FILE=$MILL_EXEC_PATH-tmp-download
MILL_DOWNLOAD_URL="https://github.com/lihaoyi/mill/releases/download/${MILL_VERSION%%-*}/$MILL_VERSION-assembly"
MILL_VERSION_TAG=$(echo $MILL_VERSION | sed -E 's/([^-]+)(-M[0-9]+)?(-.*)?/\1\2/')
MILL_DOWNLOAD_URL="https://github.com/lihaoyi/mill/releases/download/${MILL_VERSION_TAG}/$MILL_VERSION${ASSEMBLY}"
curl --fail -L -o "$DOWNLOAD_FILE" "$MILL_DOWNLOAD_URL"
chmod +x "$DOWNLOAD_FILE"
mv "$DOWNLOAD_FILE" "$MILL_EXEC_PATH"
Expand Down

0 comments on commit 6ef2c5f

Please sign in to comment.