Skip to content

Attribute linkmode in go_binary doesn't support select #4479

@alextercete

Description

@alextercete

When trying to create a cross-platform go_binary target that works for Linux/Android and 32/64 bits, the standard approach would be to use a select (unless #4478 is fixed):

config_setting(
    name = "armv7_linux",
    constraint_values = [
        "@platforms//cpu:armv7",
        "@platforms//os:linux",
    ],
)

go_binary(
    name = "run",
    srcs = ["run.go"],
    linkmode = select({
        ":armv7_linux": "normal",
        "//conditions:default": "pie",
    }),
    pure = "on",
)

However, this fails with:

ERROR: (...): in go_non_executable_binary rule //:run: Returning RunEnvironmentInfo from a non-executable, non-test target has no effect

It looks like the issue is that you're not handling a select in go_binary_macro:

if kwargs.get("linkmode", LINKMODE_NORMAL) in LINKMODES_EXECUTABLE:
go_binary(name = name, **kwargs)
else:
go_non_executable_binary(name = name, **kwargs)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions