在bazel规则内执行本机_二进制文件

在bazel规则内执行本机_二进制文件,bazel,bazel-rules,Bazel,Bazel Rules,@bazel_skylib//rules:native_binary.bzl定义了native_binary规则,可用于将本机可执行文件包装到bazel目标中。我用它来包装Sciter SDK中名为packfolder.exe的打包工具 我将二进制文件放在我的源代码树中,位于third\u party/sciter/packfolder.exe并编写了这个BUILD文件 # third_party/sciter/BUILD native_binary(name = "packfolde

@bazel_skylib//rules:native_binary.bzl
定义了
native_binary
规则,可用于将本机可执行文件包装到bazel目标中。我用它来包装Sciter SDK中名为
packfolder.exe
的打包工具

我将二进制文件放在我的源代码树中,位于
third\u party/sciter/packfolder.exe
并编写了这个
BUILD
文件

# third_party/sciter/BUILD
native_binary(name = "packfolder",
              src = "packfolder.exe",
              out = "packfolder.exe"
)
bazel运行第三方/sciter:packfolder
运行时没有问题。现在我想在我的自定义
cc\u sciter\u资源
规则中使用这个目标

# 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\\u bazel\u marki\kiodv2fz\execroot\sciter\u bazel\bazel out\x64\u windows-opt-exec-2B5CBBC6。所以错误是准确的,但我不知道如何解决这个问题

--- sciter_rules.bzl
+++ sciter_rules.bzl
@@ -6,7 +6,7 @@
         outputs = [output_file],
         inputs = in_files,
         arguments = [],
-        executable = ctx.executable.packfolder.path)
+        executable = ctx.executable.packfolder)
     return DefaultInfo(files = depset([output_file]))
 
 cc_sciter_resource = rule(
ctx.executable.packfolder.path
只是一个字符串,因此Bazel不知道需要将
packfolder
可执行文件添加为操作的输入