Skip to content

Commit

Permalink
[Truffle] Compile c specs with extconf make
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Fish committed Nov 21, 2016
1 parent 3d771b9 commit 097bb54
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion spec/ruby/optional/capi/spec_helper.rb
Expand Up @@ -3,6 +3,7 @@

require 'rbconfig'
require 'fileutils'
require 'tmpdir'

OBJDIR ||= File.expand_path("../../../ext/#{RUBY_NAME}/#{RUBY_VERSION}", __FILE__)
FileUtils.makedirs(OBJDIR)
Expand Down Expand Up @@ -43,7 +44,7 @@ def compile_extension(name)
require 'mkmf'
hdrdir = $hdrdir
elsif RUBY_NAME == 'jruby+truffle'
return compile_extension_jruby_truffle(name)
return compile_jruby_truffle_extconf_make(name, path, objdir)
else
raise "Don't know how to build C extensions with #{RUBY_NAME}"
end
Expand Down Expand Up @@ -119,6 +120,32 @@ def compile_extension_jruby_truffle(name)
File.delete(sulong_config_file) if File.exist?(sulong_config_file)
end

def compile_jruby_truffle_extconf_make(name, path, objdir)
ext = "#{name}_spec"
file = "#{ext}.c"
source = "#{path}/#{file}"
lib_target = "#{objdir}/#{ext}.#{RbConfig::CONFIG['DLEXT']}"
temp_dir = Dir.mktmpdir
begin
copy = "#{temp_dir}/#{file}"
FileUtils.cp "#{path}/rubyspec.h", temp_dir
FileUtils.cp "#{path}/jruby_truffle.h", temp_dir
FileUtils.cp source, copy
extconf_src = "require 'mkmf'\n" +
"create_makefile('#{ext}', '#{temp_dir}')"
File.write("#{temp_dir}/extconf.rb", extconf_src)
Dir.chdir(temp_dir) do
system "#{RbConfig.ruby} extconf.rb"
system "make" # run make in temp dir
FileUtils.cp "#{ext}.su", lib_target # copy to .su file to library dir
FileUtils.cp "#{ext}.ll", objdir # copy to .ll file to library dir
end
ensure
FileUtils.remove_entry temp_dir
end
lib_target
end

def load_extension(name)
require compile_extension(name)
end
Expand Down

0 comments on commit 097bb54

Please sign in to comment.