Skip to content

Commit

Permalink
rust: Register Pigweed Rust toolchains with bzlmod
Browse files Browse the repository at this point in the history
Change-Id: If3793a81104a6057ebea60386757be009a806160
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/231689
Reviewed-by: Armando Montanez <[email protected]>
Commit-Queue: Erik Gilling <[email protected]>
Lint: Lint 🤖 <[email protected]>
  • Loading branch information
konkers authored and CQ Bot Account committed Sep 5, 2024
1 parent 00faa5b commit 4816267
Show file tree
Hide file tree
Showing 8 changed files with 1,162 additions and 614 deletions.
23 changes: 18 additions & 5 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ bazel_dep(name = "rules_jvm_external", version = "6.2")
bazel_dep(name = "rules_libusb", version = "0.1.0-rc1")
bazel_dep(name = "rules_platform", version = "0.1.0")
bazel_dep(name = "rules_probe_rs", version = "0.0.2")
bazel_dep(name = "rules_proto", version = "6.0.0")
bazel_dep(name = "rules_proto", version = "6.0.2")
bazel_dep(name = "rules_python", version = "0.34.0")
bazel_dep(name = "rules_rust", version = "0.45.1")
bazel_dep(name = "rules_rust", version = "0.49.3")

bazel_dep(name = "hedron_compile_commands", dev_dependency = True)

Expand Down Expand Up @@ -69,9 +69,8 @@ git_override(
remote = "https://github.com/nanopb/nanopb.git",
)

archive_override(
single_version_override(
module_name = "rules_rust",
integrity = "sha256-+bWb47wg0VchIADaHt6L5Dma2Gn+Q589nz/MKcTi+lo=",
patch_strip = 1,
patches = [
# Fix rustdoc test w/ proc macros
Expand All @@ -85,8 +84,12 @@ archive_override(
# we will migrate to that solution.
# https://github.com/konkers/rules_rust/tree/wip/rustdoc
"//pw_rust/bazel_patches:0002-PROTOTYPE-Add-ability-to-document-multiple-crates-at.patch",
# When used through bzlmod, there is no way to disable the registration
# rules_rust's default toolchains. We force disable them here while
# TODO: https://github.com/bazelbuild/rules_rust/issues/2818 - Remove
# when mechanism to disable toolchains is added upstream.
"//pw_rust/bazel_patches:0003-WIP-disable-default-toolchain-registration.patch",
],
urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.45.1/rules_rust-v0.45.1.tar.gz"],
)

# Transitive deps not in BCR
Expand Down Expand Up @@ -166,6 +169,16 @@ register_toolchains(
"//pw_toolchain/host_clang:host_cc_toolchain_macos",
)

# Rust toolchains
pw_rust = use_extension("//pw_toolchain/rust:extensions.bzl", "pw_rust")
pw_rust.toolchain(cipd_tag = "rust_revision:bf9c7a64ad222b85397573668b39e6d1ab9f4a72")
use_repo(pw_rust, "pw_rust_toolchains")

register_toolchains(
"@pw_rust_toolchains//:all",
dev_dependency = True,
)

# Get probe-rs
# ============
probe_rs = use_extension("@rules_probe_rs//probe_rs:extensions.bzl", "probe_rs")
Expand Down
1,208 changes: 683 additions & 525 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

17 changes: 0 additions & 17 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,6 @@ git_repository(
remote = "https://pigweed.googlesource.com/third_party/github/google/googletest",
)

load(
"//pw_toolchain/rust:defs.bzl",
"pw_rust_register_toolchain_and_target_repos",
"pw_rust_register_toolchains",
)

pw_rust_register_toolchain_and_target_repos(
cipd_tag = "rust_revision:bf9c7a64ad222b85397573668b39e6d1ab9f4a72",
)

# Allows creation of a `rust-project.json` file to allow rust analyzer to work.
load("@rules_rust//tools/rust_analyzer:deps.bzl", "rust_analyzer_dependencies")

rust_analyzer_dependencies()

pw_rust_register_toolchains()

# Vendored third party rust crates.
git_repository(
name = "rust_crates",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
diff --git a/MODULE.bazel b/MODULE.bazel
index f5c16706..773a8c62 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -159,13 +159,13 @@ use_repo(
"rules_rust_wasm_bindgen_cli",
)

-rust = use_extension("//rust:extensions.bzl", "rust")
-rust.toolchain(edition = "2021")
-use_repo(rust, "rust_toolchains")
+# rust = use_extension("//rust:extensions.bzl", "rust")
+# rust.toolchain(edition = "2021")
+# use_repo(rust, "rust_toolchains")

-register_toolchains(
- "@rust_toolchains//:all",
-)
+# register_toolchains(
+# "@rust_toolchains//:all",
+# )

register_toolchains(
"//proto/protobuf:default-proto-toolchain",
69 changes: 2 additions & 67 deletions pw_toolchain/rust/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,73 +15,7 @@

load("@rules_rust//rust:toolchain.bzl", "rust_analyzer_toolchain", "rust_toolchain")
load("//pw_env_setup/bazel/cipd_setup:cipd_rules.bzl", "cipd_repository")

HOSTS = [
{
"cipd_arch": "arm64",
"cpu": "aarch64",
"dylib_ext": ".so",
"os": "linux",
"triple": "aarch64-unknown-linux-gnu",
},
{
"cipd_arch": "amd64",
"cpu": "x86_64",
"dylib_ext": ".so",
"os": "linux",
"triple": "x86_64-unknown-linux-gnu",
},
{
"cipd_arch": "arm64",
"cpu": "aarch64",
"dylib_ext": ".dylib",
"os": "macos",
"triple": "aarch64-apple-darwin",
},
{
"cipd_arch": "amd64",
"cpu": "x86_64",
"dylib_ext": ".dylib",
"os": "macos",
"triple": "x86_64-apple-darwin",
},
]

EXTRA_TARGETS = [
{
"cpu": "armv6-m",
"triple": "thumbv6m-none-eabi",
},
{
"cpu": "armv7-m",
"triple": "thumbv7m-none-eabi",
},
{
"cpu": "armv7e-m",
"triple": "thumbv7m-none-eabi",
},
{
"cpu": "armv8-m",
"triple": "thumbv7m-none-eabi", # TODO: https://pwbug.dev/352342797 - This should be some variant of ARMv8-M.
},
]

CHANNELS = [
{
"extra_rustc_flags": ["-Dwarnings", "-Zmacro-backtrace"],
"name": "nightly",
"target_settings": ["@rules_rust//rust/toolchain/channel:nightly"],
},
{
# In order to approximate a stable toolchain with our nightly one, we
# disable experimental features with the exception of `proc_macro_span`
# because the `proc-marcro2` automatically detects the toolchain
# as nightly and dynamically uses this feature.
"extra_rustc_flags": ["-Dwarnings", "-Zallow-features=proc_macro_span"],
"name": "stable",
"target_settings": ["@rules_rust//rust/toolchain/channel:stable"],
},
]
load(":toolchains.bzl", "CHANNELS", "EXTRA_TARGETS", "HOSTS")

# buildifier: disable=unnamed-macro
def pw_rust_register_toolchain_and_target_repos(cipd_tag, pigweed_repo_name = "@pigweed"):
Expand Down Expand Up @@ -252,6 +186,7 @@ def _pw_rust_host_toolchain(
rustc_srcs = "{}//:rustc_srcs".format(toolchain_repo),
target_compatible_with = compatible_with,
visibility = ["//visibility:public"],
tags = ["manual"],
)

native.toolchain(
Expand Down
Loading

0 comments on commit 4816267

Please sign in to comment.