Skip to content

Commit

Permalink
Merge pull request #1776 from DataDog/ivoanjo/prof-4428-nixos-install…
Browse files Browse the repository at this point in the history
…-issue

Skip building profiling native extension when Ruby has been compiled without JIT
  • Loading branch information
ivoanjo authored Nov 19, 2021
2 parents 76000ae + 6f7a614 commit 312ffee
Showing 1 changed file with 20 additions and 4 deletions.
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

0 comments on commit 312ffee

Please sign in to comment.