Skip to content

Commit 6ac4038

Browse files
hsbtclaude
andcommitted
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 #2640 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 59b1392 commit 6ac4038

2 files changed

Lines changed: 82 additions & 1 deletion

File tree

‎bin/ruby-build‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,13 @@ build_package_standard() {
754754
# override them and notably lose the -O3, producing a -O0 Ruby.
755755
export cflags="-std=gnu17 $cflags"
756756
fi
757+
if [ "$package_var_name" = "RUBY" ] && is_mac && ! is_mac 2700; then
758+
# The macOS 27 SDK declares dup3() and pipe2() as available since macOS 27.0.
759+
# Ruby's configure detects them even when building for an older macOS, where
760+
# they are only weakly linked and are NULL at runtime, which makes miniruby
761+
# crash during the build: https://bugs.ruby-lang.org/issues/22311
762+
export ac_cv_func_dup3=no ac_cv_func_pipe2=no
763+
fi
757764
# ./configure --prefix=/path/to/ruby
758765
# shellcheck disable=SC2086,SC2153
759766
capture_command ${!PACKAGE_CONFIGURE:-./configure} --prefix="${!PACKAGE_PREFIX_PATH:-$PREFIX_PATH}" \

‎test/compiler.bats‎

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export -n RUBY_CONFIGURE_OPTS
1212
cd "$INSTALL_ROOT"
1313

1414
stub_repeated uname '-s : echo Darwin'
15-
stub sw_vers '-productVersion : echo 10.10'
15+
stub_repeated sw_vers '-productVersion : echo 10.10'
1616
stub_repeated brew 'false'
1717
# shellcheck disable=SC2016
1818
stub_repeated make 'echo "make $(inspect_args "$@")" >> build.log'
@@ -43,3 +43,77 @@ OUT
4343
unstub brew
4444
unstub make
4545
}
46+
47+
@test "dup3 and pipe2 are hidden from configure when building on older macOS" {
48+
mkdir -p "$INSTALL_ROOT"
49+
cd "$INSTALL_ROOT"
50+
51+
stub_repeated uname '-s : echo Darwin'
52+
stub_repeated sw_vers '-productVersion : echo 26.6.2'
53+
stub_repeated brew 'false'
54+
# shellcheck disable=SC2016
55+
stub_repeated make 'echo "make $(inspect_args "$@")" >> build.log'
56+
57+
cat > ./configure <<CON
58+
#!${BASH}
59+
echo ./configure "\$@" > build.log
60+
echo dup3=\${ac_cv_func_dup3-unset} >> build.log
61+
echo pipe2=\${ac_cv_func_pipe2-unset} >> build.log
62+
CON
63+
chmod +x ./configure
64+
65+
run_inline_definition <<DEF
66+
build_package_standard ruby-3.4.0
67+
DEF
68+
assert_success
69+
run cat build.log
70+
assert_output <<OUT
71+
./configure --prefix=$INSTALL_ROOT --with-ext=openssl,psych,+
72+
dup3=no
73+
pipe2=no
74+
make -j 2
75+
make install
76+
OUT
77+
78+
unstub uname
79+
unstub sw_vers
80+
unstub brew
81+
unstub make
82+
}
83+
84+
@test "dup3 and pipe2 are left to configure on macOS 27" {
85+
mkdir -p "$INSTALL_ROOT"
86+
cd "$INSTALL_ROOT"
87+
88+
stub_repeated uname '-s : echo Darwin'
89+
stub_repeated sw_vers '-productVersion : echo 27.0'
90+
stub_repeated brew 'false'
91+
# shellcheck disable=SC2016
92+
stub_repeated make 'echo "make $(inspect_args "$@")" >> build.log'
93+
94+
cat > ./configure <<CON
95+
#!${BASH}
96+
echo ./configure "\$@" > build.log
97+
echo dup3=\${ac_cv_func_dup3-unset} >> build.log
98+
echo pipe2=\${ac_cv_func_pipe2-unset} >> build.log
99+
CON
100+
chmod +x ./configure
101+
102+
run_inline_definition <<DEF
103+
build_package_standard ruby-3.4.0
104+
DEF
105+
assert_success
106+
run cat build.log
107+
assert_output <<OUT
108+
./configure --prefix=$INSTALL_ROOT --with-ext=openssl,psych,+
109+
dup3=unset
110+
pipe2=unset
111+
make -j 2
112+
make install
113+
OUT
114+
115+
unstub uname
116+
unstub sw_vers
117+
unstub brew
118+
unstub make
119+
}

0 commit comments

Comments
 (0)