From ffd3558641374cbbdbcaab93d9e9f53ace0eddeb Mon Sep 17 00:00:00 2001 From: "fennoai[bot]" <231223108+fennoai[bot]@users.noreply.github.com> Date: Thu, 30 Jul 2026 11:47:26 +0000 Subject: [PATCH] feat(json-c): add json-c/json-c formula Translate the Conan Center json-c recipe (snapshot ffe30df101afd4dc95aac2f14b25bf345e64d7be, version 0.18) into an LLAR Formula serving upstream tag json-c-0.18-20240915. The build uses the CMake helper with the library-only configuration the Conan recipe selects for its defaults: static archive with -fPIC, BUILD_TESTING and BUILD_APPS off, and a normalized lib/ install layout. Consumer metadata is derived from the installed json-c.pc pkg-config file (static query, so the private -lm dependency is reported). onTest compiles and runs the Conan test_package consumer against the installed CMake package in a build tree independent of the onBuild scratch tree so it also passes on a cache hit. No dependencies: the upstream source and the Conan recipe declare none. 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 | 91 +++++++++++++++++++ json-c/json-c/versions.json | 4 + 2 files changed, 95 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..13e21ea --- /dev/null +++ b/json-c/json-c/json-c-0.18-20240915/Jsonc_llar.gox @@ -0,0 +1,91 @@ +import ( + "os" + "strings" +) + +id "json-c/json-c" + +fromVer "json-c-0.18-20240915" + +onBuild ctx => { + installDir := ctx.outputDir + c := cmake.new(ctx.SourceDir, ctx.SourceDir+"/_build", installDir) + + // Keep a standard lib/ layout so the installed pkg-config file and the + // dependency search paths resolve without lib64 handling. + c.define "CMAKE_INSTALL_LIBDIR", "lib" + // Build the static archive with position-independent code, matching the + // Conan recipe defaults (shared=False, fPIC=True). json-c builds its + // shared and static libraries from independent targets, so select the + // static one and leave DISABLE_STATIC_FPIC off to keep -fPIC. + c.defineBool "BUILD_SHARED_LIBS", false + c.defineBool "BUILD_STATIC_LIBS", true + c.defineBool "DISABLE_STATIC_FPIC", false + // Library-only install: skip the upstream test suite and CLI apps. + c.defineBool "BUILD_TESTING", false + c.defineBool "BUILD_APPS", false + + c.configure + c.build + c.install + + // Derive consumer flags from the installed pkg-config file. The static + // query also reports json-c's private math dependency (-lm on UNIX), + // which a static consumer must link. + c.use installDir + capout => { + exec "pkg-config", "--cflags", "--libs", "--static", "json-c" + } + if lastErr != nil { + panic lastErr + } + ctx.setMetadata strings.trimSpace(output) +} + +onTest ctx => { + installDir := ctx.outputDir + + // Build the consumer in a tree independent of the onBuild scratch tree so + // the test also runs on a cache hit, where onBuild is skipped. + testDir := ctx.SourceDir + "/_llar_consumer" + testBuild := testDir + "/_build" + + // The consumer mirrors the Conan test_package: include , + // link against json-c via its installed CMake package, then build a small + // JSON object to confirm the installed headers and library are usable. + source := `#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("%s\n", json_object_to_json_string(jobj)); + json_object_put(jobj); + return EXIT_SUCCESS; +} +` + os.mkdirAll(testDir, 0755)! + os.writeFile(testDir+"/consumer.c", []byte(source), 0644)! + + cmakeLists := `cmake_minimum_required(VERSION 3.15) +project(json_c_consumer LANGUAGES C) +find_package(json-c REQUIRED CONFIG) +add_executable(consumer consumer.c) +target_link_libraries(consumer PRIVATE json-c::json-c) +` + os.writeFile(testDir+"/CMakeLists.txt", []byte(cmakeLists), 0644)! + + tc := cmake.new(testDir, testBuild, "") + tc.use installDir + tc.configure + tc.build + + exec testBuild + "/consumer" + 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": {} +}