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

Parsing of the WORKSPACE file should be consistent with other parsing contexts #9387

Closed
shs96c opened this issue Sep 16, 2019 · 15 comments
Closed
Labels
P2 We'll consider working on this in future. (Assignee optional) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: feature request

Comments

@shs96c
Copy link
Contributor

shs96c commented Sep 16, 2019

Description of the problem / feature request:

The WORKSPACE file is parsed with a different context to other files. Notably, it's possible to mingle load and other function calls together. The same is not true of files loaded into the WORKSPACE. This makes modularising the WORKSPACE a taxing problem, littered with boilerplate as we try and avoid this inconsistency.

Feature requests: what underlying problem are you trying to solve with this feature?

As an example, Bazel Federation requires someone to load the repositories, then call a function, then load another file, then call another function:

load("@bazel_federation//:repositories.bzl", "rules_java")
rules_java()
load("@bazel_federation//setup:rules_java.bzl", "rules_java_setup")
rules_java_setup()

A similar pattern needs to be followed for people attempting to modularise any WORKSPACE file.

This approach is repetitious and filled with boilerplate, and should really be:

load("@bazel_federation//setup:rules_java.bzl", "rules_java_setup")
rules_java_setup()

Where rules_java_setup first of all loads the respositories.bzl and calls rules_java().

As another example, using maybe in a file that is loaded (but outside of a function) is unsupported, so conditional loading of repositories and subsequent calls to functions defined within those repos is unsupported.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Use Bazel Federation and boggle at the boilerplate.

What's the output of bazel info release?

0.29.0

Have you found anything relevant by searching the web?

Issues that relate to this:

#1550 If load worked within a function, this problem could be mitigated.

#1943 Recursive WORKSPACE loading would allow a clunky and inelegant solution to be implemented.

Any other information, logs, or outputs that you want to share?

I realise that someone is going to suggest the rationale for closing #1550 is still valid. On a technical level, I can buy that for now, but I think that the usability impact of this decision on Bazel users is growing, and as adoption spreads will continue to grow worse. Providing a solution to modularising WORKSPACE files in a way that minimises boilerplate is going to be crucial to enabling a pleasant developer experience.

@dslomov dslomov added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. untriaged labels Sep 16, 2019
@fweikert
Copy link
Member

fweikert commented Oct 1, 2019

@fweikert
Copy link
Member

@keith : That's the issue I mentioned to you at BazelCon.

@keith
Copy link
Member

keith commented Dec 12, 2019

Thanks. We're interested in this because we depend on Envoy with Bazel through other repos and we end up having to make sure we load the rules that are dependencies of Envoy from their workspace which requires pulling out WORKSPACE dependencies into bzl file and making sure to call those loads too.

@laurentlb laurentlb added P1 I'll work on this now. (Assignee required) type: feature request and removed untriaged labels Dec 16, 2019
@laurentlb
Copy link
Contributor

It's a known pain-point. Unfortunately, this is non-trivial to fix and might require a lot of design work to decide where we want to go with workspace files.

@fweikert
Copy link
Member

@philwo philwo added the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Jun 15, 2020
@philwo philwo added P2 We'll consider working on this in future. (Assignee optional) and removed P1 I'll work on this now. (Assignee required) labels Nov 9, 2020
@philwo
Copy link
Member

philwo commented Nov 9, 2020

I'm marking this as P2, because with the new external deps design that @meteorcloudy and @Wyverald are working on, I assume that this will become irrelevant.

(@keith Please let me know if I'm judging this wrongly.)

@keith
Copy link
Member

keith commented Nov 9, 2020

As long as recursive workspaces are supported for that, I think it should be fine!

@philwo
Copy link
Member

philwo commented Nov 10, 2020

@keith I don't think we'll add recursive workspaces or any other new features to the WORKSPACE file parsing. Instead, we're aiming for the WORKSPACE file to be a flat namespace and prevent any transitive loading in the future (like the current deps.bzl pattern). Ideally, we can then also remove all current HTTP, Git, etc. repository features from Bazel and only leave the "local repository".

Instead, the complexity of recursive / transitive dependency resolution, clean modularization and downloading modules from various sources will be solved via the new external tool bzlmod, which will generate a flat WORKSPACE file and handle downloads.

The design for that is here: https://groups.google.com/g/bazel-dev/c/6TEyoGb9ys0 - please comment on the doc if you think this doesn't address your requirements! 😊

@shs96c
Copy link
Contributor Author

shs96c commented Aug 19, 2021

Tagging at @hicksjoseph after discussing with him away from GitHub.

@hicksjoseph
Copy link

Hi Simon, I remember that we discussed this issue, but now I forget the next steps or desired outcome. Can you recap your thoughts here? Thanks, Joe

@shs96c
Copy link
Contributor Author

shs96c commented Oct 7, 2021

The key feature was the ability to interleave load statements and other statements from files loaded from the WORKSPACE, allowing the .bzl files to be used to prevent the WORKSPACE file from becoming overwhelming and unmaintainable.

@Wyverald
Copy link
Member

Wyverald commented Oct 7, 2021

Thanks for the context, @shs96c. I realize we're years late here, but the new external dependency system "bzlmod" should solve the pains you mentioned without requiring interleaving load in .bzl files. (In fact, it's such a technical burden that we want to get rid of it altogether.) With the new system, you don't need all that boilerplate to set up a dependency; simply adding the dependency will trigger all its setup logic.

With that in mind, I'm going to close this issue.

@Wyverald Wyverald closed this as completed Oct 7, 2021
@hicksjoseph
Copy link

Hi Xudong, Do you have a public link to information on bzlmod that also has a summary and background section? If not, perhaps we can make one together, post it, and link it to this issue. Thanks, Joe

@hicksjoseph hicksjoseph reopened this Oct 7, 2021
@Wyverald
Copy link
Member

Wyverald commented Oct 8, 2021

The most up-to-date information remains the original design doc Philipp linked to in #9387 (comment). It needs a bit of refreshing but the general idea is still intact.

@hicksjoseph
Copy link

Thanks much Xudong. I will follow up with Simon directly if he has any questions.

@philwo philwo removed the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: feature request
Projects
None yet
Development

No branches or pull requests

8 participants