fork/rules_rust

git clone https://git.julia.blue/fork/rules_rust

ajwernerprovide flag to exclude data at compile time (#3005)e61e6e12

main
8.3 KiB263 linesraw
1load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
2load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag")
3load(
4    "//rust:defs.bzl",
5    "capture_clippy_output",
6    "clippy_flag",
7    "clippy_flags",
8    "error_format",
9    "extra_exec_rustc_flag",
10    "extra_exec_rustc_flags",
11    "extra_rustc_flag",
12    "extra_rustc_flags",
13    "no_std",
14    "per_crate_rustc_flag",
15    "rustc_output_diagnostics",
16)
17load("//rust/private:unpretty.bzl", "rust_unpretty_flag")
18load(":incompatible.bzl", "incompatible_flag")
19
20exports_files([
21    ".clippy.toml",
22    ".rustfmt.toml",
23])
24
25bzl_library(
26    name = "bzl_lib",
27    srcs = glob(["**/*.bzl"]),
28    visibility = ["//visibility:public"],
29)
30
31rust_unpretty_flag(
32    name = "unpretty",
33    build_setting_default = [
34        "ast-tree,expanded",
35        "ast-tree",
36        "expanded,hygiene",
37        "expanded,identified",
38        "expanded",
39        "hir-tree",
40        "hir,identified",
41        "hir,typed",
42        "hir",
43        "identified",
44        "mir-cfg",
45        "mir",
46        "normal",
47    ],
48    visibility = ["//visibility:public"],
49)
50
51# A flag controlling whether to rename first-party crates such that their names
52# encode the Bazel package and target name, instead of just the target name.
53#
54# First-party vs. third-party crates are identified using the value of
55# //settings:third_party_dir.
56bool_flag(
57    name = "rename_first_party_crates",
58    build_setting_default = False,
59    visibility = ["//visibility:public"],
60)
61
62# A flag specifying the location of vendored third-party rust crates within this
63# repository that must not be renamed when `rename_first_party_crates` is enabled.
64#
65# Must be specified as a Bazel package, e.g. "//some/location/in/repo".
66string_flag(
67    name = "third_party_dir",
68    build_setting_default = "//third_party/rust",
69    visibility = ["//visibility:public"],
70)
71
72# A flag to control whether rust_library and rust_binary targets should
73# implicitly depend on the *real* import macro, or on a no-op target.
74bool_flag(
75    name = "use_real_import_macro",
76    build_setting_default = False,
77    visibility = ["//visibility:public"],
78)
79
80# When set, this flag causes rustc to emit .rmeta files and use them for rlib -> rlib dependencies.
81# While this involves one extra (short) rustc invocation to build the rmeta file,
82# it allows library dependencies to be unlocked much sooner, increasing parallelism during compilation.
83bool_flag(
84    name = "pipelined_compilation",
85    build_setting_default = False,
86    visibility = ["//visibility:public"],
87)
88
89# A flag to control whether to link rust_binary and rust_test targets using
90# cc_common.link instead of rustc.
91bool_flag(
92    name = "experimental_use_cc_common_link",
93    build_setting_default = False,
94    visibility = ["//visibility:public"],
95)
96
97# A flag to indicate that a global allocator is in use when using --@rules_rust//rust/settings:experimental_use_cc_common_link
98# Users need to specify this flag because rustc generates different set of symbols at link time when a global allocator is in use.
99# When the linking is not done by rustc, the `rust_toolchain` itself provides the appropriate set of symbols.
100bool_flag(
101    name = "experimental_use_global_allocator",
102    build_setting_default = False,
103    visibility = ["//visibility:public"],
104)
105
106# A flag to have coverage tooling added as `coverage_common.instrumented_files_info.metadata_files` instead of
107# reporting tools like `llvm-cov` and `llvm-profdata` as runfiles to each test.
108bool_flag(
109    name = "experimental_use_coverage_metadata_files",
110    build_setting_default = True,
111    visibility = ["//visibility:public"],
112)
113
114# A flag to set rustc --sysroot flag to the sysroot generated by rust_toolchain.
115bool_flag(
116    name = "toolchain_generated_sysroot",
117    build_setting_default = True,
118    visibility = ["//visibility:public"],
119)
120
121# A flag to put rust_test compilation outputs in the same directory as the rust_library compilation outputs.
122incompatible_flag(
123    name = "incompatible_change_rust_test_compilation_output_directory",
124    build_setting_default = False,
125    issue = "https://github.com/bazelbuild/rules_rust/issues/2827",
126    visibility = ["//visibility:public"],
127)
128
129# A flag to control whether to link libstd dynamically.
130bool_flag(
131    name = "experimental_link_std_dylib",
132    build_setting_default = False,
133    visibility = ["//visibility:public"],
134)
135
136# A flag to control whether the shell path from a shell toolchain (`@bazel_tools//tools/sh:toolchain_type`)
137# is embedded into the bootstrap process wrapper for the `.sh` file.
138bool_flag(
139    name = "experimental_use_sh_toolchain_for_bootstrap_process_wrapper",
140    build_setting_default = False,
141    visibility = ["//visibility:public"],
142)
143
144# This setting is used by the clippy rules. See https://bazelbuild.github.io/rules_rust/rust_clippy.html
145label_flag(
146    name = "clippy.toml",
147    build_setting_default = ".clippy.toml",
148    visibility = ["//visibility:public"],
149)
150
151# This setting is used by the rustfmt rules. See https://bazelbuild.github.io/rules_rust/rust_fmt.html
152label_flag(
153    name = "rustfmt.toml",
154    build_setting_default = ".rustfmt.toml",
155    visibility = ["//visibility:public"],
156)
157
158capture_clippy_output(
159    name = "capture_clippy_output",
160    build_setting_default = False,
161    visibility = ["//visibility:public"],
162)
163
164# This setting may be used to enable builds without the standard library.
165# Currently only no_std + alloc is supported, which can be enabled with setting the value to "alloc".
166# In the future we could add support for additional modes, e.g "core", "alloc,collections".
167string_flag(
168    name = "no_std",
169    build_setting_default = "off",
170    values = [
171        "alloc",
172        "off",
173    ],
174    visibility = ["//visibility:public"],
175)
176
177# A hack target to allow as to only apply the no_std mode in target config.
178no_std(
179    name = "build_target_in_no_std",
180)
181
182# A config setting for setting conditional `cargo_features`, `deps`, based on the `:no_std` value.
183config_setting(
184    name = "is_no_std",
185    flag_values = {
186        ":build_target_in_no_std": "alloc",
187    },
188    visibility = ["//visibility:public"],
189)
190
191# This setting may be changed from the command line to generate machine readable errors.
192error_format(
193    name = "error_format",
194    build_setting_default = "human",
195    visibility = ["//visibility:public"],
196)
197
198# This setting may be changed from the command line to generate rustc diagnostics.
199rustc_output_diagnostics(
200    name = "rustc_output_diagnostics",
201    build_setting_default = False,
202    visibility = ["//visibility:public"],
203)
204
205# This setting may be used to pass extra options to clippy from the command line.
206# It applies across all targets.
207clippy_flags(
208    name = "clippy_flags",
209    build_setting_default = [],
210    visibility = ["//visibility:public"],
211)
212
213clippy_flag(
214    name = "clippy_flag",
215    build_setting_default = [],
216    visibility = ["//visibility:public"],
217)
218
219# This setting may be used to pass extra options to rustc from the command line
220# in non-exec configuration.
221# It applies across all targets whereas the rustc_flags option on targets applies only
222# to that target. This can be useful for passing build-wide options such as LTO.
223extra_rustc_flags(
224    name = "extra_rustc_flags",
225    build_setting_default = [],
226    visibility = ["//visibility:public"],
227)
228
229extra_rustc_flag(
230    name = "extra_rustc_flag",
231    build_setting_default = [],
232    visibility = ["//visibility:public"],
233)
234
235# This setting may be used to pass extra options to rustc from the command line
236# in exec configuration.
237# It applies across all targets whereas the rustc_flags option on targets applies only
238# to that target. This can be useful for passing build-wide options such as LTO.
239extra_exec_rustc_flags(
240    name = "extra_exec_rustc_flags",
241    build_setting_default = [],
242    visibility = ["//visibility:public"],
243)
244
245extra_exec_rustc_flag(
246    name = "extra_exec_rustc_flag",
247    build_setting_default = [],
248    visibility = ["//visibility:public"],
249)
250
251per_crate_rustc_flag(
252    name = "experimental_per_crate_rustc_flag",
253    build_setting_default = [],
254    visibility = ["//visibility:public"],
255)
256
257# A flag to control whether to include data files in compile_data.
258incompatible_flag(
259    name = "incompatible_do_not_include_data_in_compile_data",
260    build_setting_default = True,
261    issue = "https://github.com/bazelbuild/rules_rust/issues/2977",
262    visibility = ["//visibility:public"],
263)