treewide: migrate external rules to bzlmod
This is a huge one as it was very annoying to migrate them separately. This migrates rules_go, gazelle, rust_rust, protobuf to bzlmod
Change-Id: If39591d43ed4c2afa2979ee5915e9d1cfa1574a9
Reviewed-on: https://review.monogon.dev/c/monogon/+/3234
Tested-by: Jenkins CI
Reviewed-by: Leopold Schabel <leo@monogon.tech>
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
diff --git a/third_party/gazelle/add-prepatching.patch b/third_party/gazelle/add-prepatching.patch
index fc409a1..fe2d31a 100644
--- a/third_party/gazelle/add-prepatching.patch
+++ b/third_party/gazelle/add-prepatching.patch
@@ -1,15 +1,15 @@
-From f784d39b50b36ca06fbe844e2b09cbd996747577 Mon Sep 17 00:00:00 2001
-From: Lorenz Brun <lorenz@monogon.tech>
-Date: Thu, 31 Aug 2023 15:52:06 +0200
+From 914eedf51a7d636caa14c09554d1cf26fd87cb05 Mon Sep 17 00:00:00 2001
+From: Tim Windelschmidt <tim@monogon.tech>
+Date: Wed, 17 Jul 2024 18:27:41 +0200
Subject: [PATCH] Add support for prepatching
---
- internal/bzlmod/go_deps.bzl | 8 ++++++++
- internal/go_repository.bzl | 10 ++++++++++
- 2 files changed, 18 insertions(+)
+ internal/bzlmod/go_deps.bzl | 13 +++++++++++++
+ internal/go_repository.bzl | 10 +++++++++-
+ 2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/internal/bzlmod/go_deps.bzl b/internal/bzlmod/go_deps.bzl
-index e304ec5..7684243 100644
+index e304ec5..778f3c3 100644
--- a/internal/bzlmod/go_deps.bzl
+++ b/internal/bzlmod/go_deps.bzl
@@ -156,6 +156,9 @@ def _get_build_extra_args(path, gazelle_overrides, gazelle_default_attributes):
@@ -22,7 +22,23 @@
def _get_patch_args(path, module_overrides):
override = _get_override_or_default(module_overrides, struct(), {}, path, None, "patch_strip")
return ["-p{}".format(override)] if override else []
-@@ -605,6 +608,7 @@ def _go_deps_impl(module_ctx):
+@@ -232,6 +235,7 @@ def _process_gazelle_override(gazelle_override_tag):
+ def _process_module_override(module_override_tag):
+ return struct(
+ patches = module_override_tag.patches,
++ pre_patches = module_override_tag.pre_patches,
+ patch_strip = module_override_tag.patch_strip,
+ )
+
+@@ -240,6 +244,7 @@ def _process_archive_override(archive_override_tag):
+ urls = archive_override_tag.urls,
+ sha256 = archive_override_tag.sha256,
+ strip_prefix = archive_override_tag.strip_prefix,
++ pre_patches = archive_override_tag.pre_patches,
+ patches = archive_override_tag.patches,
+ patch_strip = archive_override_tag.patch_strip,
+ )
+@@ -605,6 +610,7 @@ def _go_deps_impl(module_ctx):
"build_directives": _get_directives(path, gazelle_overrides, gazelle_default_attributes),
"build_file_generation": _get_build_file_generation(path, gazelle_overrides, gazelle_default_attributes),
"build_extra_args": _get_build_extra_args(path, gazelle_overrides, gazelle_default_attributes),
@@ -30,7 +46,7 @@
"patches": _get_patches(path, module_overrides),
"patch_args": _get_patch_args(path, module_overrides),
"debug_mode": debug_mode,
-@@ -616,6 +620,7 @@ def _go_deps_impl(module_ctx):
+@@ -616,6 +622,7 @@ def _go_deps_impl(module_ctx):
"urls": archive_override.urls,
"strip_prefix": archive_override.strip_prefix,
"sha256": archive_override.sha256,
@@ -38,7 +54,17 @@
"patches": _get_patches(path, archive_overrides),
"patch_args": _get_patch_args(path, archive_overrides),
})
-@@ -799,6 +804,9 @@ _module_override_tag = tag_class(
+@@ -761,6 +768,9 @@ _archive_override_tag = tag_class(
+ SHA-256 sum of the downloaded archive. When set, Bazel will verify the archive
+ against this sum before extracting it.""",
+ ),
++ "pre_patches": attr.label_list(
++ doc = "A list of patches to apply to the repository before gazelle runs.",
++ ),
+ "patches": attr.label_list(
+ doc = "A list of patches to apply to the repository *after* gazelle runs.",
+ ),
+@@ -799,6 +809,9 @@ _module_override_tag = tag_class(
extension within this Bazel module.""",
mandatory = True,
),
@@ -49,7 +75,7 @@
doc = "A list of patches to apply to the repository *after* gazelle runs.",
),
diff --git a/internal/go_repository.bzl b/internal/go_repository.bzl
-index 627a1f9..4da270f 100644
+index 627a1f9..b12adf4 100644
--- a/internal/go_repository.bzl
+++ b/internal/go_repository.bzl
@@ -296,6 +296,11 @@ def _go_repository_impl(ctx):
@@ -64,15 +90,15 @@
# Repositories are fetched. Determine if build file generation is needed.
build_file_names = ctx.attr.build_file_name.split(",")
existing_build_file = ""
-@@ -583,6 +588,11 @@ go_repository = repository_rule(
+@@ -582,7 +587,10 @@ go_repository = repository_rule(
+ prefixed with `#` automatically. A common use case is to pass a list of
Gazelle directives.""",
),
-
+-
+ # Patches to apply before running gazelle.
+ "pre_patches": attr.label_list(
+ doc = "A list of patches to apply to the repository before gazelle runs.",
+ ),
-+
# Patches to apply after running gazelle.
"patches": attr.label_list(
doc = "A list of patches to apply to the repository after gazelle runs.",