From dd87ecc91c79d6df98db9576b64d096dfccda24e Mon Sep 17 00:00:00 2001 From: Rick Guo Date: Tue, 18 Aug 2026 18:47:41 +0800 Subject: [PATCH 1/2] feat(huffman): add LLAR formula --- drichardson/huffman/v1.2.3/huffman_llar.gox | 115 ++++++++++++++++++++ drichardson/huffman/versions.json | 4 + 2 files changed, 119 insertions(+) create mode 100644 drichardson/huffman/v1.2.3/huffman_llar.gox create mode 100644 drichardson/huffman/versions.json diff --git a/drichardson/huffman/v1.2.3/huffman_llar.gox b/drichardson/huffman/v1.2.3/huffman_llar.gox new file mode 100644 index 0000000..0586b4f --- /dev/null +++ b/drichardson/huffman/v1.2.3/huffman_llar.gox @@ -0,0 +1,115 @@ +import ( + "os" + "path/filepath" + "slices" + "strings" +) + +const consumerSource = `#include +#include + +#include "huffman/huffman.h" + +int main(void) { + uint8_t input[3] = {'a', 'b', 'c'}; + unsigned char *encoded = NULL; + uint32_t encoded_len = 0; + + if (huffman_encode_memory(input, 3, &encoded, &encoded_len) != 0) { + return 1; + } + + free(encoded); + return encoded_len == 0; +} +` + +id "drichardson/huffman" + +// v1.2.3 is the first upstream tag with the CMake build and install contract +// used by v1.2.3 through v1.2.7. +fromVer "v1.2.3" + +defaults { + "shared": "OFF", + "fPIC": "ON", +} + +filter => { + for name, values in target.options { + if name != "shared" && name != "fPIC" { + return false + } + for value in values { + if value != "ON" && value != "OFF" { + return false + } + } + } + return true +} + +onBuild ctx => { + installDir := ctx.outputDir + + // Match the Conan recipe's Cygwin source fix while retaining upstream + // behavior on native Windows and other platforms. + sourcePath := filepath.join(ctx.SourceDir, "huffman.c") + source := string(os.readFile(sourcePath)!) + source = strings.replace(source, "#ifdef WIN32", "#if defined _WIN32 || defined __CYGWIN__", 1) + os.writeFile(sourcePath, []byte(source), 0644)! + + shared := slices.contains(target.options["shared"], "ON") + fPIC := slices.contains(target.options["fPIC"], "ON") + + c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir) + c.defineBool "BUILD_SHARED_LIBS", shared + c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC + c.configure + c.build + c.install + + licenseDir := filepath.join(installDir, "licenses") + os.mkdirAll(licenseDir, 0755)! + os.writeFile(filepath.join(licenseDir, "LICENSE"), os.readFile(filepath.join(ctx.SourceDir, "LICENSE"))!, 0644)! + + metadata := "-lhuffman" + if slices.contains(target.require["os"], "windows") { + metadata += " -lws2_32" + } + ctx.setMetadata metadata +} + +onTest ctx => { + installDir := ctx.outputDir + testDir := filepath.join(ctx.SourceDir, "_llar_consumer") + os.mkdirAll(testDir, 0755)! + + sourcePath := filepath.join(testDir, "consumer.c") + os.writeFile(sourcePath, []byte(consumerSource), 0644)! + + binary := filepath.join(testDir, "consumer") + args := []string{ + sourcePath, + "-I" + filepath.join(installDir, "include"), + "-L" + filepath.join(installDir, "lib"), + "-lhuffman", + "-o", binary, + } + if slices.contains(target.require["os"], "windows") { + args = append(args, "-lws2_32") + } + exec "cc", args... + lastErr! + + if slices.contains(target.options["shared"], "ON") { + os.setenv("LD_LIBRARY_PATH", filepath.join(installDir, "lib"))! + os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))! + if slices.contains(target.require["os"], "windows") { + path := os.getenv("PATH") + os.setenv("PATH", filepath.join(installDir, "bin")+";"+path)! + } + } + exec binary + lastErr! +} diff --git a/drichardson/huffman/versions.json b/drichardson/huffman/versions.json new file mode 100644 index 0000000..eb8b2aa --- /dev/null +++ b/drichardson/huffman/versions.json @@ -0,0 +1,4 @@ +{ + "path": "drichardson/huffman", + "deps": {} +} From be8611f004f6a873413e45cf528935371fbbff3c Mon Sep 17 00:00:00 2001 From: Rick Guo Date: Wed, 19 Aug 2026 17:37:50 +0800 Subject: [PATCH 2/2] fix(huffman): use relocatable pkg-config metadata --- drichardson/huffman/v1.2.3/huffman_llar.gox | 42 ++++++++++++--------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/drichardson/huffman/v1.2.3/huffman_llar.gox b/drichardson/huffman/v1.2.3/huffman_llar.gox index 0586b4f..f1206d5 100644 --- a/drichardson/huffman/v1.2.3/huffman_llar.gox +++ b/drichardson/huffman/v1.2.3/huffman_llar.gox @@ -73,11 +73,26 @@ onBuild ctx => { os.mkdirAll(licenseDir, 0755)! os.writeFile(filepath.join(licenseDir, "LICENSE"), os.readFile(filepath.join(ctx.SourceDir, "LICENSE"))!, 0644)! - metadata := "-lhuffman" + libs := "-L$${libdir} -lhuffman" if slices.contains(target.require["os"], "windows") { - metadata += " -lws2_32" + libs += " -lws2_32" } - ctx.setMetadata metadata + + pcDir := filepath.join(installDir, "lib", "pkgconfig") + os.mkdirAll(pcDir, 0755)! + pc := `prefix=$${pcfiledir}/../.. +includedir=$${prefix}/include +libdir=$${prefix}/lib + +Name: huffman +Description: Huffman encoder and decoder library +Version: 1.2.3 +Libs: ` + libs + ` +Cflags: -I$${includedir} +` + os.writeFile(filepath.join(pcDir, "huffman.pc"), []byte(pc), 0644)! + pkgconfig.use installDir + ctx.setMetadata pkgconfig.lookup("huffman")! } onTest ctx => { @@ -89,18 +104,12 @@ onTest ctx => { os.writeFile(sourcePath, []byte(consumerSource), 0644)! binary := filepath.join(testDir, "consumer") - args := []string{ - sourcePath, - "-I" + filepath.join(installDir, "include"), - "-L" + filepath.join(installDir, "lib"), - "-lhuffman", - "-o", binary, - } - if slices.contains(target.require["os"], "windows") { - args = append(args, "-lws2_32") - } - exec "cc", args... - lastErr! + pkgconfig.use installDir + flags := strings.fields(pkgconfig.lookup("huffman")!) + args := []string{sourcePath} + args <- flags... + args <- "-o", binary + cc! args... if slices.contains(target.options["shared"], "ON") { os.setenv("LD_LIBRARY_PATH", filepath.join(installDir, "lib"))! @@ -110,6 +119,5 @@ onTest ctx => { os.setenv("PATH", filepath.join(installDir, "bin")+";"+path)! } } - exec binary - lastErr! + exec! binary }