使用 Bazel 构建后自动复制可执行文件

Automatically copy executable after build with Bazel

假设我有以下目录布局:

.../
  root/
    bin/
      sdl.dll
    src/
      main/
        main.cpp
        BUILD
      WORKSPACE

还有一个 BUILD 文件,上面写着:

cc_binary(
    name = "test",
    srcs = ["main.cpp"]
)

而我的构建命令行是:

bazel build //main:hello-world --symlink_prefix=/

我需要将什么添加到我的 BUILD 文件中,以便 test.exe(和 test.pdb,如果适用)被复制到 bin(与 sdl.dll 一起)?

我查看了 this page 并尝试使用 --output_base,但比我想要的要多得多。

P.S:在 "Visual Studio" 术语中,我希望将 $(OutDir) 或后期构建从 $(OutDir) 更改为 ..\bin

您不能直接使用 Bazel 执行此操作。出于密封原因,Bazel 不会写入您的源目录。解决方法是使用手动 运行 或使用 bazel run 的 post-构建步骤脚本。

另见:.