godot3: add mono builds

This commit is contained in:
rotaerk 2023-07-30 18:46:49 -04:00
parent e138e656c7
commit e555a7b3d1
12 changed files with 346 additions and 0 deletions

View File

@ -0,0 +1,7 @@
{ godot3-mono-headless }:
godot3-mono-headless.overrideAttrs (self: base: {
pname = "godot3-mono-debug-server";
godotBuildDescription = "mono debug server";
shouldBuildTools = false;
})

View File

@ -0,0 +1,65 @@
{ godot3
, callPackage
, mkNugetDeps
, mkNugetSource
, mono
, dotnet-sdk
, writeText
}:
godot3.overrideAttrs (self: base: {
pname = "godot3-mono";
godotBuildDescription = "mono build";
nativeBuildInputs = base.nativeBuildInputs ++ [ mono dotnet-sdk ];
glue = callPackage ./glue.nix {};
nugetDeps = mkNugetDeps { name = "deps"; nugetDeps = import ./deps.nix; };
nugetSource =
mkNugetSource {
name = "${self.pname}-nuget-source";
description = "A Nuget source with dependencies for ${self.pname}";
deps = [ self.nugetDeps ];
};
nugetConfig = writeText "NuGet.Config" ''
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="${self.pname}-deps" value="${self.nugetSource}/lib" />
</packageSources>
</configuration>
'';
sconsFlags = base.sconsFlags ++ [
"module_mono_enabled=true"
"mono_prefix=${mono}"
];
shouldConfigureNuget = true;
postConfigure = ''
echo "Setting up buildhome."
mkdir buildhome
export HOME="$PWD"/buildhome
echo "Overlaying godot glue."
cp -R --no-preserve=mode "$glue"/. .
if [ -n "$shouldConfigureNuget" ]; then
echo "Configuring NuGet."
mkdir -p ~/.nuget/NuGet
ln -s "$nugetConfig" ~/.nuget/NuGet/NuGet.Config
fi
'';
installedGodotShortcutFileName = "org.godotengine.GodotMono3.desktop";
installedGodotShortcutDisplayName = "Godot Engine (Mono) 3";
passthru = {
make-deps = callPackage ./make-deps.nix {};
};
})

View File

@ -0,0 +1,34 @@
{ fetchNuGet }: [
(fetchNuGet { pname = "EnvDTE"; version = "8.0.2"; sha256 = "1wdvjzdmqbqyqlaijpjc959vvdic12vqr3c5sffhbxi7m1si5k63"; })
(fetchNuGet { pname = "GodotTools.IdeMessaging"; version = "1.1.1"; sha256 = "0v70acpw2yq9mx05jy2gmkqqdbpgj8rb29ny2f3bgvmw9g5qmq94"; })
(fetchNuGet { pname = "JetBrains.Annotations"; version = "2019.1.3"; sha256 = "188b0qw6lih0k3ddnmimadzr3y1y6vh6ramgkjnyskqd43prjzc2"; })
(fetchNuGet { pname = "Microsoft.Build"; version = "16.5.0"; sha256 = "0baihvnzanqhk125g0ass9hhsqgp55h770pjjmsxdvprv0aqq22i"; })
(fetchNuGet { pname = "Microsoft.Build.Framework"; version = "16.5.0"; sha256 = "1xgr02r7s9i6s70n237hss4yi9zicssia3zd2ny6s8vyxb7jpdyb"; })
(fetchNuGet { pname = "Microsoft.NETCore.Platforms"; version = "1.0.1"; sha256 = "01al6cfxp68dscl15z7rxfw9zvhm64dncsw09a1vmdkacsa2v6lr"; })
(fetchNuGet { pname = "Microsoft.NETCore.Platforms"; version = "1.1.0"; sha256 = "08vh1r12g6ykjygq5d3vq09zylgb84l63k49jc4v8faw9g93iqqm"; })
(fetchNuGet { pname = "Microsoft.NETCore.Targets"; version = "1.0.1"; sha256 = "0ppdkwy6s9p7x9jix3v4402wb171cdiibq7js7i13nxpdky7074p"; })
(fetchNuGet { pname = "Microsoft.NETFramework.ReferenceAssemblies"; version = "1.0.0"; sha256 = "0na724xhvqm63vq9y18fl9jw9q2v99bdwr353378s5fsi11qzxp9"; })
(fetchNuGet { pname = "Microsoft.NETFramework.ReferenceAssemblies.net472"; version = "1.0.0"; sha256 = "1bqinq2nxnpqxziypg1sqy3ly0nymxxjpn8fwkn3rl4vl6gdg3rc"; })
(fetchNuGet { pname = "Microsoft.VisualStudio.Setup.Configuration.Interop"; version = "1.16.30"; sha256 = "14022lx03vdcqlvbbdmbsxg5pqfx1rfq2jywxlyaz9v68cvsb0g4"; })
(fetchNuGet { pname = "Mono.Cecil"; version = "0.11.3"; sha256 = "0xcx7pk9y2n1hr15c0l1balzi69kw5gy8dk7sb8jwqyyvm35q4j3"; })
(fetchNuGet { pname = "NETStandard.Library"; version = "2.0.3"; sha256 = "1fn9fxppfcg4jgypp2pmrpr6awl3qz1xmnri0cygpkwvyx27df1y"; })
(fetchNuGet { pname = "Newtonsoft.Json"; version = "13.0.1"; sha256 = "0fijg0w6iwap8gvzyjnndds0q4b8anwxxvik7y8vgq97dram4srb"; })
(fetchNuGet { pname = "Semver"; version = "2.0.6"; sha256 = "136sd6d3ys49dipvc1h3ivmp8ryd4p7fdmdrr28521cqpvkw5f1k"; })
(fetchNuGet { pname = "stdole"; version = "7.0.3302"; sha256 = "1n8vbzlgyklazriwvb6kjyw5w0m9a1b3xsa0f0v29j03z23fx69p"; })
(fetchNuGet { pname = "System.Buffers"; version = "4.4.0"; sha256 = "183f8063w8zqn99pv0ni0nnwh7fgx46qzxamwnans55hhs2l0g19"; })
(fetchNuGet { pname = "System.Collections.Immutable"; version = "1.5.0"; sha256 = "1d5gjn5afnrf461jlxzawcvihz195gayqpcfbv6dd7pxa9ialn06"; })
(fetchNuGet { pname = "System.Globalization"; version = "4.0.11"; sha256 = "070c5jbas2v7smm660zaf1gh0489xanjqymkvafcs4f8cdrs1d5d"; })
(fetchNuGet { pname = "System.IO"; version = "4.1.0"; sha256 = "1g0yb8p11vfd0kbkyzlfsbsp5z44lwsvyc0h3dpw6vqnbi035ajp"; })
(fetchNuGet { pname = "System.Memory"; version = "4.5.3"; sha256 = "0naqahm3wljxb5a911d37mwjqjdxv9l0b49p5dmfyijvni2ppy8a"; })
(fetchNuGet { pname = "System.Numerics.Vectors"; version = "4.4.0"; sha256 = "0rdvma399070b0i46c4qq1h2yvjj3k013sqzkilz4bz5cwmx1rba"; })
(fetchNuGet { pname = "System.Reflection"; version = "4.1.0"; sha256 = "1js89429pfw79mxvbzp8p3q93il6rdff332hddhzi5wqglc4gml9"; })
(fetchNuGet { pname = "System.Reflection.Primitives"; version = "4.0.1"; sha256 = "1bangaabhsl4k9fg8khn83wm6yial8ik1sza7401621jc6jrym28"; })
(fetchNuGet { pname = "System.Resources.ResourceManager"; version = "4.0.1"; sha256 = "0b4i7mncaf8cnai85jv3wnw6hps140cxz8vylv2bik6wyzgvz7bi"; })
(fetchNuGet { pname = "System.Runtime"; version = "4.1.0"; sha256 = "02hdkgk13rvsd6r9yafbwzss8kr55wnj8d5c7xjnp8gqrwc8sn0m"; })
(fetchNuGet { pname = "System.Runtime.CompilerServices.Unsafe"; version = "4.5.2"; sha256 = "1vz4275fjij8inf31np78hw50al8nqkngk04p3xv5n4fcmf1grgi"; })
(fetchNuGet { pname = "System.Runtime.Serialization.Primitives"; version = "4.1.1"; sha256 = "042rfjixknlr6r10vx2pgf56yming8lkjikamg3g4v29ikk78h7k"; })
(fetchNuGet { pname = "System.Text.Encoding"; version = "4.0.11"; sha256 = "1dyqv0hijg265dwxg6l7aiv74102d6xjiwplh2ar1ly6xfaa4iiw"; })
(fetchNuGet { pname = "System.Threading.Tasks"; version = "4.0.11"; sha256 = "0nr1r41rak82qfa5m0lhk9mp0k93bvfd7bbd9sdzwx9mb36g28p5"; })
(fetchNuGet { pname = "System.Threading.Tasks.Dataflow"; version = "4.9.0"; sha256 = "1g6s9pjg4z8iy98df60y9a01imdqy59zd767vz74rrng78jl2dk5"; })
(fetchNuGet { pname = "System.Threading.Thread"; version = "4.0.0"; sha256 = "1gxxm5fl36pjjpnx1k688dcw8m9l7nmf802nxis6swdaw8k54jzc"; })
]

View File

@ -0,0 +1,28 @@
{ godot3-mono }:
godot3-mono.overrideAttrs (self: base: {
pname = "godot3-mono-export-templates";
godotBuildDescription = "nix mono export templates";
# As described in default.nix, adding the link flags to pulseaudio in detect.py was necessary to
# allow the dlopen calls to succeed in Nix builds of godot. However, it seems that this *breaks*
# the export templates, resulting in programs exported from godot using these export templates to
# be unable to load this library.
shouldAddLinkFlagsToPulse = false;
shouldBuildTools = false;
godotBuildTarget = "release";
godotBinInstallPath = "share/godot/templates/${self.version}.stable.mono";
installedGodotBinName = "linux_${self.godotBuildPlatform}_64_${self.godotBuildTarget}";
# https://docs.godotengine.org/en/stable/development/compiling/optimizing_for_size.html
# Stripping reduces the template size from around 500MB to 40MB for Linux.
# This also impacts the size of the exported games.
# This is added explicitly here because mkDerivation does not automatically
# strip binaries in the template directory.
stripAllList = (base.stripAllList or []) ++ [ "share/godot/templates" ];
meta = base.meta // {
homepage = "https://docs.godotengine.org/en/stable/development/compiling/compiling_with_mono.html#export-templates";
};
})

View File

@ -0,0 +1,66 @@
{ godot3, mono }:
godot3.overrideAttrs (self: base: {
pname = "godot3-mono-glue";
godotBuildDescription = "mono glue";
godotBuildPlatform = "server";
sconsFlags = base.sconsFlags ++ [
"module_mono_enabled=true"
"mono_glue=false" # Indicates not to expect already existing glue.
"mono_prefix=${mono}"
];
nativeBuildInputs = base.nativeBuildInputs ++ [ mono ];
patches =
base.patches ++
map (rp: ./patches + rp) (
[
# When building godot mono, a "glue version" gets baked into it, and into the mono glue code
# generated by it. Godot mono export templates are also get a glue version baked in. If you
# export a godot mono project using an export template for which the glue version doesn't
# match that of the godot mono tool itself, then the resulting game will fail with an error
# saying "The assembly 'GodotSharp' is out of sync." Thus, if we want our build of godot mono
# to be compatible with the official export templates, we need to ensure it is built with the
# same glue version as the official build.
#
# A python script in the godot source, i.e. modules/mono/build_scripts/gen_cs_glue_version.py,
# is used by the build process to generate the glue version number. The official version of it
# does so based on the latest modified time of all the C# files in the GodotSharp solution. This
# is problematic because it is difficult to reproduce the exact timestamps that the files had
# when the official build was created. This is further complicated by the fact that nix clears
# the timestamps on the source files when they're unpacked. Thus, we can't simply regenerate the
# official glue version by building from the official source.
#
# To address this, we are patching the python script with a hard-coded glue version number. This
# patch file needs to be updated for every new version of godot, so to enforce this, the godot
# version is baked in to the file name, causing the build to fail until the patch is updated.
#
# The correct glue version number for a given godot version is obtained by running the official
# build of that version of godot with the --generate-mono-glue flag. This generates the mono
# glue files. One of those files, mono_glue.gen.cpp, has a function called get_cs_glue_version()
# which contains a hard-coded number. This is the glue version to put in the patch file.
#
# For convenience, the accompanying update-glue-version.sh script automates this work. Run it by
# passing the godot version as an argument, e.g. "3.5.2".
"/gen_cs_glue_version.py/hardcodeGlueVersion_${self.version}.patch"
]
);
outputs = [ "out" ];
installPhase = ''
runHook preInstall
glue="$out"/modules/mono/glue
mkdir -p "$glue"
bin/godot_server.x11.opt.tools.*.mono --generate-mono-glue "$glue"
runHook postInstall
'';
meta = base.meta // {
homepage = "https://docs.godotengine.org/en/stable/development/compiling/compiling_with_mono.html#generate-the-glue";
};
})

View File

@ -0,0 +1,7 @@
{ godot3-mono }:
godot3-mono.overrideAttrs (self: base: {
pname = "godot3-mono-headless";
godotBuildDescription = "mono headless";
godotBuildPlatform = "server";
})

View File

@ -0,0 +1,59 @@
{ godot3-mono, nuget-to-nix }:
godot3-mono.overrideAttrs (self: base: {
pname = "godot3-mono-make-deps";
nativeBuildInputs = base.nativeBuildInputs ++ [ nuget-to-nix ];
nugetDeps = null;
nugetSource = null;
nugetConfig = null;
shouldConfigureNuget = false;
outputs = [ "out" ];
buildPhase = " ";
installPhase = ''echo "No output intended. Run make-deps.sh instead." > $out'';
# This script is used to update the accompanying deps.nix file, a nix expression listing the
# nuget packages that the godot-mono code depends on, along with their sha256 hashes. This
# file is referenced by the godot-mono derivation and needs to be updated every time the
# godot version is updated. The way it works is:
#
# 1) Creates and navigates to a temporary directory and then explicitly runs the unpack,
# patch, and configure phases from the godot-mono derivation.
# 2) Instead of building at this point, a nuget restore is performed, downloading all the
# nuget dependencies of godot-mono into a local folder.
# 3) Once these have been downloaded, the nuget-to-nix tool is used to generate a nix
# expression listing the locally obtained nuget packages, along with their sha256 hashes.
# 4) This nix expression is saved as deps.nix in the PWD.
#
# This process is impure, because it entails downloading files with unknown hashes, so it
# is run manually by the maintainer within a nix-shell environment. Running the accompanying
# make-deps.sh instead simplifies this.
makeDeps = ''
set -e
outdir="$(pwd)"
wrkdir="$(mktemp -d)"
trap 'rm -rf -- "$wrkdir"' EXIT
pushd "$wrkdir" > /dev/null
unpackPhase
cd source
patchPhase
configurePhase
# Without RestorePackagesPath set, it restores packages to a temp directory. Specifying
# a path ensures we have a place to run nuget-to-nix.
nugetRestore() { dotnet msbuild -t:Restore -p:RestorePackagesPath=nugetPackages $1; }
nugetRestore modules/mono/glue/GodotSharp/GodotSharp.sln
nugetRestore modules/mono/editor/GodotTools/GodotTools.sln
nuget-to-nix nugetPackages > "$outdir"/deps.nix
popd > /dev/null
'';
meta = base.meta // {
description = "Derivation with no output that exists to provide an environment for make-deps.sh";
};
})

View File

@ -0,0 +1,2 @@
#!/usr/bin/env bash
nix-shell "$(git rev-parse --show-toplevel)" -A godot3-mono.make-deps --run 'eval "$makeDeps"'

View File

@ -0,0 +1,22 @@
diff --git a/modules/mono/build_scripts/gen_cs_glue_version.py b/modules/mono/build_scripts/gen_cs_glue_version.py
index 98bbb4d9be..5189f2551b 100644
--- a/modules/mono/build_scripts/gen_cs_glue_version.py
+++ b/modules/mono/build_scripts/gen_cs_glue_version.py
@@ -1,16 +1,5 @@
def generate_header(solution_dir, version_header_dst):
- import os
-
- latest_mtime = 0
- for root, dirs, files in os.walk(solution_dir, topdown=True):
- dirs[:] = [d for d in dirs if d not in ["Generated"]] # Ignored generated files
- files = [f for f in files if f.endswith(".cs")]
- for file in files:
- filepath = os.path.join(root, file)
- mtime = os.path.getmtime(filepath)
- latest_mtime = mtime if mtime > latest_mtime else latest_mtime
-
- glue_version = int(latest_mtime) # The latest modified time will do for now
+ glue_version = 1678112021
with open(version_header_dst, "w") as version_header:
version_header.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")

View File

@ -0,0 +1,7 @@
{ godot3-mono-debug-server }:
godot3-mono-debug-server.overrideAttrs (self: base: {
pname = "godot3-mono-server";
godotBuildDescription = "mono server";
godotBuildTarget = "release";
})

View File

@ -0,0 +1,39 @@
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p steam-run unzip wget
# This script updates the hard-coded glue_version in:
#
# patches/gen_cs_glue_version.py/hardcodeGlueVersionFor{version}.patch
#
# It does so by pulling it from the official build.
set -e
[ -z "$1" ] && echo "Godot version not specified. Exiting." && exit 1
gdversion=$1
# Download and extract the official stable 64-bit X11 mono build of Godot.
gddir="$(mktemp -d)"
trap 'rm -rf -- "$gddir"' EXIT
wget -P "$gddir" https://downloads.tuxfamily.org/godotengine/$gdversion/mono/Godot_v$gdversion-stable_mono_x11_64.zip
unzip "$gddir"/Godot_v$gdversion-stable_mono_x11_64.zip -d "$gddir"
# Generate the mono glue from the official build.
gluedir="$(mktemp -d)"
trap 'rm -rf -- "$gluedir"' EXIT
steam-run "$gddir"/Godot_v$gdversion-stable_mono_x11_64/Godot_v$gdversion-stable_mono_x11.64 --generate-mono-glue "$gluedir"
# Extract the glue version.
glueversion=$(grep -Po '(?<=get_cs_glue_version\(\) \{ return )[0-9]+(?=; \})' "$gluedir"/mono_glue.gen.cpp)
patchdir=./patches/gen_cs_glue_version.py/
patchprefix=hardcodeGlueVersion_
newpatchname=$patchprefix$gdversion.patch
# Update the patch with the obtained glue version.
sed -i "s/^+ glue_version = [0-9]\+$/+ glue_version = $glueversion/" $patchdir/$patchprefix*.patch
mv $patchdir/$patchprefix*.patch $patchdir/$patchprefix$gdversion.patch
echo "Updated $patchdir/$patchprefix$gdversion.patch with glue_version: $glueversion"

View File

@ -8236,6 +8236,16 @@ with pkgs;
godot3-server = callPackage ../development/tools/godot/3/server.nix { };
godot3-mono = callPackage ../development/tools/godot/3/mono {};
godot3-mono-export-templates = callPackage ../development/tools/godot/3/mono/export-templates.nix { };
godot3-mono-headless = callPackage ../development/tools/godot/3/mono/headless.nix { };
godot3-mono-debug-server = callPackage ../development/tools/godot/3/mono/debug-server.nix { };
godot3-mono-server = callPackage ../development/tools/godot/3/mono/server.nix { };
goeland = callPackage ../applications/networking/feedreaders/goeland { };
go-mtpfs = callPackage ../tools/filesystems/go-mtpfs { };