nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 godot3,
3 mono,
4 scons,
5 python311Packages,
6}:
7
8(godot3.override {
9 scons = scons.override {
10 python3Packages = python311Packages;
11 };
12}).overrideAttrs
13 (
14 self: base: {
15 pname = "godot3-mono-glue";
16 godotBuildDescription = "mono glue";
17 godotBuildPlatform = "server";
18
19 sconsFlags = base.sconsFlags ++ [
20 "module_mono_enabled=true"
21 "mono_glue=false" # Indicates not to expect already existing glue.
22 "mono_prefix=${mono}"
23 ];
24
25 nativeBuildInputs = base.nativeBuildInputs ++ [ mono ];
26
27 patches =
28 base.patches
29 ++ map (rp: ./patches + rp) ([
30 # When building godot mono, a "glue version" gets baked into it, and into the mono glue code
31 # generated by it. Godot mono export templates are also get a glue version baked in. If you
32 # export a godot mono project using an export template for which the glue version doesn't
33 # match that of the godot mono tool itself, then the resulting game will fail with an error
34 # saying "The assembly 'GodotSharp' is out of sync." Thus, if we want our build of godot mono
35 # to be compatible with the official export templates, we need to ensure it is built with the
36 # same glue version as the official build.
37 #
38 # A python script in the godot source, i.e. modules/mono/build_scripts/gen_cs_glue_version.py,
39 # is used by the build process to generate the glue version number. The official version of it
40 # does so based on the latest modified time of all the C# files in the GodotSharp solution. This
41 # is problematic because it is difficult to reproduce the exact timestamps that the files had
42 # when the official build was created. This is further complicated by the fact that nix clears
43 # the timestamps on the source files when they're unpacked. Thus, we can't simply regenerate the
44 # official glue version by building from the official source.
45 #
46 # To address this, we are patching the python script with a hard-coded glue version number. This
47 # patch file needs to be updated for every new version of godot, so to enforce this, the godot
48 # version is baked in to the file name, causing the build to fail until the patch is updated.
49 #
50 # The correct glue version number for a given godot version is obtained by running the official
51 # build of that version of godot with the --generate-mono-glue flag. This generates the mono
52 # glue files. One of those files, mono_glue.gen.cpp, has a function called get_cs_glue_version()
53 # which contains a hard-coded number. This is the glue version to put in the patch file.
54 #
55 # For convenience, the accompanying update-glue-version.sh script automates this work. Run it by
56 # passing the godot version as an argument, e.g. "3.5.2".
57 "/gen_cs_glue_version.py/hardcodeGlueVersion_${self.version}.patch"
58 ]);
59
60 outputs = [ "out" ];
61
62 installPhase = ''
63 runHook preInstall
64
65 glue="$out"/modules/mono/glue
66 mkdir -p "$glue"
67 bin/godot_server.x11.opt.tools.*.mono --generate-mono-glue "$glue"
68
69 runHook postInstall
70 '';
71
72 meta = base.meta // {
73 homepage = "https://docs.godotengine.org/en/stable/development/compiling/compiling_with_mono.html#generate-the-glue";
74 };
75 }
76 )