diff --git a/pkgs/by-name/_2/_2ship2harkinian/darwin-fixes.patch b/pkgs/by-name/_2/_2ship2harkinian/darwin-fixes.patch new file mode 100644 index 000000000000..e2663fcf3e0f --- /dev/null +++ b/pkgs/by-name/_2/_2ship2harkinian/darwin-fixes.patch @@ -0,0 +1,37 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index e3c1ac7..e7884d1 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -223,17 +223,13 @@ endif() + if(CMAKE_SYSTEM_NAME MATCHES "Darwin") + add_custom_target(CreateOSXIcons + COMMAND mkdir -p ${CMAKE_BINARY_DIR}/macosx/2s2h.iconset +- COMMAND sips -z 16 16 mm/macosx/2s2hIcon.png --out ${CMAKE_BINARY_DIR}/macosx/2s2h.iconset/icon_16x16.png +- COMMAND sips -z 32 32 mm/macosx/2s2hIcon.png --out ${CMAKE_BINARY_DIR}/macosx/2s2h.iconset/icon_16x16@2x.png +- COMMAND sips -z 32 32 mm/macosx/2s2hIcon.png --out ${CMAKE_BINARY_DIR}/macosx/2s2h.iconset/icon_32x32.png +- COMMAND sips -z 64 64 mm/macosx/2s2hIcon.png --out ${CMAKE_BINARY_DIR}/macosx/2s2h.iconset/icon_32x32@2x.png +- COMMAND sips -z 128 128 mm/macosx/2s2hIcon.png --out ${CMAKE_BINARY_DIR}/macosx/2s2h.iconset/icon_128x128.png +- COMMAND sips -z 256 256 mm/macosx/2s2hIcon.png --out ${CMAKE_BINARY_DIR}/macosx/2s2h.iconset/icon_128x128@2x.png +- COMMAND sips -z 256 256 mm/macosx/2s2hIcon.png --out ${CMAKE_BINARY_DIR}/macosx/2s2h.iconset/icon_256x256.png +- COMMAND sips -z 512 512 mm/macosx/2s2hIcon.png --out ${CMAKE_BINARY_DIR}/macosx/2s2h.iconset/icon_256x256@2x.png +- COMMAND sips -z 512 512 mm/macosx/2s2hIcon.png --out ${CMAKE_BINARY_DIR}/macosx/2s2h.iconset/icon_512x512.png +- COMMAND cp mm/macosx/2s2hIcon.png ${CMAKE_BINARY_DIR}/macosx/2s2h.iconset/icon_512x512@2x.png +- COMMAND iconutil -c icns -o ${CMAKE_BINARY_DIR}/macosx/2s2h.icns ${CMAKE_BINARY_DIR}/macosx/2s2h.iconset ++ COMMAND convert ${CMAKE_SOURCE_DIR}/mm/macosx/2s2hIcon.png -resize 16x16 ${CMAKE_BINARY_DIR}/macosx/2s2h.iconset/icon_16.png ++ COMMAND convert ${CMAKE_SOURCE_DIR}/mm/macosx/2s2hIcon.png -resize 32x32 ${CMAKE_BINARY_DIR}/macosx/2s2h.iconset/icon_32.png ++ COMMAND convert ${CMAKE_SOURCE_DIR}/mm/macosx/2s2hIcon.png -resize 64x64 ${CMAKE_BINARY_DIR}/macosx/2s2h.iconset/icon_64.png ++ COMMAND convert ${CMAKE_SOURCE_DIR}/mm/macosx/2s2hIcon.png -resize 128x128 ${CMAKE_BINARY_DIR}/macosx/2s2h.iconset/icon_128.png ++ COMMAND convert ${CMAKE_SOURCE_DIR}/mm/macosx/2s2hIcon.png -resize 256x256 ${CMAKE_BINARY_DIR}/macosx/2s2h.iconset/icon_256.png ++ COMMAND convert ${CMAKE_SOURCE_DIR}/mm/macosx/2s2hIcon.png -resize 512x512 ${CMAKE_BINARY_DIR}/macosx/2s2h.iconset/icon_512.png ++ COMMAND png2icns ${CMAKE_BINARY_DIR}/macosx/2s2h.icns ${CMAKE_BINARY_DIR}/macosx/2s2h.iconset/icon_{16,32,64,128,256,512}.png + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMENT "Creating OSX icons ..." + ) +@@ -250,7 +246,6 @@ install(DIRECTORY "${CMAKE_SOURCE_DIR}/mm/assets/xml/" DESTINATION ./assets/xml) + INSTALL(CODE "FILE(RENAME \${CMAKE_INSTALL_PREFIX}/../MacOS/2s2h-macos \${CMAKE_INSTALL_PREFIX}/../MacOS/2s2h)") + install(CODE " + include(BundleUtilities) +- fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/../MacOS/2s2h\" \"\" \"${dirs}\") + ") + + endif() diff --git a/pkgs/by-name/_2/_2ship2harkinian/package.nix b/pkgs/by-name/_2/_2ship2harkinian/package.nix index ecca7747c8ff..ed77e1b5e6ab 100644 --- a/pkgs/by-name/_2/_2ship2harkinian/package.nix +++ b/pkgs/by-name/_2/_2ship2harkinian/package.nix @@ -31,6 +31,10 @@ opusfile, sdl_gamecontrollerdb, makeDesktopItem, + darwin, + glew, + libicns, + fixDarwinDylibNames, }: let @@ -103,6 +107,13 @@ let hash = "sha256-zhRFEmPYNFLqQCfvdAaG5VBNle9Qm8FepIIIrT9sh88="; }; + metalcpp = fetchFromGitHub { + owner = "briaguya-ai"; + repo = "single-header-metal-cpp"; + tag = "macOS13_iOS16"; + hash = "sha256-CSYIpmq478bla2xoPL/cGYKIWAeiORxyFFZr0+ixd7I"; + }; + in stdenv.mkDerivation (finalAttrs: { pname = "2ship2harkinian"; @@ -125,37 +136,50 @@ stdenv.mkDerivation (finalAttrs: { }; patches = [ + ./darwin-fixes.patch # remove fetching stb as we will patch our own ./dont-fetch-stb.patch ]; nativeBuildInputs = [ cmake - copyDesktopItems imagemagick - lsb-release makeWrapper ninja pkg-config python3 + ] + ++ lib.optionals stdenv.hostPlatform.isLinux [ + copyDesktopItems + lsb-release + ] + ++ lib.optionals stdenv.hostPlatform.isDarwin [ + darwin.sigtool + fixDarwinDylibNames + libicns ]; buildInputs = [ bzip2 - libGL libogg (lib.getDev libopus) libpng - libpulseaudio libvorbis - libx11 libzip nlohmann_json (lib.getDev opusfile) SDL2 spdlog tinyxml-2 + ] + ++ lib.optionals stdenv.hostPlatform.isLinux [ + libGL + libpulseaudio + libx11 zenity + ] + ++ lib.optionals stdenv.hostPlatform.isDarwin [ + glew ]; cmakeFlags = [ @@ -169,8 +193,14 @@ stdenv.mkDerivation (finalAttrs: { (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") + ] + ++ lib.optionals stdenv.hostPlatform.isDarwin [ + (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_METALCPP" "${metalcpp}") + (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_SPDLOG" "${spdlog}") ]; + env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.hostPlatform.isDarwin "-Wno-int-conversion -Wno-implicit-int -Wno-elaborated-enum-base"; + strictDeps = true; __structuredAttrs = true; enableParallelBuilding = true; @@ -209,24 +239,51 @@ stdenv.mkDerivation (finalAttrs: { cp ../OTRExporter/2ship.o2r mm/ ''; - postInstall = '' - mkdir -p $out/bin - ln -s $out/2s2h/2s2h.elf $out/bin/2s2h - install -Dm644 ../mm/linux/2s2hIcon.png $out/share/icons/hicolor/512x512/apps/2s2h.png + postInstall = + lib.optionalString stdenv.hostPlatform.isLinux '' + mkdir -p $out/bin + ln -s $out/2s2h/2s2h.elf $out/bin/2s2h + install -Dm644 ../mm/linux/2s2hIcon.png $out/share/icons/hicolor/512x512/apps/2s2h.png + '' + + lib.optionalString stdenv.hostPlatform.isDarwin '' + # Recreate the macOS bundle (without using cpack) + # We mirror the structure of the bundle distributed by the project - 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 - ''; + mkdir -p $out/Applications/2s2h.app/Contents + cp $src/mm/macosx/Info.plist.in $out/Applications/2s2h.app/Contents/Info.plist + substituteInPlace $out/Applications/2s2h.app/Contents/Info.plist \ + --replace-fail "@CMAKE_PROJECT_VERSION@" "${finalAttrs.version}" - postFixup = '' + mv $out/MacOS $out/Applications/2s2h.app/Contents/MacOS + + # "2s2h" contains all resources that are in "Resources" in the official bundle. + # We move them to the right place and symlink them back to $out/2s2h, + # as that's where the game expects them. + mv $out/Resources $out/Applications/2s2h.app/Contents/Resources + mv $out/2s2h/* $out/Applications/2s2h.app/Contents/Resources + rm -rf $out/2s2h + ln -s $out/Applications/2s2h.app/Contents/Resources $out/2s2h + + # Copy icons + cp -r ../build/macosx/2s2h.icns $out/Applications/2s2h.app/Contents/Resources/2s2h.icns + + # Codesign (ad-hoc) + codesign -f -s - $out/Applications/2s2h.app/Contents/MacOS/2s2h + '' + + '' + 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 + ''; + + fixupPhase = lib.optionalString stdenv.hostPlatform.isLinux '' wrapProgram $out/2s2h/2s2h.elf --prefix PATH ":" ${lib.makeBinPath [ zenity ]} ''; - desktopItems = [ + desktopItems = lib.optionals stdenv.hostPlatform.isLinux [ (makeDesktopItem { name = "2s2h"; icon = "2s2h"; @@ -242,8 +299,11 @@ stdenv.mkDerivation (finalAttrs: { homepage = "https://github.com/HarbourMasters/2ship2harkinian"; description = "PC port of Majora's Mask with modern controls, widescreen, high-resolution, and more"; mainProgram = "2s2h"; - platforms = [ "x86_64-linux" ]; - maintainers = with lib.maintainers; [ qubitnano ]; + platforms = lib.platforms.linux ++ lib.platforms.darwin; + maintainers = with lib.maintainers; [ + qubitnano + matteopacini + ]; license = with lib.licenses; [ # OTRExporter, ZAPDTR, libultraship, libgfxd, thread_pool mit