VirtusLab / scala-cli

Scala CLI is a command-line tool to interact with the Scala language. It lets you compile, run, test, and package your Scala code (and more!)
https://scala-cli.virtuslab.org
Apache License 2.0
540 stars 128 forks source link

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

Open keynmol opened 1 year ago

keynmol commented 1 year ago

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
tgodzik commented 1 year ago

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.

armanbilge commented 1 year ago

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 😜

SethTisue commented 1 year ago

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.

keynmol commented 1 year ago

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.

spamegg1 commented 9 months ago

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.

SethTisue commented 1 month ago

even if no special support for this is added, https://scala-cli.virtuslab.org/docs/guides/introduction/dependencies/ should document the status quo, IMO

someone asks on Discord from time to time