在Bazel中构建没有.exe扩展名的可执行文件,可以使用--platforms=//platforms:windows
标志来指定构建平台为Windows,并通过sh_binary
规则来指定可执行文件。
以下是一个示例的BUILD文件的内容:
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
git_repository(
name = "platforms",
remote = "https://github.com/bazelbuild/platforms.git",
commit = "f4b2706e2cd4e1a3c12f7d1b5a2c6b29e8d8c6f1",
)
sh_binary(
name = "my_executable",
srcs = ["my_executable.sh"],
platform_type = "@platforms//os:windows",
)
在上面的示例中,首先加载了git_repository
规则,用于从Bazel官方的platforms
存储库中获取Windows构建平台的定义。
然后,使用sh_binary
规则来定义一个名为my_executable
的可执行文件。srcs
属性指定了可执行文件的源文件,这里假设是my_executable.sh
。platform_type
属性指定了构建平台为Windows。
然后,您可以使用Bazel构建该可执行文件:
bazel build :my_executable
构建成功后,您将在bazel-bin
目录下找到生成的可执行文件my_executable
,它将没有.exe
扩展名。