Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add rust_lint_group and cargo_lints rule to define lint groups #2993

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ load("//crate_universe/tools/cross_installer:cross_installer_deps.bzl", "cross_i

cross_installer_deps()

load("//cargo/private/cargo_toml_info/3rdparty/crates:defs.bzl", cargo_toml_info_crate_repositories = "crate_repositories")

cargo_toml_info_crate_repositories()

# buildifier: disable=bzl-visibility
load("@rules_rust//proto/prost/private:repositories.bzl", "rust_prost_dependencies", "rust_prost_register_toolchains")

Expand Down
6 changes: 6 additions & 0 deletions cargo/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ load(
"//cargo/private:cargo_dep_env.bzl",
_cargo_dep_env = "cargo_dep_env",
)
load(
"//cargo/private:cargo_lints.bzl",
_extract_cargo_lints = "extract_cargo_lints",
)

cargo_bootstrap_repository = _cargo_bootstrap_repository
cargo_env = _cargo_env

cargo_build_script = _cargo_build_script
cargo_dep_env = _cargo_dep_env

extract_cargo_lints = _extract_cargo_lints
73 changes: 73 additions & 0 deletions cargo/private/cargo_lints.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""
Rule used to retrieve the lints specified in the [lints section] of a `Cargo.toml`.

[lints section](https://doc.rust-lang.org/cargo/reference/manifest.html#the-lints-section)
"""

load("//rust/private:providers.bzl", "LintsInfo")

def _extract_cargo_lints(ctx):
# Cargo.toml's to read from.
inputs = [ctx.file.manifest]
args = ctx.actions.args()

args.add("--manifest_toml={0}".format(ctx.file.manifest.path))
if ctx.attr.workspace:
inputs.append(ctx.file.workspace)
args.add("--workspace_toml={0}".format(ctx.file.workspace.path))
args.add("lints")

# Files to output our formatted arguments into.
rustc_lints_out = ctx.actions.declare_file(ctx.label.name + ".rustc" + ".lints")
rustc_check_cfg_out = ctx.actions.declare_file(ctx.label.name + ".rustc_check_cfg" + ".lints")
clippy_lints_out = ctx.actions.declare_file(ctx.label.name + ".clippy" + ".lints")
rustdoc_lints_out = ctx.actions.declare_file(ctx.label.name + ".rustdoc" + ".lints")

args.add(rustc_lints_out)
args.add(rustc_check_cfg_out)
args.add(clippy_lints_out)
args.add(rustdoc_lints_out)

outputs = [rustc_lints_out, rustc_check_cfg_out, clippy_lints_out, rustdoc_lints_out]

ctx.actions.run(
outputs = outputs,
executable = ctx.file._cargo_toml_info,
inputs = inputs,
arguments = [args],
mnemonic = "CargoLints",
progress_message = "Reading Cargo metadata to get Lints for {}".format(ctx.attr.name),
)

return [
DefaultInfo(files = depset(outputs), runfiles = ctx.runfiles(outputs)),
LintsInfo(
rustc_lint_flags = [],
rustc_lint_files = [rustc_lints_out],
clippy_lint_flags = [],
clippy_lint_files = [clippy_lints_out],
rustdoc_lint_flags = [],
rustdoc_lint_files = [rustdoc_lints_out],
)
]

extract_cargo_lints = rule(
implementation = _extract_cargo_lints,
attrs = {
"manifest": attr.label(
allow_single_file = True,
mandatory = True,
doc = "Cargo.toml to read lints from.",
),
"workspace": attr.label(
allow_single_file = True,
doc = "Workspace Cargo.toml that the manifest Cargo.toml inherits from.",
),
"_cargo_toml_info": attr.label(
allow_single_file = True,
executable = True,
default = "@rules_rust//cargo/private/cargo_toml_info",
cfg = "exec",
),
},
)
12 changes: 12 additions & 0 deletions cargo/private/cargo_toml_info/3rdparty/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("//crate_universe:defs.bzl", "crate", "crates_vendor")

crates_vendor(
name = "crates_vendor",
cargo_lockfile = "Cargo.Bazel.lock",
mode = "remote",
packages = {
"cargo_toml": crate.spec(version = "0.20.5"),
},
repository_name = "rules_rust_cargo_toml_info",
tags = ["manual"],
)
155 changes: 155 additions & 0 deletions cargo/private/cargo_toml_info/3rdparty/Cargo.Bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions cargo/private/cargo_toml_info/3rdparty/crates/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
###############################################################################
# @generated
# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To
# regenerate this file, run the following:
#
# bazel run @//cargo/private/cargo_toml_info/3rdparty:crates_vendor
###############################################################################

package(default_visibility = ["//visibility:public"])

exports_files(
[
"cargo-bazel.json",
"crates.bzl",
"defs.bzl",
] + glob(
include = ["*.bazel"],
allow_empty = True,
),
)

filegroup(
name = "srcs",
srcs = glob(
include = [
"*.bazel",
"*.bzl",
],
allow_empty = True,
),
)

# Workspace Member Dependencies
alias(
name = "cargo_toml",
actual = "@rules_rust_cargo_toml_info__cargo_toml-0.20.5//:cargo_toml",
tags = ["manual"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
###############################################################################
# @generated
# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To
# regenerate this file, run the following:
#
# bazel run @//cargo/private/cargo_toml_info/3rdparty:crates_vendor
###############################################################################

load("@rules_rust//rust:defs.bzl", "rust_library")

package(default_visibility = ["//visibility:public"])

rust_library(
name = "cargo_toml",
srcs = glob(
include = ["**/*.rs"],
allow_empty = True,
),
compile_data = glob(
include = ["**"],
allow_empty = True,
exclude = [
"**/* *",
".tmp_git_root/**/*",
"BUILD",
"BUILD.bazel",
"WORKSPACE",
"WORKSPACE.bazel",
],
),
crate_root = "src/cargo_toml.rs",
edition = "2021",
rustc_flags = [
"--cap-lints=allow",
],
tags = [
"cargo-bazel",
"crate-name=cargo_toml",
"manual",
"noclippy",
"norustfmt",
],
target_compatible_with = select({
"@rules_rust//rust/platform:aarch64-apple-darwin": [],
"@rules_rust//rust/platform:aarch64-apple-ios": [],
"@rules_rust//rust/platform:aarch64-apple-ios-sim": [],
"@rules_rust//rust/platform:aarch64-linux-android": [],
"@rules_rust//rust/platform:aarch64-pc-windows-msvc": [],
"@rules_rust//rust/platform:aarch64-unknown-fuchsia": [],
"@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [],
"@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [],
"@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [],
"@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [],
"@rules_rust//rust/platform:armv7-linux-androideabi": [],
"@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [],
"@rules_rust//rust/platform:i686-apple-darwin": [],
"@rules_rust//rust/platform:i686-linux-android": [],
"@rules_rust//rust/platform:i686-pc-windows-msvc": [],
"@rules_rust//rust/platform:i686-unknown-freebsd": [],
"@rules_rust//rust/platform:i686-unknown-linux-gnu": [],
"@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [],
"@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [],
"@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [],
"@rules_rust//rust/platform:s390x-unknown-linux-gnu": [],
"@rules_rust//rust/platform:thumbv7em-none-eabi": [],
"@rules_rust//rust/platform:thumbv8m.main-none-eabi": [],
"@rules_rust//rust/platform:wasm32-unknown-unknown": [],
"@rules_rust//rust/platform:wasm32-wasi": [],
"@rules_rust//rust/platform:wasm32-wasip1": [],
"@rules_rust//rust/platform:x86_64-apple-darwin": [],
"@rules_rust//rust/platform:x86_64-apple-ios": [],
"@rules_rust//rust/platform:x86_64-linux-android": [],
"@rules_rust//rust/platform:x86_64-pc-windows-msvc": [],
"@rules_rust//rust/platform:x86_64-unknown-freebsd": [],
"@rules_rust//rust/platform:x86_64-unknown-fuchsia": [],
"@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [],
"@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [],
"@rules_rust//rust/platform:x86_64-unknown-none": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
version = "0.20.5",
deps = [
"@rules_rust_cargo_toml_info__serde-1.0.214//:serde",
"@rules_rust_cargo_toml_info__toml-0.8.19//:toml",
],
)
Loading
Loading