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 a4727a2 commit 338aba2
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 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,33 @@ 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 = File.join(path, file)
temp_dir = Dir.mktmpdir
copy = File.join(temp_dir, file)
lib_target = File.join(objdir, "#{ext}.#{RbConfig::CONFIG['DLEXT']}")
begin
FileUtils.cp File.join(path, "rubyspec.h"), File.join(temp_dir, "rubyspec.h")
FileUtils.cp File.join(path, "jruby_truffle.h"), File.join(temp_dir, "jruby_truffle.h")
FileUtils.cp source, copy
extconf_src = "require 'mkmf'\n" +
"create_makefile('#{ext}', '#{temp_dir}')" # ,
File.open(File.join(temp_dir, "extconf_#{ext}.rb"), 'w') {|f| f.write(extconf_src) }
Dir.chdir(temp_dir) do
ruby = File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["RUBY_INSTALL_NAME"])
system "#{ruby} extconf_#{ext}.rb"
system "make" # run make in temp dir
FileUtils.copy_file("#{ext}.su", lib_target) # copy to .su file to library dir
FileUtils.copy_file("#{ext}.ll", File.join(objdir, "#{ext}.ll")) # copy to .ll file to library dir
end
ensure
FileUtils.remove_entry dir
end
lib_target
end

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

0 comments on commit 338aba2

Please sign in to comment.