treewide: update rules_rust to v0.53.0

This updated our patches for rules_rust, removes a transition as it can
be replaced with the "platform" field in the rust_binary rule. This then
allows us to correctly reference it in all targets that depend on it.
Additionally the -target parameter is replaced inside the llvm-efi
toolchain with --target=.

Change-Id: Ie98753e505736c9ef28ff92fa1c5aa5b3612aec3
Reviewed-on: https://review.monogon.dev/c/monogon/+/3473
Tested-by: Jenkins CI
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
diff --git a/third_party/rules_rust/BUILD.bazel b/third_party/rules_rust/BUILD.bazel
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/third_party/rules_rust/BUILD.bazel
diff --git a/third_party/rules_rust/rust-prost-nostd.patch b/third_party/rules_rust/rust-prost-nostd.patch
new file mode 100644
index 0000000..557a7c2
--- /dev/null
+++ b/third_party/rules_rust/rust-prost-nostd.patch
@@ -0,0 +1,119 @@
+From a3a14a5fe78a5f3d366fe2d0f3fcfb9ededc587b Mon Sep 17 00:00:00 2001
+From: Lorenz Brun <lorenz@monogon.tech>
+Date: Wed, 25 Sep 2024 02:37:42 +0200
+Subject: [PATCH 2/4] Support no_std in Prost toolchain
+
+---
+ proto/prost/private/prost.bzl         |  8 ++++++++
+ proto/prost/private/protoc_wrapper.rs | 19 +++++++++++++++++--
+ 2 files changed, 25 insertions(+), 2 deletions(-)
+
+diff --git a/proto/prost/private/prost.bzl b/proto/prost/private/prost.bzl
+index cf5e11c9..61d0bc63 100644
+--- a/proto/prost/private/prost.bzl
++++ b/proto/prost/private/prost.bzl
+@@ -67,6 +67,9 @@ def _compile_proto(ctx, crate_name, proto_info, deps, prost_toolchain, rustfmt_t
+     additional_args.add("--descriptor_set={}".format(proto_info.direct_descriptor_set.path))
+     additional_args.add_all(prost_toolchain.prost_opts, format_each = "--prost_opt=%s")
+
++    if prost_toolchain.is_nostd:
++        additional_args.add("--is_nostd")
++
+     if prost_toolchain.tonic_plugin:
+         tonic_plugin = prost_toolchain.tonic_plugin[DefaultInfo].files_to_run
+         additional_args.add(prost_toolchain.tonic_plugin_flag % tonic_plugin.executable.path)
+@@ -387,6 +390,7 @@ def _rust_prost_toolchain_impl(ctx):
+         tonic_plugin_flag = ctx.attr.tonic_plugin_flag,
+         tonic_runtime = ctx.attr.tonic_runtime,
+         include_transitive_deps = ctx.attr.include_transitive_deps,
++        is_nostd = ctx.attr.is_nostd,
+     )]
+
+ rust_prost_toolchain = rule(
+@@ -442,6 +446,10 @@ rust_prost_toolchain = rule(
+             doc = "The Tonic runtime crates to use.",
+             providers = [[rust_common.crate_info], [rust_common.crate_group_info]],
+         ),
++        "is_nostd": attr.bool(
++            doc = "If a no_std tag should be put into the generated code.",
++            default = False,
++        ),
+     }, **proto_toolchains.if_legacy_toolchain({
+         "_legacy_proto_toolchain": attr.label(
+             default = "//proto/protobuf:legacy_proto_toolchain",
+diff --git a/proto/prost/private/protoc_wrapper.rs b/proto/prost/private/protoc_wrapper.rs
+index ff4decd4..2c32ea35 100644
+--- a/proto/prost/private/protoc_wrapper.rs
++++ b/proto/prost/private/protoc_wrapper.rs
+@@ -152,8 +152,13 @@ fn generate_lib_rs(
+     prost_outputs: &BTreeSet<PathBuf>,
+     is_tonic: bool,
+     direct_dep_crate_names: Vec<String>,
++    is_nostd: bool,
+ ) -> String {
+-    let mut contents = vec!["// @generated".to_string(), "".to_string()];
++    let mut contents = vec![
++        if is_nostd { "#![no_std]".to_string() } else { "".to_string() },
++        "// @generated".to_string(),
++        "".to_string(),
++    ];
+     for crate_name in direct_dep_crate_names {
+         contents.push(format!("pub use {crate_name};"));
+     }
+@@ -442,6 +447,9 @@ struct Args {
+     /// Whether to generate tonic code.
+     is_tonic: bool,
+
++    // Whether to put a no_std tag into the generated code.
++    is_nostd: bool,
++
+     /// Extra arguments to pass to protoc.
+     extra_args: Vec<String>,
+ }
+@@ -463,6 +471,7 @@ impl Args {
+         let mut tonic_or_prost_opts = Vec::new();
+         let mut direct_dep_crate_names = Vec::new();
+         let mut is_tonic = false;
++        let mut is_nostd = false;
+
+         let mut extra_args = Vec::new();
+
+@@ -485,6 +494,10 @@ impl Args {
+                 is_tonic = true;
+                 return;
+             }
++            if arg == "--is_nostd" {
++                is_nostd = true;
++                return;
++            }
+
+             if !arg.contains('=') {
+                 extra_args.push(arg);
+@@ -621,6 +634,7 @@ impl Args {
+             proto_paths,
+             direct_dep_crate_names,
+             is_tonic,
++            is_nostd,
+             label: label.unwrap(),
+             extra_args,
+         })
+@@ -727,6 +741,7 @@ fn main() {
+         proto_paths,
+         direct_dep_crate_names,
+         is_tonic,
++        is_nostd,
+         extra_args,
+     } = Args::parse().expect("Failed to parse args");
+
+@@ -841,7 +856,7 @@ fn main() {
+     // Write outputs
+     fs::write(
+         &out_librs,
+-        generate_lib_rs(&rust_files, is_tonic, direct_dep_crate_names),
++        generate_lib_rs(&rust_files, is_tonic, direct_dep_crate_names, is_nostd),
+     )
+     .expect("Failed to write file.");
+     fs::write(
+--
+2.44.1
+
diff --git a/third_party/rust-reproducibility.patch b/third_party/rules_rust/rust-reproducibility.patch
similarity index 100%
rename from third_party/rust-reproducibility.patch
rename to third_party/rules_rust/rust-reproducibility.patch
diff --git a/third_party/rules_rust/rust-uefi-platform.patch b/third_party/rules_rust/rust-uefi-platform.patch
new file mode 100644
index 0000000..e01cf29
--- /dev/null
+++ b/third_party/rules_rust/rust-uefi-platform.patch
@@ -0,0 +1,72 @@
+From b2d165d9b2c811293f92bf083289c97c9d87d13c Mon Sep 17 00:00:00 2001
+From: Lorenz Brun <lorenz@monogon.tech>
+Date: Wed, 25 Sep 2024 02:37:09 +0200
+Subject: [PATCH 1/4] Add support for UEFI targets and OS
+
+---
+ rust/platform/triple_mappings.bzl | 7 +++++++
+ 1 file changed, 7 insertions(+)
+
+diff --git a/rust/platform/triple_mappings.bzl b/rust/platform/triple_mappings.bzl
+index 139015da..efa9f167 100644
+--- a/rust/platform/triple_mappings.bzl
++++ b/rust/platform/triple_mappings.bzl
+@@ -47,6 +47,7 @@ SUPPORTED_T2_PLATFORM_TRIPLES = {
+     "aarch64-fuchsia": _support(std = True, host_tools = False),
+     "aarch64-linux-android": _support(std = True, host_tools = False),
+     "aarch64-pc-windows-msvc": _support(std = True, host_tools = True),
++    "aarch64-unknown-uefi": _support(std = True, host_tools = False),
+     "arm-unknown-linux-gnueabi": _support(std = True, host_tools = True),
+     "armv7-linux-androideabi": _support(std = True, host_tools = False),
+     "armv7-unknown-linux-gnueabi": _support(std = True, host_tools = True),
+@@ -65,6 +66,7 @@ SUPPORTED_T2_PLATFORM_TRIPLES = {
+     "x86_64-linux-android": _support(std = True, host_tools = False),
+     "x86_64-unknown-freebsd": _support(std = True, host_tools = True),
+     "x86_64-unknown-none": _support(std = True, host_tools = False),
++    "x86_64-unknown-uefi": _support(std = True, host_tools = False),
+ }
+
+ _T3_PLATFORM_TRIPLES = {
+@@ -142,6 +144,7 @@ _SYSTEM_TO_BUILTIN_SYS_SUFFIX = {
+     "nto": "qnx",
+     "openbsd": "openbsd",
+     "solaris": None,
++    "uefi": "uefi",
+     "unknown": None,
+     "wasi": None,
+     "windows": "windows",
+@@ -160,6 +163,7 @@ _SYSTEM_TO_BINARY_EXT = {
+     "nixos": "",
+     "none": "",
+     "nto": "",
++    "uefi": ".efi",
+     # This is currently a hack allowing us to have the proper
+     # generated extension for the wasm target, similarly to the
+     # windows target
+@@ -181,6 +185,7 @@ _SYSTEM_TO_STATICLIB_EXT = {
+     "nixos": ".a",
+     "none": ".a",
+     "nto": ".a",
++    "uefi": ".lib",
+     "unknown": "",
+     "wasi": "",
+     "windows": ".lib",
+@@ -199,6 +204,7 @@ _SYSTEM_TO_DYLIB_EXT = {
+     "nixos": ".so",
+     "none": ".so",
+     "nto": ".a",
++    "uefi": "", # UEFI doesn't have dynamic linking
+     "unknown": ".wasm",
+     "wasi": ".wasm",
+     "windows": ".dll",
+@@ -244,6 +250,7 @@ _SYSTEM_TO_STDLIB_LINKFLAGS = {
+     "nto": [],
+     "openbsd": ["-lpthread"],
+     "solaris": ["-lsocket", "-lposix4", "-lpthread", "-lresolv"],
++    "uefi": [],
+     "unknown": [],
+     "uwp": ["ws2_32.lib"],
+     "wasi": [],
+--
+2.44.1
+
diff --git a/third_party/rust-prost-nostd.patch b/third_party/rust-prost-nostd.patch
deleted file mode 100644
index dc30a23..0000000
--- a/third_party/rust-prost-nostd.patch
+++ /dev/null
@@ -1,123 +0,0 @@
-From 8b464f085c9b255d81ee0e8501914ff7cb3cadd8 Mon Sep 17 00:00:00 2001
-From: Tim Windelschmidt <tim@monogon.tech>
-Date: Fri, 12 Jan 2024 15:41:50 +0100
-Subject: [PATCH 1/2] Support no_std in Prost toolchain
-
----
- proto/prost/private/prost.bzl         |  8 ++++++++
- proto/prost/private/protoc_wrapper.rs | 17 ++++++++++++++---
- 2 files changed, 22 insertions(+), 3 deletions(-)
-
-diff --git a/proto/prost/private/prost.bzl b/proto/prost/private/prost.bzl
-index c3a7d4e0..6f7449d0 100644
---- a/proto/prost/private/prost.bzl
-+++ b/proto/prost/private/prost.bzl
-@@ -65,6 +65,9 @@ def _compile_proto(ctx, crate_name, proto_info, deps, prost_toolchain, rustfmt_t
-     additional_args.add("--descriptor_set={}".format(proto_info.direct_descriptor_set.path))
-     additional_args.add_all(prost_toolchain.prost_opts, format_each = "--prost_opt=%s")
-
-+    if prost_toolchain.is_nostd:
-+        additional_args.add("--is_nostd")
-+
-     if prost_toolchain.tonic_plugin:
-         tonic_plugin = prost_toolchain.tonic_plugin[DefaultInfo].files_to_run
-         additional_args.add(prost_toolchain.tonic_plugin_flag % tonic_plugin.executable.path)
-@@ -372,6 +375,7 @@ def _rust_prost_toolchain_impl(ctx):
-         tonic_plugin = ctx.attr.tonic_plugin,
-         tonic_plugin_flag = ctx.attr.tonic_plugin_flag,
-         tonic_runtime = ctx.attr.tonic_runtime,
-+        is_nostd = ctx.attr.is_nostd,
-     )]
-
- rust_prost_toolchain = rule(
-@@ -423,6 +427,10 @@ rust_prost_toolchain = rule(
-             doc = "The Tonic runtime crates to use.",
-             providers = [[rust_common.crate_info], [rust_common.crate_group_info]],
-         ),
-+        "is_nostd": attr.bool(
-+            doc = "If a no_std tag should be put into the generated code.",
-+            default = False,
-+        ),
-     }, **proto_toolchains.if_legacy_toolchain({
-         "_legacy_proto_toolchain": attr.label(
-             default = "//proto/protobuf:legacy_proto_toolchain",
-diff --git a/proto/prost/private/protoc_wrapper.rs b/proto/prost/private/protoc_wrapper.rs
-index 9c41892c..5d67640d 100644
---- a/proto/prost/private/protoc_wrapper.rs
-+++ b/proto/prost/private/protoc_wrapper.rs
-@@ -117,7 +117,7 @@ struct Module {
- ///     }
- /// }
- /// ```
--fn generate_lib_rs(prost_outputs: &BTreeSet<PathBuf>, is_tonic: bool) -> String {
-+fn generate_lib_rs(prost_outputs: &BTreeSet<PathBuf>, is_tonic: bool, is_nostd: bool) -> String {
-     let mut module_info = BTreeMap::new();
-
-     for path in prost_outputs.iter() {
-@@ -189,7 +189,8 @@ fn generate_lib_rs(prost_outputs: &BTreeSet<PathBuf>, is_tonic: bool) -> String
-         }
-     }
-
--    let mut content = "// @generated\n\n".to_string();
-+    let mut content = if is_nostd { "#![no_std]\n".to_string() } else { "".to_string() };
-+    content.push_str(&"// @generated\n\n");
-     write_module(&mut content, &module_info, "", 0);
-     content
- }
-@@ -443,6 +444,9 @@ struct Args {
-     /// Whether to generate tonic code.
-     is_tonic: bool,
-
-+    // Whether to put a no_std tag into the generated code.
-+    is_nostd: bool,
-+
-     /// Extra arguments to pass to protoc.
-     extra_args: Vec<String>,
- }
-@@ -463,6 +467,7 @@ impl Args {
-         let mut label: Option<String> = None;
-         let mut tonic_or_prost_opts = Vec::new();
-         let mut is_tonic = false;
-+        let mut is_nostd = false;
-
-         let mut extra_args = Vec::new();
-
-@@ -485,6 +490,10 @@ impl Args {
-                 is_tonic = true;
-                 return;
-             }
-+            if arg == "--is_nostd" {
-+                is_nostd = true;
-+                return;
-+            }
-
-             if !arg.contains('=') {
-                 extra_args.push(arg);
-@@ -613,6 +622,7 @@ impl Args {
-             rustfmt,
-             proto_paths,
-             is_tonic,
-+            is_nostd,
-             label: label.unwrap(),
-             extra_args,
-         })
-@@ -718,6 +728,7 @@ fn main() {
-         rustfmt,
-         proto_paths,
-         is_tonic,
-+        is_nostd,
-         extra_args,
-     } = Args::parse().expect("Failed to parse args");
-
-@@ -830,7 +841,7 @@ fn main() {
-         .expect("Failed to compute proto package info");
-
-     // Write outputs
--    fs::write(&out_librs, generate_lib_rs(&rust_files, is_tonic)).expect("Failed to write file.");
-+    fs::write(&out_librs, generate_lib_rs(&rust_files, is_tonic, is_nostd)).expect("Failed to write file.");
-     fs::write(
-         package_info_file,
-         extern_paths
---
-2.44.1
-
diff --git a/third_party/rust-uefi-platform.patch b/third_party/rust-uefi-platform.patch
deleted file mode 100644
index 6ca627e..0000000
--- a/third_party/rust-uefi-platform.patch
+++ /dev/null
@@ -1,71 +0,0 @@
-From 28b8651b0ccba1f41802a2aff12643b51436b32b Mon Sep 17 00:00:00 2001
-From: Lorenz Brun <lorenz@monogon.tech>
-Date: Tue, 29 Aug 2023 19:02:45 +0200
-Subject: [PATCH] Add support for UEFI targets and OS
-
----
- rust/platform/triple_mappings.bzl | 7 +++++++
- 1 file changed, 7 insertions(+)
-
-diff --git a/rust/platform/triple_mappings.bzl b/rust/platform/triple_mappings.bzl
-index 61a71c73..ce594522 100644
---- a/rust/platform/triple_mappings.bzl
-+++ b/rust/platform/triple_mappings.bzl
-@@ -27,6 +27,7 @@ SUPPORTED_T2_PLATFORM_TRIPLES = [
-     "aarch64-fuchsia",
-     "aarch64-linux-android",
-     "aarch64-pc-windows-msvc",
-+    "aarch64-unknown-uefi",
-     "arm-unknown-linux-gnueabi",
-     "armv7-linux-androideabi",
-     "armv7-unknown-linux-gnueabi",
-@@ -45,6 +46,7 @@ SUPPORTED_T2_PLATFORM_TRIPLES = [
-     "x86_64-linux-android",
-     "x86_64-unknown-freebsd",
-     "x86_64-unknown-none",
-+    "x86_64-unknown-uefi",
- ]
-
-@@ -97,6 +99,7 @@ _SYSTEM_TO_BUILTIN_SYS_SUFFIX = {
-     "nto": "qnx",
-     "openbsd": "openbsd",
-     "solaris": None,
-+    "uefi": "uefi",
-     "unknown": None,
-     "wasi": None,
-     "windows": "windows",
-@@ -113,6 +116,7 @@ _SYSTEM_TO_BINARY_EXT = {
-     "nixos": "",
-     "none": "",
-     "nto": "",
-+    "uefi": ".efi",
-     # This is currently a hack allowing us to have the proper
-     # generated extension for the wasm target, similarly to the
-     # windows target
-@@ -132,6 +136,7 @@ _SYSTEM_TO_STATICLIB_EXT = {
-     "nixos": ".a",
-     "none": ".a",
-     "nto": ".a",
-+    "uefi": ".lib",
-     "unknown": "",
-     "wasi": "",
-     "windows": ".lib",
-@@ -148,6 +153,7 @@ _SYSTEM_TO_DYLIB_EXT = {
-     "nixos": ".so",
-     "none": ".so",
-     "nto": ".a",
-+    "uefi": "", # UEFI doesn't have dynamic linking
-     "unknown": ".wasm",
-     "wasi": ".wasm",
-     "windows": ".dll",
-@@ -191,6 +197,7 @@ _SYSTEM_TO_STDLIB_LINKFLAGS = {
-     "nto": [],
-     "openbsd": ["-lpthread"],
-     "solaris": ["-lsocket", "-lposix4", "-lpthread", "-lresolv"],
-+    "uefi": [],
-     "unknown": [],
-     "uwp": ["ws2_32.lib"],
-     "wasi": [],
--- 
-2.41.0
-