diff --git a/cargo/BUILD.bazel b/cargo/BUILD.bazel index e9c6ca8f80..d1bad6d04e 100644 --- a/cargo/BUILD.bazel +++ b/cargo/BUILD.bazel @@ -1,9 +1,8 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") -exports_files([ - "defs.bzl", - "Cargo.toml", -]) +exports_files( + glob(["*.bzl"]) + ["Cargo.toml"], +) bzl_library( name = "bzl_lib", diff --git a/cargo/cargo_bootstrap_repository.bzl b/cargo/cargo_bootstrap_repository.bzl new file mode 100644 index 0000000000..95fb435886 --- /dev/null +++ b/cargo/cargo_bootstrap_repository.bzl @@ -0,0 +1,8 @@ +"""# cargo_bootstrap_repository.bzl""" + +load( + "//cargo/private:cargo_bootstrap.bzl", + _cargo_bootstrap_repository = "cargo_bootstrap_repository", +) + +cargo_bootstrap_repository = _cargo_bootstrap_repository diff --git a/cargo/cargo_build_script.bzl b/cargo/cargo_build_script.bzl new file mode 100644 index 0000000000..bb19232218 --- /dev/null +++ b/cargo/cargo_build_script.bzl @@ -0,0 +1,8 @@ +"""# cargo_build_script.bzl""" + +load( + "//cargo/private:cargo_build_script_wrapper.bzl", + _cargo_build_script = "cargo_build_script", +) + +cargo_build_script = _cargo_build_script diff --git a/cargo/cargo_dep_env.bzl b/cargo/cargo_dep_env.bzl new file mode 100644 index 0000000000..c9c0cfcfb5 --- /dev/null +++ b/cargo/cargo_dep_env.bzl @@ -0,0 +1,8 @@ +"""# cargo_dep_env.bzl""" + +load( + "//cargo/private:cargo_dep_env.bzl", + _cargo_dep_env = "cargo_dep_env", +) + +cargo_dep_env = _cargo_dep_env diff --git a/cargo/cargo_env.bzl b/cargo/cargo_env.bzl new file mode 100644 index 0000000000..9b47e4a08b --- /dev/null +++ b/cargo/cargo_env.bzl @@ -0,0 +1,8 @@ +"""# cargo_env.bzl""" + +load( + "//cargo/private:cargo_bootstrap.bzl", + _cargo_env = "cargo_env", +) + +cargo_env = _cargo_env diff --git a/cargo/defs.bzl b/cargo/defs.bzl index 609965112c..e9d432663f 100644 --- a/cargo/defs.bzl +++ b/cargo/defs.bzl @@ -4,20 +4,23 @@ Common definitions for the `@rules_rust//cargo` package """ load( - "//cargo/private:cargo_bootstrap.bzl", + "//cargo:cargo_bootstrap_repository.bzl", _cargo_bootstrap_repository = "cargo_bootstrap_repository", - _cargo_env = "cargo_env", ) load( - "//cargo/private:cargo_build_script_wrapper.bzl", + "//cargo:cargo_build_script.bzl", _cargo_build_script = "cargo_build_script", ) load( - "//cargo/private:cargo_dep_env.bzl", + "//cargo:cargo_dep_env.bzl", _cargo_dep_env = "cargo_dep_env", ) load( - "//cargo/private:cargo_lints.bzl", + "//cargo:cargo_env.bzl", + _cargo_env = "cargo_env", +) +load( + "//cargo:extract_cargo_lints.bzl", _extract_cargo_lints = "extract_cargo_lints", ) load("//cargo/private:cargo_toml_env_vars.bzl", _cargo_toml_env_vars = "cargo_toml_env_vars") diff --git a/cargo/extract_cargo_lints.bzl b/cargo/extract_cargo_lints.bzl new file mode 100644 index 0000000000..95c4ee4364 --- /dev/null +++ b/cargo/extract_cargo_lints.bzl @@ -0,0 +1,8 @@ +"""# extract_cargo_lints.bzl""" + +load( + "//cargo/private:cargo_lints.bzl", + _extract_cargo_lints = "extract_cargo_lints", +) + +extract_cargo_lints = _extract_cargo_lints diff --git a/crate_universe/private/crates_repository.bzl b/crate_universe/private/crates_repository.bzl index 591ff434cb..641314d7ed 100644 --- a/crate_universe/private/crates_repository.bzl +++ b/crate_universe/private/crates_repository.bzl @@ -384,7 +384,7 @@ CARGO_BAZEL_REPIN=1 CARGO_BAZEL_REPIN_ONLY=crate_index bazel sync --only=crate_i ), "splicing_config": attr.string( doc = ( - "The configuration flags to use for splicing Cargo manifests. Use `//crate_universe:defs.bzl\\%rsplicing_config` to " + + "The configuration flags to use for splicing Cargo manifests. Use `//crate_universe:defs.bzl\\%splicing_config` to " + "generate the value for this field. If unset, the defaults defined there will be used." ), ), diff --git a/crate_universe/private/crates_vendor.bzl b/crate_universe/private/crates_vendor.bzl index 1183bfbc90..d562c482a6 100644 --- a/crate_universe/private/crates_vendor.bzl +++ b/crate_universe/private/crates_vendor.bzl @@ -293,7 +293,7 @@ def generate_config_file( mode (str): The vendoring mode. annotations: Any annotations provided. generate_binaries (bool): Whether to generate binaries for the crates. - generate_build_scripts (bool): Whether to generate BUILD.bazel files. + generate_build_scripts (bool): Whether to generate `cargo_build_script` targets for crates that have build scripts. generate_target_compatible_with (bool): DEPRECATED: Moved to `render_config`. supported_platform_triples (str): The platform triples to support in the generated BUILD.bazel files. @@ -572,7 +572,7 @@ CRATES_VENDOR_ATTRS = { ), "splicing_config": attr.string( doc = ( - "The configuration flags to use for splicing Cargo manifests. Use `//crate_universe:defs.bzl\\%rsplicing_config` to " + + "The configuration flags to use for splicing Cargo manifests. Use `//crate_universe:defs.bzl\\%splicing_config` to " + "generate the value for this field. If unset, the defaults defined there will be used." ), ), diff --git a/crate_universe/private/generate_utils.bzl b/crate_universe/private/generate_utils.bzl index d504d9cffa..8e7e46fc95 100644 --- a/crate_universe/private/generate_utils.bzl +++ b/crate_universe/private/generate_utils.bzl @@ -126,7 +126,7 @@ def render_config( crate_repository_template (str, optional): The base template to use for Crate label repository names. The available format keys are [`{repository}`, `{name}`, `{version}`]. crate_alias_template (str, optional): The template to use when referring to generated aliases within the external - repository. The available format keys are [`{repository}`, `{name}`, `{version}`]. + repository. The available format keys are [`{repository}`, `{name}`, `{version}`, `{target}`]. crates_module_template (str, optional): The pattern to use for the `defs.bzl` and `BUILD.bazel` file names used for the crates module. The available format keys are [`{file}`]. default_alias_rule (str, option): Alias rule to use when generating aliases for all crates. Acceptable values @@ -347,13 +347,15 @@ def generate_config(repository_ctx): return config_path def get_lockfiles(repository_ctx): - """_summary_ + """Resolve the Cargo and Bazel lockfile paths from the repository rule's attributes. Args: repository_ctx (repository_ctx): The rule's context object. Returns: - struct: _description_ + struct: A struct with the following fields: + - `cargo` (path): The path to the Cargo lockfile. + - `bazel` (path | None): The path to the Bazel lockfile, or `None` if none was configured. """ return struct( cargo = repository_ctx.path(repository_ctx.attr.cargo_lockfile), diff --git a/crate_universe/private/local_crate_mirror.bzl b/crate_universe/private/local_crate_mirror.bzl index 208c3fdb82..edf49a6ce0 100644 --- a/crate_universe/private/local_crate_mirror.bzl +++ b/crate_universe/private/local_crate_mirror.bzl @@ -57,7 +57,7 @@ This is effectively a `local_repository` rule implementation, but where the `BUI ), "path": attr.string( # TODO: Verify what happens if this is not an absolute path. - doc = "Absolute path to the BUILD.bazel file to generate.", + doc = "Absolute path to the crate source directory whose contents will be copied into the mirror repository.", ), "quiet": attr.bool( doc = "If stdout and stderr should not be printed to the terminal.", diff --git a/crate_universe/private/splicing_utils.bzl b/crate_universe/private/splicing_utils.bzl index 16033de2d4..c1eaa138a9 100644 --- a/crate_universe/private/splicing_utils.bzl +++ b/crate_universe/private/splicing_utils.bzl @@ -146,7 +146,10 @@ def splice_workspace_manifest( debug_workspace_dir (path): The location in which to save splicing outputs for future review. Returns: - path: The path to a Cargo metadata json file found in the spliced workspace root. + struct: A struct describing the spliced workspace outputs with the following fields: + - `metadata` (path): The path to the Cargo `metadata.json` in the spliced workspace root. + - `cargo_lock` (path): The path to the spliced `Cargo.lock` file. + - `extra_paths_to_track` (list of str): Additional paths (one per line) reported by the splicer that should be tracked for repin invalidation. """ # Generate a workspace root which contains all workspace members diff --git a/docs/BUILD.bazel b/docs/BUILD.bazel index 27c2ccc6f1..d1339df731 100644 --- a/docs/BUILD.bazel +++ b/docs/BUILD.bazel @@ -33,38 +33,98 @@ bzl_library( ) stardoc( - name = "cargo", - out = "src/cargo.md", - input = "@rules_rust//cargo:defs.bzl", - symbol_names = [ - "cargo_bootstrap_repository", - "cargo_build_script", - "cargo_dep_env", - "cargo_env", - "extract_cargo_lints", - ], - table_of_contents_template = "@stardoc//stardoc:templates/markdown_tables/table_of_contents.vm", + name = "cargo_build_script", + out = "src/cargo_build_script.md", + input = "@rules_rust//cargo:cargo_build_script.bzl", + symbol_names = ["cargo_build_script"], deps = [":all_docs"], ) stardoc( - name = "rust", - out = "src/rust.md", - input = "@rules_rust//rust:defs.bzl", - symbol_names = [ - "rust_binary", - "rust_library", - "rust_library_group", - "rust_lint_config", - "rust_static_library", - "rust_shared_library", - "rust_proc_macro", - "rust_test", - "rust_test_suite", - "rust_unpretty_aspect", - "rust_unpretty", - ], - table_of_contents_template = "@stardoc//stardoc:templates/markdown_tables/table_of_contents.vm", + name = "cargo_env", + out = "src/cargo_env.md", + input = "@rules_rust//cargo:cargo_env.bzl", + symbol_names = ["cargo_env"], + deps = [":all_docs"], +) + +stardoc( + name = "extract_cargo_lints", + out = "src/extract_cargo_lints.md", + input = "@rules_rust//cargo:extract_cargo_lints.bzl", + symbol_names = ["extract_cargo_lints"], + deps = [":all_docs"], +) + +stardoc( + name = "rust_binary", + out = "src/rust_binary.md", + input = "@rules_rust//rust:rust_binary.bzl", + symbol_names = ["rust_binary"], + deps = [":all_docs"], +) + +stardoc( + name = "rust_library", + out = "src/rust_library.md", + input = "@rules_rust//rust:rust_library.bzl", + symbol_names = ["rust_library"], + deps = [":all_docs"], +) + +stardoc( + name = "rust_library_group", + out = "src/rust_library_group.md", + input = "@rules_rust//rust:rust_library_group.bzl", + symbol_names = ["rust_library_group"], + deps = [":all_docs"], +) + +stardoc( + name = "rust_lint_config", + out = "src/rust_lint_config.md", + input = "@rules_rust//rust:rust_lint_config.bzl", + symbol_names = ["rust_lint_config"], + deps = [":all_docs"], +) + +stardoc( + name = "rust_proc_macro", + out = "src/rust_proc_macro.md", + input = "@rules_rust//rust:rust_proc_macro.bzl", + symbol_names = ["rust_proc_macro"], + deps = [":all_docs"], +) + +stardoc( + name = "rust_shared_library", + out = "src/rust_shared_library.md", + input = "@rules_rust//rust:rust_shared_library.bzl", + symbol_names = ["rust_shared_library"], + deps = [":all_docs"], +) + +stardoc( + name = "rust_static_library", + out = "src/rust_static_library.md", + input = "@rules_rust//rust:rust_static_library.bzl", + symbol_names = ["rust_static_library"], + deps = [":all_docs"], +) + +stardoc( + name = "rust_test", + out = "src/rust_test.md", + input = "@rules_rust//rust:rust_test.bzl", + symbol_names = ["rust_test"], + deps = [":all_docs"], +) + +stardoc( + name = "rust_test_suite", + out = "src/rust_test_suite.md", + input = "@rules_rust//rust:rust_test_suite.bzl", + symbol_names = ["rust_test_suite"], deps = [":all_docs"], ) @@ -72,19 +132,22 @@ stardoc( name = "rust_bzlmod", out = "src/rust_bzlmod.md", input = "@rules_rust//rust:extensions.bzl", - table_of_contents_template = "@stardoc//stardoc:templates/markdown_tables/table_of_contents.vm", deps = [":all_docs"], ) stardoc( name = "rust_unpretty", out = "src/rust_unpretty.md", - input = "@rules_rust//rust:defs.bzl", - symbol_names = [ - "rust_unpretty_aspect", - "rust_unpretty", - ], - table_of_contents_template = "@stardoc//stardoc:templates/markdown_tables/table_of_contents.vm", + input = "@rules_rust//rust:rust_unpretty.bzl", + symbol_names = ["rust_unpretty"], + deps = [":all_docs"], +) + +stardoc( + name = "rust_unpretty_aspect", + out = "src/rust_unpretty_aspect.md", + input = "@rules_rust//rust:rust_unpretty_aspect.bzl", + symbol_names = ["rust_unpretty_aspect"], deps = [":all_docs"], ) @@ -97,59 +160,94 @@ stardoc( "DepInfo", "StdLibInfo", ], - table_of_contents_template = "@stardoc//stardoc:templates/markdown_tables/table_of_contents.vm", deps = [":all_docs"], ) stardoc( name = "rust_clippy", out = "src/rust_clippy.md", - header_template = ":rust_clippy.vm", - input = "@rules_rust//rust:defs.bzl", - symbol_names = [ - "rust_clippy", - "rust_clippy_aspect", - "rust_clippy_test", - ], - table_of_contents_template = "@stardoc//stardoc:templates/markdown_tables/table_of_contents.vm", + input = "@rules_rust//rust:rust_clippy.bzl", + symbol_names = ["rust_clippy"], + deps = [":all_docs"], +) + +stardoc( + name = "rust_clippy_aspect", + out = "src/rust_clippy_aspect.md", + input = "@rules_rust//rust:rust_clippy_aspect.bzl", + symbol_names = ["rust_clippy_aspect"], + deps = [":all_docs"], +) + +stardoc( + name = "rust_clippy_test", + out = "src/rust_clippy_test.md", + input = "@rules_rust//rust:rust_clippy_test.bzl", + symbol_names = ["rust_clippy_test"], deps = [":all_docs"], ) stardoc( name = "rust_doc", out = "src/rust_doc.md", - input = "@rules_rust//rust:defs.bzl", - symbol_names = [ - "rust_doc", - "rust_doc_test", - ], - table_of_contents_template = "@stardoc//stardoc:templates/markdown_tables/table_of_contents.vm", + input = "@rules_rust//rust:rust_doc.bzl", + symbol_names = ["rust_doc"], deps = [":all_docs"], ) stardoc( - name = "rust_fmt", - out = "src/rust_fmt.md", - header_template = ":rust_fmt.vm", - input = "@rules_rust//rust:defs.bzl", - symbol_names = [ - "rustfmt_aspect", - "rustfmt_test", - ], - table_of_contents_template = "@stardoc//stardoc:templates/markdown_tables/table_of_contents.vm", + name = "rust_doc_test", + out = "src/rust_doc_test.md", + input = "@rules_rust//rust:rust_doc_test.bzl", + symbol_names = ["rust_doc_test"], deps = [":all_docs"], ) stardoc( - name = "rust_toolchains", - out = "src/rust_toolchains.md", - input = "@rules_rust//rust:toolchain.bzl", - symbol_names = [ - "rust_toolchain", - "rustfmt_toolchain", - "rust_analyzer_toolchain", - ], - table_of_contents_template = "@stardoc//stardoc:templates/markdown_tables/table_of_contents.vm", + name = "rustfmt_aspect", + out = "src/rustfmt_aspect.md", + input = "@rules_rust//rust:rustfmt_aspect.bzl", + symbol_names = ["rustfmt_aspect"], + deps = [":all_docs"], +) + +stardoc( + name = "rustfmt_test", + out = "src/rustfmt_test.md", + input = "@rules_rust//rust:rustfmt_test.bzl", + symbol_names = ["rustfmt_test"], + deps = [":all_docs"], +) + +stardoc( + name = "rust_toolchain", + out = "src/rust_toolchain.md", + input = "@rules_rust//rust:rust_toolchain.bzl", + symbol_names = ["rust_toolchain"], + deps = [":all_docs"], +) + +stardoc( + name = "rustfmt_toolchain", + out = "src/rustfmt_toolchain.md", + input = "@rules_rust//rust:rustfmt_toolchain.bzl", + symbol_names = ["rustfmt_toolchain"], + deps = [":all_docs"], +) + +stardoc( + name = "rust_analyzer_toolchain", + out = "src/rust_analyzer_toolchain.md", + input = "@rules_rust//rust:rust_analyzer_toolchain.bzl", + symbol_names = ["rust_analyzer_toolchain"], + deps = [":all_docs"], +) + +stardoc( + name = "rust_stdlib_filegroup", + out = "src/rust_stdlib_filegroup.md", + input = "@rules_rust//rust:rust_stdlib_filegroup.bzl", + symbol_names = ["rust_stdlib_filegroup"], deps = [":all_docs"], ) @@ -237,24 +335,42 @@ stardoc( mdbook( name = "book", srcs = glob(["src/**/*.md"]) + [ - ":cargo", + ":cargo_build_script", + ":cargo_env", ":cargo_settings", ":crate_universe_bzlmod", ":crate_universe_workspace", + ":extract_cargo_lints", ":providers", - ":rust", + ":rust_analyzer_toolchain", + ":rust_binary", ":rust_bindgen", ":rust_bzlmod", ":rust_clippy", + ":rust_clippy_aspect", + ":rust_clippy_test", ":rust_doc", - ":rust_fmt", + ":rust_doc_test", + ":rust_library", + ":rust_library_group", + ":rust_lint_config", ":rust_mdbook", + ":rust_proc_macro", ":rust_prost", ":rust_pyo3", ":rust_settings", - ":rust_toolchains", + ":rust_shared_library", + ":rust_static_library", + ":rust_stdlib_filegroup", + ":rust_test", + ":rust_test_suite", + ":rust_toolchain", ":rust_unpretty", + ":rust_unpretty_aspect", ":rust_wasm_bindgen", + ":rustfmt_aspect", + ":rustfmt_test", + ":rustfmt_toolchain", ], book = "book.toml", ) diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index 4d30988c07..ed984eaee0 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -6,16 +6,41 @@ - [Rules](./rules.md) - [rust](./rust.md) - - [clippy](./rust_clippy.md) - - [rustfmt](./rust_fmt.md) - - [rustdoc](./rust_doc.md) + - [rust_binary](./rust_binary.md) + - [rust_library](./rust_library.md) + - [rust_library_group](./rust_library_group.md) + - [rust_lint_config](./rust_lint_config.md) + - [rust_proc_macro](./rust_proc_macro.md) + - [rust_shared_library](./rust_shared_library.md) + - [rust_static_library](./rust_static_library.md) + - [rust_test](./rust_test.md) + - [rust_test_suite](./rust_test_suite.md) + - [clippy](./clippy.md) + - [rust_clippy](./rust_clippy.md) + - [rust_clippy_aspect](./rust_clippy_aspect.md) + - [rust_clippy_test](./rust_clippy_test.md) + - [rustfmt](./rustfmt.md) + - [rustfmt_aspect](./rustfmt_aspect.md) + - [rustfmt_test](./rustfmt_test.md) + - [rustdoc](./rustdoc.md) + - [rust_doc](./rust_doc.md) + - [rust_doc_test](./rust_doc_test.md) - [cargo](./cargo.md) + - [cargo_build_script](./cargo_build_script.md) + - [cargo_env](./cargo_env.md) + - [extract_cargo_lints](./extract_cargo_lints.md) - [rust_analyzer](./rust_analyzer.md) - - [unpretty](./rust_unpretty.md) + - [unpretty](./unpretty.md) + - [rust_unpretty](./rust_unpretty.md) + - [rust_unpretty_aspect](./rust_unpretty_aspect.md) - [Settings](./settings.md) - [Rust Settings](./rust_settings.md) - [Cargo Settings](./cargo_settings.md) - [Toolchains](./rust_toolchains.md) + - [rust_toolchain](./rust_toolchain.md) + - [rustfmt_toolchain](./rustfmt_toolchain.md) + - [rust_analyzer_toolchain](./rust_analyzer_toolchain.md) + - [rust_stdlib_filegroup](./rust_stdlib_filegroup.md) - [Bzlmod](./rust_bzlmod.md) - [External Crates](./external_crates.md) - [crate_universe](crate_universe_bzlmod.md) diff --git a/docs/src/cargo.md b/docs/src/cargo.md new file mode 100644 index 0000000000..2caf9b0e83 --- /dev/null +++ b/docs/src/cargo.md @@ -0,0 +1,21 @@ +# Cargo + +Rules for interoperating with tooling from the [Cargo][cargo] ecosystem — most +importantly, Cargo [`build.rs` scripts][build_scripts]. These rules let a Bazel +build consume the same crate-side conventions that Cargo uses (build scripts, +generated env vars, `[lints]` tables) without switching build systems. + +[cargo]: https://doc.rust-lang.org/cargo/ +[build_scripts]: https://doc.rust-lang.org/cargo/reference/build-scripts.html + +## Rules + +- [cargo_build_script](./cargo_build_script.md) — Compile and run a crate's + `build.rs` at build time, then feed the emitted `cargo:*` directives (env vars, + link args, rerun-if-changed inputs) into consumers of the crate. +- [cargo_env](./cargo_env.md) — Helper that returns Cargo's standard + `CARGO_*` env-var dict, used by rules that need to reproduce Cargo's + compilation environment. +- [extract_cargo_lints](./extract_cargo_lints.md) — Read the `[lints]` table + from a `Cargo.toml` and produce a [`rust_lint_config`](./rust_lint_config.md) + target from it, so Cargo-defined lints apply to Bazel-built crates. diff --git a/docs/rust_clippy.vm b/docs/src/clippy.md similarity index 52% rename from docs/rust_clippy.vm rename to docs/src/clippy.md index 2576175099..405f59f0b4 100644 --- a/docs/rust_clippy.vm +++ b/docs/src/clippy.md @@ -1,6 +1,4 @@ -#[[ -## Overview -]]# +# Clippy [Clippy][clippy] is a tool for catching common mistakes in Rust code and improving it. An expansive list of lints and the justification can be found in their [documentation][docs]. @@ -8,9 +6,7 @@ expansive list of lints and the justification can be found in their [documentati [clippy]: https://github.com/rust-lang/rust-clippy#readme [docs]: https://rust-lang.github.io/rust-clippy/ -#[[ -### Setup -]]# +## Setup Simply add the following to the `.bazelrc` file in the root of your workspace: @@ -19,14 +15,23 @@ build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect build --output_groups=+clippy_checks ``` -This will enable clippy on all [Rust targets](./defs.md). +This will enable clippy on all [Rust targets](./rust.md). -Note that targets tagged with `no-clippy` will not perform clippy checks +Note that targets tagged with `no-clippy` will not perform clippy checks. -To use a local clippy.toml, add the following flag to your `.bazelrc`. Note that due to +To use a local `clippy.toml`, add the following flag to your `.bazelrc`. Note that due to the upstream implementation of clippy, this file must be named either `.clippy.toml` or `clippy.toml`. Using a custom config file requires Rust 1.34.0 or newer. ```text build --@rules_rust//rust/settings:clippy.toml=//:clippy.toml ``` + +## Rules + +- [rust_clippy](./rust_clippy.md) — Rule that runs `clippy-driver` against a Rust target and + fails the build on lint findings. Attach one per target for explicit gating. +- [rust_clippy_aspect](./rust_clippy_aspect.md) — Aspect form of the above. Attach in + `.bazelrc` (as shown in Setup) to run clippy across every Rust target in the build. +- [rust_clippy_test](./rust_clippy_test.md) — Test rule that reports clippy findings as + test failures, useful in CI where a failing test is more visible than a failing build. diff --git a/docs/src/rules.md b/docs/src/rules.md index 66c5e743ea..4f4a982a63 100644 --- a/docs/src/rules.md +++ b/docs/src/rules.md @@ -1,9 +1,9 @@ # Rules -- [defs](defs.md): standard rust rules for building and testing libraries and binaries. -- [rustdoc](rust_doc.md): rules for generating and testing rust documentation. -- [clippy](rust_clippy.md): rules for running [clippy](https://github.com/rust-lang/rust-clippy#readme). -- [rustfmt](rust_fmt.md): rules for running [rustfmt](https://github.com/rust-lang/rustfmt#readme). +- [rust](rust.md): standard rust rules for building and testing libraries and binaries. +- [rustdoc](rustdoc.md): rules for generating and testing rust documentation. +- [clippy](clippy.md): rules for running [clippy](https://github.com/rust-lang/rust-clippy#readme). +- [rustfmt](rustfmt.md): rules for running [rustfmt](https://github.com/rust-lang/rustfmt#readme). - [cargo](cargo.md): Rules dedicated to Cargo compatibility. ie: [`build.rs` scripts](https://doc.rust-lang.org/cargo/reference/build-scripts.html). - [crate_universe](external_crates.md): Rules for generating Bazel targets for external crate dependencies. diff --git a/docs/src/rust.md b/docs/src/rust.md new file mode 100644 index 0000000000..0ca031a7da --- /dev/null +++ b/docs/src/rust.md @@ -0,0 +1,58 @@ +# Rust rules + +The core Rust rules for building and testing libraries, binaries, and procedural +macros. Each rule is documented on its own page; this page is an overview of what +each rule does and when to use it. + +All rules are loadable from `@rules_rust//rust:defs.bzl` or from their individual +`.bzl` file (e.g. `@rules_rust//rust:rust_binary.bzl`). Loading from the +individual file is preferred for new code. + +## Core rules + +The rules below are the primary entry points for compiling Rust code. They map +directly to the crate types Cargo produces. + +- [rust_binary](./rust_binary.md) — Build a Rust executable (`--crate-type=bin`). +- [rust_library](./rust_library.md) — Build an `rlib` (`--crate-type=lib`) that + other Rust targets can depend on. +- [rust_static_library](./rust_static_library.md) — Build a `staticlib` + (`--crate-type=staticlib`) for linking Rust code into a C/C++ binary. +- [rust_shared_library](./rust_shared_library.md) — Build a `cdylib` + (`--crate-type=cdylib`) for use as a shared library from C/C++ or other + languages. +- [rust_proc_macro](./rust_proc_macro.md) — Build a procedural macro crate + (`--crate-type=proc-macro`) that other Rust targets can consume as a compile-time + plugin. +- [rust_test](./rust_test.md) — Compile and run a Rust test binary. Can wrap a + `rust_library`/`rust_binary` (via `crate = ...`) to run its inline `#[test]`s, + or compile a standalone test binary from its own `srcs`. + +## Additional rules + +Non-core rules that ship in the same ruleset: + +- [rust_library_group](./rust_library_group.md) — Group several `rust_library` + targets so they can be depended on as a single unit without generating an + intermediate `rlib`. +- [rust_lint_config](./rust_lint_config.md) — Declare a reusable set of `rustc`, + `clippy`, and `rustdoc` lint levels that can be attached to other rules via + their `lint_config` attribute. +- [rust_test_suite](./rust_test_suite.md) — Convenience macro that expands into + one `rust_test` per source file, sharing a common set of dependencies. Useful + for `tests/**.rs` layouts that mirror Cargo's integration-test directory. + +## Related pages + +Rules that layer on top of the core rules live on their own pages: + +- [rustdoc](./rustdoc.md) — Generate and test Rust documentation. +- [clippy](./clippy.md) — Run [Clippy](https://github.com/rust-lang/rust-clippy) + over Rust targets. +- [rustfmt](./rustfmt.md) — Run [rustfmt](https://github.com/rust-lang/rustfmt) + over Rust targets. +- [unpretty](./unpretty.md) — Emit `rustc -Zunpretty=...` output for a crate. +- [cargo](./cargo.md) — `cargo_build_script` and related Cargo-compatibility rules. +- [rust_analyzer](./rust_analyzer.md) — Generate a `rust-project.json` file for + the [rust-analyzer](https://rust-analyzer.github.io) IDE server. +- [Rust Toolchains](./rust_toolchains.md) — Declare and register Rust toolchains. diff --git a/docs/src/rust_toolchains.md b/docs/src/rust_toolchains.md new file mode 100644 index 0000000000..a3f4ba364e --- /dev/null +++ b/docs/src/rust_toolchains.md @@ -0,0 +1,30 @@ +# Toolchains + +A Rust build in Bazel selects its compiler, standard library, and companion tools +through a set of registered [Bazel toolchains][bazel_toolchains]. `rules_rust` +ships one toolchain type per companion tool so that Rust, `rust-analyzer`, and +`rustfmt` can be resolved independently. + +[bazel_toolchains]: https://bazel.build/extending/toolchains + +Most users register toolchains via the `rust` module extension (see +[Bzlmod](./rust_bzlmod.md)) rather than declaring these rules directly. The rules +below exist for users who need to define custom toolchains — for example, to point +at a locally built `rustc` or to add a target triple that the extension doesn't +cover. + +## Toolchain rules + +- [rust_toolchain](./rust_toolchain.md) — Declare a Rust compilation toolchain: the + `rustc` binary, standard library, linker, and per-target compilation settings. +- [rustfmt_toolchain](./rustfmt_toolchain.md) — Declare a toolchain providing the + `rustfmt` binary used by [rustfmt](./rustfmt.md) rules. +- [rust_analyzer_toolchain](./rust_analyzer_toolchain.md) — Declare a toolchain + providing the `rust-analyzer` binary and proc-macro server used by the + [rust_analyzer](./rust_analyzer.md) integration. + +## Data rules + +- [rust_stdlib_filegroup](./rust_stdlib_filegroup.md) — Group the files of a Rust + standard library archive into a target that can be attached to a + `rust_toolchain` via the `rust_std` attribute. diff --git a/docs/src/rustdoc.md b/docs/src/rustdoc.md new file mode 100644 index 0000000000..fe936fa35d --- /dev/null +++ b/docs/src/rustdoc.md @@ -0,0 +1,18 @@ +# Rustdoc + +[Rustdoc][rustdoc] is Rust's built-in documentation generator. It reads the `///` +and `//!` doc comments in your source and produces browsable HTML — the same +tooling that generates the [standard library docs][std_docs] and every crate on +[docs.rs][docs_rs]. + +[rustdoc]: https://doc.rust-lang.org/rustdoc/ +[std_docs]: https://doc.rust-lang.org/std/ +[docs_rs]: https://docs.rs/ + +## Rules + +- [rust_doc](./rust_doc.md) — Build HTML documentation for a `rust_library`, + `rust_binary`, or `rust_proc_macro` target. Output is a directory tree suitable + for hosting on a static site. +- [rust_doc_test](./rust_doc_test.md) — Compile and run the code samples embedded + in a crate's doc comments as tests, matching Cargo's `cargo test --doc` behavior. diff --git a/docs/rust_fmt.vm b/docs/src/rustfmt.md similarity index 64% rename from docs/rust_fmt.vm rename to docs/src/rustfmt.md index 5175352575..bfef5fb2a8 100644 --- a/docs/rust_fmt.vm +++ b/docs/src/rustfmt.md @@ -1,45 +1,49 @@ -#[[ -## Overview -]]# +# Rustfmt [Rustfmt][rustfmt] is a tool for formatting Rust code according to style guidelines. By default, Rustfmt uses a style which conforms to the [Rust style guide][rsg] that has been formalized through the [style RFC process][rfcp]. A complete list of all configuration options can be found in the [Rustfmt GitHub Pages][rgp]. +[rustfmt]: https://github.com/rust-lang/rustfmt#readme +[rsg]: https://github.com/rust-lang-nursery/fmt-rfcs/blob/master/guide/guide.md +[rfcp]: https://github.com/rust-lang-nursery/fmt-rfcs +[rgp]: https://rust-lang.github.io/rustfmt/ -#[[ -### Setup -]]# +## Setup Formatting your Rust targets' source code requires no setup outside of loading `rules_rust` in your workspace. Simply run `bazel run @rules_rust//:rustfmt` to format source code. -In addition to this formatter, a simple check can be performed using the [rustfmt_aspect](#rustfmt-aspect) aspect by running +In addition to this formatter, a simple check can be performed using the +[rustfmt_aspect](./rustfmt_aspect.md) aspect by running: + ```text bazel build --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect --output_groups=rustfmt_checks ``` -Add the following to a `.bazelrc` file to enable this check during the build phase. +Add the following to a `.bazelrc` file to enable this check during the build phase: ```text build --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect build --output_groups=+rustfmt_checks ``` -It's recommended to only enable this aspect in your CI environment so formatting issues do not -impact user's ability to rapidly iterate on changes. +It's recommended to only enable this aspect in your CI environment so formatting issues do +not impact users' ability to rapidly iterate on changes. -The `rustfmt_aspect` also uses a `--@rules_rust//rust/settings:rustfmt.toml` setting which determines the -[configuration file][rgp] used by the formatter (`@rules_rust//tools/rustfmt`) and the aspect -(`rustfmt_aspect`). This flag can be added to your `.bazelrc` file to ensure a consistent config +The `rustfmt_aspect` also uses a `--@rules_rust//rust/settings:rustfmt.toml` setting which +determines the [configuration file][rgp] used by the formatter (`@rules_rust//tools/rustfmt`) +and the aspect. This flag can be added to your `.bazelrc` file to ensure a consistent config file is used whenever `rustfmt` is run: ```text build --@rules_rust//rust/settings:rustfmt.toml=//:rustfmt.toml ``` -[rustfmt]: https://github.com/rust-lang/rustfmt#readme -[rsg]: https://github.com/rust-lang-nursery/fmt-rfcs/blob/master/guide/guide.md -[rfcp]: https://github.com/rust-lang-nursery/fmt-rfcs -[rgp]: https://rust-lang.github.io/rustfmt/ +## Rules + +- [rustfmt_aspect](./rustfmt_aspect.md) — Aspect that runs `rustfmt --check` on every Rust + target in the build. Attach in `.bazelrc` (as shown in Setup) to gate CI on formatting. +- [rustfmt_test](./rustfmt_test.md) — Test rule that reports rustfmt findings as a test + failure for a specific target. diff --git a/docs/src/unpretty.md b/docs/src/unpretty.md new file mode 100644 index 0000000000..10e032f109 --- /dev/null +++ b/docs/src/unpretty.md @@ -0,0 +1,21 @@ +# Unpretty + +The unpretty rules expose `rustc`'s [`-Zunpretty=`][unpretty] flag as a +Bazel action. Given a Rust target, they emit an alternate textual representation +of it — the fully macro-expanded source, the HIR, the MIR CFG, etc. — useful for +inspecting what the compiler sees after macro expansion, lowering, or +optimization. + +Because `-Zunpretty` is a nightly-only compiler flag, these rules require a +nightly `rust_toolchain` to be registered. + +[unpretty]: https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/unpretty.html + +## Rules + +- [rust_unpretty](./rust_unpretty.md) — Rule form. Explicitly declare an unpretty + target that emits the chosen representation for a specific crate. +- [rust_unpretty_aspect](./rust_unpretty_aspect.md) — Aspect form. Attach at the + command line (`--aspects=@rules_rust//rust:defs.bzl%rust_unpretty_aspect + --output_groups=+rust_unpretty`) to emit the representation for every Rust + target in the build without adding rule instances. diff --git a/extensions/bindgen/private/bindgen.bzl b/extensions/bindgen/private/bindgen.bzl index 988d356e0e..4c730b9138 100644 --- a/extensions/bindgen/private/bindgen.bzl +++ b/extensions/bindgen/private/bindgen.bzl @@ -504,8 +504,8 @@ rust_bindgen_toolchain = rule( The tools required for the `rust_bindgen` rule. This rule depends on the [`bindgen`](https://crates.io/crates/bindgen) binary crate, and it -in turn depends on both a clang binary and the clang library. To obtain these dependencies, -`rust_bindgen_dependencies` imports bindgen and its dependencies. +in turn depends on both a clang binary and the clang library. These dependencies are provided +by the `@rules_rust_bindgen` module extension when using Bzlmod. ```python load("@rules_rust_bindgen//:defs.bzl", "rust_bindgen_toolchain") diff --git a/extensions/prost/private/prost.bzl b/extensions/prost/private/prost.bzl index 4eecf85a06..c59dcb27a3 100644 --- a/extensions/prost/private/prost.bzl +++ b/extensions/prost/private/prost.bzl @@ -501,7 +501,7 @@ rust_prost_toolchain = rule( doc = "Additional options to add to Prost.", ), "prost_plugin": attr.label( - doc = "Additional plugins to add to Prost.", + doc = "The Prost `protoc` plugin (e.g. `protoc-gen-prost`) to invoke.", cfg = "exec", executable = True, mandatory = True, @@ -530,7 +530,7 @@ rust_prost_toolchain = rule( doc = "Additional options to add to Tonic.", ), "tonic_plugin": attr.label( - doc = "Additional plugins to add to Tonic.", + doc = "The Tonic `protoc` plugin (e.g. `protoc-gen-tonic`) to invoke.", cfg = "exec", executable = True, ), diff --git a/extensions/prost/private/prost_transform.bzl b/extensions/prost/private/prost_transform.bzl index 8b672bb7f0..cd9345054e 100644 --- a/extensions/prost/private/prost_transform.bzl +++ b/extensions/prost/private/prost_transform.bzl @@ -57,7 +57,7 @@ proto_library( "a.proto", ], data = [ - ":transform", + ":a_transform", ], ) diff --git a/extensions/pyo3/private/internal_extensions_dev.bzl b/extensions/pyo3/private/internal_extensions_dev.bzl index bcfd7db8b9..c32777b14c 100644 --- a/extensions/pyo3/private/internal_extensions_dev.bzl +++ b/extensions/pyo3/private/internal_extensions_dev.bzl @@ -21,6 +21,6 @@ def _rust_ext_dev_impl(module_ctx): ) rust_ext_dev = module_extension( - doc = "Development dependencies for the rules_rust_wasm_bindgen extension.", + doc = "Development dependencies for the rules_rust_pyo3 extension.", implementation = _rust_ext_dev_impl, ) diff --git a/extensions/wasm_bindgen/private/wasm_bindgen.bzl b/extensions/wasm_bindgen/private/wasm_bindgen.bzl index e53dd3b879..7fe697bcee 100644 --- a/extensions/wasm_bindgen/private/wasm_bindgen.bzl +++ b/extensions/wasm_bindgen/private/wasm_bindgen.bzl @@ -13,8 +13,8 @@ def rust_wasm_bindgen_action(*, ctx, toolchain, wasm_file, target_output, flags Args: ctx (ctx): The rule's context object. toolchain (ToolchainInfo): The current `rust_wasm_bindgen_toolchain`. - wasm_file (Target): The target representing the `.wasm` file. - target_output (str): _description_ + wasm_file (list of Target): A single-element list containing the target representing the `.wasm` file. The attribute is a `list` because it is behind `wasm_bindgen_transition`. + target_output (str): The wasm-bindgen `--target` output type (e.g. `bundler`, `web`, `nodejs`, `no-modules`, `deno`). flags (list, optional): Flags to pass to `wasm-bindgen`. Returns: diff --git a/rust/defs.bzl b/rust/defs.bzl index a33ecc492a..426c743846 100644 --- a/rust/defs.bzl +++ b/rust/defs.bzl @@ -14,6 +14,50 @@ """Public entry point to all Rust rules and supported APIs.""" +load( + "//rust:rust_clippy.bzl", + _rust_clippy = "rust_clippy", +) +load( + "//rust:rust_clippy_aspect.bzl", + _rust_clippy_aspect = "rust_clippy_aspect", +) +load( + "//rust:rust_clippy_test.bzl", + _rust_clippy_test = "rust_clippy_test", +) +load( + "//rust:rust_doc.bzl", + _rust_doc = "rust_doc", +) +load( + "//rust:rust_doc_test.bzl", + _rust_doc_test = "rust_doc_test", +) +load( + "//rust:rust_lint_config.bzl", + _rust_lint_config = "rust_lint_config", +) +load( + "//rust:rust_test_suite.bzl", + _rust_test_suite = "rust_test_suite", +) +load( + "//rust:rust_unpretty.bzl", + _rust_unpretty = "rust_unpretty", +) +load( + "//rust:rust_unpretty_aspect.bzl", + _rust_unpretty_aspect = "rust_unpretty_aspect", +) +load( + "//rust:rustfmt_aspect.bzl", + _rustfmt_aspect = "rustfmt_aspect", +) +load( + "//rust:rustfmt_test.bzl", + _rustfmt_test = "rustfmt_test", +) load( "//rust:toolchain.bzl", _rust_stdlib_filegroup = "rust_stdlib_filegroup", @@ -24,16 +68,9 @@ load( _clippy_flag = "clippy_flag", _clippy_flags = "clippy_flags", _get_clippy_ready_crate_info = "get_clippy_ready_crate_info", - _rust_clippy = "rust_clippy", _rust_clippy_action = "rust_clippy_action", - _rust_clippy_aspect = "rust_clippy_aspect", - _rust_clippy_test = "rust_clippy_test", ) load("//rust/private:common.bzl", _rust_common = "rust_common") -load( - "//rust/private:lints.bzl", - _rust_lint_config = "rust_lint_config", -) load( "//rust/private:rust.bzl", _rust_binary = "rust_binary", @@ -43,7 +80,6 @@ load( _rust_shared_library = "rust_shared_library", _rust_static_library = "rust_static_library", _rust_test = "rust_test", - _rust_test_suite = "rust_test_suite", ) load( "//rust/private:rust_analyzer.bzl", @@ -60,24 +96,6 @@ load( _per_crate_rustc_flag = "per_crate_rustc_flag", _rustc_output_diagnostics = "rustc_output_diagnostics", ) -load( - "//rust/private:rustdoc.bzl", - _rust_doc = "rust_doc", -) -load( - "//rust/private:rustdoc_test.bzl", - _rust_doc_test = "rust_doc_test", -) -load( - "//rust/private:rustfmt.bzl", - _rustfmt_aspect = "rustfmt_aspect", - _rustfmt_test = "rustfmt_test", -) -load( - "//rust/private:unpretty.bzl", - _rust_unpretty = "rust_unpretty", - _rust_unpretty_aspect = "rust_unpretty_aspect", -) rust_library = _rust_library # See @rules_rust//rust/private:rust.bzl for a complete description. diff --git a/rust/extensions.bzl b/rust/extensions.bzl index 44601533f8..5e77821146 100644 --- a/rust/extensions.bzl +++ b/rust/extensions.bzl @@ -173,7 +173,7 @@ _COMMON_TAG_KWARGS = { ), "edition": attr.string( doc = ( - "The rust edition to be used by default (2015, 2018, or 2021). " + + "The rust edition to be used by default (2015, 2018, 2021, or 2024). " + "If absent, every rule is required to specify its `edition` attribute." ), ), @@ -272,6 +272,7 @@ _RUST_TOOLCHAIN_TAG = tag_class( doc = "Extra flags to pass to rustc in non-exec configuration. Key is the triple, value is the flag.", ), "extra_target_triples": attr.string_list( + doc = "Additional Rust target triples to fetch and register toolchains for.", default = DEFAULT_EXTRA_TARGET_TRIPLES, ), "opt_level": attr.string_dict( diff --git a/rust/platform/triple_mappings.bzl b/rust/platform/triple_mappings.bzl index 7be462fd12..b94608276f 100644 --- a/rust/platform/triple_mappings.bzl +++ b/rust/platform/triple_mappings.bzl @@ -430,7 +430,7 @@ def triple_to_abi(target_triple): """ if type(target_triple) == "string": target_triple = triple(target_triple) - return target_triple.system + return target_triple.abi def system_to_dylib_ext(system): return _SYSTEM_TO_DYLIB_EXT[system] @@ -442,14 +442,14 @@ def system_to_binary_ext(system): return _SYSTEM_TO_BINARY_EXT[system] def system_to_stdlib_linkflags(system, abi = None): - """_summary_ + """Return the stdlib linker flags for the given system (and optional abi). Args: - system (_type_): _description_ - abi (_type_, optional): _description_. Defaults to None. + system (str): The system component of a Rust target triple (e.g. `linux`, `windows`, `darwin`). + abi (str, optional): The ABI component of the triple, used to select flag variants on systems (like `windows`) whose stdlib flags depend on the ABI. Returns: - _type_: _description_ + list: A list of linker flag strings to pass to the linker for the given system/abi. """ flags = _SYSTEM_TO_STDLIB_LINKFLAGS[system] if type(flags) == "list": diff --git a/rust/private/lints.bzl b/rust/private/lints.bzl index dfaa316f08..b1c250e17a 100644 --- a/rust/private/lints.bzl +++ b/rust/private/lints.bzl @@ -53,16 +53,16 @@ rust_lint_config = rule( implementation = _rust_lint_config, attrs = { "rustc": attr.string_dict( - doc = "Set of 'rustc' lints to 'allow', 'expect', 'warn', 'force-warn', 'deny', or 'forbid'.", + doc = "Set of 'rustc' lints to 'allow', 'warn', 'force-warn', 'deny', or 'forbid'.", ), "rustc_check_cfg": attr.string_list_dict( doc = "Set of 'cfg' names and list of values to expect.", ), "clippy": attr.string_dict( - doc = "Set of 'clippy' lints to 'allow', 'expect', 'warn', 'force-warn', 'deny', or 'forbid'.", + doc = "Set of 'clippy' lints to 'allow', 'warn', 'force-warn', 'deny', or 'forbid'.", ), "rustdoc": attr.string_dict( - doc = "Set of 'rustdoc' lints to 'allow', 'expect', 'warn', 'force-warn', 'deny', or 'forbid'.", + doc = "Set of 'rustdoc' lints to 'allow', 'warn', 'force-warn', 'deny', or 'forbid'.", ), }, doc = """\ diff --git a/rust/private/lto.bzl b/rust/private/lto.bzl index 58c610936b..cf8e271c4c 100644 --- a/rust/private/lto.bzl +++ b/rust/private/lto.bzl @@ -38,7 +38,7 @@ def _rust_lto_flag_impl(ctx): return RustLtoInfo(mode = value) rust_lto_flag = rule( - doc = "A build setting which specifies the link time optimization mode used when building Rust code. Allowed values are: ".format(_LTO_MODES), + doc = "A build setting which specifies the link time optimization mode used when building Rust code. Allowed values are: {}".format(_LTO_MODES), implementation = _rust_lto_flag_impl, build_setting = config.string(flag = True), ) diff --git a/rust/private/repository_utils.bzl b/rust/private/repository_utils.bzl index e28165c7a8..f8e3a6de69 100644 --- a/rust/private/repository_utils.bzl +++ b/rust/private/repository_utils.bzl @@ -105,7 +105,7 @@ def BUILD_for_compiler(target_triple, include_linker = False, include_objcopy = """Emits a BUILD file the compiler archive. Args: - target_triple (str): The triple of the target platform + target_triple (struct): The triple of the target platform include_linker (bool): Whether to generate targets for linkers. include_objcopy (bool): Whether to generate targets for rust-objcopy. @@ -150,7 +150,7 @@ def BUILD_for_cargo(target_triple): """Emits a BUILD file the cargo archive. Args: - target_triple (str): The triple of the target platform + target_triple (struct): The triple of the target platform Returns: str: The contents of a BUILD file @@ -171,7 +171,7 @@ def BUILD_for_rust_analyzer(target_triple): """Emits a BUILD file for the rust-analyzer archive. Args: - target_triple (str): The triple of the target platform + target_triple (struct): The triple of the target platform Returns: str: The contents of a BUILD file @@ -200,7 +200,7 @@ def BUILD_for_rustfmt(target_triple): """Emits a BUILD file the rustfmt archive. Args: - target_triple (str): The triple of the target platform + target_triple (struct): The triple of the target platform Returns: str: The contents of a BUILD file @@ -221,7 +221,7 @@ def BUILD_for_rust_analyzer_proc_macro_srv(exec_triple): """Emits a BUILD file the rust_analyzer_proc_macro_srv archive. Args: - exec_triple (str): The triple of the exec platform + exec_triple (struct): The triple of the exec platform Returns: str: The contents of a BUILD file """ @@ -246,7 +246,7 @@ def BUILD_for_clippy(target_triple): """Emits a BUILD file the clippy archive. Args: - target_triple (str): The triple of the target platform + target_triple (struct): The triple of the target platform Returns: str: The contents of a BUILD file @@ -936,7 +936,7 @@ def load_arbitrary_tool( Args: ctx (repository_ctx): A repository_ctx (no attrs required). tool_name (str): The name of the given tool per the archive naming. - tool_subdirectories (str): The subdirectories of the tool files (at a level below the root directory of + tool_subdirectories (list of str): The subdirectories of the tool files (at a level below the root directory of the archive). The root directory of the archive is expected to match $TOOL_NAME-$VERSION-$TARGET_TRIPLE. Example: diff --git a/rust/private/rust_allocator_libraries.bzl b/rust/private/rust_allocator_libraries.bzl index 4667faa090..7e2571b8bc 100644 --- a/rust/private/rust_allocator_libraries.bzl +++ b/rust/private/rust_allocator_libraries.bzl @@ -291,7 +291,7 @@ rust_allocator_libraries = rule( providers = [AllocatorLibrariesImplInfo], ), "global_allocator_library": attr.label( - doc = "An optional library to provide when a default rust allocator is used.", + doc = "An optional library to provide when a global rust allocator is used.", providers = [AllocatorLibrariesImplInfo], ), }, diff --git a/rust/private/rustfmt.bzl b/rust/private/rustfmt.bzl index 1227970d7c..55e0b56b9f 100644 --- a/rust/private/rustfmt.bzl +++ b/rust/private/rustfmt.bzl @@ -17,7 +17,7 @@ def _get_rustfmt_ready_crate_info(target): target (Target): The target the aspect is running on. Returns: - CrateInfo, optional: A `CrateInfo` provider if clippy should be run or `None`. + CrateInfo, optional: A `CrateInfo` provider if rustfmt should be run or `None`. """ # Ignore external targets diff --git a/rust/private/toolchain.bzl b/rust/private/toolchain.bzl index 8effcbca4e..2443446669 100644 --- a/rust/private/toolchain.bzl +++ b/rust/private/toolchain.bzl @@ -693,7 +693,7 @@ rust_toolchain = rule( cfg = "exec", ), "debug_info": attr.string_dict( - doc = "Rustc debug info levels per opt level", + doc = "Rustc debug info levels per compilation mode (keyed by `dbg`, `fastbuild`, `opt`).", default = { "dbg": "2", "fastbuild": "0", diff --git a/rust/private/unpretty.bzl b/rust/private/unpretty.bzl index 1868a54daa..a58563f429 100644 --- a/rust/private/unpretty.bzl +++ b/rust/private/unpretty.bzl @@ -354,7 +354,7 @@ rust_unpretty( ":hello_lib", ":greeting_test", ], - mode = "expand", + mode = "expanded", ) ``` """, diff --git a/rust/rust_analyzer_toolchain.bzl b/rust/rust_analyzer_toolchain.bzl index f2d26fe0f3..7c10422f8e 100644 --- a/rust/rust_analyzer_toolchain.bzl +++ b/rust/rust_analyzer_toolchain.bzl @@ -1,4 +1,4 @@ -"""# Rust Analyzer Toolchain""" +"""# rust_analyzer_toolchain.bzl""" load( "//rust/private:rust_analyzer.bzl", diff --git a/rust/rust_binary.bzl b/rust/rust_binary.bzl index dbeba03911..dd67917e6b 100644 --- a/rust/rust_binary.bzl +++ b/rust/rust_binary.bzl @@ -1,4 +1,4 @@ -"""rust_binary""" +"""# rust_binary.bzl""" load( "//rust/private:rust.bzl", diff --git a/rust/rust_clippy.bzl b/rust/rust_clippy.bzl new file mode 100644 index 0000000000..da4fb2e7db --- /dev/null +++ b/rust/rust_clippy.bzl @@ -0,0 +1,8 @@ +"""# rust_clippy.bzl""" + +load( + "//rust/private:clippy.bzl", + _rust_clippy = "rust_clippy", +) + +rust_clippy = _rust_clippy diff --git a/rust/rust_clippy_aspect.bzl b/rust/rust_clippy_aspect.bzl new file mode 100644 index 0000000000..7a3b1db617 --- /dev/null +++ b/rust/rust_clippy_aspect.bzl @@ -0,0 +1,8 @@ +"""# rust_clippy_aspect.bzl""" + +load( + "//rust/private:clippy.bzl", + _rust_clippy_aspect = "rust_clippy_aspect", +) + +rust_clippy_aspect = _rust_clippy_aspect diff --git a/rust/rust_clippy_test.bzl b/rust/rust_clippy_test.bzl new file mode 100644 index 0000000000..f17daf0d85 --- /dev/null +++ b/rust/rust_clippy_test.bzl @@ -0,0 +1,8 @@ +"""# rust_clippy_test.bzl""" + +load( + "//rust/private:clippy.bzl", + _rust_clippy_test = "rust_clippy_test", +) + +rust_clippy_test = _rust_clippy_test diff --git a/rust/rust_doc.bzl b/rust/rust_doc.bzl new file mode 100644 index 0000000000..91f46f920f --- /dev/null +++ b/rust/rust_doc.bzl @@ -0,0 +1,8 @@ +"""# rust_doc.bzl""" + +load( + "//rust/private:rustdoc.bzl", + _rust_doc = "rust_doc", +) + +rust_doc = _rust_doc diff --git a/rust/rust_doc_test.bzl b/rust/rust_doc_test.bzl new file mode 100644 index 0000000000..1e1980af67 --- /dev/null +++ b/rust/rust_doc_test.bzl @@ -0,0 +1,8 @@ +"""# rust_doc_test.bzl""" + +load( + "//rust/private:rustdoc_test.bzl", + _rust_doc_test = "rust_doc_test", +) + +rust_doc_test = _rust_doc_test diff --git a/rust/rust_library.bzl b/rust/rust_library.bzl index b1e63494a6..f101216b38 100644 --- a/rust/rust_library.bzl +++ b/rust/rust_library.bzl @@ -1,4 +1,4 @@ -"""rust_library""" +"""# rust_library.bzl""" load( "//rust/private:rust.bzl", diff --git a/rust/rust_library_group.bzl b/rust/rust_library_group.bzl index bbfa71b1e1..65be843044 100644 --- a/rust/rust_library_group.bzl +++ b/rust/rust_library_group.bzl @@ -1,4 +1,4 @@ -"""rust_library_group""" +"""# rust_library_group.bzl""" load( "//rust/private:rust.bzl", diff --git a/rust/rust_lint_config.bzl b/rust/rust_lint_config.bzl new file mode 100644 index 0000000000..e5d1f43a59 --- /dev/null +++ b/rust/rust_lint_config.bzl @@ -0,0 +1,8 @@ +"""# rust_lint_config.bzl""" + +load( + "//rust/private:lints.bzl", + _rust_lint_config = "rust_lint_config", +) + +rust_lint_config = _rust_lint_config diff --git a/rust/rust_proc_macro.bzl b/rust/rust_proc_macro.bzl index 96d6fad093..e5bac73ca8 100644 --- a/rust/rust_proc_macro.bzl +++ b/rust/rust_proc_macro.bzl @@ -1,4 +1,4 @@ -"""rust_proc_macro""" +"""# rust_proc_macro.bzl""" load( "//rust/private:rust.bzl", diff --git a/rust/rust_shared_library.bzl b/rust/rust_shared_library.bzl index 109346bac9..665d85699e 100644 --- a/rust/rust_shared_library.bzl +++ b/rust/rust_shared_library.bzl @@ -1,4 +1,4 @@ -"""rust_shared_library""" +"""# rust_shared_library.bzl""" load( "//rust/private:rust.bzl", diff --git a/rust/rust_static_library.bzl b/rust/rust_static_library.bzl index d5c1c2b1f2..e1427124d4 100644 --- a/rust/rust_static_library.bzl +++ b/rust/rust_static_library.bzl @@ -1,4 +1,4 @@ -"""rust_static_library""" +"""# rust_static_library.bzl""" load( "//rust/private:rust.bzl", diff --git a/rust/rust_stdlib_filegroup.bzl b/rust/rust_stdlib_filegroup.bzl index 05eecb98f4..a472d88575 100644 --- a/rust/rust_stdlib_filegroup.bzl +++ b/rust/rust_stdlib_filegroup.bzl @@ -1,8 +1,4 @@ -"""# Rust Stdlib Filegroup - -Public entry point for the [rust_stdlib_filegroup](#rust_stdlib_filegroup) rule. -Implementation lives in `//rust/private:toolchain.bzl`. -""" +"""# rust_stdlib_filegroup.bzl""" load( "//rust/private:toolchain.bzl", diff --git a/rust/rust_test.bzl b/rust/rust_test.bzl index 001963fccc..5c4dcf7a45 100644 --- a/rust/rust_test.bzl +++ b/rust/rust_test.bzl @@ -1,4 +1,4 @@ -"""rust_test""" +"""# rust_test.bzl""" load( "//rust/private:rust.bzl", diff --git a/rust/rust_test_suite.bzl b/rust/rust_test_suite.bzl new file mode 100644 index 0000000000..a0a5fd049d --- /dev/null +++ b/rust/rust_test_suite.bzl @@ -0,0 +1,8 @@ +"""# rust_test_suite.bzl""" + +load( + "//rust/private:rust.bzl", + _rust_test_suite = "rust_test_suite", +) + +rust_test_suite = _rust_test_suite diff --git a/rust/rust_toolchain.bzl b/rust/rust_toolchain.bzl index eadd47ca0e..3ad889bfd2 100644 --- a/rust/rust_toolchain.bzl +++ b/rust/rust_toolchain.bzl @@ -1,8 +1,4 @@ -"""# Rust Toolchain - -Public entry point for the [rust_toolchain](#rust_toolchain) rule. -Implementation lives in `//rust/private:toolchain.bzl`. -""" +"""# rust_toolchain.bzl""" load( "//rust/private:toolchain.bzl", diff --git a/rust/rust_unpretty.bzl b/rust/rust_unpretty.bzl new file mode 100644 index 0000000000..badaf4a2b8 --- /dev/null +++ b/rust/rust_unpretty.bzl @@ -0,0 +1,8 @@ +"""# rust_unpretty.bzl""" + +load( + "//rust/private:unpretty.bzl", + _rust_unpretty = "rust_unpretty", +) + +rust_unpretty = _rust_unpretty diff --git a/rust/rust_unpretty_aspect.bzl b/rust/rust_unpretty_aspect.bzl new file mode 100644 index 0000000000..f749eba4ae --- /dev/null +++ b/rust/rust_unpretty_aspect.bzl @@ -0,0 +1,8 @@ +"""# rust_unpretty_aspect.bzl""" + +load( + "//rust/private:unpretty.bzl", + _rust_unpretty_aspect = "rust_unpretty_aspect", +) + +rust_unpretty_aspect = _rust_unpretty_aspect diff --git a/rust/rustfmt_aspect.bzl b/rust/rustfmt_aspect.bzl new file mode 100644 index 0000000000..2971dc157e --- /dev/null +++ b/rust/rustfmt_aspect.bzl @@ -0,0 +1,8 @@ +"""# rustfmt_aspect.bzl""" + +load( + "//rust/private:rustfmt.bzl", + _rustfmt_aspect = "rustfmt_aspect", +) + +rustfmt_aspect = _rustfmt_aspect diff --git a/rust/rustfmt_test.bzl b/rust/rustfmt_test.bzl new file mode 100644 index 0000000000..68580e7779 --- /dev/null +++ b/rust/rustfmt_test.bzl @@ -0,0 +1,8 @@ +"""# rustfmt_test.bzl""" + +load( + "//rust/private:rustfmt.bzl", + _rustfmt_test = "rustfmt_test", +) + +rustfmt_test = _rustfmt_test diff --git a/rust/rustfmt_toolchain.bzl b/rust/rustfmt_toolchain.bzl index ebce2d58d8..8c570e092f 100644 --- a/rust/rustfmt_toolchain.bzl +++ b/rust/rustfmt_toolchain.bzl @@ -1,4 +1,4 @@ -"""# Rustfmt Toolchain""" +"""# rustfmt_toolchain.bzl""" load( "//rust/private:rustfmt.bzl", diff --git a/rust/settings/settings.bzl b/rust/settings/settings.bzl index a25281e10e..02f455d7f4 100644 --- a/rust/settings/settings.bzl +++ b/rust/settings/settings.bzl @@ -49,7 +49,6 @@ def unpretty(): - `hir,identified` - `hir,typed` - `hir` - - `identified` - `mir-cfg` - `mir` - `normal` diff --git a/tools/rust_analyzer/env_file.bzl b/tools/rust_analyzer/env_file.bzl index 5e1f6abcbd..2c95732b75 100644 --- a/tools/rust_analyzer/env_file.bzl +++ b/tools/rust_analyzer/env_file.bzl @@ -45,9 +45,10 @@ env_file = rule( doc = """\ Emit a one-line `KEY=${pwd}/\\n` file suitable for `rust_library`'s `rustc_env_files` attribute. The path is generated through `Args.add_all`'s -`format_each` so Bazel's path mapping (`--experimental_output_paths=strip`) -rewrites it before the action runs, and the `${pwd}` prefix is later resolved -to the exec_root by `process_wrapper`'s env-block substitution. +`map_each` (via the `_arg_map_pair` callback) so Bazel's path mapping +(`--experimental_output_paths=strip`) rewrites it before the action runs, and +the `${pwd}` prefix is later resolved to the exec_root by `process_wrapper`'s +env-block substitution. Pair with a matching `compile_data = [src]` on the consumer crate and use `include_str!(env!("KEY"))` in Rust to embed the file's content at compile