bazel-skylib icon indicating copy to clipboard operation
bazel-skylib copied to clipboard

Keep version in sync between MODULE.bazel and version.bzl

Open tetromino opened this issue 3 years ago • 9 comments

Reminder to myself: after merging https://github.com/bazelbuild/bazel-skylib/pull/385, we will need some sort of a diff test to keep the module version and the version.bzl version in sync; neither file can load the other - MODULE.bazel prohibits load statements.

tetromino avatar Aug 30 '22 17:08 tetromino

The natural way to do so would be to extract version from MODULE.bazel via buildozer:

cat MODULE.bazel | buildozer 'print version' '-:bazel_skylib'

Unfortunately, this means we need to depend on buildozer, and while this is easy enough to do via WORKSPACE, it fails with --experimental_enable_bzlmod:

error loading package '@gazelle~0.26.0~go_deps~com_github_bazelbuild_buildtools//api_proto': Unable to find package for @[unknown repo 'rules_proto' requested from @gazelle~0.26.0~go_deps~com_github_bazelbuild_buildtools]//proto:defs.bzl: The repository '@[unknown repo 'rules_proto' requested from @gazelle~0.26.0~go_deps~com_github_bazelbuild_buildtools]' could not be resolved: Repository '@rules_proto' is not visible from repository '@gazelle~0.26.0~go_deps~com_github_bazelbuild_buildtools'. and referenced by '@gazelle~0.26.0~go_deps~com_github_bazelbuild_buildtools//edit:go_default_library'

I believe that I'm hitting https://github.com/bazelbuild/rules_go/issues/3265

Alternatively, we could avoid the problem trivially if there were an official buildtools module in the central registery - but it doesn't exist yet.

Current work in progress is sitting at https://github.com/tetromino/bazel-skylib/tree/version_consistency a.k.a. https://github.com/bazelbuild/bazel-skylib/pull/396

tetromino avatar Sep 08 '22 20:09 tetromino

@tetromino I just submitted a PR that should add support for go_proto_library to rules_go with Bzlmod: https://github.com/bazelbuild/rules_go/pull/3283. I manually verified that it can build buildozer.

fmeum avatar Sep 09 '22 08:09 fmeum

rules_go 0.34.0 is now available in the register and should support go_proto_library.

fmeum avatar Sep 12 '22 08:09 fmeum

rules_go 0.34.0 is now available in the register and should support go_proto_library.

0.34.0 was released in July. I think your fix is in 0.35.0, which isn't in the register yet :)

tetromino avatar Sep 12 '22 16:09 tetromino

Given the experimental status of rules_go's bzlmod support as well as the BCR, we decided to continuously push updates to it, modifying existing versions if necessary - so 0.34.0 is indeed what you want. That will of course change when the BCR and Bzlmod support in Bazel become more stable.

fmeum avatar Sep 12 '22 16:09 fmeum

Hmm. I've confirmed that 0.34.0 that got downloaded by bazel from BCR into my external/ dir does have the fix, but I'm still hitting the same error - Repository '@rules_proto' is not visible from repository '@gazelle~0.26.0~go_deps~com_github_bazelbuild_buildtools'

ERROR: /private/var/tmp/_bazel_$USER/b2b208390ac65027996afab7ba69d49e/external/gazelle~0.26.0~go_deps~com_github_bazelbuild_buildtools/edit/BUILD.bazel:3:11: error loading package '@gazelle~0.26.0~go_deps~com_github_bazelbuild_buildtools//build_proto': Unable to find package for @[unknown repo 'rules_proto' requested from @gazelle~0.26.0~go_deps~com_github_bazelbuild_buildtools]//proto:defs.bzl: The repository '@[unknown repo 'rules_proto' requested from @gazelle~0.26.0~go_deps~com_github_bazelbuild_buildtools]' could not be resolved: Repository '@rules_proto' is not visible from repository '@gazelle~0.26.0~go_deps~com_github_bazelbuild_buildtools'. and referenced by '@gazelle~0.26.0~go_deps~com_github_bazelbuild_buildtools//edit:go_default_library'
ERROR: Analysis of target '//tests:bazel_skylib_version_consistency_test' failed; build aborted:

tetromino avatar Sep 12 '22 17:09 tetromino

Ah, I now understand the problem: I also need https://github.com/bazelbuild/bazel-gazelle/pull/1331

Time for git_override.

tetromino avatar Sep 12 '22 17:09 tetromino

Gazelle 0.26.0 should have the fix, but it was updated in place so you might need to clean.

fmeum avatar Sep 12 '22 17:09 fmeum