diff --git a/src/main/starlark/builtins_bzl/common/cc/experimental_cc_shared_library.bzl b/src/main/starlark/builtins_bzl/common/cc/experimental_cc_shared_library.bzl index 5755f77ddabf4f..3ffd31a75726bb 100644 --- a/src/main/starlark/builtins_bzl/common/cc/experimental_cc_shared_library.bzl +++ b/src/main/starlark/builtins_bzl/common/cc/experimental_cc_shared_library.bzl @@ -418,6 +418,12 @@ def _get_deps(ctx): if not len(deps): deps = ctx.attr.roots + if len(deps) == 0: + fail( + "'cc_shared_library' must have at least one dependency in 'deps' (or 'roots')", + attr = "deps", + ) + return deps def _cc_shared_library_impl(ctx): 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 03b39d24abb3a2..befdab0f30ca11 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 @@ -492,3 +492,9 @@ no_exporting_static_lib_test( name = "no_exporting_static_lib_test", target_under_test = ":lib_with_no_exporting_roots", ) + +build_failure_test( + name = "shared_library_without_deps", + message = "'cc_shared_library' must have at least one dependency in 'deps' (or 'roots')", + target_under_test = "//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/failing_targets:failing_with_no_deps_so", +) diff --git a/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/failing_targets/BUILD.builtin_test b/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/failing_targets/BUILD.builtin_test index 6ab7018d6e2f0b..a4604b78e3bb2f 100644 --- a/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/failing_targets/BUILD.builtin_test +++ b/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/failing_targets/BUILD.builtin_test @@ -100,3 +100,8 @@ cc_shared_library( ], tags = TAGS, ) + +cc_shared_library( + name = "failing_with_no_deps_so", + tags = TAGS, +)