gpt4 book ai didi

c++ - 如何在 bazel 中设置动态加载的库依赖项?

转载 作者:行者123 更新时间:2023-11-30 05:05:18 25 4
gpt4 key购买 nike

假设我有一个单元测试,它使用 dlopen 从提供的共享库加载和调用代码

int main(int argc, char* argv[]) {
const char* library = argv[1];
// calls dlopen with library and does some testing
}

给定声明的库

cc_library(
name = "a",
srcs = ["a.cpp"],
visibility = ["//visibility:public"],
)

有什么方法可以使用 cc_test 来设置单元测试,以使用作为参数传入的库 a 的位置运行? (最好也是以独立于平台的方式,这样我就不必担心库使用什么后缀)

最佳答案

您也许能够编写访问运行文件的自定义 skylark 规则(相关讨论 here)。

一起破解一些东西:

构建:

load("//:foo.bzl", "runfiles")

cc_binary(
name = "liba.so",
srcs = [ "a.cc" ],
linkshared = 1,
)

runfiles(
name = "runfiles",
deps = [ ":liba.so" ],
)

foo.bzl:

def _impl(ctx):
for dep in ctx.attr.deps:
print(dep.files_to_run.executable.path)

runfiles = rule(
implementation = _impl,
attrs = {
"deps": attr.label_list(allow_files=True),
}
)

关于c++ - 如何在 bazel 中设置动态加载的库依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48461242/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com