Skip to content

Commit

Permalink
Add korge wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz committed Jun 27, 2024
1 parent a33a12f commit 375c225
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/.gradle
/.idea
/.kotlin
/.korge
/build
/modules
/bundles
Expand Down
60 changes: 60 additions & 0 deletions korge
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

export INSTALLER_VERSION="0.0.1"
export INSTALLER_URL=https://github.com/korlibs/compiler.korge.org/releases/download/v$INSTALLER_VERSION/korge-kotlin-compiler-all.tar.xz
export INSTALLER_SHA256=0de1ab981f602aa35ec239094811707c65dc5cea39d55f3510527f6d48791c79

download_file()
{
FILE_URL=$1
FILE_NAME=$2
EXPECTED_SHA256=$3
shift; shift; shift;

# Download the file if it doesn't exist
if [ ! -f "$FILE_NAME" ]; then
echo "Downloading... $FILE_URL"
curl -s -L "$FILE_URL" -o "$FILE_NAME.tmp"
if [ $? -ne 0 ]; then
echo "Failed to download the file."
exit 1
fi

# Calculate the SHA-1 checksum of the downloaded file
ACTUAL_SHA256=$(shasum -a 256 "$FILE_NAME.tmp" | awk '{ print $1 }')

# Compare the actual SHA-1 checksum with the expected one
if [ "${ACTUAL_SHA256}" != "${EXPECTED_SHA256}" ]; then
echo "SHA-1 checksum does not match for $FILE_URL in $FILE_NAME.tmp"
echo "Expected: $EXPECTED_SHA256"
echo "Actual: $ACTUAL_SHA256"
exit 1
fi

mv "$FILE_NAME.tmp" "$FILE_NAME"

# echo "File verification succeeded."
fi
}

export JAVA="$HOME/.korge/jdk-21/bin/java"

if [ ! -f "$JAVA" ]; then
download_file "https://github.com/korlibs/universal-jre/releases/download/0.0.1/macos-universal-jdk-21+35-jre.tar.xz" "$HOME/.korge/jdk-21.tar.xz" "d7b2ab87de30584ee60b788dfbd8ea3fadf3b0ee06aeef37ac99e07de6d6281c"
mkdir "$HOME/.korge/jdk-21" 2> /dev/null
tar --strip-components 3 -xf "$HOME/.korge/jdk-21.tar.xz" -C "$HOME/.korge/jdk-21"
fi

if [ ! -f "$HOME/.korge/compiler/korge-kotlin-compiler-all.$INSTALLER_VERSION.jar" ]; then
mkdir -p "$HOME/.korge/compiler" 2> /dev/null

download_file "$INSTALLER_URL" "$HOME/.korge/compiler/korge-kotlin-compiler-all.$INSTALLER_VERSION.tar.xz" "$INSTALLER_SHA256"

tar -xf "$HOME/.korge/compiler/korge-kotlin-compiler-all.$INSTALLER_VERSION.tar.xz" -C "$HOME/.korge/compiler"
cp "$HOME/.korge/compiler"/korge-kotlin-compiler-all.jar "$HOME/.korge/compiler/korge-kotlin-compiler-all.$INSTALLER_VERSION.jar"
fi

"$JAVA" -jar "$HOME/.korge/compiler/korge-kotlin-compiler-all.$INSTALLER_VERSION.jar" $*
#java -client -XX:-TieredCompilation -XX:+OptimizeStringConcat -XX:+UseSuperWord -jar "$HOME/.korge/compiler/korge-kotlin-compiler.jar" $*
#java "$HOME/.korge/compiler/korge-kotlin-compiler.jar" $*

78 changes: 78 additions & 0 deletions korge.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
@ECHO OFF

SETLOCAL EnableDelayedExpansion

SET INSTALLER_VERSION=0.0.1
SET INSTALLER_URL=https://github.com/korlibs/compiler.korge.org/releases/download/v%INSTALLER_VERSION%/korge-kotlin-compiler-all.tar.xz
SET INSTALLER_SHA256=0de1ab981f602aa35ec239094811707c65dc5cea39d55f3510527f6d48791c79

SET KORGEDIR=%USERPROFILE%\.korge
SET JAVA=%KORGEDIR%\jre-21\bin\java.exe
SET INSTALLER_PATH=%KORGEDIR%\compiler
SET INSTALLER_LOCAL_FILE=%INSTALLER_PATH%\korge-kotlin-compiler-all.%INSTALLER_VERSION%.jar
MKDIR "%INSTALLER_PATH%" 2> NUL

IF NOT EXIST "%INSTALLER_LOCAL_FILE%" (
CALL :DOWNLOAD_FILE "%INSTALLER_URL%" "%INSTALLER_LOCAL_FILE%.tar.xz" "%INSTALLER_SHA256%"
CALL :EXTRACT_TAR "%INSTALLER_LOCAL_FILE%.tar.xz" "%INSTALLER_PATH%" 0 "%INSTALLER_LOCAL_FILE%"
COPY /Y "%INSTALLER_PATH%\korge-kotlin-compiler-all.jar" %INSTALLER_LOCAL_FILE% > NUL 2> NUL
)

IF NOT EXIST "%JAVA%" (
IF "%PROCESSOR_ARCHITECTURE%" == "ARM64" (
CALL :DOWNLOAD_FILE "https://github.com/korlibs/universal-jre/releases/download/0.0.1/microsoft-jre-21.0.3-windows-aarch64.tar.xz" "%KORGEDIR%\jre-21.tar.xz" "8F18060960FD7935D76C79BBB643B1779440B73AE9715153A3BA332B1B8A2348"
) ELSE (
CALL :DOWNLOAD_FILE "https://github.com/korlibs/universal-jre/releases/download/0.0.1/microsoft-jre-21.0.3-windows-x64.tar.xz" "%KORGEDIR%\jre-21.tar.xz" "6D16528A2201DCBE0ADDB0622F5CBE0CD6FA84AE937D3830FC1F74B32132C37B"
)
CALL :EXTRACT_TAR "%KORGEDIR%\jre-21.tar.xz" "%KORGEDIR%\jre-21" 1 "%JAVA%"
)

REM CALL :NORMALIZE_PATH "."
REM echo %RETVAL%
REM "%JAVA%" "-Duser.dir=%RETVAL%" -jar "%INSTALLER_LOCAL_FILE%" %*
"%JAVA%" -jar "%INSTALLER_LOCAL_FILE%" %*

EXIT /B

:DOWNLOAD_FILE
SET URL=%~1
SET LOCAL_PATH=%~2
SET EXPECTED_SHA256=%~3

IF EXIST "%LOCAL_PATH%" (
EXIT /B
)

IF NOT EXIST "%LOCAL_PATH%.tmp" (
echo Downloading %URL% into %LOCAL_PATH%
curl -sL "%URL%" -o "%LOCAL_PATH%.tmp"
)
powershell -NoProfile -ExecutionPolicy Bypass -Command "(Get-Filehash -Path '%LOCAL_PATH:\=\\%.tmp' -Algorithm SHA256).Hash" > "%LOCAL_PATH%.sha256"
SET /p DOWNLOAD_SHA256=<"%LOCAL_PATH%.sha256"

IF /i "%DOWNLOAD_SHA256%" == "%EXPECTED_SHA256%" (
MOVE "%LOCAL_PATH%.tmp" "%LOCAL_PATH%" > NUL 2> NUL
) ELSE (
ECHO ERROR downloading %URL%, SHA256=%DOWNLOAD_SHA256%, but expected SHA256=%EXPECTED_SHA256%
EXIT /B -1
)
EXIT /b

:EXTRACT_TAR
SET INPUT_FILE=%~1
SET OUT=%~2
SET STRIP_COMPONENTS=%~3
SET CHECK_EXISTS=%~4

IF EXIST %CHECK_EXISTS% (
EXIT /B
)

MKDIR "%OUT%" > NUL 2> NUL
echo Extracting %INPUT_FILE%...
tar --strip-components %STRIP_COMPONENTS% -C "%OUT%" -xf "%INPUT_FILE%"
EXIT /b

:NORMALIZE_PATH
SET RETVAL=%~f1
EXIT /B

0 comments on commit 375c225

Please sign in to comment.