From fa2d192d155f6b0f38ebc1d4e7e9d9e332fdab7e Mon Sep 17 00:00:00 2001 From: Omar Brikaa Date: Wed, 23 Feb 2022 14:37:34 +0200 Subject: [PATCH] Add dotnet csharp --- runtimes/default.nix | 1 + runtimes/dotnet-sdk-csharp.nix | 81 ++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 runtimes/dotnet-sdk-csharp.nix diff --git a/runtimes/default.nix b/runtimes/default.nix index 5a8c6a2..3d9f65c 100644 --- a/runtimes/default.nix +++ b/runtimes/default.nix @@ -53,4 +53,5 @@ args: { "emacs" = import ./emacs.nix args; "gnat-ada" = import ./gnat-ada.nix args; "rust" = import ./rust.nix args; + "dotnet-sdk-csharp" = import ./dotnet-sdk-csharp.nix args; } diff --git a/runtimes/dotnet-sdk-csharp.nix b/runtimes/dotnet-sdk-csharp.nix new file mode 100644 index 0000000..86b3837 --- /dev/null +++ b/runtimes/dotnet-sdk-csharp.nix @@ -0,0 +1,81 @@ +{pkgs, piston, ...}: +let + nugetPkg = pkgs.stdenv.mkDerivation { + pname = "csharp-nuget-packages"; + version = pkgs.dotnet-sdk.version; + + dontUnpack = true; + dontBuild = true; + dontConfigure = true; + dontFixup = true; + dontPatch = true; + + buildInputs = [ + pkgs.dotnet-sdk + ]; + installPhase = '' + mkdir $out + cd $out + export HOME=$PWD + dotnet new console -o cache_application + rm -rf cache_application + ''; + }; + pkg = pkgs.dotnet-sdk; +in piston.mkRuntime { + language = "csharp"; + version = pkg.version; + runtime = "dotnet-sdk"; + + aliases = [ + "csharp.net" + "c#" + "cs" + "c#.net" + "cs.net" + "c#-dotnet" + "cs-dotnet" + "csharp-dotnet" + "dotnet-c#" + "dotnet-cs" + "dotnet-csharp" + ]; + + compile = '' + export HOME=${nugetPkg} + ${pkg}/dotnet build --help > /dev/null # Supress welcome message + rename 's/$/\.cs/' "$@" # Add .cs extension + ${pkg}/dotnet new console -o . --no-restore + rm Program.cs + ${pkg}/dotnet restore --source ${nugetPkg}/.nuget/packages + ${pkg}/dotnet build --no-restore + ''; + + run = '' + export HOME=$PWD + shift + ${pkg}/dotnet bin/Debug/net6.0/$(basename $(realpath .)).dll "$@" + ''; + + tests = [ + (piston.mkTest { + files = { + "test.cs" = '' + using System; + + public class Test + { + public static void Main(string[] args) + { + Console.WriteLine(args[0]); + } + } + ''; + }; + args = ["OK"]; + stdin = ""; + packages = []; + main = "test.cs"; + }) + ]; +}