guix_mirror_bot pushed a commit to branch master
in repository guix.

commit a0a9240d0aaaab6067fbe6464f20d3942c0657cc
Author: Danny Milosavljevic <[email protected]>
AuthorDate: Wed Apr 8 17:03:07 2026 +0200

    gnu: Add [email protected].
    
    * gnu/packages/patches/roslyn-2.3.0-default-literal-for-csc-2.0.patch: New 
file.
    * gnu/local.mk (dist-patch_DATA): Add reference to it.
    * gnu/packages/dotnet.scm (roslyn-2.3): New variable.
    
    Change-Id: I9f279ad1e6adcebb5148f38ae27b9cc464920713
---
 gnu/local.mk                                       |   1 +
 gnu/packages/dotnet.scm                            | 107 +++++++++++++++++++++
 .../roslyn-2.3.0-default-literal-for-csc-2.0.patch |  35 +++++++
 3 files changed, 143 insertions(+)

diff --git a/gnu/local.mk b/gnu/local.mk
index c5b6d673d6..46581dd441 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -2425,6 +2425,7 @@ dist_patch_DATA =                                         
\
   
%D%/packages/patches/rocm-bandwidth-test-take-default-gpus-from-environment.patch
    \
   %D%/packages/patches/rocprim-placement-new-delete.patch      \
   %D%/packages/patches/roslyn-2.0.0-bootstrap-with-mono.patch  \
+  %D%/packages/patches/roslyn-2.3.0-default-literal-for-csc-2.0.patch  \
   %D%/packages/patches/rottlog-direntry.patch                  \
   %D%/packages/patches/ruby-actionpack-remove-browser-tests.patch      \
   %D%/packages/patches/ruby-activesupport-fix-deprecation-warning.patch        
\
diff --git a/gnu/packages/dotnet.scm b/gnu/packages/dotnet.scm
index af89d4580f..e33eeddb98 100644
--- a/gnu/packages/dotnet.scm
+++ b/gnu/packages/dotnet.scm
@@ -2561,6 +2561,113 @@ entirely from source using Mono's @command{mcs}.  It 
produces a C# 7.0
 compiler that can be used to bootstrap newer Roslyn versions.")
     (license license:asl2.0)
     (properties '((hidden? #t)))))
+
+
+;;;
+;;; roslyn-2.3: inherits roslyn-2.0, built with csc 2.0
+;;;
+
+(define-public roslyn-2.3
+  (package
+    (inherit roslyn-2.0)
+    (version "2.3.0")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+              (url "https://github.com/dotnet/roslyn";)
+              (commit (string-append "version-" version))))
+       (file-name (git-file-name "roslyn" version))
+       (sha256
+        (base32
+         "1hr7lh7vm8lbj73a63xwlwwgmwm068mll1rcihn2cmg5bi5jkzp6"))
+       (patches
+        (search-patches "roslyn-2.3.0-default-literal-for-csc-2.0.patch"))))
+    (native-inputs (list roslyn-2.0))
+    (arguments
+     (substitute-keyword-arguments arguments
+       ((#:phases phases '())
+        #~(modify-phases #$phases
+            ;; Replace mcs-specific fixes with csc-2.0-specific fixes.
+            (replace 'fix-compiler-compat
+              (lambda _
+                ;; csc 2.0 does not support "= default)" (C# 7.1).
+                (substitute* 
"src/Compilers/Core/Portable/AdditionalTextFile.cs"
+                  (("CancellationToken cancellationToken = default\\)")
+                   "CancellationToken cancellationToken = 
default(CancellationToken))"))
+                (substitute* 
"src/Compilers/Core/Portable/FileSystemExtensions.cs"
+                  (("CancellationToken cancellationToken = default\\)")
+                   "CancellationToken cancellationToken = 
default(CancellationToken))"))))
+
+            ;; Delete pre-generated files; we regenerate from XML.
+            (add-after 'remove-stale-files 'delete-generated-files
+              (lambda _
+                (for-each delete-file
+                          (find-files "src/Compilers/CSharp/Portable/Generated"
+                                      "\\.cs$"))))
+
+            ;; Replace the mcs wrapper with one that calls roslyn-2.0's csc.
+            ;; Mono's /bin/csc is broken (points at nonexistent csc.exe),
+            ;; so we must ensure our wrapper is found first.
+            (replace 'create-csc-wrapper
+              (lambda* (#:key inputs #:allow-other-keys)
+                (mkdir-p "bootstrap-bin")
+                (call-with-output-file "bootstrap-bin/csc"
+                  (lambda (port)
+                    (format port "#!~a~%exec mono ~a \"$@\"~%"
+                            (which "bash")
+                            (string-append (assoc-ref inputs "roslyn") 
"/lib/roslyn/csc.exe"))))
+                (chmod "bootstrap-bin/csc" #o755)
+                (setenv "PATH"
+                        (string-append (getcwd) "/bootstrap-bin:"
+                                       (getenv "PATH")))))
+
+            ;; SRM source needs C# 7.2 -> 7.0 downgrades for csc 2.0.
+            (replace 'prepare-srm-source
+              (lambda _
+                (copy-recursively #$%srm-source-dir "srm-src-patched")
+                (for-each make-file-writable
+                          (find-files "srm-src-patched"))
+                (for-each
+                 (lambda (file)
+                   (substitute* file
+                     (("readonly partial struct") "partial struct")
+                     (("readonly struct") "struct")))
+                 (find-files "srm-src-patched" "\\.cs$"))
+                (for-each
+                 (lambda (file)
+                   (substitute* file
+                     (("\\bin MemoryBlock ") "MemoryBlock ")
+                     (("metadataTableStream = default;")
+                      "metadataTableStream = default(MemoryBlock);")
+                     (("standalonePdbStream = default;")
+                      "standalonePdbStream = default(MemoryBlock);")))
+                 (find-files "srm-src-patched" "MetadataReader\\.cs$"))
+                (substitute*
+                    
"srm-src-patched/System/Reflection/Metadata/Ecma335/Encoding/ControlFlowBuilder.cs"
+                  (("label: default, opCode: default\\)")
+                   "label: default(LabelHandle), opCode: default(ILOpCode))"))
+                (for-each
+                 (lambda (file)
+                   (substitute* file
+                     (("StandaloneSignatureHandle localVariablesSignature = 
default,")
+                      "StandaloneSignatureHandle localVariablesSignature = 
default(StandaloneSignatureHandle),")
+                     (("\\) : default;")
+                      ") : default(ExceptionRegionEncoder);")))
+                 (find-files 
"srm-src-patched/System/Reflection/Metadata/Ecma335/Encoding"
+                             "\\.cs$"))
+                (for-each
+                 (lambda (file)
+                   (substitute* file
+                     (("type: ") "") (("version: ") "") (("stamp: ") "")))
+                 (find-files 
"srm-src-patched/System/Reflection/PortableExecutable/DebugDirectory"
+                             "\\.cs$"))))))))
+    (synopsis "C# 7.1 compiler bootstrapped from source")
+    (description
+     "This package provides the Roslyn C# compiler (@command{csc}), built
+from source using @code{roslyn-2.0} as the bootstrap compiler.  It produces
+a C# 7.1 compiler that supports default literals, which is needed to build
+newer Roslyn versions.")))
 ;; too new version: 15.9.21.664
 ;; too old (no support for mono) version: 14.0
 (define-public msbuild
diff --git 
a/gnu/packages/patches/roslyn-2.3.0-default-literal-for-csc-2.0.patch 
b/gnu/packages/patches/roslyn-2.3.0-default-literal-for-csc-2.0.patch
new file mode 100644
index 0000000000..ad00ec82f6
--- /dev/null
+++ b/gnu/packages/patches/roslyn-2.3.0-default-literal-for-csc-2.0.patch
@@ -0,0 +1,35 @@
+Author: Danny Milosavljevic <[email protected]>
+Date: 2026-04-08
+Subject: Avoid C# 7.1 implicit default literals (fix csc 2.0 
incompatibilities) for bootstrap.
+
+--- a/src/Compilers/CSharp/Portable/Lowering/LambdaRewriter/LambdaRewriter.cs
++++ b/src/Compilers/CSharp/Portable/Lowering/LambdaRewriter/LambdaRewriter.cs
+@@ -1349,7 +1349,7 @@
+                     closureKind = ClosureKind.Static;
+                     closureOrdinal = LambdaDebugInfo.StaticClosureOrdinal;
+                 }
+-                structClosures = default;
++                structClosures = default(ImmutableArray<TypeSymbol>);
+             }
+             else
+             {
+@@ -1368,7 +1368,7 @@
+                 }
+                 else
+                 {
+-                    structClosures = default;
++                    structClosures = default(ImmutableArray<TypeSymbol>);
+                 }
+ 
+                 containerAsFrame = null;
+--- 
a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_PatternSwitchStatement.cs
++++ 
b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_PatternSwitchStatement.cs
+@@ -182,7 +182,7 @@
+                     Add(loweredDecisionTree, (e, t) => new 
DecisionTree.Guarded(
+                         expression: loweredExpression,
+                         type: loweredExpression.Type,
+-                        bindings: default,
++                        bindings: 
default(ImmutableArray<KeyValuePair<BoundExpression, BoundExpression>>),
+                         sectionSyntax: defaultSection,
+                         guard: null,
+                         label: defaultLabel));

Reply via email to