You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cc_import does not propagate its shared_library runfiles #695
In cases where the shared_library attribute in cc_import is not a plain file label, but for example a cc_shared_library target it can have its own runfiles that are currently ignored by cc_import instead of being propagated.
On the cc_import side this is straightforward; however cc_shared_library itself has surprising runfiles behavior (only forwarding runfiles for ctx.attr.dynamic_deps).
In the specific case of a shared_library having deps with a (maybe-transitive) data field (which seems like a reasonable interpretation of the original report) I think #631 might need 2-4 extra lines in cc_import and cc_shared_library to handle.
But also since cc_import is meant for precompiled files maybe we shouldn't want to support that anyway.
It looks like there has been some subtle changes/behavior (e.g. bazelbuild/bazel#19378 ) to this space.
I imagine we want to ensure we're not pulling in symlinks / dylibs for the libs that are statically linked, only those that are dynamically linked. But then there are presumably data files that are important to forward along.
Also: I'm wondering why you would cc_import a cc_shared_library target; what'd be the use case for that? Naively I would expect that you could depend on the cc_shared_library directly without a cc_import spliced in between.
As an example use case, let's say I want to model multiple runtime variants of a shared implementation FooGeneric:
cc_library(
name = "Foo_internal",
srcs = ["Foo.cc"],
hdrs = ["Foo.h"],
data = ["common_schema.json"],
)
cc_shared_library(
name = "FooGeneric",
deps = [":Foo_internal"],
)
cc_import(
name = "FooImpl1",
shared_library = ":FooGeneric",
data = ["data_file_1"],
...
)
cc_import(
name = "FooImpl2",
shared_library = ":FooGeneric",
data = ["data_file_2"],
...
)
Here, "common_schema.json" should get propagated by cc_import to any consumer of FooImpl1 instead of being lost like it is currently.
While there may be other options for modelling this like using cc_library instead of cc_import or workarounds like specifying FooGeneric in cc_import's data , cc_import should still provide complete runtime behaviour without specifying the same target in two attributes.
Activity
lilygorsheneva commentedon May 11, 2026
On the cc_import side this is straightforward; however cc_shared_library itself has surprising runfiles behavior (only forwarding runfiles for ctx.attr.dynamic_deps).
rules_cc/cc/private/rules_impl/cc_shared_library_impl.bzl
Lines 732 to 733 in 7d32823
There's tests that expect this specific behavior.
https://github.com/bazelbuild/bazel/blob/3b1112d06ad05e85117b32608e1916fe256029bc/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test/starlark_tests.bzl#L223-L247
@trybka who would know why we specifically have/expect that behavior?
keith commentedon May 11, 2026
cc @fmeum
keith commentedon May 11, 2026
i probably fixed the original report w/ #631
lilygorsheneva commentedon May 11, 2026
In the specific case of a shared_library having deps with a (maybe-transitive) data field (which seems like a reasonable interpretation of the original report) I think #631 might need 2-4 extra lines in cc_import and cc_shared_library to handle.
But also since cc_import is meant for precompiled files maybe we shouldn't want to support that anyway.
lilygorsheneva commentedon May 11, 2026
@oquenchil (Tom suggests asking you)
trybka commentedon May 11, 2026
It looks like there has been some subtle changes/behavior (e.g. bazelbuild/bazel#19378 ) to this space.
I imagine we want to ensure we're not pulling in symlinks / dylibs for the libs that are statically linked, only those that are dynamically linked. But then there are presumably data files that are important to forward along.
lilygorsheneva commentedon May 13, 2026
#673 also tries to implement the cc_shared_library-side change (and presumably ran into the same issue)
pzembrod commentedon Sep 11, 2026
Is this still an issue?
Also: I'm wondering why you would cc_import a cc_shared_library target; what'd be the use case for that? Naively I would expect that you could depend on the cc_shared_library directly without a cc_import spliced in between.
kkubiak-arista commentedon Oct 9, 2026
Yes, it's still an issue.
As an example use case, let's say I want to model multiple runtime variants of a shared implementation
FooGeneric:Here,
"common_schema.json"should get propagated bycc_importto any consumer ofFooImpl1instead of being lost like it is currently.While there may be other options for modelling this like using
cc_libraryinstead ofcc_importor workarounds like specifyingFooGenericincc_import'sdata,cc_importshould still provide complete runtime behaviour without specifying the same target in two attributes.