diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..de98947a7 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,38 @@ +name: CI +on: [push, pull_request] +jobs: + specs: + strategy: + fail-fast: false + matrix: + os: [ ubuntu, macos, windows ] + ruby: [ 2.3, 2.4, 2.5, 2.6, 2.7, ruby-head, truffleruby-head ] + exclude: + - os: windows + ruby: truffleruby-head + - os: windows + ruby: 2.3 # compilation fails + runs-on: ${{ matrix.os }}-latest + env: + MAKE: "make" # to not try to use gmake on Windows + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + + - run: brew install automake + if: matrix.os == 'macos' + + # Bundler 2 seems to fix installing rubygems-tasks on Ruby < 2.4 + - run: gem install bundler + - run: bundle install + - run: bundle exec rake libffi + - run: bundle exec rake compile + + - run: bundle exec rake test + + - run: bundle exec rake bench:all + if: matrix.ruby != 'truffleruby-head' + env: + ITER: 10 diff --git a/Rakefile b/Rakefile index 644eab7b2..91eaba49e 100644 --- a/Rakefile +++ b/Rakefile @@ -45,7 +45,7 @@ task :test => [ :spec ] namespace :bench do ITER = ENV['ITER'] ? ENV['ITER'].to_i : 100000 - bench_files = Dir["bench/bench_*.rb"].reject { |f| f == "bench/bench_helper.rb" } + bench_files = Dir["bench/bench_*.rb"].sort.reject { |f| f == "bench/bench_helper.rb" } bench_files.each do |bench| task File.basename(bench, ".rb")[6..-1] => :compile do sh %{#{Gem.ruby} #{bench} #{ITER}} diff --git a/bench/bench_getlogin.rb b/bench/bench_getlogin.rb index c5824f4e1..2112cdf40 100644 --- a/bench/bench_getlogin.rb +++ b/bench/bench_getlogin.rb @@ -9,8 +9,12 @@ module Posix ffi_lib FFI::Library::LIBC attach_function :getlogin, [], :string end - if Posix.getlogin != Etc.getlogin - raise ArgumentError, "FFI getlogin returned incorrect value" + + # getlogin(2) might return NULL, in which case Etc.getlogin uses ENV["USER"]. + # This should not matter for this benchmark, getlogin() is still called. + if (Posix.getlogin || ENV["USER"]) != Etc.getlogin + raise ArgumentError, "FFI getlogin returned incorrect value: " \ + "#{Posix.getlogin.inspect} (FFI) vs #{Etc.getlogin.inspect} (Etc)" end puts "Benchmark FFI getlogin(2) performance, #{ITER}x" @@ -27,4 +31,4 @@ module Posix iter.times { Etc.getlogin } } } -end +end unless FFI::Platform.windows? diff --git a/bench/bench_gettimeofday.rb b/bench/bench_gettimeofday.rb index 5884d76c3..848fa87d3 100644 --- a/bench/bench_gettimeofday.rb +++ b/bench/bench_gettimeofday.rb @@ -50,4 +50,4 @@ class Timeval < FFI::Struct iter.times { Time.now } } } -end +end unless FFI::Platform.windows? diff --git a/bench/bench_getuid.rb b/bench/bench_getuid.rb index 25aec5398..e82722139 100644 --- a/bench/bench_getuid.rb +++ b/bench/bench_getuid.rb @@ -24,4 +24,4 @@ module Posix iter.times { Process.uid } } } -end +end unless FFI::Platform.windows? diff --git a/bench/bench_math.rb b/bench/bench_math.rb index bea286840..24f4b7be4 100644 --- a/bench/bench_math.rb +++ b/bench/bench_math.rb @@ -3,7 +3,7 @@ module BenchMath module FFIMath extend FFI::Library - ffi_lib 'm' + ffi_lib FFI::Platform.windows? ? FFI::Library::LIBC : 'm' attach_function :cos, [ :double ], :double attach_function :cosf, [ :float ], :float end diff --git a/bench/bench_umask.rb b/bench/bench_umask.rb index 3692c35c7..1bb547387 100644 --- a/bench/bench_umask.rb +++ b/bench/bench_umask.rb @@ -59,4 +59,4 @@ def self.umask(mask = nil) ITER.times { NativeFile.umask } } } -end +end unless FFI::Platform.windows?