From 7bf0c57a579f8469b9fad9a8f2d128057cc5a2e5 Mon Sep 17 00:00:00 2001 From: qubitnano <146656568+qubitnano@users.noreply.github.com> Date: Sat, 9 Nov 2024 23:05:31 -0500 Subject: [PATCH] _2ship2harkinian: 1.0.2 -> 3.0.1 --- .../{0001-deps.patch => dont-fetch-stb.patch} | 0 pkgs/by-name/_2/_2ship2harkinian/package.nix | 141 +++++++++++------- 2 files changed, 90 insertions(+), 51 deletions(-) rename pkgs/by-name/_2/_2ship2harkinian/{0001-deps.patch => dont-fetch-stb.patch} (100%) diff --git a/pkgs/by-name/_2/_2ship2harkinian/0001-deps.patch b/pkgs/by-name/_2/_2ship2harkinian/dont-fetch-stb.patch similarity index 100% rename from pkgs/by-name/_2/_2ship2harkinian/0001-deps.patch rename to pkgs/by-name/_2/_2ship2harkinian/dont-fetch-stb.patch diff --git a/pkgs/by-name/_2/_2ship2harkinian/package.nix b/pkgs/by-name/_2/_2ship2harkinian/package.nix index 628c25666d95..074e8635fac4 100644 --- a/pkgs/by-name/_2/_2ship2harkinian/package.nix +++ b/pkgs/by-name/_2/_2ship2harkinian/package.nix @@ -1,50 +1,59 @@ { lib, + fetchFromGitHub, + applyPatches, + _2ship2harkinian, + fetchurl, + writeTextFile, stdenv, - SDL2, cmake, copyDesktopItems, - fetchFromGitHub, - fetchpatch, - fetchurl, imagemagick, - imgui, + lsb-release, + makeWrapper, + ninja, + pkg-config, + python3, + libGL, libpng, libpulseaudio, libzip, - lsb-release, - makeDesktopItem, - makeWrapper, - ninja, nlohmann_json, - pkg-config, - python3, + SDL2, spdlog, - stormlib, tinyxml-2, - writeTextFile, zenity, + bzip2, + libogg, + libopus, + libvorbis, + libX11, + opusfile, + sdl_gamecontrollerdb, + makeDesktopItem, }: let - # This would get fetched at build time otherwise, see: - # https://github.com/HarbourMasters/2ship2harkinian/blob/1.0.2/mm/CMakeLists.txt#L708 - gamecontrollerdb = fetchurl { - name = "gamecontrollerdb.txt"; - url = "https://raw.githubusercontent.com/gabomdq/SDL_GameControllerDB/b1759cf84028aab89caa1c395e198c340b8dfd89/gamecontrollerdb.txt"; - hash = "sha256-7C5EkqBIhLGNJuhi3832y0ffW5Ep7iuTYXb1bL5h2Js="; + # The following are either normally fetched during build time or a specific version is required + + dr_libs = fetchFromGitHub { + owner = "mackron"; + repo = "dr_libs"; + rev = "da35f9d6c7374a95353fd1df1d394d44ab66cf01"; + hash = "sha256-ydFhQ8LTYDBnRTuETtfWwIHZpRciWfqGsZC6SuViEn0="; }; - # 2ship needs a specific imgui version - imgui' = imgui.overrideAttrs rec { - version = "1.90.6"; + imgui' = applyPatches { src = fetchFromGitHub { owner = "ocornut"; repo = "imgui"; - tag = "v${version}-docking"; - hash = "sha256-Y8lZb1cLJF48sbuxQ3vXq6GLru/WThR78pq7LlORIzc="; + tag = "v1.91.9b-docking"; + hash = "sha256-mQOJ6jCN+7VopgZ61yzaCnt4R1QLrW7+47xxMhFRHLQ="; }; + patches = [ + "${_2ship2harkinian.src}/libultraship/cmake/dependencies/patches/imgui-fixes-and-config.patch" + ]; }; libgfxd = fetchFromGitHub { @@ -54,6 +63,13 @@ let hash = "sha256-AmHAa3/cQdh7KAMFOtz5TQpcM6FqO9SppmDpKPTjTt8="; }; + prism = fetchFromGitHub { + owner = "KiritoDv"; + repo = "prism-processor"; + rev = "bbcbc7e3f890a5806b579361e7aa0336acd547e7"; + hash = "sha256-jRPwO1Vub0cH12YMlME6kd8zGzKmcfIrIJZYpQJeOks="; + }; + stb_impl = writeTextFile { name = "stb_impl.c"; text = '' @@ -68,24 +84,17 @@ let hash = "sha256-xUsVponmofMsdeLsI6+kQuPg436JS3PBl00IZ5sg3Vw="; }; - # Apply 2ship's patch for stormlib - stormlib' = stormlib.overrideAttrs (prev: rec { - version = "9.25"; + stormlib' = applyPatches { src = fetchFromGitHub { owner = "ladislav-zezula"; repo = "StormLib"; - tag = "v${version}"; + tag = "v9.25"; hash = "sha256-HTi2FKzKCbRaP13XERUmHkJgw8IfKaRJvsK3+YxFFdc="; }; - nativeBuildInputs = prev.nativeBuildInputs ++ [ pkg-config ]; - patches = (prev.patches or [ ]) ++ [ - (fetchpatch { - name = "stormlib-optimizations.patch"; - url = "https://github.com/briaguya-ai/StormLib/commit/ff338b230544f8b2bb68d2fbe075175ed2fd758c.patch"; - hash = "sha256-Jbnsu5E6PkBifcx/yULMVC//ab7tszYgktS09Azs5+4="; - }) + patches = [ + "${_2ship2harkinian.src}/libultraship/cmake/dependencies/patches/stormlib-optimizations.patch" ]; - }); + }; thread_pool = fetchFromGitHub { owner = "bshoshany"; @@ -97,19 +106,27 @@ let in stdenv.mkDerivation (finalAttrs: { pname = "2ship2harkinian"; - version = "1.0.2"; + version = "3.0.1"; src = fetchFromGitHub { owner = "HarbourMasters"; repo = "2ship2harkinian"; tag = finalAttrs.version; - hash = "sha256-1iSFzroKxwFpsIGNMetSlQKTKRWCy7QtgCTepFdSeY8="; + hash = "sha256-EC8o5FIP/eXa+0LZt0C8EWHzKVAniv9SIXkZdbibcxg="; fetchSubmodules = true; + deepClone = true; + postFetch = '' + cd $out + git branch --show-current > GIT_BRANCH + git rev-parse --short=7 HEAD > GIT_COMMIT_HASH + (git describe --tags --abbrev=0 --exact-match HEAD 2>/dev/null || echo "") > GIT_COMMIT_TAG + rm -rf .git + ''; }; patches = [ # remove fetching stb as we will patch our own - ./0001-deps.patch + ./dont-fetch-stb.patch ]; nativeBuildInputs = [ @@ -124,14 +141,19 @@ stdenv.mkDerivation (finalAttrs: { ]; buildInputs = [ - SDL2 - imgui' + bzip2 + libGL + libogg + (lib.getDev libopus) libpng libpulseaudio + libvorbis + libX11 libzip nlohmann_json + (lib.getDev opusfile) + SDL2 spdlog - stormlib' tinyxml-2 zenity ]; @@ -139,34 +161,44 @@ stdenv.mkDerivation (finalAttrs: { cmakeFlags = [ (lib.cmakeBool "NON_PORTABLE" true) (lib.cmakeFeature "CMAKE_INSTALL_PREFIX" "${placeholder "out"}/2s2h") - (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_IMGUI" "${imgui'.src}") + (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_DR_LIBS" "${dr_libs}") + (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_IMGUI" "${imgui'}") (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_LIBGFXD" "${libgfxd}") + (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_PRISM" "${prism}") (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_STORMLIB" "${stormlib'}") (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_THREADPOOL" "${thread_pool}") + (lib.cmakeFeature "OPUS_INCLUDE_DIR" "${lib.getDev libopus}/include/opus") + (lib.cmakeFeature "OPUSFILE_INCLUDE_DIR" "${lib.getDev opusfile}/include/opus") ]; + strictDeps = true; + dontAddPrefix = true; # Linking fails without this hardeningDisable = [ "format" ]; - # Pie needs to be enabled or else it segfaults - hardeningEnable = [ "pie" ]; - preConfigure = '' # mirror 2ship's stb mkdir stb cp ${stb'} ./stb/${stb'.name} cp ${stb_impl} ./stb/${stb_impl.name} - substituteInPlace libultraship/cmake/dependencies/common.cmake \ - --replace-fail "\''${STB_DIR}" "/build/source/stb" + --replace-fail "\''${STB_DIR}" "$(readlink -f ./stb)" + ''; + + postPatch = '' + substituteInPlace mm/src/boot/build.c.in \ + --replace-fail "@CMAKE_PROJECT_GIT_BRANCH@" "$(cat GIT_BRANCH)" \ + --replace-fail "@CMAKE_PROJECT_GIT_COMMIT_HASH@" "$(cat GIT_COMMIT_HASH)" \ + --replace-fail "@CMAKE_PROJECT_GIT_COMMIT_TAG@" "$(cat GIT_COMMIT_TAG)" ''; postBuild = '' - cp ${gamecontrollerdb} ${gamecontrollerdb.name} + port_ver=$(grep CMAKE_PROJECT_VERSION: "$PWD/CMakeCache.txt" | cut -d= -f2) + cp ${sdl_gamecontrollerdb}/share/gamecontrollerdb.txt gamecontrollerdb.txt pushd ../OTRExporter - python3 ./extract_assets.py -z ../build/ZAPD/ZAPD.out --norom --xml-root ../mm/assets/xml --custom-assets-path ../mm/assets/custom --custom-otr-file 2ship.o2r --port-ver ${finalAttrs.version} + python3 ./extract_assets.py -z ../build/ZAPD/ZAPD.out --norom --xml-root ../mm/assets/xml --custom-assets-path ../mm/assets/custom --custom-otr-file 2ship.o2r --port-ver $port_ver popd ''; @@ -179,6 +211,13 @@ stdenv.mkDerivation (finalAttrs: { mkdir -p $out/bin ln -s $out/2s2h/2s2h.elf $out/bin/2s2h install -Dm644 ../mm/linux/2s2hIcon.png $out/share/pixmaps/2s2h.png + + install -Dm644 -t $out/share/licenses/2ship2harkinian ../LICENSE + install -Dm644 -t $out/share/licenses/2ship2harkinian/OTRExporter ../OTRExporter/LICENSE + install -Dm644 -t $out/share/licenses/2ship2harkinian/ZAPDTR ../ZAPDTR/LICENSE + install -Dm644 -t $out/share/licenses/2ship2harkinian/libgfxd ${libgfxd}/LICENSE + install -Dm644 -t $out/share/licenses/2ship2harkinian/libultraship ../libultraship/LICENSE + install -Dm644 -t $out/share/licenses/2ship2harkinian/thread_pool ${thread_pool}/LICENSE.txt ''; postFixup = '' @@ -204,7 +243,7 @@ stdenv.mkDerivation (finalAttrs: { platforms = [ "x86_64-linux" ]; maintainers = with lib.maintainers; [ qubitnano ]; license = with lib.licenses; [ - # OTRExporter, OTRGui, ZAPDTR, libultraship + # OTRExporter, ZAPDTR, libultraship, libgfxd, thread_pool mit # 2 Ship 2 Harkinian cc0