Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Cosima Neidahl <opna2608@protonmail.com>

add patchfile and multiarch function
  • Loading branch information
Redhawk18 committed Oct 21, 2024
1 parent bf2c280 commit 8448bf4
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 13 deletions.
29 changes: 29 additions & 0 deletions pkgs/by-name/ed/edopro/ocgcore-lua-symbols.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
From 41e750142b44465f3af197b7e2f0d6f54fc48c2d Mon Sep 17 00:00:00 2001
From: OPNA2608 <opna2608@protonmail.com>
Date: Mon, 21 Oct 2024 17:42:24 +0200
Subject: [PATCH] Mark Lua symbols as C symbols

Otherwise linking against our Lua built by a C-compiler fails due to the symbols being resolved as C++ symbols.
---
interpreter.h | 2 ++
1 file changed, 2 insertions(+)

diff --git a/interpreter.h b/interpreter.h
index 6c405a1..c471ecb 100644
--- a/interpreter.h
+++ b/interpreter.h
@@ -9,9 +9,11 @@
#define INTERPRETER_H_

// Due to longjmp behaviour, we must build Lua as C++ to avoid UB
+extern "C" {
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
+}

#include "common.h"
#include <unordered_map>
--
2.44.1

47 changes: 34 additions & 13 deletions pkgs/by-name/ed/edopro/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
bzip2,
curl,
flac,
# Use fmt 10+ after release 40.1.4+
fmt_9,
freetype,
libevent,
Expand Down Expand Up @@ -40,6 +41,14 @@
pics_url ? "https://images.ygoprodeck.com/images/cards/{}.jpg",
}:
let
archLabel =
{
"x86_64-linux" = "x64";
"aarch64-linux" = "arm64";
}
.${stdenv.hostPlatform.system}
or (throw "Don't know how to translate ${stdenv.hostPlatform.system} into an arch label for edopro");

deps = import ./deps.nix;
in
let
Expand Down Expand Up @@ -104,19 +113,24 @@ let
fetchSubmodules = true;
};

patches = [
./ocgcore-lua-symbols.patch
];

nativeBuildInputs = [ premake5 ];

buildInputs = [ lua5_3 ];

preBuild = ''
premake5 gmake2
premake5 gmake2 \
--lua-path="${lua5_3}"
'';

enableParallelBuilding = true;
buildFlags = [
"verbose=true"
"config=release"
"ocgcore"
"ocgcoreshared"
];
makeFlags = [
"-C"
Expand All @@ -126,14 +140,13 @@ let
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp bin/release/libocgcore.a $out/bin
install -Dm644 -t $out/lib bin/release/libocgcore${stdenv.hostPlatform.extensions.sharedLibrary}
runHook postInstall
'';
};

edopro = stdenv.mkDerivation rec {
edopro = stdenv.mkDerivation {
pname = "edopro";
version = deps.edopro-version;

Expand All @@ -159,7 +172,9 @@ let
libjpeg
libpng
libvorbis
lua5_3
nlohmann_json
ocgcore
openal
SDL2
sqlite
Expand All @@ -173,23 +188,25 @@ let

preBuild = ''
premake5 gmake2 \
--architecture=${archLabel} \
--covers=\"${covers_url}\" \
--fields=\"${fields_url}\" \
--no-core \
--pics=\"${pics_url}\" \
--prebuilt-core="${ocgcore}/bin" \
--prebuilt-core="${lib.getLib ocgcore}/lib" \
--sound=sfml
'';

enableParallelBuilding = true;
env = {
# remove after release 40.1.4+
# https://discord.com/channels/170601678658076672/792223685112889344/1286043823293599785
CXXFLAGS = "-include cstdint";
LDFLAGS = "-I ${irrlicht-edopro}/include -L ${irrlicht-edopro}/bin";
};
buildFlags = [
"verbose=true"
"config=release_x64"
"ygoprodll"
"config=release_${archLabel}"
"ygopro"
];
makeFlags = [
"-C"
Expand All @@ -200,7 +217,7 @@ let
runHook preInstall
mkdir -p $out/bin
cp bin/x64/release/ygoprodll $out/bin
cp bin/${archLabel}/release/ygopro $out/bin
runHook postInstall
'';
Expand All @@ -226,7 +243,7 @@ let
"WindBot"
];
in
writeShellScriptBin "EDOPro" ''
writeShellScriptBin "edopro" ''
set -eu
EDOPRO_DIR="''${XDG_DATA_HOME:-$HOME/.local/share}/edopro"
Expand All @@ -251,7 +268,7 @@ let
]
}';
exec ${edopro}/bin/ygoprodll -C $EDOPRO_DIR $@
exec ${edopro}/bin/ygopro -C $EDOPRO_DIR $@
'';

edopro-desktop = runCommandLocal "io.github.edo9300.EDOPro.desktop" { } ''
Expand Down Expand Up @@ -289,11 +306,15 @@ symlinkJoin {
changelog = "https://github.com/edo9300/edopro/releases";
license = lib.licenses.agpl3Plus;
maintainers = with lib.maintainers; [
OPNA2608
redhawk
];
mainProgram = "edopro";
# This is likely a very easy app to port if you're interested.
# We just have no way to test on other platforms.
platforms = [ "x86_64-linux" ];
platforms = [
"x86_64-linux"
"aarch64-linux"
];
};
}

0 comments on commit 8448bf4

Please sign in to comment.