[PATCH] Adding a fully-bootstrapped mono
unmush 2 years ago Aaron 2 years ago Richard 2 years ago Ludovic 2 years ago Janneke 2 years ago Ludovic 2 years ago Efraim 2 years ago Efraim 2 years ago Efraim 2 years ago Efraim 2 years ago Efraim 2 years ago Efraim 2 years ago Efraim 2 years ago Efraim 2 years ago Efraim 2 years ago Efraim 2 years ago Efraim 2 years ago Efraim 2 years ago Efraim 2 years ago Efraim 2 years ago Efraim 2 years ago Efraim 2 years ago Efraim 2 years ago Efraim 2 years ago Efraim 2 years ago Efraim 2 years ago Efraim 2 years ago Efraim 2 years ago Adam 2 years ago unmush 2 years ago unmush 2 years ago Ludovic 2 years ago Efraim 2 years ago Efraim 2 years ago [PATCH] Adding a fully-bootstrapped mono Done Details 7 participants Aaron Covrig Adam Faiz Efraim Flashner Janneke Nieuwenhuizen Ludovic Courtès Richard Sent unmush Owner unassigned Submitted by unmush Severity normal Merged with 57625 Debbugs page We used to have a mono package, but it was removed due to includingbootstrap binaries (among others).
This patch series introduces a full, 17-mono-package sequence that takes us from a mono-1.2.6 built fully from source to mono-6.12.0 built fully from source, using only packages that already have full bootstrap paths. I make no promise that this is the shortest or most optimal path, but it exists and I have verified it works. As I've spent what is probably an unreasonable amount of time working toward this, I thought I'd share some of my thoughts, experiences, and commentary.
Sorry in advance if it gets a bit rambly or lecture-ish. * Prologue I started down this road because someone I'm working on a project with decided to depend on a C# package that requires C# 12.0 features, and my personal mono package based on the tarball releases (which include bootstrap binaries) only went up to C# 7.0. This meant that the C# package in question de facto required strictly Microsoft's (er, I mean, "the .NET foundation"'s) .NET implementation - hereafter referred to as "dotnet" - and a very recent version no less.
The bootstrapping story with dotnet is very bad: https://github.com/dotnet/source-build/issues/1930. Even beginning to untangle it would probably require a relatively modern C# compiler, and something that at least sort of understands msbuild. And there's not much point to "bootstrapping" dotnet from something that isn't bootstrapped itself. So I figured I may as well start with mono. * History While mono is today probably the most well-known alternative to Microsoft's .NET offerings, it is not the only one.
Indeed, in the early 2000s there were at least 2 competing free software implementations: Mono, and DotGNU's Portable.NET (abbreviated pnet). They differed in goals, licenses, and methods: Portable.NET was a GNU project concerned with, among other things, limiting the ability of Microsoft to impose vendor lock-in via its proprietary .NET implementation and software patents. As a GNU project, it used the GPL for its runtime and compiler, and the GPL with a linking exception for its standard library, pnetlib.
Mono, on the other hand, used a mix of many copyleft and permissive licenses: X11 for the standard library, GPL for the compiler (later dual-licensed to add an X11 option), and LGPL for the runtime, with GPL and LGPL code also offered "under commercial terms for when the GPL and the LGPL are not suitable". In 2016 after its acquisition by Microsoft, the runtime was relicensed to use the Expat (MIT) license. But perhaps most importantly to us, while Mono opted to write its C# compiler, mcs, in...
C#, Portable.NET's runtime and C# compiler were both written in C. Portable.NET along with the entire DotGNU project was decommissioned in 2012, but the source is still available, and it still works fine (with a few modifications for compatibility with newer versions of its dependencies). In https://issues.guix.gnu.org/57625 Adam Faiz submitted patches to package pnet and pnetlib, along with one of their dependencies named treecc.
These packages were based on the last release of Portable.NET, version 0.8.0, released in 2007. I initially used these packages as the basis for my bootstrap efforts, and even managed to get mono-1.2.6 built using them, but later discovered that using a more recent version from git made it much easier. For example, while pnet-0.8.0 can do pointer arithmetic inside unsafe code blocks, it doesn't support the += or -= operators specifically, which requires lots of patching (after all, who would use x = x + y when you could do x+= y?).
There are many other similar improvements in the git version, so for this patch series I've decided to go with pnet-git. * The start After building mono-1.2.6, I tried a few later versions, and the third or fourth one would always fail with errors about missing methods. It turns out that the reason for this is that, contrary to what their marketing suggests, C# and Java are not "write once, run everywhere". This is because their compilers rely on the details of the libraries that the program will be run with at compile-time.
This is used, for example, to do overload resolution. Suppose, for example, that a certain implementation of the "==" operator is present in version 1.0 of a library, and then in version 2.0 of a library a more specific implementation is introduced. Now code that is compiled against version 2.0 may instead automatically reference the more-specific implementation, as is in accordance with the rules of C#. But when it is run with version 1.0, it will fail because that implementation doesn't exist.
In my case, for some reason the initial mcs and core libraries being built to compile the rest of mono were being compiled against a 2.0 library and then run with a 1.0 library. It turns out that this was because mcs uses mono's code for producing assemblies (.NET dlls and exes), and mono decides which version to put in an assembly it writes based on "which runtime version" is being used, and that version is decided at startup based on... the version that was put in the assembly it is running.
So for example, mono-1.9.1 would produce 2.0 assemblies because mono-1.2.6 produced 2.0 assemblies because pnet produced 2.0 assemblies. So I modified mono's runtime in mono-1.9.1 to allow for this version to be overridden via environment variable, and set it to "v1.1.4322", and things went a lot more smoothly after that. From there on it was mostly the usual trial-and-error process of identifying where things had bitrotted.
I made sure to unvendor libgc wherever possible, though eventually by mono-4.9.0 they explicitly dropped support in their configure script for using any libgc other than what was bundled, so at that point I switched to using their homebrewed sgen garbage collector. * A concerning development Once I got to mono-2.11.4, though, things took a turn for the interesting: mono started using git submodules, and the (recursive? #t) clones were all failing.
It turns out that this is because their submodules reference github.com using the git:// protocol. This is notable for a few reasons. First, github dropped support for the git:// protocol in 2021, so recursive clones won't work now. This means I have to explicitly list out every submodule, its commit, and its sha256 hash, for every mono version until they switched to using http or https. mono-2.11.4 has only 4 submodules, but that doesn't last for long: by mono-4.9.0 it has 14 submodules.
A significant portion of these patches is just listing these submodules and their hashes. It's a bit annoying. The more concerning reason, though, is *why* github dropped support for the git:// protocol: it is unencrypted and unauthenticated. This is mitigated somewhat by the use of sha-1 hashes to identify commits in the referenced submodules, putting a significant computational burden on anyone who would try to alter what was fetched corresponding to a given submodule.
Significantly more risky, though, is the process of *updating* submodules that use git:// URLs. It
The rest of this page is on the live site.