`cffi` failing to build due to missing `ffi.h`
Metadata
Current evaluation
cffi failed to build in charm builds because ffi.h was missing. Fixed by merged PR #2043 (commit 47fb62f3), which added libffi-dev to the charm part's build-packages.
Resolution: closed resolved
Reason: PR #2043 'fix: include libffi-dev in charm part build-packages' was merged as commit 47fb62f3 and explicitly fixes #2023. The fix is present in charmcraft/parts/plugins/_charm.py get_build_packages() and was released in Charmcraft 3.3/3.4 (release notes cite #2081 for the same libffi-dev fix).
Evaluated by: mr-cal-bot
No scores available.
Issue body
### Bug Description
An upstream change (unsure whether it's in the build images or the charm dependency) has caused the `cffi` wheel (needed for building `cryptography`, `pydantic`, etc.) to stop building.
# WORKAROUND:
Add `libffi-dev` to the part's `build-packages`
### To Reproduce
`charmcraft init && charmcraft pack`
### Environment
CI
### charmcraft.yaml
```yaml
Any default template
```
### Relevant log output
```shell
https://github.com/canonical/charmcraft/actions/runs/12259404057/job/34202679691?pr=2021
:: :: Building wheels for collected packages: maturin, cffi, pycparser
:: :: Building wheel for maturin (pyproject.toml): started
:: :: Building wheel for maturin (pyproject.toml): still running...
:: :: Building wheel for maturin (pyproject.toml): still running...
:: :: Building wheel for maturin (pyproject.toml): still running...
:: :: Building wheel for maturin (pyproject.toml): still running...
:: :: Building wheel for maturin (pyproject.toml): still running...
:: :: Building wheel for maturin (pyproject.toml): still running...
:: :: Building wheel for maturin (pyproject.toml): still running...
:: :: Building wheel for maturin (pyproject.toml): still running...
:: :: Building wheel for maturin (pyproject.toml): finished with status 'done'
:: :: Created wheel for maturin: filename=maturin-1.7.8-cp312-cp312-linux_x86_64.whl size=5996692 sha256=a72b6ab61ac975c2b3c64900a3295c6ad18bb90eaaa61e748900b089468b4e28
:: :: Stored in directory: /root/.cache/pip/wheels/1b/99/52/a31a2e02e21e6b96dcca2e8341ee674b7fc59d8e60495b331b
:: :: Building wheel for cffi (pyproject.toml): started
:: :: Building wheel for cffi (pyproject.toml): finished with status 'error'
:: :: error: subprocess-exited-with-error
:: ::
:: :: × Building wheel for cffi (pyproject.toml) did not run successfully.
:: :: │ exit code: 1
:: :: ╰─> [35 lines of output]
:: :: running bdist_wheel
:: :: running build
:: :: running build_py
:: :: creating build/lib.linux-x86_64-cpython-312/cffi
:: :: copying src/cffi/backend_ctypes.py -> build/lib.linux-x86_64-cpython-312/cffi
:: :: copying src/cffi/vengine_cpy.py -> build/lib.linux-x86_64-cpython-312/cffi
:: :: copying src/cffi/_shimmed_dist_utils.py -> build/lib.linux-x86_64-cpython-312/cffi
:: :: copying src/cffi/commontypes.py -> build/lib.linux-x86_64-cpython-312/cffi
:: :: copying src/cffi/error.py -> build/lib.linux-x86_64-cpython-312/cffi
:: :: copying src/cffi/api.py -> build/lib.linux-x86_64-cpython-312/cffi
:: :: copying src/cffi/recompiler.py -> build/lib.linux-x86_64-cpython-312/cffi
:: :: copying src/cffi/cffi_opcode.py -> build/lib.linux-x86_64-cpython-312/cffi
:: :: copying src/cffi/model.py -> build/lib.linux-x86_64-cpython-312/cffi
:: :: copying src/cffi/setuptools_ext.py -> build/lib.linux-x86_64-cpython-312/cffi
:: :: copying src/cffi/lock.py -> build/lib.linux-x86_64-cpython-312/cffi
:: :: copying src/cffi/cparser.py -> build/lib.linux-x86_64-cpython-312/cffi
:: :: copying src/cffi/__init__.py -> build/lib.linux-x86_64-cpython-312/cffi
:: :: copying src/cffi/vengine_gen.py -> build/lib.linux-x86_64-cpython-312/cffi
:: :: copying src/cffi/verifier.py -> build/lib.linux-x86_64-cpython-312/cffi
:: :: copying src/cffi/ffiplatform.py -> build/lib.linux-x86_64-cpython-312/cffi
:: :: copying src/cffi/pkgconfig.py -> build/lib.linux-x86_64-cpython-312/cffi
:: :: copying src/cffi/_imp_emulation.py -> build/lib.linux-x86_64-cpython-312/cffi
:: :: copying src/cffi/_cffi_include.h -> build/lib.linux-x86_64-cpython-312/cffi
:: :: copying src/cffi/parse_c_type.h -> build/lib.linux-x86_64-cpython-312/cffi
:: :: copying src/cffi/_embedding.h -> build/lib.linux-x86_64-cpython-312/cffi
:: :: copying src/cffi/_cffi_errors.h -> build/lib.linux-x86_64-cpython-312/cffi
:: :: running build_ext
:: :: building '_cffi_backend' extension
:: :: creating build/temp.linux-x86_64-cpython-312/src/c
:: :: x86_64-linux-gnu-gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O2 -Wall -fPIC -DFFI_BUILDING=1 -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/root/parts/charm/build/staging-venv/include -I/usr/include/python3.12 -c src/c/_cffi_backend.c -o build/temp.linux-x86_64-cpython-312/src/c/_cffi_backend.o
:: :: src/c/_cffi_backend.c:15:10: fatal error: ffi.h: No such file or directory
:: :: 15 | #include <ffi.h>
:: :: | ^~~~~~~
:: :: compilation terminated.
:: :: error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
:: :: [end of output]
:: ::
:: :: note: This error originates from a subprocess, and is likely not a problem with pip.
:: :: ERROR: Failed building wheel for cffi
:: :: Building wheel for pycparser (setup.py): started
:: :: Building wheel for pycparser (setup.py): finished with status 'done'
:: :: Created wheel for pycparser: filename=pycparser-2.22-py3-none-any.whl size=117553 sha256=2f43070a50418a1ce4b86c2a7807934d2f2c1d028e3e577eecdb4944ae399ff3
:: :: Stored in directory: /root/.cache/pip/wheels/36/53/17/c0ae2e096d359a9a8faf47fd7ded8f4c878af41a3c66cb5199
:: :: Successfully built maturin pycparser
:: :: Failed to build cffi
:: :: ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (cffi)
```
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| stealth/space-bunny-alpha | — | closed resolved | cffi failed to build in charm builds because ffi.h was missing. Fixed by merged PR #2043 (commit 47fb62f3), which added libffi-dev to the charm part's build-packages. | |
| stealth/space-bunny-alpha | — | closed resolved | Fixed by merged PR #2043 (commit 47fb62f3), adding libffi-dev to charm-part build packages so cffi can find ffi.h. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Closed without code changes. The author provided a workaround to add libffi-dev to build-packages, resolving the cffi compilation failure. No fix was merged; the issue was closed as resolved via the workaround. | |
| qwen/qwen3.6-35b-a3b | — | — | Closed without a code fix. A workaround was provided to add libffi-dev to the part's build-packages to resolve the cffi build failure caused by a missing ffi.h header in the build environment. | |
| qwen/qwen3.6-35b-a3b | — | — | Closed. Resolved via the author-provided workaround: adding libffi-dev to build-packages fixes the missing ffi.h error during cffi compilation. No code changes were merged. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Closed without a code fix. The reporter provided a workaround to add libffi-dev to build-packages, resolving the CI failure. The issue was closed after automated Jira syncs, indicating the workaround was accepted. |
Update history
No update history recorded yet.
Related work
-
Likely Fixed By:
canonical/charmcraft#2043
(confidence 99%)
Merged PR adding libffi-dev to the charm part build-packages, fixes #2023.
-
Related To:
canonical/charmcraft#2081
(confidence 90%)
Duplicate report of the same missing libffi-dev failure; also fixed by #2043 and listed in the 3.4.0 release notes.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #2043 fix: include libffi-dev in charm part build-packages | charmcraft | merged | Merged PR #2043 as commit 47fb62f3, adding libffi-dev to charm-part build packages so cffi builds can find ffi.h. Fixes #2023. | |
| #2081 `charmcraft pack` fail while packing `cos-proxy-operator` | charmcraft | closed | Fixed by PR #2043 (commit 47fb62f3), which adds libffi-dev to the charm part's build-packages so cffi builds find ffi.h. Shipped in Charmcraft 3.3; maintainer closed the issue, marking the 2.7 path WONTFIX. |