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

Better support for building on Windows #484

Merged
merged 2 commits into from
Sep 3, 2021
Merged

Conversation

sparkyb
Copy link
Contributor

@sparkyb sparkyb commented Mar 8, 2021

I know that you are not a Windows user and that you don't wish to provide support for source builds on Windows. However, I am a Windows user and have had to build mysqlclient from source because you do not provide wheels for 32-bit versions of Python (which I need for other reasons). I am hoping that you will accept this PR that should make it easier for users like me to be able to install mysqlclient from source without needing to clone this repo to edit site.cfg and setup_windows.py.

I know this cannot account for all possible setups, but at least with these changes it has a chance of building under some setups, which should be an improvement on the current defaults in setup_windows.py and site.cfg which I don't believe have any chance at building correctly. This PR includes 5 small improvements:

  1. mysqlclient can be built against either the MySQL Connector/C or the MariaDB Connector/C. Previously, which library was used was hardcoded in setup_windows.py while the path to the connector was in site.cfg. I added a second option in site.cfg so that you can specify both in one place.
  2. Editing site.cfg requires cloning this repo. I changed it so that you can override these settings with the environment variables MYSQLCLIENT_CLIENT and MYSQLCLIENT_CONNECTOR so that someone who knows what they are doing can point the build script to their copy of the connector while installing from pip without needing to clone this repo to edit site.cfg.
  3. I also added support for a limited amount of auto-detection of these two options. If a client isn't specified but a connector is, that connector path will be searched for either mariadbclient.lib or mysqlclient.lib to set the client type. If a client is specified but a connector path isn't, the default path used by the pre-built .msi installers is assumed. This will probably be "C:\Program Files\MariaDB\MariaDB Connector C" for mariadbclient and "C:\Program Files\MySQL\MySQL Connector C 6.1" for mysqlclient ("C:\Program Files (x86)" will be used on 32-bit builds). I know this doesn't account for all places someone could have installed the connector, but seemed like a reasonable default and should be no worse than not having a default. If neither client nor connector are specified, both client types will be checked to see if the appropriate .lib file exists in the default connector
    directory.
  4. I also added additional install and library directories for mariadbclient. This is because the pre-built connector binaries install the needed files in include and lib whereas building from source (like this repo's workflow does) leaves them in include/mariadb and lib/mariadb. I'm not sure why these differ, but it shouldn't be harmful to add both locations to the include/lib paths so that either works.
  5. I updated the Windows build section of the README to add a link to the MariaDB Connector to install if you want to try to install from source.

I'm happy to break up these changes if you would like to accept some of them but not others. Also, while I can confirm that building against MySQL Connector/C 6.1 does still work, since it has not been updated in over 3 years and it seems like you do not build against it anymore, we could simplify things by removing support for it. We could go back to hardcoding the client library as mariadbclient if that were the only one we support and then there would just be a single site.cfg option and environment variable, and a single default directory.

@codecov
Copy link

codecov bot commented Mar 8, 2021

Codecov Report

Merging #484 (8d49297) into master (24aaa72) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #484   +/-   ##
=======================================
  Coverage   84.32%   84.32%           
=======================================
  Files           6        6           
  Lines         555      555           
=======================================
  Hits          468      468           
  Misses         87       87           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 24aaa72...8d49297. Read the comment docs.

mysqlclient can be built against either the MySQL Connector/C or the
MariaDB Connector/C. Previously, which library was used was hardcoded in
setup_windows.py while the path to the library was in site.cfg. Now both
settings can be specified in site.cfg, as environment variables, or
auto-detected. If a client isn't specified but a connector path is, that
path will be searched for either mariadbclient.lib or mysqlclient.lib to set
the client type. If a client is specified but a connector path isn't, the
default path used by the pre-built .msi installers will be assumed. This
will probably be "C:\Program Files\MariaDB\MariaDB Connector C" for
mariadbclient and "C:\Program Files\MySQL\MySQL Connector C 6.1" for
mysqlclient ("C:\Program Files (x86)" will be used on 32-bit builds). If
neither client nor connector are specified, both client types will be checked
to see if the appropriate .lib file exists in the default connector
directory. These changes will allow users to install from source via pip
(if binary wheels aren't available) without having to clone this repo to edit
site.cfg. They can either install one of the connectors in the default
location or install it somewhere else and set the path in the
`MYSQLCLIENT_CONNECTOR` environment variable before installing.

One other slight change was to add additional install and library directories
for mariadbclient. This is because the pre-built connector binaries install
the needed files in `include` and `lib` whereas building from source
(like this repo's workflow does) leaves them in `include/mariadb` and
`lib/mariadb`.
setup_windows.py Outdated Show resolved Hide resolved
MySQL Connector/C is not longer published since 2017. New builds are always
done against MariaDB Connector/C. Dropping support for the deprecated
MySQL Connector simplifies the Windows build process.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants