From 8858134b5379bb024f9a19d57e071be38e723534 Mon Sep 17 00:00:00 2001 From: "fennoai[bot]" <231223108+fennoai[bot]@users.noreply.github.com> Date: Thu, 30 Jul 2026 11:54:21 +0000 Subject: [PATCH] Add json-c/json-c LLAR Formula (Conan 0.18 translation) Translate the Conan Center json-c recipe into an idiomatic LLAR Formula serving the upstream tag json-c-0.18-20240915. - CMake build mirroring the Conan CMakeToolchain variables for json-c >= 0.17: BUILD_SHARED_LIBS/BUILD_STATIC_LIBS from the `shared` option, DISABLE_STATIC_FPIC from `fPIC`, plus BUILD_TESTING=OFF and BUILD_APPS=OFF. - No dependencies (verified against the upstream CMakeLists; threading is optional and off by default). - Metadata derived from the installed json-c.pc via pkg-config. - onTest compiles and runs the Conan test_package consumer in an independent tree so it also passes on a build cache hit. - fromVer pinned to the verified 0.18 tag; earlier tags in the same Conan folder use a different build contract and are intentionally not claimed. Closes #39 Co-authored-by: fennoai[bot] <231223108+fennoai[bot]@users.noreply.github.com> Co-authored-by: MeteorsLiu <17515813+MeteorsLiu@users.noreply.github.com> --- .../json-c-0.18-20240915/JsonC_llar.gox | 113 ++++++++++++++++++ json-c/json-c/versions.json | 4 + 2 files changed, 117 insertions(+) create mode 100644 json-c/json-c/json-c-0.18-20240915/JsonC_llar.gox create mode 100644 json-c/json-c/versions.json diff --git a/json-c/json-c/json-c-0.18-20240915/JsonC_llar.gox b/json-c/json-c/json-c-0.18-20240915/JsonC_llar.gox new file mode 100644 index 0000000..adfdbeb --- /dev/null +++ b/json-c/json-c/json-c-0.18-20240915/JsonC_llar.gox @@ -0,0 +1,113 @@ +import "os" +import "slices" + +id "json-c/json-c" + +// Serves the json-c 0.18 upstream tag family. The Conan recipe folder also +// covers 0.14-0.17, but those revisions use a different CMake build contract +// (no BUILD_STATIC_LIBS/DISABLE_STATIC_FPIC before 0.15, no BUILD_APPS and a +// forced CMP0042/policy-min before 0.17). Only the 0.18 revision was verified, +// so this is the honest fromVer boundary. Add a lower threshold with its own +// formula when an earlier range is actually verified. +fromVer "json-c-0.18-20240915" + +// Package-owned choices from the Conan recipe: shared/static selection and, +// for the static library, whether position-independent code is emitted. The +// upstream CMakeLists defaults both libraries ON; Conan builds exactly one, +// defaulting to the static library. +defaults { + "shared": "OFF", + "fPIC": "ON", +} + +onBuild ctx => { + installDir := ctx.outputDir + + shared := slices.contains(target.options["shared"], "ON") + // Conan removes fPIC when building the shared library; PIC is implicit + // for shared objects, so it only affects the static archive. + fpic := shared || slices.contains(target.options["fPIC"], "ON") + + c := cmake.new(ctx.SourceDir, ctx.SourceDir+"/_build", installDir) + c.buildType "Release" + + // Mirror the Conan CMakeToolchain variables for json-c >= 0.17. + c.defineBool "BUILD_SHARED_LIBS", shared + c.defineBool "BUILD_STATIC_LIBS", !shared + c.defineBool "DISABLE_STATIC_FPIC", !fpic + c.defineBool "BUILD_TESTING", false + c.defineBool "BUILD_APPS", false + + c.configure + c.build + c.install + + // Derive metadata from the installed json-c.pc rather than guessing flags. + c.use installDir + capout => { + exec "pkg-config", "--libs", "json-c" + } + if lastErr != nil { + panic lastErr + } + ctx.setMetadata output.trimSpace +} + +onTest ctx => { + installDir := ctx.outputDir + + // Consumer mirrored from the Conan test_package: build a json object and + // serialize it, exercising the installed public headers and library. + testDir := ctx.SourceDir + "/_llartest" + os.mkdirAll(testDir, 0o755)! + + src := `#include +#include +#include + +int main(void) { + json_object *jobj = json_object_new_object(); + json_object *jarray = json_object_new_array(); + json_object_array_add(jarray, json_object_new_string("c")); + json_object_array_add(jarray, json_object_new_string("c++")); + json_object_object_add(jobj, "Categories", jarray); + printf("json object created: %s\n", json_object_to_json_string(jobj)); + json_object_put(jobj); + return EXIT_SUCCESS; +} +` + os.writeFile(testDir+"/consumer.c", []byte(src), 0o644)! + + // Point pkg-config at the installed result. This env change is all the + // test needs, so the consumer builds in its own tree and works identically + // on a cache hit, where onBuild (and its _build tree) never ran. + c := cmake.new(ctx.SourceDir, testDir, installDir) + c.use installDir + + capout => { + exec "pkg-config", "--cflags", "json-c" + } + if lastErr != nil { + panic lastErr + } + cflags := output.trimSpace + + capout => { + exec "pkg-config", "--libs", "json-c" + } + if lastErr != nil { + panic lastErr + } + libs := output.trimSpace + + bin := testDir + "/consumer" + exec "sh", "-c", "cc "+cflags+" "+testDir+"/consumer.c -o "+bin+" "+libs + if lastErr != nil { + panic lastErr + } + + exec bin + if lastErr != nil { + panic lastErr + } +} diff --git a/json-c/json-c/versions.json b/json-c/json-c/versions.json new file mode 100644 index 0000000..59e1006 --- /dev/null +++ b/json-c/json-c/versions.json @@ -0,0 +1,4 @@ +{ + "path": "json-c/json-c", + "deps": {} +}