Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistency between sh_binary docs and implementation #20345

Open
chrisbrown2050 opened this issue Nov 28, 2023 · 2 comments
Open

Inconsistency between sh_binary docs and implementation #20345

chrisbrown2050 opened this issue Nov 28, 2023 · 2 comments
Labels
area-Windows Windows-specific issues and feature requests P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Server Issues for serverside rules included with Bazel type: bug

Comments

@chrisbrown2050
Copy link

chrisbrown2050 commented Nov 28, 2023

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:

throw ruleContext.throwWithRuleError(
            "Source file is a Windows executable file,"
                + " target name extension should match source file extension");

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:

sh_binary(
    name = "mico-cpp.exe",
    srcs = ["mico-cpp.exe"],
)
used in rule attr:
        "_mico_cpp": attr.label(default = Label("@MICO//:mico-cpp.exe"), cfg = "host", executable=True),
results in:
ERROR: D:/udu/b/3dsz6nhl/external/MICO/BUILD.bazel:8:10: in sh_binary rule @MICO//:mico-cpp.exe: cycle in dependency graph:
    //src/server/icctskel:iccsadmin (9a08aa5e3d90fb8851bc398dec9ff1911a24c740b15279b4060412bc62040da3)
.-> @MICO//:mico-cpp.exe (929e5caa53c9bca4d9772686a4099333b8897f5d50a002376b67885bbefaa012) [self-edge]

And without extension:

sh_binary(
    name = "mico-cpp",
    srcs = ["mico-cpp.exe"],
)
used in rule attr:
        "_mico_cpp": attr.label(default = Label("@MICO//:mico-cpp"), cfg = "host", executable=True),
gives this:
ERROR: D:/udu/b/3dsz6nhl/external/MICO/BUILD.bazel:8:10: in sh_binary rule @MICO//:mico-cpp: Source file is a Windows executable file, target name extension should match source file extension
@iancha1992 iancha1992 added area-Windows Windows-specific issues and feature requests team-Rules-Server Issues for serverside rules included with Bazel untriaged type: bug more data needed and removed untriaged labels Nov 28, 2023
@iancha1992
Copy link
Member

@chrisbrown2050 What is the bazel version that you're using?

@comius comius added P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed untriaged labels Dec 27, 2023
@peakschris
Copy link

peakschris commented May 8, 2024

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Windows Windows-specific issues and feature requests P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Server Issues for serverside rules included with Bazel type: bug
Projects
None yet
Development

No branches or pull requests

4 participants