Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build and test windows wheels #469

Merged
merged 6 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,37 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-22.04, macos-12, macos-14]
os: [ubuntu-22.04, macos-12, macos-14, windows-2022]
steps:
- uses: actions/checkout@v4
- if: runner.os == 'macOS'
run: brew install pipx
- uses: msys2/setup-msys2@v2
name: Setup msys2
with:
install: >-
mingw-w64-ucrt-x86_64-gcc
autotools
msystem: ucrt64
path-type: inherit
if: ${{ matrix.os == 'windows-2022' }}
- name: Build wheels
uses: pypa/cibuildwheel@v2.16.5
env:
CIBW_PRERELEASE_PYTHONS: True
CIBW_SKIP: pp*
CIBW_BEFORE_BUILD: bash scripts/cibw_before_all.sh
CIBW_SKIP: pp* *-win32
CIBW_BEFORE_ALL: bash scripts/cibw_before_all.sh
CIBW_BEFORE_ALL_WINDOWS: msys2 -c scripts/cibw_before_all.sh
CIBW_BEFORE_BUILD_WINDOWS: pip install delvewheel
CIBW_TEST_EXTRAS: tests
CIBW_TEST_SKIP: cp38-macosx_arm64
CIBW_TEST_COMMAND: >
pytest {package}/test/ &&
python {package}/test_cython/runtests.py
CIBW_REPAIR_WHEEL_COMMAND: >
bash scripts/cibw_repair_wheel_command.sh {dest_dir} {wheel}
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: >
scripts\cibw_repair_wheel_command_windows.bat {dest_dir} {wheel}
- uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.os }}
Expand Down
16 changes: 8 additions & 8 deletions demo/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
library_dirs = sys.path + [gmpy2_packagedir]
libnames = ['mpc','mpfr','gmp']

if platform.system() != 'Windows':
bundled_libs = gmpy2_packagedir+'/../gmpy2.libs/'
if os.path.isdir(bundled_libs):
library_dirs += [bundled_libs]
if platform.system() == 'Linux':
libnames = [':' + d for d in os.listdir(bundled_libs)]
else:
libnames = [':' + bundled_libs + d for d in os.listdir(bundled_libs)]
bundled_libs = os.path.join(gmpy2_packagedir, '..', 'gmpy2.libs')
if os.path.isdir(bundled_libs):
library_dirs += [bundled_libs]
if platform.system() == 'Linux':
libnames = [':' + d for d in os.listdir(bundled_libs)]
elif platform.system() == 'Darwin':
libnames = [':' + bundled_libs + d for d in os.listdir(bundled_libs)]


gmpy_ext = [
Extension("gmpy2_demo", sources=["gmpy2_demo.c"],
Expand Down
107 changes: 59 additions & 48 deletions docs/win_build.rst
Original file line number Diff line number Diff line change
@@ -1,73 +1,84 @@
:orphan:

Windows Build from Source
=========================
Building for Windows
====================

Building gmpy2 and the related libraries from scratch requires several steps. The following
instructions create a dedicated build environment using standalone
A new build approach is being tested for the final gmpy2 v2.2.x release.

Install MSYS2
-------------
The GMP, MPFR, and MPC DLLs are created using the MinGW64 compiler suite and
are linked to UCRT. The final gmpy2 binaries are created using Visual Studio.

Browse to https://www.msys2.org and download and run the current installer. Accept the default
path of C:\msys64

Update MSYS2
------------
MSYS2 Steps
-----------

pacman -Syuu
1. Install MSYS2

pacman -S patch m4 lzip wget tar make diffutils
1. Upgrade the initial installation::

Install the MinGW-w64 Compiler Suite
------------------------------------
pacman -Syuu

MSYS2 follows a "rolling-release" model. New versions of applications, including the MinGW-w64
compiler suite, are released frequently. The continual release cycles make it difficult to
provide a reproducible build environment. We will be using MinGW-w64 as distributed by
http://winlibs.com/. This documentation was based on the following version:
2. Reboot and launch the "MSYS2 UCRT" terminal window. Upgrade the user
system::

https://github.com/brechtsanders/winlibs_mingw/releases/download/10.3.0-12.0.0-9.0.0-r2/winlibs-x86_64-posix-seh-gcc-10.3.0-mingw-w64-9.0.0-r2.zip
pacman -Syu

Unzip the downloaded file and copy the "mingw64" directory to the desired location.
The following documentation assumes the files are copied to C:\mingw64.
3. Install the MinGW64 compiler suite that links with ucrt::

The Build Environment
---------------------
pacman -Sy mingw-w64-ucrt-x86_64-gcc

The build process is split into two phases. During phase 1 we use the MSYS2 shell environment
and the winlibs.com MinGW-w64 compiler suite to build GMP, MPFR, and MPC. Once those libraries
are built, we will use the Windows command prompt and the same compiler to build the actual
gmpy2 extension (DLL).
4. Install rquired tools::

The MSYS2 environment provides different command line operating environments. We will just
use the generic "MSYS2 MSYS" environment.
pacman -Sy patch m4 lzip wget tar make diffutils git

* MSYS2 MSYS
This is the general-purpose MSYS shell but it does not provide
access to the MinGW compiler suite. We will use this shell and
manually add the location of the winlibs.com version.
2. Create a temporary working directory for the build::

MSYS2 does include versions of GMP, MPFR, and MPC but we will compile our own version directly
from the source. We do this so we can create reproducible builds.
mkdir ~/temp

Compiling GMP, MPFR, and MPC
----------------------------
3. Clone (or download) the full gmpy2 source code::

Start the appropriate shell: MSYS2 MSYS
cd ~/temp
git clone https://github.com/aleaxit/gmpy.git
cd gmpy

Add the MinGW-w64 compiler to the PATH.
4. Download and compile GMP, MPFR, and MPC:

PATH="/c/mingw64/bin:"$PATH
bash scripts/cibw_before_all.sh

In your home directory, create directories for the various files that are created.

mkdir $HOME/64
mkdir $HOME/64/src
mkdir $HOME/64/static
mkdir $HOME/64/shared
Visual Studio Steps
-------------------

Download GMP, MPFR, and MPC
---------------------------
1. Launch the "Visual Studio x64 Native Tools Command Prompt" shell.

Execute the file
2. Change to location of the build directory::

cd c:\msys64\home\<username>\temp\gmpy

3. Run::

scripts\cibw_before_all_windows.bat

4. Compile and install Windows binary wheels, e.g. for CPython 3.12::

py -3.12 -m pip install --upgrade build pytest hypothesis cython mpmath
set CIBUILDWHEEL=1
py -3.12 -m build --wheel --no-isolation
py -3.12 -m pip install dist\gmpy2-*312-*.whl --force-reinstall

5. Run the test suite::

py -3.12 -m pytest test/

6. Compile the C-API demo program::

cd demo
py -3.12 setup.py build_ext
cd build\lib.win-amd64-cpython-312
py -3.12
>>> import gmpy2
>>> import gmpy2_demo
>>> dir(gmpy2_demo)
['__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'factor']
>>> gmpy2_demo.factor(123456789)
[(mpz(3), mpz(2)), (mpz(3607), mpz(1)), (mpz(3803), mpz(1))]
63 changes: 0 additions & 63 deletions mingw64/msys2_64_shared.sh

This file was deleted.

133 changes: 0 additions & 133 deletions mingw64/msys2_build.txt

This file was deleted.

Loading
Loading