From c73a630d8f69acc0442d17c72fc2bcad9f7ce56d Mon Sep 17 00:00:00 2001 From: "fennoai[bot]" <231223108+fennoai[bot]@users.noreply.github.com> Date: Thu, 30 Jul 2026 10:47:21 +0000 Subject: [PATCH] Add ebiggers/libdeflate Formula for v1.22 and v1.25 Translate the Conan Center libdeflate recipe into an idiomatic LLAR Formula. One Formula (fromVer "v1.22") serves both v1.22 and v1.25, whose upstream CMake build, options, and installed interface are identical. - onBuild uses the CMake helper to build a single linkage selected by the `shared` option (default OFF -> static), with LIBDEFLATE_BUILD_GZIP and LIBDEFLATE_BUILD_TESTS off, matching the Conan package intent. Install layout is pinned to lib/ so the library, headers, and pkg-config file land where consumers expect them. - Consumer metadata (-I.../include -L.../lib -ldeflate) mirrors the installed libdeflate.pc. - onTest compiles and runs a small C consumer (allocate/free a compressor, as in the Conan test_package) against the installed output, in a build tree independent of onBuild so it also passes on a cache hit. - versions.json declares no dependencies; upstream libdeflate has none. The Conan `fPIC` option is dropped: libdeflate has no PIC build switch and the choice does not change the installed interface, metadata, or dependencies. Co-authored-by: fennoai[bot] <231223108+fennoai[bot]@users.noreply.github.com> Co-authored-by: MeteorsLiu <17515813+MeteorsLiu@users.noreply.github.com> --- ebiggers/libdeflate/v1.22/Libdeflate_llar.gox | 98 +++++++++++++++++++ ebiggers/libdeflate/v1.22/consumer.c | 17 ++++ ebiggers/libdeflate/versions.json | 4 + 3 files changed, 119 insertions(+) create mode 100644 ebiggers/libdeflate/v1.22/Libdeflate_llar.gox create mode 100644 ebiggers/libdeflate/v1.22/consumer.c create mode 100644 ebiggers/libdeflate/versions.json diff --git a/ebiggers/libdeflate/v1.22/Libdeflate_llar.gox b/ebiggers/libdeflate/v1.22/Libdeflate_llar.gox new file mode 100644 index 0000000..d4010ad --- /dev/null +++ b/ebiggers/libdeflate/v1.22/Libdeflate_llar.gox @@ -0,0 +1,98 @@ +import ( + "os" + "slices" +) + +id "ebiggers/libdeflate" + +fromVer "v1.22" + +// libdeflate builds a static library by default. The Conan recipe exposes the +// same static/shared choice through its `shared` option and toggles the two +// upstream CMake switches accordingly. `shared` is the only Conan package +// option that changes the installed library, so it is the only option kept. +// +// The Conan `fPIC` option is intentionally dropped: libdeflate has no PIC build +// switch, always compiles its shared library with position-independent code, +// and the static-library PIC choice changes neither the installed interface, +// the consumer metadata, nor dependency resolution. Keeping it would only add +// meaningless matrix combinations. +defaults { + "shared": "OFF", +} + +filter => { + for _, value := range target.options["shared"] { + if value != "ON" && value != "OFF" { + return false + } + } + return true +} + +onBuild ctx => { + installDir := ctx.outputDir + + shared := slices.contains(target.options["shared"], "ON") + + c := cmake.new(ctx.SourceDir, ctx.SourceDir+"/_build", installDir) + // Pin the install layout to lib/ so the pkg-config file and library land + // where the consumer metadata below and LLAR's `use` helper expect them; + // upstream honors CMAKE_INSTALL_LIBDIR through GNUInstallDirs. + c.define "CMAKE_INSTALL_LIBDIR", "lib" + // Build exactly one linkage, matching the selected `shared` option, and + // omit the gzip program and upstream test suite (the Conan package intent). + c.defineBool "LIBDEFLATE_BUILD_STATIC_LIB", !shared + c.defineBool "LIBDEFLATE_BUILD_SHARED_LIB", shared + c.defineBool "LIBDEFLATE_BUILD_GZIP", false + c.defineBool "LIBDEFLATE_BUILD_TESTS", false + c.configure + c.build + c.install + + // Consumer metadata mirrors the installed libdeflate.pc, which upstream + // generates as `Cflags: -I${includedir}` and `Libs: -L${libdir} -ldeflate` + // with includedir=/include and libdir=/lib. Emitting the + // paths directly avoids pkg-config shell-quoting of the install prefix; + // LLAR's artifact encoder rewrites the prefix into a portable form. + ctx.setMetadata "-I" + installDir + "/include -L" + installDir + "/lib -ldeflate" +} + +onTest ctx => { + installDir := ctx.outputDir + testBuild := ctx.SourceDir + "/_consumer_build" + + if err := os.mkdirAll(testBuild, 0o755); err != nil { + panic err + } + + // Ship the consumer next to the Formula so the test does not depend on the + // onBuild scratch tree, which is skipped on a cache hit. + source := ctx.Proj.readFile("v1.22/consumer.c")! + consumer := testBuild + "/consumer.c" + binary := testBuild + "/consumer" + if err := os.writeFile(consumer, source, 0o644); err != nil { + panic err + } + + // Compile and link against the installed output. libdeflate installs + // under include/ and libdeflate.{a,so} under lib/ with the + // consumer name `deflate`, matching the installed libdeflate.pc. Passing + // these paths as explicit compiler arguments keeps the test correct even + // when the install directory contains characters a pkg-config shell quote + // would otherwise escape. + exec "cc", "-o", binary, consumer, + "-I"+installDir+"/include", + "-L"+installDir+"/lib", + "-ldeflate" + if lastErr != nil { + panic lastErr + } + + // Run the consumer to confirm the installed library actually links and + // loads. A shared build needs its lib directory on the loader path. + exec {"LD_LIBRARY_PATH": installDir + "/lib", "DYLD_LIBRARY_PATH": installDir + "/lib"}, binary + if lastErr != nil { + panic lastErr + } +} diff --git a/ebiggers/libdeflate/v1.22/consumer.c b/ebiggers/libdeflate/v1.22/consumer.c new file mode 100644 index 0000000..aa4ba97 --- /dev/null +++ b/ebiggers/libdeflate/v1.22/consumer.c @@ -0,0 +1,17 @@ +/* + * Minimal libdeflate consumer used by the Formula's onTest hook. + * + * It mirrors the Conan Center test_package.c: allocate a compressor and free + * it again, exercising the installed interface and the linked + * library. Both the static and shared installed outputs must satisfy it. + */ +#include + +int main(void) { + struct libdeflate_compressor *c = libdeflate_alloc_compressor(12); + if (c == NULL) { + return 1; + } + libdeflate_free_compressor(c); + return 0; +} diff --git a/ebiggers/libdeflate/versions.json b/ebiggers/libdeflate/versions.json new file mode 100644 index 0000000..794f3bc --- /dev/null +++ b/ebiggers/libdeflate/versions.json @@ -0,0 +1,4 @@ +{ + "path": "ebiggers/libdeflate", + "deps": {} +}