nginx/unit

Ruby 3.x module on Mac OS failing to build

Closed this issue · 10 comments

Trying to compile the Ruby module on Mac OS and Ruby 3.1.1 (3.0.3 is the ~same) results in the following:

configuring Ruby module ...
ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x86_64-darwin21]
----------------------------------------
checking for Ruby library
In file included from build/autotest.c:2:
In file included from /Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby.h:38:
In file included from /Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/ruby.h:25:
In file included from /Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/defines.h:73:
In file included from /Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/backward/2/attributes.h:42:
In file included from /Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/internal/attr/pure.h:25:
/Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/assert.h:132:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes
RBIMPL_ATTR_NORETURN()
^
/Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/internal/attr/noreturn.h:29:33: note: expanded from macro 'RBIMPL_ATTR_NORETURN'
# define RBIMPL_ATTR_NORETURN() __declspec(noreturn)
                                ^
In file included from build/autotest.c:2:
In file included from /Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby.h:38:
In file included from /Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/ruby.h:26:
In file included from /Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/internal/anyargs.h:77:
/Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/internal/intern/vm.h:383:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes
RBIMPL_ATTR_NORETURN()
^
/Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/internal/attr/noreturn.h:29:33: note: expanded from macro 'RBIMPL_ATTR_NORETURN'
# define RBIMPL_ATTR_NORETURN() __declspec(noreturn)
                                ^
In file included from build/autotest.c:2:
In file included from /Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby.h:38:
In file included from /Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/ruby.h:27:
In file included from /Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/internal/arithmetic.h:23:
In file included from /Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/internal/arithmetic/char.h:23:
In file included from /Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/internal/arithmetic/int.h:26:
/Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/internal/arithmetic/long.h:70:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes
RBIMPL_ATTR_NORETURN()
^
/Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/internal/attr/noreturn.h:29:33: note: expanded from macro 'RBIMPL_ATTR_NORETURN'
# define RBIMPL_ATTR_NORETURN() __declspec(noreturn)
                                ^
In file included from build/autotest.c:2:
In file included from /Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby.h:38:
In file included from /Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/ruby.h:27:
In file included from /Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/internal/arithmetic.h:23:
In file included from /Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/internal/arithmetic/char.h:29:
In file included from /Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/internal/core/rstring.h:28:
/Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/internal/core/rbasic.h:63:14: error: expected parameter declarator
RUBY_ALIGNAS(SIZEOF_VALUE)
             ^
/Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/internal/value.h:106:23: note: expanded from macro 'SIZEOF_VALUE'
# define SIZEOF_VALUE SIZEOF_LONG
                      ^
/Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/x86_64-darwin21/ruby/config.h:68:21: note: expanded from macro 'SIZEOF_LONG'
#define SIZEOF_LONG 8
                    ^
In file included from build/autotest.c:2:
In file included from /Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby.h:38:
In file included from /Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/ruby.h:27:
In file included from /Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/internal/arithmetic.h:23:
In file included from /Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/internal/arithmetic/char.h:29:
In file included from /Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/internal/core/rstring.h:28:
/Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/internal/core/rbasic.h:63:14: error: expected ')'
/Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/internal/value.h:106:23: note: expanded from macro 'SIZEOF_VALUE'
# define SIZEOF_VALUE SIZEOF_LONG
                      ^
/Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/x86_64-darwin21/ruby/config.h:68:21: note: expanded from macro 'SIZEOF_LONG'
#define SIZEOF_LONG 8
                    ^
/Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/internal/core/rbasic.h:63:1: note: to match this '('
RUBY_ALIGNAS(SIZEOF_VALUE)
^
/Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/ruby/backward/2/stdalign.h:27:22: note: expanded from macro 'RUBY_ALIGNAS'
#define RUBY_ALIGNAS RBIMPL_ALIGNAS /**< @copydoc RBIMPL_ALIGNAS */

...truncated, same error repeating....

fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
----------

            #include <ruby.h>

            int main() {
                ruby_init();
                return ruby_cleanup(0);
            }
----------
cc -pipe -fPIC -fvisibility=hidden -O -W -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -fstrict-aliasing -Wstrict-overflow=5 -Wmissing-prototypes -Werror -g -I/Users/travisbell/.rbenv/versions/3.1.1/include/ruby-3.1.0/x86_64-darwin21 -I/Users/travisbell/.r$
----------

There's more of this, but you get the idea.

Ruby is compiled with shared support:

ruby -e "require 'rbconfig'; puts RbConfig::CONFIG['ENABLE_SHARED']"
yes

I also tried with Ruby 3.0.3 had similar issues. Is this something Unit has to address or is it something else causing me some trouble?

I don't have any issues building the Ruby module on my Ubuntu Docker image, so I assume it has something specifically to do with Mac OS.

Hi Travis,

It seems to be a bug in ruby(1) (or maybe in Apple's clang(1)).
See a mnimal reproducer below.
However, it's weird that I can't reproduce it with clang(1) on Debian :/.

$ cat ruby.c
#include <ruby.h>

int main(void)
{
	printf("RBIMPL_COMPILER_IS_MSVC: %i\n", RBIMPL_COMPILER_IS_MSVC);
	return 0;
}
$ cc -I /usr/local/opt/ruby/include/ruby-3.1.0/ -I /usr/local/opt/ruby/include/ruby-3.1.0/x86_64-darwin20/ -fdeclspec ruby.c
$ cc -I /usr/local/opt/ruby/include/ruby-3.1.0/ -I /usr/local/opt/ruby/include/ruby-3.1.0/x86_64-darwin20/ ruby.c
In file included from ruby.c:1:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/ruby.h:25:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/defines.h:73:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/backward/2/attributes.h:42:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/attr/pure.h:25:
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/assert.h:132:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes
RBIMPL_ATTR_NORETURN()
^
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/attr/noreturn.h:29:33: note: expanded from macro 'RBIMPL_ATTR_NORETURN'
# define RBIMPL_ATTR_NORETURN() __declspec(noreturn)
                                ^
In file included from ruby.c:1:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/ruby.h:26:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/anyargs.h:77:
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/intern/vm.h:383:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes
RBIMPL_ATTR_NORETURN()
^
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/attr/noreturn.h:29:33: note: expanded from macro 'RBIMPL_ATTR_NORETURN'
# define RBIMPL_ATTR_NORETURN() __declspec(noreturn)
                                ^
In file included from ruby.c:1:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/ruby.h:27:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic.h:23:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic/char.h:23:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic/int.h:26:
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic/long.h:70:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes
RBIMPL_ATTR_NORETURN()
^
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/attr/noreturn.h:29:33: note: expanded from macro 'RBIMPL_ATTR_NORETURN'
# define RBIMPL_ATTR_NORETURN() __declspec(noreturn)
                                ^
In file included from ruby.c:1:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/ruby.h:27:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic.h:23:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic/char.h:29:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/core/rstring.h:28:
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/core/rbasic.h:63:14: error: expected parameter declarator
RUBY_ALIGNAS(SIZEOF_VALUE)
             ^
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/value.h:106:23: note: expanded from macro 'SIZEOF_VALUE'
# define SIZEOF_VALUE SIZEOF_LONG
                      ^
/usr/local/opt/ruby/include/ruby-3.1.0/x86_64-darwin20/ruby/config.h:66:21: note: expanded from macro 'SIZEOF_LONG'
#define SIZEOF_LONG 8
                    ^
In file included from ruby.c:1:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/ruby.h:27:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic.h:23:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic/char.h:29:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/core/rstring.h:28:
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/core/rbasic.h:63:14: error: expected ')'
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/value.h:106:23: note: expanded from macro 'SIZEOF_VALUE'
# define SIZEOF_VALUE SIZEOF_LONG
                      ^
/usr/local/opt/ruby/include/ruby-3.1.0/x86_64-darwin20/ruby/config.h:66:21: note: expanded from macro 'SIZEOF_LONG'
#define SIZEOF_LONG 8
                    ^
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/core/rbasic.h:63:1: note: to match this '('
RUBY_ALIGNAS(SIZEOF_VALUE)
^
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/backward/2/stdalign.h:27:22: note: expanded from macro 'RUBY_ALIGNAS'
#define RUBY_ALIGNAS RBIMPL_ALIGNAS /**< @copydoc RBIMPL_ALIGNAS */
                     ^
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/stdalign.h:66:44: note: expanded from macro 'RBIMPL_ALIGNAS'
# define RBIMPL_ALIGNAS(_) __declspec(align(_))
                                           ^
In file included from ruby.c:1:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/ruby.h:27:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic.h:23:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic/char.h:29:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/core/rstring.h:28:
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/core/rbasic.h:64:1: error: expected function body after function declarator
RBasic {
^
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/core/rbasic.h:155:23: error: incomplete definition of type 'struct RBasic'
    return RBASIC(obj)->klass;
           ~~~~~~~~~~~^
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/core/rbasic.h:155:12: note: forward declaration of 'struct RBasic'
    return RBASIC(obj)->klass;
           ^
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/core/rbasic.h:40:57: note: expanded from macro 'RBASIC'
#define RBASIC(obj)                 RBIMPL_CAST((struct RBasic *)(obj))
                                                        ^
In file included from ruby.c:1:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/ruby.h:27:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic.h:23:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic/char.h:29:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/core/rstring.h:30:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/fl_type.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/value_type.h:33:
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/error.h:86:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes
RBIMPL_ATTR_NORETURN()
^
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/attr/noreturn.h:29:33: note: expanded from macro 'RBIMPL_ATTR_NORETURN'
# define RBIMPL_ATTR_NORETURN() __declspec(noreturn)
                                ^
In file included from ruby.c:1:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/ruby.h:27:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic.h:23:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic/char.h:29:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/core/rstring.h:30:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/fl_type.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/value_type.h:33:
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/error.h:103:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes
RBIMPL_ATTR_NORETURN()
^
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/attr/noreturn.h:29:33: note: expanded from macro 'RBIMPL_ATTR_NORETURN'
# define RBIMPL_ATTR_NORETURN() __declspec(noreturn)
                                ^
In file included from ruby.c:1:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/ruby.h:27:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic.h:23:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic/char.h:29:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/core/rstring.h:30:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/fl_type.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/value_type.h:33:
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/error.h:118:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes
RBIMPL_ATTR_NORETURN()
^
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/attr/noreturn.h:29:33: note: expanded from macro 'RBIMPL_ATTR_NORETURN'
# define RBIMPL_ATTR_NORETURN() __declspec(noreturn)
                                ^
In file included from ruby.c:1:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/ruby.h:27:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic.h:23:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic/char.h:29:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/core/rstring.h:30:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/fl_type.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/value_type.h:33:
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/error.h:139:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes
RBIMPL_ATTR_NORETURN()
^
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/attr/noreturn.h:29:33: note: expanded from macro 'RBIMPL_ATTR_NORETURN'
# define RBIMPL_ATTR_NORETURN() __declspec(noreturn)
                                ^
In file included from ruby.c:1:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/ruby.h:27:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic.h:23:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic/char.h:29:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/core/rstring.h:30:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/fl_type.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/value_type.h:33:
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/error.h:151:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes
RBIMPL_ATTR_NORETURN()
^
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/attr/noreturn.h:29:33: note: expanded from macro 'RBIMPL_ATTR_NORETURN'
# define RBIMPL_ATTR_NORETURN() __declspec(noreturn)
                                ^
In file included from ruby.c:1:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/ruby.h:27:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic.h:23:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic/char.h:29:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/core/rstring.h:30:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/fl_type.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/value_type.h:33:
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/error.h:176:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes
RBIMPL_ATTR_NORETURN()
^
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/attr/noreturn.h:29:33: note: expanded from macro 'RBIMPL_ATTR_NORETURN'
# define RBIMPL_ATTR_NORETURN() __declspec(noreturn)
                                ^
In file included from ruby.c:1:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/ruby.h:27:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic.h:23:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic/char.h:29:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/core/rstring.h:30:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/fl_type.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/value_type.h:33:
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/error.h:187:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes
RBIMPL_ATTR_NORETURN()
^
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/attr/noreturn.h:29:33: note: expanded from macro 'RBIMPL_ATTR_NORETURN'
# define RBIMPL_ATTR_NORETURN() __declspec(noreturn)
                                ^
In file included from ruby.c:1:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/ruby.h:27:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic.h:23:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic/char.h:29:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/core/rstring.h:30:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/fl_type.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/value_type.h:33:
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/error.h:204:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes
RBIMPL_ATTR_NORETURN()
^
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/attr/noreturn.h:29:33: note: expanded from macro 'RBIMPL_ATTR_NORETURN'
# define RBIMPL_ATTR_NORETURN() __declspec(noreturn)
                                ^
In file included from ruby.c:1:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/ruby.h:27:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic.h:23:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic/char.h:29:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/core/rstring.h:30:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/fl_type.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/value_type.h:33:
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/error.h:216:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes
RBIMPL_ATTR_NORETURN()
^
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/attr/noreturn.h:29:33: note: expanded from macro 'RBIMPL_ATTR_NORETURN'
# define RBIMPL_ATTR_NORETURN() __declspec(noreturn)
                                ^
In file included from ruby.c:1:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/ruby.h:27:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic.h:23:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic/char.h:29:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/core/rstring.h:30:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/fl_type.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/value_type.h:33:
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/error.h:236:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes
RBIMPL_ATTR_NORETURN()
^
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/attr/noreturn.h:29:33: note: expanded from macro 'RBIMPL_ATTR_NORETURN'
# define RBIMPL_ATTR_NORETURN() __declspec(noreturn)
                                ^
In file included from ruby.c:1:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/ruby.h:27:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic.h:23:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic/char.h:29:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/core/rstring.h:30:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/fl_type.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/value_type.h:33:
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/error.h:248:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes
RBIMPL_ATTR_NORETURN()
^
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/attr/noreturn.h:29:33: note: expanded from macro 'RBIMPL_ATTR_NORETURN'
# define RBIMPL_ATTR_NORETURN() __declspec(noreturn)
                                ^
In file included from ruby.c:1:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/ruby.h:27:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic.h:23:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/arithmetic/char.h:29:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/core/rstring.h:30:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/fl_type.h:38:
In file included from /usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/value_type.h:33:
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/error.h:287:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes
RBIMPL_ATTR_NORETURN()
^
/usr/local/opt/ruby/include/ruby-3.1.0/ruby/internal/attr/noreturn.h:29:33: note: expanded from macro 'RBIMPL_ATTR_NORETURN'
# define RBIMPL_ATTR_NORETURN() __declspec(noreturn)
                                ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
$ cc --version
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: x86_64-apple-darwin20.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

See the following test, to investigate the reason:

$ cat ruby_cpp.c
#include <ruby.h>

int main(void)
{
	puts("RBIMPL_ATTR_NORETURN()");
	RBIMPL_ATTR_NORETURN()

	puts("RBIMPL_HAS_DECLSPEC_ATTRIBUTE(noreturn)");
	RBIMPL_HAS_DECLSPEC_ATTRIBUTE(noreturn)

	puts("__has_declspec_attribute(noreturn)");
	__has_declspec_attribute(noreturn)
}
$ cc -I /usr/local/opt/ruby/include/ruby-3.1.0/ -I /usr/local/opt/ruby/include/ruby-3.1.0/x86_64-darwin20/ -fdeclspec -E ruby_cpp.c -o ruby_cpp.i
$ cat ruby_cpp.i | sed -n '/^int main(void)$/,$p'
int main(void)
{
 puts("RBIMPL_ATTR_NORETURN()");
 __declspec(noreturn)

 puts("RBIMPL_HAS_DECLSPEC_ATTRIBUTE(noreturn)");
 1

 puts("__has_declspec_attribute(noreturn)");
                                  1
}

However, as a workaround, you could maybe add -fdeclspec to --cc-opt.
Please confirm if that workaround works for you or not, or if you have further problems.
To me that fixes the problem but I find another problem later in the configuration process
(I suspect I'm missing a path somewhere).
Also, please share how you installed ruby(1) (was it with brew(1)?),
and the commands you run to reproduce the problem.

Thanks,

Alex


$ ./configure --cc-opt='-I/usr/local/opt/ruby/include -fdeclspec' --ld-opt='-L/usr/local/opt/ruby/lib' >/dev/null 2>&1
$ echo $?
0
$ ./configure ruby --ruby=/usr/local/opt/ruby/bin/ruby
configuring Ruby module
checking for Ruby library ... /usr/local/Cellar/ruby/3.1.1/lib
checking for Ruby version ... 3.1.1
auto/modules/ruby: line 155: build/nxt_/usr/local/opt/ruby/bin/ruby_mounts.h: No such file or directory

Hey Alex, thanks for the troubleshooting and investigation.

I installed Ruby on Mac OS with rbenv. I also noticed, like you, that there is no issue compiling the module on my Ubuntu machine. This problem seems to only show up on my Mac.

I'll give the compile flags a try when I find some time to get back to this in a few. Thanks!

Hey Travis!

It seems to be a clang(1) bug, which breaks ruby(1):

llvm/llvm-project#49958

D'oh, I didn't realize github had realized and notified about it :P

It seems that ruby(1) knew about this bug in clang(1),
and they introduced the same workaround (-fdeclspec) back in 2019:
ruby/ruby@0958e19

@hongzhidao @VBart @artemkonev What do you say guys, should we get get this flag added to Mac builds?

According to the LLVM bug, it is also triggered in some other platforms such as Cygwin, so to be safe I'd enable that flag always for clang(1).

VBart commented

According to the LLVM bug, it is also triggered in some other platforms such as Cygwin, so to be safe I'd enable that flag always for clang(1).

If we enable it unconditionally by default, then we need to make sure that this flag is supported by all the actual versions of clang.

The flag seems to have been added in 2015, in commit llvm/llvm-project@d170c4b. The first release to contain it is:

$ git describe --contains d170c4b57a91adc74ca89c6d4af616a00323b12c
llvmorg-3.8.0-rc1~7948

I couldn't find a list of maintained clang(1) versions.

I checked two Linux distros that tend to be the oldest (AFAIK), Debian and CentOS:

The oldest Debian still alive is 8 (Jessie), which is in its extended LTS.
I couldn't find which version of clang(1) it uses, but I expect it to be older than that.
However, since it will die in 3 months,
I wouldn't care too much about it.

Then goes Debian 9 (Stretch; oldoldstable).
It has clang(1) 3.8, so we're fine there.

In CentOS, however, we would have a problem.
The oldest (and the only one, actually, but there's Rocky Linux for newer RHEL versions)
CentOS alive is 7.
It has clang(1) 3.4.
Its EOL is 2024-06, so it will be supported for 2 more years.

I guess we should only add -fdeclspec to Apple clang,
as you suggested, to avoid breaking builds on CentOS 7.
Users of other systems where -fdeclspec might be necessary can add it themselves.

The fix for this bug was merged some time ago. I forgot to close this issue. Please reopen it if you still experience issues, but I guess not.

Thanks!