From 89617471f89dabf14a9044b553535799c65af1fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 7 Dec 2023 15:52:10 +0100 Subject: [PATCH] Fix linking to older OpenSSL for Ruby < 2.7.7 Explicitly set PKG_CONFIG_PATH when `--with-openssl-dir` is used for older Rubies. Otherwise, Ruby will attempt to link to the latest OpenSSL found by pkg-config, which could be incompatible. --- bin/ruby-build | 15 +++++++++++++ test/build.bats | 36 ++++++++++++++++++++++++++------ test/fixtures/ruby-3.2.0.tar.gz | Bin 222 -> 246 bytes 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/bin/ruby-build b/bin/ruby-build index 1da9d5c466..6565ab33fa 100755 --- a/bin/ruby-build +++ b/bin/ruby-build @@ -672,6 +672,21 @@ build_package_standard() { # use openssl installed from Ports Collection package_option ruby configure --with-openssl-dir="/usr/local" fi + elif [ "$(normalize_semver "${package_name#ruby-}")" -lt 200707 ]; then + local opt + for opt in $RUBY_CONFIGURE_OPTS "${RUBY_CONFIGURE_OPTS_ARRAY[@]}"; do + if [[ $opt == --with-openssl-dir=* ]]; then + # Ruby < 2.7.7 are known to prioritize the result of `pkg-config --libs openssl` + # over the directory explicitly supplied by "--with-openssl-dir". This can cause + # issues if an incompatible OpenSSL version is found in pkg-config search path. + # https://github.com/ruby/openssl/pull/486 + # + # The workaround is to adjust the search path to prioritize the location supplied + # in "--with-openssl-dir". + export PKG_CONFIG_PATH="${opt#--with-openssl-dir=}/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}" + break + fi + done fi if [[ "$RUBY_CONFIGURE_OPTS ${RUBY_CONFIGURE_OPTS_ARRAY[*]}" != *--with-ext* && "$RUBY_CONFIGURE_OPTS ${RUBY_CONFIGURE_OPTS_ARRAY[*]}" != *--without-ext* && diff --git a/test/build.bats b/test/build.bats index b712aa8562..90c412f3f3 100755 --- a/test/build.bats +++ b/test/build.bats @@ -6,6 +6,7 @@ export MAKE=make export MAKE_OPTS="-j 2" export CC=cc export -n RUBY_CONFIGURE_OPTS +export -n PKG_CONFIG_PATH setup() { mkdir -p "$INSTALL_ROOT" @@ -58,7 +59,7 @@ generate_tarball() { cat > "${path}/${file}" <> build.log +echo "$name: [\$*]" \${RUBYOPT:+RUBYOPT=\$RUBYOPT} \${PKG_CONFIG_PATH:+PKG_CONFIG_PATH=\$PKG_CONFIG_PATH} >> build.log OUT chmod +x "${path}/${file}" ;; @@ -83,7 +84,7 @@ OUT stub_make_install() { local target="${1:-install}" stub "$MAKE" \ - " : echo \"$MAKE \$(inspect_args \"\$@\")\" >> build.log" \ + " : echo \"\${PKG_CONFIG_PATH:+PKG_CONFIG_PATH=\$PKG_CONFIG_PATH }$MAKE \$(inspect_args \"\$@\")\" >> build.log" \ "$target : echo \"$MAKE \$(inspect_args \"\$@\")\" >> build.log && cat build.log >> '$INSTALL_ROOT/build.log'" } @@ -372,11 +373,11 @@ DEF unstub make assert_build_log <RB!fG_|60e?=I015yAp@TH8