Skip to content

Commit 4278084

Browse files
committed
Try generating the .dll.a file for clangarm64
1 parent f46aedd commit 4278084

3 files changed

Lines changed: 103 additions & 0 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
3+
set -o errexit
4+
5+
repo_root=$(python -c 'from pathlib import Path; print(Path.cwd().resolve().as_posix())')
6+
lib_dir="$repo_root/.local/lib"
7+
pkgconfig_dir="$lib_dir/pkgconfig"
8+
mkdir -p "$pkgconfig_dir"
9+
10+
dll_name=$(python -c 'import sysconfig; print(sysconfig.get_config_var("LDLIBRARY") or "")')
11+
pkg_version=$(python -c 'import sysconfig; print(sysconfig.get_config_var("LDVERSION") or sysconfig.get_python_version())')
12+
include_dir=$(python -c 'import sysconfig; print(sysconfig.get_config_var("INCLUDEPY") or "")')
13+
base_prefix=$(python -c 'import sys; print(getattr(sys, "base_prefix", sys.prefix))')
14+
python_bin=$(python -c 'import os, sys; print(os.path.dirname(sys.executable))')
15+
16+
include_dir=${include_dir//\\//}
17+
base_prefix=${base_prefix//\\//}
18+
python_bin=${python_bin//\\//}
19+
20+
if [ -z "$dll_name" ] || [ -z "$include_dir" ]; then
21+
echo "Could not determine Python DLL or include dir" >&2
22+
exit 1
23+
fi
24+
25+
dll_path=""
26+
for candidate in \
27+
"$python_bin/$dll_name" \
28+
"$base_prefix/$dll_name" \
29+
"$base_prefix/DLLs/$dll_name" \
30+
"$base_prefix/libs/$dll_name"
31+
do
32+
if [ -f "$candidate" ]; then
33+
dll_path="$candidate"
34+
break
35+
fi
36+
done
37+
38+
if [ -z "$dll_path" ]; then
39+
echo "Could not find $dll_name" >&2
40+
exit 1
41+
fi
42+
43+
if ! command -v gendef >/dev/null 2>&1; then
44+
echo "Could not find gendef on PATH" >&2
45+
exit 1
46+
fi
47+
48+
if command -v cc >/dev/null 2>&1; then
49+
dlltool=$(cc -print-prog-name=dlltool)
50+
fi
51+
if [ -n "${dlltool:-}" ] && [ -x "$dlltool" ]; then
52+
:
53+
elif [ -n "${dlltool:-}" ] && command -v "$dlltool" >/dev/null 2>&1; then
54+
dlltool=$(command -v "$dlltool")
55+
elif command -v dlltool >/dev/null 2>&1; then
56+
dlltool=$(command -v dlltool)
57+
elif command -v llvm-dlltool >/dev/null 2>&1; then
58+
dlltool=$(command -v llvm-dlltool)
59+
else
60+
echo "Could not find dlltool or llvm-dlltool on PATH" >&2
61+
exit 1
62+
fi
63+
64+
dll_stem=${dll_name%.dll}
65+
def_path="$lib_dir/$dll_stem.def"
66+
import_lib="$lib_dir/lib$dll_stem.dll.a"
67+
pc_path="$pkgconfig_dir/python-$pkg_version.pc"
68+
69+
rm -f "$def_path" "$import_lib"
70+
(
71+
cd "$lib_dir"
72+
gendef "$dll_path"
73+
)
74+
"$dlltool" -d "$def_path" -D "$dll_name" -l "$import_lib"
75+
76+
printf 'prefix=%s\n' "$repo_root" > "$pc_path"
77+
printf 'exec_prefix=${prefix}\n' >> "$pc_path"
78+
printf 'libdir=%s\n' "$lib_dir" >> "$pc_path"
79+
printf 'includedir=%s\n\n' "$include_dir" >> "$pc_path"
80+
printf 'Name: Python\n' >> "$pc_path"
81+
printf 'Description: CPython import library for MinGW wheel builds\n' >> "$pc_path"
82+
printf 'Version: %s\n' "$pkg_version" >> "$pc_path"
83+
printf 'Libs: -L${libdir} -l%s\n' "$dll_stem" >> "$pc_path"
84+
printf 'Cflags: -I${includedir}\n' >> "$pc_path"
85+
86+
if command -v pkg-config >/dev/null 2>&1; then
87+
pkg-config --exists "python-$pkg_version"
88+
fi
89+
90+
echo "Generated $import_lib"
91+
echo "Generated $pc_path"

meson.build

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ endif
7777

7878
pyflint_deps = [gmp_dep, mpfr_dep, flint_dep]
7979

80+
# Meson's Windows sysconfig dependency path can hand the clangarm64
81+
# toolchain the python DLL itself. Use pkg-config on Windows ARM64 so we can
82+
# provide a MinGW import library instead.
83+
if host_machine.system() == 'windows' and host_machine.cpu_family() in ['aarch64', 'arm64'] and cc.get_id() in ['gcc', 'clang']
84+
dep_py = py.dependency(method: 'pkg-config')
85+
pyflint_deps = [dep_py] + pyflint_deps
86+
endif
87+
8088
add_project_arguments(
8189
'-X', 'embedsignature=True',
8290
'-X', 'emit_code_comments=True',

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,7 @@ repair-wheel-command = [
176176
""",
177177
"delvewheel repair -w {dest_dir} {wheel} --add-path .local/bin",
178178
]
179+
180+
[[tool.cibuildwheel.overrides]]
181+
select = ["*-win_arm64"]
182+
before-build = "C:\\msys64\\usr\\bin\\bash bin/cibw_before_build_windows_arm64.sh && pip install wheel delvewheel"

0 commit comments

Comments
 (0)