summaryrefslogtreecommitdiff
path: root/etc
diff options
context:
space:
mode:
authorOliver Reiche <oliver.reiche@huawei.com>2023-04-14 16:35:17 +0200
committerKlaus Aehlig <klaus.aehlig@huawei.com>2023-04-18 12:44:10 +0200
commit78ffc7f9d2a22f53971e63c489da3c28ade1937f (patch)
treea5c39be5e38fb62597b3e5ed6d0302724a4819ff /etc
parent3ef4130f79c167ceacc8d350b51e005ff4ef8b07 (diff)
downloadjustbuild-78ffc7f9d2a22f53971e63c489da3c28ade1937f.tar.gz
imports: Fix GRPC dependencies
... as the BUILD.bazel files that are the basis for the TARGETS files seen to declare the dependencies in an incomplete way. Target `grpc_base_c` needs `grpc_init()` and `grpc_shutdown()` from target `grpc` (source `init.cc`). Adding this target dependency results in a cycle. This commit solves the issue by producing fewer but larger libraries (as done in GRPC's CMakeLists.txt): - `libgpr.a`: all gpr code - `libgrpc.a`: all gprc code, depending on `libgpr.a` - `libgrpc++.a`: all grpc++ code, depending on `libgrpc.a`
Diffstat (limited to 'etc')
-rw-r--r--etc/import/RULES.grpc212
-rw-r--r--etc/import/TARGETS.grpc31
-rw-r--r--etc/repos.json1
3 files changed, 235 insertions, 9 deletions
diff --git a/etc/import/RULES.grpc b/etc/import/RULES.grpc
new file mode 100644
index 00000000..195d3e25
--- /dev/null
+++ b/etc/import/RULES.grpc
@@ -0,0 +1,212 @@
+{ "combined lib":
+ { "doc": ["Combine multiple static libraries into a single one."]
+ , "target_fields": ["deps"]
+ , "string_fields": ["name", "stage"]
+ , "config_vars": ["AR", "ENV"]
+ , "implicit": {"defaults": [["@", "rules", "CC", "defaults"]]}
+ , "field_doc":
+ { "name":
+ ["The name of the library (without leading \"lib\" or trailing \".a\")."]
+ , "deps": ["All libraries (includes transitive) that should be combined."]
+ , "stage":
+ [ "The logical location of all public headers and the resulting library"
+ , "file. Individual directory components are joined with \"/\"."
+ ]
+ }
+ , "config_doc":
+ { "AR":
+ [ "The archive tool to used for creating the library. If None, the"
+ , "respective value from [\"@\", \"rules\", \"CC\", \"defaults\"] will"
+ , "be taken."
+ ]
+ , "ENV": ["The environment for any action generated."]
+ }
+ , "imports":
+ { "compile-deps": ["@", "rules", "CC", "compile-deps"]
+ , "compile-args-deps": ["@", "rules", "CC", "compile-args-deps"]
+ , "link-deps": ["@", "rules", "CC", "link-deps"]
+ , "link-args-deps": ["@", "rules", "CC", "link-args-deps"]
+ , "cflags-files-deps": ["@", "rules", "CC", "cflags-files-deps"]
+ , "ldflags-files-deps": ["@", "rules", "CC", "ldflags-files-deps"]
+ , "default-AR": ["@", "rules", "CC", "default-AR"]
+ }
+ , "expression":
+ { "type": "let*"
+ , "bindings":
+ [ [ "AR"
+ , { "type": "var"
+ , "name": "AR"
+ , "default": {"type": "CALL_EXPRESSION", "name": "default-AR"}
+ }
+ ]
+ , ["name", {"type": "join", "$1": {"type": "FIELD", "name": "name"}}]
+ , [ "stage"
+ , { "type": "join"
+ , "separator": "/"
+ , "$1": {"type": "FIELD", "name": "stage"}
+ }
+ ]
+ , [ "libname"
+ , { "type": "join"
+ , "$1": ["lib", {"type": "var", "name": "name"}, ".a"]
+ }
+ ]
+ , [ "libpath"
+ , { "type": "if"
+ , "cond": {"type": "var", "name": "stage"}
+ , "then":
+ { "type": "join"
+ , "separator": "/"
+ , "$1":
+ [ {"type": "var", "name": "stage"}
+ , {"type": "var", "name": "libname"}
+ ]
+ }
+ , "else": {"type": "var", "name": "libname"}
+ }
+ ]
+ , ["deps-fieldnames", ["deps"]]
+ , ["compile-deps", {"type": "CALL_EXPRESSION", "name": "compile-deps"}]
+ , [ "compile-args"
+ , {"type": "CALL_EXPRESSION", "name": "compile-args-deps"}
+ ]
+ , ["unstaged libs", {"type": "CALL_EXPRESSION", "name": "link-deps"}]
+ , [ "libs"
+ , { "type": "to_subdir"
+ , "subdir": "libs"
+ , "$1": {"type": "var", "name": "unstaged libs"}
+ }
+ ]
+ , ["link-deps", {"type": "empty_map"}]
+ , [ "link-args-deps"
+ , {"type": "CALL_EXPRESSION", "name": "link-args-deps"}
+ ]
+ , [ "non-lib-link-args-deps"
+ , { "type": "++"
+ , "$1":
+ { "type": "foreach"
+ , "var": "arg"
+ , "range": {"type": "var", "name": "link-args-deps"}
+ , "body":
+ { "type": "if"
+ , "cond":
+ { "type": "lookup"
+ , "map": {"type": "var", "name": "unstaged libs"}
+ , "key": {"type": "var", "name": "arg"}
+ }
+ , "then": []
+ , "else": [{"type": "var", "name": "arg"}]
+ }
+ }
+ }
+ ]
+ , [ "link-args"
+ , { "type": "++"
+ , "$1":
+ [ [{"type": "var", "name": "libpath"}]
+ , {"type": "var", "name": "non-lib-link-args-deps"}
+ ]
+ }
+ ]
+ , [ "ldflags-files"
+ , {"type": "CALL_EXPRESSION", "name": "ldflags-files-deps"}
+ ]
+ , [ "cflags-files"
+ , {"type": "CALL_EXPRESSION", "name": "cflags-files-deps"}
+ ]
+ , [ "package"
+ , { "type": "let*"
+ , "bindings": [["name", {"type": "var", "name": "name"}]]
+ , "body":
+ {"type": "env", "vars": ["name", "cflags-files", "ldflags-files"]}
+ }
+ ]
+ , [ "combine.sh"
+ , { "type": "singleton_map"
+ , "key": "combine.sh"
+ , "value":
+ { "type": "BLOB"
+ , "data":
+ { "type": "join"
+ , "separator": "\n"
+ , "$1":
+ [ "set -eu"
+ , "readonly ROOT=$(pwd)"
+ , "readonly AR=$1"
+ , "readonly OUT=$2"
+ , "shift 2"
+ , "for l in $@; do"
+ , " OUTDIR=${ROOT}/objs/$l"
+ , " mkdir -p $OUTDIR"
+ , " cd $OUTDIR"
+ , " $AR -t $ROOT/$l | sort | uniq -c | sed -e 's/^\\s*//' > obj.list"
+ , " NUM=$(wc -l obj.list | cut -d' ' -f1)"
+ , " for o in $(seq 1 $NUM); do"
+ , " CNT=$(sed ''$o'q;d' obj.list | cut -d' ' -f1)"
+ , " OBJ=$(sed ''$o'q;d' obj.list | cut -d' ' -f2)"
+ , " for i in $(seq 1 $CNT); do"
+ , " mkdir -p $i"
+ , " $AR -xN $i $ROOT/$l $OBJ"
+ , " mv *.o $i/"
+ , " done"
+ , " done"
+ , " cd - >/dev/null"
+ , " $AR -qc $OUT $OUTDIR/*/*.o"
+ , "done"
+ , "$AR s $OUT"
+ ]
+ }
+ }
+ }
+ ]
+ , [ "combined lib"
+ , { "type": "ACTION"
+ , "outs": [{"type": "var", "name": "libname"}]
+ , "inputs":
+ { "type": "disjoint_map_union"
+ , "$1":
+ [ {"type": "var", "name": "libs"}
+ , {"type": "var", "name": "combine.sh"}
+ ]
+ }
+ , "cmd":
+ { "type": "++"
+ , "$1":
+ [ [ "sh"
+ , "combine.sh"
+ , {"type": "var", "name": "AR"}
+ , {"type": "var", "name": "libname"}
+ ]
+ , {"type": "keys", "$1": {"type": "var", "name": "libs"}}
+ ]
+ }
+ , "env":
+ {"type": "var", "name": "ENV", "default": {"type": "empty_map"}}
+ }
+ ]
+ ]
+ , "body":
+ { "type": "RESULT"
+ , "artifacts": {"type": "var", "name": "combined lib"}
+ , "provides":
+ { "type": "map_union"
+ , "$1":
+ [ { "type": "env"
+ , "vars":
+ [ "compile-deps"
+ , "compile-args"
+ , "link-deps"
+ , "link-args"
+ , "package"
+ ]
+ }
+ , { "type": "var"
+ , "name": "extra-provides"
+ , "default": {"type": "empty_map"}
+ }
+ ]
+ }
+ }
+ }
+ }
+}
diff --git a/etc/import/TARGETS.grpc b/etc/import/TARGETS.grpc
index baadd06a..ce60ec3d 100644
--- a/etc/import/TARGETS.grpc
+++ b/etc/import/TARGETS.grpc
@@ -92,11 +92,13 @@
, ["@", "absl", "absl/time", "time"]
]
}
+, "gpr_combined":
+ {"type": "combined lib", "name": ["gpr"], "deps": ["gpr_base"]}
, "gpr_internal":
{ "type": ["@", "rules", "CC", "library"]
, "name": ["gpr"]
, "hdrs": [["./", "include/grpc", "gpr_public_headers"]]
- , "deps": ["gpr_base"]
+ , "deps": ["gpr_combined"]
}
, "atomic":
{ "type": ["@", "rules", "CC", "library"]
@@ -1416,9 +1418,9 @@
, "grpc_server_backward_compatibility"
]
}
-, "grpc_internal":
+, "grpc_main":
{ "type": ["@", "rules", "CC", "library"]
- , "name": ["grpc"]
+ , "name": ["grpc_main"]
, "srcs":
[ "src/core/lib/surface/init.cc"
, "src/core/plugin_registry/grpc_plugin_registry.cc"
@@ -1440,6 +1442,13 @@
, "grpc_transport_chttp2_server_secure"
]
}
+, "grpc_combined":
+ {"type": "combined lib", "name": ["grpc"], "deps": ["grpc_main"]}
+, "grpc_internal":
+ { "type": ["@", "rules", "CC", "library"]
+ , "name": ["grpc"]
+ , "deps": ["grpc_combined", "gpr"]
+ }
, "grpc++_sources":
{ "type": ["@", "rules", "data", "staged"]
, "srcs":
@@ -1541,9 +1550,9 @@
, "grpc_health_upb"
]
}
-, "grpc++internal":
+, "grpc++_main":
{ "type": ["@", "rules", "CC", "library"]
- , "name": ["grpc++"]
+ , "name": ["grpc++_main"]
, "srcs":
[ "src/cpp/client/insecure_credentials.cc"
, "src/cpp/client/secure_credentials.cc"
@@ -1564,15 +1573,19 @@
, "src/cpp/server/secure_server_credentials.h"
]
, "deps":
- [ "gpr"
- , "grpc"
- , "grpc++_base"
+ [ "grpc++_base"
, "grpc++_codegen_base"
, "grpc++_codegen_base_src"
, "grpc++_codegen_proto"
- , "grpc_secure"
]
}
+, "grpc++combined":
+ {"type": "combined lib", "name": ["grpc++"], "deps": ["grpc++_main"]}
+, "grpc++internal":
+ { "type": ["@", "rules", "CC", "library"]
+ , "name": ["grpc++"]
+ , "deps": ["grpc++combined", "grpc"]
+ }
, "grpc++":
{ "type": "export"
, "target": "grpc++internal"
diff --git a/etc/repos.json b/etc/repos.json
index a2ce0aca..f3dbad6e 100644
--- a/etc/repos.json
+++ b/etc/repos.json
@@ -366,6 +366,7 @@
}
, "target_root": "import targets"
, "target_file_name": "TARGETS.grpc"
+ , "rule_file_name": "RULES.grpc"
, "bindings":
{ "rules": "rules-grpc"
, "protobuf": "protobuf"