diff --git a/packages/scala/3.0.0/build.sh b/packages/scala/3.0.0/build.sh deleted file mode 100755 index 4cbf363..0000000 --- a/packages/scala/3.0.0/build.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -# Download and extract JDK8 -curl -L "https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u292-b10/OpenJDK8U-jdk_x64_linux_hotspot_8u292b10.tar.gz" -o jdk.tar.gz -tar xzf jdk.tar.gz --strip-components=1 -rm jdk.tar.gz - -# Download and extract Scala 3 -curl -L "https://github.com/lampepfl/dotty/releases/download/3.0.0/scala3-3.0.0.tar.gz" -o scala.tar.gz -tar -xzf scala.tar.gz --strip-components=1 -rm scala.tar.gz diff --git a/packages/scala/3.0.0/compile b/packages/scala/3.0.0/compile deleted file mode 100644 index 25853ef..0000000 --- a/packages/scala/3.0.0/compile +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash - -# Compile scala classes into a jar file -scalac "$@" -d out.jar - -# Create the Manifest and include scala lib jars: -# NOTE: - entry point will only consider @main and App traits from the main file -# - scala lib jars will be added to the class path in order to run the jar properly -echo "Main-Class: $(grep -oP '\@main\s+def\s+\K[a-zA-Z][a-zA-Z0-9]*|object\s+\K[a-zA-Z][a-zA-Z0-9]*(?=\s+extends\s+App)' $1) -Class-Path: $(echo $JAVA_HOME/lib/*.jar | sed 's/\s/\n /g') - -" > manifest.txt - -# Update the jar with the manifest -jar ufm out.jar manifest.txt diff --git a/packages/scala/3.0.0/environment b/packages/scala/3.0.0/environment deleted file mode 100644 index a1fcafe..0000000 --- a/packages/scala/3.0.0/environment +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -# Scala requires JAVA_HOME to be set -export JAVA_HOME=$PWD -export PATH=$PWD/bin:$PATH diff --git a/packages/scala/3.0.0/metadata.json b/packages/scala/3.0.0/metadata.json deleted file mode 100644 index 37bccf8..0000000 --- a/packages/scala/3.0.0/metadata.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "language": "scala", - "version": "3.0.0", - "aliases": ["sc"] -} diff --git a/packages/scala/3.0.0/run b/packages/scala/3.0.0/run deleted file mode 100644 index afcc045..0000000 --- a/packages/scala/3.0.0/run +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -# Run jar file -shift -java -jar out.jar "$@" diff --git a/packages/scala/3.0.0/test.scala b/packages/scala/3.0.0/test.scala deleted file mode 100644 index bf4cabc..0000000 --- a/packages/scala/3.0.0/test.scala +++ /dev/null @@ -1,3 +0,0 @@ -@main def run(): Unit = { - println("OK") -} \ No newline at end of file diff --git a/runtimes/default.nix b/runtimes/default.nix index 372ec79..29d1457 100644 --- a/runtimes/default.nix +++ b/runtimes/default.nix @@ -60,4 +60,5 @@ args: { "fpc-pascal" = import ./fpc-pascal.nix args; "brainfuck" = import ./brainfuck.nix args; "node-coffeescript" = import ./node-coffeescript.nix args; + "jvm-scala" = import ./jvm-scala.nix args; } diff --git a/runtimes/jvm-scala.nix b/runtimes/jvm-scala.nix new file mode 100644 index 0000000..ab72b36 --- /dev/null +++ b/runtimes/jvm-scala.nix @@ -0,0 +1,54 @@ +{pkgs, piston, ...}: +let + pkg = pkgs.scala; + java = pkgs.jdk8; + sed = pkgs.gnused; +in piston.mkRuntime { + language = "scala"; + version = pkg.version; + runtime = "jvm"; + + aliases = [ + "sc" + ]; + + compile = '' + # Compile scala classes into a jar file + ${pkg}/bin/scalac "$@" -d out.jar + + # Capture extra class-path libraries + java_libs="$(echo ${java}/lib/openjdk/lib/*.jar | ${sed}/bin/sed 's/\s/\\n /g')" + scala_libs="$(echo ${pkg}/lib/*.jar | ${sed}/bin/sed 's/\s/\\n /g')" + + echo -e "Class-Path: $java_libs + $scala_libs + " > classPath + + # Update the jar manifest with scala libs + ${java}/bin/jar umf classPath out.jar + ''; + + run = '' + # Run jar from compile + shift + ${java}/bin/java -jar out.jar "$@" + ''; + + tests = [ + (piston.mkTest { + files = { + "test.sc" = '' + object Main { + def main(args: Array[String]) = { + println("OK") + } + } + ''; + }; + args = []; + stdin = ""; + packages = []; + main = "test.sc"; + }) + ]; +} \ No newline at end of file