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

Use "make install" instead of manually copying extension binary #191

Merged
merged 1 commit into from Apr 2, 2021

Conversation

larskanis
Copy link
Member

@larskanis larskanis commented Mar 27, 2021

Until now rake-compiler uses make to build the extension binary, but doesn't use make install to copy it into the lib directory. This has the downside, that only the extension binary is copied, but no additional files. In particular files registered per mkmf's $INSTALLFILES mechanism are not respected. Using make install fixes this and possibly also #189.

With this PR, the call to make install is not invoked for cross ruby tasks but only for native compile. This changes the cross build, so that cross compiled extension binaries are no longer copied into the native lib directory. IMHO that makes sense in any case, since the cross compiled extension binaries belong into the platform gems only and are superfluous in the native lib directory.

As another extension to this PR, it might be useful to run the cross packaging tasks through make install as well. However the cross build and packaging is way more complex and at least in case of the pg gem, it is not helpful, since the $INSTALLFILES are not necessary for cross builds.

Fixes #190

Until now rake-compiler uses "make" to build the extension binary, but doesn't use "make install" to copy it into the lib directory.
This has the downside, that only the extension binary is copied, but no additional files.
In particular files registered per mkmf's $INSTALLFILES mechanism are not respected.
Using "make install" fixes this.
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})"
Copy link
Member Author

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 through mkintpath 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.

Copy link

@dylanahsmith dylanahsmith left a comment

Choose a reason for hiding this comment

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

I also tested on MacOS with ruby/ruby#4310 and confirmed that it does copy the *.bundle.dSYM file to lib

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

Choose a reason for hiding this comment

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

Can we use sh make, install, chdir: tmp_path here?

Copy link
Member Author

Choose a reason for hiding this comment

The 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 MAKE environment variable to something like MAKE=make -j8 V=1 . In this case a make binary with spaces in the name is tried to be executed instead of being interpret as command line options. In contrast build tools like autoconf or cmake accept options to make as part of the MAKE environment variable. I therefore think it's best how it is.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks.
I understand.

Comment on lines +144 to +145
siteconf.puts "RbConfig::MAKEFILE_CONFIG['#{dir}'] = dest_path"
siteconf.puts "RbConfig::CONFIG['#{dir}'] = dest_path"
Copy link

Choose a reason for hiding this comment

The 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?
See #202

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.

Supplementary files are not copied to the lib directory
4 participants