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.
Direct Known Subclasses
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__))
Class Method Summary collapse
-
.for_target(platform) ⇒ Object
Factory: returns the recipe subclass appropriate for the target platform.
- .ohos_target?(platform) ⇒ Boolean
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.
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/libpng/recipe.rb', line 43 def initialize super('libpng', Libpng::LIBPNG_VERSION) @files << { url: LIBPNG_URL, sha256: LIBPNG_SHA256 } @target = ROOT.join(@target).to_s @printed = {} setup_cross_compile if cross_compile? end |
Class Method Details
.for_target(platform) ⇒ Object
Factory: returns the recipe subclass appropriate for the target
platform. Currently only OHOS has a subclass; everything else
uses the base Recipe. Adding a new cross-compile platform = adding
a new Libpng::
21 22 23 24 25 |
# File 'lib/libpng/recipe.rb', line 21 def for_target(platform) return Recipe unless ohos_target?(platform) Libpng::OHOS::Recipe end |
.ohos_target?(platform) ⇒ Boolean
27 28 29 30 31 |
# File 'lib/libpng/recipe.rb', line 27 def ohos_target?(platform) return false unless platform.is_a?(String) platform.end_with?('-ohos') end |
Instance Method Details
#checkpoint ⇒ Object
71 72 73 |
# File 'lib/libpng/recipe.rb', line 71 def checkpoint File.join(@target, "#{name}-#{version}-#{target_platform}.installed") end |
#configure_defaults ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/libpng/recipe.rb', line 75 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
66 67 68 69 |
# File 'lib/libpng/recipe.rb', line 66 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.
62 63 64 |
# File 'lib/libpng/recipe.rb', line 62 def cook_if_not cook unless File.exist?(checkpoint) end |
#execute(action, command, command_opts = {}) ⇒ Object
118 119 120 |
# File 'lib/libpng/recipe.rb', line 118 def execute(action, command, command_opts = {}) super(action, command, command_opts.merge(debug: false)) end |
#install ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/libpng/recipe.rb', line 89 def install super # After `make install`, the shared lib lives under ports/<name>/<ver>/. # On Linux/macOS that's lib/. On Windows, CMake's GNUInstallDirs puts # the .dll in bin/ and the import library (.dll.a) in lib/ — we only # ship the .dll, so search both. libs = Dir.glob(File.join(port_path, shared_lib_install_glob)) raise "no libpng shared lib produced under #{port_path}" 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
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/libpng/recipe.rb', line 122 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
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/libpng/recipe.rb', line 105 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 |