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

v0.10.0 breaks @com_google_protobuf with "cannot load '@@rules_pkg~0.10.0//:mappings.bzl': no such file" #810

Closed
yuan-attrove opened this issue Jan 11, 2024 · 15 comments
Assignees
Labels
P1 An issue that must be resolved. Must have an assignee

Comments

@yuan-attrove
Copy link

My error with v0.10.0

bazel_dep(name = "rules_pkg", version = "0.10.0") gives the following error:

ERROR: error loading package '@@com_google_protobuf//': cannot load '@@rules_pkg~0.10.0//:mappings.bzl': no such file

While
bazel_dep(name = "rules_pkg", version = "0.9.1") builds fine.

Searching in the protobuf repo, it seems to be relying on v0.7.0:

Code where @rules_pkg//:mappings.bzl is used:
https://github.com/search?q=repo%3Aprotocolbuffers%2Fprotobuf%20rules_pkg&type=code

Issue #596 suggests it has been rules_pkg//pkg:mappings.bzl since v0.7.1. Not sure how the version resolution works. Why does v0.9.1 work while v0.10.0 doesn't?

My setup:

  1. Use bzlmod. Have com_google_protobuf in WORKSPACE.bzlmod:
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "com_google_protobuf",
    sha256 = "3c83e4301b968d0b4f29a0c29c0b3cde1da81d790ffd344b111c523ba1954392",
    strip_prefix = "protobuf-3.25.2",
    urls = [
        "https://github.com/protocolbuffers/protobuf/archive/refs/tags/v3.25.2.tar.gz",
    ],
)

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()
  1. Have a protobuf depends on "google/protobuf/timestamp.proto"

In my.proto:

import "google/protobuf/timestamp.proto";

message MyProto {
  google.protobuf.Timestamp my_time = 1;
}

In BUILD.bazel:

proto_library(
    name = "my_proto",
    srcs = [
        "my.proto",
    ],
    visibility = ["//visibility:public"],
    deps = ["@com_google_protobuf//:timestamp_proto"],
)

my_proto is further depended by a go_proto_library which is then depended by a go_binary, then further by a pkg_tar, and finally in oci_image.

bazel version:

Bazelisk version: development
Build label: 7.0.0
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Mon Dec 11 16:52:42 2023 (1702313562)
Build timestamp: 1702313562
Build timestamp as int: 1702313562
@aiuto
Copy link
Collaborator

aiuto commented Jan 11, 2024 via email

@yuan-attrove
Copy link
Author

//:mapping.bzl has been deprecated for a long time.

Based on 596, I assume it was deprecated before v0.9.1. If that's true it doesn't explain why v0.9.1 works while v0.10.0 doesn't.

I have created a repo for reproducing the issue: https://github.com/yuan-attrove/rules_pkg_810.

From the root of the repo, the command

bazelisk build :server-image

works as the repo is.

Changing 0.9.1 to 0.10.0 makes the above command fail with the error in comment#1 (#810 (comment))

protobuf needs a fix, or use an older rules_pkg.

protobuf seems to pin rules_pkg to v0.7.0: https://github.com/protocolbuffers/protobuf/blob/27275da1c0033331e55277613f32457b2500e811/protobuf_deps.bzl#L113-L119. But again I am not sure how version resolution works here.

@yuan-attrove
Copy link
Author

A side note, may not be relevant. 0.10.0 is not showing up in bazel central registry: https://registry.bazel.build/modules/rules_pkg

@aiuto
Copy link
Collaborator

aiuto commented Jan 12, 2024 via email

@alokpr
Copy link

alokpr commented Jan 14, 2024

protobuf is indeed using an old version - 0.7.0 - https://github.com/protocolbuffers/protobuf/blob/7b42f1c08b534f9e43629284e22acce6b13e7136/protobuf_deps.bzl#L116

However, this is still a problem for a project that uses the latest version of rules_pkg and protobuf. Would it be possible to provide a shim layer for backwards compatibility (like deps.bzl)?

@aiuto
Copy link
Collaborator

aiuto commented Jan 14, 2024 via email

@alokpr
Copy link

alokpr commented Jan 14, 2024

That's exacty what we are doing - loading rules_pkg before protobuf. The latest version of protobuf does not work against the latest version of rules_pkg. It uses @rules_pkg//:mappings.bzl which has been deleted in rules_pkg.

https://github.com/protocolbuffers/protobuf/blob/7b42f1c08b534f9e43629284e22acce6b13e7136/BUILD.bazel#L5

@aiuto
Copy link
Collaborator

aiuto commented Jan 15, 2024 via email

@alokpr
Copy link

alokpr commented Jan 15, 2024

Wouldn't all clients of rules_pkg have to do this? Wouldn't it be better to add this shim in rules_pkg itself to make the upgrade to a new version of rules_pkg easier? I suspect that most projects would just pin rules_pkg to an old version to avoid this breaking change.

@aiuto
Copy link
Collaborator

aiuto commented Jan 15, 2024 via email

@phlax
Copy link

phlax commented Jan 18, 2024

#596 (comment)

@phlax
Copy link

phlax commented Jan 26, 2024

updating protobuf is non-trivial due to rules_ruby having a dependency on this repo also

ill look at it again next week

@aiuto aiuto self-assigned this Feb 8, 2024
@aiuto aiuto added the P1 An issue that must be resolved. Must have an assignee label Feb 8, 2024
@aiuto
Copy link
Collaborator

aiuto commented Feb 8, 2024

I'll add in a symlink for mappings.bzl, and do a patch release, but this must also be fixed in protobuf.
protocolbuffers/protobuf#15779

@aiuto
Copy link
Collaborator

aiuto commented Feb 8, 2024

Being addressed in #817

@aiuto
Copy link
Collaborator

aiuto commented Feb 14, 2024

Fixed by #817. To be in 0.10.1. That is done, but not in BCR yet.

@aiuto aiuto closed this as completed Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 An issue that must be resolved. Must have an assignee
Projects
None yet
Development

No branches or pull requests

4 participants