blob: 2eb9e03a2555ef8bb0389d302043c6c987b20fbf [file] [log] [blame]
Brian Silvermancc09f182022-03-09 15:40:20 -08001load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
Adam Snaider1c095c92023-07-08 02:09:58 -04002load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
3load(
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 Silvermancc09f182022-03-09 15:40:20 -080017
18exports_files(["LICENSE"])
19
20bzl_library(
21 name = "bzl_lib",
22 srcs = [
Adam Snaider1c095c92023-07-08 02:09:58 -040023 ":version.bzl",
Brian Silvermancc09f182022-03-09 15:40:20 -080024 ],
25 visibility = ["//visibility:public"],
26)
27
Brian Silvermancc09f182022-03-09 15:40:20 -080028# This setting may be changed from the command line to generate machine readable errors.
29error_format(
30 name = "error_format",
31 build_setting_default = "human",
32 visibility = ["//visibility:public"],
33)
34
Brian Silverman5f6f2762022-08-13 19:30:05 -070035# This setting may be used to pass extra options to clippy from the command line.
36# It applies across all targets.
37clippy_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.
47is_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`.
55is_proc_macro_dep_enabled(
56 name = "is_proc_macro_dep_enabled",
57 build_setting_default = False,
58 visibility = ["//visibility:public"],
59)
60
Brian Silvermancc09f182022-03-09 15:40:20 -080061# 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.
65extra_rustc_flags(
66 name = "extra_rustc_flags",
67 build_setting_default = [],
68 visibility = ["//visibility:public"],
69)
70
Brian Silverman5f6f2762022-08-13 19:30:05 -070071extra_rustc_flag(
72 name = "extra_rustc_flag",
73 build_setting_default = "",
74 visibility = ["//visibility:public"],
75)
76
Brian Silvermancc09f182022-03-09 15:40:20 -080077# 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.
81extra_exec_rustc_flags(
82 name = "extra_exec_rustc_flags",
83 build_setting_default = [],
84 visibility = ["//visibility:public"],
85)
86
Brian Silverman5f6f2762022-08-13 19:30:05 -070087extra_exec_rustc_flag(
88 name = "extra_exec_rustc_flag",
89 build_setting_default = "",
90 visibility = ["//visibility:public"],
91)
92
Adam Snaider1c095c92023-07-08 02:09:58 -040093per_crate_rustc_flag(
94 name = "experimental_per_crate_rustc_flag",
95 build_setting_default = "",
96 visibility = ["//visibility:public"],
97)
98
Brian Silvermancc09f182022-03-09 15:40:20 -080099# This setting is used by the clippy rules. See https://bazelbuild.github.io/rules_rust/rust_clippy.html
100label_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
107label_flag(
108 name = "rustfmt.toml",
109 build_setting_default = "//tools/rustfmt:rustfmt.toml",
110 visibility = ["//visibility:public"],
111)
112
113alias(
114 name = "rustfmt",
115 actual = "//tools/rustfmt",
116 visibility = ["//visibility:public"],
117)
118
119capture_clippy_output(
120 name = "capture_clippy_output",
121 build_setting_default = False,
122 visibility = ["//visibility:public"],
123)
Adam Snaider1c095c92023-07-08 02:09:58 -0400124
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".
128string_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.
139no_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.
144config_setting(
145 name = "is_no_std",
146 flag_values = {
147 ":build_target_in_no_std": "alloc",
148 },
149 visibility = ["//visibility:public"],
150)