treewide: bump rules_rust to 0.56.0
Change-Id: I7e1ee6f6d10d1ffe0b8e94f81b4a901f49bf818d
Reviewed-on: https://review.monogon.dev/c/monogon/+/3765
Tested-by: Jenkins CI
Reviewed-by: Leopold Schabel <leo@monogon.tech>
diff --git a/third_party/rules_rust/Add-extra_rustc_flags-to-module-extension.patch b/third_party/rules_rust/Add-extra_rustc_flags-to-module-extension.patch
deleted file mode 100644
index ef71ce4..0000000
--- a/third_party/rules_rust/Add-extra_rustc_flags-to-module-extension.patch
+++ /dev/null
@@ -1,38 +0,0 @@
-From 0504caf6aa7cf920285ba68509db5d73ff9d64a7 Mon Sep 17 00:00:00 2001
-From: Tim Windelschmidt <tim@monogon.tech>
-Date: Tue, 1 Oct 2024 16:44:53 +0200
-Subject: [PATCH] Add extra_rustc_flags to module extension
-
----
- rust/extensions.bzl | 8 ++++++++
- 1 file changed, 8 insertions(+)
-
-diff --git a/rust/extensions.bzl b/rust/extensions.bzl
-index 683d11db..250d3ad1 100644
---- a/rust/extensions.bzl
-+++ b/rust/extensions.bzl
-@@ -69,6 +69,8 @@ def _rust_impl(module_ctx):
- urls = toolchain.urls,
- versions = toolchain.versions,
- register_toolchains = False,
-+ extra_rustc_flags = toolchain.extra_rustc_flags,
-+ extra_exec_rustc_flags = toolchain.extra_exec_rustc_flags,
- )
-
- _COMMON_TAG_KWARGS = dict(
-@@ -97,6 +99,12 @@ _COMMON_TAG_KWARGS = dict(
- doc = "A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format).",
- default = DEFAULT_STATIC_RUST_URL_TEMPLATES,
- ),
-+ extra_rustc_flags = attr.string_list(
-+ default = [],
-+ ),
-+ extra_exec_rustc_flags = attr.string_list(
-+ default = [],
-+ ),
- )
-
- _RUST_TOOLCHAIN_TAG = tag_class(
---
-2.44.1
-
diff --git a/third_party/rules_rust/rust-prost-nostd.patch b/third_party/rules_rust/rust-prost-nostd.patch
index 557a7c2..28e1015 100644
--- a/third_party/rules_rust/rust-prost-nostd.patch
+++ b/third_party/rules_rust/rust-prost-nostd.patch
@@ -1,36 +1,36 @@
-From a3a14a5fe78a5f3d366fe2d0f3fcfb9ededc587b Mon Sep 17 00:00:00 2001
+From f9f2bdfd156f62c67af78ed7c0a46ae67ec148e2 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(-)
+ extensions/prost/private/prost.bzl | 8 ++++++++
+ extensions/prost/private/protoc_wrapper.rs | 18 +++++++++++++++++-
+ 2 files changed, 25 insertions(+), 1 deletion(-)
-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")
-
+diff --git a/extensions/prost/private/prost.bzl b/extensions/prost/private/prost.bzl
+index f06719db..6d9d4969 100644
+--- a/extensions/prost/private/prost.bzl
++++ b/extensions/prost/private/prost.bzl
+@@ -86,6 +86,9 @@ def _compile_proto(
+ additional_args.add("--additional_srcs={}".format(",".join([f.path for f in all_additional_srcs.to_list()])))
+ additional_args.add_all(prost_toolchain.prost_opts + 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):
+@@ -442,6 +445,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(
+@@ -497,6 +501,10 @@ rust_prost_toolchain = rule(
doc = "The Tonic runtime crates to use.",
providers = [[rust_common.crate_info], [rust_common.crate_group_info]],
),
@@ -40,45 +40,49 @@
+ ),
}, **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>,
+ default = Label("//private:legacy_proto_toolchain"),
+diff --git a/extensions/prost/private/protoc_wrapper.rs b/extensions/prost/private/protoc_wrapper.rs
+index a0403f82..1dded7aa 100644
+--- a/extensions/prost/private/protoc_wrapper.rs
++++ b/extensions/prost/private/protoc_wrapper.rs
+@@ -156,8 +156,17 @@ fn generate_lib_rs(
is_tonic: bool,
direct_dep_crate_names: Vec<String>,
+ additional_content: 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() },
++ 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 {
+@@ -457,6 +462,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 {
+@@ -479,6 +487,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 {
+
+@@ -501,6 +510,10 @@ impl Args {
is_tonic = true;
return;
}
@@ -86,10 +90,10 @@
+ is_nostd = true;
+ return;
+ }
-
+
if !arg.contains('=') {
extra_args.push(arg);
-@@ -621,6 +634,7 @@ impl Args {
+@@ -644,6 +657,7 @@ impl Args {
proto_paths,
direct_dep_crate_names,
is_tonic,
@@ -97,23 +101,22 @@
label: label.unwrap(),
extra_args,
})
-@@ -727,6 +741,7 @@ fn main() {
+@@ -748,6 +762,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),
+
+@@ -917,6 +932,7 @@ fn main() {
+ is_tonic,
+ direct_dep_crate_names,
+ additional_content,
++ is_nostd,
+ ),
)
.expect("Failed to write file.");
- fs::write(
---
-2.44.1
+--
+2.47.0
diff --git a/third_party/rules_rust/rust-reproducibility.patch b/third_party/rules_rust/rust-reproducibility.patch
index e0254f2..9b412f0 100644
--- a/third_party/rules_rust/rust-reproducibility.patch
+++ b/third_party/rules_rust/rust-reproducibility.patch
@@ -1,7 +1,7 @@
-From 544ee8b571a006a8e03eb4401f6644bb8bf6628f Mon Sep 17 00:00:00 2001
+From b05e8fb3ae3a385d5615a8e9753f4510c4ca8d79 Mon Sep 17 00:00:00 2001
From: Serge Bazanski <serge@monogon.tech>
Date: Wed, 25 Sep 2024 02:38:50 +0200
-Subject: [PATCH] Improve reproducibility
+Subject: [PATCH 3/4] Improve reproducibility
Fixes a few issues with rules_rust/rustc reproducibility when the same code is
being built in slightly different BuildConfigurations.
@@ -24,35 +24,35 @@
2. We add a remap path option to rustc that replaces bazel-out/<dir>/bin/ with
bin/.
---
- proto/prost/private/prost.bzl | 3 ++-
- proto/protobuf/proto.bzl | 2 +-
- rust/private/clippy.bzl | 2 +-
- rust/private/rust.bzl | 6 +++---
- rust/private/rustc.bzl | 4 ++++
- rust/private/utils.bzl | 7 +++++--
- 6 files changed, 16 insertions(+), 8 deletions(-)
+ extensions/prost/private/prost.bzl | 3 ++-
+ extensions/protobuf/proto.bzl | 2 +-
+ rust/private/clippy.bzl | 2 +-
+ rust/private/rust.bzl | 6 +++---
+ rust/private/rustc.bzl | 4 ++++
+ rust/private/utils.bzl | 8 ++++++--
+ 6 files changed, 17 insertions(+), 8 deletions(-)
-diff --git a/proto/prost/private/prost.bzl b/proto/prost/private/prost.bzl
-index 20814500..45b283d9 100644
---- a/proto/prost/private/prost.bzl
-+++ b/proto/prost/private/prost.bzl
-@@ -132,7 +132,8 @@ def _compile_rust(ctx, attr, crate_name, src, deps, edition):
+diff --git a/extensions/prost/private/prost.bzl b/extensions/prost/private/prost.bzl
+index 6d9d4969..8dad0961 100644
+--- a/extensions/prost/private/prost.bzl
++++ b/extensions/prost/private/prost.bzl
+@@ -164,7 +164,8 @@ def _compile_rust(
A DepVariantInfo provider.
"""
toolchain = ctx.toolchains["@rules_rust//rust:toolchain_type"]
- output_hash = repr(hash(src.path + ".prost"))
+ src_path = src.path.replace(ctx.bin_dir.path, 'bin')
+ output_hash = repr(hash(src_path + ".prost"))
-
+
lib_name = "{prefix}{name}-{lib_hash}{extension}".format(
prefix = "lib",
-diff --git a/proto/protobuf/proto.bzl b/proto/protobuf/proto.bzl
-index 959d0c1c..00dff5d0 100644
---- a/proto/protobuf/proto.bzl
-+++ b/proto/protobuf/proto.bzl
+diff --git a/extensions/protobuf/proto.bzl b/extensions/protobuf/proto.bzl
+index 56025417..7c025b11 100644
+--- a/extensions/protobuf/proto.bzl
++++ b/extensions/protobuf/proto.bzl
@@ -187,7 +187,7 @@ def _rust_proto_compile(protos, descriptor_sets, imports, crate_name, ctx, is_gr
srcs.append(lib_rs)
-
+
# And simulate rust_library behavior
- output_hash = determine_output_hash(lib_rs, ctx.label)
+ output_hash = determine_output_hash(ctx.bin_dir, lib_rs, ctx.label)
@@ -60,10 +60,10 @@
output_dir,
crate_name,
diff --git a/rust/private/clippy.bzl b/rust/private/clippy.bzl
-index 748f33a0..772b39ad 100644
+index 8c172ae0..efdba8fc 100644
--- a/rust/private/clippy.bzl
+++ b/rust/private/clippy.bzl
-@@ -131,7 +131,7 @@ def _clippy_aspect_impl(target, ctx):
+@@ -138,7 +138,7 @@ def _clippy_aspect_impl(target, ctx):
dep_info = dep_info,
linkstamp_outs = linkstamp_outs,
ambiguous_libs = ambiguous_libs,
@@ -73,7 +73,7 @@
out_dir = out_dir,
build_env_files = build_env_files,
diff --git a/rust/private/rust.bzl b/rust/private/rust.bzl
-index 21881729..24792e99 100644
+index 2717d3f5..be277010 100644
--- a/rust/private/rust.bzl
+++ b/rust/private/rust.bzl
@@ -159,7 +159,7 @@ def _rust_library_common(ctx, crate_type):
@@ -82,10 +82,10 @@
else:
- output_hash = determine_output_hash(crate_root, ctx.label)
+ output_hash = determine_output_hash(ctx.bin_dir, crate_root, ctx.label)
-
+
rust_lib_name = determine_lib_name(
crate_name,
-@@ -316,7 +316,7 @@ def _rust_test_impl(ctx):
+@@ -321,7 +321,7 @@ def _rust_test_impl(ctx):
)
else:
crate_name = crate.name
@@ -94,7 +94,7 @@
output = ctx.actions.declare_file(
"test-%s/%s%s" % (
output_hash,
-@@ -380,7 +380,7 @@ def _rust_test_impl(ctx):
+@@ -388,7 +388,7 @@ def _rust_test_impl(ctx):
ctx.label.name + toolchain.binary_ext,
)
else:
@@ -104,13 +104,13 @@
"test-%s/%s%s" % (
output_hash,
diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl
-index c82c236b..576de4e3 100644
+index 2bc6ce19..73e472f5 100644
--- a/rust/private/rustc.bzl
+++ b/rust/private/rustc.bzl
-@@ -973,6 +973,10 @@ def construct_arguments(
+@@ -972,6 +972,10 @@ def construct_arguments(
if remap_path_prefix != None:
rustc_flags.add("--remap-path-prefix=${{pwd}}={}".format(remap_path_prefix))
-
+
+ # Replace unstable bindir path (based on ST-hash which is in turn based on
+ # build configuration) with a stable bin/ path.
+ rustc_flags.add("--remap-path-prefix={}=bin".format(ctx.bin_dir.path))
@@ -119,31 +119,32 @@
for kind in emit:
if kind == "link" and crate_info.type == "bin" and crate_info.output != None:
diff --git a/rust/private/utils.bzl b/rust/private/utils.bzl
-index a0fda352..ff45a149 100644
+index 7b11c10d..41f7d2db 100644
--- a/rust/private/utils.bzl
+++ b/rust/private/utils.bzl
-@@ -188,7 +188,7 @@ def abs(value):
- return -value
- return value
-
+@@ -176,7 +176,7 @@ def get_lib_name_for_windows(lib):
+
+ return libname
+
-def determine_output_hash(crate_root, label):
+def determine_output_hash(bin_dir, crate_root, label):
"""Generates a hash of the crate root file's path.
-
+
Args:
-@@ -199,8 +199,11 @@ def determine_output_hash(crate_root, label):
+@@ -187,8 +187,12 @@ def determine_output_hash(crate_root, label):
str: A string representation of the hash.
"""
-
+
+ # Remove any unstable BuildConfiguration derived dir fragments to unify
+ # hashes between different configs.
-+ crate_root_path = crate_root.path.replace(bin_dir.path, 'bin')
++ crate_root_path = crate_root.path.replace(bin_dir.path, "bin")
++
# Take the absolute value of hash() since it could be negative.
- h = abs(hash(crate_root.path) + hash(repr(label)))
+ h = abs(hash(crate_root_path) + hash(repr(label)))
return repr(h)
-
+
def get_preferred_artifact(library_to_link, use_pic):
---
-2.44.1
+--
+2.47.0
diff --git a/third_party/rules_rust/rust-uefi-platform.patch b/third_party/rules_rust/rust-uefi-platform.patch
index e01cf29..fa906df 100644
--- a/third_party/rules_rust/rust-uefi-platform.patch
+++ b/third_party/rules_rust/rust-uefi-platform.patch
@@ -1,4 +1,4 @@
-From b2d165d9b2c811293f92bf083289c97c9d87d13c Mon Sep 17 00:00:00 2001
+From e361ea153a5ba02bfb56a5894a88418270cd05a4 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
@@ -8,34 +8,34 @@
1 file changed, 7 insertions(+)
diff --git a/rust/platform/triple_mappings.bzl b/rust/platform/triple_mappings.bzl
-index 139015da..efa9f167 100644
+index b436af3a..15fca0b2 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-fuchsia": _support(std = True, host_tools = False),
+ "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-fuchsia": _support(std = True, host_tools = False),
"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 = {
+@@ -148,6 +150,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 = {
+ "wasip1": None,
+@@ -167,6 +170,7 @@ _SYSTEM_TO_BINARY_EXT = {
"nixos": "",
"none": "",
"nto": "",
@@ -43,23 +43,23 @@
# 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 = {
+@@ -189,6 +193,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 = {
+ "wasip1": "",
+@@ -208,6 +213,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 = {
+ "wasip1": ".wasm",
+@@ -254,6 +260,7 @@ _SYSTEM_TO_STDLIB_LINKFLAGS = {
"nto": [],
"openbsd": ["-lpthread"],
"solaris": ["-lsocket", "-lposix4", "-lpthread", "-lresolv"],
@@ -67,6 +67,6 @@
"unknown": [],
"uwp": ["ws2_32.lib"],
"wasi": [],
---
-2.44.1
+--
+2.47.0