From 32ea9c17dc2c774fbf3ac4e35153a81dd035590a Mon Sep 17 00:00:00 2001 From: Jorge Gorbe Moya Date: Wed, 20 May 2026 10:04:31 +0000 Subject: [PATCH] Remove is_proc_macro_dep. This was only used internally at Google during bootstrapping, and it's no longer needed. --- rust/private/BUILD.bazel | 19 -- rust/private/rust.bzl | 38 +--- rust/private/rustc.bzl | 33 ---- test/unit/is_proc_macro_dep/BUILD.bazel | 5 - .../is_proc_macro_dep_test.bzl | 175 ------------------ .../is_proc_macro_dep/proc_macro_crate.rs | 11 -- test/unit/is_proc_macro_dep/proc_macro_dep.rs | 3 - 7 files changed, 1 insertion(+), 283 deletions(-) delete mode 100644 test/unit/is_proc_macro_dep/BUILD.bazel delete mode 100644 test/unit/is_proc_macro_dep/is_proc_macro_dep_test.bzl delete mode 100644 test/unit/is_proc_macro_dep/proc_macro_crate.rs delete mode 100644 test/unit/is_proc_macro_dep/proc_macro_dep.rs diff --git a/rust/private/BUILD.bazel b/rust/private/BUILD.bazel index 89444bb9bc..ce935ba6d0 100644 --- a/rust/private/BUILD.bazel +++ b/rust/private/BUILD.bazel @@ -1,6 +1,5 @@ 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") # Exported for docs exports_files(["providers.bzl"]) @@ -32,24 +31,6 @@ bzl_library( ], ) -# 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 -# made available to the rustc invocation. -is_proc_macro_dep( - name = "is_proc_macro_dep", - build_setting_default = False, - visibility = ["//visibility:public"], -) - -# This setting enables the feature to identify dependencies of proc-macro-s, -# see `is_proc_macro_dep`. -is_proc_macro_dep_enabled( - name = "is_proc_macro_dep_enabled", - build_setting_default = False, - visibility = ["//visibility:public"], -) - rust_analyzer_detect_sysroot( name = "rust_analyzer_detect_sysroot", visibility = ["//visibility:public"], diff --git a/rust/private/rust.bzl b/rust/private/rust.bzl index 9d9c1d12b4..8f2aa464af 100644 --- a/rust/private/rust.bzl +++ b/rust/private/rust.bzl @@ -626,12 +626,6 @@ RUSTC_ATTRS = { "_extra_rustc_flags": attr.label( default = Label("//rust/settings:extra_rustc_flags"), ), - "_is_proc_macro_dep": attr.label( - default = Label("//rust/private:is_proc_macro_dep"), - ), - "_is_proc_macro_dep_enabled": attr.label( - default = Label("//rust/private:is_proc_macro_dep_enabled"), - ), "_per_crate_rustc_flag": attr.label( default = Label("//rust/settings:experimental_per_crate_rustc_flag"), ), @@ -1108,40 +1102,10 @@ rust_shared_library = rule( """), ) -def _proc_macro_dep_transition_impl(settings, _attr): - if settings["//rust/private:is_proc_macro_dep_enabled"]: - return {"//rust/private:is_proc_macro_dep": True} - else: - return [] - -_proc_macro_dep_transition = transition( - inputs = ["//rust/private:is_proc_macro_dep_enabled"], - outputs = ["//rust/private:is_proc_macro_dep"], - implementation = _proc_macro_dep_transition_impl, -) - rust_proc_macro = rule( implementation = _rust_proc_macro_impl, provides = COMMON_PROVIDERS, - # Start by copying the common attributes, then override the `deps` attribute - # to apply `_proc_macro_dep_transition`. To add this transition we additionally - # need to declare `_allowlist_function_transition`, see - # https://docs.bazel.build/versions/main/skylark/config.html#user-defined-transitions. - attrs = dict( - _COMMON_ATTRS.items(), - _allowlist_function_transition = attr.label( - default = Label("//tools/allowlists/function_transition_allowlist"), - ), - deps = attr.label_list( - doc = dedent("""\ - List of other libraries to be linked to this library target. - - These can be either other `rust_library` targets or `cc_library` targets if - linking a native library. - """), - cfg = _proc_macro_dep_transition, - ), - ), + attrs = _COMMON_ATTRS, fragments = ["cpp"], toolchains = [ str(Label("//rust:toolchain_type")), diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index f1a44fe9e5..b9687c5deb 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -101,34 +101,6 @@ PerCrateRustcFlagsInfo = provider( fields = {"per_crate_rustc_flags": "List[string] Extra flags to pass to rustc in non-exec configuration"}, ) -IsProcMacroDepInfo = provider( - doc = "Records if this is a transitive dependency of a proc-macro.", - fields = {"is_proc_macro_dep": "Boolean"}, -) - -def _is_proc_macro_dep_impl(ctx): - return IsProcMacroDepInfo(is_proc_macro_dep = ctx.build_setting_value) - -is_proc_macro_dep = rule( - doc = "Records if this is a transitive dependency of a proc-macro.", - implementation = _is_proc_macro_dep_impl, - build_setting = config.bool(flag = True), -) - -IsProcMacroDepEnabledInfo = provider( - doc = "Enables the feature to record if a library is a transitive dependency of a proc-macro.", - fields = {"enabled": "Boolean"}, -) - -def _is_proc_macro_dep_enabled_impl(ctx): - return IsProcMacroDepEnabledInfo(enabled = ctx.build_setting_value) - -is_proc_macro_dep_enabled = rule( - doc = "Enables the feature to record if a library is a transitive dependency of a proc-macro.", - implementation = _is_proc_macro_dep_enabled_impl, - build_setting = config.bool(flag = True), -) - def _get_rustc_env(attr, toolchain, crate_name): """Gathers rustc environment variables @@ -161,11 +133,6 @@ def _get_rustc_env(attr, toolchain, crate_name): "CARGO_PKG_VERSION_PATCH": patch, "CARGO_PKG_VERSION_PRE": pre, } - if hasattr(attr, "_is_proc_macro_dep_enabled") and attr._is_proc_macro_dep_enabled[IsProcMacroDepEnabledInfo].enabled: - is_proc_macro_dep = "0" - if hasattr(attr, "_is_proc_macro_dep") and attr._is_proc_macro_dep[IsProcMacroDepInfo].is_proc_macro_dep: - is_proc_macro_dep = "1" - result["BAZEL_RULES_RUST_IS_PROC_MACRO_DEP"] = is_proc_macro_dep return result def get_compilation_mode_opts(ctx, toolchain): diff --git a/test/unit/is_proc_macro_dep/BUILD.bazel b/test/unit/is_proc_macro_dep/BUILD.bazel deleted file mode 100644 index ac655a594a..0000000000 --- a/test/unit/is_proc_macro_dep/BUILD.bazel +++ /dev/null @@ -1,5 +0,0 @@ -load(":is_proc_macro_dep_test.bzl", "is_proc_macro_dep_test_suite") - -is_proc_macro_dep_test_suite( - name = "is_proc_macro_dep_test_suite", -) diff --git a/test/unit/is_proc_macro_dep/is_proc_macro_dep_test.bzl b/test/unit/is_proc_macro_dep/is_proc_macro_dep_test.bzl deleted file mode 100644 index e93c5dec0a..0000000000 --- a/test/unit/is_proc_macro_dep/is_proc_macro_dep_test.bzl +++ /dev/null @@ -1,175 +0,0 @@ -"""Unittests for the is_proc_macro_dep setting.""" - -load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts") -load("//rust:defs.bzl", "rust_library", "rust_proc_macro") - -DepActionsInfo = provider( - "Contains information about dependencies actions.", - fields = {"actions": "List[Action]"}, -) - -def _collect_dep_actions_aspect_impl(target, ctx): - actions = [] - actions.extend(target.actions) - for dep in ctx.rule.attr.deps: - actions.extend(dep[DepActionsInfo].actions) - return [DepActionsInfo(actions = actions)] - -collect_dep_actions_aspect = aspect( - implementation = _collect_dep_actions_aspect_impl, - attr_aspects = ["deps"], -) - -def _attach_dep_actions_aspect_impl(ctx): - return [ctx.attr.dep[DepActionsInfo]] - -attach_dep_actions_aspect = rule( - implementation = _attach_dep_actions_aspect_impl, - attrs = { - "dep": attr.label(aspects = [collect_dep_actions_aspect]), - }, -) - -def _enable_is_proc_macro_dep_transition_impl(_settings, _attr): - return {"//rust/private:is_proc_macro_dep_enabled": True} - -enable_is_proc_macro_dep_transition = transition( - inputs = [], - outputs = ["//rust/private:is_proc_macro_dep_enabled"], - implementation = _enable_is_proc_macro_dep_transition_impl, -) - -attach_dep_actions_and_enable_is_proc_macro_dep_aspect = rule( - implementation = _attach_dep_actions_aspect_impl, - attrs = { - "dep": attr.label( - aspects = [collect_dep_actions_aspect], - ), - "_allowlist_function_transition": attr.label( - default = Label( - "//tools/allowlists/function_transition_allowlist", - ), - ), - }, - cfg = enable_is_proc_macro_dep_transition, -) - -def _is_proc_macro_dep_is_not_in_env_for_top_level_action(ctx): - env = analysistest.begin(ctx) - top_level_action = analysistest.target_under_test(env).actions[0] - asserts.false(env, "BAZEL_RULES_RUST_IS_PROC_MACRO_DEP" in top_level_action.env) - return analysistest.end(env) - -is_proc_macro_dep_is_not_in_env_for_top_level_action_test = analysistest.make(_is_proc_macro_dep_is_not_in_env_for_top_level_action) - -def _is_proc_macro_dep_is_false_for_proc_macro(ctx): - env = analysistest.begin(ctx) - tut = analysistest.target_under_test(env) - proc_macro_dep_action = [a for a in tut[DepActionsInfo].actions if str(a) == "action 'Compiling Rust proc-macro proc_macro_crate (1 file)'"][0] - asserts.equals(env, proc_macro_dep_action.env["BAZEL_RULES_RUST_IS_PROC_MACRO_DEP"], "0") - return analysistest.end(env) - -is_proc_macro_dep_is_false_for_proc_macro_test = analysistest.make(_is_proc_macro_dep_is_false_for_proc_macro) - -def _is_proc_macro_dep_is_false_for_top_level_library(ctx): - env = analysistest.begin(ctx) - tut = analysistest.target_under_test(env) - top_level_library_action = [a for a in tut[DepActionsInfo].actions if str(a) == "action 'Compiling Rust rlib top_level_library (1 file)'"][0] - asserts.equals(env, top_level_library_action.env["BAZEL_RULES_RUST_IS_PROC_MACRO_DEP"], "0") - return analysistest.end(env) - -is_proc_macro_dep_is_false_for_top_level_library_test = analysistest.make(_is_proc_macro_dep_is_false_for_top_level_library) - -def _is_proc_macro_dep_is_true_for_proc_macro_dep(ctx): - env = analysistest.begin(ctx) - tut = analysistest.target_under_test(env) - proc_macro_dep_action = [a for a in tut[DepActionsInfo].actions if str(a) == "action 'Compiling Rust rlib proc_macro_dep (1 file)'"][0] - asserts.equals(env, proc_macro_dep_action.env["BAZEL_RULES_RUST_IS_PROC_MACRO_DEP"], "1") - return analysistest.end(env) - -is_proc_macro_dep_is_true_for_proc_macro_dep_test = analysistest.make(_is_proc_macro_dep_is_true_for_proc_macro_dep) - -def _is_proc_macro_dep_is_not_in_env_for_proc_macro_dep(ctx): - env = analysistest.begin(ctx) - tut = analysistest.target_under_test(env) - proc_macro_dep_action = [a for a in tut[DepActionsInfo].actions if str(a) == "action 'Compiling Rust rlib proc_macro_dep (1 file)'"][0] - asserts.true(env, "BAZEL_RULES_RUST_IS_PROC_MACRO_DEP" not in proc_macro_dep_action.env) - return analysistest.end(env) - -is_proc_macro_dep_is_not_in_env_for_proc_macro_dep_test = analysistest.make(_is_proc_macro_dep_is_not_in_env_for_proc_macro_dep) - -def _is_proc_macro_dep_test(): - """Generate targets and tests.""" - - rust_library( - name = "proc_macro_dep", - srcs = ["proc_macro_dep.rs"], - edition = "2018", - ) - - rust_proc_macro( - name = "proc_macro_crate", - srcs = ["proc_macro_crate.rs"], - deps = ["proc_macro_dep"], - edition = "2018", - ) - - is_proc_macro_dep_is_not_in_env_for_top_level_action_test( - name = "is_proc_macro_dep_is_not_in_env_for_top_level_proc_macro", - target_under_test = ":proc_macro_crate", - ) - - is_proc_macro_dep_is_not_in_env_for_top_level_action_test( - name = "is_proc_macro_dep_is_not_in_env_for_top_level_library", - target_under_test = ":proc_macro_dep", - ) - - attach_dep_actions_and_enable_is_proc_macro_dep_aspect( - name = "proc_macro_crate_enabled_with_actions", - dep = ":proc_macro_crate", - ) - - is_proc_macro_dep_is_false_for_proc_macro_test( - name = "is_proc_macro_dep_is_false_for_proc_macro", - target_under_test = ":proc_macro_crate_enabled_with_actions", - ) - - is_proc_macro_dep_is_true_for_proc_macro_dep_test( - name = "is_proc_macro_dep_is_true_for_proc_macro_dep", - target_under_test = ":proc_macro_crate_enabled_with_actions", - ) - - rust_library( - name = "top_level_library", - srcs = ["proc_macro_dep.rs"], - edition = "2018", - ) - - attach_dep_actions_and_enable_is_proc_macro_dep_aspect( - name = "top_level_library_enabled_with_actions", - dep = ":top_level_library", - ) - - is_proc_macro_dep_is_false_for_top_level_library_test( - name = "is_proc_macro_dep_is_false_for_top_level_library", - target_under_test = ":top_level_library_enabled_with_actions", - ) - -def is_proc_macro_dep_test_suite(name): - """Entry-point macro called from the BUILD file. - - Args: - name: Name of the macro. - """ - _is_proc_macro_dep_test() - - native.test_suite( - name = name, - tests = [ - "is_proc_macro_dep_is_not_in_env_for_top_level_proc_macro", - "is_proc_macro_dep_is_not_in_env_for_top_level_library", - "is_proc_macro_dep_is_false_for_proc_macro", - "is_proc_macro_dep_is_false_for_top_level_library", - "is_proc_macro_dep_is_true_for_proc_macro_dep", - ], - ) diff --git a/test/unit/is_proc_macro_dep/proc_macro_crate.rs b/test/unit/is_proc_macro_dep/proc_macro_crate.rs deleted file mode 100644 index c01a286164..0000000000 --- a/test/unit/is_proc_macro_dep/proc_macro_crate.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate proc_macro; - -use proc_macro::TokenStream; - -#[proc_macro] -pub fn make_answer(_item: TokenStream) -> TokenStream { - let answer = proc_macro_dep::proc_macro_dep(); - format!("fn answer() -> u32 {{ {answer} }}") - .parse() - .unwrap() -} diff --git a/test/unit/is_proc_macro_dep/proc_macro_dep.rs b/test/unit/is_proc_macro_dep/proc_macro_dep.rs deleted file mode 100644 index 3358e72c85..0000000000 --- a/test/unit/is_proc_macro_dep/proc_macro_dep.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub fn proc_macro_dep() -> i64 { - 42 -}