ruby-build/test/compiler.bats
Hiroshi SHIBATA 6ac4038204
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 <noreply@anthropic.com>
2026-09-16 09:14:57 +09:00

119 lines
2.5 KiB
Shell
Executable file

#!/usr/bin/env bats
load test_helper
export MAKE=make
export MAKE_OPTS='-j 2'
export -n CFLAGS
export -n CC
export -n RUBY_CONFIGURE_OPTS
@test "CC=clang by default on OS X 10.10" {
mkdir -p "$INSTALL_ROOT"
cd "$INSTALL_ROOT"
stub_repeated uname '-s : echo Darwin'
stub_repeated sw_vers '-productVersion : echo 10.10'
stub_repeated brew 'false'
# shellcheck disable=SC2016
stub_repeated make 'echo "make $(inspect_args "$@")" >> build.log'
cat > ./configure <<CON
#!${BASH}
echo ./configure "\$@" > build.log
echo CC=\$CC >> build.log
echo CFLAGS=\${CFLAGS-no} >> build.log
CON
chmod +x ./configure
run_inline_definition <<DEF
build_package_standard ruby-2.5.0
DEF
assert_success
run cat build.log
assert_output <<OUT
./configure --prefix=$INSTALL_ROOT --with-ext=openssl,psych,+
CC=clang
CFLAGS=no
make -j 2
make install
OUT
unstub uname
unstub sw_vers
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 <<CON
#!${BASH}
echo ./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 <<DEF
build_package_standard ruby-3.4.0
DEF
assert_success
run cat build.log
assert_output <<OUT
./configure --prefix=$INSTALL_ROOT --with-ext=openssl,psych,+
dup3=no
pipe2=no
make -j 2
make install
OUT
unstub uname
unstub sw_vers
unstub brew
unstub make
}
@test "dup3 and pipe2 are left to configure on macOS 27" {
mkdir -p "$INSTALL_ROOT"
cd "$INSTALL_ROOT"
stub_repeated uname '-s : echo Darwin'
stub_repeated sw_vers '-productVersion : echo 27.0'
stub_repeated brew 'false'
# shellcheck disable=SC2016
stub_repeated make 'echo "make $(inspect_args "$@")" >> build.log'
cat > ./configure <<CON
#!${BASH}
echo ./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 <<DEF
build_package_standard ruby-3.4.0
DEF
assert_success
run cat build.log
assert_output <<OUT
./configure --prefix=$INSTALL_ROOT --with-ext=openssl,psych,+
dup3=unset
pipe2=unset
make -j 2
make install
OUT
unstub uname
unstub sw_vers
unstub brew
unstub make
}