GithubHelp home page GithubHelp logo

Support for Scala.js about rules_scala HOT 18 OPEN

bazelbuild avatar bazelbuild commented on June 15, 2024 14
Support for Scala.js

from rules_scala.

Comments (18)

muller avatar muller commented on June 15, 2024 2

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

from rules_scala.

DhashS avatar DhashS commented on June 15, 2024 1

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

from rules_scala.

gvacaliuc avatar gvacaliuc commented on June 15, 2024 1

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.

from rules_scala.

johnynek avatar johnynek commented on June 15, 2024

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

from rules_scala.

ngbinh avatar ngbinh commented on June 15, 2024

thanks!

from rules_scala.

johnynek avatar johnynek commented on June 15, 2024

Nice work!

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

from rules_scala.

muller avatar muller commented on June 15, 2024

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.

from rules_scala.

johnynek avatar johnynek commented on June 15, 2024

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.

from rules_scala.

ittaiz avatar ittaiz commented on June 15, 2024

from rules_scala.

johnynek avatar johnynek commented on June 15, 2024

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.

from rules_scala.

johnynek avatar johnynek commented on June 15, 2024

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.

from rules_scala.

ittaiz avatar ittaiz commented on June 15, 2024

from rules_scala.

DhashS avatar DhashS commented on June 15, 2024

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

from rules_scala.

ittaiz avatar ittaiz commented on June 15, 2024

from rules_scala.

dieu avatar dieu commented on June 15, 2024

@ittaiz any progress around scalajs integration?

from rules_scala.

ittaiz avatar ittaiz commented on June 15, 2024

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

from rules_scala.

gvacaliuc avatar gvacaliuc commented on June 15, 2024

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!

from rules_scala.

ittaiz avatar ittaiz commented on June 15, 2024

No update but I wish you a lot of luck!

from rules_scala.

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.