Skip to content

Commit

Permalink
Add rust as a dependency if --enable-yjit is given (#496).
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Jan 31, 2025
1 parent 49d5e3e commit 7971422
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
13 changes: 13 additions & 0 deletions share/ruby-install/ruby/dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,16 @@ if [[ " ${configure_opts[*]} " == *" --with-jemalloc "* ]]; then
;;
esac
fi

#
# Install Rust if YJIT support is explicitly enabled.
#
if [[ " ${configure_opts[*]} " == *" --enable-yjit "* ]]; then
# NOTE: YJIT is written in Rust, thus requires rustc
if ! command -v rustc >/dev/null; then
case "$package_manager" in
apt) ruby_dependencies+=(rustc) ;;
*) ruby_dependencies+=(rust) ;;
esac
fi
fi
57 changes: 57 additions & 0 deletions test/ruby-tests/dependencies_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,63 @@ function test_ruby_dependencies_when_with_jemalloc_is_given()
configure_opts=("${original_configure_opts[@]}")
}

function test_ruby_dependencies_when_enable_yjit_is_given_and_rustc_is_not_installed_and_the_package_manager_is_apt()
{
command -v rustc && return

local original_package_manager="$package_manager"
local original_configure_opts=("${configure_opts[@]}")

package_manager="apt"
configure_opts=(--enable-yjit)

source "$ruby_install_dir/$ruby/dependencies.sh"

assertTrue "did not contain rustc to the dependencies" \
'[[ " ${ruby_dependencies[*]} " == *" rustc "* ]]'

package_manager="$original_package_manager"
configure_opts=("${original_configure_opts[@]}")
}

function test_ruby_dependencies_when_enable_yjit_is_given_and_rustc_is_not_installed_and_the_package_manager_is_not_apt()
{
command -v rustc >/dev/null && return

local original_package_manager="$package_manager"
local original_configure_opts=("${configure_opts[@]}")

package_manager="dnf"
configure_opts=(--enable-yjit)

source "$ruby_install_dir/$ruby/dependencies.sh"

assertTrue "did not contain rust to the dependencies" \
'[[ " ${ruby_dependencies[*]} " == *" rust "* ]]'

package_manager="$original_package_manager"
configure_opts=("${original_configure_opts[@]}")
}

function test_ruby_dependencies_when_enable_yjit_is_given_but_rustc_is_installed()
{
command -v rustc >/dev/null || return

local original_configure_opts=("${configure_opts[@]}")

configure_opts=(--enable-yjit)

source "$ruby_install_dir/$ruby/dependencies.sh"

assertTrue "did accidentally add rustc to the dependencies" \
'[[ ! " ${ruby_dependencies[*]} " == *" rustc "* ]]'

assertTrue "did accidentally add rust to the dependencies" \
'[[ ! " ${ruby_dependencies[*]} " == *" rust "* ]]'

configure_opts=("${original_configure_opts[@]}")
}

function tearDown()
{
unset ruby ruby_version ruby_dependencies openssl_version
Expand Down

0 comments on commit 7971422

Please sign in to comment.