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

Skip building profiling native extension when Ruby has been compiled without JIT #1776

Merged
merged 1 commit into from
Nov 19, 2021
Merged
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
24 changes: 20 additions & 4 deletions ext/ddtrace_profiling_native_extension/extconf.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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 <https://github.com/DataDog/dd-trace-rb/issues/new>.
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
Expand Down Expand Up @@ -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.
Expand Down