我有一个共享库(libname.so)的cc_library(),它需要一个数据文件data.xml,该文件与它本身在同一目录中。
Bazel * .runfiles /将数据文件放置在与软件存储库中相同的相对路径中,但是我希望如上所述。谢谢!
我尝试过:
cc_library(
name = "libname",
srcs = ["libname.so"],
data = ["data.xml"],
)
我希望data.xml和libname.so位于同一路径(bazel-bin / proj / program.runfiles / repo / _solib_k8 / _U_S_Slibname /),但是数据文件位于相对于项目根目录的目录中。 (bazel-bin / proj / program.runfiles / repo / src / data.xml)
答案 0 :(得分:0)
到目前为止,最佳解决方案是运行文件可执行文件,但是bazel run program
无法动态加载库。
1)将共享库和数据文件分组在一起:
filegroup(
name = "libs_and_data",
# This creates *.runfiles/.../path/to/data/files, for runpath
data =glob(["*.so*"]) + glob(["*.xml"]),
)
2)从共享库的原始文件夹中手动构建链接, 3)手动将运行路径设置为包含共享库和数据文件的运行文件数据依赖项目录。
cc_library(
name = "lib",
data = [
# Shared objects are data, not library deps, to avoid _solib in RUNPATH
"//path/to/libs_and_data",
],
linkopts = [
# Explicit build-linking of libraries, because we are avoiding cc_library()
"-lLibrary1",
"-lLibrary2",
"-Lpath/to/libs",
# Point dynamic loader to runfiles location of libraries and datafiles
# Only the *.runfiles executable will successfully load libraries
"-Wl,-rpath='../../../path/to/libs'",
],
deps = [
"//path/to/headers",
],
)