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": {} +}