|
| 1 | +diff --git a/graalpy-config b/graalpy-config |
| 2 | +new file mode 100755 |
| 3 | +index 00000000..1f69f726 |
| 4 | +--- /dev/null |
| 5 | ++++ b/graalpy-config |
| 6 | +@@ -0,0 +1,78 @@ |
| 7 | ++#!/bin/sh |
| 8 | ++ |
| 9 | ++# Adapted from CPython but deferring to GraalPy |
| 10 | ++ |
| 11 | ++exit_with_usage () |
| 12 | ++{ |
| 13 | ++ echo "Usage: $0 --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--help|--abiflags|--configdir|--embed" |
| 14 | ++ exit $1 |
| 15 | ++} |
| 16 | ++ |
| 17 | ++if [ "$1" = "" ] ; then |
| 18 | ++ exit_with_usage 1 |
| 19 | ++fi |
| 20 | ++ |
| 21 | ++# Returns the actual prefix where this script was installed to. |
| 22 | ++EXE=$(cd $(dirname "$0") && pwd -P) |
| 23 | ++if which readlink >/dev/null 2>&1 ; then |
| 24 | ++ if readlink -f "$RESULT" >/dev/null 2>&1; then |
| 25 | ++ EXE=$(readlink -f "$RESULT") |
| 26 | ++ fi |
| 27 | ++fi |
| 28 | ++EXE=$EXE/graalpy |
| 29 | ++ |
| 30 | ++if ! test -x "$EXE" ; then |
| 31 | ++ EXE=graalpy |
| 32 | ++fi |
| 33 | ++ |
| 34 | ++# Scan for --help or unknown argument. |
| 35 | ++for ARG in $* |
| 36 | ++do |
| 37 | ++ case $ARG in |
| 38 | ++ --help) |
| 39 | ++ exit_with_usage 0 |
| 40 | ++ ;; |
| 41 | ++ --embed) |
| 42 | ++ echo "graalpy-config does not print embedding flags" |
| 43 | ++ exit 1 |
| 44 | ++ ;; |
| 45 | ++ --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--abiflags|--configdir) |
| 46 | ++ ;; |
| 47 | ++ *) |
| 48 | ++ exit_with_usage 1 |
| 49 | ++ ;; |
| 50 | ++ esac |
| 51 | ++done |
| 52 | ++ |
| 53 | ++for ARG in "$@" |
| 54 | ++do |
| 55 | ++ case "$ARG" in |
| 56 | ++ --prefix) |
| 57 | ++ $EXE -c "print(__import__('sysconfig').get_config_var('prefix'))" |
| 58 | ++ ;; |
| 59 | ++ --exec-prefix) |
| 60 | ++ $EXE -c "print(__import__('sysconfig').get_config_var('exec_prefix'))" |
| 61 | ++ ;; |
| 62 | ++ --includes) |
| 63 | ++ $EXE -c "from sysconfig import get_path; print('-I'+get_path('include'), '-I'+get_path('platinclude'))" |
| 64 | ++ ;; |
| 65 | ++ --cflags) |
| 66 | ++ $EXE -c "import sysconfig as s; print('-I' + s.get_path('include'), '-I' + s.get_path('platinclude'), s.get_config_var('CFLAGS').replace('NDEBUG', 'DEBUG'), s.get_config_var('OPT').replace('NDEBUG', 'DEBUG'))" |
| 67 | ++ ;; |
| 68 | ++ --libs) |
| 69 | ++ $EXE -c "import sysconfig as s; print('-L' + s.get_config_var('LIBDIR'))" |
| 70 | ++ ;; |
| 71 | ++ --ldflags) |
| 72 | ++ $EXE -c "import sysconfig as s; print('-L' + s.get_config_var('LIBDIR'))" |
| 73 | ++ ;; |
| 74 | ++ --extension-suffix) |
| 75 | ++ $EXE -c "import sysconfig as s; print(s.get_config_var('EXT_SUFFIX'))" |
| 76 | ++ ;; |
| 77 | ++ --abiflags) |
| 78 | ++ $EXE -c "import sysconfig as s; print(s.get_config_var('ABIFLAGS'))" |
| 79 | ++ ;; |
| 80 | ++ --configdir) |
| 81 | ++ echo "" |
| 82 | ++ ;; |
| 83 | ++esac |
| 84 | ++done |
| 85 | +diff --git a/setup.py b/setup.py |
| 86 | +index 5fba2c97..3fe63b07 100755 |
| 87 | +--- a/setup.py |
| 88 | ++++ b/setup.py |
| 89 | +@@ -1452,0 +1452,35 @@ |
| 90 | ++if sys.implementation.name == "graalpy": |
| 91 | ++ import os |
| 92 | ++ import re |
| 93 | ++ import subprocess |
| 94 | ++ import shutil |
| 95 | ++ import sysconfig |
| 96 | ++ from pathlib import Path |
| 97 | ++ |
| 98 | ++ def build_wheel(wheel_directory, config_settings=None, metadata_directory=None): |
| 99 | ++ wheel_directory = Path(wheel_directory).absolute() |
| 100 | ++ sdir = Path(__file__).absolute().parent |
| 101 | ++ python311 = shutil.which("python3.11") |
| 102 | ++ if not python311: |
| 103 | ++ raise RuntimeError("python3.11 must be available on the PATH for cross-compilation") |
| 104 | ++ env = os.environ.copy() |
| 105 | ++ env["PIPCL_PYTHON_CONFIG"] = str(sdir / "graalpy-config") |
| 106 | ++ env["PYMUPDF_SETUP_PY_LIMITED_API"] = "1" |
| 107 | ++ subprocess.run( |
| 108 | ++ [python311, "setup.py", "bdist_wheel"], |
| 109 | ++ env=env, |
| 110 | ++ cwd=sdir, |
| 111 | ++ check=True, |
| 112 | ++ ) |
| 113 | ++ wheels = list((sdir / 'dist').glob('*.whl')) |
| 114 | ++ assert len(wheels) == 1, f"Expected 1 wheel, found {len(wheels)}" |
| 115 | ++ wheel = wheels[0] |
| 116 | ++ assert "-cp311-abi3" in wheel.name, f"Expected wheel to be for CPython 3.11 ABI 3, got {wheel.name}" |
| 117 | ++ graalpy_ext_suffix = sysconfig.get_config_var("EXT_SUFFIX") |
| 118 | ++ m = re.match(r"\.graalpy(\d+[^\-]*)-(\d+)", sysconfig.get_config_var("EXT_SUFFIX")) |
| 119 | ++ gpver = m[1] |
| 120 | ++ cpver = m[2] |
| 121 | ++ graalpy_wheel_tag = f"graalpy{cpver}-graalpy{gpver}_{cpver}_native" |
| 122 | ++ name = wheel.name.replace("cp311-abi3", graalpy_wheel_tag) |
| 123 | ++ shutil.copyfile(wheel, wheel_directory / name) |
| 124 | ++ return str(name) |
0 commit comments