-
Notifications
You must be signed in to change notification settings - Fork 73
Description
Hello. In Fedora, we use the PEP 517 get_requires_for_build_wheel hook to gather the build dependencies.
With a project that uses setuptools.setup(cffi_modules=...), calling such hooks attempts to build the CFFI modules. That seems unexpected, as calling get_requires_for_build_wheel should not compile stuff.
To reproduce, I use the https://github.com/anrieff/libcpuid project at the current master branch:
$ git clone https://github.com/anrieff/libcpuid
$ cd libcpuid
[libcpuid (master)]$ uv venv --python=python3.13 venv
[libcpuid (master)]$ . venv/bin/activate
(venv) [libcpuid (master)]$ uv pip install pyproject_hooks setuptools cffi
+ cffi==1.17.1
+ pycparser==2.22
+ pyproject-hooks==1.2.0
+ setuptools==80.9.0
(venv) [libcpuid (master)]$ cd python/
(venv) [python (master)]$ LANG=C.utf-8 python
Python 3.13.7 (main, Aug 14 2025, 00:00:00) [GCC 14.3.1 20250523 (Red Hat 14.3.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyproject_hooks import BuildBackendHookCaller
>>> hook_caller = BuildBackendHookCaller('.', 'setuptools.build_meta')
>>> hook_caller.get_requires_for_build_wheel()
/usr/bin/ld: cannot find -lcpuid: No such file or directory
collect2: error: ld returned 1 exit status
Traceback (most recent call last):
File ".../libcpuid/venv/lib64/python3.13/site-packages/pyproject_hooks/_in_process/_in_process.py", line 389, in <module>
main()
~~~~^^
File ".../libcpuid/venv/lib64/python3.13/site-packages/pyproject_hooks/_in_process/_in_process.py", line 373, in main
json_out["return_val"] = hook(**hook_input["kwargs"])
~~~~^^^^^^^^^^^^^^^^^^^^^^^^
File ".../libcpuid/venv/lib64/python3.13/site-packages/pyproject_hooks/_in_process/_in_process.py", line 143, in get_requires_for_build_wheel
return hook(config_settings)
File ".../libcpuid/venv/lib64/python3.13/site-packages/setuptools/build_meta.py", line 331, in get_requires_for_build_wheel
return self._get_build_requires(config_settings, requirements=[])
~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../libcpuid/venv/lib64/python3.13/site-packages/setuptools/build_meta.py", line 301, in _get_build_requires
self.run_setup()
~~~~~~~~~~~~~~^^
File ".../libcpuid/venv/lib64/python3.13/site-packages/setuptools/build_meta.py", line 317, in run_setup
exec(code, locals())
~~~~^^^^^^^^^^^^^^^^
File "<string>", line 3, in <module>
File ".../libcpuid/venv/lib64/python3.13/site-packages/setuptools/__init__.py", line 115, in setup
return distutils.core.setup(**attrs)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
File ".../libcpuid/venv/lib64/python3.13/site-packages/setuptools/_distutils/core.py", line 148, in setup
_setup_distribution = dist = klass(attrs)
~~~~~^^^^^^^
File ".../libcpuid/venv/lib64/python3.13/site-packages/setuptools/dist.py", line 321, in __init__
_Distribution.__init__(self, dist_attrs)
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
File ".../libcpuid/venv/lib64/python3.13/site-packages/setuptools/_distutils/dist.py", line 309, in __init__
self.finalize_options()
~~~~~~~~~~~~~~~~~~~~~^^
File ".../libcpuid/venv/lib64/python3.13/site-packages/setuptools/dist.py", line 784, in finalize_options
ep(self)
~~^^^^^^
File ".../libcpuid/venv/lib64/python3.13/site-packages/setuptools/dist.py", line 804, in _finalize_setup_keywords
ep.load()(self, ep.name, value)
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File ".../libcpuid/venv/lib64/python3.13/site-packages/cffi/setuptools_ext.py", line 216, in cffi_modules
add_cffi_module(dist, cffi_module)
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
File ".../libcpuid/venv/lib64/python3.13/site-packages/cffi/setuptools_ext.py", line 49, in add_cffi_module
execfile(build_file_name, mod_vars)
~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../libcpuid/venv/lib64/python3.13/site-packages/cffi/setuptools_ext.py", line 25, in execfile
exec(code, glob, glob)
~~~~^^^^^^^^^^^^^^^^^^
File "src/libcpuid/_ffi_build.py", line 90, in <module>
NO_SIZEOF_HEADER = eval_sizeofs(PREPROCESSED_HEADER, EVAL_SIZEOF_CFLAGS)
File "src/libcpuid/_ffi_build.py", line 62, in eval_sizeofs
subprocess.check_call(["gcc", c_program_path, *cflags, "-o", executable_path])
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.13/subprocess.py", line 419, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['gcc', PosixPath('/tmp/tmpvmg_lwo9/sizeof.c'), '-I.../libcpuid/libcpuid', '-L.../libcpuid/libcpuid/.libs', '-lcpuid', '-Wl,-rpath=.../libcpuid/libcpuid/.libs', '-o', PosixPath('/tmp/tmpvmg_lwo9/sizeof')]' returned non-zero exit status 1.
Traceback (most recent call last):
File "<python-input-2>", line 1, in <module>
hook_caller.get_requires_for_build_wheel()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File ".../libcpuid/venv/lib64/python3.13/site-packages/pyproject_hooks/_impl.py", line 196, in get_requires_for_build_wheel
return self._call_hook(
~~~~~~~~~~~~~~~^
"get_requires_for_build_wheel", {"config_settings": config_settings}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File ".../libcpuid/venv/lib64/python3.13/site-packages/pyproject_hooks/_impl.py", line 392, in _call_hook
self._subprocess_runner(
~~~~~~~~~~~~~~~~~~~~~~~^
[python, abspath(str(script)), hook_name, td],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cwd=self.source_dir,
^^^^^^^^^^^^^^^^^^^^
extra_environ=extra_environ,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File ".../libcpuid/venv/lib64/python3.13/site-packages/pyproject_hooks/_impl.py", line 83, in default_subprocess_runner
check_call(cmd, cwd=cwd, env=env)
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.13/subprocess.py", line 419, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['.../libcpuid/venv/bin/python', '.../libcpuid/venv/lib64/python3.13/site-packages/pyproject_hooks/_in_process/_in_process.py', 'get_requires_for_build_wheel', '/tmp/tmpvtcdk7vc']' returned non-zero exit status 1.
Expected results: ['setuptools, 'cffi']
Note that in Fedora, we don't have -lcpuid yet at this point because the library is built as part of the same Fedora package, and when we gather the dependencies, we haven't yet built the library. But that's not the point. The point is, building any code with gcc during get_requires_for_build_wheel or prepare_metadata_for_build_wheel hooks is unexpected.