Skip to content

Commit ae3b6ec

Browse files
committed
feat: compile native extension during gem install
1 parent 800965f commit ae3b6ec

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

.agents/codebase-insights.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ The native tracer (Rust extension) caches frequently used Ruby method IDs and
44
class constants in the `Recorder` struct. When adding new Ruby method calls,
55
ensure the IDs are interned once during allocation and stored in the struct for
66
reuse.
7+
8+
When the native extension is built via `rb_sys` during gem installation, the
9+
compiled shared library is placed directly under the gem's `lib` directory
10+
instead of `ext/native_tracer/target/release`.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
In codetracer-ruby-recorder.gemspec, set spec.extensions to ['ext/native_tracer/extconf.rb'] and verify that rake build produces a gem that compiles the extension when installed

gems/codetracer-ruby-recorder/codetracer-ruby-recorder.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
1717
'ext/native_tracer/target/release/*'
1818
]
1919
spec.require_paths = ['lib']
20-
spec.extensions = []
20+
spec.extensions = ['ext/native_tracer/extconf.rb']
2121
spec.bindir = 'bin'
2222
spec.executables = ['codetracer-ruby-recorder']
2323

gems/codetracer-ruby-recorder/lib/codetracer_ruby_recorder.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ def load_native_recorder
117117
ext_dir = File.expand_path('../ext/native_tracer/target/release', __dir__)
118118
dlext = RbConfig::CONFIG['DLEXT']
119119
target_path = File.join(ext_dir, "codetracer_ruby_recorder.#{dlext}")
120+
121+
unless File.exist?(target_path)
122+
# When built via rb_sys during gem installation, the extension is
123+
# placed directly under the gem's lib directory.
124+
lib_path = File.expand_path("codetracer_ruby_recorder.#{dlext}", __dir__)
125+
target_path = lib_path if File.exist?(lib_path)
126+
end
127+
120128
unless File.exist?(target_path)
121129
extensions = %w[so bundle dylib dll]
122130
alt_path = extensions

0 commit comments

Comments
 (0)