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 Scala3 support #27

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
23 changes: 14 additions & 9 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,14 @@ object `llvm-firtool` extends JavaModule with ChipsAlliancePublishModule {
// ******************** WARNING ********************
// This is extremely manual and changing dependencies IN ANY WAY (including bumping version)
// requires carefully checking the packages to shade and dynamic ivy deps in the outer project
object `firtool-resolver` extends Cross[FirtoolResolver]("2.13", "2.12")
trait FirtoolResolver extends CrossScalaModule with ChipsAlliancePublishModule { root =>
object `firtool-resolver` extends Cross[FirtoolResolver]("2.13", "2.12", "3.4", "3.3")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
object `firtool-resolver` extends Cross[FirtoolResolver]("2.13", "2.12", "3.4", "3.3")
object `firtool-resolver` extends Cross[FirtoolResolver]("2.13", "2.12", "3")

trait FirtoolResolver extends CrossSbtModule with ChipsAlliancePublishModule { root =>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rather than switching this to SBT style, I would rather stick with vanilla Mill style. We only use SBT style in Chisel for historical reasons, we could just override millSourcePath here. Fortunately, we don't even need to do that as I will explain below.


override def crossScalaVersion = Map(
"2.13" -> "2.13.11",
"2.12" -> "2.12.18"
"2.12" -> "2.12.18",
"3.4" -> "3.4.2",
"3.3" -> "3.3.3"
Comment on lines +242 to +243
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"3.4" -> "3.4.2",
"3.3" -> "3.3.3"
"3" -> "3.3.3"

Scala 3 maintains binary compatibility across all minor versions so there is no reason to cross compile for any version but 1 in Scala 3 (unlike Scala 2 where it you do have to compile differently for 2.12 and 2.13.

)(crossValue)

def scalacOptions = Seq("-deprecation", "-feature", "-release:8")
Expand Down Expand Up @@ -281,8 +283,7 @@ trait FirtoolResolver extends CrossScalaModule with ChipsAlliancePublishModule {
ivy"org.scala-lang.modules::scala-collection-compat:2.11.0"
)

object core extends ScalaModule {

object core extends CrossSbtModule with CrossValue {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
object core extends CrossSbtModule with CrossValue {
object core extends ScalaModule with CrossValue {

def scalaVersion = root.scalaVersion

def scalacOptions = root.scalacOptions
Expand All @@ -292,10 +293,14 @@ trait FirtoolResolver extends CrossScalaModule with ChipsAlliancePublishModule {

// We cannot use os-lib because it cannot be shaded without screwing up
// getting System property os.name
def ivyDeps = Agg(
ivy"dev.dirs:directories:26",
ivy"io.get-coursier::coursier:2.1.8",
)
def ivyDeps = if (this.crossScalaVersion.startsWith("3")) {
Agg(ivy"dev.dirs:directories:26")
} else {
Agg(
ivy"dev.dirs:directories:26",
ivy"io.get-coursier::coursier:2.1.8",
)
}

// Modify the classpath to remove things we want to dynamically link (Scala jars).
override def upstreamAssemblyClasspath: T[Agg[PathRef]] = T {
Expand Down
296 changes: 0 additions & 296 deletions firtool-resolver/src/Main.scala

This file was deleted.

48 changes: 48 additions & 0 deletions firtool-resolver/src/main/scala-2/FetchArtifact.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: Apache-2.0

package firtoolresolver

import scala.util.{Failure, Success, Try}
import java.net.URLClassLoader
import coursier._
import coursier.core.Extension

object FetchArtifact {
def apply(logger: Logger, defaultVersion: String): Either[String, FirtoolBinary] = {
val platform =
determinePlatform(logger) match {
case Left(msg) =>
logger.debug(msg)
return Left(msg)
case Right(name) => name
}
// See coursier.parse.DependencyParser to understand how the classifier is added via Publication
val org = Organization(groupId)
val module = Module(org, ModuleName(s"$artId"), Map())
val dep =
Dependency(module, defaultVersion)
.withPublication("", Type.empty, Extension.empty, Classifier(platform))
// One would think there'd be a built-in pretty print like this but there isn't
// (coursier.util.Print doesn't include the classifier)
logger.debug(s"Attempting to fetch ${dep.module}:${dep.version},clasifier=${platform}")

val resolution = Try {
coursier.Fetch()
.addDependencies(dep)
.run()
}
if (resolution.isFailure) {
val msg = resolution.failed.get.toString + "\n" // Coursier's message is already pretty good
logger.debug(msg)
return Left(msg)
}
// Head here is dangerous, without the classifier, multiple jars are fetched
val jar = resolution.get.head
logger.debug(s"Successfully fetched $jar")


logger.debug(s"Loading $jar to search its resources")
val classloader = new URLClassLoader(Array(jar.toURI.toURL))
checkResources(Some(classloader), logger)
}
}
Loading
Loading