bazelbuild / rules_scala

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

Scala 3 Support #1269

Open marcesquerra opened 3 years ago

marcesquerra commented 3 years ago

Now that scala 3 is officially live, how difficult would it be to add support for it in bazel?

If it's just a matter of adding a custom toolchain, a bit of documentation would help (I tried to do it in a sample project but couldn't manage)

UPDATE: I initially said I could give a shot on trying to move this forward, but I have to back down. Both the scope of this and the demands of real life ended up being bigger than I thought. But still, support for Scala 3 would still be great!

liucijus commented 3 years ago

It may not be trivial, but any help is appreciated!

What I would do:

  1. Create a small (simple Hello World app is ok) Scala 3 project with rules_scala to learn what are the gaps. Such project will force you to learn how to configure scala toolchain with deps providers for Scala 3 libs (you can use Rules JVM External to manage deps.
  2. Make rules_scala compatible with Scala 3. Keep in mind that we still have 2.11 users, so we need to stay compatible with old versions. This part is the most complex, it includes such complicated parts like dependency analyzer.
  3. Add third party deps to repositories configs. This step can be a blocker for some parts of Rules Scala if there are no Scala 3 support yet for some of the dep.
  4. Add version tests, CI config

Let me know if you get stuck or need help on any of the steps.

cocreature commented 3 years ago

I started looking into this and I got it to the point where I can at least compile & run a hello world https://github.com/cocreature/rules_scala/tree/scala-3. The next big missing piece is probably the dependency analyzer. I’m also largely ignoring backwards compatibility for now since I first want to get it to work before I worry about that too much. The compiler API is completely different so some parts will just consist of duplicating the code. Happy to share the work, the time I can spend on this atm is relatively limited.

liucijus commented 2 years ago

@cocreature would you be still interested contributing your work? I experimented on your changes, you can see how to make them Scala 2.x compatible: https://github.com/liucijus/rules_scala/tree/scala3-in-progress

cocreature commented 2 years ago

Unfortunately I got stuck trying to port the custom scala code for the unused deps & similar to Scala 3 so while it worked for a hello world, I couldn’t actually get it to work on our full project. I don’t expect keeping compatbiility with Scala 2 at the end will be the challenging part.

I don’t have the time at the moment to debug this further so if someone else wants to pick it up, by all means go for it. If not, I expect I’ll eventually get back to it but no idea about timelines.

liucijus commented 2 years ago

@cocreature I'm planning to work on Scala 3 support, and got it working to some extent based on your changes though I had to do some modifications to select code based on Scala version. I thought it would be great to get you attributed for your initial development (ScalaWorker, Scala 3 deps, etc). Of course I can just start from scratch and open PR myself as I did in my fork. But it's up to you to decide. The only requirement is to make the Scala 2 compatible, Scala 3 code can be untested, I will take over from there. Let me know what you think.

cocreature commented 2 years ago

Appreciate it but I’m perfectly happy to not be acknowledged here so just go ahead and open a PR yourself.

liucijus commented 2 years ago

Reopening as it was closed unintentionally

meisam commented 2 years ago

I'd be glad to help with this issue. I just opened #1408 for an issue I was facing with Scala3.

cgrindel commented 1 month ago

Has anyone created an inventory of what needs to be completed to declare victory on Scala3 compatibility? Are there Scala3 features that are not supported, yet?

BillyAutrey commented 1 month ago

I imagine at the very least, we'd want to be able to compile code and add CI to ensure that something using Scala 3 LTS (currently 3.3.4) can compile safely. And, there is some interplay between Scala 3 and 2.13 libraries for compatibility reasons, so we'll want to ensure that anything compiled using those flags doesn't break. Most adopters will be straddling for a while.

Though, now that I've said that, it looks like that's what test_crossbuild does.

Should one of us go through the list of open issues tagged with Scala 3 as a start?

cgrindel commented 4 weeks ago

I just checked. There are no open issues tagged with scala3. I did find two other issues besides this one that mention Scala3.

I pinged this thread, because I saw a scala3 example in the repo and I saw this open issue. I am mostly trying to understand what we think is missing. If anyone is using this ruleset with scala3 code, I would love to hear about it.

BillyAutrey commented 4 weeks ago

I'd say that Scala native is nice to have, not a requirement for Scala3 compatibility of this rule set.

Edit - looks like the cats issue was just transitive dependencies.

If we feel like test_crossbuild has minimal compatibility with Scala 3.3.4, supports the varying crossbuild flags for 2.13/3, supports usage of 2.13 libraries for Scala 3 (like sbt does with for3Use2_13), and compiles valid Java bytecode - we're probably fine to declare victory. That's my vote.