Skip to content

Commit

Permalink
Experiment to introduce a libdatadog Ruby binding using SWIG
Browse files Browse the repository at this point in the history
  • Loading branch information
ivoanjo committed Jul 25, 2024
1 parent 552e6d3 commit d9c4238
Show file tree
Hide file tree
Showing 7 changed files with 15,778 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,11 @@ NATIVE_EXTS = [

Rake::ExtensionTask.new("datadog_profiling_loader.#{RUBY_VERSION}_#{RUBY_PLATFORM}") do |ext|
ext.ext_dir = 'ext/datadog_profiling_loader'
end
end,

Rake::ExtensionTask.new("libdatadog_ruby") do |ext|
ext.ext_dir = 'ext/libdatadog_ruby'
end,
].freeze

NATIVE_CLEAN = ::Rake::FileList[]
Expand Down
2 changes: 1 addition & 1 deletion datadog.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ Gem::Specification.new do |spec|
# (and yes we have a test for it)
spec.add_dependency 'libdatadog', '~> 11.0.0.1.0'

spec.extensions = ['ext/datadog_profiling_native_extension/extconf.rb', 'ext/datadog_profiling_loader/extconf.rb']
spec.extensions = ['ext/datadog_profiling_native_extension/extconf.rb', 'ext/datadog_profiling_loader/extconf.rb', 'libdatadog_ruby/extconf.rb']
end
17 changes: 17 additions & 0 deletions ext/libdatadog_ruby/extconf.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# rubocop:disable Style/StderrPuts
# rubocop:disable Style/GlobalVars

require 'mkmf'
require 'libdatadog'

# If we got here, libdatadog is available and loaded
ENV['PKG_CONFIG_PATH'] = "#{ENV['PKG_CONFIG_PATH']}:#{Libdatadog.pkgconfig_folder}"
Logging.message("[datadog] PKG_CONFIG_PATH set to #{ENV['PKG_CONFIG_PATH'].inspect}\n")
$stderr.puts("Using libdatadog #{Libdatadog::VERSION} from #{Libdatadog.pkgconfig_folder}")

unless pkg_config('datadog_profiling_with_rpath')
Logging.message("[datadog] Ruby detected the pkg-config command is #{$PKGCONFIG.inspect}\n")
end

create_makefile("libdatadog_ruby")

1 change: 1 addition & 0 deletions ext/libdatadog_ruby/generate-swig.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
swig -I/home/ivo.anjo/datadog/libdatadog/build-linux/x86_64-linux/include -ruby libdatadog.i
22 changes: 22 additions & 0 deletions ext/libdatadog_ruby/libdatadog.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
%module libdatadog_ruby

%{
#include <datadog/common.h>
#include <datadog/profiling.h>
%}

%typemap(in) uintptr_t {
$1 = (uintptr_t) NUM2ULONG($input);
}

%typemap(in) uint64_t {
$1 = (uint64_t) NUM2ULONG($input);
}

%typemap(out) struct ddog_Error* {
ddog_CharSlice char_slice = ddog_Error_message($1);
$result = rb_str_new(char_slice.ptr, char_slice.len);
}

%include <datadog/common.h>
%include <datadog/profiling.h>
Loading

0 comments on commit d9c4238

Please sign in to comment.