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

Add precompiled StormLib for Linux #84

Merged
Merged
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
Binary file not shown.
8 changes: 7 additions & 1 deletion src/richchk/mpq/stormlib/stormlib_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class StormLibFinder:
_MAC_STORM_INTEL = os.path.join(_SCRIPT_PATH, "dlls/macos/libStorm.dylib")
_MAC_STORM_M1 = os.path.join(_SCRIPT_PATH, "dlls/macos/libstorm.9.22.0.dylib")
_WINDOWS_STORM = os.path.join(_SCRIPT_PATH, "dlls/windows/Storm.dll")
_LINUX_STORM_X86_64 = os.path.join(_SCRIPT_PATH, "dlls/linux/libstorm.so.9.22.0")

@classmethod
def find_stormlib(
Expand All @@ -29,7 +30,7 @@ def find_stormlib(
else:
cls._LOG.warning(
"No path to a StormLib DLL was provided, "
"attempting to use precompiled DLL for Windows and macOS. "
"attempting to use precompiled DLL for Windows, macOS and Linux. "
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work for every flavor of 64-bit Linux? Ubuntu, centos, Debian, etc.?

How was this DLL compiled? Did you compile it? Or where did it come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should work.

The library was compiled by myself. I am using Debian 12.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for letting me know! Only thing I would add, could you provide the instructions you did to compile the StormLib DLL on your system? Either in the PR request or a link to something, etc. Wanting to make sure it can be repeated. E.g. for macOS StormLib, Homebrew builds it: https://formulae.brew.sh/formula/stormlib

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The instructions are described in the StormLib repository: https://github.com/ladislav-zezula/StormLib?tab=readme-ov-file#linux. One thing I added the BUILD_SHARED_LIBS=True flag to cmake.

git clone https://github.com/ladislav-zezula/StormLib.git
mkdir StormLib/build && cd StormLib/build
cmake ../CMakeLists.txt -D BUILD_SHARED_LIBS=True
make

and in the build folder will be compiled library libstorm.so.9.22.0

"Future compatibility is not guaranteed; "
"please provide a path to StormLib DLL compiled for your platform."
)
Expand All @@ -42,6 +43,11 @@ def find_stormlib(
return StormLibFilePath(_path_to_stormlib_dll=cls._MAC_STORM_M1)
elif platform.system().lower() == "darwin":
return StormLibFilePath(_path_to_stormlib_dll=cls._MAC_STORM_INTEL)
elif (
platform.system().lower() == "linux"
and platform.machine().lower() == "x86_64"
):
return StormLibFilePath(_path_to_stormlib_dll=cls._LINUX_STORM_X86_64)
else:
msg = (
f"Unsupported platform for precompiled StormLib DLL. "
Expand Down
1 change: 1 addition & 0 deletions src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
_PACKAGE_DATA["richchk"] = [
"mpq/stormlib/dlls/macos/*.*",
"mpq/stormlib/dlls/windows/*.*",
"mpq/stormlib/dlls/linux/*.*",
]

setup(
Expand Down
4 changes: 4 additions & 0 deletions test/chk_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ def _extract_chk_section_name_from_file_path(file_path: str) -> str:
Path.joinpath(_RESOURCES_DIR_PATH, "stormlib/macos/libstorm.9.22.0.dylib")
).absolute()

LINUX_STORMLIB_X86_64 = Path(
Path.joinpath(_RESOURCES_DIR_PATH, "stormlib/linux/libstorm.so.9.22.0")
).absolute()

EXAMPLE_STARCRAFT_SCX_MAP = Path(
Path.joinpath(_RESOURCES_DIR_PATH, "stormlib/example-stacraft-map.scx")
).absolute()
Expand Down
6 changes: 6 additions & 0 deletions test/helpers/stormlib_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ def run_test_if_mac_m1() -> bool:
return (
platform.system().lower() == "darwin" and platform.machine().lower() == "arm64"
)


def run_test_if_linux_x86_64() -> bool:
return (
platform.system().lower() == "linux" and platform.machine().lower() == "x86_64"
)
16 changes: 14 additions & 2 deletions test/mpq/stormlib/search/stormlib_file_searcher_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
from richchk.mpq.stormlib.stormlib_loader import StormLibLoader
from richchk.mpq.stormlib.stormlib_wrapper import StormLibWrapper

from ....chk_resources import COMPLEX_STARCRAFT_SCX_MAP, MACOS_STORMLIB_M1
from ....helpers.stormlib_helper import run_test_if_mac_m1
from ....chk_resources import (
COMPLEX_STARCRAFT_SCX_MAP,
LINUX_STORMLIB_X86_64,
MACOS_STORMLIB_M1,
)
from ....helpers.stormlib_helper import run_test_if_linux_x86_64, run_test_if_mac_m1

# the canonical place the CHK is stored in a SCX/SCM map file
_CHK_MPQ_PATH = "staredit\\scenario.chk"
Expand All @@ -36,6 +40,14 @@ def stormlib_wrapper():
)
)
)
elif run_test_if_linux_x86_64():
return StormLibWrapper(
StormLibLoader.load_stormlib(
path_to_stormlib=StormLibFilePath(
_path_to_stormlib_dll=LINUX_STORMLIB_X86_64
)
)
)


def _read_file_as_bytes(infile: str) -> bytes:
Expand Down
14 changes: 13 additions & 1 deletion test/mpq/stormlib/stormlib_finder_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,20 @@ def test_it_finds_precompiled_macos_intel_dll_if_no_path_provided():
assert path_to_stormlib.path_to_stormlib_dll.endswith("libStorm.dylib")


def test_it_finds_precompiled_linux_dll_if_no_path_provided():
with (
patch("platform.system") as mock_platform_system,
patch("platform.machine") as mock_cpu,
):
mock_platform_system.return_value = "Linux"
mock_cpu.return_value = "x86_64"
path_to_stormlib = StormLibFinder.find_stormlib()
assert os.path.join(path_to_stormlib.path_to_stormlib_dll)
assert path_to_stormlib.path_to_stormlib_dll.endswith("libstorm.so.9.22.0")


def test_it_throws_if_unrecognized_operating_system():
with patch("platform.system") as mock_platform_system:
mock_platform_system.return_value = "Linux"
mock_platform_system.return_value = "iOS"
with pytest.raises(OSError):
StormLibFinder.find_stormlib()
16 changes: 14 additions & 2 deletions test/mpq/stormlib/stormlib_wrapper_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
from richchk.mpq.stormlib.stormlib_loader import StormLibLoader
from richchk.mpq.stormlib.stormlib_wrapper import StormLibWrapper

from ...chk_resources import EXAMPLE_STARCRAFT_SCX_MAP, MACOS_STORMLIB_M1
from ...helpers.stormlib_helper import run_test_if_mac_m1
from ...chk_resources import (
EXAMPLE_STARCRAFT_SCX_MAP,
LINUX_STORMLIB_X86_64,
MACOS_STORMLIB_M1,
)
from ...helpers.stormlib_helper import run_test_if_linux_x86_64, run_test_if_mac_m1

# the canonical place the CHK is stored in a SCX/SCM map file
_CHK_MPQ_PATH = "staredit\\scenario.chk"
Expand All @@ -29,6 +33,14 @@ def stormlib_wrapper():
)
)
)
elif run_test_if_linux_x86_64():
return StormLibWrapper(
StormLibLoader.load_stormlib(
path_to_stormlib=StormLibFilePath(
_path_to_stormlib_dll=LINUX_STORMLIB_X86_64
)
)
)


def _read_file_as_bytes(infile: str) -> bytes:
Expand Down
Binary file added test/resources/stormlib/linux/libstorm.so.9.22.0
Binary file not shown.
Loading