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

Clean built artifacts after building extensions #6133

Merged
merged 3 commits into from
Dec 16, 2022

Conversation

deivid-rodriguez
Copy link
Member

@deivid-rodriguez deivid-rodriguez commented Dec 15, 2022

What was the end-user or developer problem that led to this PR?

Currently installing extensions leaves around intermediary files that may end up taking a lot of disk space.

What is your fix for the problem, implemented in this PR?

Add a clean step after installing the extension.

This PR is based on the useful work by @eloyesp at #4017.

Fixes #3958.

Make sure the following tasks are checked

Copy link
Contributor

@eloyesp eloyesp left a comment

Choose a reason for hiding this comment

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

I like these simplifications a lot, just wanted to add that there might be a secondary bug that was hidden by the build artifacts.

That is: when bundle install a git sourced gem, it adds some non-existing paths to the load path, I've added a check for that on Bundler::Runtime#setup breaking multiple escenarios.

The problem is that I'm not entirely sure how rubygems and bundler interact when building extensions on git sourced gems.

Hope my comments help somehow.

lib/rubygems/ext/builder.rb Outdated Show resolved Hide resolved
lib/rubygems/ext/ext_conf_builder.rb Outdated Show resolved Hide resolved
@deivid-rodriguez deivid-rodriguez force-pushed the clean_build_files_after_install_debug branch from 0afebd2 to 20e84f6 Compare December 16, 2022 10:41
@deivid-rodriguez
Copy link
Member Author

That is: when bundle install a git sourced gem, it adds some non-existing paths to the load path, I've added a check for that on Bundler::Runtime#setup breaking multiple escenarios.

Yeah, building extensions for git gems is a big hack at the moment, and it indeed has the consequence of some paths to be added to the $LOAD_PATH that don't exist. That's actually what prevents us to refactor things further and also stop copying build artifacts to lib_dir, because that's apparently what makes extensions for git gems actually work.

We should refactoring things further to just be able to make, make install, make clean to install extensions, no matter the source. But it sounds too much for this PR.

eloyesp and others added 3 commits December 16, 2022 13:36
Some tests check that the shared objects are actually installed, but
checking an intermediate build file instead of the installed one.
The installed file not always have the `.so` extension.

Co-authored-by: Eloy Espinaco <eloyesp@gmail.com>
@deivid-rodriguez deivid-rodriguez force-pushed the clean_build_files_after_install_debug branch from 20e84f6 to 98b6a95 Compare December 16, 2022 12:38
@deivid-rodriguez deivid-rodriguez marked this pull request as ready for review December 16, 2022 13:45
@deivid-rodriguez deivid-rodriguez marked this pull request as draft December 16, 2022 13:46
@deivid-rodriguez
Copy link
Member Author

deivid-rodriguez commented Dec 16, 2022

After investigating the issues here, I think this is safe to do.

I could only see this breaking if someone is intentionally changing the $LOAD_PATH to point to where the intermediate artifacts live (normally the ext/ folder of an installed gem). These artifacts are already installed in two places right now (the lib folder of the installed gem, and the extensions folder), and both are already in the $LOAD_PATH by default. So it makes no sense that someone did this, and if they did, it can't hardly be considered a breaking change in my opinion. Also, cleanup is currently limited to extconf extension builder, so the scope is even more limited.

So from my side this is ready.

@deivid-rodriguez deivid-rodriguez marked this pull request as ready for review December 16, 2022 14:10
@simi simi self-requested a review December 16, 2022 14:15
@eloyesp
Copy link
Contributor

eloyesp commented Dec 16, 2022

Just one more question, will this impact bundler installs? Is bundler installing gems using the extconf builder or is it running his own builder?

@deivid-rodriguez
Copy link
Member Author

Yes, Bundler delegates to RubyGems to install extensions, so it will use whatever builder each gem uses. If gems define their extension through an extconf.rb file, then Bundler will use that builder from RubyGems.

@simi
Copy link
Member

simi commented Dec 16, 2022

Thanks for digging in this @deivid-rodriguez. I did other review of the build artifact handling. I agree this seems safe. I did quick test to see impact on sassc issue sass/sassc-ruby#200 and bundle size went from 65MB to 25MB.

@simi simi merged commit 49c54da into master Dec 16, 2022
@simi simi deleted the clean_build_files_after_install_debug branch December 16, 2022 16:18
@simi
Copy link
Member

simi commented Dec 16, 2022

Thanks @eloyesp for pushing this forward!

zunda added a commit to zunda/blurhash that referenced this pull request Dec 27, 2022
RubyGems started to clean built artifacts after building extensions
since Ruby 3.2.0: rubygems/rubygems#6133

Related: rubygems/rubygems#6205
akihikodaki added a commit to akihikodaki/cld3-ruby that referenced this pull request Dec 29, 2022
RubyGems cleans built artifacts after building extensions since  3.4.0:
rubygems/rubygems#6133

Therefore cld3-ruby now needs to refer the installed binary instead of
the binary at the build directory.
@lipidity
Copy link

lipidity commented Jan 4, 2023

Hi 👋

Running make clean after installing an extension breaks https://github.com/ohler55/ox because it removes the built artifacts which are needed at runtime.

@simi
Copy link
Member

simi commented Jan 4, 2023

Hi wave

Running make clean after installing an extension breaks https://github.com/ohler55/ox because it removes the built artifacts which are needed at runtime.

#6205 (comment)

@lipidity
Copy link

lipidity commented Jan 4, 2023

@simi thanks, I should have linked to ohler55/ox#303 (it's still broken on macOS)

@hsbt
Copy link
Member

hsbt commented Jan 4, 2023

@lipidity No. It works. Please confirm my comment

@lipidity
Copy link

lipidity commented Jan 4, 2023

I was wrong about ox still being broken. Confirmed that it works.

Shimokuni added a commit to Shimokuni/figure_set that referenced this pull request Mar 14, 2023
Shimokuni added a commit to Shimokuni/figure_set that referenced this pull request Mar 14, 2023
Shimokuni added a commit to Shimokuni/figure_set that referenced this pull request Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cleanup object files on gems with extensions
5 participants