Skip to content

Commit b10cd04

Browse files
Initial commit
0 parents  commit b10cd04

6 files changed

Lines changed: 277 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- main
6+
tags:
7+
- "v*"
8+
pull_request:
9+
10+
jobs:
11+
compile:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
with:
16+
fetch-depth: 0
17+
- uses: coursier/cache-action@v6.3
18+
- uses: coursier/setup-action@v1.2.0-M3
19+
with:
20+
jvm: temurin:17
21+
- name: Compile
22+
run: ./scala-cli.sh compile . --cross
23+
24+
publish:
25+
needs: compile
26+
if: github.event_name == 'push'
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v3
30+
with:
31+
fetch-depth: 0
32+
- uses: coursier/cache-action@v6.3
33+
- uses: coursier/setup-action@v1.2.0-M3
34+
with:
35+
jvm: temurin:17
36+
- name: Release
37+
run: ./scala-cli.sh publish . --cross
38+
env:
39+
PUBLISH_USER: ${{ secrets.PUBLISH_USER }}
40+
PUBLISH_PASSWORD: ${{ secrets.PUBLISH_PASSWORD }}
41+
PUBLISH_SECRET_KEY: ${{ secrets.PUBLISH_SECRET_KEY }}
42+
PUBLISH_SECRET_KEY_PASSWORD: ${{ secrets.PUBLISH_SECRET_KEY_PASSWORD }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.bsp/
2+
/.scala-build/

.scalafmt.conf

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
version = "3.5.2"
2+
3+
align.preset = more
4+
maxColumn = 100
5+
assumeStandardLibraryStripMargin = true
6+
indent.defnSite = 2
7+
indentOperator.topLevelOnly = false
8+
align.preset = more
9+
align.openParenCallSite = false
10+
newlines.source = keep
11+
newlines.beforeMultiline = keep
12+
newlines.afterCurlyLambdaParams = keep
13+
newlines.alwaysBeforeElseAfterCurlyIf = true
14+
15+
runner.dialect = scala213source3
16+
17+
rewrite.rules = [
18+
RedundantBraces
19+
RedundantParens
20+
SortModifiers
21+
]
22+
23+
rewrite.redundantBraces {
24+
ifElseExpressions = true
25+
includeUnitMethods = false
26+
stringInterpolation = true
27+
}
28+
29+
rewrite.sortModifiers.order = [
30+
"private", "final", "override", "protected",
31+
"implicit", "sealed", "abstract", "lazy"
32+
]
33+
34+
project.excludeFilters = [
35+
".bloop"
36+
".metals"
37+
".scala-build"
38+
]

scala-cli.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
3+
# This is the launcher script of Scala CLI (https://github.com/VirtusLab/scala-cli).
4+
# This script downloads and runs the Scala CLI version set by SCALA_CLI_VERSION below.
5+
#
6+
# Download the latest version of this script at https://github.com/VirtusLab/scala-cli/raw/main/scala-cli.sh
7+
8+
set -eu
9+
10+
SCALA_CLI_VERSION="nightly"
11+
12+
GH_ORG="alexarchambault"
13+
GH_NAME="scala-cli"
14+
15+
if [ "$SCALA_CLI_VERSION" == "nightly" ]; then
16+
TAG="nightly"
17+
else
18+
TAG="v$SCALA_CLI_VERSION"
19+
fi
20+
21+
if [ "$(expr substr $(uname -s) 1 5 2>/dev/null)" == "Linux" ]; then
22+
SCALA_CLI_URL="https://github.com/$GH_ORG/$GH_NAME/releases/download/$TAG/scala-cli-x86_64-pc-linux.gz"
23+
CACHE_BASE="$HOME/.cache/coursier/v1"
24+
elif [ "$(uname)" == "Darwin" ]; then
25+
SCALA_CLI_URL="https://github.com/$GH_ORG/$GH_NAME/releases/download/$TAG/scala-cli-x86_64-apple-darwin.gz"
26+
CACHE_BASE="$HOME/Library/Caches/Coursier/v1"
27+
else
28+
echo "This standalone scala-cli launcher is supported only in Linux and macOS. If you are using Windows, please use the dedicated launcher scala-cli.bat"
29+
exit 1
30+
fi
31+
32+
CACHE_DEST="$CACHE_BASE/$(echo "$SCALA_CLI_URL" | sed 's@://@/@')"
33+
SCALA_CLI_BIN_PATH=${CACHE_DEST%.gz}
34+
35+
if [ ! -f "$CACHE_DEST" ]; then
36+
mkdir -p "$(dirname "$CACHE_DEST")"
37+
TMP_DEST="$CACHE_DEST.tmp-setup"
38+
echo "Downloading $SCALA_CLI_URL"
39+
curl -fLo "$TMP_DEST" "$SCALA_CLI_URL"
40+
mv "$TMP_DEST" "$CACHE_DEST"
41+
fi
42+
43+
if [ ! -f "$SCALA_CLI_BIN_PATH" ]; then
44+
gunzip -k "$CACHE_DEST"
45+
fi
46+
47+
if [ ! -x "$SCALA_CLI_BIN_PATH" ]; then
48+
chmod +x "$SCALA_CLI_BIN_PATH"
49+
fi
50+
51+
exec "$SCALA_CLI_BIN_PATH" "$@"

src/ScalaCliCompile.scala

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
//> using scala "2.13"
2+
//> using lib "com.lihaoyi::mill-scalalib:0.10.4"
3+
//> using option "-deprecation"
4+
5+
package scala.cli.mill
6+
7+
import coursier.cache.{ArchiveCache, FileCache}
8+
import coursier.cache.loggers.{FallbackRefreshDisplay, ProgressBarRefreshDisplay, RefreshLogger}
9+
import coursier.util.Artifact
10+
import mill._
11+
import mill.scalalib.ScalaModule
12+
import mill.scalalib.api.CompilationResult
13+
14+
import java.io.File
15+
import java.util.Locale
16+
17+
import scala.util.Properties
18+
19+
trait ScalaCliCompile extends ScalaModule {
20+
21+
protected object ScalaCliInternal {
22+
// disable using scala-cli to build scala-cli on unsupported architectures
23+
lazy val isSupportedArch: Boolean = {
24+
val supportedArch = Seq("x86_64", "amd64")
25+
val osArch = sys.props("os.arch").toLowerCase(Locale.ROOT)
26+
supportedArch.exists(osArch.contains(_))
27+
}
28+
29+
lazy val compileScalaCliImpl = compileScalaCliUrl.map { url =>
30+
val logger = RefreshLogger.create(
31+
if (coursier.paths.Util.useAnsiOutput())
32+
ProgressBarRefreshDisplay.create()
33+
else
34+
new FallbackRefreshDisplay
35+
)
36+
val cache = FileCache().withLogger(logger)
37+
val archiveCache = ArchiveCache()
38+
.withCache(cache)
39+
val artifact = Artifact(url).withChanging(compileScalaCliIsChanging)
40+
val file = archiveCache.get(artifact).unsafeRun()(cache.ec) match {
41+
case Left(e) => throw new Exception(e)
42+
case Right(f) =>
43+
if (Properties.isWin)
44+
os.list(os.Path(f, os.pwd)).filter(_.last.endsWith(".exe")).headOption match {
45+
case None => sys.error(s"No .exe found under $f")
46+
case Some(exe) => exe
47+
}
48+
else {
49+
f.setExecutable(true)
50+
os.Path(f, os.pwd)
51+
}
52+
}
53+
PathRef(file)
54+
}
55+
}
56+
import ScalaCliInternal._
57+
58+
def enableScalaCli: Boolean =
59+
System.getenv("CI") == null && isSupportedArch
60+
def scalaCliVersion: String =
61+
"0.1.5"
62+
63+
def compileScalaCliUrl: Option[String] = {
64+
val ver = scalaCliVersion
65+
if (Properties.isLinux) Some(
66+
s"https://github.com/VirtusLab/scala-cli/releases/download/v$ver/scala-cli-x86_64-pc-linux.gz"
67+
)
68+
else if (Properties.isWin) Some(
69+
s"https://github.com/VirtusLab/scala-cli/releases/download/v$ver/scala-cli-x86_64-pc-win32.zip"
70+
)
71+
else if (Properties.isMac) Some(
72+
s"https://github.com/VirtusLab/scala-cli/releases/download/v$ver/scala-cli-x86_64-apple-darwin.gz"
73+
)
74+
else None
75+
}
76+
def compileScalaCliIsChanging: Boolean = false
77+
78+
def compileScalaCli: Option[PathRef] = compileScalaCliImpl
79+
80+
def extraScalaCliOptions: T[List[String]] =
81+
T {
82+
List.empty[String]
83+
}
84+
85+
override def compile: T[CompilationResult] =
86+
if (enableScalaCli)
87+
compileScalaCli.map(_.path) match {
88+
case None => super.compile
89+
case Some(cli) =>
90+
T.persistent {
91+
val out = os.pwd / ".scala-build" / ".unused"
92+
93+
val sourceFiles = allSources()
94+
.map(_.path)
95+
.filter(os.exists(_))
96+
val workspace = T.dest / "workspace"
97+
os.makeDir.all(workspace)
98+
val classFilesDir =
99+
if (sourceFiles.isEmpty) out / "classes"
100+
else {
101+
def asOpt[T](opt: String, values: IterableOnce[T]): Seq[String] =
102+
values.iterator.toList.flatMap(v => Seq(opt, v.toString))
103+
104+
val proc = os.proc(
105+
cli,
106+
Seq("compile", "--classpath"),
107+
Seq("-S", scalaVersion()),
108+
asOpt("-O", scalacOptions()),
109+
asOpt("--jar", compileClasspath().map(_.path)),
110+
asOpt("-O", scalacPluginClasspath().map(p => s"-Xplugin:${p.path}")),
111+
extraScalaCliOptions(),
112+
// "--strict-bloop-json-check=false", // don't check Bloop JSON files at each run
113+
workspace,
114+
sourceFiles
115+
)
116+
117+
val compile = proc.call()
118+
val out = compile.out.trim()
119+
120+
os.Path(out.split(File.pathSeparator).head)
121+
}
122+
123+
CompilationResult(out / "unused.txt", PathRef(classFilesDir))
124+
}
125+
}
126+
else
127+
super.compile
128+
129+
}

src/publish-conf.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//> using publish.organization "io.github.alexarchambault.mill"
2+
//> using publish.name "mill-scala-cli_mill0.10"
3+
//> using publish.computeVersion "git:tag"
4+
5+
//> using publish.license "Apache-2.0"
6+
//> using publish.url "https://github.com/scala-cli/mill-scala-cli"
7+
//> using publish.versionControl "github:scala-cli/mill-scala-cli"
8+
//> using publish.developer "alexarchambault|Alex Archambault|https://github.com/alexarchambault"
9+
10+
//> using publish.repository "central-s01"
11+
//> using publish.user "env:PUBLISH_USER"
12+
//> using publish.password "env:PUBLISH_PASSWORD"
13+
14+
//> using publish.secretKey "env:PUBLISH_SECRET_KEY"
15+
//> using publish.secretKeyPassword "env:PUBLISH_SECRET_KEY_PASSWORD"

0 commit comments

Comments
 (0)