rules_scala icon indicating copy to clipboard operation
rules_scala copied to clipboard

Support for Scala.js

Open ngbinh opened this issue 9 years ago • 19 comments

Scala.js http://www.scala-js.org/ has been very popular in Scala community. At work we are having a very large code base in both Scala (backend) and Scala.js (frontend). I am wondering if anyone has tried to compile scala.js using bazel?

ngbinh avatar Sep 06 '16 16:09 ngbinh

it would be nice to have support for scalajs. I have not looked at it.

johnynek avatar Sep 06 '16 18:09 johnynek

@ngbinh @johnynek I managed to create the .sjsir files in https://gist.github.com/muller/728f3d4c45ec593f1fde4fce19d686ea.

I am working now on execute the linking part with a genrule, what should give me the JavaScript file.

muller avatar Aug 29 '17 08:08 muller

thanks!

ngbinh avatar Aug 29 '17 14:08 ngbinh

Nice work!

It would be great to have this be an easy option we could set up with a scala toolchain #170

johnynek avatar Aug 29 '17 17:08 johnynek

I just added the linker to the gist. Now it is possible to write .scala and get .js out.

@johnynek I don't fully understand the toolchains. I will have a look on #170, see if I can port this gist to use it.

muller avatar Aug 30 '17 10:08 muller

note that with #380 we can probably think about how to do this again.

We might need to look at adding scalajs support to scala_import.

johnynek avatar Jan 04 '18 19:01 johnynek

Sounds interesting! What do you mean by scala.js support in scala_import? On Thu, 4 Jan 2018 at 21:41 P. Oscar Boykin [email protected] wrote:

note that with #380 https://github.com/bazelbuild/rules_scala/issues/380 we can probably think about how to do this again.

We might need to look at adding scalajs support to scala_import.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/bazelbuild/rules_scala/issues/90#issuecomment-355377356, or mute the thread https://github.com/notifications/unsubscribe-auth/ABUIF2zFn_rY64T_0ACMX_dnwX4KgQ8yks5tHSf-gaJpZM4J2CCw .

ittaiz avatar Jan 04 '18 21:01 ittaiz

scala.js uses maven jars for its compiled code. So, for scala_import, you could also say this scala library exists for jvm and js (and maybe later, native).

Then when we go to compile a library that we want scalajs for, we make sure all dependencies are scala, or transitively depend on scala_import with js. That might work.

johnynek avatar Jan 04 '18 22:01 johnynek

I too have had luck getting rules_scala to build me .sjsir files, with the following in my WORKSPACE

 scala_maven_import_external(
    name = "org_scala_js_scalajs_compiler",
    artifact = "org.scala-js:scalajs-compiler_2.12.8:0.6.28",
    licenses = ["notice"],
    server_urls = [
        "https://repo.maven.apache.org/maven2/",
    ],   
)

bind(
  name = 'jar/org/scala_js/scalajs_compiler_2_12_8_0_6_28',
  actual = '@org_scala_js_scalajs_compiler//jar'
)

and in my BUILD's scala-library

plugins = ["@org_scala_js_scalajs_compiler//jar"]

is all that's needed to make scala emit a .jar file with .sjsir files inside it. The linker program above worked perfectly, even to fullOptJS things, by modifying the Linker's Config object.

I'd love to have support for scalajs, and AFAICT this involves adding support for scalajs by changing new_scala_default_repository to support scalajs importing by including the fully version-qualified org.scalajs scalajs-compiler, scalajs-ir, and scalajs-tools into the included libraries if it's a JS project, and an additional target rule similar to the existing scaladoc/tut ones.

If i have time in the coming weeks, i'll format this stuff out as a PR

DhashS avatar Sep 09 '19 05:09 DhashS

Amazing that it is so easy! I'd love to see a PR with docs, or better a small example that we can add to the tests.

It would be interesting to think about how to not have to define two separate build targets. It could be that aspects could be useful here. If a target only defines scala dependencies, then we could possibly generate all the internal scalajs_library targets with an aspect.

johnynek avatar Sep 10 '19 03:09 johnynek

Btw, A co-worker at Wix has an internal scala.js back-office application built and deployed to production for a few months now

On Tue, Sep 10, 2019 at 6:06 AM P. Oscar Boykin [email protected] wrote:

Amazing that it is so easy! I'd love to see a PR with docs, or better a small example that we can add to the tests.

It would be interesting to think about how to not have to define two separate build targets. It could be that aspects could be useful here. If a target only defines scala dependencies, then we could possibly generate all the internal scalajs_library targets with an aspect.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/bazelbuild/rules_scala/issues/90?email_source=notifications&email_token=AAKQQFZSPYNXKOYLTLCYUZ3QI4FKBA5CNFSM4COYECYKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6JVJIA#issuecomment-529749152, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKQQF3TKPXNXBS5E5H4FTTQI4FKBANCNFSM4COYECYA .

ittaiz avatar Sep 21 '19 14:09 ittaiz

I've completed a linker to turn the SJSIR/class files into js, and have added some checks to make it successfully build JS. I'm going to clean up my code and submit a PR soon - need to finish

  1. Tests
  2. Removing hacks
  3. Passing arguments to the linker

DhashS avatar Nov 24 '19 01:11 DhashS

Thanks! Very interesting. Please take into account that in the next 2-3 weeks we won’t be able to accept contributions since we’re merging a huge refactor PR which changes the architecture of the rules. After it’s in and you’ll readjust to it’s pattern I’d love to review.

On Sun, 24 Nov 2019 at 3:32 Dhash Shrivathsa [email protected] wrote:

I've completed a linker to turn the SJSIR/class files into js, and have added some checks to make it successfully build JS. I'm going to clean up my code and submit a PR soon - need to finish

  1. Tests
  2. Removing hacks
  3. Passing arguments to the linker

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/bazelbuild/rules_scala/issues/90?email_source=notifications&email_token=AAKQQF52G36ZZA4AW7YN4ZTQVHKQ3A5CNFSM4COYECYKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFABR4Q#issuecomment-557848818, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKQQF5WDPQJOVZQGKPYRCLQVHKQ3ANCNFSM4COYECYA .

--

Ittai Zeidman

Cell: 054-6735021

40 Hanamal street, Tel Aviv, Israel

http://www.wix.com

ittaiz avatar Nov 24 '19 04:11 ittaiz

@ittaiz any progress around scalajs integration?

dieu avatar May 15 '20 06:05 dieu

None on my side. @DhashS are you interested in picking it up? @avitaln FYI

ittaiz avatar May 15 '20 08:05 ittaiz

Hi everyone, I'm interested in playing with this, but I wanted to see if anyone had done any work before getting in too deep.

I'm mostly hoping to get scalapb and :crossed_fingers: scalapb-grpcweb working, the latter of which depends on a very new version of scala.js (1.5.0). I was able to get a simple build working (no scalapb) with @muller 's gist + an updated scala.js linker: https://gist.github.com/2201dda3b4acdeb0a9206f5073060745.

If anyone has pointers or suggestions, please drop em here!

gvacaliuc avatar Feb 27 '21 16:02 gvacaliuc

No update but I wish you a lot of luck!

ittaiz avatar Feb 27 '21 20:02 ittaiz

I was able to get things mostly working! It's still quite rough and definitely not ready for review, as there are many open questions, but if anyone is interested in taking a look / making suggestions, the rules_scala changes are here: https://github.com/ConsultingMD/rules_scala/pull/14 and there is an example repo that uses them with a compatible toolchain here: https://github.com/gvacaliuc/bazel-scalapb-grpcweb-example.

gvacaliuc avatar Mar 05 '21 14:03 gvacaliuc