Otok public index

apotocki/libarchive

apotocki/libarchive 3.8.11 (r1, windows)

Library
libarchive
Variant
windows, target windows
Channel
stable
Published
2026-11-14
Recipe source
https://github.com/otok-dev/recipes.git
38eb6de92a0f69e47500c65fdf47bbfc088321f1 in recipes/libarchive/3.8/windows/
Recipe SHA-256
3a3a456bfd475675bae933a1a030a63999805ecec2eb3ca80b05ca8c0a54ecb7

Recipe files changed

Inputs

source.mirrors["https://www.libarchive.org/downloads/libarchive-3.8.11.tar.xz"]
source.sha256a3dc0872b1b39da34dc18ef1b944f0f11ffd37425d70ae04be679279f1cf43d2
source.urlhttps://github.com/libarchive/libarchive/releases/download/v3.8.11/libarchive-3.8.11.tar.xz

Platforms

windows

Options

OptionTypeDefaultDescription
bzip2additive bool true bzip2, and bzip2 in zip, 7-Zip and XAR, with bzip2.
crypto enum of ["cng", "openssl", "none"] "cng" Windows' CNG or OpenSSL for traditional and AES encryption of zip and the digests of XAR, mtree and WARC; none leaves them out.
lz4additive bool true lz4, with lz4.
lzmaadditive bool true xz, lzma and lzip, and LZMA in zip, 7-Zip and XAR, with liblzma.
xml enum of ["xmllite", "libxml2", "expat", "none"] "xmllite" The XML library of the XAR format: Windows' XmlLite or libxml2 (reading and writing), Expat (reading only), or none (no XAR).
zlibadditive bool true gzip, deflate in zip, and the formats that need it (ISO 9660 zisofs, XAR, 7-Zip deflate), with zlib.
zstdadditive bool true zstd, and zstd in zip and 7-Zip, with zstd.

Dependencies

LibraryVersionRecipeDetails
bzip2 >= 1.0 apotocki/bzip2 when = { option = "bzip2" }
expat >= 2.0 apotocki/expat linkage = static
when = { is = "expat", option = "xml" }
libxml2 >= 2.9 apotocki/libxml2 linkage = static
when = { is = "libxml2", option = "xml" }
lz4 >= 1.7 apotocki/lz4 when = { option = "lz4" }
lzma >= 5.0 apotocki/lzma when = { option = "lzma" }
openssl >= 3.0 apotocki/openssl when = { is = "openssl", option = "crypto" }
zlib >= 1.2.1 apotocki/zlib when = { option = "zlib" }
zstd >= 1.4 apotocki/zstd when = { option = "zstd" }

Toolchains

Recipe files

build.lua 6531 bytes · raw
-- libarchive's CMake project: the library with the dependencies of the options, given to CMake by their files; in the tool
-- slice also bsdtar and bsdunzip, linked with the static library. libarchive finds by trial builds which macros zlib,
-- bzip2 and liblzma need; Expat and libxml2, static only here, get XML_STATIC or LIBXML_STATIC from a file CMake includes
-- after project(). What it installs: archive.lib, a static archive, or the import library with archive.dll (and
-- archive_static.lib beside them, which is not returned).

-- A static libcrypto calls Windows libraries (the `link` of the OpenSSL recipe, Configure's ex_libs of the VC- targets),
-- which libarchive's CMake does not give with it: its checks of PBKDF2 and the digests would fail to link and leave
-- encryption and the digests out, and bsdtar would not link. Every use of the OpenSSL libraries gets them.
local openssl_system_libraries = "ws2_32;crypt32;advapi32;user32;gdi32"

local function patch_static_openssl()
    local text = otok.read("CMakeLists.txt")
    local total = 0
    for _, variable in ipairs{ "OPENSSL_CRYPTO_LIBRARY", "OPENSSL_LIBRARIES" } do
        local count
        text, count = text:gsub("%${" .. variable .. "}", "${" .. variable .. "};" .. openssl_system_libraries)
        total = total + count
    end
    if total < 4 then error("libarchive's CMakeLists.txt has fewer uses of the OpenSSL libraries than expected") end
    otok.write("CMakeLists.txt", text)
end

-- libarchive's CMake takes libxml2 only with iconv, for headers of a libxml2 built with it; the libxml2 recipe for Windows
-- builds without iconv, and libarchive converts with the Windows API here, so the condition goes.
local function patch_libxml2_without_iconv()
    local text, count = otok.read("CMakeLists.txt"):gsub("IF%(ENABLE_LIBXML2 AND HAVE_ICONV%)", "IF(ENABLE_LIBXML2)", 1)
    if count ~= 1 then error("libarchive's CMakeLists.txt has no libxml2 condition of the expected form") end
    otok.write("CMakeLists.txt", text)
end

function build(slice, options, deps)
    local static = slice.linkage == "static"
    local defines = {
        ENABLE_TEST = false, ENABLE_WERROR = false, ENABLE_COVERAGE = false, ENABLE_INSTALL = true,
        ENABLE_TAR = slice.is_tool, ENABLE_UNZIP = slice.is_tool, ENABLE_CPIO = false, ENABLE_CAT = false,
        ENABLE_ZLIB = options.zlib, ENABLE_BZip2 = options.bzip2, ENABLE_LZMA = options.lzma, ENABLE_LZ4 = options.lz4,
        ENABLE_ZSTD = options.zstd, ENABLE_LIBB2 = false, ENABLE_LZO = false, ENABLE_MD = false, ENABLE_BSDXML = false,
        ENABLE_EXPAT = options.xml == "expat", ENABLE_LIBXML2 = options.xml == "libxml2",
        ENABLE_WIN32_XMLLITE = options.xml == "xmllite",
        ENABLE_CNG = options.crypto == "cng", ENABLE_OPENSSL = options.crypto == "openssl", ENABLE_MBEDTLS = false,
        ENABLE_NETTLE = false, ENABLE_PCREPOSIX = false, ENABLE_PCRE2POSIX = false, ENABLE_LIBGCC = false,
        ENABLE_ACL = false, ENABLE_XATTR = false, ENABLE_ICONV = false, MSVC_USE_STATIC_CRT = false,
        POSIX_REGEX_LIB = "NONE",
    }
    if options.zlib then
        defines.ZLIB_USE_STATIC_LIBS = deps.zlib.linkage == "static"
        defines.ZLIB_INCLUDE_DIR = deps.zlib.include
        defines.ZLIB_LIBRARY = deps.zlib.libraries.z
    end
    if options.bzip2 then
        defines.BZIP2_INCLUDE_DIR = deps.bzip2.include
        defines.BZIP2_LIBRARY_RELEASE = deps.bzip2.libraries.bz2
    end
    if options.lzma then
        defines.LIBLZMA_INCLUDE_DIR = deps.lzma.include
        defines.LIBLZMA_LIBRARY_RELEASE = deps.lzma.libraries.lzma
    end
    if options.lz4 then
        defines.LZ4_INCLUDE_DIR = deps.lz4.include
        defines.LZ4_LIBRARY = deps.lz4.libraries.lz4
    end
    if options.zstd then
        defines.ZSTD_INCLUDE_DIR = deps.zstd.include
        defines.ZSTD_LIBRARY = deps.zstd.libraries.zstd
    end
    local static_define -- the macro a static XML library needs, for the whole build
    if options.xml == "expat" then
        defines.EXPAT_INCLUDE_DIR = deps.expat.include
        defines.EXPAT_LIBRARY = deps.expat.libraries.expat
        if deps.expat.linkage == "static" then static_define = "XML_STATIC" end
    elseif options.xml == "libxml2" then
        defines.LIBXML2_INCLUDE_DIR = deps.libxml2.include
        defines.LIBXML2_LIBRARY = deps.libxml2.libraries.xml2
        patch_libxml2_without_iconv()
        -- libarchive's trial of LIBXML_STATIC only compiles, so it never finds that a static libxml2 needs it
        if deps.libxml2.linkage == "static" then static_define = "LIBXML_STATIC" end
    end
    if static_define then
        local include = slice.build .. "/otok-project-include.cmake"
        otok.write(include, "add_compile_definitions(" .. static_define .. ")\n")
        defines.CMAKE_PROJECT_INCLUDE = include
    end
    if options.crypto == "openssl" then
        local ssl = deps.openssl
        defines.OPENSSL_ROOT_DIR = ssl.prefix
        defines.OPENSSL_USE_STATIC_LIBS = ssl.linkage == "static"
        defines.OPENSSL_INCLUDE_DIR = ssl.include
        defines.OPENSSL_CRYPTO_LIBRARY = ssl.libraries.crypto
        defines.OPENSSL_SSL_LIBRARY = ssl.libraries.ssl
        if ssl.linkage == "static" then patch_static_openssl() end
    end
    otok.cmake{ defines = defines }
    local p = slice.prefix
    local headers = p .. "/include"
    if static then
        -- archive.h and archive_entry.h declare the functions dllimport unless LIBARCHIVE_STATIC is defined, which only
        -- libarchive's own build defines: the headers of a static library say it themselves
        for _, name in ipairs{ "archive.h", "archive_entry.h" } do
            local path = headers .. "/" .. name
            local text, count = otok.read(path):gsub("(#if %(%(defined __WIN32__%) || %(defined _WIN32%) || defined%(__CYGWIN__%)%) && %(!defined LIBARCHIVE_STATIC%))",
                "#ifndef LIBARCHIVE_STATIC\n#define LIBARCHIVE_STATIC\n#endif\n%1", 1)
            if count ~= 1 then error(name .. " has no LIBARCHIVE_STATIC test of the expected form") end
            otok.write(path, text)
        end
    end
    local out = { headers = headers }
    if static then
        out.libraries = { archive = otok.glob("lib/archive.lib", p)[1] }
    else
        out.libraries = { archive = { link = otok.glob("lib/archive.lib", p)[1], runtime = otok.glob("bin/archive.dll", p)[1] } }
    end
    if slice.is_tool then out.programs = { bsdtar = p .. "/bin/bsdtar.exe", bsdunzip = p .. "/bin/bsdunzip.exe" } end
    return out
end
recipe.toml 3895 bytes · raw
# The otok recipe of libarchive (https://github.com/apotocki/otok): libarchive for Windows, from the release archive, with
# libarchive's CMake; the library, static or dynamic, and, built for the build machine as a tool, the programs bsdtar and
# bsdunzip. The formats come with the libraries of the options (zlib, bzip2, lzma, lz4, zstd, all on by default), XAR
# with Windows' XmlLite or libxml2 (libarchive's CMake told to take it without iconv) or Expat (reading only), encryption
# and the digests with Windows' CNG or OpenSSL. Without libb2 (libarchive's own BLAKE2 is used), LZO, Mbed TLS
# (libarchive needs its 3.x API), Nettle and PCRE.
[recipe]
api = 1
library = "libarchive"
name = "libarchive"
version = "3.8.11"
revision = 1
license = "BSD-2-Clause AND BSD-3-Clause AND (CC0-1.0 OR OpenSSL OR Apache-2.0)"
license-files = ["COPYING"]
homepage = "https://www.libarchive.org"
documentation = "https://github.com/libarchive/libarchive/wiki"
description = "libarchive, a library reading and writing tar, cpio, zip, 7-Zip, RAR, ISO 9660, XAR and other archive and compression formats, with bsdtar and bsdunzip."
keywords = ["archive", "tar", "zip", "7z", "compression"]
linkage = ["static", "dynamic"]

[tool]
programs = ["bsdtar", "bsdunzip"]

[source]
url = "https://github.com/libarchive/libarchive/releases/download/v3.8.11/libarchive-3.8.11.tar.xz"
sha256 = "a3dc0872b1b39da34dc18ef1b944f0f11ffd37425d70ae04be679279f1cf43d2"
mirrors = ["https://www.libarchive.org/downloads/libarchive-3.8.11.tar.xz"]

[options.zlib]
type = "bool"
default = true
additive = true
doc = "gzip, deflate in zip, and the formats that need it (ISO 9660 zisofs, XAR, 7-Zip deflate), with zlib."

[options.bzip2]
type = "bool"
default = true
additive = true
doc = "bzip2, and bzip2 in zip, 7-Zip and XAR, with bzip2."

[options.lzma]
type = "bool"
default = true
additive = true
doc = "xz, lzma and lzip, and LZMA in zip, 7-Zip and XAR, with liblzma."

[options.lz4]
type = "bool"
default = true
additive = true
doc = "lz4, with lz4."

[options.zstd]
type = "bool"
default = true
additive = true
doc = "zstd, and zstd in zip and 7-Zip, with zstd."

[options.xml]
type = "enum"
values = ["xmllite", "libxml2", "expat", "none"]
default = "xmllite"
doc = "The XML library of the XAR format: Windows' XmlLite or libxml2 (reading and writing), Expat (reading only), or none (no XAR)."

[options.crypto]
type = "enum"
values = ["cng", "openssl", "none"]
default = "cng"
doc = "Windows' CNG or OpenSSL for traditional and AES encryption of zip and the digests of XAR, mtree and WARC; none leaves them out."

[platforms]
supported = ["windows"]
build-on = ["windows/msvc", "linux/clang-cl"]

[deps.zlib]
version = ">= 1.2.1"
default-recipe = "apotocki/zlib"
when = { option = "zlib" }

[deps.bzip2]
version = ">= 1.0"
default-recipe = "apotocki/bzip2"
when = { option = "bzip2" }

[deps.lzma]
version = ">= 5.0"
default-recipe = "apotocki/lzma"
when = { option = "lzma" }

[deps.lz4]
version = ">= 1.7"
default-recipe = "apotocki/lz4"
when = { option = "lz4" }

[deps.zstd]
version = ">= 1.4"
default-recipe = "apotocki/zstd"
when = { option = "zstd" }

[deps.expat]
version = ">= 2.0"
default-recipe = "apotocki/expat"
linkage = "static"
when = { option = "xml", is = "expat" }

[deps.libxml2]
version = ">= 2.9"
default-recipe = "apotocki/libxml2"
linkage = "static"
when = { option = "xml", is = "libxml2" }

[deps.openssl]
version = ">= 3.0"
default-recipe = "apotocki/openssl"
when = { option = "crypto", is = "openssl" }

[toolchains]
cmake = { version = ">= 3.20", default-recipe = "apotocki/cmake" }
ninja = { version = ">= 1.10", default-recipe = "apotocki/ninja" }

[[product]]
name = "LibArchive"
libraries = ["archive"]
link = { libraries = [
    "bcrypt",
    { library = "xmllite", when = { option = "xml", is = "xmllite" } },
    { library = "uuid", when = { option = "xml", is = "xmllite" } },
] }