From 6ac4038204162a22648bdf10f4ebd55249899e59 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Wed, 16 Sep 2026 09:14:57 +0900 Subject: [PATCH] Hide dup3() and pipe2() from configure on macOS older than 27 The macOS 27 SDK declares both as available since macOS 27.0, and `AC_CHECK_FUNCS` detects them regardless of the deployment target, so Ruby built on macOS 26 with the Command Line Tools 27 calls weakly linked NULL symbols and crashes miniruby during the build. https://bugs.ruby-lang.org/issues/22311 https://github.com/rbenv/ruby-build/issues/2640 Co-Authored-By: Claude Opus 5 --- bin/ruby-build | 7 +++++ test/compiler.bats | 76 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/bin/ruby-build b/bin/ruby-build index 6b56ec4252..5000794fe7 100755 --- a/bin/ruby-build +++ b/bin/ruby-build @@ -754,6 +754,13 @@ build_package_standard() { # override them and notably lose the -O3, producing a -O0 Ruby. export cflags="-std=gnu17 $cflags" fi + if [ "$package_var_name" = "RUBY" ] && is_mac && ! is_mac 2700; then + # The macOS 27 SDK declares dup3() and pipe2() as available since macOS 27.0. + # Ruby's configure detects them even when building for an older macOS, where + # they are only weakly linked and are NULL at runtime, which makes miniruby + # crash during the build: https://bugs.ruby-lang.org/issues/22311 + export ac_cv_func_dup3=no ac_cv_func_pipe2=no + fi # ./configure --prefix=/path/to/ruby # shellcheck disable=SC2086,SC2153 capture_command ${!PACKAGE_CONFIGURE:-./configure} --prefix="${!PACKAGE_PREFIX_PATH:-$PREFIX_PATH}" \ diff --git a/test/compiler.bats b/test/compiler.bats index 58728379f6..14ac4daa7e 100755 --- a/test/compiler.bats +++ b/test/compiler.bats @@ -12,7 +12,7 @@ export -n RUBY_CONFIGURE_OPTS cd "$INSTALL_ROOT" stub_repeated uname '-s : echo Darwin' - stub sw_vers '-productVersion : echo 10.10' + stub_repeated sw_vers '-productVersion : echo 10.10' stub_repeated brew 'false' # shellcheck disable=SC2016 stub_repeated make 'echo "make $(inspect_args "$@")" >> build.log' @@ -43,3 +43,77 @@ OUT unstub brew unstub make } + +@test "dup3 and pipe2 are hidden from configure when building on older macOS" { + mkdir -p "$INSTALL_ROOT" + cd "$INSTALL_ROOT" + + stub_repeated uname '-s : echo Darwin' + stub_repeated sw_vers '-productVersion : echo 26.6.2' + stub_repeated brew 'false' + # shellcheck disable=SC2016 + stub_repeated make 'echo "make $(inspect_args "$@")" >> build.log' + + cat > ./configure < build.log +echo dup3=\${ac_cv_func_dup3-unset} >> build.log +echo pipe2=\${ac_cv_func_pipe2-unset} >> build.log +CON + chmod +x ./configure + + run_inline_definition <> build.log' + + cat > ./configure < build.log +echo dup3=\${ac_cv_func_dup3-unset} >> build.log +echo pipe2=\${ac_cv_func_pipe2-unset} >> build.log +CON + chmod +x ./configure + + run_inline_definition <