New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Truffle] Compile c specs with extconf make #4326
Conversation
Looks good. You could also just move the files in the repo and commit that. |
File.open(File.join(temp_dir, "extconf.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.rb" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RbConfig.ruby
FileUtils.cp source, copy | ||
extconf_src = "require 'mkmf'\n" + | ||
"create_makefile('#{ext}', '#{temp_dir}')" # , | ||
File.open(File.join(temp_dir, "extconf.rb"), 'w') {|f| f.write(extconf_src) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space between {
and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or alternatively use File.write
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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could just have just temp_dir
for the second argument
system "#{ruby} extconf.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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why copy_file
but cp
above?
Looks good, please address my comments. |
Ha you hate File.join! |
@chrisseaton Indeed 😄 |
076a80d
to
372a227
Compare
@eregon I've pushed an update with all your recommended updates, thanks |
This is a lot easier to read, thanks! 👍 |
ext = "#{name}_spec" | ||
file = "#{ext}.c" | ||
source = "#{path}/#{file}" | ||
temp_dir = Dir.mktmpdir |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be right before the begin
, otherwise it could leave an extra tmpdir if the lines below fail.
One way is moving those lines in the begin.
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}/#{ext}.ll" # copy to .ll file to library dir |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the second argument can be just objdir
Let's merge this once my final nitpicks are adressed 😃 |
372a227
to
097bb54
Compare
@eregon I just pushed updates for the last two comments |
It looks like
mkmf
will always look for all c files in the directory. So, I copied the c spec to a temp directory for compilation. This appears to be working. It may run a little slower than the previous method since I had to runextconf.rb
with another jruby+truffle (or the makefile would contain values from previous extension).cc: @chrisseaton