Skip to content

Commit

Permalink
Merge pull request #25 from scala-cli/graalvm-22.0.0
Browse files Browse the repository at this point in the history
Update GraalVM to 22.0.0, switch to Java 17
  • Loading branch information
alexarchambault authored Mar 21, 2022
2 parents 5c5547f + 1794818 commit dc75f8d
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 53 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/launchers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ jobs:
with:
jvm: 8
- run: |
./mill -i "native.writeNativeImageScript" generate.sh && \
./mill -i "native.writeNativeImageScript" generate.sh "" && \
./generate.sh && \
./mill -i "native.copyToArtifacts" artifacts/
if: runner.os != 'Windows'
- run: |
@call ./mill.bat -i "native.writeNativeImageScript" generate.bat
@call ./mill.bat -i "native.writeNativeImageScript" generate.bat ""
@call generate.bat
@call ./mill.bat -i "native.copyToArtifacts" artifacts/
shell: cmd
Expand Down Expand Up @@ -56,7 +56,7 @@ jobs:
with:
jvm: 8
- run: |
./mill -i "native-static.writeNativeImageScript" generate.sh && \
./mill -i "native-static.writeNativeImageScript" generate.sh "" && \
./generate.sh && \
./mill -i "native-static.copyToArtifacts" artifacts/
- uses: actions/[email protected]
Expand All @@ -82,7 +82,7 @@ jobs:
with:
jvm: 8
- run: |
./mill -i "native-mostly-static.writeNativeImageScript" generate.sh && \
./mill -i "native-mostly-static.writeNativeImageScript" generate.sh "" && \
./generate.sh && \
./mill -i "native-mostly-static.copyToArtifacts" artifacts/
- uses: actions/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .mill-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.12
0.10.2
36 changes: 24 additions & 12 deletions build.sc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version_mill0.9:0.1.1`
import $ivy.`io.github.alexarchambault.mill::mill-native-image_mill0.9:0.1.12`
import $ivy.`io.github.alexarchambault.mill::mill-native-image-upload:0.1.12`
import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.1.4`
import $ivy.`io.github.alexarchambault.mill::mill-native-image::0.1.19`
import $ivy.`io.github.alexarchambault.mill::mill-native-image-upload:0.1.19`

import de.tobiasroeser.mill.vcs.version._
import io.github.alexarchambault.millnativeimage.NativeImage
Expand All @@ -11,7 +11,7 @@ import mill.scalalib._
def scalafmtVersion = "3.4.3"

trait ScalafmtNativeImage extends ScalaModule with NativeImage {
def scalaVersion = "2.13.6"
def scalaVersion = "2.13.8"

def nativeImageClassPath = T{
runClasspath()
Expand All @@ -22,7 +22,7 @@ trait ScalafmtNativeImage extends ScalaModule with NativeImage {
)
}
def nativeImagePersist = System.getenv("CI") != null
def nativeImageGraalVmJvmId = "graalvm-java11:21.2.0"
def nativeImageGraalVmJvmId = "graalvm-java17:22.0.0"
def nativeImageName = "scalafmt"
def ivyDeps = super.ivyDeps() ++ Seq(
ivy"org.scalameta::scalafmt-cli:$scalafmtVersion"
Expand All @@ -43,24 +43,36 @@ trait ScalafmtNativeImage extends ScalaModule with NativeImage {

object native extends ScalafmtNativeImage

def csDockerVersion = "2.0.16"
def csDockerVersion = "2.1.0-M5-18-gfebf9838c"

object `native-static` extends ScalafmtNativeImage {
def nameSuffix = "-static"
def nativeImageDockerParams = Some(
NativeImage.linuxStaticParams(
"messense/rust-musl-cross@sha256:12d0dd535ef7364bf49cb2608ae7eaf60e40d07834eb4d9160c592422a08d3b3",
s"https://github.com/coursier/coursier/releases/download/v$csDockerVersion/cs-x86_64-pc-linux"
def buildHelperImage = T {
os.proc("docker", "build", "-t", "scala-cli-base-musl:latest", ".")
.call(cwd = os.pwd / "musl-image", stdout = os.Inherit)
()
}
def nativeImageDockerParams = T{
buildHelperImage()
Some(
NativeImage.linuxStaticParams(
"scala-cli-base-musl:latest",
s"https://github.com/coursier/coursier/releases/download/v$csDockerVersion/cs-x86_64-pc-linux.gz"
)
)
)
}
def writeNativeImageScript(scriptDest: String, imageDest: String = "") = T.command {
buildHelperImage()
super.writeNativeImageScript(scriptDest, imageDest)()
}
}

object `native-mostly-static` extends ScalafmtNativeImage {
def nameSuffix = "-mostly-static"
def nativeImageDockerParams = Some(
NativeImage.linuxMostlyStaticParams(
"ubuntu:18.04", // TODO Pin that?
s"https://github.com/coursier/coursier/releases/download/v$csDockerVersion/cs-x86_64-pc-linux"
s"https://github.com/coursier/coursier/releases/download/v$csDockerVersion/cs-x86_64-pc-linux.gz"
)
)
}
Expand Down
103 changes: 77 additions & 26 deletions mill
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,33 @@
# If no version is given, it falls back to the value of DEFAULT_MILL_VERSION
#
# Project page: https://github.com/lefou/millw
# Script Version: 0.4.2
#
# If you want to improve this script, please also contribute your changes back!
#
# Licensed under the Apache License, Version 2.0


DEFAULT_MILL_VERSION=0.9.5
DEFAULT_MILL_VERSION=0.10.0

set -e

MILL_REPO_URL="https://github.com/com-lihaoyi/mill"

if [ -z "${CURL_CMD}" ] ; then
CURL_CMD=curl
fi

# Explicit commandline argument takes precedence over all other methods
if [ "x$1" = "x--mill-version" ] ; then
if [ "$1" = "--mill-version" ] ; then
shift
if [ "x$1" != "x" ] ; then
MILL_VERSION="$1"
shift
else
echo "You specified --mill-version without a version."
echo "Please provide a version that matches one provided on"
echo "${MILL_REPO_URL}/releases"
echo "You specified --mill-version without a version." 1>&2
echo "Please provide a version that matches one provided on" 1>&2
echo "${MILL_REPO_URL}/releases" 1>&2
false
fi
fi
Expand All @@ -35,59 +40,103 @@ fi
# We reuse it's value and skip searching for a value.

# If not already set, read .mill-version file
if [ "x${MILL_VERSION}" = "x" ] ; then
if [ -z "${MILL_VERSION}" ] ; then
if [ -f ".mill-version" ] ; then
MILL_VERSION="$(head -n 1 .mill-version 2> /dev/null)"
fi
fi

if [ "x${XDG_CACHE_HOME}" != "x" ] ; then
if [ -n "${XDG_CACHE_HOME}" ] ; then
MILL_DOWNLOAD_PATH="${XDG_CACHE_HOME}/mill/download"
else
MILL_DOWNLOAD_PATH="${HOME}/.cache/mill/download"
fi

# If not already set, try to fetch newest from Github
if [ "x${MILL_VERSION}" = "x" ] ; then
if [ -z "${MILL_VERSION}" ] ; then
# TODO: try to load latest version from release page
echo "No mill version specified."
echo "You should provide a version via '.mill-version' file or --mill-version option."
echo "No mill version specified." 1>&2
echo "You should provide a version via '.mill-version' file or --mill-version option." 1>&2

mkdir -p "${MILL_DOWNLOAD_PATH}"
LANG=C touch -d '1 hour ago' "${MILL_DOWNLOAD_PATH}/.expire_latest"
if [ "${MILL_DOWNLOAD_PATH}/.latest" -nt "${MILL_DOWNLOAD_PATH}/.expire_latest" ] ; then
LANG=C touch -d '1 hour ago' "${MILL_DOWNLOAD_PATH}/.expire_latest" 2>/dev/null || (
# we might be on OSX or BSD which don't have -d option for touch
# but probably a -A [-][[hh]mm]SS
touch "${MILL_DOWNLOAD_PATH}/.expire_latest"; touch -A -010000 "${MILL_DOWNLOAD_PATH}/.expire_latest"
) || (
# in case we still failed, we retry the first touch command with the intention
# to show the (previously suppressed) error message
LANG=C touch -d '1 hour ago' "${MILL_DOWNLOAD_PATH}/.expire_latest"
)

# POSIX shell variant of bash's -nt operator, see https://unix.stackexchange.com/a/449744/6993
# if [ "${MILL_DOWNLOAD_PATH}/.latest" -nt "${MILL_DOWNLOAD_PATH}/.expire_latest" ] ; then
if [ -n "$(find -L "${MILL_DOWNLOAD_PATH}/.latest" -prune -newer "${MILL_DOWNLOAD_PATH}/.expire_latest")" ]; then
# we know a current latest version
MILL_VERSION="$(head -n 1 ${MILL_DOWNLOAD_PATH}/.latest 2> /dev/null)"
MILL_VERSION=$(head -n 1 "${MILL_DOWNLOAD_PATH}"/.latest 2> /dev/null)
fi

if [ "x${MILL_VERSION}" = "x" ] ; then
if [ -z "${MILL_VERSION}" ] ; then
# we don't know a current latest version
echo "Retrieving latest mill version ..."
LANG=C curl -s -i -f -I ${MILL_REPO_URL}/releases/latest 2> /dev/null | grep --ignore-case Location: | sed s'/^.*tag\///' | tr -d '\r\n' > "${MILL_DOWNLOAD_PATH}/.latest"
MILL_VERSION="$(head -n 1 ${MILL_DOWNLOAD_PATH}/.latest 2> /dev/null)"
echo "Retrieving latest mill version ..." 1>&2
LANG=C ${CURL_CMD} -s -i -f -I ${MILL_REPO_URL}/releases/latest 2> /dev/null | grep --ignore-case Location: | sed s'/^.*tag\///' | tr -d '\r\n' > "${MILL_DOWNLOAD_PATH}/.latest"
MILL_VERSION=$(head -n 1 "${MILL_DOWNLOAD_PATH}"/.latest 2> /dev/null)
fi

if [ "x${MILL_VERSION}" = "x" ] ; then
if [ -z "${MILL_VERSION}" ] ; then
# Last resort
MILL_VERSION="${DEFAULT_MILL_VERSION}"
echo "Falling back to hardcoded mill version ${MILL_VERSION}"
echo "Falling back to hardcoded mill version ${MILL_VERSION}" 1>&2
else
echo "Using mill version ${MILL_VERSION}"
echo "Using mill version ${MILL_VERSION}" 1>&2
fi
fi

MILL="${MILL_DOWNLOAD_PATH}/${MILL_VERSION}"

try_to_use_system_mill() {
MILL_IN_PATH="$(command -v mill || true)"

if [ -z "${MILL_IN_PATH}" ]; then
return
fi

UNIVERSAL_SCRIPT_MAGIC="@ 2>/dev/null # 2>nul & echo off & goto BOF"

if ! head -c 128 "${MILL_IN_PATH}" | grep -qF "${UNIVERSAL_SCRIPT_MAGIC}"; then
if [ -n "${MILLW_VERBOSE}" ]; then
echo "Could not determine mill version of ${MILL_IN_PATH}, as it does not start with the universal script magic2" 1>&2
fi
return
fi

# Roughly the size of the universal script.
MILL_VERSION_SEARCH_RANGE="2403"
MILL_IN_PATH_VERSION=$(head -c "${MILL_VERSION_SEARCH_RANGE}" "${MILL_IN_PATH}" |\
sed -n 's/^.*-DMILL_VERSION=\([^\s]*\) .*$/\1/p' |\
head -n 1)

if [ -z "${MILL_IN_PATH_VERSION}" ]; then
echo "Could not determine mill version, even though ${MILL_IN_PATH} has the universal script magic" 1>&2
return
fi

if [ "${MILL_IN_PATH_VERSION}" = "${MILL_VERSION}" ]; then
MILL="${MILL_IN_PATH}"
fi
}
try_to_use_system_mill

# If not already downloaded, download it
if [ ! -s "${MILL}" ] ; then

# support old non-XDG download dir
MILL_OLD_DOWNLOAD_PATH="${HOME}/.mill/download"
OLD_MILL="${MILL_OLD_DOWNLOAD_PATH}/${MILL_VERSION}"
if [ -x "${OLD_MILL}" ] ; then
MILL="${OLD_MILL}"
else
VERSION_PREFIX="$(echo -n $MILL_VERSION | cut -b -4)"
VERSION_PREFIX="$(echo $MILL_VERSION | cut -b -4)"
case $VERSION_PREFIX in
0.0. | 0.1. | 0.2. | 0.3. | 0.4. )
DOWNLOAD_SUFFIX=""
Expand All @@ -98,10 +147,11 @@ if [ ! -s "${MILL}" ] ; then
esac
unset VERSION_PREFIX

DOWNLOAD_FILE=$(mktemp mill.XXXX)
DOWNLOAD_FILE=$(mktemp mill.XXXXXX)
# TODO: handle command not found
echo "Downloading mill ${MILL_VERSION} from ${MILL_REPO_URL}/releases ..."
curl -L -o "${DOWNLOAD_FILE}" "${MILL_REPO_URL}/releases/download/${MILL_VERSION%%-*}/${MILL_VERSION}${DOWNLOAD_SUFFIX}"
echo "Downloading mill ${MILL_VERSION} from ${MILL_REPO_URL}/releases ..." 1>&2
MILL_VERSION_TAG=$(echo $MILL_VERSION | sed -E 's/([^-]+)(-M[0-9]+)?(-.*)?/\1\2/')
${CURL_CMD} -f -L -o "${DOWNLOAD_FILE}" "${MILL_REPO_URL}/releases/download/${MILL_VERSION_TAG}/${MILL_VERSION}${DOWNLOAD_SUFFIX}"
chmod +x "${DOWNLOAD_FILE}"
mkdir -p "${MILL_DOWNLOAD_PATH}"
mv "${DOWNLOAD_FILE}" "${MILL}"
Expand All @@ -115,6 +165,7 @@ unset MILL_DOWNLOAD_PATH
unset MILL_OLD_DOWNLOAD_PATH
unset OLD_MILL
unset MILL_VERSION
unset MILL_VERSION_TAG
unset MILL_REPO_URL

exec $MILL "$@"
exec "${MILL}" "$@"
26 changes: 16 additions & 10 deletions mill.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ rem You can give the required mill version with --mill-version parameter
rem If no version is given, it falls back to the value of DEFAULT_MILL_VERSION
rem
rem Project page: https://github.com/lefou/millw
rem Script Version: 0.4.2
rem
rem If you want to improve this script, please also contribute your changes back!
rem
Expand All @@ -14,7 +15,7 @@ rem setlocal seems to be unavailable on Windows 95/98/ME
rem but I don't think we need to support them in 2019
setlocal enabledelayedexpansion

set "DEFAULT_MILL_VERSION=0.9.5"
set "DEFAULT_MILL_VERSION=0.10.0"

set "MILL_REPO_URL=https://github.com/com-lihaoyi/mill"

Expand All @@ -25,9 +26,9 @@ if [%~1%]==[--mill-version] (
set MILL_VERSION=%~2%
set "STRIP_VERSION_PARAMS=true"
) else (
echo You specified --mill-version without a version.
echo Please provide a version that matches one provided on
echo %MILL_REPO_URL%/releases
echo You specified --mill-version without a version. 1>&2
echo Please provide a version that matches one provided on 1>&2
echo %MILL_REPO_URL%/releases 1>&2
exit /b 1
)
)
Expand Down Expand Up @@ -57,31 +58,36 @@ if not exist "%MILL%" (
if [!VERSION_PREFIX!]==[0.4.] set DOWNLOAD_SUFFIX=
set VERSION_PREFIX=

for /F "delims=-" %%A in ("!MILL_VERSION!") do (
set MILL_BASE_VERSION=%%A
for /F "delims=- tokens=1" %%A in ("!MILL_VERSION!") do set MILL_VERSION_BASE=%%A
for /F "delims=- tokens=2" %%A in ("!MILL_VERSION!") do set MILL_VERSION_MILESTONE=%%A
set VERSION_MILESTONE_START=!MILL_VERSION_MILESTONE:~0,1!
if [!VERSION_MILESTONE_START!]==[M] (
set MILL_VERSION_TAG="!MILL_VERSION_BASE!-!MILL_VERSION_MILESTONE!"
) else (
set MILL_VERSION_TAG=!MILL_VERSION_BASE!
)

rem there seems to be no way to generate a unique temporary file path (on native Windows)
set DOWNLOAD_FILE=%MILL%.tmp

set DOWNLOAD_URL=%MILL_REPO_URL%/releases/download/!MILL_BASE_VERSION!/!MILL_VERSION!!DOWNLOAD_SUFFIX!
set DOWNLOAD_URL=%MILL_REPO_URL%/releases/download/!MILL_VERSION_TAG!/!MILL_VERSION!!DOWNLOAD_SUFFIX!

echo Downloading mill %MILL_VERSION% from %MILL_REPO_URL%/releases ...
echo Downloading mill %MILL_VERSION% from %MILL_REPO_URL%/releases ... 1>&2

if not exist "%MILL_DOWNLOAD_PATH%" mkdir "%MILL_DOWNLOAD_PATH%"
rem curl is bundled with recent Windows 10
rem but I don't think we can expect all the users to have it in 2019
where /Q curl
if %ERRORLEVEL% EQU 0 (
curl -L "!DOWNLOAD_URL!" -o "!DOWNLOAD_FILE!"
curl -f -L "!DOWNLOAD_URL!" -o "!DOWNLOAD_FILE!"
) else (
rem bitsadmin seems to be available on Windows 7
rem without /dynamic, github returns 403
rem bitsadmin is sometimes needlessly slow but it looks better with /priority foreground
bitsadmin /transfer millDownloadJob /dynamic /priority foreground "!DOWNLOAD_URL!" "!DOWNLOAD_FILE!"
)
if not exist "!DOWNLOAD_FILE!" (
echo Could not download mill %MILL_VERSION%
echo Could not download mill %MILL_VERSION% 1>&2
exit /b 1
)

Expand Down
4 changes: 4 additions & 0 deletions musl-image/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# copied from https://github.com/VirtusLab/scala-cli/blob/b73b3e612eeba09c3231da9a51720cb8ddff1874/project/musl-image/Dockerfile
FROM messense/rust-musl-cross@sha256:47a3721b3e186abfd705feb1e03bf1d5212357ea26762cceef11530e0a2f2c7c
ADD setup.sh /setup.sh
RUN /setup.sh
11 changes: 11 additions & 0 deletions musl-image/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -e

# copied from https://github.com/VirtusLab/scala-cli/blob/b73b3e612eeba09c3231da9a51720cb8ddff1874/project/musl-image/setup.sh

cd /usr/local/musl/bin

for i in x86_64-unknown-linux-musl-*; do
dest="$(echo "$i" | sed 's/-unknown//')"
ln -s "$i" "$dest"
done

0 comments on commit dc75f8d

Please sign in to comment.