curses icon indicating copy to clipboard operation
curses copied to clipboard

Fails to build on macOS with Ruby 3.4.7

Open coder2000 opened this issue 1 month ago • 6 comments

Curses gem fails to build on Ruby 3.4.7 with macOS (arm64): "convertible type of chtype... failed"

Environment

  • Ruby version: 3.4.7
  • Curses gem version: 1.5.3
  • Operating System: macOS 26.1 (Build 25B78)
  • Architecture: arm64 (Apple Silicon)
  • Compiler: Apple clang version 21.0.0
  • ncurses: 6.5 (installed via Homebrew at /opt/homebrew/opt/ncurses)

Description

The curses gem fails to compile on Ruby 3.4.7 during the native extension build. The build fails at the chtype type conversion test in extconf.rb.

Steps to Reproduce

gem install curses -- --use-system-libraries --with-ncurses-dir=/opt/homebrew/opt/ncurses

Error Output

From gem_make.out:

checking for convertible type of chtype... failed
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.

Root Cause

From analyzing mkmf.log, the issue appears to be twofold:

  1. Ruby 3.4.7 header warning: Ruby's internal header (ruby/internal/core/rstring.h:398) triggers a compiler warning:

    warning: default initialization of an object of type 'struct RString' with const member 
    leaves the object uninitialized [-Wdefault-const-init-field-unsafe]
    
  2. chtype conversion test failure: The test to determine the C type equivalent of chtype fails with:

    conftest.c:8:20: error: 'conftest_const' declared as an array with a negative size
    int conftest_const[((rbcv_typedef_)-1 < 0) ? 1 : -1];
    

The test program attempts to determine if chtype is signed, but the compilation fails before it can complete the type detection logic.

Attempted Workarounds

  • Setting --with-cflags="-Wno-error=default-const-init-field-unsafe" does not resolve the issue
  • The warning flag is applied correctly, but the chtype conversion test still fails

Relevant Log Excerpt

convertible_int: checking for convertible type of chtype... -------------------- failed

DYLD_LIBRARY_PATH=.:/Users/coder2000/.local/share/mise/installs/ruby/3.4.7/lib ASAN_OPTIONS=detect_leaks=0 "clang -I/Users/coder2000/.local/share/mise/installs/ruby/3.4.7/include/ruby-3.4.0/arm64-darwin25 -I/Users/coder2000/.local/share/mise/installs/ruby/3.4.0/ruby/backward -I/Users/coder2000/.local/share/mise/installs/ruby/3.4.7/include/ruby-3.4.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -Wno-error=default-const-init-field-unsafe -arch arm64  -c conftest.c"
...
conftest.c:8:20: error: 'conftest_const' declared as an array with a negative size
    8 | int conftest_const[((rbcv_typedef_)-1 < 0) ? 1 : -1];

Expected Behavior

The gem should compile successfully and the chtype type conversion should be detected properly.

Additional Notes

  • This appears to be specific to Ruby 3.4.x on macOS with Apple Silicon
  • The same issue may affect other recent Ruby 3.4.x versions
  • ncurses libraries are found correctly - all function checks pass up until the chtype conversion test

Question

Is there a known incompatibility with Ruby 3.4.x's internal headers and the type detection logic in extconf.rb? Would it be possible to update the type detection mechanism to be more robust against compiler warnings in Ruby headers?

coder2000 avatar Nov 06 '25 18:11 coder2000

I was experiencing the same issue, and was able to work around it by creating a temporary proxy script for clang to use in compilation. The problem is that ruby sets its own Werror flag, so you need a way to remove it. You can intercept the call to clang and remove the flag like so:

WRAPPER_DIR="$(mktemp -d)"

cat > "$WRAPPER_DIR/clang" << 'EOF'
#!/bin/bash
args=()
for arg in "$@"; do
     # here we check for ruby's flag and ensure clang doesn't use it
    [[ "$arg" != "-Werror" ]] && args+=("$arg")
done
exec /usr/bin/clang "${args[@]}"
EOF

chmod +x "$WRAPPER_DIR/clang"

PATH="$WRAPPER_DIR:$PATH" gem install curses -- \
  --with-ncursesw-dir="$(brew --prefix ncurses)"

rm -rf "$WRAPPER_DIR"

gillisd avatar Nov 07 '25 20:11 gillisd

That works, thanks. Hopefully the issue can be resolved where it's not needed.

coder2000 avatar Nov 08 '25 00:11 coder2000

I've heard from @nobu that the Ruby 3.4.7 header warning has already been fixed in the ruby_3_4 branch. We are investigating the chtype conversion test failure now.

shugo avatar Nov 08 '25 01:11 shugo

I can't reproduce the second issue "chtype conversion test failure" with Apple clang version 17.0.0. And Apple clang version 21 doesn't look released yet. Are you using developers beta or something?

nobu avatar Nov 08 '25 01:11 nobu

@coder2000 Could you show your mkmf.log file?

nobu avatar Nov 08 '25 01:11 nobu

Here is the mkmf.log file as requested.

mkmf.log

coder2000 avatar Nov 09 '25 02:11 coder2000