From 6f7a614655afc5a81f20daa0d88328a4318c3128 Mon Sep 17 00:00:00 2001 From: Ivo Anjo Date: Thu, 18 Nov 2021 14:22:47 +0000 Subject: [PATCH] Skip building profiling native extension when Ruby has been compiled without JIT The profiling native extension relies on the Ruby MJIT headers on 2.6+. But these headers are not available in Rubies that were compiled with JIT disabled. To avoid impacting these users (e.g. making them explicitly need to install with `DD_PROFILING_NO_EXTENSION=true`), let's automatically skip the extension when we detect that the JIT was disabled. In the future, we can explore using `debase-ruby_core_source` for these Ruby versions, if we still want to support these users. Fixes #1774 --- .../extconf.rb | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/ext/ddtrace_profiling_native_extension/extconf.rb b/ext/ddtrace_profiling_native_extension/extconf.rb index 3c9917c40a1..9d3044f4154 100644 --- a/ext/ddtrace_profiling_native_extension/extconf.rb +++ b/ext/ddtrace_profiling_native_extension/extconf.rb @@ -1,5 +1,8 @@ # typed: ignore +# Older Rubies don't have the MJIT header, used by the JIT compiler, so we need to use a different approach +CAN_USE_MJIT_HEADER = RUBY_VERSION >= '2.6' + def skip_building_extension? # We don't support JRuby for profiling, and JRuby doesn't support native extensions, so let's just skip this entire # thing so that JRuby users of dd-trace-rb aren't impacted. @@ -12,12 +15,28 @@ def skip_building_extension? # Microsoft Windows is unsupported, so let's not build the extension there. on_windows = Gem.win_platform? + # On some Rubies, we require the mjit header to be present. If Ruby was installed without MJIT support, we also skip + # building the extension. + if expected_to_use_mjit_but_mjit_is_disabled = CAN_USE_MJIT_HEADER && RbConfig::CONFIG["MJIT_SUPPORT"] != 'yes' + $stderr.puts(%( ++------------------------------------------------------------------------------+ +| Your Ruby has been compiled without JIT support (--disable-jit-support). | +| The profiling native extension requires a Ruby compiled with JIT support, | +| even if the JIT is not in use by the application itself. | +| | +| WARNING: Without the profiling native extension, some profiling features | +| will not be available. | ++------------------------------------------------------------------------------+ + +)) + end + # Experimental toggle to disable building the extension. # Disabling the extension will lead to the profiler not working in future releases. # If you needed to use this, please tell us why on . disabled_via_env = ENV['DD_PROFILING_NO_EXTENSION'].to_s.downcase == 'true' - on_jruby || on_truffleruby || on_windows || disabled_via_env + on_jruby || on_truffleruby || on_windows || expected_to_use_mjit_but_mjit_is_disabled || disabled_via_env end # IMPORTANT: When adding flags, remember that our customers compile with a wide range of gcc/clang versions, so @@ -84,9 +103,6 @@ def add_compiler_flag(flag) $defs << '-DHAVE_PTHREAD_GETCPUCLOCKID' end -# Older Rubies don't have the MJIT header, used by the JIT compiler, so we need to use a different approach -CAN_USE_MJIT_HEADER = RUBY_VERSION >= '2.6' - # Tag the native extension library with the Ruby version and Ruby platform. # This makes it easier for development (avoids "oops I forgot to rebuild when I switched my Ruby") and ensures that # the wrong library is never loaded.