Skip to content

Commit 4da6ab6

Browse files
committed
Simplify befre_build script for Windows on ARM
1 parent 484e620 commit 4da6ab6

2 files changed

Lines changed: 38 additions & 53 deletions

File tree

.github/workflows/buildwheel.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
if: ${{ matrix.os == 'windows-11-arm' }}
6464
env:
6565
CIBW_BEFORE_ALL_WINDOWS: msys2 -c bin/cibw_before_all_windows_arm64.sh
66-
CIBW_BEFORE_BUILD_WINDOWS: msys2 -c bin/cibw_before_build_windows_arm64.sh && pip install wheel delvewheel
66+
CIBW_BEFORE_BUILD_WINDOWS: python bin/cibw_before_build_windows_arm64.py && msys2 -c bin/cibw_before_build_windows_arm64.sh && pip install wheel delvewheel
6767

6868
# After all the Windows-specific steps above this is what actually
6969
# builds the wheels for every other OS:

bin/cibw_before_build_windows_arm64.sh

Lines changed: 37 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,31 @@
22

33
set -o errexit
44

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
5+
env_file=.local/cibw_before_build_windows_arm64.env
6+
if [ ! -f "$env_file" ]; then
7+
echo "Could not find $env_file" >&2
228
exit 1
239
fi
2410

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
11+
# shellcheck disable=SC1090
12+
. "$env_file"
3713

38-
if [ -z "$dll_path" ]; then
39-
echo "Could not find $dll_name" >&2
40-
exit 1
14+
lib_dir_msys="$LIB_DIR"
15+
pkgconfig_dir_msys="$PKGCONFIG_DIR"
16+
dll_path_msys="$DLL_PATH"
17+
if command -v cygpath >/dev/null 2>&1; then
18+
lib_dir_msys=$(cygpath -u "$LIB_DIR")
19+
pkgconfig_dir_msys=$(cygpath -u "$PKGCONFIG_DIR")
20+
dll_path_msys=$(cygpath -u "$DLL_PATH")
4121
fi
22+
mkdir -p "$pkgconfig_dir_msys"
4223

4324
if ! command -v gendef >/dev/null 2>&1; then
4425
echo "Could not find gendef on PATH" >&2
4526
exit 1
4627
fi
4728

29+
dlltool=
4830
if command -v cc >/dev/null 2>&1; then
4931
dlltool=$(cc -print-prog-name=dlltool)
5032
fi
@@ -61,31 +43,34 @@ else
6143
exit 1
6244
fi
6345

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"
46+
dll_stem=${DLL_NAME%.dll}
47+
def_path_msys="$lib_dir_msys/$dll_stem.def"
48+
import_lib_msys="$lib_dir_msys/lib$dll_stem.dll.a"
49+
pc_path_msys="$pkgconfig_dir_msys/python-$PKG_VERSION.pc"
6850

69-
rm -f "$def_path" "$import_lib"
51+
rm -f "$def_path_msys" "$import_lib_msys"
7052
(
71-
cd "$lib_dir"
72-
gendef "$dll_path"
53+
cd "$lib_dir_msys"
54+
gendef "$dll_path_msys"
7355
)
74-
"$dlltool" -d "$def_path" -D "$dll_name" -l "$import_lib"
56+
"$dlltool" -d "$def_path_msys" -D "$DLL_NAME" -l "$import_lib_msys"
57+
58+
cat > "$pc_path_msys" <<EOF
59+
prefix=$REPO_ROOT
60+
exec_prefix=\${prefix}
61+
libdir=$LIB_DIR
62+
includedir=$INCLUDE_DIR
7563
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"
64+
Name: Python
65+
Description: CPython import library for MinGW wheel builds
66+
Version: $PKG_VERSION
67+
Libs: -L\${libdir} -l$dll_stem
68+
Cflags: -I\${includedir}
69+
EOF
8570

8671
if command -v pkg-config >/dev/null 2>&1; then
87-
pkg-config --exists "python-$pkg_version"
72+
pkg-config --exists "python-$PKG_VERSION"
8873
fi
8974

90-
echo "Generated $import_lib"
91-
echo "Generated $pc_path"
75+
echo "Generated $import_lib_msys"
76+
echo "Generated $pc_path_msys"

0 commit comments

Comments
 (0)