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

feat: support bzlmod usage of jq/yq #88

Merged
merged 2 commits into from Apr 28, 2022
Merged

feat: support bzlmod usage of jq/yq #88

merged 2 commits into from Apr 28, 2022

Conversation

alexeagle
Copy link
Member

No description provided.

@alexeagle
Copy link
Member Author

This has to disable our docs generation due to bazelbuild/bazel#14140

It also has to remove our gazelle setup for maintaining the bzl_library targets due to bazelbuild/bazel-skylib#250

@alexeagle alexeagle force-pushed the bzlmod branch 5 times, most recently from 1cceab8 to a838fdd Compare April 27, 2022 20:18
@alexeagle alexeagle marked this pull request as ready for review April 27, 2022 20:18
@alexeagle alexeagle requested a review from kormide April 27, 2022 20:18
@alexeagle alexeagle changed the title refactor: use MODULE.bazel instead of WORKSPACE feat: support bzlmod usage of jq/yq Apr 27, 2022
@alexeagle
Copy link
Member Author

Reduced scope here, instead of trying to switch from WORKSPACE to MODULE.bazel for local development, just added an e2e folder that verifies users can use it as a bzlmod module.

Needs some CI setup in a followup so the e2e is actually getting tested. I verified manually with cd e2e/bzlmod; bazel test ...

MODULE.bazel Outdated
Comment on lines 16 to 18
ext = use_extension("@aspect_bazel_lib//lib:extensions.bzl", "lib")
use_repo(ext, "jq_toolchains")
use_repo(ext, "yq_toolchains")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do consumers need this to be in our MODULE file? Wouldn't they just include it in theirs to use the toolchains?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it needs to be in our file in order for the new e2e to succeed, because we reference it above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we declare it a dev dependency?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's a dev dependency, then the user gets

ERROR: /home/alexeagle/Projects/bazel-lib/e2e/bzlmod/BUILD.bazel:5:3: While resolving toolchains for target //:case_no_sources: invalid registered toolchain '@jq_toolchains//:all': @jq_toolchains is not visible from repository `@aspect_bazel_lib`

which I think makes sense, when the user evaluates this file it's like all the dev_dependency lines don't exist

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this example, we use the toolchain under our jq rule implementation.
If users want to reference the toolchain themselves, then yes they'd need this too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. So users are forced to download the toolchain even if they don't use jq?

Copy link
Member Author

@alexeagle alexeagle Apr 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great question, looking in the external/ folder under the e2e/bzlmod I see

aspect_bazel_lib.ext.jq_linux_amd64
aspect_bazel_lib.ext.jq_toolchains
aspect_bazel_lib.ext.yq_toolchains
aspect_bazel_lib.lib.jq_linux_amd64
aspect_bazel_lib.lib.jq_toolchains
aspect_bazel_lib.lib.yq_toolchains

Which is what I hoped - the yq toolchain wasn't used by this example, so Bazel never fetched the binary.
(lib and ext are duplicated just because I renamed the module extension, and the repos get namespaced this way, and I didnt' clean --expunge )

lib/extensions.bzl Outdated Show resolved Hide resolved
@kormide
Copy link
Member

kormide commented Apr 27, 2022

Reduced scope here, instead of trying to switch from WORKSPACE to MODULE.bazel for local development, just added an e2e folder that verifies users can use it as a bzlmod module.

Needs some CI setup in a followup so the e2e is actually getting tested. I verified manually with cd e2e/bzlmod; bazel test ...

I think you can just add a simple shell script under e2e that does a cd then calls bazel, then the ci will run it.

@kormide
Copy link
Member

kormide commented Apr 27, 2022

Not for this PR, but I guess we'll need to publish sample MODULE.bazel snippets on release to show how to use the extensions.

@kormide
Copy link
Member

kormide commented Apr 27, 2022

I think we're missing a bzlmod dependency on stardoc.

EDIT: Oh, that isn't in the bcr..

EDIT: Yes it is, just under a different name.

lib/extensions.bzl Outdated Show resolved Hide resolved
@alexeagle alexeagle force-pushed the bzlmod branch 5 times, most recently from 8608689 to 29494cf Compare April 27, 2022 23:47
e2e/bzlmod/BUILD.bazel Outdated Show resolved Hide resolved
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

Successfully merging this pull request may close these issues.

None yet

2 participants