Skip to content

cc_import does not propagate its shared_library runfiles #695

Open

Description

@kkubiak-arista

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.

Activity

  1. lilygorsheneva commented on May 11, 2026

    @lilygorsheneva
    Collaborator

    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).

    for dep in ctx.attr.dynamic_deps:
    runfiles = runfiles.merge(dep[DefaultInfo].data_runfiles)

    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?

  2. keith commented on May 11, 2026

    @keith
    Member
  3. keith commented on May 11, 2026

    @keith
    Member

    i probably fixed the original report w/ #631

  4. lilygorsheneva commented on May 11, 2026

    @lilygorsheneva
    Collaborator

    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.

  5. lilygorsheneva commented on May 11, 2026

    @lilygorsheneva
    Collaborator

    @oquenchil (Tom suggests asking you)

  6. trybka commented on May 11, 2026

    @trybka
    Collaborator

    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.

  7. lilygorsheneva commented on May 13, 2026

    @lilygorsheneva
    Collaborator

    #673 also tries to implement the cc_shared_library-side change (and presumably ran into the same issue)

  8. pzembrod commented on Sep 11, 2026

    @pzembrod
    Collaborator

    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.

  9. kkubiak-arista commented on Oct 9, 2026

    @kkubiak-arista
    Author

    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:

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions