Class: Libpng::Recipe
- Inherits:
-
MiniPortileCMake
- Object
- MiniPortileCMake
- Libpng::Recipe
- Defined in:
- lib/libpng/recipe.rb
Overview
MiniPortile-based recipe for building libpng from source. Mirrors the
pattern used by emf2svg-ruby: during gem install, ext/extconf.rb
invokes Recipe#cook, which downloads the libpng source tarball, runs
configure + make, and installs the shared library into the gem's lib/
directory. The pre-compiled gems (built via rake gem:native:<plat>)
ship the .so/.dylib/.dll and disable extconf.rb entirely.
Constant Summary collapse
- LIBPNG_URL =
Pinned libpng source URL + sha256. Bump deliberately to refresh the upstream — and remember to update both fields together.
"https://downloads.sourceforge.net/project/libpng/libpng16/#{Libpng::LIBPNG_VERSION}/libpng-#{Libpng::LIBPNG_VERSION}.tar.gz".freeze
- LIBPNG_SHA256 =
sha256 of the libpng-X.Y.Z.tar.gz tarball. Verify with:
curl -sL <URL> | shasum -a 256 '8c9b05b675ca7301a458df2c2e46f26e1d41ff36b8863f8c33530bc58c2e6225'.freeze
- ROOT =
Pathname.new(File.('../..', __dir__))
Instance Method Summary collapse
- #checkpoint ⇒ Object
- #configure_defaults ⇒ Object
- #cook ⇒ Object
-
#cook_if_not ⇒ Object
libpng ships a CMake build alongside the autotools one.
- #execute(action, command, command_opts = {}) ⇒ Object
-
#initialize ⇒ Recipe
constructor
A new instance of Recipe.
- #install ⇒ Object
- #message(text) ⇒ Object
- #verify_libs ⇒ Object
Constructor Details
#initialize ⇒ Recipe
Returns a new instance of Recipe.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/libpng/recipe.rb', line 25 def initialize super('libpng', Libpng::LIBPNG_VERSION) @files << { url: LIBPNG_URL, sha256: LIBPNG_SHA256 } @target = ROOT.join(@target).to_s @printed = {} end |
Instance Method Details
#checkpoint ⇒ Object
52 53 54 |
# File 'lib/libpng/recipe.rb', line 52 def checkpoint File.join(@target, "#{name}-#{version}-#{target_platform}.installed") end |
#configure_defaults ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/libpng/recipe.rb', line 56 def configure_defaults # Build a static+self-contained shared library: we only ship the .so # to consumers, so libpng's transitive dep on zlib must be linked in. opts = super opts << '-DPNG_SHARED=ON' opts << '-DPNG_STATIC=OFF' opts << '-DPNG_TESTS=OFF' opts << '-DPNG_FRAMEWORK=OFF' # macOS: avoid the .framework build; we want a plain .dylib. opts << '-DCMAKE_INSTALL_LIBDIR=lib' opts << '-DCMAKE_BUILD_TYPE=Release' opts end |
#cook ⇒ Object
47 48 49 50 |
# File 'lib/libpng/recipe.rb', line 47 def cook super FileUtils.touch(checkpoint) end |
#cook_if_not ⇒ Object
libpng ships a CMake build alongside the autotools one. We use CMake for consistency with mini_portile2's defaults and to handle Windows cleanly (autotools on native Windows is fragile). No additional configuration is needed; defaults build PNG_SHARED=ON and PNG_STATIC=OFF, which is what we want.
43 44 45 |
# File 'lib/libpng/recipe.rb', line 43 def cook_if_not cook unless File.exist?(checkpoint) end |
#execute(action, command, command_opts = {}) ⇒ Object
97 98 99 |
# File 'lib/libpng/recipe.rb', line 97 def execute(action, command, command_opts = {}) super(action, command, command_opts.merge(debug: false)) end |
#install ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/libpng/recipe.rb', line 70 def install super # After `make install`, the .so/.dylib/.dll is under ports/<name>/<ver>/lib/. # Copy it into the gem's lib/libpng/ so FFI can load it at runtime. libs = Dir.glob(File.join(port_path, 'lib', shared_lib_glob)) raise "no libpng shared lib produced at #{port_path}/lib" if libs.empty? target_dir = ROOT.join('lib', 'libpng') FileUtils.mkdir_p(target_dir) FileUtils.cp_r(libs, target_dir, verbose: true) verify_libs end |
#message(text) ⇒ Object
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/libpng/recipe.rb', line 101 def (text) return super unless text.start_with?("\rDownloading") match = text.match(/(\rDownloading .*)\(\s*\d+%\)/) pattern = match ? match[1] : text return if @printed[pattern] @printed[pattern] = true super end |
#verify_libs ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/libpng/recipe.rb', line 84 def verify_libs each_built_lib do |path| out, st = Open3.capture2("file #{path}") raise "Failed to query file #{path}: #{out}" unless st.exitstatus.zero? next if target_format.eql?('skip') raise "Invalid file format '#{out}', /#{target_format.source}/ expected" unless target_format.match?(out) ("Verifying #{path} ... OK\n") end end |