[ruby-core:117931] [Ruby master Bug#20494] Non-default directories are not searched when checking for a gmp header
From:
"nobu (Nobuyoshi Nakada) via ruby-core" <ruby-core@...>
Date:
2024-05-20 02:49:04 UTC
List:
ruby-core #117931
Issue #20494 has been updated by nobu (Nobuyoshi Nakada).
Made a separate macro.
```diff
commit a0d3cda4b54ce3eb9e77a450462a47fc3944d93c
Author: Nobuyoshi Nakada <nobu@ruby-lang.org>
AuthorDate: 2024-05-20 11:44:27 +0900
Commit: Nobuyoshi Nakada <nobu@ruby-lang.org>
CommitDate: 2024-05-20 11:44:27 +0900
[Bug #20494] Search non-default directories for GMP
Co-Authored-by: lish82 (Hiroki Katagiri)
diff --git a/configure.ac b/configure.ac
index e9a452ebee2..09f95b2bece 100644
--- a/configure.ac
+++ b/configure.ac
@@ -16,6 +16,7 @@ m4_include([tool/m4/ruby_append_option.m4])dnl
m4_include([tool/m4/ruby_append_options.m4])dnl
m4_include([tool/m4/ruby_check_builtin_func.m4])dnl
m4_include([tool/m4/ruby_check_builtin_setjmp.m4])dnl
+m4_include([tool/m4/ruby_check_header.m4])dnl
m4_include([tool/m4/ruby_check_printf_prefix.m4])dnl
m4_include([tool/m4/ruby_check_setjmp.m4])dnl
m4_include([tool/m4/ruby_check_signedness.m4])dnl
@@ -1375,7 +1376,7 @@ AS_CASE("$target_cpu", [x64|x86_64|i[3-6]86*], [
RUBY_UNIVERSAL_CHECK_HEADER([x86_64, i386], x86intrin.h)
AS_IF([test "x$with_gmp" != xno],
- [AC_CHECK_HEADERS(gmp.h)
+ [RUBY_CHECK_HEADER(gmp.h)
AS_IF([test "x$ac_cv_header_gmp_h" != xno],
AC_SEARCH_LIBS([__gmpz_init], [gmp],
[AC_DEFINE(HAVE_LIBGMP, 1)]))])
diff --git a/tool/m4/ruby_check_header.m4 b/tool/m4/ruby_check_header.m4
new file mode 100644
index 00000000000..171455549e3
--- /dev/null
+++ b/tool/m4/ruby_check_header.m4
@@ -0,0 +1,8 @@
+dnl -*- Autoconf -*-
+AC_DEFUN([RUBY_CHECK_HEADER],
+ [# RUBY_CHECK_HEADER($@)
+ save_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS m4_if([$5], [], [$INCFLAGS], [$5])"
+ AC_CHECK_HEADER([$1], [$2], [$3], [$4])
+ CPPFLAGS="$save_CPPFLAGS"
+ unset save_CPPFLAGS])
```
----------------------------------------
Bug #20494: Non-default directories are not searched when checking for a gmp header
https://bugs.ruby-lang.org/issues/20494#change-108343
* Author: lish82 (Hiroki Katagiri)
* Status: Assigned
* Assignee: nobu (Nobuyoshi Nakada)
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
This is my very first issue submission
I would be happy to know if I missed anything
---
I found that the ruby installed with `ruby-build` is not linked to the gmp library
Environment:
- OS: macOS Sonoma 14.5
- Directory that gmp is installed: /opt/homebrew (= installed via homebrew)
I believe it was able to link to gmp before, so I tried to investigate the cause of the problem
As a result, I found the followings:
- During the execution of `./configure`, `checking for gmp.h...` is showing `no`
- Specifying `--with-gmp-dir=/opt/homebrew` does not work
- It has been occurring since 3.2.3
- When I built it on linux, it was successfully linked to gmp
- gmp was installed in the default directory (`/usr/include`)
- Revert the following changes and the problem goes away
- https://github.com/ruby/ruby/pull/8449
Based on these observations, I believe the issue is that the directories specified with `--with-opt-dir` or `--with-gmp-dir` are not being included in the search path when checking for the gmp header
I was able to solve the problem by changing the build process as follows
```patch
diff --git a/configure.ac b/configure.ac
index 18b4247..a440de6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1363,7 +1363,11 @@ AS_CASE("$target_cpu", [x64|x86_64|i[3-6]86*], [
RUBY_UNIVERSAL_CHECK_HEADER([x86_64, i386], x86intrin.h)
AS_IF([test "x$with_gmp" != xno],
- [AC_CHECK_HEADERS(gmp.h)
+ [original_CPPFLAGS="${CPPFLAGS}"
+ CPPFLAGS="${INCFLAGS} ${CPPFLAGS}"
+ AC_CHECK_HEADERS(gmp.h)
+ CPPFLAGS="${original_CPPFLAGS}"
+ unset original_CPPFLAGS
AS_IF([test "x$ac_cv_header_gmp_h" != xno],
AC_SEARCH_LIBS([__gmpz_init], [gmp],
[AC_DEFINE(HAVE_LIBGMP, 1)]))])
```
However, I am not familiar with ruby's build process or autotools, so I'm not sure if this is the correct approach
---
I would appreciate it if someone could consider resolving this issue
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/