Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 1 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") |
Adam Snaider | 1c095c9 | 2023-07-08 02:09:58 -0400 | [diff] [blame] | 2 | load("@bazel_skylib//rules:common_settings.bzl", "string_flag") |
| 3 | load( |
| 4 | "//rust:defs.bzl", |
| 5 | "capture_clippy_output", |
| 6 | "clippy_flags", |
| 7 | "error_format", |
| 8 | "extra_exec_rustc_flag", |
| 9 | "extra_exec_rustc_flags", |
| 10 | "extra_rustc_flag", |
| 11 | "extra_rustc_flags", |
| 12 | "is_proc_macro_dep", |
| 13 | "is_proc_macro_dep_enabled", |
| 14 | "no_std", |
| 15 | "per_crate_rustc_flag", |
| 16 | ) |
Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 17 | |
| 18 | exports_files(["LICENSE"]) |
| 19 | |
| 20 | bzl_library( |
| 21 | name = "bzl_lib", |
| 22 | srcs = [ |
Adam Snaider | 1c095c9 | 2023-07-08 02:09:58 -0400 | [diff] [blame] | 23 | ":version.bzl", |
Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 24 | ], |
| 25 | visibility = ["//visibility:public"], |
| 26 | ) |
| 27 | |
Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 28 | # This setting may be changed from the command line to generate machine readable errors. |
| 29 | error_format( |
| 30 | name = "error_format", |
| 31 | build_setting_default = "human", |
| 32 | visibility = ["//visibility:public"], |
| 33 | ) |
| 34 | |
Brian Silverman | 5f6f276 | 2022-08-13 19:30:05 -0700 | [diff] [blame] | 35 | # This setting may be used to pass extra options to clippy from the command line. |
| 36 | # It applies across all targets. |
| 37 | clippy_flags( |
| 38 | name = "clippy_flags", |
| 39 | build_setting_default = [], |
| 40 | visibility = ["//visibility:public"], |
| 41 | ) |
| 42 | |
| 43 | # This setting may be used to identify dependencies of proc-macro-s. |
| 44 | # This feature is only enabled if `is_proc_macro_dep_enabled` is true. |
| 45 | # Its value controls the BAZEL_RULES_RUST_IS_PROC_MACRO_DEP environment variable |
| 46 | # made available to the rustc invocation. |
| 47 | is_proc_macro_dep( |
| 48 | name = "is_proc_macro_dep", |
| 49 | build_setting_default = False, |
| 50 | visibility = ["//visibility:public"], |
| 51 | ) |
| 52 | |
| 53 | # This setting enables the feature to identify dependencies of proc-macro-s, |
| 54 | # see `is_proc_macro_dep`. |
| 55 | is_proc_macro_dep_enabled( |
| 56 | name = "is_proc_macro_dep_enabled", |
| 57 | build_setting_default = False, |
| 58 | visibility = ["//visibility:public"], |
| 59 | ) |
| 60 | |
Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 61 | # This setting may be used to pass extra options to rustc from the command line |
| 62 | # in non-exec configuration. |
| 63 | # It applies across all targets whereas the rustc_flags option on targets applies only |
| 64 | # to that target. This can be useful for passing build-wide options such as LTO. |
| 65 | extra_rustc_flags( |
| 66 | name = "extra_rustc_flags", |
| 67 | build_setting_default = [], |
| 68 | visibility = ["//visibility:public"], |
| 69 | ) |
| 70 | |
Brian Silverman | 5f6f276 | 2022-08-13 19:30:05 -0700 | [diff] [blame] | 71 | extra_rustc_flag( |
| 72 | name = "extra_rustc_flag", |
| 73 | build_setting_default = "", |
| 74 | visibility = ["//visibility:public"], |
| 75 | ) |
| 76 | |
Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 77 | # This setting may be used to pass extra options to rustc from the command line |
| 78 | # in exec configuration. |
| 79 | # It applies across all targets whereas the rustc_flags option on targets applies only |
| 80 | # to that target. This can be useful for passing build-wide options such as LTO. |
| 81 | extra_exec_rustc_flags( |
| 82 | name = "extra_exec_rustc_flags", |
| 83 | build_setting_default = [], |
| 84 | visibility = ["//visibility:public"], |
| 85 | ) |
| 86 | |
Brian Silverman | 5f6f276 | 2022-08-13 19:30:05 -0700 | [diff] [blame] | 87 | extra_exec_rustc_flag( |
| 88 | name = "extra_exec_rustc_flag", |
| 89 | build_setting_default = "", |
| 90 | visibility = ["//visibility:public"], |
| 91 | ) |
| 92 | |
Adam Snaider | 1c095c9 | 2023-07-08 02:09:58 -0400 | [diff] [blame] | 93 | per_crate_rustc_flag( |
| 94 | name = "experimental_per_crate_rustc_flag", |
| 95 | build_setting_default = "", |
| 96 | visibility = ["//visibility:public"], |
| 97 | ) |
| 98 | |
Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 99 | # This setting is used by the clippy rules. See https://bazelbuild.github.io/rules_rust/rust_clippy.html |
| 100 | label_flag( |
| 101 | name = "clippy.toml", |
| 102 | build_setting_default = "//tools/clippy:clippy.toml", |
| 103 | visibility = ["//visibility:public"], |
| 104 | ) |
| 105 | |
| 106 | # This setting is used by the rustfmt rules. See https://bazelbuild.github.io/rules_rust/rust_fmt.html |
| 107 | label_flag( |
| 108 | name = "rustfmt.toml", |
| 109 | build_setting_default = "//tools/rustfmt:rustfmt.toml", |
| 110 | visibility = ["//visibility:public"], |
| 111 | ) |
| 112 | |
| 113 | alias( |
| 114 | name = "rustfmt", |
| 115 | actual = "//tools/rustfmt", |
| 116 | visibility = ["//visibility:public"], |
| 117 | ) |
| 118 | |
| 119 | capture_clippy_output( |
| 120 | name = "capture_clippy_output", |
| 121 | build_setting_default = False, |
| 122 | visibility = ["//visibility:public"], |
| 123 | ) |
Adam Snaider | 1c095c9 | 2023-07-08 02:09:58 -0400 | [diff] [blame] | 124 | |
| 125 | # This setting may be used to enable builds without the standard library. |
| 126 | # Currently only no_std + alloc is supported, which can be enabled with setting the value to "alloc". |
| 127 | # In the future we could add support for additional modes, e.g "core", "alloc,collections". |
| 128 | string_flag( |
| 129 | name = "no_std", |
| 130 | build_setting_default = "off", |
| 131 | values = [ |
| 132 | "alloc", |
| 133 | "off", |
| 134 | ], |
| 135 | visibility = ["//visibility:public"], |
| 136 | ) |
| 137 | |
| 138 | # A hack target to allow as to only apply the no_std mode in target config. |
| 139 | no_std( |
| 140 | name = "build_target_in_no_std", |
| 141 | ) |
| 142 | |
| 143 | # A config setting for setting conditional `cargo_features`, `deps`, based on the `:no_std` value. |
| 144 | config_setting( |
| 145 | name = "is_no_std", |
| 146 | flag_values = { |
| 147 | ":build_target_in_no_std": "alloc", |
| 148 | }, |
| 149 | visibility = ["//visibility:public"], |
| 150 | ) |