Skip to content

Commit

Permalink
Merge pull request #761 from eregon/fix-ci-truffleruby
Browse files Browse the repository at this point in the history
Fix remaining issues to make TruffleRuby pass the CI
  • Loading branch information
larskanis committed Mar 30, 2020
2 parents 6dfc35f + 300c623 commit b89831d
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 26 deletions.
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ script:
- bundle exec rake libffi
- bundle exec rake compile
- bundle exec rake test
- ITER=10 bundle exec rake bench:all
- |
if [[ $(ruby -v) != *truffleruby* ]]; then
ITER=10 bundle exec rake bench:all
fi
os:
- linux
- osx
Expand All @@ -32,7 +35,6 @@ matrix:
rvm: 2.3.8
- os: linux
rvm: ruby-head
- rvm: truffleruby-head
include:
- name: powerpc
language: generic
Expand All @@ -48,5 +50,8 @@ matrix:
docker build --rm -t ffi-armhf -f spec/env/Dockerfile.armhf .
script: |
docker run --rm -t -v `pwd`:/ffi ffi-armhf
exclude:
- os: osx
rvm: truffleruby-head
after_failure:
- "find build -name mkmf.log | xargs cat"
12 changes: 5 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'rubygems/tasks'
require 'rbconfig'
require 'rake/clean'
require File.expand_path("./lib/ffi/version")
require_relative "lib/ffi/version"

require 'date'
require 'fileutils'
Expand Down Expand Up @@ -45,16 +45,15 @@ task :test => [ :spec ]

namespace :bench do
ITER = ENV['ITER'] ? ENV['ITER'].to_i : 100000
bench_libs = "-Ilib" unless RUBY_PLATFORM == "java"
bench_files = Dir["bench/bench_*.rb"].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_libs} #{bench} #{ITER}}
sh %{#{Gem.ruby} #{bench} #{ITER}}
end
end
task :all => :compile do
bench_files.each do |bench|
sh %{#{Gem.ruby} #{bench_libs} #{bench}}
sh %{#{Gem.ruby} #{bench}}
end
end
end
Expand Down Expand Up @@ -149,14 +148,13 @@ end.each do |f|
end
end

$LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'lib')
require 'ffi/platform'
require_relative "lib/ffi/platform"
types_conf = File.expand_path(File.join(FFI::Platform::CONF_DIR, 'types.conf'))
logfile = File.join(File.dirname(__FILE__), 'types_log')

file types_conf => File.join("lib", "ffi", "version.rb") do |task|
require 'fileutils'
require 'ffi/tools/types_generator'
require_relative "lib/ffi/tools/types_generator"
options = {}
FileUtils.mkdir_p(File.dirname(task.name), { :mode => 0755 })
File.open(task.name, File::CREAT|File::TRUNC|File::RDWR, 0644) do |f|
Expand Down
3 changes: 1 addition & 2 deletions bench/bench_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
lib = File.expand_path('../../lib', __FILE__)

cext = "#{lib}/ffi_c.#{RbConfig::CONFIG['DLEXT']}"
if (!defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx') &&
!File.exist?(cext)
if (RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx') && !File.exist?(cext)
abort "#{cext} is not compiled. Compile it with 'rake compile' first."
end

Expand Down
2 changes: 1 addition & 1 deletion bench/bench_memptr_alloc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module LibC
}
end

if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
if RUBY_ENGINE == "jruby"
require 'java'
puts "calling java gc"
10.times {
Expand Down
2 changes: 1 addition & 1 deletion ext/ffi_c/extconf.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby

if !defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
if RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
require 'mkmf'
require 'rbconfig'

Expand Down
4 changes: 2 additions & 2 deletions lib/ffi.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if !defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
if RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
Object.send(:remove_const, :FFI) if defined?(::FFI)
begin
require RUBY_VERSION.split('.')[0, 2].join('.') + '/ffi_c'
Expand All @@ -8,7 +8,7 @@

require 'ffi/ffi'

elsif defined?(RUBY_ENGINE)
else
# Remove the ffi gem dir from the load path, then reload the internal ffi implementation
$LOAD_PATH.delete(File.dirname(__FILE__))
$LOAD_PATH.delete(File.join(File.dirname(__FILE__), 'ffi'))
Expand Down
2 changes: 1 addition & 1 deletion spec/ffi/embed-test/ext/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# For licensing, see LICENSE.SPECS
#

if !defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
if RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
require "mkmf"

create_makefile("embed_test")
Expand Down
6 changes: 3 additions & 3 deletions spec/ffi/long_double_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
require 'bigdecimal'

# long double not yet supported on TruffleRuby
describe ":long_double arguments and return values", :if => RUBY_ENGINE != "truffleruby" && RUBY_PLATFORM !~ /mingw|mswin/ do
describe ":long_double arguments and return values", if: RUBY_PLATFORM !~ /mingw|mswin/ do
module LibTest
extend FFI::Library
ffi_lib TestLibrary::PATH
attach_function :add_f128, [ :long_double, :long_double ], :long_double
attach_function :ret_f128, [ :long_double ], :long_double
end if RUBY_ENGINE != "truffleruby"
end

it "returns first parameter" do
expect(LibTest.ret_f128(0.1)).to be_within(0.01).of(0.1)
Expand All @@ -28,4 +28,4 @@ module LibTest
it "add two long double numbers" do
expect(LibTest.add_f128(0.1, 0.2)).to be_within(0.01).of(0.3)
end
end
end if RUBY_ENGINE != "truffleruby"
4 changes: 2 additions & 2 deletions spec/ffi/number_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ module LibTest
end
end
# range checks are not yet supported on TruffleRuby
describe "Integer parameter range checking", :if => RUBY_ENGINE != "truffleruby" do
describe "Integer parameter range checking" do
[ 128, -129 ].each do |i|
it ":char call(:char (#{i}))" do
expect { expect(LibTest.ret_s8(i)).to eq(i) }.to raise_error(Exception) { |error| expect([RSpec::Expectations::ExpectationNotMetError, RangeError]).to be_include(error.class) }
Expand Down Expand Up @@ -174,7 +174,7 @@ module LibTest
expect { expect(LibTest.ret_u32(i)).to eq(i) }.to raise_error(Exception) { |error| expect([RSpec::Expectations::ExpectationNotMetError, RangeError]).to be_include(error.class) }
end
end
end
end if RUBY_ENGINE != "truffleruby"
describe "Three different size Integer arguments" do
TYPE_MAP = {
's8' => :char, 'u8' => :uchar, 's16' => :short, 'u16' => :ushort,
Expand Down
4 changes: 2 additions & 2 deletions spec/ffi/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

module TestLibrary
def self.force_gc
if RUBY_PLATFORM =~ /java/
if RUBY_ENGINE == 'jruby'
java.lang.System.gc
elsif defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
elsif RUBY_ENGINE == 'rbx'
GC.run(true)
else
GC.start
Expand Down
6 changes: 3 additions & 3 deletions spec/ffi/struct_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ class ContainerStruct < FFI::Struct
end

# struct by value not yet supported on TruffleRuby
describe FFI::Struct, ' by value', :if => RUBY_ENGINE != "truffleruby" do
describe FFI::Struct, ' by value' do
module LibTest
extend FFI::Library
ffi_lib TestLibrary::PATH
Expand All @@ -714,7 +714,7 @@ class StructString < FFI::Struct
attach_function :struct_s8s32_ret_s8s32, [ S8S32.by_value ], S8S32.by_value
attach_function :struct_s32_ptr_s32_s8s32_ret_s32, [ :int, :pointer, :int, S8S32.by_value ], :int
attach_function :struct_varargs_ret_struct_string, [ :int, :varargs ], StructString.by_value
end if RUBY_ENGINE != "truffleruby"
end

it 'return using pre-set values' do
s = LibTest.struct_return_s8s32
Expand Down Expand Up @@ -787,7 +787,7 @@ class StructString < FFI::Struct
expect(s[:len]).to eq(string.length)
expect(s[:bytes]).to eq(string)
end
end
end if RUBY_ENGINE != "truffleruby"

describe FFI::Struct, ' with an array field' do
module LibTest
Expand Down

0 comments on commit b89831d

Please sign in to comment.