configure should check for existence of ffi.h
Summary
Running ./configure checks for the system FFI library, but doesn't (correctly) check for the corresponding header file ffi.h. If the library is found but the header does not exist, this will result in Error, file does not exist and no rule available: ffi.h when using hadrian.
Analysis
The check is implemented here https://gitlab.haskell.org/ghc/ghc/-/blob/4a7809284354025d07221f0aeca10a7992d23677/m4/fp_find_libffi.m4#L61-64
AC_CHECK_LIB(ffi, ffi_call,
[AC_CHECK_HEADERS([ffi.h], [break], [])
AC_DEFINE([HAVE_SYSTEM_LIBFFI], [1], [Define to 1 if you have libffi.])],
[AC_MSG_ERROR([Cannot find system libffi])])
and that [break] does not skip the definition of HAVE_SYSTEM_LIBFFI; it only breaks out of the loop that implements AC_CHECK_HEADERS (with autoconf 2.71):
#...
for ac_header in ffi.h
do :
ac_fn_c_check_header_compile "$LINENO" "ffi.h" "ac_cv_header_ffi_h" "$ac_includes_default"
if test "x$ac_cv_header_ffi_h" = xyes
then :
printf "%s\n" "#define HAVE_FFI_H 1" >>confdefs.h
break
fi
done
#...
Proposed fix:
AC_CHECK_LIB(ffi, ffi_call,
[AC_CHECK_HEADERS([ffi.h],
[AC_DEFINE([HAVE_SYSTEM_LIBFFI], [1], [Define to 1 if you have libffi.])],
[AC_MSG_ERROR([Cannot find ffi.h for system libffi])])],
[AC_MSG_ERROR([Cannot find system libffi])])
Note that there is a second instance of this pattern at https://gitlab.haskell.org/ghc/ghc/-/blob/4a7809284354025d07221f0aeca10a7992d23677/m4/fp_find_libdw.m4#L39-42
Environment
- GHC version used: 9.4-alpha1
Optional:
- Operating System: Linux
Edited by Bertram Felgenhauer