build: Roll Pigweed and rules_rust
Change-Id: I4f580db629c93587432ec0b1de5f27dfdbb598fc
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/maize/+/260335
Reviewed-by: Travis Geiselbrecht <travisg@google.com>
Presubmit-Verified: CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
Commit-Queue: Erik Gilling <konkers@google.com>
diff --git a/MODULE.bazel b/MODULE.bazel
index d743020..cfcc944 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -17,7 +17,7 @@
)
bazel_dep(name = "bazel_skylib", version = "1.7.1")
-bazel_dep(name = "rules_rust", version = "0.54.1")
+bazel_dep(name = "rules_rust", version = "0.56.0")
bazel_dep(name = "pigweed")
bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "rules_python", version = "0.40.0")
@@ -27,11 +27,12 @@
git_override(
module_name = "pigweed",
- commit = "3173ab38ddaa0617685501aba30c3b367bacc03d",
+ commit = "41b6f9ada52fb2ae5878c67c88cd5187a73f3b16",
remote = "https://pigweed.googlesource.com/pigweed/pigweed",
patch_strip = 1,
patches = [
- "//build/external:pigweed-Specify-rustc_srcs_subdir-for-rust_analyzer_tool.patch",
+ "//build/external/pigweed:0001-WIP-pw_toolchain-Support-building-Rust-libcore-from-.patch",
+ "//build/external/pigweed:0002-WIP-Specify-rustc_srcs_subdir-for-rust_analyzer_tool.patch",
],
)
@@ -39,10 +40,8 @@
module_name = "rules_rust",
patch_strip = 1,
patches = [
- # rules_rust does not contain thumbv6m and thumbv7m triples.
- "//build/external:rules_rust-add-triples.patch",
- # allows rust_analyzer to find std library sources.
- "//build/external:rules_rust-add-rust_srcs_subdir-to-rust_analyzer_toolchain.patch",
+ "//build/external/rules_rust:0001-Add-thumbv6m-and-more-thumbv7m-and-thumbv8m-triples.patch",
+ "//build/external/rules_rust:0002-Add-rust_srcs_subdir-to-rust_analyzer_toolchain.patch",
],
)
diff --git a/build/external/pigweed/0001-WIP-pw_toolchain-Support-building-Rust-libcore-from-.patch b/build/external/pigweed/0001-WIP-pw_toolchain-Support-building-Rust-libcore-from-.patch
new file mode 100644
index 0000000..dcb0487
--- /dev/null
+++ b/build/external/pigweed/0001-WIP-pw_toolchain-Support-building-Rust-libcore-from-.patch
@@ -0,0 +1,405 @@
+From 49d9c273f5e0a1bbbd6440f3175f9895a5e8b194 Mon Sep 17 00:00:00 2001
+From: Erik Gilling <konkers@google.com>
+Date: Mon, 13 Jan 2025 11:04:20 -0800
+Subject: [PATCH 1/2] WIP: pw_toolchain: Support building Rust libcore from
+ source.
+
+Change-Id: I5b8d31a13279544dc10d3fbcbb00c16a28d8db6f
+---
+ pw_toolchain/rust/BUILD.bazel | 43 ++++++++++++++++
+ pw_toolchain/rust/extensions.bzl | 60 +++++++++++++++-------
+ pw_toolchain/rust/no_stdlibs.bzl | 70 ++++++++++++++++++++++++++
+ pw_toolchain/rust/rust_toolchain.BUILD | 60 ++++++++++++++++++++++
+ pw_toolchain/rust/templates.bzl | 56 +++++++++++++++++++++
+ pw_toolchain/rust/toolchains.bzl | 3 +-
+ 6 files changed, 272 insertions(+), 20 deletions(-)
+ create mode 100644 pw_toolchain/rust/no_stdlibs.bzl
+
+diff --git a/pw_toolchain/rust/BUILD.bazel b/pw_toolchain/rust/BUILD.bazel
+index 8b13f55e3..082f6b471 100644
+--- a/pw_toolchain/rust/BUILD.bazel
++++ b/pw_toolchain/rust/BUILD.bazel
+@@ -12,6 +12,49 @@
+ # License for the specific language governing permissions and limitations under
+ # the License.
+
++load("@bazel_skylib//rules:common_settings.bzl", "string_setting")
++
+ package(default_visibility = ["//visibility:public"])
+
+ licenses(["notice"])
++
++# Setting used when building rust std libraries from scratch (core, alloc, std,
++# etc.).
++string_setting(
++ name = "stdlibs_flavor",
++ build_setting_default = "core_alloc_std",
++ visibility = ["//visibility:public"],
++)
++
++# Special set with no std libs.
++#
++# Used when building core.
++config_setting(
++ name = "stdlibs_none",
++ flag_values = {":stdlibs_flavor": "none"},
++)
++
++# Special set with only core.
++# Used when building compiler_builtins.
++config_setting(
++ name = "stdlibs_core_only",
++ flag_values = {":stdlibs_flavor": "core_only"},
++)
++
++# Included libs: core, compiler_builtins
++config_setting(
++ name = "stdlibs_core",
++ flag_values = {":stdlibs_flavor": "core"},
++)
++
++# Included libs: core, alloc, compiler_builtins
++config_setting(
++ name = "stdlibs_core_alloc",
++ flag_values = {":stdlibs_flavor": "core_alloc"},
++)
++
++# Included libs: core, alloc, std, compiler_builtins
++config_setting(
++ name = "stdlibs_core_alloc_std",
++ flag_values = {":stdlibs_flavor": "core_alloc_std"},
++)
+diff --git a/pw_toolchain/rust/extensions.bzl b/pw_toolchain/rust/extensions.bzl
+index 5099fd000..e38d40d35 100644
+--- a/pw_toolchain/rust/extensions.bzl
++++ b/pw_toolchain/rust/extensions.bzl
+@@ -14,7 +14,7 @@
+ """Extension for declaring Pigweed Rust toolchains."""
+
+ load("//pw_env_setup/bazel/cipd_setup:cipd_rules.bzl", "cipd_repository")
+-load(":templates.bzl", "rust_analyzer_toolchain_template", "rust_toolchain_template", "rustfmt_toolchain_template", "toolchain_template")
++load(":templates.bzl", "rust_analyzer_toolchain_template", "rust_toolchain_no_prebuilt_template", "rust_toolchain_template", "rustfmt_toolchain_template", "toolchain_template")
+ load(":toolchains.bzl", "CHANNELS", "EXTRA_TARGETS", "HOSTS")
+
+ def _module_cipd_tag(module):
+@@ -82,12 +82,16 @@ def _pw_rust_impl(ctx):
+ )
+
+ for target in EXTRA_TARGETS:
+- cipd_repository(
+- name = "rust_toolchain_target_{}_{}".format(target["triple"], target["cpu"]),
+- build_file = "//pw_toolchain/rust:rust_stdlib.BUILD",
+- path = "fuchsia/third_party/rust/target/{}".format(target["triple"]),
+- tag = cipd_tag,
+- )
++ build_std = False
++ if build_std in target:
++ build_std = target.build_std
++ if not build_std:
++ cipd_repository(
++ name = "rust_toolchain_target_{}_{}".format(target["triple"], target["cpu"]),
++ build_file = "//pw_toolchain/rust:rust_stdlib.BUILD",
++ path = "fuchsia/third_party/rust/target/{}".format(target["triple"]),
++ tag = cipd_tag,
++ )
+
+ _toolchain_repository_hub(name = "pw_rust_toolchains")
+
+@@ -146,18 +150,31 @@ def _pw_rust_toolchain(
+ target_settings,
+ extra_rustc_flags,
+ analyzer_toolchain_name = None,
+- rustfmt_toolchain_name = None):
+- build_file = rust_toolchain_template(
+- name = name,
+- exec_compatible_with = exec_compatible_with,
+- target_compatible_with = target_compatible_with,
+- dylib_ext = dylib_ext,
+- target_repo = target_repo,
+- toolchain_repo = toolchain_repo,
+- exec_triple = exec_triple,
+- target_triple = target_triple,
+- extra_rustc_flags = extra_rustc_flags,
+- )
++ rustfmt_toolchain_name = None,
++ build_std = False):
++ if build_std:
++ build_file = rust_toolchain_no_prebuilt_template(
++ name = name,
++ exec_compatible_with = exec_compatible_with,
++ target_compatible_with = target_compatible_with,
++ dylib_ext = dylib_ext,
++ toolchain_repo = toolchain_repo,
++ exec_triple = exec_triple,
++ target_triple = target_triple,
++ extra_rustc_flags = extra_rustc_flags,
++ )
++ else:
++ build_file = rust_toolchain_template(
++ name = name,
++ exec_compatible_with = exec_compatible_with,
++ target_compatible_with = target_compatible_with,
++ dylib_ext = dylib_ext,
++ target_repo = target_repo,
++ toolchain_repo = toolchain_repo,
++ exec_triple = exec_triple,
++ target_triple = target_triple,
++ extra_rustc_flags = extra_rustc_flags,
++ )
+
+ build_file += toolchain_template(
+ name = name,
+@@ -213,6 +230,10 @@ def _BUILD_for_toolchain_repo():
+ )
+
+ for target in EXTRA_TARGETS:
++ build_std = False
++ if "build_std" in target:
++ build_std = target["build_std"]
++
+ build_file += _pw_rust_toolchain(
+ name = "{}_{}_rust_toolchain_{}_{}_{}".format(host["os"], host["cpu"], target["triple"], target["cpu"], channel["name"]),
+ exec_triple = host["triple"],
+@@ -229,6 +250,7 @@ def _BUILD_for_toolchain_repo():
+ ],
+ target_settings = channel["target_settings"],
+ extra_rustc_flags = channel["extra_rustc_flags"],
++ build_std = build_std,
+ )
+ return build_file
+
+diff --git a/pw_toolchain/rust/no_stdlibs.bzl b/pw_toolchain/rust/no_stdlibs.bzl
+new file mode 100644
+index 000000000..ba10c0e46
+--- /dev/null
++++ b/pw_toolchain/rust/no_stdlibs.bzl
+@@ -0,0 +1,70 @@
++# Copyright 2025 The Pigweed Authors
++#
++# Licensed under the Apache License, Version 2.0 (the "License"); you may not
++# use this file except in compliance with the License. You may obtain a copy of
++# the License at
++#
++# https://www.apache.org/licenses/LICENSE-2.0
++#
++# Unless required by applicable law or agreed to in writing, software
++# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
++# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
++# License for the specific language governing permissions and limitations under
++# the License.
++
++"""
++Transitions used when building rust std libraries from source
++"""
++
++def _no_stdlibs_transition_impl(_, __):
++ return {"//pw_toolchain/rust:stdlibs_flavor": "none"}
++
++_no_stdlibs_transition = transition(
++ implementation = _no_stdlibs_transition_impl,
++ inputs = [],
++ outputs = ["//pw_toolchain/rust:stdlibs_flavor"],
++)
++
++def _core_only_transition_impl(_, __):
++ return {"//pw_toolchain/rust:stdlibs_flavor": "core_only"}
++
++_core_only_transition = transition(
++ implementation = _core_only_transition_impl,
++ inputs = [],
++ outputs = ["//pw_toolchain/rust:stdlibs_flavor"],
++)
++
++def _forward_and_symlink(ctx):
++ outs = []
++ for file in ctx.files.deps:
++ # Append the label name to the file name but keep the same extension. i.e.
++ # "<file>.<extension>" -> "<file>_<label>.<extension>"
++ stem = file.basename.removesuffix(".{}".format(file.extension))
++ out = ctx.actions.declare_file("{}_{}.{}".format(stem, ctx.label.name, file.extension))
++ ctx.actions.symlink(output = out, target_file = file)
++ outs.append(out)
++ return [DefaultInfo(files = depset(outs))]
++
++build_with_no_stdlibs = rule(
++ implementation = _forward_and_symlink,
++ cfg = _no_stdlibs_transition,
++ attrs = {
++ # Mandatory attribute for rules with transition.
++ "_allowlist_function_transition": attr.label(
++ default = Label("@bazel_tools//tools/allowlists/function_transition_allowlist"),
++ ),
++ "deps": attr.label_list(allow_files = True, mandatory = True),
++ },
++)
++
++build_with_core_only = rule(
++ implementation = _forward_and_symlink,
++ cfg = _core_only_transition,
++ attrs = {
++ # Mandatory attribute for rules with transition.
++ "_allowlist_function_transition": attr.label(
++ default = Label("@bazel_tools//tools/allowlists/function_transition_allowlist"),
++ ),
++ "deps": attr.label_list(allow_files = True, mandatory = True),
++ },
++)
+diff --git a/pw_toolchain/rust/rust_toolchain.BUILD b/pw_toolchain/rust/rust_toolchain.BUILD
+index 87e7b1c3e..f7d552546 100644
+--- a/pw_toolchain/rust/rust_toolchain.BUILD
++++ b/pw_toolchain/rust/rust_toolchain.BUILD
+@@ -12,6 +12,9 @@
+ # License for the specific language governing permissions and limitations under
+ # the License.
+
++load("@pigweed//pw_toolchain/rust:no_stdlibs.bzl", "build_with_core_only", "build_with_no_stdlibs")
++load("@rules_rust//rust:defs.bzl", "rust_library", "rust_stdlib_filegroup")
++
+ exports_files(glob(["**"]))
+
+ filegroup(
+@@ -35,3 +38,60 @@ filegroup(
+ srcs = glob(["lib/rustlib/src/rust/src/**"]),
+ visibility = ["//visibility:public"],
+ )
++
++rust_library(
++ name = "libcore",
++ srcs = glob([
++ "lib/rustlib/src/rust/library/core/src/**/*.rs",
++ "lib/rustlib/src/rust/library/stdarch/crates/core_arch/src/**/*.rs",
++ "lib/rustlib/src/rust/library/portable-simd/crates/core_simd/src/**/*.rs",
++ ]),
++ compile_data = glob([
++ "lib/rustlib/src/rust/library/core/src/**/*.md",
++ "lib/rustlib/src/rust/library/stdarch/crates/core_arch/src/**/*.md",
++ "lib/rustlib/src/rust/library/portable-simd/crates/core_simd/src/**/*.md",
++ ]),
++ crate_features = ["stdsimd"],
++ crate_name = "core",
++ edition = "2021",
++ rustc_flags = ["--cap-lints=allow"],
++)
++
++rust_stdlib_filegroup(
++ name = "rust_libs_none",
++ srcs = [],
++ visibility = ["//visibility:public"],
++)
++
++build_with_no_stdlibs(
++ name = "rust_libs_core_files",
++ visibility = ["//visibility:public"],
++ deps = [
++ ":libcore",
++ ],
++)
++
++build_with_core_only(
++ name = "rust_libs_compiler_builtin_files",
++ visibility = ["//visibility:public"],
++ deps = [
++ "@rust_crates//:compiler_builtins",
++ ],
++)
++
++rust_stdlib_filegroup(
++ name = "rust_libs_core_only",
++ srcs = [
++ ":rust_libs_core_files",
++ ],
++ visibility = ["//visibility:public"],
++)
++
++rust_stdlib_filegroup(
++ name = "rust_libs_core",
++ srcs = [
++ ":rust_libs_compiler_builtin_files",
++ ":rust_libs_core_files",
++ ],
++ visibility = ["//visibility:public"],
++)
+diff --git a/pw_toolchain/rust/templates.bzl b/pw_toolchain/rust/templates.bzl
+index a798db4c8..56e60aba6 100644
+--- a/pw_toolchain/rust/templates.bzl
++++ b/pw_toolchain/rust/templates.bzl
+@@ -13,6 +13,62 @@
+ # the License.
+ """Private templates for generating toolchain repos."""
+
++_rust_toolchain_no_prebuilt_template = """\
++rust_toolchain(
++ name = "{name}_rust_toolchain",
++ binary_ext = "",
++ cargo = "{toolchain_repo}//:bin/cargo",
++ clippy_driver = "{toolchain_repo}//:bin/clippy-driver",
++ default_edition = "2021",
++ dylib_ext = "{dylib_ext}",
++ exec_compatible_with = {exec_compatible_with},
++ exec_triple = "{exec_triple}",
++ opt_level = {{
++ "dbg": "0",
++ "fastbuild": "0",
++ "opt": "z",
++ }},
++ rust_doc = "{toolchain_repo}//:bin/rustdoc",
++ rust_std = select({{
++ "@pigweed//pw_toolchain/rust:stdlibs_none": "{toolchain_repo}//:rust_libs_none",
++ "@pigweed//pw_toolchain/rust:stdlibs_core_only": "{toolchain_repo}//:rust_libs_core_only",
++ "//conditions:default": "{toolchain_repo}//:rust_libs_core",
++ }}),
++ rustc = "{toolchain_repo}//:bin/rustc",
++ rustc_lib = "{toolchain_repo}//:rustc_lib",
++ staticlib_ext = ".a",
++ stdlib_linkflags = [],
++ target_compatible_with = {target_compatible_with},
++ target_triple = "{target_triple}",
++ extra_rustc_flags = {extra_rustc_flags},
++ extra_exec_rustc_flags = {extra_rustc_flags},
++ # TODO: https://pwbug.dev/342695883 - Works around confusing
++ # target_compatible_with semantics in rust_toolchain. Figure out how to
++ # do better.
++ tags = ["manual"],
++)
++"""
++
++def rust_toolchain_no_prebuilt_template(
++ name,
++ exec_triple,
++ target_triple,
++ toolchain_repo,
++ dylib_ext,
++ exec_compatible_with,
++ target_compatible_with,
++ extra_rustc_flags):
++ return _rust_toolchain_no_prebuilt_template.format(
++ name = name,
++ exec_triple = exec_triple,
++ target_triple = target_triple,
++ toolchain_repo = toolchain_repo,
++ dylib_ext = dylib_ext,
++ exec_compatible_with = json.encode(exec_compatible_with),
++ target_compatible_with = json.encode(target_compatible_with),
++ extra_rustc_flags = json.encode(extra_rustc_flags),
++ )
++
+ _rust_toolchain_template = """\
+ rust_toolchain(
+ name = "{name}_rust_toolchain",
+diff --git a/pw_toolchain/rust/toolchains.bzl b/pw_toolchain/rust/toolchains.bzl
+index 3700da159..37fe1d540 100644
+--- a/pw_toolchain/rust/toolchains.bzl
++++ b/pw_toolchain/rust/toolchains.bzl
+@@ -59,7 +59,8 @@ EXTRA_TARGETS = [
+ },
+ {
+ "cpu": "armv8-m",
+- "triple": "thumbv7m-none-eabi", # TODO: https://pwbug.dev/352342797 - This should be some variant of ARMv8-M.
++ "triple": "thumbv8m.main-none-eabihf",
++ "build_std": True,
+ },
+ ]
+
+--
+2.48.0.rc2.279.g1de40edade-goog
+
diff --git a/build/external/pigweed-Specify-rustc_srcs_subdir-for-rust_analyzer_tool.patch b/build/external/pigweed/0002-WIP-Specify-rustc_srcs_subdir-for-rust_analyzer_tool.patch
similarity index 80%
rename from build/external/pigweed-Specify-rustc_srcs_subdir-for-rust_analyzer_tool.patch
rename to build/external/pigweed/0002-WIP-Specify-rustc_srcs_subdir-for-rust_analyzer_tool.patch
index d08b2ae..4a64f7e 100644
--- a/build/external/pigweed-Specify-rustc_srcs_subdir-for-rust_analyzer_tool.patch
+++ b/build/external/pigweed/0002-WIP-Specify-rustc_srcs_subdir-for-rust_analyzer_tool.patch
@@ -1,7 +1,8 @@
-From 1c4c7f99242202988abbfb3725b17d29486b7c80 Mon Sep 17 00:00:00 2001
+From de556b37f8a77dc542f78860ee49f2828ce64015 Mon Sep 17 00:00:00 2001
From: Erik Gilling <konkers@google.com>
Date: Thu, 9 Jan 2025 12:52:39 -0800
-Subject: [PATCH] WIP: Specify rustc_srcs_subdir for rust_analyzer_toolchains
+Subject: [PATCH 2/2] WIP: Specify rustc_srcs_subdir for
+ rust_analyzer_toolchains
Change-Id: I531944659e240eacedfc1ed9ef8caf5ee19bf5bf
---
@@ -10,10 +11,10 @@
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/pw_toolchain/rust/rust_toolchain.BUILD b/pw_toolchain/rust/rust_toolchain.BUILD
-index f8f3bf0de..4f1823fca 100644
+index f7d552546..bee96730e 100644
--- a/pw_toolchain/rust/rust_toolchain.BUILD
+++ b/pw_toolchain/rust/rust_toolchain.BUILD
-@@ -28,6 +28,6 @@ filegroup(
+@@ -35,7 +35,7 @@ filegroup(
filegroup(
name = "rustc_srcs",
@@ -21,11 +22,12 @@
+ srcs = glob(["lib/rustlib/src/rust/**/*"]),
visibility = ["//visibility:public"],
)
+
diff --git a/pw_toolchain/rust/templates.bzl b/pw_toolchain/rust/templates.bzl
-index 1f0ed66a2..0b8b0164b 100644
+index 56e60aba6..2f9a5a695 100644
--- a/pw_toolchain/rust/templates.bzl
+++ b/pw_toolchain/rust/templates.bzl
-@@ -23,6 +23,11 @@ rust_toolchain(
+@@ -79,6 +79,11 @@ rust_toolchain(
dylib_ext = "{dylib_ext}",
exec_compatible_with = {exec_compatible_with},
exec_triple = "{exec_triple}",
@@ -37,7 +39,7 @@
rust_doc = "{toolchain_repo}//:bin/rustdoc",
rust_std = "{target_repo}//:rust_std",
rustc = "{toolchain_repo}//:bin/rustc",
-@@ -92,6 +97,7 @@ rust_analyzer_toolchain(
+@@ -148,6 +153,7 @@ rust_analyzer_toolchain(
proc_macro_srv = "{toolchain_repo}//:libexec/rust-analyzer-proc-macro-srv",
rustc = "{toolchain_repo}//:bin/rustc",
rustc_srcs = "{toolchain_repo}//:rustc_srcs",
@@ -46,5 +48,5 @@
visibility = ["//visibility:public"],
)
--
-2.47.1.613.gc27f4b7a9f-goog
+2.48.0.rc2.279.g1de40edade-goog
diff --git a/build/external/pigweed/BUILD.bazel b/build/external/pigweed/BUILD.bazel
new file mode 100644
index 0000000..0f3dcd2
--- /dev/null
+++ b/build/external/pigweed/BUILD.bazel
@@ -0,0 +1,13 @@
+# Copyright 2025 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
diff --git a/build/external/rules_rust-add-triples.patch b/build/external/rules_rust-add-triples.patch
deleted file mode 100644
index fe73b60..0000000
--- a/build/external/rules_rust-add-triples.patch
+++ /dev/null
@@ -1,13 +0,0 @@
-diff --git a/rust/platform/triple_mappings.bzl b/rust/platform/triple_mappings.bzl
-index f8b7af92..1ca46cb6 100644
---- a/rust/platform/triple_mappings.bzl
-+++ b/rust/platform/triple_mappings.bzl
-@@ -56,6 +56,8 @@ SUPPORTED_T2_PLATFORM_TRIPLES = {
- "riscv32imc-unknown-none-elf": _support(std = True, host_tools = False),
- "riscv64gc-unknown-none-elf": _support(std = True, host_tools = False),
- "s390x-unknown-linux-gnu": _support(std = True, host_tools = True),
-+ "thumbv6m-none-eabi": _support(std = False, host_tools = False),
-+ "thumbv7m-none-eabi": _support(std = False, host_tools = False),
- "thumbv7em-none-eabi": _support(std = True, host_tools = False),
- "thumbv8m.main-none-eabi": _support(std = True, host_tools = False),
- "wasm32-unknown-unknown": _support(std = True, host_tools = False),
diff --git a/build/external/rules_rust/0001-Add-thumbv6m-and-more-thumbv7m-and-thumbv8m-triples.patch b/build/external/rules_rust/0001-Add-thumbv6m-and-more-thumbv7m-and-thumbv8m-triples.patch
new file mode 100644
index 0000000..1a04721
--- /dev/null
+++ b/build/external/rules_rust/0001-Add-thumbv6m-and-more-thumbv7m-and-thumbv8m-triples.patch
@@ -0,0 +1,29 @@
+From d6e8d7bd0d41316912cba51857f1d915fa1f345b Mon Sep 17 00:00:00 2001
+From: Erik Gilling <konkers@google.com>
+Date: Thu, 12 Dec 2024 14:45:10 -0800
+Subject: [PATCH 1/2] Add thumbv6m and more thumbv7m and thumbv8m triples
+
+These are commonly used in microcontrollers.
+---
+ rust/platform/triple_mappings.bzl | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/rust/platform/triple_mappings.bzl b/rust/platform/triple_mappings.bzl
+index b436af3a..73e89467 100644
+--- a/rust/platform/triple_mappings.bzl
++++ b/rust/platform/triple_mappings.bzl
+@@ -56,8 +56,11 @@ SUPPORTED_T2_PLATFORM_TRIPLES = {
+ "riscv32imc-unknown-none-elf": _support(std = True, host_tools = False),
+ "riscv64gc-unknown-none-elf": _support(std = True, host_tools = False),
+ "s390x-unknown-linux-gnu": _support(std = True, host_tools = True),
++ "thumbv6m-none-eabi": _support(std = False, host_tools = False),
++ "thumbv7m-none-eabi": _support(std = False, host_tools = False),
+ "thumbv7em-none-eabi": _support(std = True, host_tools = False),
+ "thumbv8m.main-none-eabi": _support(std = True, host_tools = False),
++ "thumbv8m.main-none-eabihf": _support(std = True, host_tools = False),
+ "wasm32-unknown-unknown": _support(std = True, host_tools = False),
+ "wasm32-wasip1": _support(std = True, host_tools = False),
+ "x86_64-apple-ios": _support(std = True, host_tools = False),
+--
+2.48.0.rc2.279.g1de40edade-goog
+
diff --git a/build/external/rules_rust-add-rust_srcs_subdir-to-rust_analyzer_toolchain.patch b/build/external/rules_rust/0002-Add-rust_srcs_subdir-to-rust_analyzer_toolchain.patch
similarity index 68%
rename from build/external/rules_rust-add-rust_srcs_subdir-to-rust_analyzer_toolchain.patch
rename to build/external/rules_rust/0002-Add-rust_srcs_subdir-to-rust_analyzer_toolchain.patch
index d4d8da1..b029a7a 100644
--- a/build/external/rules_rust-add-rust_srcs_subdir-to-rust_analyzer_toolchain.patch
+++ b/build/external/rules_rust/0002-Add-rust_srcs_subdir-to-rust_analyzer_toolchain.patch
@@ -1,17 +1,20 @@
-From 610c7743f36413fe4315bd50d3b5fd7e6abe88e1 Mon Sep 17 00:00:00 2001
+From 76378fa41d8ff92b7a9ac2b78497524d06cc6845 Mon Sep 17 00:00:00 2001
From: Erik Gilling <konkers@google.com>
Date: Thu, 9 Jan 2025 12:44:29 -0800
-Subject: [PATCH] WIP: add rust_srcs_subdir to rust_analyzer_toolchain
+Subject: [PATCH 2/2] Add rust_srcs_subdir to rust_analyzer_toolchain
+This allows rust toolchains to be declared from repositories with only
+a single BUILD file. An example would be an `http_archive` repository
+using the `build_file` argument.
---
rust/private/rust_analyzer.bzl | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/rust/private/rust_analyzer.bzl b/rust/private/rust_analyzer.bzl
-index 813f2a2d..68d9178c 100644
+index bc12306a..5f40ed00 100644
--- a/rust/private/rust_analyzer.bzl
+++ b/rust/private/rust_analyzer.bzl
-@@ -273,6 +273,7 @@ def _rust_analyzer_toolchain_impl(ctx):
+@@ -277,6 +277,7 @@ def _rust_analyzer_toolchain_impl(ctx):
proc_macro_srv = ctx.executable.proc_macro_srv,
rustc = ctx.executable.rustc,
rustc_srcs = ctx.attr.rustc_srcs,
@@ -19,7 +22,7 @@
)
return [toolchain]
-@@ -298,6 +299,10 @@ rust_analyzer_toolchain = rule(
+@@ -302,6 +303,10 @@ rust_analyzer_toolchain = rule(
doc = "The source code of rustc.",
mandatory = True,
),
@@ -30,7 +33,7 @@
},
)
-@@ -312,7 +317,7 @@ def _rust_analyzer_detect_sysroot_impl(ctx):
+@@ -316,7 +321,7 @@ def _rust_analyzer_detect_sysroot_impl(ctx):
rustc_srcs = rust_analyzer_toolchain.rustc_srcs
@@ -38,7 +41,7 @@
+ sysroot_src = rustc_srcs.label.package + rust_analyzer_toolchain.rustc_srcs_subdir + "/library"
if rustc_srcs.label.workspace_root:
sysroot_src = _OUTPUT_BASE_TEMPLATE + rustc_srcs.label.workspace_root + "/" + sysroot_src
-
+ else:
--
-2.47.1.613.gc27f4b7a9f-goog
+2.48.0.rc2.279.g1de40edade-goog
diff --git a/build/external/rules_rust/BUILD.bazel b/build/external/rules_rust/BUILD.bazel
new file mode 100644
index 0000000..0f3dcd2
--- /dev/null
+++ b/build/external/rules_rust/BUILD.bazel
@@ -0,0 +1,13 @@
+# Copyright 2025 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.