Generate rules/cpp/cc_configure.WORKSPACE from distdir_deps.bzl rather than keeping it in sync by hand
This makes it possible for the versions of repositories used in the distributed Bazel tests to align with the versions used at Bazel build time without updating files scattered throughout the source and test trees.
- Add //distdir_deps.bzl%gen_workspace_stanza rule to generate WORKSPACE rules for libraries in DISTDIR_DEPS.
- Apply the new capability to rules_cc.
- move dist_http_archive from distdir_deps.bzl to distdir.bzl so that all the repository time rules are distinct from the build time rules.
This finalizes the structural changes needed for issue #12081. The remaining part is applying the same pattern for each of the dependencies.
Closes #12743.
PiperOrigin-RevId: 350527359
diff --git a/distdir.bzl b/distdir.bzl
index 60b8678..3178180 100644
--- a/distdir.bzl
+++ b/distdir.bzl
@@ -13,6 +13,9 @@
# limitations under the License.
"""Defines a repository rule that generates an archive consisting of the specified files to fetch"""
+load("//:distdir_deps.bzl", "DIST_DEPS")
+load("//tools/build_defs/repo:http.bzl", "http_archive")
+
_BUILD = """
load("@rules_pkg//:pkg.bzl", "pkg_tar")
@@ -70,3 +73,28 @@
urls = urls,
dirname = dirname,
)
+
+def dist_http_archive(name, **kwargs):
+ """Wraps http_archive but takes sha and urls from DIST_DEPS.
+
+ dist_http_archive wraps an http_archive invocation, but looks up relevant
+ information from DIST_DEPS so the user does not have to specify it. It
+ always strips sha256 and urls from kwargs.
+
+ Args:
+ name: repo name
+ **kwargs: see http_archive for allowed args.
+ """
+ info = DIST_DEPS[name]
+ if "patch_args" not in kwargs:
+ kwargs["patch_args"] = info.get("patch_args")
+ if "patches" not in kwargs:
+ kwargs["patches"] = info.get("patches")
+ if "strip_prefix" not in kwargs:
+ kwargs["strip_prefix"] = info.get("strip_prefix")
+ http_archive(
+ name = name,
+ sha256 = info["sha256"],
+ urls = info["urls"],
+ **kwargs
+ )