Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d88cf93
Rearrange link paths on Windows to reduce size overruns and fix errors
dzbarsky Jan 20, 2026
4e2991f
Revert "Fix stamping for rules that don't have a stamp attribute (#38…
dzbarsky Feb 7, 2026
0542271
Revert "Switch stamping detection to ctx.configuration.stamp_binaries…
dzbarsky Feb 7, 2026
0f4dcfa
Fix process-wrapper link lib handling when using argfiles
dzbarsky Feb 16, 2026
5335ed4
Rewrite process_wrapper_bootstrap to cc
dzbarsky Feb 18, 2026
fe28472
Attempt to fix CopyFile for windows
dzbarsky Feb 18, 2026
b880d62
Apply lint config in exec configuration (#2)
isaacparker0 Feb 20, 2026
41dceb7
Fix up rules_rust bzl_library targets
dzbarsky Feb 20, 2026
d8f8e7b
rust-analyzer: include Bazel package dir in crate source include_dirs…
isaacparker0 Feb 20, 2026
df94bb0
Improve proc_macro_deps ergonomics
dzbarsky Sep 9, 2025
88fd88f
Always use param file for process wrapper
dzbarsky Feb 25, 2026
e799bf7
Avoid hashing RustAnalyzerInfo in rust_analyzer alias mapping
dzbarsky Feb 26, 2026
3181144
Convert wrappers to symbolic macros
dzbarsky Feb 26, 2026
d226f9e
Handle toolchain registration when not registered as a bazel_dep
dzbarsky Feb 28, 2026
a456214
Replace the --rustc-quit-on-rmeta / .rmeta approach with Buck2-style …
walter-zeromatter Feb 26, 2026
91e54b7
Cleanup some process_wrapper code
dzbarsky Mar 2, 2026
fc4f530
Fix prost to be compatible with multiplatform
dzbarsky Mar 13, 2026
7d696e9
Avoid vendored crates for rust-analyzer binary
dzbarsky Apr 1, 2026
cd55918
Improve toolchain make var env expansion
dzbarsky Apr 5, 2026
d7d3be0
Improve rust compilation messages
dzbarsky Apr 9, 2026
66ad7ea
Add compile_data to test location expansion
dzbarsky Apr 14, 2026
df56164
Add rust_test sharding support (#13)
bolinfest Apr 15, 2026
1d8ffca
When '--strategy=Rustc=local' is used with pipelined compilation, rus…
walter-zeromatter Apr 17, 2026
f6608dd
Fix nondeterministic SVH from sandbox-local OUT_DIR/CARGO_MANIFEST_DIR
walter-zeromatter Apr 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module(
## Core
###############################################################################

bazel_dep(name = "bazel_lib", version = "3.0.0")
bazel_dep(name = "bazel_features", version = "1.32.0")
bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "platforms", version = "1.0.0")
Expand Down
7 changes: 5 additions & 2 deletions cargo/private/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@bazel_lib//lib:copy_file.bzl", "copy_file")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("//rust:defs.bzl", "rust_binary")

rust_binary(
Expand Down Expand Up @@ -39,6 +39,9 @@ copy_file(

bzl_library(
name = "bzl_lib",
deps = [
"//rust:bzl_lib",
],
srcs = glob(["**/*.bzl"]),
visibility = ["//:__subpackages__"],
visibility = ["//visibility:public"],
)
2 changes: 1 addition & 1 deletion cargo/private/cargo_build_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ def _cargo_build_script_impl(ctx):
tools = tools,
inputs = depset(build_script_inputs, transitive = extra_inputs),
mnemonic = "CargoBuildScriptRun",
progress_message = "Running Cargo build script {}".format(pkg_name),
progress_message = "Running Cargo build script %{label}",
env = env,
toolchain = None,
use_default_shell_env = use_default_shell_env,
Expand Down
2 changes: 2 additions & 0 deletions extensions/prost/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ load("//:defs.bzl", "rust_prost_toolchain")
load(":legacy_proto_toolchain.bzl", "legacy_proto_toolchain")
load(":prost.bzl", "RUST_EDITION", "current_prost_runtime")

exports_files(["protoc_wrapper.rs"])

current_prost_runtime(
name = "current_prost_runtime",
)
Expand Down
23 changes: 12 additions & 11 deletions extensions/prost/private/prost.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ RUST_EDITION = "2021"

TOOLCHAIN_TYPE = "@rules_rust_prost//:toolchain_type"

def _create_proto_lang_toolchain(ctx, prost_toolchain):
def _create_proto_lang_toolchain(prost_toolchain):
proto_lang_toolchain = proto_common.ProtoLangToolchainInfo(
out_replacement_format_flag = "--prost_out=%s",
plugin_format_flag = prost_toolchain.prost_plugin_flag,
plugin = prost_toolchain.prost_plugin[DefaultInfo].files_to_run,
runtime = prost_toolchain.prost_runtime,
provided_proto_sources = depset(),
proto_compiler = ctx.attr._prost_process_wrapper[DefaultInfo].files_to_run,
proto_compiler = prost_toolchain.prost_process_wrapper[DefaultInfo].files_to_run,
protoc_opts = prost_toolchain.protoc_opts,
progress_message = "ProstGenProto %{label}",
mnemonic = "ProstGenProto",
Expand Down Expand Up @@ -118,7 +118,7 @@ def _compile_proto(
additional_inputs = additional_inputs,
additional_args = additional_args,
generated_files = [lib_rs, package_info_file],
proto_lang_toolchain_info = _create_proto_lang_toolchain(ctx, prost_toolchain),
proto_lang_toolchain_info = _create_proto_lang_toolchain(prost_toolchain),
plugin_output = ctx.bin_dir.path,
)

Expand Down Expand Up @@ -180,7 +180,7 @@ def _compile_rust(
prefix = "lib",
name = crate_name,
lib_hash = output_hash,
extension = ".rmeta",
extension = "_meta.rlib",
)

lib = ctx.actions.declare_file(lib_name)
Expand All @@ -193,7 +193,7 @@ def _compile_rust(
prefix = "lib",
name = crate_name,
lib_hash = output_hash,
extension = ".rmeta",
extension = "_meta.rlib",
)
rmeta = ctx.actions.declare_file(rmeta_name)
rustc_rmeta_output = generate_output_diagnostics(ctx, rmeta)
Expand Down Expand Up @@ -377,12 +377,6 @@ rust_prost_aspect = aspect(
default = Label("@bazel_tools//tools/cpp:grep-includes"),
cfg = "exec",
),
"_prost_process_wrapper": attr.label(
doc = "The wrapper script for the Prost protoc plugin.",
cfg = "exec",
executable = True,
default = Label("//private:protoc_wrapper"),
),
} | RUSTC_ATTRS | {
# Need to override this attribute to explicitly set the workspace.
"_always_enable_metadata_output_groups": attr.label(
Expand Down Expand Up @@ -473,6 +467,7 @@ def _rust_prost_toolchain_impl(ctx):
prost_plugin = ctx.attr.prost_plugin,
prost_plugin_flag = ctx.attr.prost_plugin_flag,
prost_runtime = ctx.attr.prost_runtime,
prost_process_wrapper = ctx.attr._prost_process_wrapper,
prost_types = ctx.attr.prost_types,
proto_compiler = proto_compiler,
protoc_opts = ctx.fragments.proto.experimental_protoc_opts,
Expand Down Expand Up @@ -516,6 +511,12 @@ rust_prost_toolchain = rule(
mandatory = True,
aspects = [rust_analyzer_aspect],
),
"_prost_process_wrapper": attr.label(
doc = "The wrapper script for the Prost protoc plugin.",
cfg = "exec",
executable = True,
default = Label("@rules_rust_prost//private:protoc_wrapper"),
),
"prost_types": attr.label(
doc = "The Prost types crates to use.",
providers = [[rust_common.crate_info], [rust_common.crate_group_info]],
Expand Down
7 changes: 5 additions & 2 deletions extensions/wasm_bindgen/private/wasm_bindgen_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ load(
"@rules_rust//rust/private:utils.bzl",
"determine_output_hash",
"expand_dict_value_locations",
"filter_deps",
"find_toolchain",
"generate_output_diagnostics",
"get_import_macro_deps",
Expand Down Expand Up @@ -61,8 +62,10 @@ def _rust_wasm_bindgen_test_binary_impl(ctx):
toolchain = find_toolchain(ctx)

crate_type = "bin"
deps = transform_deps(ctx.attr.deps + [wb_toolchain.wasm_bindgen_test])
proc_macro_deps = transform_deps(ctx.attr.proc_macro_deps + get_import_macro_deps(ctx))

deps, proc_macro_deps = filter_deps(ctx)
deps = transform_deps(deps + [wb_toolchain.wasm_bindgen_test])
proc_macro_deps = transform_deps(proc_macro_deps + get_import_macro_deps(ctx))

# Target is building the crate in `test` config
if WasmBindgenTestCrateInfo in ctx.attr.wasm:
Expand Down
47 changes: 40 additions & 7 deletions rust/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

"""Public entry point to all Rust rules and supported APIs."""

load("@bazel_features//:features.bzl", "bazel_features")
load(
"//rust:toolchain.bzl",
_rust_stdlib_filegroup = "rust_stdlib_filegroup",
Expand Down Expand Up @@ -78,25 +79,57 @@ load(
_rust_unpretty_aspect = "rust_unpretty_aspect",
)

rust_library = _rust_library
def _rule_wrapper(rule):
def _wrapped(name, deps = [], proc_macro_deps = [], **kwargs):
rule(
name = name,
deps = deps + proc_macro_deps,
# TODO(zbarsky): This attribute would ideally be called `exec_configured_deps` or similar.
proc_macro_deps = deps + proc_macro_deps,
**kwargs
)

return _wrapped

def _symbolic_rule_wrapper(rule, macro_fn):
def _wrapped(name, visibility, deps, proc_macro_deps, **kwargs):
rule(
name = name,
visibility = visibility,
deps = deps + proc_macro_deps,
# TODO(zbarsky): This attribute would ideally be called `exec_configured_deps` or similar.
proc_macro_deps = deps + proc_macro_deps,
**kwargs
)

return macro_fn(
implementation = _wrapped,
inherit_attrs = rule,
attrs = {
"deps": attr.label_list(default = []),
"proc_macro_deps": attr.label_list(default = []),
},
)

rust_library = _symbolic_rule_wrapper(_rust_library, bazel_features.globals.macro) if bazel_features.globals.macro else _rule_wrapper(_rust_library)
# See @rules_rust//rust/private:rust.bzl for a complete description.

rust_static_library = _rust_static_library
rust_static_library = _rule_wrapper(_rust_static_library)
# See @rules_rust//rust/private:rust.bzl for a complete description.

rust_shared_library = _rust_shared_library
rust_shared_library = _rule_wrapper(_rust_shared_library)
# See @rules_rust//rust/private:rust.bzl for a complete description.

rust_proc_macro = _rust_proc_macro
rust_proc_macro = _rule_wrapper(_rust_proc_macro)
# See @rules_rust//rust/private:rust.bzl for a complete description.

rust_binary = _rust_binary
rust_binary = _symbolic_rule_wrapper(_rust_binary, bazel_features.globals.macro) if bazel_features.globals.macro else _rule_wrapper(_rust_binary)
# See @rules_rust//rust/private:rust.bzl for a complete description.

rust_library_group = _rust_library_group
# See @rules_rust//rust/private:rust.bzl for a complete description.

rust_test = _rust_test
rust_test = _symbolic_rule_wrapper(_rust_test, bazel_features.globals.macro) if bazel_features.globals.macro else _rule_wrapper(_rust_test)
# See @rules_rust//rust/private:rust.bzl for a complete description.

rust_test_suite = _rust_test_suite
Expand All @@ -105,7 +138,7 @@ rust_test_suite = _rust_test_suite
rust_doc = _rust_doc
# See @rules_rust//rust/private:rustdoc.bzl for a complete description.

rust_doc_test = _rust_doc_test
rust_doc_test = _rule_wrapper(_rust_doc_test)
# See @rules_rust//rust/private:rustdoc_test.bzl for a complete description.

clippy_flag = _clippy_flag
Expand Down
6 changes: 3 additions & 3 deletions rust/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ def _find_modules(module_ctx):
our_module = mod
if root == None:
root = our_module
if our_module == None:
fail("Unable to find rules_rust module")

return root, our_module

Expand Down Expand Up @@ -105,7 +103,9 @@ def _rust_impl(module_ctx):
if toolchain_triples.get(repository_set["exec_triple"]) == repository_set["name"]:
toolchain_triples.pop(repository_set["exec_triple"], None)

toolchains = root.tags.toolchain or rules_rust.tags.toolchain
toolchains = root.tags.toolchain
if not toolchains and rules_rust:
toolchains = rules_rust.tags.toolchain

for toolchain in toolchains:
if toolchain.extra_rustc_flags and toolchain.extra_rustc_flags_triples:
Expand Down
1 change: 0 additions & 1 deletion rust/platform/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@ package_group(
bzl_library(
name = "bzl_lib",
srcs = glob(["**/*.bzl"]),
visibility = ["//rust:__subpackages__"],
)
10 changes: 9 additions & 1 deletion rust/private/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("//rust/private:rust_analyzer.bzl", "rust_analyzer_detect_sysroot")
load("//rust/private:rustc.bzl", "is_proc_macro_dep", "is_proc_macro_dep_enabled")
load("//rust/private:stamp.bzl", "stamp_build_setting")

# Exported for docs
exports_files(["providers.bzl"])

exports_files([
"test_sharding_wrapper.bat",
"test_sharding_wrapper.sh",
])

bzl_library(
name = "bazel_tools_bzl_lib",
srcs = ["@bazel_tools//tools:bzl_srcs"],
Expand All @@ -21,7 +27,7 @@ bzl_library(
bzl_library(
name = "bzl_lib",
srcs = glob(["**/*.bzl"]),
visibility = ["//rust:__subpackages__"],
visibility = ["//visibility:public"],
deps = [
":bazel_tools_bzl_lib",
":rules_cc_bzl_lib",
Expand All @@ -32,6 +38,8 @@ bzl_library(
],
)

stamp_build_setting(name = "stamp")

# This setting may be used to identify dependencies of proc-macro-s.
# This feature is only enabled if `is_proc_macro_dep_enabled` is true.
# Its value controls the BAZEL_RULES_RUST_IS_PROC_MACRO_DEP environment variable
Expand Down
2 changes: 1 addition & 1 deletion rust/private/clippy.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def rust_clippy_action(ctx, clippy_executable, process_wrapper, crate_info, conf
out_dir = out_dir,
build_env_files = build_env_files,
build_flags_files = build_flags_files,
emit = ["dep-info", "metadata"],
emit = ["metadata"],
skip_expanding_rustc_env = True,
use_json_output = bool(clippy_diagnostics_file),
error_format = error_format,
Expand Down
Loading
Loading