Skip to content

Commit

Permalink
ja2-stracciatella: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
TomaSajt committed Nov 1, 2024
1 parent 27bc680 commit 9127fee
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 125 deletions.
98 changes: 49 additions & 49 deletions pkgs/games/ja2-stracciatella/default.nix
Original file line number Diff line number Diff line change
@@ -1,86 +1,86 @@
{
stdenv,
lib,
stdenv,
fetchurl,
fetchFromGitHub,

cmake,
python3,
rustPlatform,
cargo,
rustc,

SDL2,
fltk,
rapidjson,
gtest,
Carbon,
Cocoa,
}:

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";
hash = "sha256-0li4o8KutJjpJdviqqqhMvNqhNVBw4L98DIJtebb2VQ=";
};
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
'';
};
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;
patches = [
# only relevant for darwin
./dont-use-vendored-sdl2.patch
];

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

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

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

patches = [
./remove-rust-buildstep.patch
buildInputs = [
SDL2
fltk
rapidjson
gtest
];

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
cargoRoot = "rust";

# Patch dependencies that are usually loaded by url
substituteInPlace dependencies/lib-string_theory/builder/CMakeLists.txt.in \
--replace ${stringTheoryUrl} file://${stringTheory}
cargoDeps = rustPlatform.fetchCargoTarball {
inherit pname version src;
sourceRoot = "${src.name}/${cargoRoot}";
hash = "sha256-zkctR16QIjCTiDmrhFqPPOThbPwsm0T0nlnCekkXNN8=";
};

cmakeFlagsArray+=("-DLOCAL_RAPIDJSON_LIB=OFF" "-DLOCAL_GTEST_LIB=OFF" "-DEXTRA_DATA_DIR=$out/share/ja2")
'';
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 @@ -34599,9 +34599,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

0 comments on commit 9127fee

Please sign in to comment.