2

我需要外部(或内部)依赖的路径将其作为参数传递给内部的函数。我们需要文件夹的位置,而不是特定文件。此外,有时,我们需要共享库所在文件夹的路径,由cc_library.

Python 文件

import cppyy
cppyy.add_include_path('path/to/external/dependency/1')
cppyy.add_library_path('path/to/another/external/dependency/2')
cppyy.add_include_path('path/to/another/internal/dependency')
cppyy.include('file/in/external/dependency')

构建文件

py_binary(
    name = "sample",
    srcs = ["sample.py"],
    deps = [
        "@cppyy_archive//:cppyy",
    ],
    data = [
        "@external-dependency//location:target",
        "//internal-dependency/location:target2"
    ]
)
4

1 回答 1

0

来自https://docs.bazel.build/versions/master/external.html#layout

您可以通过运行查看外部目录:

ls $(bazel info output_base)/external

路径的external实际外观实际上取决于存档使用的规则。例如,如果它http_fileWORKSPACE文件中使用 an 声明:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
http_file(
    name = "fenix",
    urls = ["https://github.com/mozilla-mobile/fenix/archive/v76.0.0-beta.2.tar.gz"],
    sha256 = "94050c664e5ec5b66cd2ca9f6a8b898987ab63d9602090533217df1a3f2dc5a9"
)

您会发现该v76.0.0-beta.2.tar.gz文件为external/fenix/file/downloaded

user@host:~$ file $(bazel info output_base)/external/fenix/file/downloaded                 
/home/user/.cache/bazel/_bazel_user/761044447e04744e746cd54d0b4b5056/external/fenix/file/downloaded: gzip compressed data, from Unix, original size modulo 2^32 15759360
于 2020-05-15T20:55:38.873 回答