From baf65b91c51bb04b09ecc98b94ddd4ba3b446912 Mon Sep 17 00:00:00 2001 From: David Allsopp Date: Sat, 20 Apr 2024 07:33:25 +0100 Subject: [PATCH] Merge pull request #13100 from dra27/zstd-runs Fix detection of zstd when compiling with musl-gcc (cherry picked from commit d784a6951fdb97fd7531d1c5efee45f6291447fb) --- configure | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 38 ++++++++++++++++++++++++ 2 files changed, 122 insertions(+) diff --git a/configure b/configure index d36802ae9823ce36b50ca4733fe4d502a39f0f36..b45d5873a5aafebf58af98a765c22057a6b97d91 100755 --- a/configure +++ b/configure @@ -18303,6 +18303,90 @@ fi fi fi +# When building the mingw-w64 port in Cygwin, it is very easy to have the +# library available, but not have the DLL in PATH. This then causes the build to +# fail as soon as ocamlrun is first executed. This check avoids automatically +# enabling zstd when the resulting executable doesn't actually work. +case $host in #( + *-w64-mingw32*|*-pc-windows) : + check_zstd_runs=$host_runnable ;; #( + *) : + check_zstd_runs=false ;; +esac + +if test x"$zstd_status" = "xok" +then : + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether programs can be linked with zstd" >&5 +printf %s "checking whether programs can be linked with zstd... " >&6; } + + saved_CC="$CC" + saved_CFLAGS="$CFLAGS" + saved_CPPFLAGS="$CPPFLAGS" + saved_LIBS="$LIBS" + saved_ac_ext="$ac_ext" + saved_ac_compile="$ac_compile" + # Move the content of confdefs.h to another file so it does not + # get included + mv confdefs.h confdefs.h.bak + touch confdefs.h + + LIBS="$LIBS $zstd_libs" + CFLAGS="$CFLAGS $zstd_flags" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include +int main(void) { + return (ZSTD_versionNumber() == 0); +} + +_ACEOF +if ac_fn_c_try_link "$LINENO" +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether programs linked with zstd can execute" >&5 +printf %s "checking whether programs linked with zstd can execute... " >&6; } + if $check_zstd_runs +then : + if ac_fn_c_try_run LINENO +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } + zstd_libs='' + zstd_flags='' + zstd_status=\ +"programs linked with zstd do not appear to be executable." +fi +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: skipped" >&5 +printf "%s\n" "skipped" >&6; } +fi +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } + zstd_libs='' + zstd_flags='' + zstd_status="zstd found, but programs cannot be linked with it." +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext + + # Restore the content of confdefs.h + mv confdefs.h.bak confdefs.h + ac_compile="$saved_ac_compile" + ac_ext="$saved_ac_ext" + CPPFLAGS="$saved_CPPFLAGS" + CFLAGS="$saved_CFLAGS" + CC="$saved_CC" + LIBS="$saved_LIBS" + +fi + if test x"$zstd_status" = "xok" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: compressed compilation artefacts supported" >&5 diff --git a/configure.ac b/configure.ac index b81da53c4292f464967575958bb69a00bd7f1907..041885d6deb1ee2de8ff8ec4a2aecb85f6b47bb0 100644 --- a/configure.ac +++ b/configure.ac @@ -1995,6 +1995,44 @@ AS_IF([test x"$with_zstd" != "xno"], [[#include ]])], [zstd_status="zstd library not found"])])) +# When building the mingw-w64 port in Cygwin, it is very easy to have the +# library available, but not have the DLL in PATH. This then causes the build to +# fail as soon as ocamlrun is first executed. This check avoids automatically +# enabling zstd when the resulting executable doesn't actually work. +AS_CASE([$host], + [*-w64-mingw32*|*-pc-windows], + [check_zstd_runs=$host_runnable], + [check_zstd_runs=false]) + +AS_IF([test x"$zstd_status" = "xok"],[ + AC_MSG_CHECKING([whether programs can be linked with zstd]) + OCAML_CC_SAVE_VARIABLES + LIBS="$LIBS $zstd_libs" + CFLAGS="$CFLAGS $zstd_flags" + AC_LINK_IFELSE( + [AC_LANG_SOURCE([[ +#include +int main(void) { + return (ZSTD_versionNumber() == 0); +} + ]])], + [AC_MSG_RESULT([yes]) + AC_MSG_CHECKING([whether programs linked with zstd can execute]) + AS_IF([$check_zstd_runs], + [AS_IF([ac_fn_c_try_run LINENO], + [AC_MSG_RESULT([yes])], + [AC_MSG_RESULT([no]) + zstd_libs='' + zstd_flags='' + zstd_status=\ +"programs linked with zstd do not appear to be executable."])], + [AC_MSG_RESULT([skipped])])], + [AC_MSG_RESULT([no]) + zstd_libs='' + zstd_flags='' + zstd_status="zstd found, but programs cannot be linked with it."]) + OCAML_CC_RESTORE_VARIABLES]) + AS_IF([test x"$zstd_status" = "xok"], [AC_MSG_NOTICE([compressed compilation artefacts supported]) internal_cppflags="$internal_cppflags $zstd_flags"