]> Savannah Git Hosting - gnulib.git/commitdiff
csharpcomp-script: Add support for dotnet.
authorBruno Haible <bruno@clisp.org>
Wed, 9 Oct 2024 01:14:26 +0000 (03:14 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 16 Oct 2024 12:07:23 +0000 (14:07 +0200)
* m4/csharpcomp.m4 (gt_CSHARPCOMP): Support 'dotnet' as implementation.
Set HAVE_DOTNET_SDK, HAVE_DOTNET_CSC.
* build-aux/csharpcomp.sh.in: Add implementations for the cases
$HAVE_DOTNET_SDK = 1 and $HAVE_DOTNET_CSC = 1.

ChangeLog
build-aux/csharpcomp.sh.in
m4/csharpcomp.m4

index 48b6bc549eb0e9732cea9de8851c452f9ff912e4..539d81b601c526de3dd3c83ad6266f482b1e9ed4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-10-08  Bruno Haible  <bruno@clisp.org>
+
+       csharpcomp-script: Add support for dotnet.
+       * m4/csharpcomp.m4 (gt_CSHARPCOMP): Support 'dotnet' as implementation.
+       Set HAVE_DOTNET_SDK, HAVE_DOTNET_CSC.
+       * build-aux/csharpcomp.sh.in: Add implementations for the cases
+       $HAVE_DOTNET_SDK = 1 and $HAVE_DOTNET_CSC = 1.
+
 2024-10-08  Bruno Haible  <bruno@clisp.org>
 
        csharpexec: Add support for dotnet.
index 9febcddd7268266637e62d27e9c76815f3a76ca7..85ea5aaf22cc31594fdd19c596846651f22a43ce 100644 (file)
@@ -82,8 +82,8 @@ while test $# != 0; do
           ;;
       esac
       options_mcs="$options_mcs -out:"`echo "$2" | sed -e "$sed_quote_subst"`
-      # On Windows, assume that 'csc' is a native Windows program,
-      # not a Cygwin program.
+      # On Windows, assume that 'dotnet' and 'csc' are native Windows programs,
+      # not Cygwin programs.
       arg="$2"
       case "@build_os@" in
         cygwin*)
@@ -95,8 +95,8 @@ while test $# != 0; do
       ;;
     -L)
       options_mcs="$options_mcs -lib:"`echo "$2" | sed -e "$sed_quote_subst"`
-      # On Windows, assume that 'csc' is a native Windows program,
-      # not a Cygwin program.
+      # On Windows, assume that 'dotnet' and 'csc' are native Windows programs,
+      # not Cygwin programs.
       arg="$2"
       case "@build_os@" in
         cygwin*)
@@ -124,8 +124,8 @@ while test $# != 0; do
       ;;
     *.resources)
       options_mcs="$options_mcs -resource:"`echo "$1" | sed -e "$sed_quote_subst"`
-      # On Windows, assume that 'csc' is a native Windows program,
-      # not a Cygwin program.
+      # On Windows, assume that 'dotnet' and 'csc' are native Windows programs,
+      # not Cygwin programs.
       arg="$1"
       case "@build_os@" in
         cygwin*)
@@ -136,8 +136,8 @@ while test $# != 0; do
       ;;
     *.cs)
       sources="$sources "`echo "$1" | sed -e "$sed_quote_subst"`
-      # On Windows, assume that 'csc' is a native Windows program,
-      # not a Cygwin program.
+      # On Windows, assume that 'dotnet' and 'csc' are native Windows programs,
+      # not Cygwin programs.
       arg="$1"
       case "@build_os@" in
         cygwin*)
@@ -169,11 +169,35 @@ if test -n "@HAVE_MCS@"; then
   rm -rf "$tmp"
   exit $result
 else
-  if test -n "@HAVE_CSC@"; then
-    test -z "$CSHARP_VERBOSE" || echo csc $options_csc $sources_csc
-    exec csc $options_csc $sources_csc
+  if test -n "@HAVE_DOTNET_SDK@"; then
+    dotnet_runtime_dir=`dotnet --list-runtimes | sed -n -e 's/Microsoft.NETCore.App \([^ ]*\) \[\(.*\)\].*/\2\/\1/p' | sed -e 1q`
+    dotnet_sdk_dir=`dotnet --list-sdks | sed -e 's/\([^ ]*\) \[\(.*\)\].*/\2\/\1/p' | sed -e 1q`
+    # Add -lib and -reference options, so that the compiler finds Object, Console, String, etc.
+    arg="$dotnet_runtime_dir"
+    case "@build_os@" in
+      cygwin*)
+        arg=`cygpath -w "$arg"`
+        ;;
+    esac
+    options_csc="$options_csc -lib:"`echo "$arg" | sed -e "$sed_quote_subst"`
+    for file in `cd "$dotnet_runtime_dir" && echo *.dll`; do
+      options_csc="$options_csc -reference:"`echo "$file" | sed -e "$sed_quote_subst"`
+    done
+    csc="$dotnet_sdk_dir/Roslyn/bincore/csc.dll"
+    case "@build_os@" in
+      cygwin*)
+        csc=`cygpath -w "$csc"`
+        ;;
+    esac
+    test -z "$CSHARP_VERBOSE" || echo dotnet "$csc" $options_csc $sources_csc
+    exec dotnet "$csc" $options_csc $sources_csc
   else
-    echo 'C# compiler not found, try installing mono, then reconfigure' 1>&2
-    exit 1
+    if test -n "@HAVE_DOTNET_CSC@" || test -n "@HAVE_CSC@"; then
+      test -z "$CSHARP_VERBOSE" || echo csc $options_csc $sources_csc
+      exec csc $options_csc $sources_csc
+    else
+      echo 'C# compiler not found, try installing mono or dotnet, then reconfigure' 1>&2
+      exit 1
+    fi
   fi
 fi
index 5a236ed4e5c9e5ee4bfe9757070785622edd16a1..360eb970deec94b08e6e2fd31f9f25016c5de06a 100644 (file)
@@ -1,4 +1,4 @@
-# csharpcomp.m4 serial 9
+# csharpcomp.m4 serial 11
 dnl Copyright (C) 2003-2005, 2007, 2009-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -6,7 +6,7 @@ dnl with or without modifications, as long as this notice is preserved.
 
 # Prerequisites of csharpcomp.sh.
 # Checks for a C# compiler.
-# Sets at most one of HAVE_MCS, HAVE_CSC.
+# Sets at most one of HAVE_MCS, HAVE_DOTNET_SDK, HAVE_DOTNET_CSC, HAVE_CSC.
 # Sets HAVE_CSHARPCOMP to nonempty if csharpcomp.sh will work.
 # Also sets CSHARPCOMPFLAGS.
 AC_DEFUN([gt_CSHARPCOMP],
@@ -18,11 +18,12 @@ AC_DEFUN([gt_CSHARPCOMP],
   pushdef([AC_CHECKING],[:])dnl
   pushdef([AC_MSG_RESULT],[:])dnl
   AC_CHECK_PROG([HAVE_MCS_IN_PATH], [mcs], [yes])
+  AC_CHECK_PROG([HAVE_DOTNET_IN_PATH], [dotnet], [yes])
   AC_CHECK_PROG([HAVE_CSC_IN_PATH], [csc], [yes])
   popdef([AC_MSG_RESULT])dnl
   popdef([AC_CHECKING])dnl
   popdef([AC_MSG_CHECKING])dnl
-  for impl in "$CSHARP_CHOICE" mono sscli no; do
+  for impl in "$CSHARP_CHOICE" mono dotnet sscli no; do
     case "$impl" in
       mono)
         if test -n "$HAVE_MCS_IN_PATH" \
@@ -33,6 +34,34 @@ AC_DEFUN([gt_CSHARPCOMP],
           break
         fi
         ;;
+      dotnet)
+        # The dotnet compiler is called "Roslyn".
+        # <https://en.wikipedia.org/wiki/Roslyn_(compiler)>
+        # There are two situations:
+        # - A dotnet SDK, that contains a 'dotnet' program and the Roslyn
+        #   compiler as csc.dll.
+        # - An MSVC installation, that contains the Roslyn compiler as csc.exe
+        #   (e.g. in C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\csc.exe).
+        # In the first case, the user only has to make sure that 'dotnet' is
+        # found in $PATH.
+        # In the second case, they need to make sure that both 'dotnet' and
+        # 'csc' are found in $PATH.
+        if test -n "$HAVE_DOTNET_IN_PATH" \
+           && dotnet --list-runtimes >/dev/null 2>/dev/null \
+           && test -n "`dotnet --list-sdks 2>/dev/null`"; then
+          HAVE_DOTNET_SDK=1
+          ac_result="dotnet"
+          break
+        else
+          if test -n "$HAVE_CSC_IN_PATH" \
+             && csc -help 2>/dev/null | grep analyzer >/dev/null \
+             && { if csc -help 2>/dev/null | grep -i chicken > /dev/null; then false; else true; fi; }; then
+            HAVE_DOTNET_CSC=1
+            ac_result="dotnet"
+            break
+          fi
+        fi
+        ;;
       sscli)
         if test -n "$HAVE_CSC_IN_PATH" \
            && csc -help >/dev/null 2>/dev/null \
@@ -51,6 +80,8 @@ AC_DEFUN([gt_CSHARPCOMP],
   done
   AC_MSG_RESULT([$ac_result])
   AC_SUBST([HAVE_MCS])
+  AC_SUBST([HAVE_DOTNET_SDK])
+  AC_SUBST([HAVE_DOTNET_CSC])
   AC_SUBST([HAVE_CSC])
   dnl Provide a default for CSHARPCOMPFLAGS.
   if test -z "${CSHARPCOMPFLAGS+set}"; then