From e614b5a2d0dc2dc6eab502f34e72c219ecf8fa46 Mon Sep 17 00:00:00 2001 From: Milan Date: Mon, 11 Jan 2021 15:55:52 +0100 Subject: [PATCH] mindustry: build Arc from source (#108274) - reduce the buildPhase of the fixed-output dependencies derivation to only download all dependencies, instead of building the full thing. - add wayland variant, which is linked against a different variant of the glew library to run natively using SDL_VIDEODRIVER=wayland - use jdk (Java 15) instead of jre (Java 8) at runtime - use new copyDesktopItems hook --- ...1-fix-include-path-for-SDL2-on-linux.patch | 33 ++++ pkgs/games/mindustry/default.nix | 171 ++++++++++++------ pkgs/top-level/all-packages.nix | 5 + 3 files changed, 154 insertions(+), 55 deletions(-) create mode 100644 pkgs/games/mindustry/0001-fix-include-path-for-SDL2-on-linux.patch diff --git a/pkgs/games/mindustry/0001-fix-include-path-for-SDL2-on-linux.patch b/pkgs/games/mindustry/0001-fix-include-path-for-SDL2-on-linux.patch new file mode 100644 index 000000000000..d4fe7be19183 --- /dev/null +++ b/pkgs/games/mindustry/0001-fix-include-path-for-SDL2-on-linux.patch @@ -0,0 +1,33 @@ +From 9dbfa680db6bfd1033772dda753120fe4452e0d9 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Milan=20P=C3=A4ssler?= +Date: Fri, 8 Jan 2021 04:49:14 +0100 +Subject: [PATCH] fix include path for SDL2 on linux + +--- + .../src/main/java/arc/backend/sdl/jni/SDL.java | 8 -------- + 1 file changed, 8 deletions(-) + +diff --git a/backends/backend-sdl/src/main/java/arc/backend/sdl/jni/SDL.java b/backends/backend-sdl/src/main/java/arc/backend/sdl/jni/SDL.java +index 62d9286a..2853119d 100644 +--- a/Arc/backends/backend-sdl/src/main/java/arc/backend/sdl/jni/SDL.java ++++ b/Arc/backends/backend-sdl/src/main/java/arc/backend/sdl/jni/SDL.java +@@ -8,16 +8,8 @@ import java.nio.*; + public class SDL{ + /*JNI + +- #ifdef __APPLE__ +- + #include "SDL2/SDL.h" + +- #else +- +- #include "SDL.h" +- +- #endif +- + */ + + static{ +-- +2.29.2 + diff --git a/pkgs/games/mindustry/default.nix b/pkgs/games/mindustry/default.nix index db2dcdf91807..6cf3941fb08a 100644 --- a/pkgs/games/mindustry/default.nix +++ b/pkgs/games/mindustry/default.nix @@ -1,12 +1,20 @@ { lib, stdenv , makeWrapper , makeDesktopItem +, copyDesktopItems , fetchFromGitHub +, fetchpatch , gradleGen , jdk , perl -, jre + +# for arc +, SDL2 +, pkg-config +, stb +, ant , alsaLib +, glew # Make the build version easily overridable. # Server and client build versions must match, and an empty build version means @@ -25,12 +33,52 @@ let version = "122.1"; buildVersion = makeBuildVersion version; - src = fetchFromGitHub { + Mindustry = fetchFromGitHub { owner = "Anuken"; repo = "Mindustry"; rev = "v${version}"; sha256 = "18m4s81cfb2cr2fj61nf6spiln7cbvx25g42w6fypfikflv3qd8y"; }; + Arc = fetchFromGitHub { + owner = "Anuken"; + repo = "Arc"; + rev = "v${version}"; + sha256 = "0inzyj01442da7794cpxlaab7di9gv1snc97cbffqsdxgin16i7d"; + }; + soloud = fetchFromGitHub { + owner = "Anuken"; + repo = "soloud"; + # this is never pinned in upstream, see https://github.com/Anuken/Arc/issues/39 + rev = "8553049c6fb0d1eaa7f57c1793b96219c84e8ba5"; + sha256 = "076vnjs2qxd65qq5i37gbmj5v5i04a1vw0kznq986gv9190jj531"; + }; + + patches = [ + ./0001-fix-include-path-for-SDL2-on-linux.patch + # upstream fix for https://github.com/Anuken/Arc/issues/40, remove on next release + (fetchpatch { + url = "https://github.com/Anuken/Arc/commit/b2f3d212c1a88a62f140f5cb04f4c86e61332d1c.patch"; + sha256 = "1yjp4drv7lk3kinzy47g8jhb2qazr92b85vbc79vsqrs8sycskan"; + extraPrefix = "Arc/"; + stripLen = 1; + }) + # add resolveDependencies task, remove when and if it gets added upstream in a future release + (fetchpatch { + url = "https://github.com/Anuken/Mindustry/pull/4302.patch"; + sha256 = "0yp42sray4fxkajhpdljal0wss8jh9rvmclysw6cixsa94pw5khq"; + extraPrefix = "Mindustry/"; + stripLen = 1; + }) + ]; + + unpackPhase = '' + cp -r ${Mindustry} Mindustry + cp -r ${Arc} Arc + chmod -R u+w -- Mindustry Arc + cp ${stb.src}/stb_image.h Arc/arc-core/csrc/ + cp -r ${soloud} Arc/arc-core/csrc/soloud + chmod -R u+w -- Arc + ''; desktopItem = makeDesktopItem { type = "Application"; @@ -40,7 +88,9 @@ let icon = "mindustry"; }; - postPatch = '' + cleanupMindustrySrc = '' + pushd Mindustry + # Remove unbuildable iOS stuff sed -i '/^project(":ios"){/,/^}/d' build.gradle sed -i '/robo(vm|VM)/d' build.gradle @@ -48,12 +98,11 @@ let # Pin 'SNAPSHOT' versions sed -i 's/com.github.anuken:packr:-SNAPSHOT/com.github.anuken:packr:034efe51781d2d8faa90370492133241bfb0283c/' build.gradle + + popd ''; preBuild = '' - # Arc is run at build time for sprite packing, and it needs to see - # the runtime libraries - ${stdenv.lib.optionalString stdenv.isLinux "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${alsaLib}/lib"} export GRADLE_USER_HOME=$(mktemp -d) ''; @@ -63,15 +112,17 @@ let # fake build to pre-download deps into fixed-output derivation deps = stdenv.mkDerivation { pname = "${pname}-deps"; - inherit version src postPatch; + inherit version unpackPhase patches; + postPatch = cleanupMindustrySrc; + nativeBuildInputs = [ gradle_6 perl ]; - # Here we build both the server and the client so we only have to specify - # one hash for 'deps'. Deps can be garbage collected after the build, - # so this is not really an issue. - buildPhase = '' - ${preBuild} - gradle --no-daemon desktop:dist -Pbuildversion=${buildVersion} - gradle --no-daemon server:dist -Pbuildversion=${buildVersion} + # Here we download dependencies for both the server and the client so + # we only have to specify one hash for 'deps'. Deps can be garbage + # collected after the build, so this is not really an issue. + buildPhase = preBuild + '' + pushd Mindustry + gradle --no-daemon resolveDependencies + popd ''; # perl code mavenizes pathes (com.squareup.okio/okio/1.13.0/a9283170b7305c8d92d25aff02a6ab7e45d06cbe/okio-1.13.0.jar -> com/squareup/okio/okio/1.13.0/okio-1.13.0.jar) installPhase = '' @@ -81,51 +132,65 @@ let ''; outputHashAlgo = "sha256"; outputHashMode = "recursive"; - outputHash = "0vzck6hsrvs438s3ikk66qmpak88bmqcb8inqbbjwy7x87d2qsvj"; + outputHash = "09rwyrg2yv8r499b0dk1bzvymsf98d4j5b95bwd9s4xvrz71is3l"; }; - # Separate commands for building and installing the server and the client - buildClient = '' - gradle --offline --no-daemon desktop:dist -Pbuildversion=${buildVersion} - ''; - buildServer = '' - gradle --offline --no-daemon server:dist -Pbuildversion=${buildVersion} - ''; - installClient = '' - install -Dm644 desktop/build/libs/Mindustry.jar $out/share/mindustry.jar - mkdir -p $out/bin - makeWrapper ${jre}/bin/java $out/bin/mindustry \ - ${stdenv.lib.optionalString stdenv.isLinux "--prefix LD_LIBRARY_PATH : ${alsaLib}/lib"} \ - --add-flags "-jar $out/share/mindustry.jar" - install -Dm644 core/assets/icons/icon_64.png $out/share/icons/hicolor/64x64/apps/mindustry.png - install -Dm644 ${desktopItem}/share/applications/Mindustry.desktop $out/share/applications/Mindustry.desktop - ''; - installServer = '' - install -Dm644 server/build/libs/server-release.jar $out/share/mindustry-server.jar - mkdir -p $out/bin - makeWrapper ${jre}/bin/java $out/bin/mindustry-server \ - --add-flags "-jar $out/share/mindustry-server.jar" - ''; - in assert stdenv.lib.assertMsg (enableClient || enableServer) "mindustry: at least one of 'enableClient' and 'enableServer' must be true"; stdenv.mkDerivation rec { - inherit pname version src postPatch; + inherit pname version unpackPhase patches; - nativeBuildInputs = [ gradle_6 makeWrapper ]; + postPatch = '' + # ensure the prebuilt shared objects don't accidentally get shipped + rm Arc/natives/natives-desktop/libs/libarc*.so + rm Arc/backends/backend-sdl/libs/linux64/libsdl-arc*.so + '' + cleanupMindustrySrc; - buildPhase = with stdenv.lib; '' - ${preBuild} + buildInputs = [ + SDL2 + glew + alsaLib + ]; + nativeBuildInputs = [ + pkg-config + gradle_6 + makeWrapper + jdk + ant + copyDesktopItems + ]; + + desktopItems = [ desktopItem ]; + + buildPhase = with stdenv.lib; preBuild + '' # point to offline repo - sed -ie "s#mavenLocal()#mavenLocal(); maven { url '${deps}' }#g" build.gradle - ${optionalString enableClient buildClient} - ${optionalString enableServer buildServer} + sed -ie "s#mavenLocal()#mavenLocal(); maven { url '${deps}' }#g" Mindustry/build.gradle + sed -ie "s#mavenCentral()#mavenCentral(); maven { url '${deps}' }#g" Arc/build.gradle + + pushd Mindustry + '' + optionalString enableClient '' + gradle --offline --no-daemon jnigenBuild -Pbuildversion=${buildVersion} + gradle --offline --no-daemon sdlnatives -Pdynamic -Pbuildversion=${buildVersion} + patchelf ../Arc/backends/backend-sdl/libs/linux64/libsdl-arc*.so \ + --add-needed ${glew.out}/lib/libGLEW.so \ + --add-needed ${SDL2}/lib/libSDL2.so + gradle --offline --no-daemon desktop:dist -Pbuildversion=${buildVersion} + '' + optionalString enableServer '' + gradle --offline --no-daemon server:dist -Pbuildversion=${buildVersion} ''; - installPhase = with stdenv.lib; '' - ${optionalString enableClient installClient} - ${optionalString enableServer installServer} + installPhase = with stdenv.lib; optionalString enableClient '' + install -Dm644 desktop/build/libs/Mindustry.jar $out/share/mindustry.jar + mkdir -p $out/bin + makeWrapper ${jdk}/bin/java $out/bin/mindustry \ + --add-flags "-jar $out/share/mindustry.jar" + install -Dm644 core/assets/icons/icon_64.png $out/share/icons/hicolor/64x64/apps/mindustry.png + '' + optionalString enableServer '' + install -Dm644 server/build/libs/server-release.jar $out/share/mindustry-server.jar + mkdir -p $out/bin + makeWrapper ${jdk}/bin/java $out/bin/mindustry-server \ + --add-flags "-jar $out/share/mindustry-server.jar" ''; meta = with lib; { @@ -133,14 +198,10 @@ stdenv.mkDerivation rec { downloadPage = "https://github.com/Anuken/Mindustry/releases"; description = "A sandbox tower defense game"; license = licenses.gpl3Plus; - maintainers = with maintainers; [ fgaz ]; - platforms = platforms.all; + maintainers = with maintainers; [ fgaz petabyteboy ]; + platforms = platforms.x86_64; # Hash mismatch on darwin: # https://github.com/NixOS/nixpkgs/pull/105590#issuecomment-737120293 - # Problems with native libraries in aarch64: - # https://github.com/NixOS/nixpkgs/pull/107646 - # https://logs.nix.ci/?key=nixos/nixpkgs.107646&attempt_id=3032c060-72e9-4a76-8186-4739544397dd - broken = stdenv.isDarwin || - stdenv.isAarch64; + broken = stdenv.isDarwin; }; } diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 9196cad2077a..0f86f563434b 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -13361,6 +13361,10 @@ in glew110 = callPackage ../development/libraries/glew/1.10.nix { inherit (darwin.apple_sdk.frameworks) AGL OpenGL; }; + glew-egl = glew.overrideAttrs (oldAttrs: { + pname = "glew-egl"; + makeFlags = oldAttrs.makeFlags ++ [ "SYSTEM=linux-egl" ]; + }); glfw = glfw3; glfw2 = callPackage ../development/libraries/glfw/2.x.nix { }; @@ -26368,6 +26372,7 @@ in megaglest = callPackage ../games/megaglest {}; mindustry = callPackage ../games/mindustry { }; + mindustry-wayland = callPackage ../games/mindustry { glew = glew-egl; }; mindustry-server = callPackage ../games/mindustry { enableClient = false;