Skip to content

Commit b1ea1fb

Browse files
committed
Get windows building
1 parent 19dda23 commit b1ea1fb

File tree

5 files changed

+206
-32
lines changed

5 files changed

+206
-32
lines changed

relenv/_resources/xz/config.h

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/* config.h for compiling liblzma (*not* the whole XZ Utils) with MSVC 2019 */
2+
3+
/* Prefix for symbols exported by tuklib_*.c files */
4+
#define TUKLIB_SYMBOL_PREFIX lzma_
5+
6+
/* How many MiB of RAM to assume if the real amount cannot be determined. */
7+
#define ASSUME_RAM 128
8+
9+
/* Define to 1 if crc32 integrity check is enabled. */
10+
#define HAVE_CHECK_CRC32 1
11+
12+
/* Define to 1 if crc64 integrity check is enabled. */
13+
#define HAVE_CHECK_CRC64 1
14+
15+
/* Define to 1 if sha256 integrity check is enabled. */
16+
#define HAVE_CHECK_SHA256 1
17+
18+
/* Define to 1 if any of HAVE_DECODER_foo have been defined. */
19+
#define HAVE_DECODERS 1
20+
21+
/* Define to 1 if arm decoder is enabled. */
22+
#define HAVE_DECODER_ARM 1
23+
24+
/* Define to 1 if armthumb decoder is enabled. */
25+
#define HAVE_DECODER_ARMTHUMB 1
26+
27+
/* Define to 1 if delta decoder is enabled. */
28+
#define HAVE_DECODER_DELTA 1
29+
30+
/* Define to 1 if ia64 decoder is enabled. */
31+
#define HAVE_DECODER_IA64 1
32+
33+
/* Define to 1 if lzma1 decoder is enabled. */
34+
#define HAVE_DECODER_LZMA1 1
35+
36+
/* Define to 1 if lzma2 decoder is enabled. */
37+
#define HAVE_DECODER_LZMA2 1
38+
39+
/* Define to 1 if powerpc decoder is enabled. */
40+
#define HAVE_DECODER_POWERPC 1
41+
42+
/* Define to 1 if sparc decoder is enabled. */
43+
#define HAVE_DECODER_SPARC 1
44+
45+
/* Define to 1 if x86 decoder is enabled. */
46+
#define HAVE_DECODER_X86 1
47+
48+
/* Define to 1 if any of HAVE_ENCODER_foo have been defined. */
49+
#define HAVE_ENCODERS 1
50+
51+
/* Define to 1 if arm encoder is enabled. */
52+
#define HAVE_ENCODER_ARM 1
53+
54+
/* Define to 1 if armthumb encoder is enabled. */
55+
#define HAVE_ENCODER_ARMTHUMB 1
56+
57+
/* Define to 1 if delta encoder is enabled. */
58+
#define HAVE_ENCODER_DELTA 1
59+
60+
/* Define to 1 if ia64 encoder is enabled. */
61+
#define HAVE_ENCODER_IA64 1
62+
63+
/* Define to 1 if lzma1 encoder is enabled. */
64+
#define HAVE_ENCODER_LZMA1 1
65+
66+
/* Define to 1 if lzma2 encoder is enabled. */
67+
#define HAVE_ENCODER_LZMA2 1
68+
69+
/* Define to 1 if powerpc encoder is enabled. */
70+
#define HAVE_ENCODER_POWERPC 1
71+
72+
/* Define to 1 if sparc encoder is enabled. */
73+
#define HAVE_ENCODER_SPARC 1
74+
75+
/* Define to 1 if x86 encoder is enabled. */
76+
#define HAVE_ENCODER_X86 1
77+
78+
/* Define to 1 if you have the <inttypes.h> header file. */
79+
#define HAVE_INTTYPES_H 1
80+
81+
/* Define to 1 if you have the <limits.h> header file. */
82+
#define HAVE_LIMITS_H 1
83+
84+
/* Define to 1 to enable bt2 match finder. */
85+
#define HAVE_MF_BT2 1
86+
87+
/* Define to 1 to enable bt3 match finder. */
88+
#define HAVE_MF_BT3 1
89+
90+
/* Define to 1 to enable bt4 match finder. */
91+
#define HAVE_MF_BT4 1
92+
93+
/* Define to 1 to enable hc3 match finder. */
94+
#define HAVE_MF_HC3 1
95+
96+
/* Define to 1 to enable hc4 match finder. */
97+
#define HAVE_MF_HC4 1
98+
99+
/* Define to 1 if stdbool.h conforms to C99. */
100+
#define HAVE_STDBOOL_H 1
101+
102+
/* Define to 1 if you have the <stdint.h> header file. */
103+
#define HAVE_STDINT_H 1
104+
105+
/* Define to 1 if you have the <stdlib.h> header file. */
106+
#define HAVE_STDLIB_H 1
107+
108+
/* Define to 1 if you have the <string.h> header file. */
109+
#define HAVE_STRING_H 1
110+
111+
/* Define to 1 or 0, depending whether the compiler supports simple visibility
112+
declarations. */
113+
#define HAVE_VISIBILITY 0
114+
115+
/* Define to 1 if the system has the type `_Bool'. */
116+
#define HAVE__BOOL 1
117+
118+
#ifdef _M_IX86
119+
/* Define to 1 when using Windows 95 (and thus XP) compatible threads. This
120+
avoids use of features that were added in Windows Vista.
121+
This is used for 32-bit x86 builds for compatibility reasons since it
122+
makes no measurable difference in performance compared to Vista threads. */
123+
#define MYTHREAD_WIN95 1
124+
#else
125+
/* Define to 1 when using Windows Vista compatible threads. This uses features
126+
that are not available on Windows XP. */
127+
#define MYTHREAD_VISTA 1
128+
#endif
129+
130+
/* Define to 1 to disable debugging code. */
131+
#define NDEBUG 1
132+
133+
/* Define to the full name of this package. */
134+
#define PACKAGE_NAME "XZ Utils"
135+
136+
/* Define to the home page for this package. */
137+
#define PACKAGE_URL "https://tukaani.org/xz/"
138+
139+
/* The size of `size_t', as computed by sizeof. */
140+
#ifdef _WIN64
141+
#define SIZEOF_SIZE_T 8
142+
#else
143+
#define SIZEOF_SIZE_T 4
144+
#endif
145+
146+
/* Define to 1 if the system supports fast unaligned access to 16-bit and
147+
32-bit integers. */
148+
#define TUKLIB_FAST_UNALIGNED_ACCESS 1

relenv/_resources/xz/readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
The config.h file was removed from XZ-Utils tarting with version 5.5.0.
2+
XZ-Utils seems to build just fine with the config.h file from 5.4.7, so we're
3+
including it here. This will be copied into the src/windows directory in the
4+
extracted source for XZ-Utils.

relenv/build/common.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,12 +374,10 @@ def update_ensurepip(lib_dir):
374374
update_pip = False
375375
update_setuptools = False
376376
for file in bundle_dir.glob("*.whl"):
377-
if "pip" in file:
377+
if "pip" in str(file):
378378
update_pip = True
379-
file.unlink()
380-
if "setuptools" in file:
379+
if "setuptools" in str(file):
381380
update_setuptools = True
382-
file.unlink()
383381

384382
# Download whl files
385383
# pip

relenv/build/windows.py

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,24 @@ def update_props(source, old, new):
5858
:type new: str
5959
"""
6060
patch_file(source / "PCbuild" / "python.props", old, new)
61+
patch_file(source / "PCbuild" / "get_externals.bat", old, new)
6162

6263

63-
def get_externals_source(source_root, url):
64+
def get_externals_source(externals_dir, url):
6465
"""
6566
Download external source code dependency.
6667
6768
Download source code and extract to the "externals" directory in the root of
6869
the python source. Only works with a tarball
6970
"""
70-
externals_dir = source_root / "externals"
71-
externals_dir.mkdir(parents=True, exist_ok=True)
72-
local_file = download_url(url, str(externals_dir))
73-
extract_archive(str(local_file), str(externals_dir))
74-
os.path.unlink(str(local_file))
71+
zips_dir = externals_dir / "zips"
72+
zips_dir.mkdir(parents=True, exist_ok=True)
73+
local_file = download_url(url=url, dest=str(zips_dir))
74+
extract_archive(archive=str(local_file), to_dir=str(externals_dir))
75+
try:
76+
os.remove(local_file)
77+
except OSError:
78+
log.exception("Failed to remove temporary file")
7579

7680

7781
def get_externals_bin(source_root, url):
@@ -96,30 +100,39 @@ def build_python(env, dirs, logfp):
96100
:type logfp: file
97101
"""
98102
# Override default versions
103+
104+
# Create externals directory
105+
externals_dir = dirs.source / "externals"
106+
externals_dir.mkdir(parents=True, exist_ok=True)
107+
99108
# SQLITE
100109
if env["RELENV_PY_MAJOR_VERSION"] in ["3.10", "3.11", "3.12"]:
101110
version = "3.50.4.0"
102-
update_props(dirs.source, r"sqlite-\d+.\d+.\d+.\d+", "sqlite-{ver}")
103-
url = "https://sqlite.org/2025/sqlite-autoconf-3500400.tar.gz"
104-
get_externals_source(dirs.source, url=url)
105-
# we need to fix the name of the extracted directory
106-
extracted_dir = dirs.source / "externals" / "sqlite-src-3500400"
107-
target_dir = dirs.source / "externals" / f"sqlite-{version}"
108-
shutil.move(str(extracted_dir), str(target_dir))
111+
target_dir = externals_dir / f"sqlite-{version}"
112+
if not target_dir.exists():
113+
update_props(dirs.source, r"sqlite-\d+.\d+.\d+.\d+", f"sqlite-{version}")
114+
url = "https://sqlite.org/2025/sqlite-autoconf-3500400.tar.gz"
115+
get_externals_source(externals_dir=externals_dir, url=url)
116+
# # we need to fix the name of the extracted directory
117+
extracted_dir = externals_dir / "sqlite-autoconf-3500400"
118+
shutil.move(str(extracted_dir), str(target_dir))
109119

110120
# XZ-Utils
111121
if env["RELENV_PY_MAJOR_VERSION"] in ["3.10", "3.11", "3.12", "3.13", "3.14"]:
112-
update_props(dirs.source, r"xz-\d+.\d+.\d+", "xz-5.6.2")
113-
url = "https://github.com/tukaani-project/xz/releases/download/v5.6.2/xz-5.6.2.tar.xz"
114-
get_externals_source(dirs.source, url=url)
115-
116-
# zlib (3.14 uses zlib-ng)
117-
if env["RELENV_PY_MAJOR_VERSION"] in ["3.10", "3.11", "3.12", "3.13"]:
118-
# already in python.props with the correct version in all the above versions
119-
# update_props(dirs.source, r"zlib-\d+.\d+.\d+", "zlib-1.3.1")
120-
# but it still needs to be in "externals"
121-
url = "https://zlib.net/zlib-1.3.1.tar.gz"
122-
get_externals_source(dirs.source, url=url)
122+
version = "5.6.2"
123+
target_dir = externals_dir / f"xz-{version}"
124+
if not target_dir.exists():
125+
update_props(dirs.source, r"xz-\d+.\d+.\d+", f"xz-{version}")
126+
url = f"https://github.com/tukaani-project/xz/releases/download/v{version}/xz-{version}.tar.xz"
127+
get_externals_source(externals_dir=externals_dir, url=url)
128+
# Starting with version v5.5.0, XZ-Utils removed the ability to compile
129+
# with MSBuild. We are bringing the config.h from the last version that
130+
# had it, 5.4.7
131+
config_file = target_dir / "windows" / "config.h"
132+
config_file = target_dir / "src" / "common" / "config.h"
133+
config_file_source = dirs.root / "_resources" / "xz" / "config.h"
134+
if not config_file.exists():
135+
shutil.copy(str(config_file_source), str(config_file))
123136

124137
arch_to_plat = {
125138
"amd64": "x64",
@@ -133,7 +146,6 @@ def build_python(env, dirs, logfp):
133146
"-p",
134147
plat,
135148
"--no-tkinter",
136-
"-e",
137149
]
138150

139151
log.info("Start PCbuild")

relenv/common.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,19 @@ def extract_archive(to_dir, archive):
336336
:type archive: str
337337
"""
338338
if archive.endswith("tgz"):
339+
log.debug("Found tgz archive")
340+
read_type = "r:gz"
341+
elif archive.endswith("tar.gz"):
342+
log.debug("Found tar.gz archive")
339343
read_type = "r:gz"
340344
elif archive.endswith("xz"):
345+
log.debug("Found xz archive")
341346
read_type = "r:xz"
342347
elif archive.endswith("bz2"):
348+
log.debug("Found bz2 archive")
343349
read_type = "r:bz2"
344350
else:
351+
log.warning("Found unknown archive type: %s", archive)
345352
read_type = "r"
346353
with tarfile.open(archive, read_type) as t:
347354
t.extractall(to_dir)
@@ -411,6 +418,7 @@ def fetch_url(url, fp, backoff=3, timeout=30):
411418
n += 1
412419
try:
413420
fin = urllib.request.urlopen(url, timeout=timeout)
421+
break
414422
except (
415423
urllib.error.HTTPError,
416424
urllib.error.URLError,
@@ -420,6 +428,8 @@ def fetch_url(url, fp, backoff=3, timeout=30):
420428
raise RelenvException(f"Error fetching url {url} {exc}")
421429
log.debug("Unable to connect %s", url)
422430
time.sleep(n * 10)
431+
else:
432+
raise RelenvException(f"Error fetching url: {url}")
423433
log.info("url opened %s", url)
424434
try:
425435
total = 0
@@ -434,7 +444,6 @@ def fetch_url(url, fp, backoff=3, timeout=30):
434444
block = fin.read(10240)
435445
finally:
436446
fin.close()
437-
# fp.close()
438447
log.info("Download complete %s", url)
439448

440449

@@ -514,18 +523,21 @@ def download_url(url, dest, verbose=True, backoff=3, timeout=60):
514523
"""
515524
local = get_download_location(url, dest)
516525
if verbose:
517-
print(f"Downloading {url} -> {local}")
526+
log.debug(f"Downloading {url} -> {local}")
518527
fout = open(local, "wb")
519528
try:
520529
fetch_url(url, fout, backoff, timeout)
521530
except Exception as exc:
522531
if verbose:
523-
print(f"Unable to download: {url} {exc}", file=sys.stderr, flush=True)
532+
log.error(f"Unable to download: {url} {exc}", file=sys.stderr, flush=True)
524533
try:
525534
os.unlink(local)
526535
except OSError:
527536
pass
528537
raise
538+
finally:
539+
fout.close()
540+
log.debug(f"Finished downloading {url} -> {local}")
529541
return local
530542

531543

0 commit comments

Comments
 (0)