Skip to content

v1.7.0

Latest
Compare
Choose a tag to compare
@Gedochao Gedochao released this 06 Mar 08:52
· 7 commits to main since this release
f289e12

Switch to scalameta/scalafmt images of scalafmt 3.9.1+

Since version 3.9.1 scalafmt ships with native images built with Scala Native. As a result, we are sunsetting https://github.com/virtuslab/scalafmt-native-image and Scala CLI will use the artifacts from https://github.com/scalameta/scalafmt for scalafmt versions >=3.9.1

Note that older Scala CLI versions may still attempt to download a native image from the old repository for the new versions.
We will keep releasing those for a short while to help late upgraders migrate.

scala-cli fmt -F -version
# scalafmt 3.9.2

Added by @Gedochao in #3521

Support the --test command line option for run and package

It is now possible to run a main method from the test scope with the --test flag.

//> using target.scope test
@main def helloFromTestScope(): Unit = println("Hello from the test scope!")
scala-cli run HelloFromTestScope.scala --test --power

# Hello from the test scope!  

Similarly, it is now possible to package the main and test scopes together, using the same --test flag.

scala-cli package HelloFromTestScope.scala --test --power
# # Wrote ./helloFromTestScope, run it with                                       
#  ./helloFromTestScope  
./helloFromTestScope
# Hello from the test scope!  

Keep in mind that the test and main scopes are still separate compilation units, where the test scope depends on the main scope (while the reverse isn't true).

Added by @Gedochao in #3502 and #3519

Detect objects with main class in scripts

Scala CLI now detects objects with a main method in scripts and runs them by default.

object Main {
  def main(args: Array[String]): Unit = println("Hello")
}

Do note that, this is chiefly a convenience feature for migration of old scripts, using the old, legacy scala runner.

If any top-level code is present alongside an object with a main method, the top-level code will be run instead and a warning printed.

object Main {
  def main(args: Array[String]): Unit = println("Hello")
}
println("Top level code says hello")
scala-cli run scriptWithMainObjectAndTopLevel.sc
# [warn]  Script contains objects with main methods and top-level statements, only the latter will be run.                                   
# Compiling project (Scala 3.6.3, JVM (23))
# Compiled project (Scala 3.6.3, JVM (23))
# Top level code says hello

Additionally, cases where multiple main methods are present in the same script are not supported, inidicated by a warning.

object Main {
  def main(args: Array[String]): Unit = println("Hello1")
}

object Main2 {
  def main(args: Array[String]): Unit = println("Hello2")
}

Note that no output is printed in this example:

scala-cli run scriptWithMultipleMainObjects.sc
# [warn]  Only a single main is allowed within scripts. Multiple main classes were found in the script: Main, Main2                          
# Compiling project (Scala 3.6.3, JVM (23))
# Compiled project (Scala 3.6.3, JVM (23))

Finally, main methods defined in this way cannot be chosen via the --main-class command line option directive, and neither will they be printed by the --list-main-methods flag.

Added by @tgodzik in #3479

Support for Scala Native 0.5.7

This Scala CLI version switches the default Scala Native version to 0.5.7.

scala-cli -e 'println("Hello from Scala Native 0.5.7!")' --native
# Compiling project (Scala 3.6.3, Scala Native 0.5.7)
# Compiled project (Scala 3.6.3, Scala Native 0.5.7)
# [info] Linking (multithreadingEnabled=true, disable if not used) (1045 ms)
# [info] Discovered 915 classes and 5608 methods after classloading
# [info] Checking intermediate code (quick) (41 ms)
# [info] Multithreading was not explicitly enabled - initial class loading has not detected any usage of system threads. Multithreading support will be disabled to improve performance.
# [info] Linking (multithreadingEnabled=false) (352 ms)
# [info] Discovered 498 classes and 2506 methods after classloading
# [info] Checking intermediate code (quick) (9 ms)
# [info] Discovered 477 classes and 1930 methods after optimization
# [info] Optimizing (debug mode) (608 ms)
# [info] Produced 9 LLVM IR files
# [info] Generating intermediate code (650 ms)
# [info] Compiling to native code (1674 ms)
# [info] Linking with [pthread, dl, m]
# [info] Linking native code (immix gc, none lto) (339 ms)
# [info] Postprocessing (0 ms)
# [info] Total (4655 ms)
# Hello from Scala Native 0.5.7!

Added in #3527

Features

  • improvement: Detect objects with main class in scripts by @tgodzik in #3479
  • Add support for running a main method from the test scope by @Gedochao in #3502
  • Support the --test flag with the package sub-command by @Gedochao in #3519

Fixes

Internal and build changes

Documentation changes

Updates

Full Changelog: v1.6.2...v1.7.0