Skip to content

Commit 69f66df

Browse files
Create README.md
1 parent b10cd04 commit 69f66df

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

README.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# mill-scala-cli
2+
3+
[![Build status](https://github.com/scala-cli/mill-scala-cli/workflows/CI/badge.svg)](https://github.com/scala-cli/mill-scala-cli/actions?query=workflow%3ACI)
4+
[![Maven Central](https://img.shields.io/maven-central/v/io.github.alexarchambault.mill/mill-scala-cli_mill0.10_2.13.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.alexarchambault.mill/mill-scala-cli_mill0.10_2.13)
5+
6+
*mill-scala-cli* is a Mill plugin, that allows to compile Scala modules
7+
with [Scala CLI](https://github.com/VirtusLab/scala-cli) rather than with Mill's
8+
[`ZincWorker`](https://github.com/com-lihaoyi/mill/blob/4d94945c463b4f4b2aac3d74e0d75511714e00f0/scalalib/src/ZincWorkerModule.scala).
9+
10+
*mill-scala-cli* is used in [Scala CLI](https://github.com/VirtusLab/scala-cli)'s own build. The motivation for writing it originates
11+
from incremental compilation issues seen with Mill's `ZincWorker` in the Scala CLI build. When using *mill-scala-cli*, compilation is delegated to
12+
Scala CLI, which delegates it to Bloop, whose use of Zinc has been tried and tested for quite some time. These incremental compilation issues
13+
go away with *mill-scala-cli*.
14+
15+
See below for a list of pros and cons for using mill-scala-cli.
16+
17+
## Usage
18+
19+
Add a dependency towards *mill-scala-cli* in your `build.sc` file (or any Mill build file you want to use `ScalaCliCompile` from),
20+
and import `ScalaCliCompile`:
21+
```scala
22+
import $ivy.`io.github.alexarchambault.mill::mill-scala-cli::0.1.0`
23+
import scala.cli.mill.ScalaCliCompile
24+
```
25+
26+
Note that mill-scala-cli only supports Mill 0.10.x.
27+
28+
Then have your Scala modules extend `ScalaCliCompile`:
29+
```scala
30+
object foo extends SbtModule with ScalaCliCompile {
31+
def scalaVersion = "2.13.8"
32+
}
33+
```
34+
35+
`ScalaCliCompile` can be added to modules extending `mill.scalalib.ScalaModule`, which includes `SbtModule`, `CrossScalaModule`, `CrossSbtModule`, …
36+
37+
Note that Scala CLI is disabled by default on CIs, where incremental compilation is somewhat less sollicited.
38+
39+
Note also that Scala CLI is only enabled on CPUs / OSes that have native Scala CLI launchers (as of writing this, Linux / Windows / macOS on x86_64).
40+
41+
## Customization
42+
43+
### Change Scala CLI version
44+
45+
```scala
46+
def scalaCliVersion = "0.1.6"
47+
```
48+
49+
### Pass custom options to Scala CLI
50+
51+
Add them to `extraScalaCliOptions`:
52+
```scala
53+
def extraScalaCliOptions = T {
54+
super.extraScalaCliOptions() ++ Seq("-v", "-v")
55+
}
56+
```
57+
58+
### Force Scala CLI use
59+
60+
```scala
61+
def enableScalaCli = true
62+
```
63+
64+
By default, this is false on CIs and on unsupported CPUs / OSes (see above).
65+
66+
### Change the URL Scala CLI is downloaded from
67+
68+
```scala
69+
def compileScalaCliUrl = Some("https://…/scala-cli-x86_64-pc-linux.gz")
70+
```
71+
72+
Both compressed and non-compressed Scala CLI launchers are accepted (compressed launchers should have the right compression method extension).
73+
Decompression is handled by the ArchiveCache capabilities of coursier.
74+
75+
## Benefits / drawbacks / limitations
76+
77+
Benefits:
78+
- more reliable incremental compilation
79+
80+
Drawbacks:
81+
- when compiling things in non-interactive mode, the output of Scala CLI, that prints errors and warnings, is sometimes trapped - use of `./mill -i` is recommended, which slows Mill commands a bit
82+
- no-op incremental compilation (when no sources changed, and nothing new needs to be compiled) has a small but noticeable cost - it takes a small amount of time (maybe in the ~100s of ms), which adds up when running Mill tasks involving numerous modules
83+
84+
Limitations:
85+
- even though *mill-scala-cli* uses Bloop under-the-hood, the dependencies between modules compiled via *mill-scala-cli* are not "seen" by Bloop - each module lives in its own workspace, and dependencies between modules simply consist in putting a module byte code directory in the class path of its dependees, which trumps some Bloop optimizations
86+
87+
## Authors
88+
89+
Compilation via Scala CLI from Mill was originally added in the Scala CLI build by [Krzysztof Romanowski](https://github.com/romanowski). It was
90+
later customized, then extracted and moved to the repository here by [Alex Archambault](https://github.com/alexarchambault).

0 commit comments

Comments
 (0)