diff --git a/ext/configuration.yml b/ext/configuration.yml new file mode 100644 index 0000000..3dfb52b --- /dev/null +++ b/ext/configuration.yml @@ -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" diff --git a/lib/ffi-libarchive-binary/base_recipe.rb b/lib/ffi-libarchive-binary/base_recipe.rb index c5a33a7..a711621 100644 --- a/lib/ffi-libarchive-binary/base_recipe.rb +++ b/lib/ffi-libarchive-binary/base_recipe.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "mini_portile2" +require_relative "configuration" module LibarchiveBinary FORMATS = { @@ -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 diff --git a/lib/ffi-libarchive-binary/configuration.rb b/lib/ffi-libarchive-binary/configuration.rb new file mode 100644 index 0000000..1a8405b --- /dev/null +++ b/lib/ffi-libarchive-binary/configuration.rb @@ -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 diff --git a/lib/ffi-libarchive-binary/libarchive_recipe.rb b/lib/ffi-libarchive-binary/libarchive_recipe.rb index 27efff2..7a78747 100644 --- a/lib/ffi-libarchive-binary/libarchive_recipe.rb +++ b/lib/ffi-libarchive-binary/libarchive_recipe.rb @@ -3,6 +3,7 @@ require "pathname" require "open3" +require_relative "configuration" require_relative "base_recipe" require_relative "zlib_recipe" require_relative "libexpat_recipe" @@ -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 @@ -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 @@ -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 @@ -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}") diff --git a/lib/ffi-libarchive-binary/libexpat_recipe.rb b/lib/ffi-libarchive-binary/libexpat_recipe.rb index 16c4ed9..7ff19ca 100644 --- a/lib/ffi-libarchive-binary/libexpat_recipe.rb +++ b/lib/ffi-libarchive-binary/libexpat_recipe.rb @@ -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 diff --git a/lib/ffi-libarchive-binary/openssl_recipe.rb b/lib/ffi-libarchive-binary/openssl_recipe.rb index a9caf67..2cf47a6 100644 --- a/lib/ffi-libarchive-binary/openssl_recipe.rb +++ b/lib/ffi-libarchive-binary/openssl_recipe.rb @@ -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 @@ -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 diff --git a/lib/ffi-libarchive-binary/version.rb b/lib/ffi-libarchive-binary/version.rb index 04c1fd8..564af85 100644 --- a/lib/ffi-libarchive-binary/version.rb +++ b/lib/ffi-libarchive-binary/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module LibarchiveBinary - VERSION = "0.3.4" + VERSION = "0.4.0" end diff --git a/lib/ffi-libarchive-binary/xz_recipe.rb b/lib/ffi-libarchive-binary/xz_recipe.rb index f188114..ff43a58 100644 --- a/lib/ffi-libarchive-binary/xz_recipe.rb +++ b/lib/ffi-libarchive-binary/xz_recipe.rb @@ -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 diff --git a/lib/ffi-libarchive-binary/zlib_recipe.rb b/lib/ffi-libarchive-binary/zlib_recipe.rb index e8fce0d..5c90957 100644 --- a/lib/ffi-libarchive-binary/zlib_recipe.rb +++ b/lib/ffi-libarchive-binary/zlib_recipe.rb @@ -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