|
8 | 8 | import subprocess |
9 | 9 | import sys |
10 | 10 | import sysconfig |
| 11 | +import hashlib |
11 | 12 | import tempfile |
12 | 13 | from urllib.request import urlopen |
13 | 14 | from pathlib import Path |
@@ -164,20 +165,60 @@ def make_build_python(context, working_dir): |
164 | 165 | print(f"🎉 {binary} {version}") |
165 | 166 |
|
166 | 167 |
|
167 | | -@subdir(HOST_BUILD_DIR, clean_ok=True) |
168 | | -def make_emscripten_libffi(context, working_dir): |
169 | | - shutil.rmtree(working_dir / "libffi-3.4.6", ignore_errors=True) |
| 168 | +def check_shasum(file: str, expected_shasum: str): |
| 169 | + with open(file, "rb") as f: |
| 170 | + digest = hashlib.file_digest(f, "sha256") |
| 171 | + if digest.hexdigest() != expected_shasum: |
| 172 | + raise RuntimeError(f"Unexpected shasum for {file}") |
| 173 | + |
| 174 | + |
| 175 | +def download_and_unpack(working_dir: Path, url: str, expected_shasum: str): |
170 | 176 | with tempfile.NamedTemporaryFile(suffix=".tar.gz", delete_on_close=False) as tmp_file: |
171 | | - with urlopen( |
172 | | - "https://github.com/libffi/libffi/releases/download/v3.4.6/libffi-3.4.6.tar.gz" |
173 | | - ) as response: |
| 177 | + with urlopen(url) as response: |
174 | 178 | shutil.copyfileobj(response, tmp_file) |
175 | 179 | tmp_file.close() |
| 180 | + check_shasum(tmp_file.name, expected_shasum) |
176 | 181 | shutil.unpack_archive(tmp_file.name, working_dir) |
| 182 | + |
| 183 | + |
| 184 | +@subdir(HOST_BUILD_DIR, clean_ok=True) |
| 185 | +def make_emscripten_libffi(context, working_dir): |
| 186 | + ver = "3.4.6" |
| 187 | + libffi_dir = working_dir / f"libffi-{ver}" |
| 188 | + shutil.rmtree(libffi_dir, ignore_errors=True) |
| 189 | + download_and_unpack(working_dir, f"https://github.com/libffi/libffi/releases/download/v{ver}/libffi-{ver}.tar.gz", "b0dea9df23c863a7a50e825440f3ebffabd65df1497108e5d437747843895a4e") |
177 | 190 | call( |
178 | 191 | [EMSCRIPTEN_DIR / "make_libffi.sh"], |
179 | 192 | env=updated_env({"PREFIX": PREFIX_DIR}), |
180 | | - cwd=working_dir / "libffi-3.4.6", |
| 193 | + cwd=libffi_dir, |
| 194 | + quiet=context.quiet, |
| 195 | + ) |
| 196 | + |
| 197 | + |
| 198 | +@subdir(HOST_BUILD_DIR, clean_ok=True) |
| 199 | +def make_mpdec(context, working_dir): |
| 200 | + ver = "4.0.1" |
| 201 | + mpdec_dir = working_dir / f"mpdecimal-{ver}" |
| 202 | + shutil.rmtree(mpdec_dir, ignore_errors=True) |
| 203 | + download_and_unpack(working_dir, f"https://www.bytereef.org/software/mpdecimal/releases/mpdecimal-{ver}.tar.gz", "96d33abb4bb0070c7be0fed4246cd38416188325f820468214471938545b1ac8") |
| 204 | + call( |
| 205 | + [ |
| 206 | + "emconfigure", |
| 207 | + mpdec_dir / "configure", |
| 208 | + "CFLAGS=-fPIC", |
| 209 | + "--prefix", |
| 210 | + PREFIX_DIR, |
| 211 | + "--disable-shared", |
| 212 | + ], |
| 213 | + cwd=mpdec_dir, |
| 214 | + quiet=context.quiet, |
| 215 | + ) |
| 216 | + call( |
| 217 | + [ |
| 218 | + "make", |
| 219 | + "install" |
| 220 | + ], |
| 221 | + cwd=mpdec_dir, |
181 | 222 | quiet=context.quiet, |
182 | 223 | ) |
183 | 224 |
|
@@ -315,6 +356,7 @@ def build_all(context): |
315 | 356 | configure_build_python, |
316 | 357 | make_build_python, |
317 | 358 | make_emscripten_libffi, |
| 359 | + make_mpdec, |
318 | 360 | configure_emscripten_python, |
319 | 361 | make_emscripten_python, |
320 | 362 | ] |
@@ -343,6 +385,9 @@ def main(): |
343 | 385 | configure_build = subcommands.add_parser( |
344 | 386 | "configure-build-python", help="Run `configure` for the " "build Python" |
345 | 387 | ) |
| 388 | + make_mpdec_cmd = subcommands.add_parser( |
| 389 | + "make-mpdec", help="Clone mpdec repo, configure and build it for emscripten" |
| 390 | + ) |
346 | 391 | make_libffi_cmd = subcommands.add_parser( |
347 | 392 | "make-libffi", help="Clone libffi repo, configure and build it for emscripten" |
348 | 393 | ) |
@@ -363,6 +408,7 @@ def main(): |
363 | 408 | build, |
364 | 409 | configure_build, |
365 | 410 | make_libffi_cmd, |
| 411 | + make_mpdec_cmd, |
366 | 412 | make_build, |
367 | 413 | configure_host, |
368 | 414 | make_host, |
@@ -400,6 +446,7 @@ def main(): |
400 | 446 |
|
401 | 447 | dispatch = { |
402 | 448 | "make-libffi": make_emscripten_libffi, |
| 449 | + "make-mpdec": make_mpdec, |
403 | 450 | "configure-build-python": configure_build_python, |
404 | 451 | "make-build-python": make_build_python, |
405 | 452 | "configure-host": configure_emscripten_python, |
|