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

Smaller gems #172

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Smaller gems #172

wants to merge 2 commits into from

Conversation

tabfugnic
Copy link

Hello!

I was running into an issue recently where my heroku instance was failing to build due to too large of a slug.

I looked into wkhtmltopdf_heroku, but wasn't keen on setting variables for production vs other environments.

I opted to take the different approach of limiting the files per platform.

This is by no means a perfect solution, but there is really no reason to have a bunch of x86 or arm64 binaries when all you use is x86_64.

I took a few liberties in renaming files.

There is a bit more testing to do.

Use more consistent naming for files

Rubygems(and even rbconfig) use standard architecture naming. Instead
of going against the grain ensure that the architecture matching that
naming for the most part.

Small gotcha is that arch64, aarch64, arm64 to be the
same architecture.

Build gems based on platform

The previous gem size peaked at over 250MB by providing an unnecessary
amount of unused binaries.

Using the os host(kernel name) and the architecture, separate out
individual platform gemspecs provide a subset of the needed files.

This change is NOT perfect. It can only limit platforms by kernel and
architecture. It does not take the distribution of Linux into account,
so it will still provide an unnecessary number of files, but fewer.

Minor updates:

  • Set minimum ruby version
  • Set versions for development dependencies

Rubygems(and even rbconfig) use standard architecture naming. Instead
of going against the grain ensure that the architecture matching that
naming for the most part.

Small gotcha is that arch64, aarch64, arm64 to be the
same architecture.
The previous gem size peaked at over 250MB by providing an unnecessary
amount of unused binaries.

Using the os host(kernel name) and the architecture, separate out
individual platform gemspecs provide a subset of the needed files.

This change is NOT perfect. It can only limit platforms by kernel and
architecture. It does not take the distribution of Linux into account,
so it will still provide an unnecessary number of files, but fewer.

Minor updates:

- Set minimum ruby version
- Set versions for development dependencies
s.require_path = '.'
s.required_ruby_version = '>= 3.0'
Copy link
Contributor

Choose a reason for hiding this comment

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

Since many people using this gem are likely using Ruby versions older than 3.0, we should be careful about adding this version constraint. It might be better to create a separate PR to discuss this.

Copy link
Author

Choose a reason for hiding this comment

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

This is fair. My main assessment with this was thinking it might be good to set a standard given how little is changing with the underlying binaries going forward.

Comment on lines +19 to +40
SUPPORTED_DARWIN_ARCHITECTURES.each do |architecture|
GEMSPEC.dup.tap do |gemspec|
platform = "#{architecture}-darwin"
gemspec.platform = platform
gemspec.files = ['bin/wkhtmltopdf_macos_cocoa.gz']

gem_path = Gem::PackageTask.new(gemspec).define
desc "Package #{architecture} Darwin gem"
task "gem:#{platform}" => [gem_path]
end
end

SUPPORTED_LINUX_ARCHITECTURES.each do |architecture|
GEMSPEC.dup.tap do |gemspec|
platform = "#{architecture}-linux"
gemspec.platform = platform
gemspec.files = Dir["bin/wkhtmltopdf_*_#{file_architecture(architecture)}.gz"]

gem_path = Gem::PackageTask.new(gemspec).define
desc "Package #{architecture} Linux gem"
task "gem:#{platform}" => [gem_path]
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the gems for each architecture built using commands like rake gem:x86_64-darwin? I think it would be useful to have a command that builds all the necessary gems at once or pushes them to rubygems.org in one go.

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.

2 participants