buildtools icon indicating copy to clipboard operation
buildtools copied to clipboard

Migrate to Bzlmod for managing external dependencies

Open meteorcloudy opened this issue 2 years ago • 7 comments
trafficstars

With future Bazel LTS versions, Bzlmod will become the default system for external dependencies management.

Please consider migrating all your external dependencies in WORKSPACE to MODULE.bazel

For more information, please check https://github.com/bazelbuild/bazel/issues/18958

meteorcloudy avatar Oct 06 '23 13:10 meteorcloudy

I would love to use this repo through a Bazel module as well! I use Bazel modules and I had to write my own module extension to load it as an http_archive which is a hassle. I would be open to helping with the migration if there are any well scoped tasks I could take on.

AttilaTheFun avatar Oct 20 '23 17:10 AttilaTheFun

@AttilaTheFun This issue is more about migrating buildtools to be built and tested with external deps fetched from Bzlmod. Do you mean you want to buildtools as an external dependency? Can you explain a bit about why you need to do that?

meteorcloudy avatar Oct 23 '23 09:10 meteorcloudy

@meteorcloudy I know you can install buildifier and buildozer as prebuilt binaries, but I much prefer to add them as bazel dependencies and build from source.

This is especially useful if I want to use forked copy of the repo while waiting for changes to be merged upstream. I also don't need to worry about selecting the right binary for use on the machine (macos arm vs intel, linux on ci).

AttilaTheFun avatar Oct 23 '23 16:10 AttilaTheFun

I see, that sounds doable. @vladmos is the main maintainer of buildtools, I assume he'll be happy to accept the contributions ;)

meteorcloudy avatar Oct 30 '23 10:10 meteorcloudy

@meteorcloudy @vladmos FYI other people are requesting this on the bazelbuild/bazel-central-registry side too: https://github.com/bazelbuild/bazel-central-registry/issues/380 I'm not sure what providing a Bazel module requires beyond adding a MODULE.bazel file to the repository. If I had a more concrete understanding of what the remaining issues are, I could possibly help out.

AttilaTheFun avatar Jan 02 '24 19:01 AttilaTheFun

I tried and took a stab at adding support, but the check on the generated proto files fails due to the version mismatch between protoc-gen-go and protoc. Bazel central registry doesn't have 24.4 or latest protobuf yet. Otherwise it looks to be working fine.

https://github.com/fardream/buildtools/commit/51b8a3f3ad767a4b91b0f160263eb11d14b05c98

fardream avatar Feb 04 '24 03:02 fardream

For the record, there's an unofficial repo that allows setting up buildifier via MODULE.bazel: https://github.com/keith/buildifier-prebuilt

Example:

# MODULE.bazel
bazel_dep(name = "buildifier_prebuilt", version = "6.4.0", dev_dependency = True)
# ./BUILD
load("@buildifier_prebuilt//:rules.bzl", "buildifier")

buildifier(
    name = "buildifier.check",
    exclude_patterns = [
        "./.git/*",
    ],
    lint_mode = "warn",
    mode = "diff",
)
$ bazel run -- //:buildifier.check
INFO: Analyzed target //:buildifier.check (68 packages loaded, 343 targets configured).
INFO: Found 1 target...
Target //:buildifier.check up-to-date:
  bazel-bin/buildifier.check.bash
INFO: Elapsed time: 0.387s, Critical Path: 0.01s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/buildifier.check.bash
./tests/BUILD:
--- ./tests/BUILD       2024-02-20 20:26:07.852510800 -0800
+++ /tmp/buildifier-tmp-1708334010      2024-02-20 20:26:09.836148000 -0800
@@ -4,8 +4,8 @@

 py_library(
     name = "__init__",
-    deps = [],
     srcs = ["__init__.py"],
+    deps = [],
 )

 py_library(
exit status 1

dougthor42 avatar Feb 21 '24 04:02 dougthor42