Skip to content

Commit be47600

Browse files
authored
Merge pull request #147 from Watson1978/feature/valgrind-memcheck
Add Valgrind memcheck (ruby_memcheck) for the C extension
2 parents 2d3e95d + 564dcf5 commit be47600

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
22

33
# Specify your gem's dependencies in zstd_ruby.gemspec
44
gemspec
5+
6+
gem 'ruby_memcheck', '~> 3.0' if RUBY_PLATFORM.include?('linux')

Rakefile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,34 @@ end
1515

1616
task :default => [:clobber, :compile, :spec]
1717

18+
if RUBY_PLATFORM.include?('linux')
19+
begin
20+
require 'ruby_memcheck'
21+
require 'ruby_memcheck/rspec/rake_task'
22+
23+
RubyMemcheck.config(
24+
binary_name: 'zstdruby',
25+
# Valgrind and YJIT interfere with each other, adding noise and slowdown,
26+
# so keep YJIT disabled while running under Valgrind.
27+
ruby: "#{FileUtils::RUBY} --disable-yjit"
28+
)
29+
30+
namespace :spec do
31+
task :check_valgrind do
32+
unless system('command -v valgrind > /dev/null 2>&1')
33+
abort("\nValgrind is required for `rake spec:valgrind` but was not found.\n" \
34+
"Install it first (Linux only), e.g. `sudo apt-get install valgrind`.\n")
35+
end
36+
end
37+
38+
RubyMemcheck::RSpec::RakeTask.new(valgrind: [:check_valgrind, :compile])
39+
end
40+
rescue LoadError
41+
# ruby_memcheck is an optional, Linux-only development dependency. If it is
42+
# not installed just skip defining the task instead of breaking the Rakefile.
43+
end
44+
end
45+
1846
desc 'Sync zstd libs dirs to ext/zstdruby/libzstd'
1947
task :zstd_update do
2048
FileUtils.rm_r("ext/zstdruby/libzstd")

0 commit comments

Comments
 (0)