bazelbuild / rules_scala

Scala rules for Bazel
Apache License 2.0
363 stars 278 forks source link

Support for Scala.js #90

Open ngbinh opened 8 years ago

ngbinh commented 8 years ago

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?

johnynek commented 8 years ago

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

muller commented 7 years ago

@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.

ngbinh commented 7 years ago

thanks!

johnynek commented 7 years ago

Nice work!

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

muller commented 7 years ago

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.

johnynek commented 6 years ago

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.

ittaiz commented 6 years ago

Sounds interesting! What do you mean by scala.js support in scala_import? On Thu, 4 Jan 2018 at 21:41 P. Oscar Boykin notifications@github.com 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 .

johnynek commented 6 years ago

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.

DhashS commented 5 years ago

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

johnynek commented 5 years ago

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.

ittaiz commented 5 years ago

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 notifications@github.com 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 .

DhashS commented 4 years ago

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
ittaiz commented 4 years ago

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 notifications@github.com 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

dieu commented 4 years ago

@ittaiz any progress around scalajs integration?

ittaiz commented 4 years ago

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

gvacaliuc commented 3 years ago

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!

ittaiz commented 3 years ago

No update but I wish you a lot of luck!

gvacaliuc commented 3 years ago

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.