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

A directive to specify the scala-cli version that should be used

Open armanbilge opened this issue 2 years ago • 3 comments

Is your feature request related to a problem? Please describe.

Currently there is no way to get stable, reproducible build outputs in a scala-cli project. This is only achievable by providing external context (e.g. in a README or GitHub actions workflow) about which scala-cli version should be used to build the project.

Describe the solution you'd like

A directive like:

//> using cli 1.0.6

that hard-codes the version of scala-cli that is used (or should be used).

Describe alternatives you've considered

Manually pinning all the Scala, Scala.js/Native, library versions etc. etc. But as explained in https://github.com/VirtusLab/scala-cli/issues/2145, this doesn't actually work: these are not sufficient to fully version the entire toolchain that scala-cli may use to generate build outputs.

Additional context Related tickets:

  • https://github.com/VirtusLab/scala-cli/issues/2145
  • https://github.com/VirtusLab/scala-cli/issues/2426

armanbilge avatar Nov 13 '23 21:11 armanbilge

If this sounds like a feature the scala-cli team is open to, then I'll gladly attempt a PR at this!

zetashift avatar Nov 13 '23 21:11 zetashift

This is easier said than done, as we'd need to have the CLI version parsed before the launcher is established, while we normally parse directives much later. And this isn't just a matter of a large refactor, as the rules for directives being parsed may differ between Scala CLI versions.

So to achieve this, we'd effectively have to parse for this directive specifically before the launcher is established.

If this sounds like a feature the scala-cli team is open to, then I'll gladly attempt a PR at this!

@zetashift Go ahead, and let us know if you need any help. I don't think the Scala CLI team would work on this anytime soon, but we're open to a contribution, by all means.

A couple of tips and suggestions on how to simplify the task/limit the scope:

  • as mentioned earlier, you'll probably have to parse for the directive a second time before the launcher is picked, so that the directive value is known before the --cli-version launcher option is checked for
  • the --cli-version launcher option has to still override whatever would be configured in the using directive
  • I think it's okay not to look for the directive everywhere, and instead enforce for it to be the first directive in the project.scala configuration file (or for single-source-file builds, in the main source file)

Gedochao avatar Nov 14 '23 08:11 Gedochao

So to achieve this, we'd effectively have to parse for this directive specifically before the launcher is established.

That sounds right 👍

  • and instead enforce for it to be the first directive in the project.scala configuration file (or for single-source-file builds, in the main source file)

As does this 👍

Thanks for the input!

armanbilge avatar Nov 14 '23 15:11 armanbilge