Search code examples
bazel

bazel 8 : no such package '@@[unknown repo 'platforms' requested from @@]//os'


I had to roll back a bazel upgrade from 8.x back to 7.x because of the following error occuring in my builds.

no such package '@@[unknown repo 'platforms' requested from @@]//os': The repository '@@[unknown repo 'platforms' requested from @@]' could not be resolved: No repository visible as '@platforms' from main repository

What do I need to change to fix it ? I'm still a bit of a bazel noob.

My module.bazel:

module(
    name = "REDACTED",
    version = "0.1.0",
)

bazel_dep(name = "rules_go", version = "0.52.0")
bazel_dep(name = "gazelle", version = "0.41.0")

go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.nogo(nogo = "//:my_nogo")
go_sdk.download(version = "1.23.4")

go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")
use_repo(go_deps, "com_github_aws_aws_sdk_go_v2", "com_github_aws_aws_sdk_go_v2_config", "com_github_aws_aws_sdk_go_v2_service_sesv2", "com_github_go_acme_lego_v4", "com_github_jackc_pgx_v5", "com_github_jub0bs_cors", "com_github_prometheus_client_golang", "com_github_prometheus_client_model", "com_github_prometheus_common", "io_opentelemetry_go_otel", "org_golang_google_protobuf", "org_golang_x_crypto", "org_golang_x_net")

My build.bazel:

load("@gazelle//:def.bzl", "gazelle")
load("@rules_go//go:def.bzl", "nogo")

#gazelle:map_kind go_binary go_binary //rules/go:rules_go.bzl

gazelle(name = "gazelle")

gazelle(
    name = "gazelle-update-repos",
    args = [
        "-from_file=go.mod",
        "-prune",
    ],
    command = "update-repos",
)

gazelle(
    name = "gazelle-fix",
    command = "fix",
)

nogo(
    name = "my_nogo",
    vet = True,
    visibility = ["//visibility:public"],
)

My .bazelrc:

build:mac_arm64 --platforms=@rules_go//go/toolchain:darwin_arm64 --stamp --workspace_status_command="$(pwd)/version.sh"
build:linux_amd64 --platforms=@rules_go//go/toolchain:linux_amd64 --stamp --workspace_status_command="$(pwd)/version.sh"
build:bsd_amd64 --platforms=@rules_go//go/toolchain:openbsd_amd64 --stamp --workspace_status_command="$(pwd)/version.sh"

Solution

  • Bazel 8 no longer accepts indirect dependencies (in my case, platforms via rules_go). You now have to declare explicitly:

    https://github.com/bazel-contrib/rules_go/issues/4192#issuecomment-2532276415