Skip to content

Commit c939956

Browse files
authored
Merge branch 'main' into rust_v1.93.0
2 parents 7875e9b + 9586468 commit c939956

File tree

5 files changed

+9
-66
lines changed

5 files changed

+9
-66
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
This repository provides rules for building [Rust](https://www.rust-lang.org/) projects with [Bazel](https://bazel.build/).
88

9+
### Starter repo
10+
11+
The fastest way to try this in an empty project is to click the green "Use this template" button on https://github.com/bazel-starters/rust.
12+
913
## Community
1014

1115
General discussions and announcements take place in the [GitHub Discussions](https://github.com/bazelbuild/rules_rust/discussions), but there are

rust/private/BUILD.bazel

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
22
load("//rust/private:rust_analyzer.bzl", "rust_analyzer_detect_sysroot")
33
load("//rust/private:rustc.bzl", "is_proc_macro_dep", "is_proc_macro_dep_enabled")
4-
load("//rust/private:stamp.bzl", "stamp_build_setting")
54

65
# Exported for docs
76
exports_files(["providers.bzl"])
@@ -33,8 +32,6 @@ bzl_library(
3332
],
3433
)
3534

36-
stamp_build_setting(name = "stamp")
37-
3835
# This setting may be used to identify dependencies of proc-macro-s.
3936
# This feature is only enabled if `is_proc_macro_dep_enabled` is true.
4037
# Its value controls the BAZEL_RULES_RUST_IS_PROC_MACRO_DEP environment variable

rust/private/rust.bzl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -826,10 +826,6 @@ _common_attrs = {
826826
doc = "Enable collection of cfg flags with results stored in CrateInfo.cfgs.",
827827
default = Label("//rust/settings:collect_cfgs"),
828828
),
829-
"_stamp_flag": attr.label(
830-
doc = "A setting used to determine whether or not the `--stamp` flag is enabled",
831-
default = Label("//rust/private:stamp"),
832-
),
833829
} | RUSTC_ATTRS | RUSTC_ALLOCATOR_LIBRARIES_ATTRS
834830

835831
_coverage_attrs = {

rust/private/rustc.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,7 @@ def rustc_compile_action(
13491349
linkstamps = depset([])
13501350

13511351
# Determine if the build is currently running with --stamp
1352-
stamp = is_stamping_enabled(attr)
1352+
stamp = is_stamping_enabled(ctx, attr)
13531353

13541354
# Add flags for any 'rustc' lints that are specified.
13551355
#

rust/private/stamp.bzl

Lines changed: 4 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,10 @@
1-
"""A small utility module dedicated to detecting whether or not the `--stamp` flag is enabled
1+
"""A small utility module dedicated to detecting whether or not the `--stamp` flag is enabled"""
22

3-
This module can be removed likely after the following PRs ar addressed:
4-
- https://github.com/bazelbuild/bazel/issues/11164
5-
"""
6-
7-
load("//rust/private:utils.bzl", "dedent")
8-
9-
StampSettingInfo = provider(
10-
doc = "Information about the `--stamp` command line flag",
11-
fields = {
12-
"value": "bool: Whether or not the `--stamp` flag was enabled",
13-
},
14-
)
15-
16-
def _stamp_build_setting_impl(ctx):
17-
return StampSettingInfo(value = ctx.attr.value)
18-
19-
_stamp_build_setting = rule(
20-
doc = dedent("""\
21-
Whether to encode build information into the binary. Possible values:
22-
23-
- stamp = 1: Always stamp the build information into the binary, even in [--nostamp][stamp] builds. \
24-
This setting should be avoided, since it potentially kills remote caching for the binary and \
25-
any downstream actions that depend on it.
26-
- stamp = 0: Always replace build information by constant values. This gives good build result caching.
27-
- stamp = -1: Embedding of build information is controlled by the [--[no]stamp][stamp] flag.
28-
29-
Stamped binaries are not rebuilt unless their dependencies change.
30-
[stamp]: https://docs.bazel.build/versions/main/user-manual.html#flag--stamp
31-
"""),
32-
implementation = _stamp_build_setting_impl,
33-
attrs = {
34-
"value": attr.bool(
35-
doc = "The default value of the stamp build flag",
36-
mandatory = True,
37-
),
38-
},
39-
)
40-
41-
def stamp_build_setting(name, visibility = ["//visibility:public"]):
42-
native.config_setting(
43-
name = "stamp_detect",
44-
values = {"stamp": "1"},
45-
visibility = visibility,
46-
)
47-
48-
_stamp_build_setting(
49-
name = name,
50-
value = select({
51-
":stamp_detect": True,
52-
"//conditions:default": False,
53-
}),
54-
visibility = visibility,
55-
)
56-
57-
def is_stamping_enabled(attr):
3+
def is_stamping_enabled(ctx, attr):
584
"""Determine whether or not build stamping is enabled
595
606
Args:
7+
ctx (ctx): The rule's context object
618
attr (struct): A rule's struct of attributes (`ctx.attr`)
629
6310
Returns:
@@ -69,7 +16,6 @@ def is_stamping_enabled(attr):
6916
elif stamp_num == 0:
7017
return False
7118
elif stamp_num == -1:
72-
stamp_flag = getattr(attr, "_stamp_flag", None)
73-
return stamp_flag[StampSettingInfo].value if stamp_flag else False
19+
return ctx.configuration.stamp_binaries()
7420
else:
7521
fail("Unexpected `stamp` value: {}".format(stamp_num))

0 commit comments

Comments
 (0)