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

go is only meant to be used with 'bazel run', not as a tool #4283

Open
Zemnmez opened this issue Feb 25, 2025 · 0 comments
Open

go is only meant to be used with 'bazel run', not as a tool #4283

Zemnmez opened this issue Feb 25, 2025 · 0 comments

Comments

@Zemnmez
Copy link

Zemnmez commented Feb 25, 2025

I'm trying to run a tool that uses gocommand (oapi-codegen), and thus needs Go in path in a genrule (it's used with go:generate, so this makes sense).

See below script:

genrule(
    name = "gen_api",
    srcs = [
        "@com_github_openai_openai_openapi//:openapi.yaml",
        "codegen.yaml",
    ],
    outs = ["api.go"],
    cmd = """
	export PATH=$$(dirname $$(realpath $(location //bin/sh:go))):$$PATH


$(execpath //bin/host/oapi-codegen) \\
	-config $(location codegen.yaml) \\
	-o $(location api.go) \\
	 $(location @com_github_openai_openai_openapi//:openapi.yaml)
	""",
    tools = [
        "//bin/host/oapi-codegen",
        "//sh/bin:go",
    ],
)

I get the below error:

                fail("//go is only meant to be used with 'bazel run', not as a tool. " +
Error in fail: //go is only meant to be used with 'bazel run', not as a tool. If you need to use it as a tool (e.g. in a genrule), please open an issue at https://github.com/bazelbuild/rules_go/issues/new explaining your use case.

This works in CI because the CI runner has go installed , but I think it's a little strange to need to do that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant