Giter Club home page Giter Club logo

Comments (11)

lloydmeta avatar lloydmeta commented on July 17, 2024

Hi there,

This is a bit embarrassing, but I've never used ScalaJs before and don't even know how to start making this compatible with it. It would be great if this lib was made compatible with it and help is definitely welcome.

BTW, what kind of problems are you having?

Lloyd

from enumeratum.

PhilAndrew avatar PhilAndrew commented on July 17, 2024

I had a try today with it in ScalaJS, I guess you use reflection, which would be the main problem. Reflection is not happy in ScalaJS.

So methods like values, withName, withNameOption, don't work.

[info] Fast optimizing C:\home\projects\shape\shape\shape\target\scala-2.11\example-fastopt.js
[error] Referring to non-existent class Lenumeratum_Enum
[error] called from Lexample_Main$.setupPaperJS__Lorg_scalajs_dom_raw_HTMLCanvasElement__sci_Set
[error] called from Lexample_Main$.setupApplication__Lorg_scalajs_dom_raw_HTMLCanvasElement__sci_Set
[error] called from Lexample_Main$.main__Lorg_scalajs_dom_raw_HTMLCanvasElement__V
[error] called from Lexample_Main$.$$js$exported$meth$main__Lorg_scalajs_dom_raw_HTMLCanvasElement__O
[error] called from Lexample_Main$.main
[error] exported to JavaScript with @JSExport
[error] involving instantiated classes:
[error] Lexample_Main$
[error] Referring to non-existent method Lenumeratum_Enum$class.$$init$Lenumeratum_Enum__V
[error] called from Lexample_Greeting$.init_

[error] called from Lexample_Main$.setupPaperJS__Lorg_scalajs_dom_raw_HTMLCanvasElement__sci_Set
[error] called from Lexample_Main$.setupApplication__Lorg_scalajs_dom_raw_HTMLCanvasElement__sci_Set
[error] called from Lexample_Main$.main__Lorg_scalajs_dom_raw_HTMLCanvasElement__V
[error] called from Lexample_Main$.$$js$exported$meth$main__Lorg_scalajs_dom_raw_HTMLCanvasElement__O
[error] called from Lexample_Main$.main
[error] exported to JavaScript with @JSExport
[error] involving instantiated classes:
[error] Lexample_Main$
[info] workbench: Checking example-fastopt.js
[info] workbench: Refreshing http://localhost:12345\target\scala-2.11\example-fastopt.js
java.lang.RuntimeException: There were linking errors
at scala.sys.package$.error(package.scala:27)
at org.scalajs.core.tools.optimizer.Linker.link(Linker.scala:92)
at org.scalajs.core.tools.optimizer.Linker.link(Linker.scala:59)
at org.scalajs.core.tools.optimizer.ScalaJSOptimizer$$anonfun$1.apply(ScalaJSOptimizer.scala:106)
at org.scalajs.core.tools.optimizer.ScalaJSOptimizer$$anonfun$1.apply(ScalaJSOptimizer.scala:106)
at org.scalajs.core.tools.optimizer.package$.logTime(package.scala:19)
at org.scalajs.core.tools.optimizer.ScalaJSOptimizer.optimizeIR(ScalaJSOptimizer.scala:105)
at org.scalajs.core.tools.optimizer.ScalaJSOptimizer.optimizeIR(ScalaJSOptimizer.scala:89)
at org.scalajs.core.tools.optimizer.ScalaJSOptimizer$$anonfun$optimizeCP$1.apply$mcV$sp(ScalaJSOptimizer.scala:65)
at org.scalajs.core.tools.io.CacheUtils$.cached(CacheUtils.scala:41)
at org.scalajs.core.tools.optimizer.ScalaJSOptimizer.optimizeCP(ScalaJSOptimizer.scala:63)
at org.scalajs.sbtplugin.ScalaJSPluginInternal$$anonfun$14.apply(ScalaJSPluginInternal.scala:145)
at org.scalajs.sbtplugin.ScalaJSPluginInternal$$anonfun$14.apply(ScalaJSPluginInternal.scala:129)
at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
at sbt.std.Transform$$anon$4.work(System.scala:63)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
at sbt.Execute.work(Execute.scala:235)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
error There were linking errors
[error] Total time: 1 s, completed Apr 3, 2015 8:17:58 PM
13. Waiting for source changes... (press enter to interrupt)

from enumeratum.

lloydmeta avatar lloydmeta commented on July 17, 2024

Interesting, do you mind sharing your code on Github so I can try it out?

I guess you use reflection, which would be the main problem.

The macro that powers this uses the reflection packages at compile time to find members of the type passed to Enum. That said, not knowing anything about ScalaJs, I'm hoping like @sjrd or @gzm0 could give us some pointers...

from enumeratum.

sjrd avatar sjrd commented on July 17, 2024

Compile-time reflection is all fine. Runtime reflection is not supported.

But here the missing is class is "Referring to non-existent class Lenumeratum_Enum", which is a part of this project. So @PhilAndrew it seems you're depending on this library with a %% dependency, instead of a Scala.js dependency (%%%).

from enumeratum.

PhilAndrew avatar PhilAndrew commented on July 17, 2024

Yes I used %%, not %%% ... sorry I'm a trouble, I'm just a user of libraries but don't look into the details of what its doing enough.
However if I do %%% it doesn't work as it cannot find its dependency. I guess if I am eager to use this I should try to make it work in ScalaJS myself and submit the pull request, I'm being a bit lazy by asking here.

from enumeratum.

sjrd avatar sjrd commented on July 17, 2024

Libraries need to be published separately for Scala.js, using the Scala.js sbt plugin. So it is normal that it cannot find the dependency: it's not published. There are discussions on the Scala.js mailing list on how to publish a library for Scala.js.

from enumeratum.

lloydmeta avatar lloydmeta commented on July 17, 2024

@sjrd thanks for clearing that up; so theoretically, the core lib + macro should work; the Play-enhanced projects might not (depending on whether or not the Play libs they depend on have ScalaJS published versions).

@PhilAndrew yeah, I took a look in the ScalaJs docs and apparently it requires libs to be specially published for ScalaJs, which I hadn't done.

I took a stab at making this lib ScalaJS compatible in 2e94a5c (new branch feature/scalajs) but:

  1. I don't think Scalatest works with ScalaJs, meaning I don't know if the end product actually works...
  2. Beyond compiled classes making it into the new projects' target directories, nothing seems to have changed much:
[info] Compiling 1 Scala source to /Users/Lloyd/Documents/scala_dev/enumeratum/enumeratum-core/jvm/target/scala-2.10/classes...
[info] Compiling 1 Scala source to /Users/Lloyd/Documents/scala_dev/enumeratum/enumeratum-core/js/target/scala-2.10/classes...

I was able to publish 1.1.1-SNAPSHOT for the ScalaJs Macro + Core projects and push it to Sonatype snapshots. Let me know if it works. Not sure how much further I can help here because I don't use ScalaJs; would definitely appreciate a helping hand 😄

EDIT: actually, I don't think it worked, I don't see any JARs named *sjs0.6_2* like it said in the cross building docs.

from enumeratum.

sjrd avatar sjrd commented on July 17, 2024

ScalaTest does not work with Scala.js yet, indeed. Although they're working on it :)

Your commit looks good to me. I would suggest using a Pure cross-type, since you don't have any platform-specific source files. This way you don't have to move files to shared/.

So if you run for example macrosJs/package it should definitely create a JAR named *sjs0.6_* something in the target/scala-2.11/ directory. Also, next to the .class files there should be .sjsir files as well.

from enumeratum.

lloydmeta avatar lloydmeta commented on July 17, 2024

@sjrd Thanks for the tip on using the Pure cross-type; it looks a lot better now 705237d

However, that alone didnt allow me to publish *sjs0.6_* JARs. The problem was that I had (stupidly?) put crossScalaVersions and crossVersion settings in each of the projects. Removing those settings and just having them in the root (aggregate) project fixed things, allowing the JARs to be created + published :)

ScalaTest does not work with Scala.js yet, indeed. Although they're working on it :)

Ah sounds good; not too keen on porting all the tests to micro test. Hopefully that is finished soon. On an unrelated note, once more and more libs become compatible w/ ScalaJs...I wonder if .Net compatibility will come back 😛

EDIT: Doesn't look like scoverage is happy w/ the new .js .jvm directories.

@PhilAndrew Can you give 1.1.1-SNAPSHOT a try w/ your ScalaJs project? I've now published the SNAPSHOT versions for ScalaJS to Sonatype.

from enumeratum.

lloydmeta avatar lloydmeta commented on July 17, 2024

I managed to port the tests to utest, but there are other issues.

I think the conversation should continue at #9

from enumeratum.

lloydmeta avatar lloydmeta commented on July 17, 2024

Closing because ScalaJS support added as of version 1.3.4

from enumeratum.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.