【发布时间】:2020-11-25 00:26:55
【问题描述】:
@bazel_skylib//rules:native_binary.bzl 定义了 native_binary 规则,该规则可用于将本机可执行文件包装在 bazel 目标中。我用它从 Sciter SDK 中封装了一个名为 packfolder.exe 的打包工具。
我将二进制文件放入我的源代码树third_party/sciter/packfolder.exe 并编写了这个BUILD 文件。
# third_party/sciter/BUILD
native_binary(name = "packfolder",
src = "packfolder.exe",
out = "packfolder.exe"
)
bazel run third_party/sciter:packfolder 运行没有问题。现在我想在我的自定义 cc_sciter_resource 规则中使用这个目标。
# third_party/sciter/sciter_rules.bzl
def _impl(ctx):
in_files = ctx.files.srcs
output_file = ctx.actions.declare_file(ctx.label.name)
ctx.actions.run(
outputs = [output_file],
inputs = in_files,
arguments = [],
executable = ctx.executable.packfolder.path)
return DefaultInfo(files = depset([output_file]))
cc_sciter_resource = rule(
implementation = _impl,
attrs = {
"srcs": attr.label_list(),
"packfolder": attr.label(
default = Label("//third_party/sciter:packfolder"),
executable = True,
cfg = "exec"
),
}
)
问题是,当我尝试构建一个使用此规则的目标时,说
cc_sciter_resource(
name = "hello_world_resource.cpp"
srcs = [...]
)
我收到以下错误。
ERROR: C:/users/marki/sciter-bazel/examples/BUILD:12:19: Action examples/hello_world_resource.cpp failed (Exit -1): packfolder.exe failed: error executing command
cd C:/users/marki/_bazel_marki/kiodv2fz/execroot/sciter_bazel
bazel-out/x64_windows-opt-exec-2B5CBBC6/bin/third_party/sciter/packfolder.exe
Execution platform: @local_config_platform//:host. Note: Remote connection/protocol failed with: execution failed
Action failed to execute: java.io.IOException: ERROR: src/main/native/windows/process.cc(202): CreateProcessW("C:\users\marki\_bazel_marki\kiodv2fz\execroot\sciter_bazel\bazel-out\x64_windows-opt-exec-2B5CBBC6\bin\third_party\sciter\packfolder.exe"): The system cannot find the file specified.
(error: 2)
Target //examples:hello_world_resource.cpp failed to build
我的计算机上不存在目录C:\users\marki\_bazel_marki\kiodv2fz\execroot\sciter_bazel\bazel-out\x64_windows-opt-exec-2B5CBBC6。所以错误是准确的,但我不知道如何解决这个问题。
【问题讨论】:
标签: bazel bazel-rules