Skip to content

Commit

Permalink
Workaround for Ruby 2.1 not having a public thread_native.h header
Browse files Browse the repository at this point in the history
Hopefully we can deprecate Ruby 2.1 soon.
  • Loading branch information
ivoanjo committed Oct 27, 2021
1 parent eb8ff20 commit b47bdbb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,6 @@ Style/TrailingCommaInHashLiteral:
Style/GlobalVars:
Exclude:
- 'ext/ddtrace_profiling_native_extension/extconf.rb'

Naming/VariableNumber:
Enabled: false
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
#include <errno.h>

#include <ruby.h>

#ifdef RUBY_2_1_WORKAROUND
#include <thread_native.h>
#else
#include <ruby/thread_native.h>
#endif

#include "private_vm_api_access.h"

Expand Down
10 changes: 9 additions & 1 deletion ext/ddtrace_profiling_native_extension/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,18 @@ def add_compiler_flag(flag)
# This gem ships source code copies of these VM headers for the different Ruby VM versions;
# see https://github.com/ruby-debug/debase-ruby_core_source for details

thread_native_for_ruby_2_1 = proc { true }
if RUBY_VERSION < '2.2'
# This header became public in Ruby 2.2, but we need to pull it from the private headers folder for 2.1
thread_native_for_ruby_2_1 = proc { have_header('thread_native.h') }
$defs << '-DRUBY_2_1_WORKAROUND'
end

create_header

require 'debase/ruby_core_source'
dir_config('ruby') # allow user to pass in non-standard core include directory

Debase::RubyCoreSource.create_makefile_with_core(proc { have_header('vm_core.h') }, EXTENSION_NAME)
Debase::RubyCoreSource
.create_makefile_with_core(proc { have_header('vm_core.h') && thread_native_for_ruby_2_1.call }, EXTENSION_NAME)
end
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/rails/rack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}
end

let(:rails_older_than_3_2) do # rubocop:disable Naming/VariableNumber
let(:rails_older_than_3_2) do
Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new('3.2')
end

Expand Down

0 comments on commit b47bdbb

Please sign in to comment.