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

Building on MinGW #1169

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,17 @@ environment:
MYSQL_PATH: "C:\\Program Files\\MySQL\\MySQL Server 8.0"
# the cache should always be saved, even on failure, to be available for the next run
APPVEYOR_SAVE_CACHE_ON_ERROR: "true"
TEST_MSYS2: "false"

matrix:
# all the Python versions to be tested, both 32-bit and 64-bit
# ref: https://www.appveyor.com/docs/windows-images-software/#python
- PYTHON_HOME: "C:\\Python313-x64"
CHERE_INVOKING: 1
MSYSTEM: UCRT64
# breaks $python_arch in install.ps1 but we don't need it here.
PATH: C:\msys64\usr\bin;%PATH%
TEST_MSYS2: "true"
- PYTHON_HOME: "C:\\Python313-x64"
- PYTHON_HOME: "C:\\Python313"
- PYTHON_HOME: "C:\\Python312-x64"
Expand Down
8 changes: 6 additions & 2 deletions appveyor/after_test.cmd
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
IF "%TEST_MSYS2%" == "true" (
ECHO *** MSYS2 - Skipping generation of the wheel file
GOTO :end
)
IF "%APVYR_GENERATE_WHEELS%" == "true" (
ECHO *** pip install build/wheel modules
"%PYTHON_HOME%\python" -m pip install build wheel --quiet --no-warn-script-location
Expand All @@ -7,8 +11,8 @@ IF "%APVYR_GENERATE_WHEELS%" == "true" (
ECHO.
ECHO *** \dist directory listing:
DIR /B dist
ECHO.
) ELSE (
ECHO *** Skipping generation of the wheel file
ECHO.
)
:end
ECHO.
33 changes: 33 additions & 0 deletions appveyor/build_script.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ ECHO APVYR_GENERATE_WHEELS : %APVYR_GENERATE_WHEELS%
ECHO APVYR_VERBOSE : %APVYR_VERBOSE%
ECHO.
ECHO PYTHON_HOME : %PYTHON_HOME%
ECHO TEST_MSYS2 : %TEST_MSYS2%
ECHO MSSQL_INSTANCE: %MSSQL_INSTANCE%
ECHO POSTGRES_PATH : %POSTGRES_PATH%
ECHO MYSQL_PATH : %MYSQL_PATH%

ECHO.
IF "%TEST_MSYS2%" == "true" GOTO :msys2
ECHO *** Get build info and compiler for the current Python installation:
"%PYTHON_HOME%\python" -c "import platform; print(platform.python_build(), platform.python_compiler())"

Expand Down Expand Up @@ -51,4 +53,35 @@ ECHO.
ECHO *** Get version of the built pyodbc module:
"%PYTHON_HOME%\python" -c "import pyodbc; print(pyodbc.version)"

GOTO :end

:msys2
ECHO *** Get build info and compiler for the current Python installation:
bash -lc "python -c ""import platform; print(platform.python_build(), platform.python_compiler())"""

ECHO.
bash -lc "python -m pip freeze --all"

ECHO.
ECHO *** Installing pyodbc...
SET PYTHON_ARGS=.
IF "%APVYR_VERBOSE%" == "true" (
SET PYTHON_ARGS=--verbose %PYTHON_ARGS%
)
SET PIP_BREAK_SYSTEM_PACKAGES=1
bash -lc "python -m pip install %PYTHON_ARGS%"
IF ERRORLEVEL 1 (
ECHO *** ERROR: pyodbc install failed
EXIT 1
)

ECHO.
ECHO *** pip freeze...
bash -lc "python -m pip freeze --all"

ECHO.
ECHO *** Get version of the built pyodbc module:
bash -lc "python -c ""import pyodbc; print(pyodbc.version)"""

:end
ECHO.
11 changes: 9 additions & 2 deletions appveyor/install.cmd
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
ECHO *** pip install pytest and other dev requirements ***
"%PYTHON_HOME%\python" -m pip install -r requirements-dev.txt --quiet --no-warn-script-location
IF "%TEST_MSYS2%" == "true" (
ECHO *** pacman install dev requirements ***
bash -lc "pacman --noconfirm -Syuu"
bash -lc "pacman --noconfirm -Syuu"
bash -lc "pacman --noconfirm --needed -S - < ./appveyor/mingw_pkglist.txt"
) ELSE (
ECHO *** pip install pytest and other dev requirements ***
"%PYTHON_HOME%\python" -m pip install -r requirements-dev.txt --quiet --no-warn-script-location
)
ECHO.
8 changes: 8 additions & 0 deletions appveyor/mingw_pkglist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
base-devel
mingw-w64-ucrt-x86_64-toolchain
mingw-w64-ucrt-x86_64-cmake
mingw-w64-ucrt-x86_64-unixodbc
mingw-w64-ucrt-x86_64-python-setuptools
mingw-w64-ucrt-x86_64-python-pip
mingw-w64-ucrt-x86_64-python-wheel
mingw-w64-ucrt-x86_64-python-pytest
35 changes: 34 additions & 1 deletion appveyor/test_script.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ SET OVERALL_RESULT=0

REM Output a list of the ODBC drivers available to pyodbc
ECHO *** Available ODBC Drivers:
"%PYTHON_HOME%\python" -c "import pyodbc; print('\n'.join(sorted(pyodbc.drivers())))"
IF "%TEST_MSYS2%" == "true" (
bash -lc "python -c ""import pyodbc; print('\n'.join(sorted(pyodbc.drivers())))"""
) ELSE (
"%PYTHON_HOME%\python" -c "import pyodbc; print('\n'.join(sorted(pyodbc.drivers())))"
)


REM check if any testing should be done at all
Expand Down Expand Up @@ -43,6 +47,14 @@ IF ERRORLEVEL 1 (
)


REM check if only msys2 tests
IF "%TEST_MSYS2%" == "true" (
ECHO.
ECHO *** testing MSYS2
GOTO :msys2
)


:mssql2
REM Native Client 11.0 is so old, it might not be available on the server
SET DRIVER={SQL Server Native Client 11.0}
Expand Down Expand Up @@ -216,6 +228,27 @@ IF "%APVYR_VERBOSE%" == "true" (
%PYTHON_ARGS% "tests\mysql_test.py"
IF ERRORLEVEL 1 SET OVERALL_RESULT=1

GOTO :end

:msys2
SET DRIVER={ODBC Driver 17 for SQL Server}
SET PYODBC_SQLSERVER=Driver=%DRIVER%;Server=%MSSQL_INSTANCE%;Database=test_db;UID=sa;PWD=Password12!;
ECHO.
ECHO *** Run tests using driver: "%DRIVER%"
bash -lc "python appveyor/test_connect.py '%PYODBC_SQLSERVER%'"
IF ERRORLEVEL 1 (
ECHO *** ERROR: Could not connect using the connection string:
ECHO "%PYODBC_SQLSERVER%"
SET OVERALL_RESULT=1
GOTO :end
)
SET PYTHON_ARGS=-m pytest
IF "%APVYR_VERBOSE%" == "true" (
SET PYTHON_ARGS=%PYTHON_ARGS% --verbose
)
bash -lc "python %PYTHON_ARGS% tests/sqlserver_test.py"
IF ERRORLEVEL 1 SET OVERALL_RESULT=1


:end
ECHO.
Expand Down
15 changes: 13 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

import sys, os, shlex, re
import sys, os, re, shlex, sysconfig
from os.path import exists, join, isdir, relpath, expanduser
from pathlib import Path
from inspect import cleandoc
Expand Down Expand Up @@ -83,7 +83,18 @@ def get_compiler_settings():
'define_macros': [('PYODBC_VERSION', VERSION)]
}

if os.name == 'nt':
if 'mingw' in sysconfig.get_platform():
# Windows MinGW NOTE os.name = 'nt' and output from
# `odbc_config --cflags --libs` does not work as expected, excluding
# C:/msys64/ from begining of paths
settings['extra_compile_args'].extend([
'-Wno-write-strings',
])
unixodbc_headers = os.getenv("MSYSTEM_PREFIX") + "/include/unixodbc"
settings['include_dirs'] = [unixodbc_headers]
settings['libraries'].append('odbc32')

elif os.name == 'nt':
settings['extra_compile_args'].extend([
'/Wall',
'/wd4514', # unreference inline function removed
Expand Down
3 changes: 2 additions & 1 deletion src/pyodbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ typedef long long INT64;
typedef unsigned long long UINT64;
#define _strcmpi strcasecmp
#define _strdup strdup
inline int max(int lhs, int rhs) { return (rhs > lhs) ? rhs : lhs; }
inline int max(int lhs, int rhs) { return (rhs > lhs) ? rhs : lhs; }
inline int min(int lhs, int rhs) { return (rhs < lhs) ? rhs : lhs; }
#endif

#ifdef __SUN__
Expand Down