Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ja2-stracciatella: refactor #353027

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 62 additions & 37 deletions pkgs/games/ja2-stracciatella/default.nix
Original file line number Diff line number Diff line change
@@ -1,61 +1,86 @@
{ stdenv, lib, fetchurl, fetchFromGitHub, cmake, python3, rustPlatform, SDL2, fltk, rapidjson, gtest, Carbon, Cocoa }:
{
lib,
stdenv,
fetchurl,
fetchFromGitHub,

cmake,
python3,
rustPlatform,
cargo,
rustc,

SDL2,
fltk,
rapidjson,
gtest,
}:

let
stringTheory = fetchurl {
url = "https://github.com/zrax/string_theory/archive/3.1.tar.gz";
hash = "sha256-gexVFxGpkmCMQrpCJQ/g2BsCpsCsUTSaD1X0PacRmLo=";
};
in
stdenv.mkDerivation rec {
pname = "ja2-stracciatella";
version = "0.17.0";

src = fetchFromGitHub {
owner = "ja2-stracciatella";
repo = "ja2-stracciatella";
rev = "v${version}";
sha256 = "0m6rvgkba29jy3yq5hs1sn26mwrjl6mamqnv4plrid5fqaivhn6j";
};
libstracciatella = rustPlatform.buildRustPackage {
pname = "libstracciatella";
inherit version;
src = "${src}/rust";
cargoHash = "sha256-asUt+wUpwwDvSyuNZds6yMC4Ef4D8woMYWamzcJJiy4=";

preBuild = ''
mkdir -p $out/include/stracciatella
export HEADER_LOCATION=$out/include/stracciatella/stracciatella.h
'';
hash = "sha256-0li4o8KutJjpJdviqqqhMvNqhNVBw4L98DIJtebb2VQ=";
};
stringTheoryUrl = "https://github.com/zrax/string_theory/archive/3.1.tar.gz";
stringTheory = fetchurl {
url = stringTheoryUrl;
sha256 = "1flq26kkvx2m1yd38ldcq2k046yqw07jahms8a6614m924bmbv41";
};
in
stdenv.mkDerivation {
pname = "ja2-stracciatella";
inherit src version;

nativeBuildInputs = [ cmake python3 ];
buildInputs = [ SDL2 fltk rapidjson gtest ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ Carbon Cocoa ];

patches = [
./remove-rust-buildstep.patch
# only relevant for darwin
./dont-use-vendored-sdl2.patch
];

preConfigure = ''
# Use rust library built with nix
substituteInPlace CMakeLists.txt \
--replace lib/libstracciatella_c_api.a ${libstracciatella}/lib/libstracciatella_c_api.a \
--replace include/stracciatella ${libstracciatella}/include/stracciatella \
--replace bin/ja2-resource-pack ${libstracciatella}/bin/ja2-resource-pack

postPatch = ''
# Patch dependencies that are usually loaded by url
substituteInPlace dependencies/lib-string_theory/builder/CMakeLists.txt.in \
--replace ${stringTheoryUrl} file://${stringTheory}

cmakeFlagsArray+=("-DLOCAL_RAPIDJSON_LIB=OFF" "-DLOCAL_GTEST_LIB=OFF" "-DEXTRA_DATA_DIR=$out/share/ja2")
--replace-fail ${stringTheory.url} file://${stringTheory}
'';

nativeBuildInputs = [
cmake
python3
rustPlatform.cargoSetupHook
cargo
rustc
];

buildInputs = [
SDL2
fltk
rapidjson
gtest
];

cargoRoot = "rust";

cargoDeps = rustPlatform.fetchCargoTarball {
inherit pname version src;
sourceRoot = "${src.name}/${cargoRoot}";
hash = "sha256-zkctR16QIjCTiDmrhFqPPOThbPwsm0T0nlnCekkXNN8=";
};

cmakeFlags = [
(lib.cmakeBool "LOCAL_RAPIDJSON_LIB" false)
(lib.cmakeBool "LOCAL_GTEST_LIB" false)
(lib.cmakeFeature "EXTRA_DATA_DIR" "${placeholder "out"}/share/ja2")
];

# error: 'uint64_t' does not name a type
# gcc13 and above don't automatically include cstdint
env.CXXFLAGS = "-include cstdint";

doInstallCheck = true;

installCheckPhase = ''
HOME=/tmp $out/bin/ja2 -unittests
HOME=$(mktemp -d) $out/bin/ja2 -unittests
'';

meta = {
Expand Down
17 changes: 17 additions & 0 deletions pkgs/games/ja2-stracciatella/dont-use-vendored-sdl2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e4e5547af..a3017d197 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -428,12 +425,6 @@ if (MINGW)
install(SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/install-dlls-mingw.cmake")
endif()

-if(APPLE)
- file(GLOB APPLE_DIST_FILES "${CMAKE_CURRENT_SOURCE_DIR}/assets/distr-files-mac/*.txt")
- install(FILES ${APPLE_DIST_FILES} DESTINATION .)
- install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/lib-SDL2-2.0.8-macos/SDL2.framework DESTINATION .)
-endif()
-
## Uninstall

add_custom_templated_target("uninstall")
73 changes: 0 additions & 73 deletions pkgs/games/ja2-stracciatella/remove-rust-buildstep.patch

This file was deleted.

4 changes: 1 addition & 3 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34450,9 +34450,7 @@ with pkgs;

ivan = callPackage ../games/ivan { };

ja2-stracciatella = callPackage ../games/ja2-stracciatella {
inherit (darwin.apple_sdk.frameworks) Carbon Cocoa;
};
ja2-stracciatella = callPackage ../games/ja2-stracciatella { };

jfsw = callPackage ../games/jfsw { };

Expand Down