diff --git a/tools/clippy/clippy.toml b/.clippy.toml similarity index 100% rename from tools/clippy/clippy.toml rename to .clippy.toml diff --git a/BUILD.bazel b/BUILD.bazel index 27a04d131..3dfbda71d 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,58 +1,36 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") -load("@bazel_skylib//rules:common_settings.bzl", "string_flag") -load( - "//rust:defs.bzl", - "capture_clippy_output", - "clippy_flag", - "clippy_flags", - "error_format", - "extra_exec_rustc_flag", - "extra_exec_rustc_flags", - "extra_rustc_flag", - "extra_rustc_flags", - "no_std", - "per_crate_rustc_flag", - "rustc_output_diagnostics", -) - exports_files([ + ".clippy.toml", + ".rustfmt.toml", "LICENSE", "MODULE.bazel", + "version.bzl", ]) -bzl_library( - name = "bzl_lib", - srcs = [ - ":version.bzl", - ], - visibility = ["//visibility:public"], -) - # This setting may be changed from the command line to generate machine readable errors. -error_format( +alias( name = "error_format", - build_setting_default = "human", + actual = "//rust/settings:error_format", visibility = ["//visibility:public"], ) # This setting may be changed from the command line to generate rustc diagnostics. -rustc_output_diagnostics( +alias( name = "rustc_output_diagnostics", - build_setting_default = False, + actual = "//rust/settings:rustc_output_diagnostics", visibility = ["//visibility:public"], ) # This setting may be used to pass extra options to clippy from the command line. # It applies across all targets. -clippy_flags( +alias( name = "clippy_flags", - build_setting_default = [], + actual = "//rust/settings:clippy_flags", visibility = ["//visibility:public"], ) -clippy_flag( +alias( name = "clippy_flag", - build_setting_default = "", + actual = "//rust/settings:clippy_flag", visibility = ["//visibility:public"], ) @@ -60,15 +38,15 @@ clippy_flag( # in non-exec configuration. # It applies across all targets whereas the rustc_flags option on targets applies only # to that target. This can be useful for passing build-wide options such as LTO. -extra_rustc_flags( +alias( name = "extra_rustc_flags", - build_setting_default = [], + actual = "//rust/settings:extra_rustc_flags", visibility = ["//visibility:public"], ) -extra_rustc_flag( +alias( name = "extra_rustc_flag", - build_setting_default = "", + actual = "//rust/settings:extra_rustc_flag", visibility = ["//visibility:public"], ) @@ -76,35 +54,33 @@ extra_rustc_flag( # in exec configuration. # It applies across all targets whereas the rustc_flags option on targets applies only # to that target. This can be useful for passing build-wide options such as LTO. -extra_exec_rustc_flags( +alias( name = "extra_exec_rustc_flags", - build_setting_default = [], + actual = "//rust/settings:extra_exec_rustc_flags", visibility = ["//visibility:public"], ) -extra_exec_rustc_flag( +alias( name = "extra_exec_rustc_flag", - build_setting_default = "", + actual = "//rust/settings:extra_exec_rustc_flag", visibility = ["//visibility:public"], ) -per_crate_rustc_flag( +alias( name = "experimental_per_crate_rustc_flag", - build_setting_default = "", + actual = "//rust/settings:experimental_per_crate_rustc_flag", visibility = ["//visibility:public"], ) -# This setting is used by the clippy rules. See https://bazelbuild.github.io/rules_rust/rust_clippy.html -label_flag( +alias( name = "clippy.toml", - build_setting_default = "//tools/clippy:clippy.toml", + actual = "//rust/settings:clippy.toml", visibility = ["//visibility:public"], ) -# This setting is used by the rustfmt rules. See https://bazelbuild.github.io/rules_rust/rust_fmt.html -label_flag( +alias( name = "rustfmt.toml", - build_setting_default = "//tools/rustfmt:rustfmt.toml", + actual = "//rust/settings:rustfmt.toml", visibility = ["//visibility:public"], ) @@ -114,35 +90,20 @@ alias( visibility = ["//visibility:public"], ) -capture_clippy_output( +alias( name = "capture_clippy_output", - build_setting_default = False, + actual = "//rust/settings:capture_clippy_output", visibility = ["//visibility:public"], ) -# This setting may be used to enable builds without the standard library. -# Currently only no_std + alloc is supported, which can be enabled with setting the value to "alloc". -# In the future we could add support for additional modes, e.g "core", "alloc,collections". -string_flag( +alias( name = "no_std", - build_setting_default = "off", - values = [ - "alloc", - "off", - ], + actual = "//rust/settings:no_std", visibility = ["//visibility:public"], ) -# A hack target to allow as to only apply the no_std mode in target config. -no_std( - name = "build_target_in_no_std", -) - -# A config setting for setting conditional `cargo_features`, `deps`, based on the `:no_std` value. -config_setting( +alias( name = "is_no_std", - flag_values = { - ":build_target_in_no_std": "alloc", - }, + actual = "//rust/settings:is_no_std", visibility = ["//visibility:public"], ) diff --git a/docs/BUILD.bazel b/docs/BUILD.bazel index 5f22c97de..0f4842b50 100644 --- a/docs/BUILD.bazel +++ b/docs/BUILD.bazel @@ -26,7 +26,6 @@ bzl_library( name = "all_docs", deps = [ ":docs_deps", - "@rules_rust//:bzl_lib", "@rules_rust//bindgen:bzl_lib", "@rules_rust//cargo:bzl_lib", "@rules_rust//crate_universe:bzl_lib", diff --git a/rust/settings/.clippy.toml b/rust/settings/.clippy.toml new file mode 100644 index 000000000..7a4b169c9 --- /dev/null +++ b/rust/settings/.clippy.toml @@ -0,0 +1 @@ +# clippy options: https://rust-lang.github.io/rust-clippy/ diff --git a/tools/rustfmt/rustfmt.toml b/rust/settings/.rustfmt.toml similarity index 100% rename from tools/rustfmt/rustfmt.toml rename to rust/settings/.rustfmt.toml diff --git a/rust/settings/BUILD.bazel b/rust/settings/BUILD.bazel index 3b50985db..2a073f7ae 100644 --- a/rust/settings/BUILD.bazel +++ b/rust/settings/BUILD.bazel @@ -1,13 +1,31 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag") +load( + "//rust:defs.bzl", + "capture_clippy_output", + "clippy_flag", + "clippy_flags", + "error_format", + "extra_exec_rustc_flag", + "extra_exec_rustc_flags", + "extra_rustc_flag", + "extra_rustc_flags", + "no_std", + "per_crate_rustc_flag", + "rustc_output_diagnostics", +) load("//rust/private:unpretty.bzl", "rust_unpretty_flag") load(":incompatible.bzl", "incompatible_flag") -package(default_visibility = ["//visibility:public"]) +exports_files([ + ".clippy.toml", + ".rustfmt.toml", +]) bzl_library( name = "bzl_lib", srcs = glob(["**/*.bzl"]), + visibility = ["//visibility:public"], ) rust_unpretty_flag( @@ -27,6 +45,7 @@ rust_unpretty_flag( "mir", "normal", ], + visibility = ["//visibility:public"], ) # A flag controlling whether to rename first-party crates such that their names @@ -37,6 +56,7 @@ rust_unpretty_flag( bool_flag( name = "rename_first_party_crates", build_setting_default = False, + visibility = ["//visibility:public"], ) # A flag specifying the location of vendored third-party rust crates within this @@ -46,6 +66,7 @@ bool_flag( string_flag( name = "third_party_dir", build_setting_default = "//third_party/rust", + visibility = ["//visibility:public"], ) # A flag to control whether rust_library and rust_binary targets should @@ -53,6 +74,7 @@ string_flag( bool_flag( name = "use_real_import_macro", build_setting_default = False, + visibility = ["//visibility:public"], ) # When set, this flag causes rustc to emit .rmeta files and use them for rlib -> rlib dependencies. @@ -61,6 +83,7 @@ bool_flag( bool_flag( name = "pipelined_compilation", build_setting_default = False, + visibility = ["//visibility:public"], ) # A flag to control whether to link rust_binary and rust_test targets using @@ -68,6 +91,7 @@ bool_flag( bool_flag( name = "experimental_use_cc_common_link", build_setting_default = False, + visibility = ["//visibility:public"], ) # A flag to indicate that a global allocator is in use when using --@rules_rust//rust/settings:experimental_use_cc_common_link @@ -76,6 +100,7 @@ bool_flag( bool_flag( name = "experimental_use_global_allocator", build_setting_default = False, + visibility = ["//visibility:public"], ) # A flag to have coverage tooling added as `coverage_common.instrumented_files_info.metadata_files` instead of @@ -83,12 +108,14 @@ bool_flag( bool_flag( name = "experimental_use_coverage_metadata_files", build_setting_default = True, + visibility = ["//visibility:public"], ) # A flag to set rustc --sysroot flag to the sysroot generated by rust_toolchain. bool_flag( name = "toolchain_generated_sysroot", build_setting_default = True, + visibility = ["//visibility:public"], ) # A flag to put rust_test compilation outputs in the same directory as the rust_library compilation outputs. @@ -96,12 +123,14 @@ incompatible_flag( name = "incompatible_change_rust_test_compilation_output_directory", build_setting_default = False, issue = "https://github.com/bazelbuild/rules_rust/issues/2827", + visibility = ["//visibility:public"], ) # A flag to control whether to link libstd dynamically. bool_flag( name = "experimental_link_std_dylib", build_setting_default = False, + visibility = ["//visibility:public"], ) # A flag to control whether the shell path from a shell toolchain (`@bazel_tools//tools/sh:toolchain_type`) @@ -109,4 +138,118 @@ bool_flag( bool_flag( name = "experimental_use_sh_toolchain_for_bootstrap_process_wrapper", build_setting_default = False, + visibility = ["//visibility:public"], +) + +# This setting is used by the clippy rules. See https://bazelbuild.github.io/rules_rust/rust_clippy.html +label_flag( + name = "clippy.toml", + build_setting_default = ".clippy.toml", + visibility = ["//visibility:public"], +) + +# This setting is used by the rustfmt rules. See https://bazelbuild.github.io/rules_rust/rust_fmt.html +label_flag( + name = "rustfmt.toml", + build_setting_default = ".rustfmt.toml", + visibility = ["//visibility:public"], +) + +capture_clippy_output( + name = "capture_clippy_output", + build_setting_default = False, + visibility = ["//visibility:public"], +) + +# This setting may be used to enable builds without the standard library. +# Currently only no_std + alloc is supported, which can be enabled with setting the value to "alloc". +# In the future we could add support for additional modes, e.g "core", "alloc,collections". +string_flag( + name = "no_std", + build_setting_default = "off", + values = [ + "alloc", + "off", + ], + visibility = ["//visibility:public"], +) + +# A hack target to allow as to only apply the no_std mode in target config. +no_std( + name = "build_target_in_no_std", +) + +# A config setting for setting conditional `cargo_features`, `deps`, based on the `:no_std` value. +config_setting( + name = "is_no_std", + flag_values = { + ":build_target_in_no_std": "alloc", + }, + visibility = ["//visibility:public"], +) + +# This setting may be changed from the command line to generate machine readable errors. +error_format( + name = "error_format", + build_setting_default = "human", + visibility = ["//visibility:public"], +) + +# This setting may be changed from the command line to generate rustc diagnostics. +rustc_output_diagnostics( + name = "rustc_output_diagnostics", + build_setting_default = False, + visibility = ["//visibility:public"], +) + +# This setting may be used to pass extra options to clippy from the command line. +# It applies across all targets. +clippy_flags( + name = "clippy_flags", + build_setting_default = [], + visibility = ["//visibility:public"], +) + +clippy_flag( + name = "clippy_flag", + build_setting_default = "", + visibility = ["//visibility:public"], +) + +# This setting may be used to pass extra options to rustc from the command line +# in non-exec configuration. +# It applies across all targets whereas the rustc_flags option on targets applies only +# to that target. This can be useful for passing build-wide options such as LTO. +extra_rustc_flags( + name = "extra_rustc_flags", + build_setting_default = [], + visibility = ["//visibility:public"], +) + +extra_rustc_flag( + name = "extra_rustc_flag", + build_setting_default = "", + visibility = ["//visibility:public"], +) + +# This setting may be used to pass extra options to rustc from the command line +# in exec configuration. +# It applies across all targets whereas the rustc_flags option on targets applies only +# to that target. This can be useful for passing build-wide options such as LTO. +extra_exec_rustc_flags( + name = "extra_exec_rustc_flags", + build_setting_default = [], + visibility = ["//visibility:public"], +) + +extra_exec_rustc_flag( + name = "extra_exec_rustc_flag", + build_setting_default = "", + visibility = ["//visibility:public"], +) + +per_crate_rustc_flag( + name = "experimental_per_crate_rustc_flag", + build_setting_default = "", + visibility = ["//visibility:public"], )