Skip to content

Commit

Permalink
Merge pull request #25 from fontist/maxirmx-next-gen
Browse files Browse the repository at this point in the history
feat: manage libraries' versions through configuration file
  • Loading branch information
maxirmx authored Dec 25, 2024
2 parents ae7d1f6 + a8c07a9 commit 311d6d9
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 74 deletions.
40 changes: 40 additions & 0 deletions ext/configuration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
libraries:
zlib:
all:
version: "1.3.1"
url: "http://zlib.net/fossils/zlib-1.3.1.tar.gz"
sha256: "9a93b2b7dfdac77ceba5a558a580e74667dd6fede4585b91eefb60f03b72df23"
libexpat:
all:
version: "2.6.4"
url: "https://github.com/libexpat/libexpat/releases/download/R_2_6_4/expat-2.6.4.tar.gz"
sha256: "fd03b7172b3bd7427a3e7a812063f74754f24542429b634e0db6511b53fb2278"
# openssl:
# version 3.x.y requires pod2man, that is not easily available on Windows
openssl:
windows:
version: "1.1.1w"
url: "https://github.com/openssl/openssl/releases/download/OpenSSL_1_1_1w/openssl-1.1.1w.tar.gz"
sha256: "cf3098950cb4d853ad95c0841f1f9c6d3dc102dccfcacd521d93925208b76ac8"
all:
version: "3.3.2"
url: "https://github.com/openssl/openssl/releases/download/openssl-3.3.2/openssl-3.3.2.tar.gz"
sha256: "2e8a40b01979afe8be0bbfb3de5dc1c6709fedb46d6c89c10da114ab5fc3d281"
# xz:
# versions > 5.2.4 get crazy on MinGW
# versions <= 5.2.5 do not support arm64-apple-darwin target
# version 5.2.7 could not be linked statically to libarchive
xz:
windows:
version: "5.2.4"
url: "https://tukaani.org/xz/xz-5.2.4.tar.gz"
sha256: "b512f3b726d3b37b6dc4c8570e137b9311e7552e8ccbab4d39d47ce5f4177145"
all:
version: "5.2.6"
url: "https://tukaani.org/xz/xz-5.2.6.tar.gz"
sha256: "a2105abee17bcd2ebd15ced31b4f5eda6e17efd6b10f921a01cda4a44c91b3a0"
libarchive:
all:
version: "3.7.7"
url: "https://www.libarchive.org/downloads/libarchive-3.7.7.tar.gz"
sha256: "4cc540a3e9a1eebdefa1045d2e4184831100667e6d7d5b315bb1cbc951f8ddff"
14 changes: 12 additions & 2 deletions lib/ffi-libarchive-binary/base_recipe.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "mini_portile2"
require_relative "configuration"

module LibarchiveBinary
FORMATS = {
Expand All @@ -24,9 +25,18 @@ module LibarchiveBinary
"arm64-apple-darwin" => "libarchive.dylib",
}.freeze

ROOT = Pathname.new(File.expand_path("../..", __dir__))

class BaseRecipe < MiniPortile
def initialize(name, version)
super
def initialize(name)
library = LibarchiveBinary.library_for(name)
version = library["version"]
super(name, version)
@target = ROOT.join(@target).to_s
@files << {
url: library["url"],
sha256: library["sha256"],
}
@printed = {}
end

Expand Down
31 changes: 31 additions & 0 deletions lib/ffi-libarchive-binary/configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require "psych"
require "yaml"

module LibarchiveBinary
def self.libraries
configuration_file = File.join(File.dirname(__FILE__), "..", "..", "ext", "configuration.yml")
@@libraries ||= ::YAML.load_file(configuration_file)["libraries"] || {}
rescue Psych::SyntaxError => e
puts "Warning: The configuration file '#{configuration_file}' contains invalid YAML syntax."
puts e.message
exit 1
rescue StandardError => e
puts "An unexpected error occurred while loading the configuration file '#{configuration_file}'."
puts e.message
exit 1
end

def self.library_for(libname)
if MiniPortile::windows?
libraries[libname]["windows"] || libraries[libname]["all"]
else
libraries[libname]["all"]
end
rescue StandardError => e
puts "Failed to load library configuration for '#{libname}'."
puts e.message
exit 1
end
end
38 changes: 31 additions & 7 deletions lib/ffi-libarchive-binary/libarchive_recipe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "pathname"
require "open3"

require_relative "configuration"
require_relative "base_recipe"
require_relative "zlib_recipe"
require_relative "libexpat_recipe"
Expand All @@ -12,13 +13,15 @@
module LibarchiveBinary
class LibarchiveRecipe < MiniPortileCMake
ROOT = Pathname.new(File.expand_path("../..", __dir__))
NAME = "libarchive"
def initialize
super("libarchive", "3.7.7")
libarchive = LibarchiveBinary.library_for(NAME)
super(NAME, libarchive["version"])
@printed = {}

@files << {
url: "https://www.libarchive.org/downloads/libarchive-3.7.7.tar.gz",
sha256: "4cc540a3e9a1eebdefa1045d2e4184831100667e6d7d5b315bb1cbc951f8ddff",
url: libarchive["url"],
sha256: libarchive["sha256"],
}

@target = ROOT.join(@target).to_s
Expand All @@ -44,9 +47,9 @@ def default_flags
"-DENABLE_ZLIB::BOOL=ON", "-DENABLE_BZip2:BOOL=OFF", "-DENABLE_LIBXML2:BOOL=OFF",
"-DENABLE_EXPAT::BOOL=ON", "-DENABLE_TAR:BOOL=OFF", "-DENABLE_ICONV::BOOL=OFF",
"-DENABLE_CPIO::BOOL=OFF", "-DENABLE_CAT:BOOL=OFF", "-DENABLE_ACL:BOOL=OFF",
"-DENABLE_TEST:BOOL=OFF", "-DENABLE_UNZIP:BOOL=OFF",
"-DCMAKE_INCLUDE_PATH=#{include_path}",
"-DCMAKE_LIBRARY_PATH=#{library_path}"
"-DENABLE_TEST:BOOL=OFF", "-DENABLE_UNZIP:BOOL=OFF", "-DOPENSSL_USE_STATIC_LIBS=ON",
"-DCMAKE_INCLUDE_PATH:STRING=#{include_path}",
"-DCMAKE_LIBRARY_PATH:STRING=#{library_path}"
]
end

Expand All @@ -67,7 +70,7 @@ def include_path

def library_path
paths = [@zlib_recipe.path, @expat_recipe.path, @openssl_recipe.path, @xz_recipe.path]
paths.map { |k| "#{k}/lib" }.join(";")
paths.map { |k| "#{k}/lib;#{k}/lib64" }.join(";")
end

def activate
Expand Down Expand Up @@ -127,6 +130,27 @@ def lib_fullpath
@lib_fullpath ||= lib_filename.nil? ? nil : File.join(lib_workpath, lib_filename)
end

def libraries
configuration_file = File.join(File.dirname(__FILE__), "..", "..", "ext", "configuration.yml")
@libraries ||= ::YAML.load_file(configuration_file)["libraries"] || {}
rescue Psych::SyntaxError => e
puts "Warning: The configuration file '#{configuration_file}' contains invalid YAML syntax."
puts e.message
exit 1
rescue StandardError => e
puts "An unexpected error occurred while loading the configuration file '#{configuration_file}'."
puts e.message
exit 1
end

def library_for(libname)
libraries[libname][MiniPortile::windows? ? "windows" : "all"]
rescue StandardError => e
puts "Failed to load library configuration for '#{libname}'."
puts e.message
exit 1
end

def verify_lib
begin
out, = Open3.capture2("file #{lib_fullpath}")
Expand Down
9 changes: 1 addition & 8 deletions lib/ffi-libarchive-binary/libexpat_recipe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@

module LibarchiveBinary
class LibexpatRecipe < BaseRecipe
ROOT = Pathname.new(File.expand_path("../..", __dir__))

def initialize
super("libexpat", "2.6.4")

@files << {
url: "https://github.com/libexpat/libexpat/releases/download/R_2_6_4/expat-2.6.4.tar.gz",
sha256: "fd03b7172b3bd7427a3e7a812063f74754f24542429b634e0db6511b53fb2278",
}
super("libexpat")

@target = ROOT.join(@target).to_s
end
Expand Down
17 changes: 1 addition & 16 deletions lib/ffi-libarchive-binary/openssl_recipe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@ module LibarchiveBinary
ENV_CMD = ["env", "CFLAGS=-fPIC", "LDFLAGS=-fPIC"].freeze

class OpensslRecipe < BaseRecipe
ROOT = Pathname.new(File.expand_path("../..", __dir__))

def initialize
super("openssl", MiniPortile::windows? ? "1.1.1w" : "3.3.2")

@files << source_archive
@target = ROOT.join(@target).to_s
super("openssl")
end

def configure
Expand Down Expand Up @@ -49,15 +44,5 @@ def cook

FileUtils.touch(checkpoint)
end

def source_archive
if MiniPortile::windows?
{ url: "https://github.com/openssl/openssl/releases/download/OpenSSL_1_1_1w/openssl-1.1.1w.tar.gz",
sha256: "cf3098950cb4d853ad95c0841f1f9c6d3dc102dccfcacd521d93925208b76ac8" }
else
{ url: "https://github.com/openssl/openssl/releases/download/openssl-3.3.2/openssl-3.3.2.tar.gz",
sha256: "2e8a40b01979afe8be0bbfb3de5dc1c6709fedb46d6c89c10da114ab5fc3d281" }
end
end
end
end
2 changes: 1 addition & 1 deletion lib/ffi-libarchive-binary/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module LibarchiveBinary
VERSION = "0.3.4"
VERSION = "0.4.0"
end
31 changes: 1 addition & 30 deletions lib/ffi-libarchive-binary/xz_recipe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,8 @@

module LibarchiveBinary
class XZRecipe < BaseRecipe
ROOT = Pathname.new(File.expand_path("../..", __dir__))

# As of 19.10.2022
# versions > 5.2.4 get crazy on MinGW
# versions <= 5.2.5 do not support arm64-apple-darwin target
# version 5.2.7 could not be linked statically to libarchive

def initialize
if MiniPortile::windows?
super("xz", "5.2.4")
windows_files
else
super("xz", "5.2.6")
not_windows_files
end

@target = ROOT.join(@target).to_s
end

def windows_files
@files << {
url: "https://tukaani.org/xz/xz-5.2.4.tar.gz",
sha256: "b512f3b726d3b37b6dc4c8570e137b9311e7552e8ccbab4d39d47ce5f4177145",
}
end

def not_windows_files
@files << {
url: "https://tukaani.org/xz/xz-5.2.6.tar.gz",
sha256: "a2105abee17bcd2ebd15ced31b4f5eda6e17efd6b10f921a01cda4a44c91b3a0",
}
super("xz")
end

def configure_defaults
Expand Down
11 changes: 1 addition & 10 deletions lib/ffi-libarchive-binary/zlib_recipe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,8 @@

module LibarchiveBinary
class ZLibRecipe < BaseRecipe
ROOT = Pathname.new(File.expand_path("../..", __dir__))

def initialize
super("zlib", "1.3.1")

@files << {
url: "http://zlib.net/fossils/zlib-1.3.1.tar.gz",
sha256: "9a93b2b7dfdac77ceba5a558a580e74667dd6fede4585b91eefb60f03b72df23",
}

@target = ROOT.join(@target).to_s
super("zlib")
end

def configure_defaults
Expand Down

0 comments on commit 311d6d9

Please sign in to comment.