Home > Enterprise >  Provide run time environment variable path (e.g. LD_LIBRARY_PATH) to third party dependency in bazel
Provide run time environment variable path (e.g. LD_LIBRARY_PATH) to third party dependency in bazel

Time:05-17

In the code base I am working with we use the oracle instant client library as a third party dependency in Bazel as follows:

cc_library(
    name = "instant_client_basiclite",
    srcs = glob(["*.so*"]),
    visibility = ["//visibility:public"],
)

The library looks as this:

$ bazel query 'deps(@instant_client_basiclite//:instant_client_basiclite)'
@instant_client_basiclite//:instant_client_basiclite
@instant_client_basiclite//:liboramysql.so
@instant_client_basiclite//:libociicus.so
@instant_client_basiclite//:libocci.so.21.1
@instant_client_basiclite//:libocci.so
@instant_client_basiclite//:libnnz21.so
@instant_client_basiclite//:libclntshcore.so
...

It works as far as linking is concerned, but it seems that the path to the library is still needed because otherwise I get a run time error (oracle error 1804). The error can be solved by setting any of the environment variables ORACLE_HOME or LD_LIBRARY_PATH. In fact for the IBM WebSphere MQ there is the same need (character encoding table files need to be found).

ldd on a binary points to .../bazel-bin/app/../../../_solib_k8/_U@instant_Uclient_Ubasiclite_S_S_Cinstant_Uclient_Ubasiclite___U/libocci.so.21.1

How can I set those needed path variables so that bazel test, bazel run and Bazel container image rules work?

CodePudding user response:

One possibility is to add the following command line option:

--test_env=ORACLE_HOME="$(bazel info output_base)/external/instant_client_basiclite"

It is a pity that it cannot be put in .bazelrc.

  • Related