openxla/xla

Help linking transitive dependencies when building shared library with XLA

Closed this issue · 1 comments

Hi, I'm building a thin wrapper around select parts of XLA, but having tremendous difficulty.

I have a number of Bazel targets such as

cc_library(
    name = "pjrt_c",
    linkstatic = True,
    alwayslink = True,
    srcs = glob(["*.cpp"]),
    hdrs = glob(["*.h"]),
    deps = [
        "@xla//xla/pjrt/c:pjrt_c_api_cpu",
        "//src/xla:xla",
        "//src/xla/pjrt:pjrt",
    ],
    visibility = ["//visibility:public"],
)

which are referenced by a shared library rule

cc_binary(
    name = "c_xla",
    linkshared = True,
    srcs = [
        "//src/xla:xla",
        "//src/xla/client:client",
        "//src/xla/client/lib:lib",
        "//src/xla/pjrt:pjrt",
        "//src/xla/pjrt/c:pjrt_c",
        "//src/xla/service:service",
        "//src:src",
    ],
)

with a WORKSPACE

local_repository(name = "xla", path = "xla")

load("@xla//:workspace4.bzl", "xla_workspace4")
xla_workspace4()

load("@xla//:workspace3.bzl", "xla_workspace3")
xla_workspace3()

load("@xla//:workspace2.bzl", "xla_workspace2")
xla_workspace2()

load("@xla//:workspace1.bzl", "xla_workspace1")
xla_workspace1()

load("@xla//:workspace0.bzl", "xla_workspace0")
xla_workspace0()

With that setup I see, at runtime

undefined symbol: _ZN4absl12lts_2023080213hash_internal15MixingHashState5kSeedE

I assumed that meant I need to statically link transitive dependencies into my build, but it's not clear to me how to do that.

solved - i needed to include the dependencies in the cc_binary deps, which I did implicitly by putting everything in srcs also in deps