Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Scala.js #90

Open
ngbinh opened this issue Sep 6, 2016 · 18 comments
Open

Support for Scala.js #90

ngbinh opened this issue Sep 6, 2016 · 18 comments

Comments

@ngbinh
Copy link

ngbinh commented Sep 6, 2016

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
Copy link
Member

johnynek commented Sep 6, 2016

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

@muller
Copy link

muller commented Aug 29, 2017

@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
Copy link
Author

ngbinh commented Aug 29, 2017

thanks!

@johnynek
Copy link
Member

Nice work!

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

@muller
Copy link

muller commented Aug 30, 2017

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
Copy link
Member

johnynek commented Jan 4, 2018

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
Copy link
Member

ittaiz commented Jan 4, 2018 via email

@johnynek
Copy link
Member

johnynek commented Jan 4, 2018

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
Copy link

DhashS commented Sep 9, 2019

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
Copy link
Member

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
Copy link
Member

ittaiz commented Sep 21, 2019 via email

@DhashS
Copy link

DhashS commented Nov 24, 2019

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
Copy link
Member

ittaiz commented Nov 24, 2019 via email

@dieu
Copy link

dieu commented May 15, 2020

@ittaiz any progress around scalajs integration?

@ittaiz
Copy link
Member

ittaiz commented May 15, 2020

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

@gvacaliuc
Copy link

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 🤞 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
Copy link
Member

ittaiz commented Feb 27, 2021

No update but I wish you a lot of luck!

@gvacaliuc
Copy link

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: ConsultingMD#14 and there is an example repo that uses them with a compatible toolchain here: https://github.com/gvacaliuc/bazel-scalapb-grpcweb-example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants