Unverified Commit e9fbfe42 authored by David McFarland's avatar David McFarland Committed by GitHub
Browse files

godot_4: add godot_4-mono (#353242)

parents 14434de3 f73d108d
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
{
  godot_4,
}:
godot_4.override {
  withMono = true;
}
+269 −0

File added.

Preview size limit exceeded, changes collapsed.

+200 −140
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@
  autoPatchelfHook,
  buildPackages,
  dbus,
  dotnet-sdk_8,
  dotnetCorePackages,
  fetchFromGitHub,
  fontconfig,
  installShellFiles,
@@ -19,6 +21,7 @@
  libxkbcommon,
  libXrandr,
  libXrender,
  makeWrapper,
  pkg-config,
  scons,
  speechd-minimal,
@@ -29,6 +32,7 @@
  wayland-scanner,
  withDbus ? true,
  withFontconfig ? true,
  withMono ? false,
  withPlatform ? "linuxbsd",
  withPrecision ? "single",
  withPulseaudio ? true,
@@ -49,9 +53,11 @@ let
  mkSconsFlagsFromAttrSet = lib.mapAttrsToList (
    k: v: if builtins.isString v then "${k}=${v}" else "${k}=${builtins.toJSON v}"
  );
in
stdenv.mkDerivation rec {
  pname = "godot4";

  suffix = if withMono then "-mono" else "";

  attrs = rec {
    pname = "godot4${suffix}";
    version = "4.3-stable";
    commitHash = "77dcf97d82cbfe4e4615475fa52ca03da645dbd8";

@@ -85,9 +91,15 @@ stdenv.mkDerivation rec {
    #
    # See also 'hash' in
    # https://docs.godotengine.org/en/stable/classes/class_engine.html#class-engine-method-get-version-info
  preConfigure = ''
    preConfigure =
      ''
        mkdir -p .git
        echo ${commitHash} > .git/HEAD
      ''
      + lib.optionalString withMono ''
        dotnet restore modules/mono/glue/GodotSharp/GodotSharp.sln
        dotnet restore modules/mono/editor/GodotTools/GodotTools.sln
        dotnet restore modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk.sln
      '';

    # From: https://github.com/godotengine/godot/blob/4.2.2-stable/SConstruct
@@ -108,6 +120,8 @@ stdenv.mkDerivation rec {
      udev = withUdev; # Use udev for gamepad connection callbacks
      wayland = withWayland; # Compile with Wayland support
      x11 = withX11; # Compile with X11 support

      module_mono_enabled = withMono;
    };

    enableParallelBuilding = true;
@@ -119,12 +133,29 @@ stdenv.mkDerivation rec {
      pkg-config
    ];

  nativeBuildInputs = [
    nativeBuildInputs =
      [
        autoPatchelfHook
        installShellFiles
        pkg-config
        scons
  ] ++ lib.optionals withWayland [ wayland-scanner ];
      ]
      ++ lib.optionals withWayland [ wayland-scanner ]
      ++ lib.optionals withMono [
        dotnet-sdk_8
        makeWrapper
      ];

    postBuild = lib.optionalString withMono ''
      echo "Generating Glue"
      if [[ ${withPrecision} == *double* ]]; then
          bin/godot.${withPlatform}.${withTarget}.${withPrecision}.x86_64.mono --headless --generate-mono-glue modules/mono/glue
      else
          bin/godot.${withPlatform}.${withTarget}.x86_64.mono --headless --generate-mono-glue modules/mono/glue
      fi
      echo "Building C#/.NET Assemblies"
      python modules/mono/build_scripts/build_assemblies.py --godot-output-dir bin --precision=${withPrecision}
    '';

    runtimeDependencies =
      [
@@ -159,22 +190,34 @@ stdenv.mkDerivation rec {
      ++ lib.optionals withSpeechd [ speechd-minimal ]
      ++ lib.optionals withUdev [ udev ];

  installPhase = ''
    installPhase =
      ''
        runHook preInstall

        mkdir -p "$out/bin"
    cp bin/godot.* $out/bin/godot4
        cp bin/godot.* $out/bin/godot4${suffix}

        installManPage misc/dist/linux/godot.6

        mkdir -p "$out"/share/{applications,icons/hicolor/scalable/apps}
    cp misc/dist/linux/org.godotengine.Godot.desktop "$out/share/applications/org.godotengine.Godot4.desktop"
    substituteInPlace "$out/share/applications/org.godotengine.Godot4.desktop" \
      --replace "Exec=godot" "Exec=$out/bin/godot4" \
        cp misc/dist/linux/org.godotengine.Godot.desktop "$out/share/applications/org.godotengine.Godot4${suffix}.desktop"
        substituteInPlace "$out/share/applications/org.godotengine.Godot4${suffix}.desktop" \
          --replace "Exec=godot" "Exec=$out/bin/godot4${suffix}" \
          --replace "Godot Engine" "Godot Engine 4"
        cp icon.svg "$out/share/icons/hicolor/scalable/apps/godot.svg"
        cp icon.png "$out/share/icons/godot.png"

      ''
      + lib.optionalString withMono ''
        cp -r bin/GodotSharp/ $out/bin/
        wrapProgram $out/bin/godot4${suffix} \
          --set DOTNET_ROOT ${dotnet-sdk_8} \
          --prefix PATH : "${
            lib.makeBinPath [
              dotnet-sdk_8
            ]
          }"
      ''
      + ''
        runHook postInstall
      '';

@@ -184,13 +227,30 @@ stdenv.mkDerivation rec {
      homepage = "https://godotengine.org";
      license = lib.licenses.mit;
      platforms = [
      "i686-linux"
        "x86_64-linux"
        "aarch64-linux"
    ];
      ] ++ lib.optional (!withMono) "i686-linux";
      maintainers = with lib.maintainers; [
        shiryel
        corngood
      ];
    mainProgram = "godot4";
      mainProgram = "godot4${suffix}";
    };
  };

in
stdenv.mkDerivation (
  finalAttrs:
  if withMono then
    dotnetCorePackages.addNuGetDeps {
      nugetDeps = ./deps.nix;
      overrideFetchAttrs = old: rec {
        runtimeIds = map (system: dotnetCorePackages.systemToDotnetRid system) old.meta.platforms;
        buildInputs =
          old.buildInputs
          ++ lib.concatLists (lib.attrValues (lib.getAttrs runtimeIds dotnet-sdk_8.targetPackages));
      };
}
    } attrs finalAttrs
  else
    attrs
)