-
Notifications
You must be signed in to change notification settings - Fork 2
Add json-c/json-c LLAR Formula (Conan 0.18 translation) #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| "shared": "OFF", | ||
| "fPIC": "ON", | ||
| } | ||
|
|
||
| onBuild ctx => { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| installDir := ctx.outputDir | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| shared := slices.contains(target.options["shared"], "ON") | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| // 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 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| 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 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| 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 <json-c/json.h> | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
|
|
||
| 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 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment accuracy: this says "the consumer builds in its own tree", but the consumer is compiled by a raw |
||
| // 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 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assembles a shell command by concatenating unquoted values into |
||
| if lastErr != nil { | ||
| panic lastErr | ||
| } | ||
|
|
||
| exec bin | ||
| if lastErr != nil { | ||
| panic lastErr | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "path": "json-c/json-c", | ||
| "deps": {} | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fromVer "json-c-0.18-20240915"uses a full upstream tag string as the version boundary. SKILL.md describesfromVeras the minimum version served and the existing example uses a plain1.0.0.json-c-0.18-20240915is not semver/dpkg-comparable, so the defaultgnu.Comparemay not order it as intended. Consider adding ajson-c_cmp.goxversion comparator (see SKILL.md "Two Classfiles") and confirm how the resolver compares this tag.