我正在尝试设置一个简单的Bazel工作区来构建pybind库,并且我无法让Bazel使用特定的非系统python (使用rules_python Bazel提取)。
这是我的设计:
.
├── BUILD
├── WORKSPACE
└── example.cpp建造:
load("@pybind11_bazel//:build_defs.bzl", "pybind_extension")
pybind_extension(
name = "example",
srcs = ["example.cpp"],
deps = [ ],
)工作空间:
oad("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "rules_python",
sha256 = "8c8fe44ef0a9afc256d1e75ad5f448bb59b81aba149b8958f02f7b3a98f5d9b4",
strip_prefix = "rules_python-0.13.0",
url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/0.13.0.tar.gz",
)
load("@rules_python//python:repositories.bzl", "python_register_toolchains")
python_register_toolchains(
name = "python3_9",
python_version = "3.9",
)
load("@python3_9//:defs.bzl", "interpreter")
load("@rules_python//python:pip.bzl", "pip_parse")
pip_parse(
python_interpreter_target = interpreter,
)
http_archive(
name = "pybind11_bazel",
strip_prefix = "pybind11_bazel-9a24c33cbdc510fa60ab7f5ffb7d80ab89272799",
urls = ["https://github.com/pybind/pybind11_bazel/archive/9a24c33cbdc510fa60ab7f5ffb7d80ab89272799.zip"],
)
http_archive(
name = "pybind11",
build_file = "@pybind11_bazel//:pybind11.BUILD",
strip_prefix = "pybind11-2.10.0",
urls = ["https://github.com/pybind/pybind11/archive/refs/tags/v2.10.0.zip"],
)
load("@pybind11_bazel//:python_configure.bzl", "python_configure")
python_configure(
name = "local_config_python",
python_interpreter_target = "**what goes here**",
)example.cpp:
#include <pybind11/pybind11.h>
namespace py = pybind11;
void do_something() { }
PYBIND11_MODULE(example, m) {
m.def("do_something", &do_something, "A function that does something");
}如果我将python_interpreter_target = "**what goes here**"行从WORKSPACE中删除,那么一切都可以工作,但它使用的是系统python,而这正是我所要避免的。但是我找不到bazel的目标-- python3二进制文件是从rules_bazel pakage拉出的。
如果有帮助,我可以看到@python3_9的所有目标
% bazel query @python3_9//...
@python3_9//:files
@python3_9//:includes
@python3_9//:libpython
@python3_9//:pip
@python3_9//:py3_runtime
@python3_9//:python3
@python3_9//:python_headers
@python3_9//:python_runtimes
Loading: 0 packages loaded(这些似乎都不是python_interpreter_target想要的)
发布于 2022-10-26 11:25:50
请尝试将实际路径传递给目标python可执行文件。请将python可执行文件签入third_party dir,而不是使用python调用rules_python,而是将相对于工作区的可执行文件的相对路径传递给该可执行文件。谢谢!
https://stackoverflow.com/questions/74146522
复制相似问题