Skip to content

Commit c3132bb

Browse files
committed
Attempt at supporting zlib on windows
1 parent e0ba107 commit c3132bb

3 files changed

Lines changed: 48 additions & 12 deletions

File tree

patches/unzip_windows.patch

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
diff --git a/libgambatte/src/file/unzip/crypt.h b/libgambatte/src/file/unzip/crypt.h
2+
index 7d8597c2..fa890c1b 100644
3+
--- a/libgambatte/src/file/unzip/crypt.h
4+
+++ b/libgambatte/src/file/unzip/crypt.h
5+
@@ -27,6 +27,12 @@
6+
Encryption is not supported.
7+
*/
8+
9+
+#ifdef _MSC_VER
10+
+#ifndef __attribute__
11+
+#define __attribute__(x)
12+
+#endif
13+
+#endif
14+
+
15+
#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
16+
17+
/***********************************************************************
18+
diff --git a/libgambatte/src/file/unzip/ioapi.c b/libgambatte/src/file/unzip/ioapi.c
19+
index 84795e34..9489ad5f 100644
20+
--- a/libgambatte/src/file/unzip/ioapi.c
21+
+++ b/libgambatte/src/file/unzip/ioapi.c
22+
@@ -13,6 +13,11 @@
23+
#include <zlib.h>
24+
#include "ioapi.h"
25+
26+
+#ifdef _MSC_VER
27+
+#ifndef __attribute__
28+
+#define __attribute__(x)
29+
+#endif
30+
+#endif
31+
32+
33+
/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */

pyproject.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,14 @@ module = [
6767
ignore_missing_imports = true
6868

6969
[tool.cibuildwheel]
70-
skip = ["cp3??t-*", "cp*-musllinux_*"]
70+
skip = ["cp3??t-*", "cp*-musllinux_*", "*-win32"]
7171

7272
[tool.cibuildwheel.windows]
73-
before-all = "git -C gambatte-core apply ../patches/statesaver_windows.patch"
73+
before-all = [
74+
"git -C gambatte-core apply ../patches/statesaver_windows.patch ../patches/unzip_windows.patch",
75+
"vcpkg install zlib:x64-windows-static-md",
76+
]
77+
environment = { CL = "/I C:/vcpkg/installed/x64-windows-static-md/include", LINK = "/LIBPATH:C:/vcpkg/installed/x64-windows-static-md/lib" }
7478
test-command = "gambaterm --help"
7579

7680
[tool.cibuildwheel.macos]

setup.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
import platform
55
from setuptools import Extension, setup
66

7-
# No ZIP support for windows, building with zlib is a pain
8-
ZIP_SUPPORT = platform.system() != "Windows"
9-
107

118
def get_extensions() -> list[Extension]:
129
import numpy # Lazy import; numpy provided via build-system requires
@@ -16,19 +13,21 @@ def get_extensions() -> list[Extension]:
1613
libgambatte_sources = [
1714
p
1815
for p in glob.glob("gambatte-core/libgambatte/src/**/*.cpp", recursive=True)
19-
if (ZIP_SUPPORT and not p.endswith("file.cpp"))
20-
or (not ZIP_SUPPORT and not p.endswith("file_zip.cpp"))
16+
if not p.endswith(
17+
"file.cpp"
18+
) # Exclude file.cpp because file_zip.cpp is included
2119
]
2220

2321
# Add unzip C sources for ZIP support
24-
if ZIP_SUPPORT:
25-
libgambatte_sources += glob.glob(
26-
"gambatte-core/libgambatte/src/file/unzip/*.c", recursive=True
27-
)
22+
libgambatte_sources += glob.glob(
23+
"gambatte-core/libgambatte/src/file/unzip/*.c", recursive=True
24+
)
2825

2926
# Add zlib library for ZIP support
3027
libraries = []
31-
if ZIP_SUPPORT:
28+
if platform.system() == "Windows":
29+
libraries += ["zlib"]
30+
else:
3231
libraries += ["z"]
3332

3433
libgambatte_include_dirs = [

0 commit comments

Comments
 (0)