summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOliver Reiche <oliver.reiche@huawei.com>2023-01-11 18:55:11 +0100
committerOliver Reiche <oliver.reiche@huawei.com>2023-01-20 16:02:11 +0100
commit741a00134ff1de2ec59c98997aa3b1045c99e3a6 (patch)
tree00a6ffe3e7a5cd1e5391f7793fe4dceb3fed8454
parentbd60c35a646f5b4e173a812164b7dbf15a9ca322 (diff)
downloadrules-cc-741a00134ff1de2ec59c98997aa3b1045c99e3a6.tar.gz
Initial support for prebuilt libraries
-rw-r--r--CC/prebuilt/EXPRESSIONS271
-rw-r--r--CC/prebuilt/RULES120
2 files changed, 391 insertions, 0 deletions
diff --git a/CC/prebuilt/EXPRESSIONS b/CC/prebuilt/EXPRESSIONS
new file mode 100644
index 0000000..ca576f4
--- /dev/null
+++ b/CC/prebuilt/EXPRESSIONS
@@ -0,0 +1,271 @@
+{ "check-file-ending":
+ { "doc": ["Returns true if all file names end with the given ending."]
+ , "vars": ["files", "ending", "invert"]
+ , "vars_doc":
+ { "files": ["Artifact map that contains the files."]
+ , "ending": ["The ending to check for (without \".\")."]
+ , "invert": ["Invert condition to file name not ending with \"ending\"."]
+ }
+ , "expression":
+ { "type": "and"
+ , "$1":
+ { "type": "foreach"
+ , "var": "file"
+ , "range": {"type": "keys", "$1": {"type": "var", "name": "files"}}
+ , "body":
+ { "type": "let*"
+ , "bindings":
+ [ [ "is-equal"
+ , { "type": "=="
+ , "$1": {"type": "var", "name": "file"}
+ , "$2":
+ { "type": "change_ending"
+ , "$1": {"type": "var", "name": "file"}
+ , "ending":
+ { "type": "join"
+ , "$1": [".", {"type": "var", "name": "ending"}]
+ }
+ }
+ }
+ ]
+ ]
+ , "body":
+ { "type": "if"
+ , "cond": {"type": "var", "name": "invert", "default": false}
+ , "then":
+ { "type": "if"
+ , "cond": {"type": "var", "name": "is-equal"}
+ , "then": false
+ , "else": true
+ }
+ , "else": {"type": "var", "name": "is-equal"}
+ }
+ }
+ }
+ }
+ }
+, "check-libs-non-static":
+ { "doc":
+ [ "Returns true if all libs are non-static libraries or false otherwise."
+ , "Throws if static and non-static libraries are mixed."
+ ]
+ , "vars": ["libs"]
+ , "vars_doc": {"libs": ["List of artifact maps that contain the libraries."]}
+ , "imports": {"check-file-ending": "check-file-ending"}
+ , "expression":
+ { "type": "let*"
+ , "bindings":
+ [ ["files", {"type": "map_union", "$1": {"type": "var", "name": "libs"}}]
+ , [ "static"
+ , { "type": "let*"
+ , "bindings": [["ending", "a"]]
+ , "body": {"type": "CALL_EXPRESSION", "name": "check-file-ending"}
+ }
+ ]
+ , [ "shared"
+ , { "type": "let*"
+ , "bindings": [["ending", "a"], ["invert", true]]
+ , "body": {"type": "CALL_EXPRESSION", "name": "check-file-ending"}
+ }
+ ]
+ ]
+ , "body":
+ { "type": "if"
+ , "cond":
+ { "type": "or"
+ , "$1":
+ [ {"type": "var", "name": "static"}
+ , {"type": "var", "name": "shared"}
+ ]
+ }
+ , "then": {"type": "var", "name": "shared"}
+ , "else":
+ { "type": "fail"
+ , "msg": "Prebuilt library types (static/shared) may not be mixed."
+ }
+ }
+ }
+ }
+, "prebuilt result":
+ { "vars":
+ [ "name"
+ , "version"
+ , "stage"
+ , "cflags"
+ , "ldflags"
+ , "libs"
+ , "hdrs"
+ , "deps-fieldnames"
+ ]
+ , "imports":
+ { "check-libs-non-static": "check-libs-non-static"
+ , "compile-deps": ["./", "..", "compile-deps"]
+ , "compile-args-deps": ["./", "..", "compile-args-deps"]
+ , "link-deps": ["./", "..", "link-deps"]
+ , "link-args-deps": ["./", "..", "link-args-deps"]
+ , "run-libs-deps": ["./", "..", "run-libs-deps"]
+ , "run-libs-args-deps": ["./", "..", "run-libs-args-deps"]
+ }
+ , "expression":
+ { "type": "let*"
+ , "bindings":
+ [ [ "shared"
+ , {"type": "CALL_EXPRESSION", "name": "check-libs-non-static"}
+ ]
+ , [ "lib-stage"
+ , { "type": "if"
+ , "cond": {"type": "var", "name": "shared"}
+ , "then": "."
+ , "else": {"type": "var", "name": "stage"}
+ }
+ ]
+ , [ "staged-libs"
+ , { "type": "foreach"
+ , "var": "lib"
+ , "range": {"type": "var", "name": "libs"}
+ , "body":
+ { "type": "to_subdir"
+ , "subdir": {"type": "var", "name": "lib-stage"}
+ , "flat": true
+ , "msg": "prebuilt libraries may not overlap"
+ , "$1": {"type": "var", "name": "lib"}
+ }
+ }
+ ]
+ , [ "link-args"
+ , { "type": "if"
+ , "cond": {"type": "var", "name": "shared"}
+ , "then": []
+ , "else":
+ { "type": "foreach"
+ , "var": "lib"
+ , "range": {"type": "var", "name": "staged-libs"}
+ , "body":
+ { "type": "join"
+ , "$1": {"type": "keys", "$1": {"type": "var", "name": "lib"}}
+ }
+ }
+ }
+ ]
+ , [ "run-libs-args"
+ , { "type": "if"
+ , "cond": {"type": "var", "name": "shared"}
+ , "then":
+ { "type": "foreach"
+ , "var": "lib"
+ , "range": {"type": "var", "name": "staged-libs"}
+ , "body":
+ { "type": "join"
+ , "$1": {"type": "keys", "$1": {"type": "var", "name": "lib"}}
+ }
+ }
+ }
+ ]
+ , [ "libs"
+ , { "type": "disjoint_map_union"
+ , "msg": "prebuilt libraries may not overlap"
+ , "$1": {"type": "var", "name": "staged-libs"}
+ }
+ ]
+ , [ "hdrs"
+ , { "type": "to_subdir"
+ , "subdir": {"type": "var", "name": "stage"}
+ , "$1":
+ { "type": "disjoint_map_union"
+ , "msg": "prebuilt headers may not overlap"
+ , "$1": {"type": "var", "name": "hdrs"}
+ }
+ }
+ ]
+ , ["compile-deps", {"type": "CALL_EXPRESSION", "name": "compile-deps"}]
+ , [ "compile-args"
+ , { "type": "nub_right"
+ , "$1":
+ { "type": "++"
+ , "$1":
+ [ {"type": "var", "name": "cflags"}
+ , {"type": "CALL_EXPRESSION", "name": "compile-args-deps"}
+ ]
+ }
+ }
+ ]
+ , ["link-deps", {"type": "CALL_EXPRESSION", "name": "link-deps"}]
+ , [ "link-args"
+ , { "type": "nub_right"
+ , "$1":
+ { "type": "++"
+ , "$1":
+ [ {"type": "var", "name": "link-args"}
+ , {"type": "CALL_EXPRESSION", "name": "link-args-deps"}
+ ]
+ }
+ }
+ ]
+ , [ "run-libs"
+ , { "type": "map_union"
+ , "$1":
+ [ { "type": "if"
+ , "cond": {"type": "var", "name": "shared"}
+ , "then": {"type": "var", "name": "libs"}
+ , "else": {"type": "empty_map"}
+ }
+ , {"type": "CALL_EXPRESSION", "name": "run-libs-deps"}
+ ]
+ }
+ ]
+ , [ "run-libs-args"
+ , { "type": "nub_right"
+ , "$1":
+ { "type": "++"
+ , "$1":
+ [ {"type": "var", "name": "run-libs-args"}
+ , {"type": "var", "name": "ldflags"}
+ , {"type": "CALL_EXPRESSION", "name": "run-libs-args-deps"}
+ ]
+ }
+ }
+ ]
+ , [ "package"
+ , { "type": "let*"
+ , "bindings":
+ [ ["name", {"type": "var", "name": "name"}]
+ , [ "version"
+ , { "type": "if"
+ , "cond": {"type": "var", "name": "version"}
+ , "then":
+ { "type": "join"
+ , "separator": "."
+ , "$1": {"type": "var", "name": "version"}
+ }
+ , "else": null
+ }
+ ]
+ ]
+ , "body": {"type": "env", "vars": ["name", "version"]}
+ }
+ ]
+ ]
+ , "body":
+ { "type": "RESULT"
+ , "artifacts": {"type": "var", "name": "libs"}
+ , "runfiles": {"type": "var", "name": "hdrs"}
+ , "provides":
+ { "type": "map_union"
+ , "$1":
+ [ { "type": "env"
+ , "vars":
+ [ "compile-deps"
+ , "compile-args"
+ , "link-deps"
+ , "link-args"
+ , "run-libs"
+ , "run-libs-args"
+ , "package"
+ ]
+ }
+ ]
+ }
+ }
+ }
+ }
+}
diff --git a/CC/prebuilt/RULES b/CC/prebuilt/RULES
new file mode 100644
index 0000000..be2bacc
--- /dev/null
+++ b/CC/prebuilt/RULES
@@ -0,0 +1,120 @@
+{ "library":
+ { "doc": ["A prebuilt C++ library"]
+ , "target_fields": ["lib", "hdrs", "deps"]
+ , "string_fields":
+ ["name", "version", "stage", "defines", "cflags", "ldflags"]
+ , "field_doc":
+ { "name":
+ [ "The name of the library (without leading \"lib\" or trailing file name"
+ , "extension), also used as name for pkg-config files."
+ ]
+ , "version":
+ [ "The library version, used for pkg-config files. Individual version"
+ , "components are joined with \".\"."
+ ]
+ , "lib":
+ [ "The actual prebuilt library. If multiple libraries are specified"
+ , "(e.g., one depends on the other), the order matters. Library types"
+ , "cannot be mixed. All of them have to be either static or shared."
+ ]
+ , "hdrs": ["Any public header files of the library."]
+ , "deps": ["Any other libraries this library depends upon."]
+ , "stage":
+ [ "The logical location of all header and source files, as well as the"
+ , "resulting library file. Individual directory components are joined"
+ , "with \"/\"."
+ ]
+ , "defines":
+ [ "List of defines set for this target and its consumers."
+ , "Each list entry will be prepended by \"-D\"."
+ ]
+ , "cflags":
+ ["List of compile flags set for this target and its consumers."]
+ , "ldflags":
+ ["Additional linker flags (typically for linking system libraries)."]
+ }
+ , "artifacts_doc":
+ [ "The actual library (libname.a or libname.so). Only static libraries are"
+ , "staged in the specified directory."
+ ]
+ , "runfiles_doc": ["The public headers staged to the specified directory."]
+ , "provides_doc":
+ { "compile-deps":
+ [ "Map of artifacts specifying any additional files that, besides the"
+ , "runfiles have to be present in compile actions of targets depending on"
+ , "this library."
+ ]
+ , "link-deps":
+ [ "Map of artifacts specifying any additional files that, besides the artifacts,"
+ , "have to be present in a link actions of targets depending on this library"
+ ]
+ , "run-libs":
+ [ "Map of artifacts specifying all files, including the artifacts of this"
+ , "library if shared, that have to be present in link actions of targets"
+ , "depending on this library."
+ ]
+ , "link-args":
+ [ "List of strings that have to be added to the command line for linking"
+ , "actions in targets depending on this library."
+ ]
+ , "run-libs-args":
+ [ "List of strings that have to be added to the command line for linking"
+ , "runtime libraries in targets depending on this library."
+ ]
+ , "compile-args":
+ [ "List of strings that have to be added to the command line for compile"
+ , "actions in targets depending on this library."
+ ]
+ }
+ , "imports":
+ { "artifacts_list": ["./", "../..", "field_artifacts_list"]
+ , "prebuilt result": "prebuilt result"
+ }
+ , "expression":
+ { "type": "let*"
+ , "bindings":
+ [ [ "name"
+ , { "type": "assert_non_empty"
+ , "msg": "name is required for prebuilt library"
+ , "$1": {"type": "join", "$1": {"type": "FIELD", "name": "name"}}
+ }
+ ]
+ , ["version", {"type": "FIELD", "name": "version"}]
+ , [ "stage"
+ , { "type": "join"
+ , "separator": "/"
+ , "$1": {"type": "FIELD", "name": "stage"}
+ }
+ ]
+ , [ "cflags"
+ , { "type": "++"
+ , "$1":
+ [ {"type": "FIELD", "name": "cflags"}
+ , { "type": "foreach"
+ , "var": "def"
+ , "range": {"type": "FIELD", "name": "defines"}
+ , "body":
+ {"type": "join", "$1": ["-D", {"type": "var", "name": "def"}]}
+ }
+ ]
+ }
+ ]
+ , ["ldflags", {"type": "FIELD", "name": "ldflags"}]
+ , [ "libs"
+ , { "type": "let*"
+ , "bindings": [["fieldname", "lib"]]
+ , "body": {"type": "CALL_EXPRESSION", "name": "artifacts_list"}
+ }
+ ]
+ , [ "hdrs"
+ , { "type": "let*"
+ , "bindings": [["fieldname", "hdrs"]]
+ , "body": {"type": "CALL_EXPRESSION", "name": "artifacts_list"}
+ }
+ ]
+ , ["deps-fieldnames", ["deps"]]
+ ]
+ , "body": {"type": "CALL_EXPRESSION", "name": "prebuilt result"}
+ }
+ }
+}