Skip to content

Commit 9cc23ec

Browse files
committed
wip: ruby gem tooling
1 parent 87fa3ec commit 9cc23ec

File tree

6 files changed

+43
-34
lines changed

6 files changed

+43
-34
lines changed

pyroscope_ffi/ruby/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.DS_Store
33
**/target
44
*.so
5+
tmp

pyroscope_ffi/ruby/Rakefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
# frozen_string_literal: true
22

3-
load File.expand_path('./ext/rbspy/Rakefile', __dir__)
3+
require 'rake/extensiontask'
4+
45
load File.expand_path('./ext/thread_id/Rakefile', __dir__)
6+
load File.expand_path('./ext/rbspy/Rakefile', __dir__)
57

68
task default: %w[hello]
79

810
task :hello do
911
puts 'Hello!'
1012
end
13+
14+
Rake::ExtensionTask.new('thread_id')
15+
Rake::ExtensionTask.new('rbspy')

pyroscope_ffi/ruby/ext/rbspy/Rakefile

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require "shellwords"
44

5-
class RakeCargoHelper
5+
class RbspyRakeCargoHelper
66
attr_reader :gemname
77

88
def initialize(gemname=File.basename(__dir__))
@@ -104,54 +104,55 @@ class RakeCargoHelper
104104

105105
end
106106

107-
task default: [:install, :clean]
107+
task default: [:rbspy_install, :rbspy_clean]
108+
task rbspy: [:rbspy_install, :rbspy_clean]
108109

109110
desc "set dev mode for subsequent task, run like `rake dev install`"
110-
task :dev do
111+
task :rbspy_dev do
111112
@dev = true
112113
end
113114

114115
desc "build gem native extension and copy to lib"
115-
task install: [:cd, :build] do
116-
helper = RakeCargoHelper.new
116+
task rbspy_install: [:rbspy_cd, :rbspy_build] do
117+
helper = RbspyRakeCargoHelper.new
117118
profile_dir = @dev ? "debug" : "release"
118-
source = File.join(RakeCargoHelper.cargo_target_dir, profile_dir, helper.rust_name)
119+
source = File.join(RbspyRakeCargoHelper.cargo_target_dir, profile_dir, helper.rust_name)
119120
dest = File.join(helper.install_dir, helper.ruby_name)
120121
mkdir_p(helper.install_dir)
121122
rm(dest) if File.exist?(dest)
122123
cp(source, dest)
123124
end
124125

125126
desc "build gem native extension"
126-
task build: [:cargo, :cd] do
127-
sh "cargo", "rustc", *(["--locked", "--release"] unless @dev), "--", *RakeCargoHelper.flags
127+
task rbspy_build: [:rbspy_cargo, :rbspy_cd] do
128+
sh "cargo", "rustc", *(["--locked", "--release"] unless @dev), "--", *RbspyRakeCargoHelper.flags
128129
end
129130

130131
desc "clean up release build artifacts"
131-
task clean: [:cargo, :cd] do
132+
task rbspy_clean: [:rbspy_cargo, :rbspy_cd] do
132133
sh "cargo clean --release"
133134
end
134135

135136
desc "clean up build artifacts"
136-
task clobber: [:cargo, :cd] do
137+
task rbspy_clobber: [:rbspy_cargo, :rbspy_cd] do
137138
sh "cargo clean"
138139
end
139140

140141
desc "check for cargo"
141-
task :cargo do
142-
raise <<-MSG unless RakeCargoHelper.command?("cargo")
142+
task :rbspy_cargo do
143+
raise <<-MSG unless RbspyRakeCargoHelper.command?("cargo")
143144
This gem requires a Rust compiler and the `cargo' build tool to build the
144145
gem's native extension. See https://www.rust-lang.org/tools/install for
145146
how to install Rust. `cargo' is usually part of the Rust installation.
146147
MSG
147148

148-
raise <<-MSG if Gem.win_platform? && RakeCargoHelper.rust_toolchain !~ /gnu/
149-
Found Rust toolchain `#{RakeCargoHelper.rust_toolchain}' but the gem native
149+
raise <<-MSG if Gem.win_platform? && RbspyRakeCargoHelper.rust_toolchain !~ /gnu/
150+
Found Rust toolchain `#{RbspyRakeCargoHelper.rust_toolchain}' but the gem native
150151
extension requires the gnu toolchain on Windows.
151152
MSG
152153
end
153154

154155
# ensure task is running in the right dir
155-
task :cd do
156+
task :rbspy_cd do
156157
cd(__dir__) unless __dir__ == pwd
157158
end
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
require 'mkmf'
2+
require 'rb_sys/mkmf'
23
require 'rake'
34

4-
create_makefile('rbspy')
5+
create_rust_makefile('rbspy')
56

67
app = Rake.application
78
app.init
89
app.add_import 'Rakefile'
910
app.load_rakefile
1011

11-
app['default'].invoke
12+
app['rbspy'].invoke

pyroscope_ffi/ruby/ext/thread_id/Rakefile

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require "shellwords"
44

5-
class RakeCargoHelper
5+
class ThreadIdRakeCargoHelper
66
attr_reader :gemname
77

88
def initialize(gemname=File.basename(__dir__))
@@ -104,54 +104,55 @@ class RakeCargoHelper
104104

105105
end
106106

107-
task default: [:install, :clean]
107+
task default: [:thread_id_install, :thread_id_clean]
108+
task thread_id: [:thread_id_install, :thread_id_clean]
108109

109110
desc "set dev mode for subsequent task, run like `rake dev install`"
110-
task :dev do
111+
task :thread_id_dev do
111112
@dev = true
112113
end
113114

114115
desc "build gem native extension and copy to lib"
115-
task install: [:cd, :build] do
116-
helper = RakeCargoHelper.new
116+
task thread_id_install: [:thread_id_cd, :thread_id_build] do
117+
helper = ThreadIdRakeCargoHelper.new
117118
profile_dir = @dev ? "debug" : "release"
118-
source = File.join(RakeCargoHelper.cargo_target_dir, profile_dir, helper.rust_name)
119+
source = File.join(ThreadIdRakeCargoHelper.cargo_target_dir, profile_dir, helper.rust_name)
119120
dest = File.join(helper.install_dir, helper.ruby_name)
120121
mkdir_p(helper.install_dir)
121122
rm(dest) if File.exist?(dest)
122123
cp(source, dest)
123124
end
124125

125126
desc "build gem native extension"
126-
task build: [:cargo, :cd] do
127-
sh "cargo", "rustc", *(["--locked", "--release"] unless @dev), "--", *RakeCargoHelper.flags
127+
task thread_id_build: [:thread_id_cargo, :thread_id_cd] do
128+
sh "cargo", "rustc", *(["--locked", "--release"] unless @dev), "--", *ThreadIdRakeCargoHelper.flags
128129
end
129130

130131
desc "clean up release build artifacts"
131-
task clean: [:cargo, :cd] do
132+
task thread_id_clean: [:thread_id_cargo, :thread_id_cd] do
132133
sh "cargo clean --release"
133134
end
134135

135136
desc "clean up build artifacts"
136-
task clobber: [:cargo, :cd] do
137+
task thread_id_clobber: [:thread_id_cargo, :thread_id_cd] do
137138
sh "cargo clean"
138139
end
139140

140141
desc "check for cargo"
141-
task :cargo do
142-
raise <<-MSG unless RakeCargoHelper.command?("cargo")
142+
task :thread_id_cargo do
143+
raise <<-MSG unless ThreadIdRakeCargoHelper.command?("cargo")
143144
This gem requires a Rust compiler and the `cargo' build tool to build the
144145
gem's native extension. See https://www.rust-lang.org/tools/install for
145146
how to install Rust. `cargo' is usually part of the Rust installation.
146147
MSG
147148

148-
raise <<-MSG if Gem.win_platform? && RakeCargoHelper.rust_toolchain !~ /gnu/
149-
Found Rust toolchain `#{RakeCargoHelper.rust_toolchain}' but the gem native
149+
raise <<-MSG if Gem.win_platform? && ThreadIdRakeCargoHelper.rust_toolchain !~ /gnu/
150+
Found Rust toolchain `#{ThreadIdRakeCargoHelper.rust_toolchain}' but the gem native
150151
extension requires the gnu toolchain on Windows.
151152
MSG
152153
end
153154

154155
# ensure task is running in the right dir
155-
task :cd do
156+
task :thread_id_cd do
156157
cd(__dir__) unless __dir__ == pwd
157158
end

pyroscope_ffi/ruby/ext/thread_id/extconf.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
app.add_import 'Rakefile'
99
app.load_rakefile
1010

11-
app['default'].invoke
11+
app['thread_id'].invoke

0 commit comments

Comments
 (0)