Skip to content
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

Merged
merged 1 commit into from Nov 21, 2016

Conversation

bjfish
Copy link
Contributor

@bjfish bjfish commented Nov 21, 2016

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 run extconf.rb with another jruby+truffle (or the makefile would contain values from previous extension).

cc: @chrisseaton

@bjfish bjfish added the truffle label Nov 21, 2016
@chrisseaton
Copy link
Contributor

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"
Copy link
Member

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) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space between { and |

Copy link
Member

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")
Copy link
Member

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
Copy link
Member

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?

@eregon
Copy link
Member

eregon commented Nov 21, 2016

Looks good, please address my comments.
In general, don't bother with File.join, it just adds / between the arguments, even on Windows, and adds quite a bit of noise.

@chrisseaton
Copy link
Contributor

Ha you hate File.join!

@eregon
Copy link
Member

eregon commented Nov 21, 2016

@chrisseaton Indeed 😄
More precisely, I dislike mixing File/FileUtils and other pathname-related modules, and File.join is usually all over the place when it does nothing useful beyond what would be clearer as "#{bin}/#{ruby}".

@bjfish
Copy link
Contributor Author

bjfish commented Nov 21, 2016

@eregon I've pushed an update with all your recommended updates, thanks

@eregon
Copy link
Member

eregon commented Nov 21, 2016

This is a lot easier to read, thanks! 👍

ext = "#{name}_spec"
file = "#{ext}.c"
source = "#{path}/#{file}"
temp_dir = Dir.mktmpdir
Copy link
Member

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
Copy link
Member

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

@eregon
Copy link
Member

eregon commented Nov 21, 2016

Let's merge this once my final nitpicks are adressed 😃

@bjfish
Copy link
Contributor Author

bjfish commented Nov 21, 2016

@eregon I just pushed updates for the last two comments

@eregon eregon merged commit 491f793 into truffle-head Nov 21, 2016
@eregon eregon deleted the truffle-spec-helper-capi branch November 21, 2016 21:00
@enebo enebo modified the milestone: truffle-dev Jan 10, 2017
@enebo enebo added this to the Non-Release milestone Dec 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants