guix_mirror_bot pushed a commit to branch master
in repository guix.

commit 8bd02af8349e07a2b93db8451054bf4ab78f56d8
Author: Danny Milosavljevic <[email protected]>
AuthorDate: Fri Apr 10 18:00:21 2026 +0200

    gnu: Add [email protected].
    
    * gnu/packages/patches/roslyn-3.9.0-bootstrap-with-csc-3.8.patch: New file.
    * gnu/local.mk (dist_patch_DATA): Add reference to it.
    * gnu/packages/dotnet.scm (roslyn-3.9): New variable.
    (roslyn): Replace variable.
    
    Change-Id: I1910ce649e10122a7dea87866a4a33869f7d855c
---
 gnu/local.mk                                       |  1 +
 gnu/packages/dotnet.scm                            | 93 +++++++++++++++++++++-
 .../roslyn-3.9.0-bootstrap-with-csc-3.8.patch      | 84 +++++++++++++++++++
 3 files changed, 177 insertions(+), 1 deletion(-)

diff --git a/gnu/local.mk b/gnu/local.mk
index 99140d48ce..6bcf4b22e0 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -2430,6 +2430,7 @@ dist_patch_DATA =                                         
\
   %D%/packages/patches/roslyn-3.0.0-bootstrap-with-csc-2.8.patch       \
   %D%/packages/patches/roslyn-3.2.0-bootstrap-with-csc-3.0.patch       \
   %D%/packages/patches/roslyn-3.8.0-bootstrap-with-csc-3.2.patch       \
+  %D%/packages/patches/roslyn-3.9.0-bootstrap-with-csc-3.8.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 350147536a..ee2bbb9d03 100644
--- a/gnu/packages/dotnet.scm
+++ b/gnu/packages/dotnet.scm
@@ -3453,7 +3453,98 @@ using System.Reflection;
 scripting libraries, built from source using @code{roslyn-3.2} as the
 bootstrap compiler.  It produces a C# 9.0 compiler matching Mono 6.12.")))
 
-(define roslyn roslyn-3.8)
+;; roslyn-3.9: inherits roslyn-3.8, built with csc 3.8.
+;; Upstream mono 6.12.0.206 ships 3.9.0 (roslyn-binaries commit
+;; 1c6482470c).  Both 3.8 and 3.9 implement C# 9.  The only
+;; 3.9-specific change is project-wide nullable enable (was per-file
+;; in 3.8), plus a few new Mono-compat fixes in the patch
+;; (CodePagesEncodingProvider in BuildClient.cs, Unsafe.As in
+;; ImmutableArrayExtensions.cs).
+(define-public roslyn-3.9
+  (package
+    (inherit roslyn-3.8)
+    (version "3.9.0")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/dotnet/roslyn";)
+             (commit (string-append "v" version))))
+       (file-name (git-file-name "roslyn" version))
+       (sha256
+        (base32
+         "1kgm9aq5kd3cb8hw7nrmdyxlxw0blxvhdayyc0f28dzns2ph6v58"))
+       (patches
+        (search-patches "roslyn-3.9.0-bootstrap-with-csc-3.8.patch"))))
+    (native-inputs (list roslyn-3.8))
+    (arguments
+     (substitute-keyword-arguments (package-arguments roslyn-3.8)
+       ((#:phases phases '())
+        #~(modify-phases #$phases
+            ;; Point at roslyn-3.8's csc.
+            (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")))))
+
+            ;; 3.9 uses project-wide nullable enable instead of
+            ;; per-file #nullable enable directives.
+            (replace 'create-csc-rsp
+              (lambda _
+                (call-with-output-file "csc.rsp"
+                  (lambda (port)
+                    (display
+                     "-langversion:preview\n-d:NET472\n-nullable:enable\n"
+                     port)))))
+
+            ;; Broad Mono workarounds that are impractical in a patch
+            ;; (too many files).  Targeted fixes are in the patch.
+            (add-after 'unpack 'fix-mono-compat-3.9
+              (lambda _
+                ;; SignatureCallingConvention.Unmanaged (value 9) not
+                ;; in Mono's SRM.  The enum initializer in Members.cs
+                ;; is handled by the patch; sweep remaining uses.
+                (for-each
+                 (lambda (file)
+                   (substitute* file
+                     (("SignatureCallingConvention\\.Unmanaged")
+                      "(SignatureCallingConvention)9")))
+                 (append
+                  (find-files "src/Compilers/Core/Portable" "\\.cs$")
+                  (find-files "src/Compilers/CSharp/Portable" "\\.cs$")))
+                ;; PathUtilities ambiguity with SRM (too many files
+                ;; to patch individually).
+                (for-each
+                 (lambda (file)
+                   (substitute* file
+                     (("\\bPathUtilities\\.")
+                      "Roslyn.Utilities.PathUtilities.")))
+                 (append
+                  (find-files "src/Compilers/Core/Portable" "\\.cs$")
+                  (find-files "src/Scripting" "\\.cs$")))
+                ;; Index/Range polyfills are internal and shadow Mono's
+                ;; public mscorlib types.  Delete so csc finds the
+                ;; mscorlib versions.
+                (delete-file
+                 "src/Compilers/Core/Portable/InternalUtilities/Index.cs")
+                (delete-file
+                 
"src/Compilers/Core/Portable/InternalUtilities/Range.cs")))))))
+    (synopsis "C# 9.0 compiler and scripting libraries, bootstrapped from 
source")
+    (description
+     "This package provides the Roslyn C# compiler (@command{csc}) and
+scripting libraries, built from source using @code{roslyn-3.8} as the
+bootstrap compiler.  This is the version shipped by upstream Mono 6.12.")))
+
+(define roslyn roslyn-3.9)
 
 ;; too new version: 15.9.21.664
 ;; too old (no support for mono) version: 14.0
diff --git a/gnu/packages/patches/roslyn-3.9.0-bootstrap-with-csc-3.8.patch 
b/gnu/packages/patches/roslyn-3.9.0-bootstrap-with-csc-3.8.patch
new file mode 100644
index 0000000000..2cb8bf84cc
--- /dev/null
+++ b/gnu/packages/patches/roslyn-3.9.0-bootstrap-with-csc-3.8.patch
@@ -0,0 +1,84 @@
+--- a/src/Compilers/CSharp/Portable/Compilation/CSharpCompilation.cs
++++ b/src/Compilers/CSharp/Portable/Compilation/CSharpCompilation.cs
+@@ -2214,7 +2214,7 @@
+ 
+         private BinderFactory GetBinderFactory(SyntaxTree syntaxTree, bool 
ignoreAccessibility, ref WeakReference<BinderFactory>[]? cachedBinderFactories)
+         {
+-            Debug.Assert(System.Runtime.CompilerServices.Unsafe.AreSame(ref 
cachedBinderFactories, ref ignoreAccessibility ? ref 
_ignoreAccessibilityBinderFactories : ref _binderFactories));
++            // Unsafe.AreSame not available on Mono
+ 
+             var treeNum = GetSyntaxTreeOrdinal(syntaxTree);
+             WeakReference<BinderFactory>[]? binderFactories = 
cachedBinderFactories;
+--- a/src/Compilers/Shared/BuildClient.cs
++++ b/src/Compilers/Shared/BuildClient.cs
+@@ -84,7 +84,7 @@
+             {
+                 // Register encodings for console
+                 // https://github.com/dotnet/roslyn/issues/10785
+-                
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
++                // CodePagesEncodingProvider not available on Mono
+             }
+ 
+             var client = new BuildClient(language, compileFunc, logger);
+--- a/src/Compilers/Core/Portable/PEWriter/Members.cs
++++ b/src/Compilers/Core/Portable/PEWriter/Members.cs
+@@ -58,7 +58,7 @@
+         /// Extensible calling convention protocol. This represents either 
the union of calling convention modopts after the paramcount specifier
+         /// in IL, or platform default if none are present
+         /// </summary>
+-        Unmanaged = SignatureCallingConvention.Unmanaged,
++        Unmanaged = 9,
+ 
+         /// <summary>
+         /// The convention for calling a generic method.
+--- a/src/Compilers/Core/Portable/PEWriter/PeWriter.cs
++++ b/src/Compilers/Core/Portable/PEWriter/PeWriter.cs
+@@ -350,7 +350,7 @@
+                 _resourceSection = resourceSection;
+             }
+ 
+-            protected override void Serialize(BlobBuilder builder, 
SectionLocation location)
++            protected internal override void Serialize(BlobBuilder builder, 
SectionLocation location)
+             {
+                 NativeResourceWriter.SerializeWin32Resources(builder, 
_resourceSection, location.RelativeVirtualAddress);
+             }
+@@ -366,7 +366,7 @@
+                 _resources = resources;
+             }
+ 
+-            protected override void Serialize(BlobBuilder builder, 
SectionLocation location)
++            protected internal override void Serialize(BlobBuilder builder, 
SectionLocation location)
+             {
+                 NativeResourceWriter.SerializeWin32Resources(builder, 
_resources, location.RelativeVirtualAddress);
+             }
+--- a/src/Compilers/Core/Portable/Emit/EditAndContinue/DeltaMetadataWriter.cs
++++ b/src/Compilers/Core/Portable/Emit/EditAndContinue/DeltaMetadataWriter.cs
+@@ -635,7 +635,7 @@
+ 
+             if (localVariables.Length > 0)
+             {
+-                var writer = PooledBlobBuilder.GetInstance();
++                var writer = Microsoft.Cci.PooledBlobBuilder.GetInstance();
+                 var encoder = new 
BlobEncoder(writer).LocalVariableSignature(localVariables.Length);
+ 
+                 foreach (ILocalDefinition local in localVariables)
+--- a/src/Compilers/Core/Portable/Collections/ImmutableArrayExtensions.cs
++++ b/src/Compilers/Core/Portable/Collections/ImmutableArrayExtensions.cs
+@@ -669,7 +669,7 @@
+         // TODO(https://github.com/dotnet/corefx/issues/34126): Remove when 
System.Collections.Immutable
+         // provides a Span API
+         internal static T[] DangerousGetUnderlyingArray<T>(this 
ImmutableArray<T> array)
+-            => Unsafe.As<ImmutableArray<T>, ImmutableArrayProxy<T>>(ref 
array).MutableArray;
++            => System.Linq.Enumerable.ToArray(array);
+ 
+         internal static ReadOnlySpan<T> AsSpan<T>(this ImmutableArray<T> 
array)
+             => array.DangerousGetUnderlyingArray();
+@@ -678,7 +678,7 @@
+         {
+             var proxy = new ImmutableArrayProxy<T> { MutableArray = array };
+             array = null!;
+-            return Unsafe.As<ImmutableArrayProxy<T>, ImmutableArray<T>>(ref 
proxy);
++            return 
System.Collections.Immutable.ImmutableArray.Create(proxy.MutableArray);
+         }
+ 
+         internal static Dictionary<K, ImmutableArray<T>> ToDictionary<K, 
T>(this ImmutableArray<T> items, Func<T, K> keySelector, IEqualityComparer<K>? 
comparer = null)

Reply via email to