Project

General

Profile

Actions

Bug #20494

closed

Non-default directories are not searched when checking for a gmp header

Added by lish82 (Hiroki Katagiri) 7 months ago. Updated 6 months ago.

Status:
Closed
Target version:
-
[ruby-core:117918]

Description

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

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

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


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #20515: --with-gmp is not working - GMP support won't be builtClosedsorah (Sorah Fukumori)Actions

Updated by mame (Yusuke Endoh) 7 months ago

  • Status changed from Open to Assigned
  • Assignee set to nobu (Nobuyoshi Nakada)

Looks good to me. I found no other AC_CHECK_HEADERS that might want to find non-system header files. @nobu (Nobuyoshi Nakada) What do you think?

Updated by nobu (Nobuyoshi Nakada) 7 months ago

Made a separate macro.

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])
Actions #3

Updated by nobu (Nobuyoshi Nakada) 7 months ago

  • Status changed from Assigned to Closed

Applied in changeset git|18eaf0be905e3e251423b42d6f4e56b7cae1bc3b.


[Bug #20494] Search non-default directories for GMP

Co-Authored-by: lish82 (Hiroki Katagiri)

Updated by hsbt (Hiroshi SHIBATA) 7 months ago

What's your ruby-build version? ruby-build already have auto-detect feature for gmp provided by homebrew

https://github.com/rbenv/ruby-build/blob/master/bin/ruby-build#L1034

Updated by hsbt (Hiroshi SHIBATA) 7 months ago

Specifying --with-gmp-dir=/opt/homebrew does not work

Ah, sorry. I skipped to read above report. It seems not only ruby-build issue.

Updated by lish82 (Hiroki Katagiri) 7 months ago

@nobu (Nobuyoshi Nakada)
Thank you for your quick fix!

Updated by lish82 (Hiroki Katagiri) 7 months ago

@nobu (Nobuyoshi Nakada)
I just realized, isn't it necessary to backport this change to 3.2.x?
Since this bug seems to be present since 3.2.3, and 3.2.x has not yet reached EOL

I'm sorry if this has already been addressed

Actions #8

Updated by hsbt (Hiroshi SHIBATA) 7 months ago

  • Backport changed from 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN to 3.1: UNKNOWN, 3.2: REQUIRED, 3.3: REQUIRED

Updated by k0kubun (Takashi Kokubun) 7 months ago

  • Backport changed from 3.1: UNKNOWN, 3.2: REQUIRED, 3.3: REQUIRED to 3.1: UNKNOWN, 3.2: REQUIRED, 3.3: DONE
Actions #10

Updated by sorah (Sorah Fukumori) 7 months ago

  • Related to Bug #20515: --with-gmp is not working - GMP support won't be built added

Updated by sorah (Sorah Fukumori) 7 months ago

The committed patch broke --with-gmp entirely, be advised https://bugs.ruby-lang.org/issues/20515 is required when backporting this to 3.2.

3.3 backport is also requested at #20515.

Updated by nagachika (Tomoyuki Chikanaga) 6 months ago

  • Backport changed from 3.1: UNKNOWN, 3.2: REQUIRED, 3.3: DONE to 3.1: UNKNOWN, 3.2: DONE, 3.3: DONE
Actions

Also available in: Atom PDF

Like0
Like0Like1Like0Like0Like1Like0Like0Like0Like0Like0Like1Like0