diff --git a/src/main/starlark/builtins_bzl/common/cc/cc_shared_library.bzl b/src/main/starlark/builtins_bzl/common/cc/cc_shared_library.bzl index a70dea701550b3..a5fb4bf3e222e8 100644 --- a/src/main/starlark/builtins_bzl/common/cc/cc_shared_library.bzl +++ b/src/main/starlark/builtins_bzl/common/cc/cc_shared_library.bzl @@ -19,6 +19,7 @@ load(":common/cc/cc_helper.bzl", "cc_helper") load(":common/cc/cc_info.bzl", "CcInfo") load(":common/cc/cc_shared_library_hint_info.bzl", "CcSharedLibraryHintInfo") load(":common/cc/semantics.bzl", "semantics") +load(":common/paths.bzl", "paths") load(":common/proto/proto_info.bzl", "ProtoInfo") # TODO(#5200): Add export_define to library_to_link and cc_library @@ -682,6 +683,13 @@ def _cc_shared_library_impl(ctx): if ctx.attr.shared_lib_name: main_output = ctx.actions.declare_file(ctx.attr.shared_lib_name) + pdb_file = None + if cc_common.is_enabled(feature_configuration = feature_configuration, feature_name = "generate_pdb_file"): + if ctx.attr.shared_lib_name: + pdb_file = ctx.actions.declare_file(paths.replace_extension(ctx.attr.shared_lib_name, ".pdb")) + else: + pdb_file = ctx.actions.declare_file(ctx.label.name + ".pdb") + win_def_file = None if cc_common.is_enabled(feature_configuration = feature_configuration, feature_name = "targets_windows"): object_files = [] @@ -714,6 +722,7 @@ def _cc_shared_library_impl(ctx): name = ctx.label.name, output_type = "dynamic_library", main_output = main_output, + pdb_file = pdb_file, win_def_file = win_def_file, ) diff --git a/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/BUILD.builtin_test b/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/BUILD.builtin_test index dd99fbbfd35b77..eb8dd32cf2fd4e 100644 --- a/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/BUILD.builtin_test +++ b/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/BUILD.builtin_test @@ -11,6 +11,7 @@ load( "nocode_cc_lib", "wrapped_cc_lib", "exports_test", + "pdb_test", ) load("@rules_testing//lib:analysis_test.bzl", "analysis_test") load("@rules_python//python:py_test.bzl", "py_test") @@ -119,7 +120,10 @@ cc_shared_library( "//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library3:diff_pkg_so", "private_lib_so", ], - features = ["windows_export_all_symbols"], + features = [ + "windows_export_all_symbols", + "generate_pdb_file", + ], exports_filter = [ ":indirect_dep2", ], @@ -519,3 +523,8 @@ exports_test( "//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:a_suffix", ], ) + +pdb_test( + name = "pdb_test", + target = ":foo_so", +) diff --git a/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/starlark_tests.bzl b/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/starlark_tests.bzl index 514bbb797b5129..79e4880e08baee 100644 --- a/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/starlark_tests.bzl +++ b/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/starlark_tests.bzl @@ -401,3 +401,31 @@ def _exports_test_macro(name, target, targets_that_should_be_claimed_to_be_expor ) exports_test = _exports_test_macro + +def _pdb_test_impl(env, target): + if not env.ctx.target_platform_has_constraint(env.ctx.attr._is_windows[platform_common.ConstraintValueInfo]): + return + + target_action = None + for action in target.actions: + if action.mnemonic == "CppLink": + target_action = action + break + + outputs = [f.basename for f in target_action.outputs.to_list()] + + env.expect.that_collection(outputs).contains_at_least_predicates([ + matching.contains("foo_so.pdb"), + ]) + +def _pdb_test_macro(name, target): + analysis_test( + name = name, + impl = _pdb_test_impl, + target = target, + attrs = { + "_is_windows": attr.label(default = "@platforms//os:windows"), + }, + ) + +pdb_test = _pdb_test_macro