Skip to content

Commit

Permalink
Fix the GLPK build on Windows for setuptools>74.0 (#106)
Browse files Browse the repository at this point in the history
* update the MSVC detection

* start debug

* start debug

* start debug

* start debug

* try the dumbest thing possible

* try the dumbest thing possible

* try the dumbest thing possible

* try the dumbest thing possible

* try the dumbest thing possible

* try the dumbest thing possible

* try the dumbest thing possible

* add a vcvarsall finder

* try with best guess and fallback

* try with best guess and fallback

* use correct path for search

* bump cibuildwheel
  • Loading branch information
cdiener authored Nov 20, 2024
1 parent 234c338 commit 378d8ac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
platforms: all

- name: Build wheels
uses: pypa/cibuildwheel@v2.20.0
uses: pypa/cibuildwheel@v2.21.3
env:
NEW_GLPK_VERSION: ${{ inputs.glpk_version }}
GLPK_HEADER_PATH: glpk-${{ inputs.glpk_version }}/src
Expand Down
43 changes: 16 additions & 27 deletions scripts/build_glpk.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,33 @@
# taken from https://github.com/opencobra/cobrapy/blob/devel/appveyor/build_glpk.py

import os
import sys
# import hashlib
import tarfile
import struct
import shutil
import setuptools.msvc
import urllib.request as urllib2
import subprocess

GUESS_VCVARS = (
"C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\"
"VC\\Auxiliary\\Build\\vcvarsall.bat"
)

# these need to be set to the latest glpk version
glpk_version = os.getenv('NEW_GLPK_VERSION')
# glpk_md5 = "eda7965907f6919ffc69801646f13c3e"

glpk_build_dir = "glpk_build/glpk-%s" % glpk_version
url = "http://ftp.gnu.org/gnu/glpk/glpk-%s.tar.gz" % glpk_version
bitness = struct.calcsize("P") * 8
arch = "x86_amd64" if bitness == 64 else "x86"


# def md5(fname):
# hash = hashlib.md5()
# with open(fname, "rb") as f:
# for chunk in iter(lambda: f.read(4096), b""):
# hash.update(chunk)
# return hash.hexdigest()


def get_vcvarsall_cmd():
py_ver = sys.version_info
if py_ver.major == 3 and py_ver.minor >= 5:
vc_ver = 14
elif py_ver.major == 3 and py_ver.minor >= 3:
vc_ver = 10
else:
vc_ver = 9
vc_path = setuptools.msvc.msvc9_find_vcvarsall(vc_ver)
assert vc_path is not None
return '"%s" %s' % (vc_path, " amd64" if bitness == 64 else "")
def find_vcvarsall():
if os.path.isfile(GUESS_VCVARS):
return(GUESS_VCVARS)
for root, _, files in os.walk("C:\\Program Files\\Microsoft Visual Studio\\"):
for f in files:
if f == "vcvarsall.bat":
return(os.path.join(root, f))
raise RuntimeError("Could not find vcvarsall.bat :(")


if not os.path.isdir("glpk_build/"):
Expand All @@ -54,10 +43,10 @@ def get_vcvarsall_cmd():
os.chdir("%s/w%d" % (glpk_build_dir, bitness))
if not os.path.isfile("glpk.lib"):
shutil.copy2("config_VC", "config.h")
os.environ.update(setuptools.msvc.msvc14_get_vc_env(arch))
vc_setup = find_vcvarsall()
subprocess.run(
["nmake", "/f", "Makefile_VC"],
check=True,
f'"{vc_setup}" {arch} & nmake /f Makefile_VC',
check=True, shell=True
)
shutil.copy2("glpk.lib", "../../..")
os.chdir("../../..")
Expand Down

0 comments on commit 378d8ac

Please sign in to comment.