Skip to content

Commit 8c5d628

Browse files
committed
feat(native): package extension with rb_sys (#20)
Summary: - package native extension with rb_sys - provide publishing instructions in the extension README
1 parent f83529c commit 8c5d628

File tree

7 files changed

+64
-4
lines changed

7 files changed

+64
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
!test/benchmarks/fixtures/*.json
55
test/tmp/
66
.direnv/
7+
pkg/

Rakefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'rb_sys/extensiontask'
2+
3+
RbSys::ExtensionTask.new('codetracer_ruby_native_recorder') do |ext|
4+
ext.ext_dir = 'ext/native_tracer'
5+
ext.lib_dir = 'src'
6+
ext.gem_spec = Gem::Specification.load('codetracer-ruby-recorder.gemspec')
7+
end

codetracer-ruby-recorder.gemspec

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Gem::Specification.new do |spec|
2+
spec.name = 'codetracer-ruby-recorder'
3+
spec.version = '0.1.0'
4+
spec.authors = ['Metacraft Labs']
5+
spec.email = ['info@metacraft-labs.com']
6+
7+
spec.summary = 'CodeTracer Ruby recorder with native extension'
8+
spec.description = 'Ruby tracer that records execution steps via a Rust native extension.'
9+
spec.license = 'MIT'
10+
spec.homepage = 'https://github.com/metacraft-labs/codetracer-ruby-recorder'
11+
12+
spec.files = Dir['src/**/*', 'ext/native_tracer/**/{Cargo.toml,*.rs}', 'ext/native_tracer/extconf.rb', 'README.md', 'LICENSE']
13+
spec.require_paths = ['src']
14+
spec.extensions = ['ext/native_tracer/extconf.rb']
15+
16+
spec.add_development_dependency 'rb_sys', '~> 0.9'
17+
end

ext/native_tracer/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "codetracer_ruby_native_recoreder"
2+
name = "codetracer_ruby_native_recorder"
33
version = "0.1.0"
44
edition = "2021" # latest stable Rust edition
55
description = "Native Ruby tracer using rb_add_event_hook2"

ext/native_tracer/README.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# codetracer_ruby_native_recoreder
1+
# codetracer_ruby_native_recorder
22

33
This crate provides a minimal Ruby tracer implemented in Rust.
44
It registers a Ruby VM event hook using `rb_add_event_hook2` and
@@ -17,8 +17,39 @@ If you have `just` installed, run `just build-extension` from the project root.
1717
The produced shared library can be required from Ruby:
1818

1919
```ruby
20-
require_relative 'target/release/libcodetracer_ruby_native_recoreder'
20+
require_relative 'target/release/libcodetracer_ruby_native_recorder'
2121
```
2222

2323
Once loaded, the tracer starts writing a trace to `trace.json` or the
2424
path specified via the `CODETRACER_DB_TRACE_PATH` environment variable.
25+
26+
## Publishing platform-specific gems
27+
28+
This extension can be packaged as a Ruby gem so the compiled library is
29+
distributed for each target platform. The gemspec at the project root uses
30+
[`rb_sys`](https://github.com/oxidize-rb/rb-sys) to build the library.
31+
32+
To publish prebuilt binaries:
33+
34+
1. Install the development dependencies:
35+
36+
```bash
37+
bundle install
38+
```
39+
40+
2. For each target triple, set `RB_SYS_CARGO_TARGET` and run the packaging task:
41+
42+
```bash
43+
RB_SYS_CARGO_TARGET=x86_64-unknown-linux-gnu rake cross_native_gem
44+
```
45+
46+
Replace the target triple with the platform you want to build for, e.g.
47+
`aarch64-apple-darwin` or `x86_64-pc-windows-msvc`.
48+
49+
3. Push the generated gem from the `pkg/` directory to RubyGems:
50+
51+
```bash
52+
gem push pkg/codetracer-ruby-recorder-0.1.0-x86_64-linux.gem
53+
```
54+
55+
Repeat these steps for each platform to provide platform-specific gems.

ext/native_tracer/extconf.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require 'mkmf'
2+
require 'rb_sys/mkmf'
3+
4+
create_rust_makefile('codetracer_ruby_native_recorder')

ext/native_tracer/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extern "C" fn event_hook(ev: rb_event_flag_t, _data: VALUE, _self: VALUE, _mid:
2323
}
2424

2525
#[no_mangle]
26-
pub extern "C" fn Init_codetracer_ruby_native_recoreder() {
26+
pub extern "C" fn Init_codetracer_ruby_native_recorder() {
2727
unsafe {
2828
let out = std::env::var("CODETRACER_DB_TRACE_PATH").unwrap_or_else(|_| "trace.json".to_string());
2929
let file = std::fs::File::create(out).expect("failed to create trace output");

0 commit comments

Comments
 (0)