Open chrisbrown2050 opened 11 months ago
@chrisbrown2050 What is the bazel version that you're using?
sorry for the delay, new github ID.
We are using bazel 7.1.1, and the error is still emitted. This is causing us significant complexity in our cross-platform build, because we need to use different tool labels on windows vs linux.
sh_binary(
name = "flatc",
srcs = ["bin/flatc.exe"],
visibility = ["//visibility:public"],
)
ERROR: D:/udu/b/kjvohmfq/external/flatbuffers/BUILD.bazel:37:10: in sh_binary rule @@flatbuffers//:flatc: Source file is a Windows executable file, target name extension should match source file extension
The desired fix is to change the implementation to match documentation; relax the check in sh_binary so that the label can be the executable name minus the '.exe'
The sh_binary docs say:
We recommend that you name your sh_binary() rules after the name of the script minus the extension (e.g. .sh); the rule name and the file name must be distinct
But on windows, if the sh_binary is written without extension, this error is thrown:
https://github.com/bazelbuild/bazel/blob/b074ddb86eb0cdb7ca96110d6c3c8b602dde08d8/src/main/java/com/google/devtools/build/lib/bazel/rules/sh/ShBinary.java#L132C27-L132C27
This makes it impossible to declare sh_binaries that wrap pre-compiled windows targets and use them in rules or genrules.
Errors are produced both when an extension is used in target name:
And without extension: