Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b4c649c
Proper handling for windows mingw flags
dzbarsky Dec 23, 2025
5403348
Properly handle artifact_name_patterns
dzbarsky Dec 18, 2025
4dc9ac6
Rearrange link paths on Windows to reduce size overruns and fix errors
dzbarsky Jan 20, 2026
09cc477
Fix some triple-mapping errors
dzbarsky Jan 31, 2026
93206e6
Strip -pthread for Windows link args
dzbarsky Feb 7, 2026
e0f1c13
Revert "Fix stamping for rules that don't have a stamp attribute (#38…
dzbarsky Feb 7, 2026
f8d867c
Revert "Switch stamping detection to ctx.configuration.stamp_binaries…
dzbarsky Feb 7, 2026
8efa3fa
Fix process-wrapper link lib handling when using argfiles
dzbarsky Feb 16, 2026
70777e4
Rewrite process_wrapper_bootstrap to cc
dzbarsky Feb 18, 2026
c24d82e
Attempt to fix CopyFile for windows
dzbarsky Feb 18, 2026
53fb4fa
Apply lint config in exec configuration (#2)
isaacparker0 Feb 20, 2026
775d23a
Fix up rules_rust bzl_library targets
dzbarsky Feb 20, 2026
81cbd5d
rust-analyzer: include Bazel package dir in crate source include_dirs…
isaacparker0 Feb 20, 2026
fa7a428
Improve proc_macro_deps ergonomics
dzbarsky Sep 9, 2025
e1d254a
Always use param file for process wrapper
dzbarsky Feb 25, 2026
c69567d
Avoid hashing RustAnalyzerInfo in rust_analyzer alias mapping
dzbarsky Feb 26, 2026
1272c03
Convert wrappers to symbolic macros
dzbarsky Feb 26, 2026
8e568ba
Add missing system keys to `triple_mappings.bzl` (#5)
ArchangelX360 Feb 28, 2026
333382b
Handle toolchain registration when not registered as a bazel_dep
dzbarsky Feb 28, 2026
627b424
Switch pipelining metadata action to hollow rlib (-Zno-codegen)
walter-zeromatter Feb 26, 2026
6f3357c
Cleanup some process_wrapper code
dzbarsky Mar 2, 2026
7ed8a24
Fix prost to be compatible with multiplatform
dzbarsky Mar 13, 2026
3bd9743
Pass File objects instead of path strings for PathMapper compatibility
walter-zeromatter Mar 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: 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
19 changes: 10 additions & 9 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 @@ -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 @@ -64,8 +65,10 @@ def _rust_wasm_bindgen_test_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 @@ -93,7 +91,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__"],
)
32 changes: 23 additions & 9 deletions rust/platform/triple_mappings.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ _CPU_ARCH_TO_BUILTIN_PLAT_SUFFIX = {
"le32": None,
"mips": None,
"mipsel": None,
"powerpc": "ppc",
"powerpc64": None,
"powerpc": "ppc32",
"powerpc64": "ppc",
"powerpc64le": "ppc64le",
"riscv32": "riscv32",
"riscv32imc": "riscv32",
Expand Down Expand Up @@ -154,17 +154,17 @@ _SYSTEM_TO_BUILTIN_SYS_SUFFIX = {
"linux": "linux",
"macos": "osx",
"nacl": None,
"netbsd": None,
"netbsd": "netbsd",
"nixos": "nixos",
"none": "none",
"nto": "qnx",
"openbsd": "openbsd",
"solaris": None,
"uefi": "uefi",
"unknown": None,
"wasi": None,
"wasip1": None,
"wasip2": None,
"wasi": "wasi",
"wasip1": "wasi",
"wasip2": "wasi",
"windows": "windows",
}

Expand All @@ -179,6 +179,7 @@ _SYSTEM_TO_BINARY_EXT = {
"ios": "",
"linux": "",
"macos": "",
"netbsd": "",
"nixos": "",
"none": "",
"nto": "",
Expand All @@ -187,6 +188,7 @@ _SYSTEM_TO_BINARY_EXT = {
# generated extension for the wasm target, similarly to the
# windows target
"unknown": ".wasm",
"threads": ".wasm",
"wasi": ".wasm",
"wasip1": ".wasm",
"wasip2": ".wasm",
Expand All @@ -204,11 +206,13 @@ _SYSTEM_TO_STATICLIB_EXT = {
"ios": ".a",
"linux": ".a",
"macos": ".a",
"netbsd": ".a",
"nixos": ".a",
"none": ".a",
"nto": ".a",
"uefi": ".lib",
"unknown": "",
"threads": "",
"wasi": "",
"wasip1": "",
"wasip2": "",
Expand All @@ -226,11 +230,13 @@ _SYSTEM_TO_DYLIB_EXT = {
"ios": ".dylib",
"linux": ".so",
"macos": ".dylib",
"netbsd": ".so",
"nixos": ".so",
"none": ".so",
"nto": ".a",
"uefi": "", # UEFI doesn't have dynamic linking
"unknown": ".wasm",
"threads": ".wasm",
"wasi": ".wasm",
"wasip1": ".wasm",
"wasip2": ".wasm",
Expand Down Expand Up @@ -284,7 +290,12 @@ _SYSTEM_TO_STDLIB_LINKFLAGS = {
"wasi": [],
"wasip1": [],
"wasip2": [],
"windows": ["advapi32.lib", "ws2_32.lib", "userenv.lib", "Bcrypt.lib"],
"windows": {
# see https://github.com/rust-lang/rust/blob/c4aa646f15e40bd3e64ddb5017b7b89b3646ac99/src/tools/run-make-support/src/external_deps/c_cxx_compiler/extras.rs#L14-L23
"gnu": ["-lws2_32", "-luserenv", "-lbcrypt", "-lntdll", "-lsynchronization"],
"gnullvm": ["-lws2_32", "-luserenv", "-lbcrypt", "-lntdll", "-lsynchronization"],
"msvc": ["advapi32.lib", "ws2_32.lib", "userenv.lib", "Bcrypt.lib"],
},
}

def cpu_arch_to_constraints(cpu_arch, *, system = None, abi = None):
Expand Down Expand Up @@ -410,8 +421,11 @@ def system_to_staticlib_ext(system):
def system_to_binary_ext(system):
return _SYSTEM_TO_BINARY_EXT[system]

def system_to_stdlib_linkflags(system):
return _SYSTEM_TO_STDLIB_LINKFLAGS[system]
def system_to_stdlib_linkflags(target_triple):
val = _SYSTEM_TO_STDLIB_LINKFLAGS[target_triple.system]
if type(val) == "list":
return val
return val[target_triple.abi]

def triple_to_constraint_set(target_triple):
"""Returns a set of constraints for a given platform triple
Expand Down
5 changes: 4 additions & 1 deletion rust/private/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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"])
Expand All @@ -21,7 +22,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 +33,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 @@ -165,7 +165,7 @@ def rust_clippy_action(ctx, clippy_executable, process_wrapper, crate_info, conf
attr = ctx.rule.attr,
file = ctx.file,
toolchain = toolchain,
tool_path = clippy_executable.path,
tool_path = clippy_executable,
cc_toolchain = cc_toolchain,
feature_configuration = feature_configuration,
crate_info = crate_info,
Expand Down
2 changes: 1 addition & 1 deletion rust/private/repository_utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ def BUILD_for_rust_toolchain(
str: A rendered template of a `rust_toolchain` declaration
"""
if stdlib_linkflags == None:
stdlib_linkflags = ", ".join(['"%s"' % x for x in system_to_stdlib_linkflags(target_triple.system)])
stdlib_linkflags = ", ".join(['"%s"' % x for x in system_to_stdlib_linkflags(target_triple)])

rustfmt_label = None
if include_rustfmt:
Expand Down
Loading