diff --git a/Gemfile b/Gemfile index afffcc2..2c76704 100644 --- a/Gemfile +++ b/Gemfile @@ -2,3 +2,5 @@ source 'https://rubygems.org' # Specify your gem's dependencies in zstd_ruby.gemspec gemspec + +gem 'ruby_memcheck', '~> 3.0' if RUBY_PLATFORM.include?('linux') diff --git a/Rakefile b/Rakefile index f76e1c2..a2eb7e5 100644 --- a/Rakefile +++ b/Rakefile @@ -15,6 +15,34 @@ end task :default => [:clobber, :compile, :spec] +if RUBY_PLATFORM.include?('linux') + begin + require 'ruby_memcheck' + require 'ruby_memcheck/rspec/rake_task' + + RubyMemcheck.config( + binary_name: 'zstdruby', + # Valgrind and YJIT interfere with each other, adding noise and slowdown, + # so keep YJIT disabled while running under Valgrind. + ruby: "#{FileUtils::RUBY} --disable-yjit" + ) + + namespace :spec do + task :check_valgrind do + unless system('command -v valgrind > /dev/null 2>&1') + abort("\nValgrind is required for `rake spec:valgrind` but was not found.\n" \ + "Install it first (Linux only), e.g. `sudo apt-get install valgrind`.\n") + end + end + + RubyMemcheck::RSpec::RakeTask.new(valgrind: [:check_valgrind, :compile]) + end + rescue LoadError + # ruby_memcheck is an optional, Linux-only development dependency. If it is + # not installed just skip defining the task instead of breaking the Rakefile. + end +end + desc 'Sync zstd libs dirs to ext/zstdruby/libzstd' task :zstd_update do FileUtils.rm_r("ext/zstdruby/libzstd")