Created
December 14, 2023 19:09
-
-
Save masterflitzer/397b8f66f8c53feb6905a6cf88278623 to your computer and use it in GitHub Desktop.
Compile Kotlin/Native on FreeBSD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
DIR_KOTLIN="${HOME}/kotlin" | |
GIT_KOTLIN="jetbrains/kotlin" | |
PORT_CA_ROOT="security/ca_root_nss" | |
PORT_GIT="devel/git" | |
PORT_JDK="java/openjdk17" | |
PORT_JQ="textproc/jq" | |
for PORT in "${PORT_CA_ROOT}" "${PORT_GIT}" "${PORT_JDK}" "${PORT_JQ}" | |
do | |
pkg info "${PORT}" | |
if test "${?}" -ne 0 | |
then | |
cd "/usr/ports/${PORT}" | |
make clean install clean | |
test "${?}" -ne 0 && exit 1 | |
fi | |
done | |
mkdir -p "${DIR_KOTLIN}" | |
cd "${DIR_KOTLIN}" | |
GIT_KOTLIN_BRANCH="$(curl -Ls "https://api.github.com/repos/${GIT_KOTLIN}" | jq -r '.default_branch')" | |
GIT_KOTLIN_TAG="$(curl -Ls "https://api.github.com/repos/${GIT_KOTLIN}/releases/latest" | jq -r '.tag_name')" | |
git switch "${GIT_KOTLIN_BRANCH}" && git pull --prune > /dev/null 2>&1 || git clone "https://github.com/${GIT_KOTLIN}.git" . | |
git switch --detach "${GIT_KOTLIN_TAG}" | |
test "${?}" -ne 0 && exit 1 | |
cat <<EOF > local.properties | |
kotlin.build.isObsoleteJdkOverrideEnabled=true | |
kotlin.native.enabled=true | |
org.gradle.java.installations.auto-detect=false | |
EOF | |
./gradlew :kotlin-native:bundle | |
test "${?}" -ne 0 && exit 1 | |
cat <<EOF > /tmp/hello.kt | |
fun main() { | |
println("Hello Kotlin/Native!") | |
} | |
EOF | |
rm /tmp/hello.kexe | |
"${DIR_KOTLIN}/kotlin-native/dist/bin/kotlinc-native" /tmp/hello.kt -o /tmp/hello | |
if test "$(/tmp/hello.kexe)" == "Hello Kotlin/Native!" | |
then | |
echo "Success!" | |
else | |
echo "Failure!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment