From d27e884897f10c27b8958d537dc0bb8786e91752 Mon Sep 17 00:00:00 2001 From: Eric Collins Date: Tue, 28 May 2024 23:49:13 -0400 Subject: [PATCH 1/2] 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. --- bin/wkhtmltopdf | 10 ++++------ ...nux_amd64.gz => wkhtmltopdf_archlinux_x86_64.gz} | Bin ...centos_6_i386.gz => wkhtmltopdf_centos_6_x86.gz} | Bin ...os_6_amd64.gz => wkhtmltopdf_centos_6_x86_64.gz} | Bin ...centos_7_i386.gz => wkhtmltopdf_centos_7_x86.gz} | Bin ...os_7_amd64.gz => wkhtmltopdf_centos_7_x86_64.gz} | Bin ...os_8_amd64.gz => wkhtmltopdf_centos_8_x86_64.gz} | Bin ...bian_10_i386.gz => wkhtmltopdf_debian_10_x86.gz} | Bin ..._10_amd64.gz => wkhtmltopdf_debian_10_x86_64.gz} | Bin ...bian_11_i386.gz => wkhtmltopdf_debian_11_x86.gz} | Bin ..._11_amd64.gz => wkhtmltopdf_debian_11_x86_64.gz} | Bin ...bian_12_i386.gz => wkhtmltopdf_debian_12_x86.gz} | Bin ..._12_amd64.gz => wkhtmltopdf_debian_12_x86_64.gz} | Bin ...debian_9_i386.gz => wkhtmltopdf_debian_9_x86.gz} | Bin ...an_9_amd64.gz => wkhtmltopdf_debian_9_x86_64.gz} | Bin ...6.04_i386.gz => wkhtmltopdf_ubuntu_16.04_x86.gz} | Bin ..._amd64.gz => wkhtmltopdf_ubuntu_16.04_x86_64.gz} | Bin ...8.04_i386.gz => wkhtmltopdf_ubuntu_18.04_x86.gz} | Bin ..._amd64.gz => wkhtmltopdf_ubuntu_18.04_x86_64.gz} | Bin ..._amd64.gz => wkhtmltopdf_ubuntu_20.04_x86_64.gz} | Bin ..._amd64.gz => wkhtmltopdf_ubuntu_21.10_x86_64.gz} | Bin ..._amd64.gz => wkhtmltopdf_ubuntu_22.04_x86_64.gz} | Bin 22 files changed, 4 insertions(+), 6 deletions(-) rename bin/{wkhtmltopdf_archlinux_amd64.gz => wkhtmltopdf_archlinux_x86_64.gz} (100%) rename bin/{wkhtmltopdf_centos_6_i386.gz => wkhtmltopdf_centos_6_x86.gz} (100%) rename bin/{wkhtmltopdf_centos_6_amd64.gz => wkhtmltopdf_centos_6_x86_64.gz} (100%) rename bin/{wkhtmltopdf_centos_7_i386.gz => wkhtmltopdf_centos_7_x86.gz} (100%) rename bin/{wkhtmltopdf_centos_7_amd64.gz => wkhtmltopdf_centos_7_x86_64.gz} (100%) rename bin/{wkhtmltopdf_centos_8_amd64.gz => wkhtmltopdf_centos_8_x86_64.gz} (100%) rename bin/{wkhtmltopdf_debian_10_i386.gz => wkhtmltopdf_debian_10_x86.gz} (100%) rename bin/{wkhtmltopdf_debian_10_amd64.gz => wkhtmltopdf_debian_10_x86_64.gz} (100%) rename bin/{wkhtmltopdf_debian_11_i386.gz => wkhtmltopdf_debian_11_x86.gz} (100%) rename bin/{wkhtmltopdf_debian_11_amd64.gz => wkhtmltopdf_debian_11_x86_64.gz} (100%) rename bin/{wkhtmltopdf_debian_12_i386.gz => wkhtmltopdf_debian_12_x86.gz} (100%) rename bin/{wkhtmltopdf_debian_12_amd64.gz => wkhtmltopdf_debian_12_x86_64.gz} (100%) rename bin/{wkhtmltopdf_debian_9_i386.gz => wkhtmltopdf_debian_9_x86.gz} (100%) rename bin/{wkhtmltopdf_debian_9_amd64.gz => wkhtmltopdf_debian_9_x86_64.gz} (100%) rename bin/{wkhtmltopdf_ubuntu_16.04_i386.gz => wkhtmltopdf_ubuntu_16.04_x86.gz} (100%) rename bin/{wkhtmltopdf_ubuntu_16.04_amd64.gz => wkhtmltopdf_ubuntu_16.04_x86_64.gz} (100%) rename bin/{wkhtmltopdf_ubuntu_18.04_i386.gz => wkhtmltopdf_ubuntu_18.04_x86.gz} (100%) rename bin/{wkhtmltopdf_ubuntu_18.04_amd64.gz => wkhtmltopdf_ubuntu_18.04_x86_64.gz} (100%) rename bin/{wkhtmltopdf_ubuntu_20.04_amd64.gz => wkhtmltopdf_ubuntu_20.04_x86_64.gz} (100%) rename bin/{wkhtmltopdf_ubuntu_21.10_amd64.gz => wkhtmltopdf_ubuntu_21.10_x86_64.gz} (100%) rename bin/{wkhtmltopdf_ubuntu_22.04_amd64.gz => wkhtmltopdf_ubuntu_22.04_x86_64.gz} (100%) diff --git a/bin/wkhtmltopdf b/bin/wkhtmltopdf index 66ed8040..f169971f 100755 --- a/bin/wkhtmltopdf +++ b/bin/wkhtmltopdf @@ -11,13 +11,11 @@ require 'rbconfig' require 'zlib' def architecture - case RbConfig::CONFIG['host_cpu'] - when *%w[arm64 aarch64 arch64] + host_cpu = RbConfig::CONFIG['host_cpu'] + if %w[arm64 aarch64 arch64].include?(host_cpu) 'arm64' - when 'x86_64' - 'amd64' else - 'i386' + host_cpu end end @@ -38,7 +36,7 @@ suffix = case RbConfig::CONFIG['host_os'] os = 'ubuntu_20.04' if os.start_with?('ubuntu_20.') || os.start_with?('linuxmint_20.') - + os = 'ubuntu_21.10' if os.start_with?('ubuntu_21.') || os.start_with?('linuxmint_21.') diff --git a/bin/wkhtmltopdf_archlinux_amd64.gz b/bin/wkhtmltopdf_archlinux_x86_64.gz similarity index 100% rename from bin/wkhtmltopdf_archlinux_amd64.gz rename to bin/wkhtmltopdf_archlinux_x86_64.gz diff --git a/bin/wkhtmltopdf_centos_6_i386.gz b/bin/wkhtmltopdf_centos_6_x86.gz similarity index 100% rename from bin/wkhtmltopdf_centos_6_i386.gz rename to bin/wkhtmltopdf_centos_6_x86.gz diff --git a/bin/wkhtmltopdf_centos_6_amd64.gz b/bin/wkhtmltopdf_centos_6_x86_64.gz similarity index 100% rename from bin/wkhtmltopdf_centos_6_amd64.gz rename to bin/wkhtmltopdf_centos_6_x86_64.gz diff --git a/bin/wkhtmltopdf_centos_7_i386.gz b/bin/wkhtmltopdf_centos_7_x86.gz similarity index 100% rename from bin/wkhtmltopdf_centos_7_i386.gz rename to bin/wkhtmltopdf_centos_7_x86.gz diff --git a/bin/wkhtmltopdf_centos_7_amd64.gz b/bin/wkhtmltopdf_centos_7_x86_64.gz similarity index 100% rename from bin/wkhtmltopdf_centos_7_amd64.gz rename to bin/wkhtmltopdf_centos_7_x86_64.gz diff --git a/bin/wkhtmltopdf_centos_8_amd64.gz b/bin/wkhtmltopdf_centos_8_x86_64.gz similarity index 100% rename from bin/wkhtmltopdf_centos_8_amd64.gz rename to bin/wkhtmltopdf_centos_8_x86_64.gz diff --git a/bin/wkhtmltopdf_debian_10_i386.gz b/bin/wkhtmltopdf_debian_10_x86.gz similarity index 100% rename from bin/wkhtmltopdf_debian_10_i386.gz rename to bin/wkhtmltopdf_debian_10_x86.gz diff --git a/bin/wkhtmltopdf_debian_10_amd64.gz b/bin/wkhtmltopdf_debian_10_x86_64.gz similarity index 100% rename from bin/wkhtmltopdf_debian_10_amd64.gz rename to bin/wkhtmltopdf_debian_10_x86_64.gz diff --git a/bin/wkhtmltopdf_debian_11_i386.gz b/bin/wkhtmltopdf_debian_11_x86.gz similarity index 100% rename from bin/wkhtmltopdf_debian_11_i386.gz rename to bin/wkhtmltopdf_debian_11_x86.gz diff --git a/bin/wkhtmltopdf_debian_11_amd64.gz b/bin/wkhtmltopdf_debian_11_x86_64.gz similarity index 100% rename from bin/wkhtmltopdf_debian_11_amd64.gz rename to bin/wkhtmltopdf_debian_11_x86_64.gz diff --git a/bin/wkhtmltopdf_debian_12_i386.gz b/bin/wkhtmltopdf_debian_12_x86.gz similarity index 100% rename from bin/wkhtmltopdf_debian_12_i386.gz rename to bin/wkhtmltopdf_debian_12_x86.gz diff --git a/bin/wkhtmltopdf_debian_12_amd64.gz b/bin/wkhtmltopdf_debian_12_x86_64.gz similarity index 100% rename from bin/wkhtmltopdf_debian_12_amd64.gz rename to bin/wkhtmltopdf_debian_12_x86_64.gz diff --git a/bin/wkhtmltopdf_debian_9_i386.gz b/bin/wkhtmltopdf_debian_9_x86.gz similarity index 100% rename from bin/wkhtmltopdf_debian_9_i386.gz rename to bin/wkhtmltopdf_debian_9_x86.gz diff --git a/bin/wkhtmltopdf_debian_9_amd64.gz b/bin/wkhtmltopdf_debian_9_x86_64.gz similarity index 100% rename from bin/wkhtmltopdf_debian_9_amd64.gz rename to bin/wkhtmltopdf_debian_9_x86_64.gz diff --git a/bin/wkhtmltopdf_ubuntu_16.04_i386.gz b/bin/wkhtmltopdf_ubuntu_16.04_x86.gz similarity index 100% rename from bin/wkhtmltopdf_ubuntu_16.04_i386.gz rename to bin/wkhtmltopdf_ubuntu_16.04_x86.gz diff --git a/bin/wkhtmltopdf_ubuntu_16.04_amd64.gz b/bin/wkhtmltopdf_ubuntu_16.04_x86_64.gz similarity index 100% rename from bin/wkhtmltopdf_ubuntu_16.04_amd64.gz rename to bin/wkhtmltopdf_ubuntu_16.04_x86_64.gz diff --git a/bin/wkhtmltopdf_ubuntu_18.04_i386.gz b/bin/wkhtmltopdf_ubuntu_18.04_x86.gz similarity index 100% rename from bin/wkhtmltopdf_ubuntu_18.04_i386.gz rename to bin/wkhtmltopdf_ubuntu_18.04_x86.gz diff --git a/bin/wkhtmltopdf_ubuntu_18.04_amd64.gz b/bin/wkhtmltopdf_ubuntu_18.04_x86_64.gz similarity index 100% rename from bin/wkhtmltopdf_ubuntu_18.04_amd64.gz rename to bin/wkhtmltopdf_ubuntu_18.04_x86_64.gz diff --git a/bin/wkhtmltopdf_ubuntu_20.04_amd64.gz b/bin/wkhtmltopdf_ubuntu_20.04_x86_64.gz similarity index 100% rename from bin/wkhtmltopdf_ubuntu_20.04_amd64.gz rename to bin/wkhtmltopdf_ubuntu_20.04_x86_64.gz diff --git a/bin/wkhtmltopdf_ubuntu_21.10_amd64.gz b/bin/wkhtmltopdf_ubuntu_21.10_x86_64.gz similarity index 100% rename from bin/wkhtmltopdf_ubuntu_21.10_amd64.gz rename to bin/wkhtmltopdf_ubuntu_21.10_x86_64.gz diff --git a/bin/wkhtmltopdf_ubuntu_22.04_amd64.gz b/bin/wkhtmltopdf_ubuntu_22.04_x86_64.gz similarity index 100% rename from bin/wkhtmltopdf_ubuntu_22.04_amd64.gz rename to bin/wkhtmltopdf_ubuntu_22.04_x86_64.gz From bf574243524ed8571b0e56b17b2d899d5397dbcf Mon Sep 17 00:00:00 2001 From: Eric Collins Date: Tue, 28 May 2024 23:51:57 -0400 Subject: [PATCH 2/2] 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 --- Rakefile | 38 +++++++++++++++++++++++++++++++++++--- wkhtmltopdf-binary.gemspec | 8 ++++---- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/Rakefile b/Rakefile index b461e91e..4f4be170 100644 --- a/Rakefile +++ b/Rakefile @@ -2,10 +2,42 @@ require 'rubygems' require 'rubygems/package_task' require 'rake/testtask' -spec = eval(File.new("wkhtmltopdf-binary.gemspec").readlines.join("\n")) +SUPPORTED_DARWIN_ARCHITECTURES = [:arm64, :x86_64] +SUPPORTED_LINUX_ARCHITECTURES = [:arm64, :aarch64, :arch64, :x86, :x86_64] +ARM64_COMPATIBLE_ARCHITECTURES = [:aarch64, :arch64] -Gem::PackageTask.new(spec) do |pkg| - pkg.need_tar = true +def file_architecture(architecture) + if ARM64_COMPATIBLE_ARCHITECTURES.include?(architecture) + :arm64 + else + architecture + end +end + +GEMSPEC = eval(File.new("wkhtmltopdf-binary.gemspec").readlines.join("\n")) + +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 end Rake::TestTask.new do |t| diff --git a/wkhtmltopdf-binary.gemspec b/wkhtmltopdf-binary.gemspec index 07c51808..c1a66ceb 100644 --- a/wkhtmltopdf-binary.gemspec +++ b/wkhtmltopdf-binary.gemspec @@ -8,14 +8,14 @@ Gem::Specification.new do |s| s.email = "zakird@gmail.com" s.platform = Gem::Platform::RUBY s.summary = "Provides binaries for WKHTMLTOPDF project in an easily accessible package." - s.files = Dir['bin/*'] - s.executables << "wkhtmltopdf" + s.executables << 'wkhtmltopdf' s.require_path = '.' + s.required_ruby_version = '>= 3.0' s.homepage = 'https://github.com/zakird/wkhtmltopdf_binary_gem' s.metadata['source_code_uri'] = s.homepage s.metadata['changelog_uri'] = "#{s.homepage}/blob/master/CHANGELOG.md" - s.add_development_dependency "minitest" - s.add_development_dependency "rake" + s.add_development_dependency 'minitest', '~> 5.23' + s.add_development_dependency 'rake', '~> 13.2' end