diff options
-rw-r--r-- | rules/CC/EXPRESSIONS | 229 | ||||
-rw-r--r-- | rules/CC/IDE/RULES | 96 | ||||
-rw-r--r-- | rules/CC/RULES | 231 | ||||
-rw-r--r-- | rules/CC/pkgconfig/EXPRESSIONS | 136 | ||||
-rw-r--r-- | rules/CC/pkgconfig/RULES | 52 | ||||
-rw-r--r-- | rules/CC/proto/EXPRESSIONS | 166 | ||||
-rw-r--r-- | rules/CC/proto/RULES | 238 | ||||
-rw-r--r-- | rules/CC/proto/TARGETS | 13 |
8 files changed, 769 insertions, 392 deletions
diff --git a/rules/CC/EXPRESSIONS b/rules/CC/EXPRESSIONS index 5a425c7..a520cde 100644 --- a/rules/CC/EXPRESSIONS +++ b/rules/CC/EXPRESSIONS @@ -115,7 +115,7 @@ } , "defaults-base-provides": { "doc": ["Query list-provider from 'base' targets (last wins)"] - , "vars": ["provider"] + , "vars": ["provider", "default"] , "vars_doc": {"provider": ["The name of the list-provider in the provides map."]} , "imports": {"provider_list": ["./", "..", "field_provider_list"]} @@ -125,6 +125,7 @@ , "body": { "type": "foldl" , "var": "next" + , "start": {"type": "var", "name": "default", "default": []} , "accum_var": "curr" , "range": {"type": "CALL_EXPRESSION", "name": "provider_list"} , "body": @@ -1590,4 +1591,230 @@ } } } +, "install-with-deps result": + { "vars": ["pc-install-dir", "targets", "prefix", "flat-libs", "hdrs-only"] + , "imports": + { "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" + , "pkg-config": "pkg-config" + } + , "expression": + { "type": "let*" + , "bindings": + [ [ "install-stage" + , { "type": "disjoint_map_union" + , "msg": "install stages may not overlap" + , "$1": + { "type": "foreach" + , "var": "target" + , "range": {"type": "var", "name": "targets"} + , "body": + { "type": "let*" + , "bindings": + [ [ "runfiles" + , { "type": "DEP_RUNFILES" + , "dep": {"type": "var", "name": "target"} + , "default": {"type": "empty_map"} + } + ] + , [ "compile-deps" + , { "type": "DEP_PROVIDES" + , "dep": {"type": "var", "name": "target"} + , "provider": "compile-deps" + , "default": {"type": "empty_map"} + } + ] + , [ "headers" + , { "type": "disjoint_map_union" + , "msg": "headers may not overlap" + , "$1": + [ {"type": "var", "name": "runfiles"} + , {"type": "var", "name": "compile-deps"} + ] + } + ] + ] + , "body": + { "type": "if" + , "cond": {"type": "var", "name": "hdrs-only"} + , "then": {"type": "var", "name": "headers"} + , "else": + { "type": "let*" + , "bindings": + [ [ "artifacts" + , { "type": "DEP_ARTIFACTS" + , "dep": {"type": "var", "name": "target"} + , "default": {"type": "empty_map"} + } + ] + , [ "link-deps" + , { "type": "DEP_PROVIDES" + , "dep": {"type": "var", "name": "target"} + , "provider": "link-deps" + , "default": {"type": "empty_map"} + } + ] + , [ "run-libs" + , { "type": "DEP_PROVIDES" + , "dep": {"type": "var", "name": "target"} + , "provider": "run-libs" + , "default": {"type": "empty_map"} + } + ] + , [ "package" + , { "type": "DEP_PROVIDES" + , "dep": {"type": "var", "name": "target"} + , "provider": "package" + , "default": {"type": "empty_map"} + } + ] + , [ "to_bin" + , { "type": "lookup" + , "key": "to_bin" + , "map": {"type": "var", "name": "package"} + } + ] + , [ "binaries" + , { "type": "if" + , "cond": {"type": "var", "name": "to_bin"} + , "then": {"type": "var", "name": "artifacts"} + , "else": {"type": "empty_map"} + } + ] + , [ "libraries" + , { "type": "disjoint_map_union" + , "msg": "libraries may not overlap" + , "$1": + { "type": "++" + , "$1": + [ { "type": "if" + , "cond": {"type": "var", "name": "to_bin"} + , "then": [] + , "else": [{"type": "var", "name": "artifacts"}] + } + , [{"type": "var", "name": "link-deps"}] + , [{"type": "var", "name": "run-libs"}] + ] + } + } + ] + , [ "pkg-name" + , { "type": "lookup" + , "key": "name" + , "map": {"type": "var", "name": "package"} + } + ] + , [ "pkg-config" + , { "type": "if" + , "cond": {"type": "var", "name": "pkg-name"} + , "then": + { "type": "let*" + , "bindings": + [ ["pkg-prefix", {"type": "var", "name": "prefix"}] + , [ "pkg-version" + , { "type": "lookup" + , "key": "version" + , "map": {"type": "var", "name": "package"} + } + ] + , [ "pkg-cflags" + , { "type": "DEP_PROVIDES" + , "dep": {"type": "var", "name": "target"} + , "provider": "compile-args" + , "default": [] + } + ] + , [ "pkg-ldflags" + , { "type": "++" + , "$1": + [ { "type": "DEP_PROVIDES" + , "dep": {"type": "var", "name": "target"} + , "provider": "link-args" + , "default": [] + } + , { "type": "DEP_PROVIDES" + , "dep": {"type": "var", "name": "target"} + , "provider": "run-libs-args" + , "default": [] + } + ] + } + ] + , [ "pkg-flag-files" + , { "type": "map_union" + , "$1": + [ { "type": "lookup" + , "key": "cflags-files" + , "map": {"type": "var", "name": "package"} + , "default": {"type": "empty_map"} + } + , { "type": "lookup" + , "key": "ldflags-files" + , "map": {"type": "var", "name": "package"} + , "default": {"type": "empty_map"} + } + ] + } + ] + , [ "pkg-libs" + , {"type": "var", "name": "libraries"} + ] + , [ "flat-libs" + , {"type": "var", "name": "flat-libs"} + ] + ] + , "body": + { "type": "map_union" + , "$1": + [ { "type": "CALL_EXPRESSION" + , "name": "pkg-config" + } + , {"type": "var", "name": "pkg-flag-files"} + ] + } + } + , "else": {"type": "empty_map"} + } + ] + ] + , "body": + { "type": "map_union" + , "$1": + [ { "type": "to_subdir" + , "subdir": "bin" + , "flat": true + , "msg": "install binaries may not overlap" + , "$1": {"type": "var", "name": "binaries"} + } + , { "type": "to_subdir" + , "subdir": "include" + , "$1": {"type": "var", "name": "headers"} + } + , { "type": "to_subdir" + , "subdir": "lib" + , "flat": {"type": "var", "name": "flat-libs"} + , "msg": "install libraries may not overlap" + , "$1": {"type": "var", "name": "libraries"} + } + , { "type": "to_subdir" + , "subdir": {"type": "var", "name": "pc-install-dir"} + , "$1": {"type": "var", "name": "pkg-config"} + } + ] + } + } + } + } + } + } + ] + ] + , "body": + {"type": "RESULT", "artifacts": {"type": "var", "name": "install-stage"}} + } + } } diff --git a/rules/CC/IDE/RULES b/rules/CC/IDE/RULES deleted file mode 100644 index dc4b607..0000000 --- a/rules/CC/IDE/RULES +++ /dev/null @@ -1,96 +0,0 @@ -{ "headers": - { "doc": ["Transitive public headers of C++ target"] - , "target_fields": ["proto", "deps"] - , "string_fields": ["stage"] - , "field_doc": - { "proto": ["The proto source files for creating cc bindings."] - , "deps": ["The targets to obtain the headers from."] - , "stage": - [ "The logical location of the header files. Individual directory" - , "components are joined with \"/\"." - ] - } - , "anonymous": - { "proto-deps": - { "target": "proto" - , "provider": "proto" - , "rule_map": - { "library": ["./", "../proto", "library"] - , "service library": ["./", "../proto", "service library"] - } - } - } - , "imports": {"runfiles_list": ["./", "../..", "field_runfiles_list"]} - , "expression": - { "type": "let*" - , "bindings": - [ [ "stage" - , { "type": "join" - , "separator": "/" - , "$1": {"type": "FIELD", "name": "stage"} - } - ] - , [ "artifacts" - , { "type": "to_subdir" - , "subdir": {"type": "var", "name": "stage"} - , "$1": - { "type": "map_union" - , "$1": - { "type": "++" - , "$1": - [ { "type": "let*" - , "bindings": [["fieldname", "proto-deps"]] - , "body": - {"type": "CALL_EXPRESSION", "name": "runfiles_list"} - } - , { "type": "foreach" - , "var": "x" - , "range": {"type": "FIELD", "name": "proto-deps"} - , "body": - { "type": "DEP_PROVIDES" - , "provider": "compile-deps" - , "dep": {"type": "var", "name": "x"} - , "default": - { "type": "fail" - , "msg": - [ "Expected a library target, but got:" - , {"type": "var", "name": "x"} - ] - } - } - } - , { "type": "let*" - , "bindings": [["fieldname", "deps"]] - , "body": - {"type": "CALL_EXPRESSION", "name": "runfiles_list"} - } - , { "type": "foreach" - , "var": "x" - , "range": {"type": "FIELD", "name": "deps"} - , "body": - { "type": "DEP_PROVIDES" - , "provider": "compile-deps" - , "dep": {"type": "var", "name": "x"} - , "default": - { "type": "fail" - , "msg": - [ "Expected a library target, but got:" - , {"type": "var", "name": "x"} - ] - } - } - } - ] - } - } - } - ] - ] - , "body": - { "type": "RESULT" - , "artifacts": {"type": "var", "name": "artifacts"} - , "runfiles": {"type": "var", "name": "artifacts"} - } - } - } -} diff --git a/rules/CC/RULES b/rules/CC/RULES index 9133833..960c8d9 100644 --- a/rules/CC/RULES +++ b/rules/CC/RULES @@ -588,16 +588,8 @@ ] , "config_vars": ["PREFIX"] , "target_fields": ["targets"] - , "string_fields": ["flat-libs", "prefix"] - , "imports": - { "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" - , "pkg-config": "pkg-config" - } + , "string_fields": ["flat-libs", "prefix", "hdrs-only"] + , "imports": {"install result": "install-with-deps result"} , "field_doc": { "targets": ["Targets to install artifacts from."] , "flat-libs": @@ -611,6 +603,7 @@ , "prefix is specified, the value from the config variable \"PREFIX\" is" , "taken, with the default value being \"/\"." ] + , "hdrs-only": ["Only collect headers from deps (without subdirectory)."] } , "config_doc": { "PREFIX": @@ -625,215 +618,23 @@ { "type": "let*" , "bindings": [ ["pc-install-dir", "share/pkgconfig"] - , [ "install-stage" - , { "type": "disjoint_map_union" - , "msg": "install stages may not overlap" - , "$1": - { "type": "foreach" - , "var": "target" - , "range": {"type": "FIELD", "name": "targets"} - , "body": - { "type": "let*" - , "bindings": - [ [ "artifacts" - , { "type": "DEP_ARTIFACTS" - , "dep": {"type": "var", "name": "target"} - , "default": {"type": "empty_map"} - } - ] - , [ "runfiles" - , { "type": "DEP_RUNFILES" - , "dep": {"type": "var", "name": "target"} - , "default": {"type": "empty_map"} - } - ] - , [ "compile-deps" - , { "type": "DEP_PROVIDES" - , "dep": {"type": "var", "name": "target"} - , "provider": "compile-deps" - , "default": {"type": "empty_map"} - } - ] - , [ "link-deps" - , { "type": "DEP_PROVIDES" - , "dep": {"type": "var", "name": "target"} - , "provider": "link-deps" - , "default": {"type": "empty_map"} - } - ] - , [ "run-libs" - , { "type": "DEP_PROVIDES" - , "dep": {"type": "var", "name": "target"} - , "provider": "run-libs" - , "default": {"type": "empty_map"} - } - ] - , [ "package" - , { "type": "DEP_PROVIDES" - , "dep": {"type": "var", "name": "target"} - , "provider": "package" - , "default": {"type": "empty_map"} - } - ] - , [ "to_bin" - , { "type": "lookup" - , "key": "to_bin" - , "map": {"type": "var", "name": "package"} - } - ] - , [ "binaries" - , { "type": "if" - , "cond": {"type": "var", "name": "to_bin"} - , "then": {"type": "var", "name": "artifacts"} - , "else": {"type": "empty_map"} - } - ] - , [ "headers" - , { "type": "disjoint_map_union" - , "msg": "headers may not overlap" - , "$1": - [ {"type": "var", "name": "runfiles"} - , {"type": "var", "name": "compile-deps"} - ] - } - ] - , [ "libraries" - , { "type": "disjoint_map_union" - , "msg": "libraries may not overlap" - , "$1": - { "type": "++" - , "$1": - [ { "type": "if" - , "cond": {"type": "var", "name": "to_bin"} - , "then": [] - , "else": [{"type": "var", "name": "artifacts"}] - } - , [{"type": "var", "name": "link-deps"}] - , [{"type": "var", "name": "run-libs"}] - ] - } - } - ] - , [ "pkg-name" - , { "type": "lookup" - , "key": "name" - , "map": {"type": "var", "name": "package"} - } - ] - , [ "pkg-config" - , { "type": "if" - , "cond": {"type": "var", "name": "pkg-name"} - , "then": - { "type": "let*" - , "bindings": - [ [ "pkg-prefix" - , { "type": "if" - , "cond": {"type": "FIELD", "name": "prefix"} - , "then": - { "type": "join" - , "separator": "/" - , "$1": - { "type": "++" - , "$1": - [[""], {"type": "FIELD", "name": "prefix"}] - } - } - , "else": - {"type": "var", "name": "PREFIX", "default": "/"} - } - ] - , [ "pkg-version" - , { "type": "lookup" - , "key": "version" - , "map": {"type": "var", "name": "package"} - } - ] - , [ "pkg-cflags" - , { "type": "DEP_PROVIDES" - , "dep": {"type": "var", "name": "target"} - , "provider": "compile-args" - , "default": [] - } - ] - , [ "pkg-ldflags" - , { "type": "++" - , "$1": - [ { "type": "DEP_PROVIDES" - , "dep": {"type": "var", "name": "target"} - , "provider": "link-args" - , "default": [] - } - , { "type": "DEP_PROVIDES" - , "dep": {"type": "var", "name": "target"} - , "provider": "run-libs-args" - , "default": [] - } - ] - } - ] - , [ "pkg-flag-files" - , { "type": "map_union" - , "$1": - [ { "type": "lookup" - , "key": "cflags-files" - , "map": {"type": "var", "name": "package"} - , "default": {"type": "empty_map"} - } - , { "type": "lookup" - , "key": "ldflags-files" - , "map": {"type": "var", "name": "package"} - , "default": {"type": "empty_map"} - } - ] - } - ] - , ["pkg-libs", {"type": "var", "name": "libraries"}] - , ["flat-libs", {"type": "FIELD", "name": "flat-libs"}] - ] - , "body": - { "type": "map_union" - , "$1": - [ {"type": "CALL_EXPRESSION", "name": "pkg-config"} - , {"type": "var", "name": "pkg-flag-files"} - ] - } - } - , "else": {"type": "empty_map"} - } - ] - ] - , "body": - { "type": "map_union" - , "$1": - [ { "type": "to_subdir" - , "subdir": "bin" - , "flat": true - , "msg": "install binaries may not overlap" - , "$1": {"type": "var", "name": "binaries"} - } - , { "type": "to_subdir" - , "subdir": "include" - , "$1": {"type": "var", "name": "headers"} - } - , { "type": "to_subdir" - , "subdir": "lib" - , "flat": {"type": "FIELD", "name": "flat-libs"} - , "msg": "install libraries may not overlap" - , "$1": {"type": "var", "name": "libraries"} - } - , { "type": "to_subdir" - , "subdir": {"type": "var", "name": "pc-install-dir"} - , "$1": {"type": "var", "name": "pkg-config"} - } - ] - } - } + , ["targets", {"type": "FIELD", "name": "targets"}] + , [ "prefix" + , { "type": "if" + , "cond": {"type": "FIELD", "name": "prefix"} + , "then": + { "type": "join" + , "separator": "/" + , "$1": + {"type": "++", "$1": [[""], {"type": "FIELD", "name": "prefix"}]} } + , "else": {"type": "var", "name": "PREFIX", "default": "/"} } ] + , ["flat-libs", {"type": "FIELD", "name": "flat-libs"}] + , ["hdrs-only", {"type": "FIELD", "name": "hdrs-only"}] ] - , "body": - {"type": "RESULT", "artifacts": {"type": "var", "name": "install-stage"}} + , "body": {"type": "CALL_EXPRESSION", "name": "install result"} } } } diff --git a/rules/CC/pkgconfig/EXPRESSIONS b/rules/CC/pkgconfig/EXPRESSIONS new file mode 100644 index 0000000..c770421 --- /dev/null +++ b/rules/CC/pkgconfig/EXPRESSIONS @@ -0,0 +1,136 @@ +{ "pkgconfig result": + { "vars": ["ENV", "name", "args", "stage"] + , "imports": {"default-ENV": ["./", "..", "default-ENV"]} + , "expression": + { "type": "let*" + , "bindings": + [ [ "ENV" + , { "type": "map_union" + , "$1": + { "type": "++" + , "$1": + [ {"type": "CALL_EXPRESSION", "name": "default-ENV"} + , [ { "type": "var" + , "name": "ENV" + , "default": {"type": "empty_map"} + } + ] + ] + } + } + ] + , [ "cflags-filename" + , {"type": "join", "$1": [{"type": "var", "name": "name"}, ".cflags"]} + ] + , [ "cflags-files" + , { "type": "to_subdir" + , "subdir": {"type": "var", "name": "stage"} + , "$1": + { "type": "ACTION" + , "inputs": {"type": "empty_map"} + , "cmd": + [ "/bin/sh" + , "-c" + , { "type": "join" + , "separator": " " + , "$1": + { "type": "++" + , "$1": + [ ["pkg-config"] + , [ { "type": "join_cmd" + , "$1": + { "type": "++" + , "$1": + [ {"type": "var", "name": "args", "default": []} + , ["--cflags", {"type": "var", "name": "name"}] + ] + } + } + ] + , [">"] + , [ { "type": "join_cmd" + , "$1": {"type": "var", "name": "cflags-filename"} + } + ] + ] + } + } + ] + , "env": {"type": "var", "name": "ENV"} + , "outs": [{"type": "var", "name": "cflags-filename"}] + } + } + ] + , [ "compile-args" + , { "type": "foreach_map" + , "var_key": "flag-file" + , "range": {"type": "var", "name": "cflags-files"} + , "body": + {"type": "join", "$1": ["@", {"type": "var", "name": "flag-file"}]} + } + ] + , [ "ldflags-filename" + , {"type": "join", "$1": [{"type": "var", "name": "name"}, ".ldflags"]} + ] + , [ "ldflags-files" + , { "type": "to_subdir" + , "subdir": {"type": "var", "name": "stage"} + , "$1": + { "type": "ACTION" + , "inputs": {"type": "empty_map"} + , "cmd": + [ "/bin/sh" + , "-c" + , { "type": "join" + , "separator": " " + , "$1": + { "type": "++" + , "$1": + [ ["pkg-config"] + , [ { "type": "join_cmd" + , "$1": + { "type": "++" + , "$1": + [ {"type": "var", "name": "args", "default": []} + , ["--libs", {"type": "var", "name": "name"}] + ] + } + } + ] + , [">"] + , [ { "type": "join_cmd" + , "$1": {"type": "var", "name": "ldflags-filename"} + } + ] + ] + } + } + ] + , "env": {"type": "var", "name": "ENV"} + , "outs": [{"type": "var", "name": "ldflags-filename"}] + } + } + ] + , [ "link-args" + , { "type": "foreach_map" + , "var_key": "flag-file" + , "range": {"type": "var", "name": "ldflags-files"} + , "body": + {"type": "join", "$1": ["@", {"type": "var", "name": "flag-file"}]} + } + ] + , ["package", {"type": "env", "vars": ["cflags-files", "ldflags-files"]}] + , ["compile-deps", {"type": "empty_map"}] + , ["link-deps", {"type": "empty_map"}] + ] + , "body": + { "type": "RESULT" + , "provides": + { "type": "env" + , "vars": + ["compile-deps", "compile-args", "link-deps", "link-args", "package"] + } + } + } + } +} diff --git a/rules/CC/pkgconfig/RULES b/rules/CC/pkgconfig/RULES new file mode 100644 index 0000000..a6f6ce8 --- /dev/null +++ b/rules/CC/pkgconfig/RULES @@ -0,0 +1,52 @@ +{ "system_library": + { "doc": ["A system library via pkg-config"] + , "string_fields": ["name", "args", "stage"] + , "implicit": {"defaults": [["./", "..", "defaults"]]} + , "config_vars": ["PKG_CONFIG_ARGS", "ENV"] + , "field_doc": + { "name": ["The pkg-config name of the library."] + , "args": + [ "Additional pkg-config arguments (e.g., \"--define-prefix\" or" + , "\"--static\"), appended to the config variable \"PKG_CONFIG_ARGS\"." + ] + , "stage": ["The stage of the internally created flag files."] + } + , "config_doc": + { "PKG_CONFIG_ARGS": + [ "Additional pkg-config arguments (e.g., \"--define-prefix\" or" + , "\"--static\")." + ] + , "ENV": + [ "The environment for any action generated. May contain colon-separated" + , "\"PKG_CONFIG_PATH\" for looking up pkg-config files." + ] + } + , "imports": {"pkgconfig result": "pkgconfig result"} + , "expression": + { "type": "let*" + , "bindings": + [ [ "name" + , { "type": "assert_non_empty" + , "msg": "system_library requires non-empty name" + , "$1": {"type": "join", "$1": {"type": "FIELD", "name": "name"}} + } + ] + , [ "args" + , { "type": "++" + , "$1": + [ {"type": "var", "name": "PKG_CONFIG_ARGS", "default": []} + , {"type": "FIELD", "name": "args"} + ] + } + ] + , [ "stage" + , { "type": "join" + , "separator": "/" + , "$1": {"type": "FIELD", "name": "stage"} + } + ] + ] + , "body": {"type": "CALL_EXPRESSION", "name": "pkgconfig result"} + } + } +} diff --git a/rules/CC/proto/EXPRESSIONS b/rules/CC/proto/EXPRESSIONS index 1ab17a5..d2705f1 100644 --- a/rules/CC/proto/EXPRESSIONS +++ b/rules/CC/proto/EXPRESSIONS @@ -1,4 +1,81 @@ -{ "protoc-deps": +{ "default-PROTOC": + { "vars": ["defaults-transition"] + , "imports": {"list_provider": ["./", "../..", "field_list_provider"]} + , "expression": + { "type": "let*" + , "bindings": + [ ["fieldname", "proto-defaults"] + , ["provider", "PROTOC"] + , [ "transition" + , {"type": "var", "name": "defaults-transition", "default": null} + ] + ] + , "body": {"type": "CALL_EXPRESSION", "name": "list_provider"} + } + } +, "default-LDFLAGS": + { "vars": ["defaults-transition"] + , "imports": {"list_provider": ["./", "../..", "field_list_provider"]} + , "expression": + { "type": "let*" + , "bindings": + [ ["fieldname", "proto-defaults"] + , ["provider", "LDFLAGS"] + , [ "transition" + , {"type": "var", "name": "defaults-transition", "default": null} + ] + ] + , "body": {"type": "CALL_EXPRESSION", "name": "list_provider"} + } + } +, "default-GRPC_PLUGIN": + { "vars": ["defaults-transition"] + , "imports": {"list_provider": ["./", "../..", "field_list_provider"]} + , "expression": + { "type": "let*" + , "bindings": + [ ["fieldname", "proto-defaults"] + , ["provider", "GRPC_PLUGIN"] + , [ "transition" + , {"type": "var", "name": "defaults-transition", "default": null} + ] + ] + , "body": {"type": "CALL_EXPRESSION", "name": "list_provider"} + } + } +, "default-ENV": + { "vars": ["defaults-transition"] + , "imports": {"map_provider": ["./", "../..", "field_map_provider"]} + , "expression": + { "type": "let*" + , "bindings": + [ ["fieldname", "proto-defaults"] + , ["provider", "ENV"] + , [ "transition" + , {"type": "var", "name": "defaults-transition", "default": null} + ] + , ["default", {"type": "empty_map"}] + ] + , "body": {"type": "CALL_EXPRESSION", "name": "map_provider"} + } + } +, "default-TOOLCHAIN": + { "vars": ["defaults-transition"] + , "imports": {"map_provider": ["./", "../..", "field_map_provider"]} + , "expression": + { "type": "let*" + , "bindings": + [ ["fieldname", "proto-defaults"] + , ["provider", "TOOLCHAIN"] + , [ "transition" + , {"type": "var", "name": "defaults-transition", "default": null} + ] + , ["default", {"type": "empty_map"}] + ] + , "body": {"type": "CALL_EXPRESSION", "name": "map_provider"} + } + } +, "protoc-deps": { "imports": {"map_provider": ["./", "../..", "field_map_provider"]} , "expression": { "type": "let*" @@ -16,57 +93,66 @@ , "name" , "stage" , "service support" - , "deps-transition" , "public-fieldnames" , "private-fieldnames" ] , "imports": { "stage": ["", "stage_singleton_field"] , "result": ["./", "..", "lib result"] - , "artifacts": ["./", "../..", "field_artifacts"] + , "runfiles": ["./", "../..", "field_runfiles"] , "artifacts_list": ["./", "../..", "field_artifacts_list"] , "protoc-deps": "protoc-deps" + , "default-PROTOC": "default-PROTOC" + , "default-LDFLAGS": "default-LDFLAGS" + , "default-GRPC_PLUGIN": "default-GRPC_PLUGIN" + , "default-ENV": "default-ENV" + , "default-TOOLCHAIN": "default-TOOLCHAIN" } , "expression": { "type": "let*" , "bindings": [ ["pure C", false] - , [ "protoc" - , { "type": "let*" - , "bindings": - [ ["fieldname", "protoc"] - , ["transition", {"type": "var", "name": "deps-transition"}] - , ["location", "protoc"] - ] - , "body": {"type": "CALL_EXPRESSION", "name": "stage"} - } - ] - , [ "grpc_cpp_plugin" + , ["TOOLCHAIN_DIR", "toolchain"] + , ["TOOLCHAIN", {"type": "CALL_EXPRESSION", "name": "default-TOOLCHAIN"}] + , [ "TOOLCHAIN" , { "type": "if" - , "cond": {"type": "var", "name": "service support"} + , "cond": {"type": "var", "name": "TOOLCHAIN"} , "then": - { "type": "let*" - , "bindings": - [ ["fieldname", "grpc_cpp_plugin"] - , ["transition", {"type": "var", "name": "deps-transition"}] - , ["location", "grpc_cpp_plugin"] + { "type": "to_subdir" + , "subdir": {"type": "var", "name": "TOOLCHAIN_DIR"} + , "$1": {"type": "var", "name": "TOOLCHAIN"} + } + } + ] + , [ "PROTOC" + , { "type": "join" + , "$1": + { "type": "++" + , "$1": + [ { "type": "if" + , "cond": {"type": "var", "name": "TOOLCHAIN"} + , "then": ["./", {"type": "var", "name": "TOOLCHAIN_DIR"}, "/"] + } + , {"type": "CALL_EXPRESSION", "name": "default-PROTOC"} ] - , "body": {"type": "CALL_EXPRESSION", "name": "stage"} } - , "else": {"type": "empty_map"} } ] - , ["protoc-deps", {"type": "CALL_EXPRESSION", "name": "protoc-deps"}] - , [ "proto deps" - , { "type": "to_subdir" - , "subdir": "work" + , [ "GRPC_PLUGIN" + , { "type": "join" , "$1": - { "type": "let*" - , "bindings": [["fieldname", "well_known_protos"]] - , "body": {"type": "CALL_EXPRESSION", "name": "artifacts"} + { "type": "++" + , "$1": + [ { "type": "if" + , "cond": {"type": "var", "name": "TOOLCHAIN"} + , "then": ["./", {"type": "var", "name": "TOOLCHAIN_DIR"}, "/"] + } + , {"type": "CALL_EXPRESSION", "name": "default-GRPC_PLUGIN"} + ] } } ] + , ["protoc-deps", {"type": "CALL_EXPRESSION", "name": "protoc-deps"}] , [ "proto srcs" , { "type": "disjoint_map_union" , "msg": "Sources may not conflict" @@ -139,12 +225,20 @@ , [ "cmd" , { "type": "++" , "$1": - [ ["./protoc", "--proto_path=work", "--cpp_out=work"] + [ [ {"type": "var", "name": "PROTOC"} + , "--proto_path=work" + , "--cpp_out=work" + ] , { "type": "if" , "cond": {"type": "var", "name": "service support"} , "then": [ "--grpc_out=work" - , "--plugin=protoc-gen-grpc=./grpc_cpp_plugin" + , { "type": "join" + , "$1": + [ "--plugin=protoc-gen-grpc=" + , {"type": "var", "name": "GRPC_PLUGIN"} + ] + } ] , "else": [] } @@ -158,9 +252,7 @@ { "type": "map_union" , "$1": [ {"type": "var", "name": "staged all proto srcs"} - , {"type": "var", "name": "protoc"} - , {"type": "var", "name": "grpc_cpp_plugin"} - , {"type": "var", "name": "proto deps"} + , {"type": "var", "name": "TOOLCHAIN"} ] } , "outs": {"type": "var", "name": "outs"} @@ -299,8 +391,10 @@ } ] , ["cflags", []] - , ["private-cflags", ["-Wno-sign-conversion", "-Wno-unused-function"]] - , ["private-ldflags", []] + , ["private-cflags", []] + , [ "private-ldflags" + , {"type": "CALL_EXPRESSION", "name": "default-LDFLAGS"} + ] ] , "body": {"type": "CALL_EXPRESSION", "name": "result"} } diff --git a/rules/CC/proto/RULES b/rules/CC/proto/RULES index af484b0..97b4367 100644 --- a/rules/CC/proto/RULES +++ b/rules/CC/proto/RULES @@ -1,4 +1,186 @@ -{ "library": +{ "defaults": + { "doc": + [ "A rule to provide protoc/GRPC defaults." + , "Used to implement [\"CC/proto\", \"defaults\"] for CC proto libraries" + , "and [\"CC/proto\", \"service defaults\"] for CC proto service libraries" + , "(GRPC)." + ] + , "target_fields": ["base", "toolchain", "deps"] + , "string_fields": + ["PROTOC", "LDFLAGS", "ADD_LDFLAGS", "GRPC_PLUGIN", "PATH"] + , "config_vars": ["ARCH", "HOST_ARCH"] + , "field_doc": + { "base": + [ "Other targets (using the same rule) to inherit values from. If" + , "multiple targets are specified, for values that are overwritten (see" + , "documentation of other fields) the last specified value wins." + ] + , "toolchain": + [ "Optional toolchain directory. A collection of artifacts that provide" + , "the protobuf compiler and the GRPC plugin (if needed). Note that only" + , "artifacts of the specified targets are considered (no runfiles etc.)." + , "Specifying this field overlays artifacts from \"base\"." + ] + , "deps": + [ "Optional CC libraries the resulting CC proto libraries implicitly" + , "depend on. Those are typically \"libprotobuf\" for CC proto libraries" + , "and \"libgrpc++\" for CC proto service libraries. Specifying this" + , "field extends dependencies from \"base\"." + ] + , "PROTOC": + [ "The proto compiler. If \"toolchain\" is empty, this field's value is" + , "considered the proto compiler name that is looked up in \"PATH\". If" + , "\"toolchain\" is non-empty, this field's value is assumed to be the" + , "relative path to the proto compiler in \"toolchain\". Specifying this" + , "field overwrites values from \"base\"." + ] + , "GRPC_PLUGIN": + [ "The GRPC plugin for the proto compiler. If \"toolchain\" is empty," + , "this field's value is considered to be the absolute system path to the" + , "plugin. If \"toolchain\" is non-empty, this field's value is assumed" + , "to be the relative path to the plugin in \"toolchain\". Specifying" + , "this field overwrites values from \"base\"." + ] + , "LDFLAGS": + [ "Linker flags for linking the final CC library. Specifying this field" + , "overwrites values from \"base\"." + ] + , "ADD_LDFLAGS": + [ "Additional linker flags for linking the final CC library. Specifying" + , "this field extends values from \"base\"." + ] + , "PATH": + [ "Path for looking up the proto compiler. Individual paths are joined" + , "with \":\"." + ] + } + , "imports": + { "base-provides": ["./", "..", "defaults-base-provides"] + , "artifacts": ["", "field_artifacts"] + , "compile-deps": ["CC", "compile-deps"] + , "compile-args-deps": ["CC", "compile-args-deps"] + , "link-deps": ["CC", "link-deps"] + , "link-args-deps": ["CC", "link-args-deps"] + , "cflags-files-deps": ["CC", "cflags-files-deps"] + , "ldflags-files-deps": ["CC", "ldflags-files-deps"] + , "for host": ["transitions", "for host"] + } + , "config_transitions": + {"toolchain": [{"type": "CALL_EXPRESSION", "name": "for host"}]} + , "expression": + { "type": "let*" + , "bindings": + [ ["PROTOC", {"type": "FIELD", "name": "PROTOC"}] + , ["LDFLAGS", {"type": "FIELD", "name": "LDFLAGS"}] + , ["GRPC_PLUGIN", {"type": "FIELD", "name": "GRPC_PLUGIN"}] + , ["PATH", {"type": "FIELD", "name": "PATH"}] + , ["provider", "PROTOC"] + , [ "PROTOC" + , { "type": "if" + , "cond": {"type": "var", "name": "PROTOC"} + , "then": {"type": "var", "name": "PROTOC"} + , "else": {"type": "CALL_EXPRESSION", "name": "base-provides"} + } + ] + , ["provider", "LDFLAGS"] + , [ "LDFLAGS" + , { "type": "if" + , "cond": {"type": "var", "name": "LDFLAGS"} + , "then": {"type": "var", "name": "LDFLAGS"} + , "else": {"type": "CALL_EXPRESSION", "name": "base-provides"} + } + ] + , ["provider", "GRPC_PLUGIN"] + , [ "GRPC_PLUGIN" + , { "type": "if" + , "cond": {"type": "var", "name": "GRPC_PLUGIN"} + , "then": {"type": "var", "name": "GRPC_PLUGIN"} + , "else": {"type": "CALL_EXPRESSION", "name": "base-provides"} + } + ] + , ["provider", "ENV"] + , [ "ENV" + , { "type": "if" + , "cond": {"type": "var", "name": "PATH"} + , "then": + { "type": "singleton_map" + , "key": "PATH" + , "value": + { "type": "join" + , "separator": ":" + , "$1": {"type": "var", "name": "PATH"} + } + } + , "else": {"type": "CALL_EXPRESSION", "name": "base-provides"} + } + ] + , ["provider", "TOOLCHAIN"] + , ["default", {"type": "empty_map"}] + , [ "TOOLCHAIN" + , { "type": "map_union" + , "$1": + [ {"type": "CALL_EXPRESSION", "name": "base-provides"} + , { "type": "if" + , "cond": {"type": "FIELD", "name": "toolchain"} + , "then": + { "type": "let*" + , "bindings": + [ ["fieldname", "toolchain"] + , [ "transition" + , {"type": "CALL_EXPRESSION", "name": "for host"} + ] + ] + , "body": {"type": "CALL_EXPRESSION", "name": "artifacts"} + } + , "else": {"type": "empty_map"} + } + ] + } + ] + , [ "LDFLAGS" + , { "type": "++" + , "$1": + [ {"type": "var", "name": "LDFLAGS"} + , {"type": "FIELD", "name": "ADD_LDFLAGS"} + ] + } + ] + , ["deps-fieldnames", ["base", "deps"]] + , ["compile-deps", {"type": "CALL_EXPRESSION", "name": "compile-deps"}] + , [ "compile-args" + , {"type": "CALL_EXPRESSION", "name": "compile-args-deps"} + ] + , ["link-deps", {"type": "CALL_EXPRESSION", "name": "link-deps"}] + , ["link-args", {"type": "CALL_EXPRESSION", "name": "link-args-deps"}] + , [ "cflags-files" + , {"type": "CALL_EXPRESSION", "name": "cflags-files-deps"} + ] + , [ "ldflags-files" + , {"type": "CALL_EXPRESSION", "name": "ldflags-files-deps"} + ] + , ["package", {"type": "env", "vars": ["cflags-files", "ldflags-files"]}] + ] + , "body": + { "type": "RESULT" + , "provides": + { "type": "env" + , "vars": + [ "PROTOC" + , "LDFLAGS" + , "GRPC_PLUGIN" + , "ENV" + , "TOOLCHAIN" + , "compile-deps" + , "compile-args" + , "link-deps" + , "link-args" + , "package" + ] + } + } + } + } +, "library": { "doc": [ "A library C++ library, generated from proto files." , "" @@ -7,20 +189,10 @@ ] , "string_fields": ["name", "stage"] , "target_fields": ["srcs", "deps"] - , "config_vars": - ["OS", "ARCH", "HOST_ARCH", "CXX", "CFLAGS", "ADD_CFLAGS", "AR", "ENV"] + , "config_vars": ["CXX", "CXXFLAGS", "ADD_CXXFLAGS", "AR", "ENV"] , "implicit": - { "protoc": [["@", "protoc", "", "protoc"]] - , "defaults": [["./", "..", "defaults"]] - , "proto-deps": [["@", "protoc", "", "C++ runtime"]] - , "well_known_protos": [["@", "protoc", "", "well_known_protos"]] - } - , "imports": - { "protoc-compile": "protoc-compile" - , "host transition": ["transitions", "for host"] - } - , "config_transitions": - {"protoc": [{"type": "CALL_EXPRESSION", "name": "host transition"}]} + {"defaults": [["./", "..", "defaults"]], "proto-defaults": ["defaults"]} + , "imports": {"protoc-compile": "protoc-compile"} , "expression": { "type": "let*" , "bindings": @@ -31,11 +203,8 @@ , "$1": {"type": "FIELD", "name": "stage"} } ] - , [ "deps-transition" - , {"type": "CALL_EXPRESSION", "name": "host transition"} - ] - , ["public-fieldnames", ["deps", "proto-deps"]] - , ["private-fieldnames", ["deps", "proto-deps"]] + , ["public-fieldnames", ["deps"]] + , ["private-fieldnames", ["deps", "proto-defaults"]] ] , "body": {"type": "CALL_EXPRESSION", "name": "protoc-compile"} } @@ -49,28 +218,12 @@ ] , "string_fields": ["name", "stage"] , "target_fields": ["srcs", "deps"] - , "config_vars": - ["OS", "ARCH", "HOST_ARCH", "CXX", "CXXFLAGS", "ADD_CXXFLAGS", "AR", "ENV"] + , "config_vars": ["CXX", "CXXFLAGS", "ADD_CXXFLAGS", "AR", "ENV"] , "implicit": - { "protoc": [["@", "protoc", "", "protoc"]] - , "grpc_cpp_plugin": [["@", "grpc", "src/compiler", "grpc_cpp_plugin"]] - , "defaults": [["./", "..", "defaults"]] - , "proto-deps": - [ ["@", "grpc", "", "grpc++_codegen_proto"] - , ["@", "grpc", "", "grpc++_codegen_base_src"] - , ["@", "protoc", "", "C++ runtime"] - ] - , "well_known_protos": [["@", "protoc", "", "well_known_protos"]] - } - , "imports": - { "protoc-compile": "protoc-compile" - , "host transition": ["transitions", "for host"] - } - , "config_transitions": - { "protoc": [{"type": "CALL_EXPRESSION", "name": "host transition"}] - , "grpc_cpp_plugin": - [{"type": "CALL_EXPRESSION", "name": "host transition"}] + { "defaults": [["./", "..", "defaults"]] + , "proto-defaults": ["service defaults"] } + , "imports": {"protoc-compile": "protoc-compile"} , "expression": { "type": "let*" , "bindings": @@ -82,11 +235,8 @@ , "$1": {"type": "FIELD", "name": "stage"} } ] - , [ "deps-transition" - , {"type": "CALL_EXPRESSION", "name": "host transition"} - ] - , ["public-fieldnames", ["deps", "proto-deps"]] - , ["private-fieldnames", ["deps", "proto-deps"]] + , ["public-fieldnames", ["deps", "proto-defaults"]] + , ["private-fieldnames", ["deps", "proto-defaults"]] ] , "body": {"type": "CALL_EXPRESSION", "name": "protoc-compile"} } diff --git a/rules/CC/proto/TARGETS b/rules/CC/proto/TARGETS new file mode 100644 index 0000000..45ef759 --- /dev/null +++ b/rules/CC/proto/TARGETS @@ -0,0 +1,13 @@ +{ "defaults": + { "type": ["CC/proto", "defaults"] + , "PROTOC": ["protoc"] + , "LDFLAGS": ["-lprotobuf"] + , "PATH": ["/bin", "/usr/bin"] + } +, "service defaults": + { "type": ["CC/proto", "defaults"] + , "base": ["defaults"] + , "GRPC_PLUGIN": ["/usr/bin/grpc_cpp_plugin"] + , "ADD_LDFLAGS": ["-lgrpc++", "-lgrpc", "-lgpr"] + } +} |