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_cross_binary stops working with bazel 8 #4192

Closed
fishy opened this issue Dec 9, 2024 · 3 comments
Closed

go_cross_binary stops working with bazel 8 #4192

fishy opened this issue Dec 9, 2024 · 3 comments

Comments

@fishy
Copy link
Contributor

fishy commented Dec 9, 2024

What version of rules_go are you using?

0.50.1

What version of gazelle are you using?

0.40.0

What version of Bazel are you using?

8.0.0

Does this issue reproduce with the latest releases of all the above?

Those are latest releases

What operating system and processor architecture are you using?

linux/amd64

Any other potentially useful information about your toolchain?

What did you do?

From the discussion of #4131, we are using the following to do cross build for container image:

  • on top level BUILD.bazel:
platform(
    name = "amd64_v1",
    constraint_values = [
        "@platforms//os:linux",
        "@platforms//cpu:x86_64",
        "@rules_go//go/constraints/amd64:v1",
    ],
)

alias(
    name = "linux_amd64",
    actual = ":amd64_v1",
    visibility = ["//visibility:public"],
)
  • in the directory with go binary:
go_binary(
    name = "foo",
    embed = [":foo_lib"],
    pure = "on",
    visibility = ["//visibility:public"],
    x_defs = {
        ...,
    },
)

go_cross_binary(
    name = "linux_amd64/foo",
    platform = "//:linux_amd64",
    target = ":foo",
    visibility = ["//visibility:public"],
)

pkg_tar(
    name = "bin",
    srcs = [
        ":linux_amd64/foo",
    ],
    mode = "0755",
    package_dir = "/bin",
)

# Then package bin to oci_image

This works with bazel 7, but when I try update bazel to 8, I'm starting to get:

$ bazel build //path/to/foo:bin
ERROR: no such package '@@[unknown repo 'platforms' requested from @@]//cpu': The repository '@@[unknown repo 'platforms' requested from @@]' could not be resolved: No repository visible as '@platforms' from main repository. Was the repository introduced in WORKSPACE? The WORKSPACE file is disabled by default in Bazel 8 (late 2024) and will be removed in Bazel 9 (late 2025), please migrate to Bzlmod. See https://bazel.build/external/migration
ERROR: /path/to/top/BUILD.bazel:10:9: no such package '@@[unknown repo 'platforms' requested from @@]//cpu': The repository '@@[unknown repo 'platforms' requested from @@]' could not be resolved: No repository visible as '@platforms' from main repository. Was the repository introduced in WORKSPACE? The WORKSPACE file is disabled by default in Bazel 8 (late 2024) and will be removed in Bazel 9 (late 2025), please migrate to Bzlmod. See https://bazel.build/external/migration and referenced by '//:amd64_v1'
ERROR: /path/to/top/path/to/foo/BUILD.bazel:115:16: Target //:linux_amd64 was referenced as a platform, but does not provide PlatformInfo
ERROR: Analysis of target '//path/to/foo:bin' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.356s, Critical Path: 0.01s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully

I tried to look up the bazel docs regarding platforms for 8 and they doesn't seem changed from 7, so I'm not sure whether this is an issue with rules_go or something with bazel 8. I currently don't have any bzlmod dependency to platform or @platforms, not sure if that's migrated to a bzlmod (I found https://registry.bazel.build/modules/rules_platform & https://registry.bazel.build/modules/platforms on BCR but neither look like the provider of @platforms to me).

What did you expect to see?

What did you see instead?

@fmeum
Copy link
Member

fmeum commented Dec 10, 2024

unknown repo 'platforms' requested from @@ means that the main repository doesn't see any repo under the name platforms. Since Bazel 8 disabled WORKSPACE by default, you either need to pass --enable_workspace or add a bazel_dep on the platforms module.

@fmeum fmeum closed this as not planned Won't fix, can't repro, duplicate, stale Dec 10, 2024
@fishy
Copy link
Contributor Author

fishy commented Dec 10, 2024

oh so this is bazel_dep(name = "platforms", version = "0.0.10") in MODULE.bazel, in bazel 7 it's from indirect dependency (likely via rules_go) and that's enough, but in bazel 8 it must be declared as direct dependency to work.

@fmeum
Copy link
Member

fmeum commented Dec 11, 2024

platforms is treated specially when WORKSPACE is enabled purely for backwards compatibility, you generally have to declare all repos as direct deps that you reference.

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

2 participants