Log4s / log4s

High-performance SLF4J wrapper for Scala.
Other
171 stars 25 forks source link

Support Scala 3.0.0 #75

Closed kevin-lee closed 3 years ago

kevin-lee commented 3 years ago

Support Scala 3.0.0

@rossabaker Sorry I tried to use your commit for #64 but failed since it's not up to date. I had some issue when I tired to rebase.

My PR contains two commits. The first one is purely config changes and the second one is mostly from your commit with a little changes so please feel free to replace the second one with yours if you want.

Unfortunately, I don't have knowledge of the entire codebase so I'm not 100% sure if I've done it properly but I when ran the following sbt task, I got all the expected artifacts.

+packagedArtifacts
rossabaker commented 3 years ago

I still get these linking errors when I enable 3.0.0. I'm not a scala.js person. I suppose we could release to unblock downstream projects and hope to introduce the scala.js support in a patch release.

[error] Referring to non-existent method scala.scalajs.js.$bar$.UnionOps(java.lang.Object)java.lang.Object
[error]   called from org.log4s.log4sjs.FunctionalType.fromDynamicType(scala.scalajs.js.$bar)scala.scalajs.js.Any
[error]   called from static org.log4s.log4sjs.FunctionalType.org$log4s$log4sjs$FunctionalType$Provider$$$_$$lessinit$greater$$anonfun$4(org.log4s.log4sjs.FunctionalType,scala.scalajs.js.$bar)scala.scalajs.js.Any
[error]   called from constructor org.log4s.log4sjs.FunctionalType$Provider$.<init>(org.log4s.log4sjs.FunctionalType)void
[error]   called from org.log4s.log4sjs.FunctionalType.Provider()org.log4s.log4sjs.FunctionalType$Provider$
[error]   called from org.log4s.PlatformInit$.init()void
[error]   called from org.log4s.LoggerInit.$init$()void
[error]   called from constructor org.log4s.GetLoggerSpec.<init>()void
[error]   called from static constructor org.log4s.GetLoggerSpec.<stinit>()void
[error]   called from core module analyzer
[error] involving instantiated classes:
[error]   org.log4s.log4sjs.Log4sAppender$
[error]   org.log4s.PlatformInit$
[error] Referring to non-existent method scala.scalajs.js.$bar$UnionOps$.merge$extension(java.lang.Object,scala.scalajs.js.$bar$Evidence)java.lang.Object
[error]   called from org.log4s.log4sjs.FunctionalType.fromDynamicType(scala.scalajs.js.$bar)scala.scalajs.js.Any
[error]   called from static org.log4s.log4sjs.FunctionalType.org$log4s$log4sjs$FunctionalType$Provider$$$_$$lessinit$greater$$anonfun$4(org.log4s.log4sjs.FunctionalType,scala.scalajs.js.$bar)scala.scalajs.js.Any
[error]   called from constructor org.log4s.log4sjs.FunctionalType$Provider$.<init>(org.log4s.log4sjs.FunctionalType)void
[error]   called from org.log4s.log4sjs.FunctionalType.Provider()org.log4s.log4sjs.FunctionalType$Provider$
[error]   called from org.log4s.PlatformInit$.init()void
[error]   called from org.log4s.LoggerInit.$init$()void
[error]   called from constructor org.log4s.GetLoggerSpec.<init>()void
[error]   called from static constructor org.log4s.GetLoggerSpec.<stinit>()void
[error]   called from core module analyzer
[error] involving instantiated classes:
[error]   org.log4s.log4sjs.Log4sAppender$
[error]   org.log4s.PlatformInit$
[error] Referring to non-existent method scala.scalajs.js.$bar$UnionOps$.merge$extension(java.lang.Object,scala.scalajs.js.$bar$Evidence)java.lang.Object
[error]   called from org.log4s.log4sjs.FunctionalType.fromDynamicType(scala.scalajs.js.$bar)scala.scalajs.js.Any
[error]   called from static org.log4s.log4sjs.FunctionalType.org$log4s$log4sjs$FunctionalType$Provider$$$_$$lessinit$greater$$anonfun$4(org.log4s.log4sjs.FunctionalType,scala.scalajs.js.$bar)scala.scalajs.js.Any
[error]   called from constructor org.log4s.log4sjs.FunctionalType$Provider$.<init>(org.log4s.log4sjs.FunctionalType)void
[error]   called from org.log4s.log4sjs.FunctionalType.Provider()org.log4s.log4sjs.FunctionalType$Provider$
[error]   called from org.log4s.PlatformInit$.init()void
[error]   called from org.log4s.LoggerInit.$init$()void
[error]   called from constructor org.log4s.GetLoggerSpec.<init>()void
[error]   called from static constructor org.log4s.GetLoggerSpec.<stinit>()void
[error]   called from core module analyzer
[error] involving instantiated classes:
[error]   org.log4s.log4sjs.Log4sAppender$
[error]   org.log4s.PlatformInit$
[error] There were linking errors
kevin-lee commented 3 years ago

👍 Nice, thank you.

It looks like the crossScalaVersions for scala.js are still restricted to 2.x? Is the scala.js support still missing for 3.0, even though this brings us closer?

Oh sorry, I totally missed that crossScalaVersions := crossScalaVersions.value.filter(_.startsWith("2.")). OK. so it still has linking errors as you said. Hmmm let me check if there's any known solution.

rossabaker commented 3 years ago

It seems to be coming from this part of FunctionalType.scala, but I haven't found a solution yet. It doesn't like that merge.

  type DynamicType = js.|[FunctionType, Type]

  def fromDynamicType(formatter: DynamicType): Type = {
    val dynamic = formatter.merge.asInstanceOf[js.Dynamic]
    if (dynamic.selectDynamic(dynamicField.name).isInstanceOf[js.Function]) {
      from(dynamic.asInstanceOf[Type])
    } else if (dynamic.isInstanceOf[js.Function]) {
      from(dynamic.asInstanceOf[FunctionType])
    } else {
      throw new IllegalArgumentException(s"$typeName object has no $dynamicField and is not a function: $dynamic")
    }
  }
kevin-lee commented 3 years ago

@rossabaker I think I found some workaround. I'm not sure if it's a correct way but it seems to work. I'll push my code soon.

rossabaker commented 3 years ago

Yes, that looks like a good interim solution to me.

kevin-lee commented 3 years ago

@rossabaker Nice! Thank you!!