Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix installing OpenSSL on non-Linux or with clang #2496

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions bin/ruby-build
Original file line number Diff line number Diff line change
Expand Up @@ -1211,11 +1211,21 @@ build_package_openssl() {
# Tell Ruby to use this openssl for its extension.
package_option ruby configure --with-openssl-dir="$OPENSSL_PREFIX_PATH"

local nokerberos
[[ "$1" != openssl-1.0.* ]] || nokerberos=1

# Compile a shared lib with zlib dynamically linked.
package_option openssl configure --openssldir="$OPENSSLDIR" --libdir="lib" -Wl,-rpath="$OPENSSL_PREFIX_PATH/lib" zlib-dynamic no-ssl3 shared ${nokerberos:+no-ssl2 no-krb5}
package_option openssl configure --openssldir="$OPENSSLDIR" --libdir="lib" zlib-dynamic no-ssl3 shared

# Help OpenSSL find its own shared libraries on Linux.
if [ "$(uname -s)" = "Linux" ]; then
# shellcheck disable=SC2031
if [ "$CC" = "clang" ] || "${CC:-cc}" --version 2>&1 | grep -wq clang; then
package_option openssl configure -Wl,-rpath,"$OPENSSL_PREFIX_PATH/lib"
else
package_option openssl configure -Wl,-rpath="$OPENSSL_PREFIX_PATH/lib"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use the comma syntax -Wl,-rpath,"$OPENSSL_PREFIX_PATH/lib" for GCC as well (the commas are split into separate args to pass to the linker, giving ld -rpath … instead of ld -rpath=…) so we can drop the clang check.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fi
fi

# Disable SSLv2 and Kerberos on older OpenSSL
[[ "$1" != openssl-1.0.* ]] || package_option openssl configure no-ssl2 no-krb5

# Skip building OpenSSL docs, which is slow.
local make_target="install_sw install_ssldirs"
Expand Down
35 changes: 33 additions & 2 deletions test/build.bats
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,9 @@ OUT

stub_repeated uname '-s : echo Linux'
stub_repeated brew false
stub cc '-xc -E - : echo "OpenSSL 1.0.1a 1 Aug 2023"'
stub cc \
'-xc -E - : echo "OpenSSL 1.0.1a 1 Aug 2023"' \
'--version : echo gcc'
stub openssl "version -d : echo 'OPENSSLDIR: \"${TMP}/ssl\"'"
stub_make_install "install_sw"
stub_make_install
Expand All @@ -397,7 +399,7 @@ DEF
unstub make

assert_build_log <<OUT
openssl-1.1.1w: [--prefix=${INSTALL_ROOT}/openssl,--openssldir=${INSTALL_ROOT}/openssl/ssl,--libdir=lib,-Wl,-rpath=${INSTALL_ROOT}/openssl/lib,zlib-dynamic,no-ssl3,shared]
openssl-1.1.1w: [--prefix=${INSTALL_ROOT}/openssl,--openssldir=${INSTALL_ROOT}/openssl/ssl,--libdir=lib,zlib-dynamic,no-ssl3,shared,-Wl,-rpath=${INSTALL_ROOT}/openssl/lib]
make -j 2
make install_sw install_ssldirs
ruby-3.2.0: [--prefix=$INSTALL_ROOT,--with-openssl-dir=$INSTALL_ROOT/openssl,--with-ext=openssl,psych,+] PKG_CONFIG_PATH=${TMP}/install/openssl/lib/pkgconfig
Expand All @@ -406,6 +408,35 @@ make install
OUT
}

@test "install OpenSSL with clang" {
cached_tarball "openssl-1.1.1w" config

mkdir -p "${TMP}/ssl/certs"
touch "${TMP}/ssl/cert.pem"

stub_repeated uname '-s : echo Linux'
stub cc '--version : echo "Hello clang 1.2.3"'
stub openssl "version -d : echo 'OPENSSLDIR: \"${TMP}/ssl\"'"
stub_make_install "install_sw"

mkdir -p "$INSTALL_ROOT"/openssl/ssl # OPENSSLDIR
run_inline_definition <<DEF
install_package "openssl-1.1.1w" "https://www.openssl.org/source/openssl-1.1.1w.tar.gz" openssl
DEF
assert_success

unstub uname
unstub cc
# unstub openssl
unstub make

assert_build_log <<OUT
openssl-1.1.1w: [--prefix=${INSTALL_ROOT}/openssl,--openssldir=${INSTALL_ROOT}/openssl/ssl,--libdir=lib,zlib-dynamic,no-ssl3,shared,-Wl,-rpath,${INSTALL_ROOT}/openssl/lib]
make -j 2
make install_sw install_ssldirs
OUT
}

@test "skip bundling OpenSSL if custom openssl dir was specified" {
cached_tarball "ruby-3.2.0" configure

Expand Down
Loading