Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions rust/private/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("//rust/private:rust_analyzer.bzl", "rust_analyzer_detect_sysroot")
load("//rust/private:rustc.bzl", "is_proc_macro_dep", "is_proc_macro_dep_enabled")
load("//rust/private:stamp.bzl", "stamp_build_setting")

# Exported for docs
exports_files(["providers.bzl"])
Expand Down Expand Up @@ -33,8 +32,6 @@ bzl_library(
],
)

stamp_build_setting(name = "stamp")

# This setting may be used to identify dependencies of proc-macro-s.
# This feature is only enabled if `is_proc_macro_dep_enabled` is true.
# Its value controls the BAZEL_RULES_RUST_IS_PROC_MACRO_DEP environment variable
Expand Down
4 changes: 0 additions & 4 deletions rust/private/rust.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -826,10 +826,6 @@ _common_attrs = {
doc = "Enable collection of cfg flags with results stored in CrateInfo.cfgs.",
default = Label("//rust/settings:collect_cfgs"),
),
"_stamp_flag": attr.label(
doc = "A setting used to determine whether or not the `--stamp` flag is enabled",
default = Label("//rust/private:stamp"),
),
} | RUSTC_ATTRS | RUSTC_ALLOCATOR_LIBRARIES_ATTRS

_coverage_attrs = {
Expand Down
2 changes: 1 addition & 1 deletion rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,7 @@ def rustc_compile_action(
linkstamps = depset([])

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

# Add flags for any 'rustc' lints that are specified.
#
Expand Down
62 changes: 4 additions & 58 deletions rust/private/stamp.bzl
Original file line number Diff line number Diff line change
@@ -1,63 +1,10 @@
"""A small utility module dedicated to detecting whether or not the `--stamp` flag is enabled
"""A small utility module dedicated to detecting whether or not the `--stamp` flag is enabled"""

This module can be removed likely after the following PRs ar addressed:
- https://github.com/bazelbuild/bazel/issues/11164
"""

load("//rust/private:utils.bzl", "dedent")

StampSettingInfo = provider(
doc = "Information about the `--stamp` command line flag",
fields = {
"value": "bool: Whether or not the `--stamp` flag was enabled",
},
)

def _stamp_build_setting_impl(ctx):
return StampSettingInfo(value = ctx.attr.value)

_stamp_build_setting = rule(
doc = dedent("""\
Whether to encode build information into the binary. Possible values:

- stamp = 1: Always stamp the build information into the binary, even in [--nostamp][stamp] builds. \
This setting should be avoided, since it potentially kills remote caching for the binary and \
any downstream actions that depend on it.
- stamp = 0: Always replace build information by constant values. This gives good build result caching.
- stamp = -1: Embedding of build information is controlled by the [--[no]stamp][stamp] flag.

Stamped binaries are not rebuilt unless their dependencies change.
[stamp]: https://docs.bazel.build/versions/main/user-manual.html#flag--stamp
"""),
implementation = _stamp_build_setting_impl,
attrs = {
"value": attr.bool(
doc = "The default value of the stamp build flag",
mandatory = True,
),
},
)

def stamp_build_setting(name, visibility = ["//visibility:public"]):
native.config_setting(
name = "stamp_detect",
values = {"stamp": "1"},
visibility = visibility,
)

_stamp_build_setting(
name = name,
value = select({
":stamp_detect": True,
"//conditions:default": False,
}),
visibility = visibility,
)

def is_stamping_enabled(attr):
def is_stamping_enabled(ctx, attr):
"""Determine whether or not build stamping is enabled

Args:
ctx (ctx): The rule's context object
attr (struct): A rule's struct of attributes (`ctx.attr`)

Returns:
Expand All @@ -69,7 +16,6 @@ def is_stamping_enabled(attr):
elif stamp_num == 0:
return False
elif stamp_num == -1:
stamp_flag = getattr(attr, "_stamp_flag", None)
return stamp_flag[StampSettingInfo].value if stamp_flag else False
return ctx.configuration.stamp_binaries()
else:
fail("Unexpected `stamp` value: {}".format(stamp_num))