scala-cli icon indicating copy to clipboard operation
scala-cli copied to clipboard

Provide a cross-platform way to use Scala 2.13 libraries from Scala 3

Open keynmol opened this issue 3 years ago • 6 comments

SBT has a way of specifying 2.13 as a fallback, using CrossVersion.for3Use2_13 or for2_13Use3.

Scala CLI has no such thing, so you have to specify the dependency in full:

//> using lib "org.bla:hello_2.13:1.0.0"

This gets hairy when you are using native/JS dependencies:

//> using lib "org.bla:hello_native0.4_2.13:1.0.0"
//> using lib "org.bla:hello_sjs1_2.13:1.0.0"

And you are also immediately using the ability to use the --native or --js CLI flags if your script is cross-building.

To kick start the bikeshedding, one can add syntax as follows (vote with 👍 ):

//> using lib "org.bla::hello::1.0.0".for3Use2_13

or even better (vote with ❤️ ):

//> using lib.for3Use2_13 "org.bla::hello::1.0.0"

or (and I don't like it) the way url parameter is added (vote with 🚀):

//> using lib "org.bla::hello::1.0.0,for3Use2_13=true"
//> using lib "org.bla::hello::1.0.0,for3Use2_13" //shorter option for boolean flags

On the last note, it would be much more preferable to have the key-value pairs outside the string (vote with 🎉 ):

//> using lib "org.bla::hello::1.0.0" for3Use2_13=true,url=http://blabla.com/jar.jar
//> using lib "org.bla::hello::1.0.0" for3Use2_13 //shorter option for boolean flags

keynmol avatar Nov 02 '22 10:11 keynmol

Thanks for reporting! I wonder how hard would it be to fallback to 2.13 if 3 version doesn't exist (maybe also the other way?). That would be a much better experience for the user since they wouldn't need to learn about for2_13Use3.

tgodzik avatar Nov 02 '22 14:11 tgodzik

True, but it would also create non-determinism. The list of dependencies is no longer sufficient to precisely define a build: you have to know the "state of the world" at the time.

There's also the option of lockfiles 😜

armanbilge avatar Nov 02 '22 14:11 armanbilge

There are enough caveats with for2_13Use3 (the big two being: macros, diamond dependency conflicts) that I don't think I'd be comfortable with it ever being enabled without explicit opt-in.

SethTisue avatar Nov 02 '22 15:11 SethTisue

Agree with Seth and Arman.

Given that people have taken to backpublishing their libraries under same versions but for Scala 3, it's not a good world where you suddenly compile and run against a different artifact.

keynmol avatar Nov 02 '22 15:11 keynmol

I ran into this today, trying to use scala-graph for Advent of Code 2023 in a Scala-cli project for 3.3.1.

I worked around it with:

//> using dep org.scala-graph:graph-core_2.13:2.0.0

(Note that I had to drop one of the colons to make it work.)

I support @keynmol 's suggestion! Either syntax option is fine with me.

Automatic fallback would be bad indeed.

spamegg1 avatar Dec 08 '23 11:12 spamegg1