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
Use "make install" instead of manually copying extension binary #191
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,7 @@ def define_compile_tasks(for_platform = nil, ruby_ver = RUBY_VERSION) | |
tmp_path = "#{@tmp_dir}/#{platf}/#{@name}/#{ruby_ver}" | ||
stage_path = "#{@tmp_dir}/#{platf}/stage" | ||
|
||
siteconf_path = "#{tmp_path}/.rake-compiler-siteconf.rb" | ||
tmp_binary_path = "#{tmp_path}/#{binary_path}" | ||
tmp_binary_dir_path = File.dirname(tmp_binary_path) | ||
stage_binary_path = "#{stage_path}/#{lib_path}/#{binary_path}" | ||
|
@@ -132,10 +133,27 @@ def define_compile_tasks(for_platform = nil, ruby_ver = RUBY_VERSION) | |
directory lib_binary_dir_path | ||
directory stage_binary_dir_path | ||
|
||
directory File.dirname(siteconf_path) | ||
# Set paths for "make install" destinations | ||
file siteconf_path => File.dirname(siteconf_path) do | ||
File.open(siteconf_path, "w") do |siteconf| | ||
siteconf.puts "require 'rbconfig'" | ||
siteconf.puts "require 'mkmf'" | ||
siteconf.puts "dest_path = mkintpath(#{File.expand_path(lib_path).dump})" | ||
%w[sitearchdir sitelibdir].each do |dir| | ||
siteconf.puts "RbConfig::MAKEFILE_CONFIG['#{dir}'] = dest_path" | ||
siteconf.puts "RbConfig::CONFIG['#{dir}'] = dest_path" | ||
Comment on lines
+144
to
+145
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is highly problematic, could you find a way which does not mutate RbConfig, as that can break many things? |
||
end | ||
end | ||
end | ||
|
||
# copy binary from temporary location to final lib | ||
# tmp/extension_name/extension_name.{so,bundle} => lib/ | ||
task "copy:#{@name}:#{platf}:#{ruby_ver}" => [lib_binary_dir_path, tmp_binary_path] do | ||
install tmp_binary_path, "#{lib_path}/#{binary_path}" | ||
task "copy:#{@name}:#{platf}:#{ruby_ver}" => [lib_binary_dir_path, tmp_binary_path, "#{tmp_path}/Makefile"] do | ||
# install in lib for native platform only | ||
unless for_platform | ||
sh "#{make} install", chdir: tmp_path | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is how I did it first, but then I noticed, that it doesn't work if one sets the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. |
||
end | ||
end | ||
# copy binary from temporary location to staging directory | ||
task "copy:#{@name}:#{platf}:#{ruby_ver}" => [stage_binary_dir_path, tmp_binary_path] do | ||
|
@@ -164,12 +182,12 @@ def define_compile_tasks(for_platform = nil, ruby_ver = RUBY_VERSION) | |
|
||
# makefile depends of tmp_dir and config_script | ||
# tmp/extension_name/Makefile | ||
file "#{tmp_path}/Makefile" => [tmp_path, extconf] do |t| | ||
file "#{tmp_path}/Makefile" => [tmp_path, extconf, siteconf_path] do |t| | ||
options = @config_options.dup | ||
|
||
# include current directory | ||
include_dirs = ['.'].concat(@config_includes).uniq.join(File::PATH_SEPARATOR) | ||
cmd = [Gem.ruby, "-I#{include_dirs}"] | ||
cmd = [Gem.ruby, "-I#{include_dirs}", "-r#{File.basename(siteconf_path)}"] | ||
|
||
# build a relative path to extconf script | ||
abs_tmp_path = (Pathname.new(Dir.pwd) + tmp_path).realpath | ||
|
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 is the same mechanism as used in rubygems. However we're using an absolute
dest_path
here, which has to be passed throughmkintpath
to properly work on Windows. In contrast rubygems uses a relative path and subsequently copies the files from a temporary directory to the destination extension directory.