Skip to content

[Bug]: with setuptools>=60, cannot find msbuild #23147

Closed
@QuLogic

Description

@QuLogic

In testing out #23146, I've been unable to fully update cibuildwheel because Windows builds fail. They cannot find msbuild with cibuildwheel >= 2.4.0. I originally filed this with cibuildwheel (pypa/cibuildwheel#1118), but further investigation shows this is a problem outside of cibuildwheel.

I modified our GitHub Action to only install on Windows, and it fails to build as well. From bisecting cibuildwheel, I know that this came about from setuptools 60, which has the change:

#2896: Setuptools once again makes its local copy of distutils the default. To override, set SETUPTOOLS_USE_DISTUTILS=stdlib.

Setting the override variable does fix the build, but I don't think that should be our preferred option.

I think this comes about from our hacky attempt to find a compiler search path:

matplotlib/setupext.py

Lines 528 to 548 in 6296e50

def get_ccompiler():
"""
Return a new CCompiler instance.
CCompiler used to be constructible via `distutils.ccompiler.new_compiler`,
but this API was removed as part of the distutils deprecation. Instead,
we trick setuptools into instantiating it by creating a dummy Distribution
with a list of extension modules that claims to be truthy, but is actually
empty, and then running the Distribution's build_ext command. (If using
a plain empty ext_modules, build_ext would early-return without doing
anything.)
"""
class L(list):
def __bool__(self):
return True
build_ext = Distribution({"ext_modules": L()}).get_command_obj("build_ext")
build_ext.finalize_options()
build_ext.run()
return build_ext.compiler

matplotlib/setupext.py

Lines 693 to 705 in 6296e50

cc = get_ccompiler()
cc.initialize() # Get msbuild in the %PATH% of cc.spawn.
# Freetype 2.10.0+ support static builds.
msbuild_config = (
"Release Static"
if [*map(int, LOCAL_FREETYPE_VERSION.split("."))] >= [2, 10]
else "Release"
)
cc.spawn(["msbuild", str(sln_path),
"/t:Clean;Build",
f"/p:Configuration={msbuild_config};"
f"Platform={msbuild_platform}"])

but I don't know what we can do to fix it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BuildRelease criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions