Skip to content

Commit

Permalink
Cross compile cli on Scala 3 LTS & Next
Browse files Browse the repository at this point in the history
  • Loading branch information
Gedochao committed Feb 23, 2024
1 parent 98c8e2a commit ce36200
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/build-linux-aarch64-from-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ eval "$(cs java --env --jvm temurin:17 --jvm-index https://github.com/coursier/j

git config --global --add safe.directory "$(pwd)"

./mill -i show cli.nativeImage
./mill -i show 'cli[]'.nativeImage
./mill -i copyDefaultLauncher ./artifacts
if "true" == $(./mill -i ci.shouldPublish); then
.github/scripts/generate-os-packages.sh
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/generate-docker-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
WORKDIR="$ROOT/out/docker-workdir"

mkdir -p "$WORKDIR"
./mill -i copyTo cli.nativeImageStatic "$WORKDIR/scala-cli" 1>&2
./mill -i copyTo 'cli[]'.nativeImageStatic "$WORKDIR/scala-cli" 1>&2

cd "$WORKDIR"
docker build -t scala-cli -f "$ROOT/.github/scripts/docker/ScalaCliDockerFile" .
8 changes: 4 additions & 4 deletions .github/scripts/generate-native-image.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -e

COMMAND="cli.base-image.writeNativeImageScript"
COMMAND="cli[].base-image.writeNativeImageScript"

# temporary, until we pass JPMS options to native-image,
# see https://www.graalvm.org/release-notes/22_2/#native-image
Expand All @@ -20,19 +20,19 @@ if [[ "$OSTYPE" == "msys" ]]; then
else
if [ $# == "0" ]; then
if [[ "$OSTYPE" == "linux-gnu" ]]; then
COMMAND="cli.linux-docker-image.writeNativeImageScript"
COMMAND="cli[].linux-docker-image.writeNativeImageScript"
CLEANUP=("sudo" "rm" "-rf" "out/cli/linux-docker-image/nativeImageDockerWorkingDir")
else
CLEANUP=("true")
fi
else
case "$1" in
"static")
COMMAND="cli.static-image.writeNativeImageScript"
COMMAND="cli[].static-image.writeNativeImageScript"
CLEANUP=("sudo" "rm" "-rf" "out/cli/static-image/nativeImageDockerWorkingDir")
;;
"mostly-static")
COMMAND="cli.mostly-static-image.writeNativeImageScript"
COMMAND="cli[].mostly-static-image.writeNativeImageScript"
CLEANUP=("sudo" "rm" "-rf" "out/cli/mostly-static-image/nativeImageDockerWorkingDir")
;;
*)
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/generate-os-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ packager() {
}

launcher() {
local launcherMillCommand="cli.nativeImage"
local launcherMillCommand="cli[].nativeImage"
local launcherName

if [[ "${OS-}" == "Windows_NT" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/generate-slim-docker-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
WORKDIR="$ROOT/out/docker-slim-workdir"

mkdir -p "$WORKDIR"
./mill -i copyTo cli.nativeImageMostlyStatic "$WORKDIR/scala-cli" 1>&2
./mill -i copyTo 'cli[]'.nativeImageMostlyStatic "$WORKDIR/scala-cli" 1>&2

cd "$WORKDIR"
docker build -t scala-cli-slim -f "$ROOT/.github/scripts/docker/ScalaCliSlimDockerFile" .
23 changes: 17 additions & 6 deletions DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,29 @@ The Scala CLI sources ship with Mill launchers, so that Mill itself doesn't need

#### Running the CLI from sources

Run the `scala` target with Mill:
```bash
./mill -i scala …arguments…
```

This is the equivalent of running the `cli` task with the default Scala version:
```bash
./mill -i 'cli[]'.run …arguments…
```

#### Debugging the CLI from sources

```bash
./mill -i debug debug-port …arguments…
```

which is short for:
```bash
./mill -i 'cli[]'.debug debug-port …arguments…
```
E.g:
```bash
./mill -i cli.debug 5050 ~/Main.scala -S 3.3.0
./mill -i 'cli[]'.debug 5050 ~/Main.scala -S 3.3.0
```

#### Run unit tests
Expand Down Expand Up @@ -129,7 +140,7 @@ Otherwise, some IDE features may not work correctly, i.e. the debugger might cra
#### Generate a native launcher

```bash
./mill -i show cli.nativeImage
./mill -i show 'cli[]'.nativeImage
```

This prints the path to the generated native image.
Expand All @@ -140,7 +151,7 @@ whether the files it points at exists or not.)
#### Generate a JVM launcher

```bash
./mill -i show cli.launcher
./mill -i show 'cli[]'.launcher
```

This prints the path to the generated launcher. This launcher is a JAR,
Expand All @@ -153,7 +164,7 @@ JVM one (see below).
#### Generate a standalone JVM launcher

```bash
./mill -i show cli.standaloneLauncher
./mill -i show 'cli[]'.standaloneLauncher
```

This prints the path to the generated launcher. This launcher is a JAR,
Expand Down Expand Up @@ -296,15 +307,15 @@ image.
To generate the relevant configuration automatically, you can run:

```bash
./mill -i cli.runWithAssistedConfig <scala-cli-sub-command> <args> <options>
./mill -i 'cli[]'.runWithAssistedConfig <scala-cli-sub-command> <args> <options>
```

Just make sure to run it exactly the same as the native image would have been run, as the configuration is generated for
a particular invocation path. The run has to succeed as well, as the configuration will only be fully generated after an
exit code 0.

```text
Config generated in out/cli/runWithAssistedConfig.dest/config
Config generated in out/cli/<scalaVersion>/runWithAssistedConfig.dest/config
```

As a result, you should get the path to the generated configuration file. It might contain some unnecessary entries, so
Expand Down
Loading

0 comments on commit ce36200

Please sign in to comment.