akka-js / akka.js

Akka, for Scala.js
http://akka-js.org
474 stars 39 forks source link

Linking errors appear when using Akka.js with circe-java8 and sbt 1.3.0 #98

Closed pishen closed 4 years ago

pishen commented 5 years ago

Here's a minimal project to reproduce it: https://github.com/pishen/circe_akka_js_sbt

This only happen when using Akka.js and circe-java8 and sbt 1.3.0 together. If I downgrade to sbt 1.2.8 or remove circe-java8 or remove akka.js, things will work.

When running fastOptJS, I saw this:

[error] Referring to non-existent method java.time.LocalDate.compareTo0(java.time.LocalDate)scala.Int
[error]   called from java.time.LocalDateTime.compareTo0(java.time.LocalDateTime)scala.Int
[error]   called from java.time.LocalDateTime.compareTo(java.time.chrono.ChronoLocalDateTime)scala.Int
[error]   called from java.time.LocalDateTime.compareTo(java.lang.Object)scala.Int
[error]   called from scala.math.LowPriorityOrderingImplicits$$anon$3.compare(java.lang.Object,java.lang.Object)scala.Int
[error]   called from scala.math.Ordering.gteq(java.lang.Object,java.lang.Object)scala.Boolean
[error]   called from scala.math.LowPriorityOrderingImplicits$$anon$3.gteq(java.lang.Object,java.lang.Object)scala.Boolean
[error]   called from scala.collection.TraversableOnce.$$anonfun$max$1(scala.math.Ordering,java.lang.Object,java.lang.Object)java.lang.Object
[error]   called from scala.collection.immutable.HashMap.$$anonfun$max$1(scala.math.Ordering,java.lang.Object,java.lang.Object)java.lang.Object
[error]   called from scala.collection.TraversableOnce.max(scala.math.Ordering)java.lang.Object
[error]   called from scala.collection.AbstractTraversable.max(scala.math.Ordering)java.lang.Object
[error]   called from akka.util.ManifestInfo.checkSameVersion(java.lang.String,scala.collection.immutable.Seq,scala.Boolean)scala.Boolean
[error]   called from akka.actor.ActorSystemImpl.liftedTree2$1()akka.actor.ActorSystemImpl
[error]   called from akka.actor.ActorSystemImpl.$$undstart$lzycompute()akka.actor.ActorSystemImpl
[error]   called from akka.actor.ActorSystemImpl.$$undstart()akka.actor.ActorSystemImpl
[error]   called from akka.actor.ActorSystemImpl.start()akka.actor.ActorSystemImpl
[error]   called from akka.actor.ActorSystem$.apply(java.lang.String,akka.actor.setup.ActorSystemSetup)akka.actor.ActorSystem
[error]   called from akka.actor.ActorSystem$.apply(java.lang.String,scala.Option,scala.Option,scala.Option)akka.actor.ActorSystem
[error]   called from akka.actor.ActorSystem$.apply(java.lang.String)akka.actor.ActorSystem
[error]   called from core.Main$.main([java.lang.String)scala.Unit
[error]   called from core module module initializers
[error] involving instantiated classes:
[error]   java.time.LocalDateTime
[error]   scala.math.LowPriorityOrderingImplicits$$anon$3
[error]   scala.collection.immutable.HashMap$EmptyHashMap$
[error]   scala.collection.immutable.HashMap$HashMap1
[error]   scala.collection.immutable.HashMap$HashMapCollision1
[error]   scala.collection.immutable.HashMap$HashTrieMap
[error]   scala.collection.immutable.HashMap
[error]   scala.collection.immutable.SortedMap$DefaultKeySortedSet
[error]   scala.collection.immutable.Set$Set2
[error]   scala.collection.immutable.HashSet$HashTrieSet
[error]   scala.collection.immutable.Set$EmptySet$
[error]   scala.collection.immutable.MapLike$ImmutableDefaultKeySet
[error]   scala.collection.immutable.Set$Set3
[error]   scala.collection.immutable.HashSet$HashSet1
[error]   scala.collection.immutable.ListSet$Node
[error]   scala.collection.immutable.HashSet$HashSetCollision1
[error]   scala.collection.immutable.ListSet$EmptyListSet$
[error]   scala.collection.immutable.Set$Set1
[error]   scala.collection.immutable.HashSet$EmptyHashSet$
[error]   scala.collection.immutable.Set$Set4
[error]   scala.collection.immutable.HashSet
[error]   akka.util.ManifestInfo
[error]   akka.actor.ActorSystemImpl
[error]   akka.actor.ActorSystem$
[error]   core.Main$

The whole error message is available here: https://gist.github.com/pishen/e000860e99a58637bf5fd33dd0659edc

andreaTP commented 5 years ago

thanks for reporting and for the repro! it should be as easy as short-circuiting akka.util.ManifestInfo.checkSameVersion to true, we don't have anyhow information from the Manifest, the check is pointless.

Will probably take a look next week during Scala Italy and release and updated version containing the fix.

andreaTP commented 4 years ago

Sorry for the long delay removed the source cause from akka.util.ManifestInfo, release is 1.2.5.26 please note that this is not enough to link your example due to missing java8 time implementation in Scala.Js itself. You can try to use: https://github.com/cquiroz/scala-java-time but it has possible limitation as well.

ChristianPolt commented 4 years ago

@andreaTP The problem is fixed in version 1.2.5.26, however in version 2.2.6.3 the problem still remains for me. Is the fix #98 also present in version 2.2.6.3?

andreaTP commented 4 years ago

Hey @ChristianPolt it does indeed: https://github.com/akka-js/akka.js/blob/v2.2.6.3/akka-js-actor/js/src/main/scala/akka/util/ManifestInfo.scala#L165-L185

it's my understanding that this specific method shouldn't give any linking problem anymore. Can you check if it's a problem with caching running an sbt clean? If not probably the liker exception is different, can you please post it and/or provide a reproduction?

ChristianPolt commented 4 years ago

The following example does not work with Version "2.2.6.3", but works with Version "1.2.5.26":

build.properties:

sbt.version=1.3.8

plugins.sbt:

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

Main.scala:

package core

import java.time.LocalDateTime

object Main {
  def main(args: Array[String]): Unit = {
    LocalDateTime.now()
  }
}

build.sbt:

val akkaJsVersionNotWorking = "2.2.6.3"
val akkaJsVersionWorking = "1.2.5.26"
lazy val root = (project in file("."))
  .enablePlugins(ScalaJSPlugin)
  .settings(
    name := "akka_js_test",
    scalaVersion := "2.12.11",
    scalaJSUseMainModuleInitializer := true,
    libraryDependencies ++= Seq(
      "org.akka-js" %%% "akkajsactor" % akkaJsVersionNotWorking,
      "io.github.cquiroz" %%% "scala-java-time" % "2.0.0-M12"
    )
  )

The output (fastOptJS) with the linking errors is attached in this file: LinkingErrors.txt

andreaTP commented 4 years ago

Thanks for the reproduction @ChristianPolt ! It's not a regression in Akka.Js, this simply depends on the order dependencies are picked-up by the linker that is not deterministic. Basically Akka.Js ships with scalajs-java-time that is strictly a minimal subset of scala-java-time (e.g. it doesn't contain java.time.LocalDateTime), in this case the fix(and to make a reproduciple build even with 1.2.5.26) is to exclude from the transitive libraries scalajs-java-time:

"org.akka-js" %%% "akkajsactor" % akkaJsVersionNotWorking exclude("org.scala-js", "scalajs-java-time")

Since this is a problem that happened in the past and most likely is going to affect users in the future I will follow up with this explanation in the readme (if @cquiroz doesn't have a better suggestion :-) ).