Skip to content

Conversation

@meteorcloudy
Copy link
Member

@meteorcloudy meteorcloudy commented Jan 3, 2023

Historically, Bazel checks in precompiled jar dependencies under the third_party directory, which has a few drawbacks:

  • Due to those precompiled artifacts, we cannot check in the third_party directory into google3. This means we often have to split a PR into third_party and non-third_party changes and merge them separately, which makes it very hard to maintain the dependencies under third_party directory.
  • Checked in jar files are large and will forever increase the size of the Bazel git repository.
  • Checked in jar files are supposed to be downloaded from Maven Central Repository, but there is no verification on that.

This PR tries to use rules_jvm_external to replace the checked-in guava jar files and all jar dependencies in guava's transitive clousure. To achieve this and not breaking Bazel's offline bootstrap build, we had to

  • Patch rules_jvm_external to make it easier to vendor the @maven repository and export downloaded jar files.
  • Vendor BUILD, WORKSPACE and jar files from the @maven repository in the bootstrap distfile.
  • Point filegroup targets of jar files required by the bootstrap java toolchain to use jar files from the @maven repository.

This PR doesn't yet replace and remove all checked-in jar files, but it provides a framework to do so and can help avoid #17014

This is also working towards resolving #17036

@meteorcloudy meteorcloudy requested review from Wyverald and aiuto January 3, 2023 05:36
@meteorcloudy
Copy link
Member Author

FYI @rjobredeaux3

@sgowroji sgowroji added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. awaiting-review PR is awaiting review from an assigned reviewer labels Jan 3, 2023
Copy link

@aiuto aiuto left a comment

Choose a reason for hiding this comment

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

Nice start. Just some questions and a nit or two.

@haxorz
Copy link
Contributor

haxorz commented Jan 3, 2023

Hey @meteorcloudy , what do sort of review do you need from me? Or is @aiuto 's review sufficient?

@meteorcloudy
Copy link
Member Author

@haxorz I think you are somehow suggested by GitHub, @aiuto and @Wyverald should be enough, thanks!

@meteorcloudy meteorcloudy removed the request for review from haxorz January 4, 2023 05:57
@meteorcloudy
Copy link
Member Author

/cc @ted-xie @comius feel free to take a look, but mostly I'm adding you as FYI

@meteorcloudy meteorcloudy requested review from fweikert and removed request for comius and ted-xie January 4, 2023 05:58
Copy link

@aiuto aiuto left a comment

Choose a reason for hiding this comment

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

This is great.
Will the next phase be to replace the targets java_library targets like //third_party:jsr305 with targets outside of //third_party, so that we eventually reduce //third_party/BUILD to nothing?

Copy link
Member

@Wyverald Wyverald left a comment

Choose a reason for hiding this comment

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

nice!!!

@meteorcloudy
Copy link
Member Author

so that we eventually reduce //third_party/BUILD to nothing?

Something like that, at least we want to remove all content under third_party that prevents us from checking in this directory into google3.

@meteorcloudy
Copy link
Member Author

Thanks for the review, I'll split this change into separate PRs to merge it.

meteorcloudy added a commit to meteorcloudy/bazel that referenced this pull request Jan 5, 2023
meteorcloudy added a commit to meteorcloudy/bazel that referenced this pull request Jan 5, 2023
meteorcloudy added a commit to meteorcloudy/bazel that referenced this pull request Jan 5, 2023
- Delete replaced jar files and update BUILD files.

Merging bazelbuild#17112
@jin
Copy link
Member

jin commented Jan 5, 2023

cc @shs96c @cheister


load("@rules_jvm_external//:defs.bzl", "maven_install")

maven_install(
Copy link
Member

Choose a reason for hiding this comment

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

Please also use pinning to use bazel's downloader and repo caching instead of coursier.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I see, thanks! Does the pinning also work with Bzlmod?

Copy link
Member

Choose a reason for hiding this comment

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

It should! @shs96c could correct me if it doesn't :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice, I'll try it!

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, please take another look ;)

Copy link
Member Author

@meteorcloudy meteorcloudy Jan 5, 2023

Choose a reason for hiding this comment

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

Looks like the vendoring of @maven no longer works. glob(["v1/**/*.jar"]) doesn't work anymore since jar files are copied by a genrule from their own repo. Have to figure out a workaround..

Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/bazelbuild/rules_jvm_external#accessing-transitive-dependencies-list may be useful to generate BUILD rules on the Bazel side if all you need is a way to get the complete list of artifacts.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I still have to hack rules_jvm_external to make it work. Basically, I need to mock the maven repository for the bootstrap build, which includes vendoring all the jar files and generate a usable BUILD file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Pinning works with bzlmod, and if there are problems, that's a bug that we should fix :)

meteorcloudy added a commit to meteorcloudy/bazel that referenced this pull request Jan 5, 2023
meteorcloudy added a commit to meteorcloudy/bazel that referenced this pull request Jan 5, 2023
- Delete replaced jar files and update BUILD files.

Merging bazelbuild#17112
copybara-service bot pushed a commit that referenced this pull request Jan 10, 2023
- Non-third_party changes in #17112

Merging #17112

Stacking on #17142

Closes #17143.

PiperOrigin-RevId: 500980364
Change-Id: Ie03d4bc8e167d8a27ed8b33cd90f2e3af2c472f6
@meteorcloudy
Copy link
Member Author

Merged by #17142, #17143, #17144

hvadehra pushed a commit that referenced this pull request Feb 14, 2023
- Non-third_party changes in #17112

Merging #17112

Stacking on #17142

Closes #17143.

PiperOrigin-RevId: 500980364
Change-Id: Ie03d4bc8e167d8a27ed8b33cd90f2e3af2c472f6
meteorcloudy added a commit to meteorcloudy/rules_jvm_external that referenced this pull request Mar 23, 2023
This change is required to support Bazel's offline bootstrap build.
More context in bazelbuild/bazel#17112

Instead of checking in jar files in Bazel's source tree, Bazel wants to use rules_jvm_external
to fetch jars dependencies. However, to support Bazel's bootstrap build,
we need to patch rules_jvm_external for vendoring the @maven repository.

- Generate a BUILD.vendor file to be used in the vendored `@maven` repository.
  Added a jvm_import and a filegroup rule for each downloaded jar artifact.
  The filegroup rule is required by the bootstrap Java toolchain used in Bazel's
  bootstrap build. The bootstrap Java toolchain cannot depend on a jvm_import target.
  Because the jvm_import rule depends on a java_binary tool "AddJarManifestEntry",
  which requires a Java toolchain. Depending on the jar via a filegroup rule helps
  avoid this cyclic dependency.
- Added a filegroup rule to collect all sources needed for vendoring `@maven`,
  including BUILD.vendor, WORKSPACE and jar files.
SalmaSamy pushed a commit that referenced this pull request Apr 19, 2023
- Non-third_party changes in #17112

Merging #17112

Stacking on #17142

Closes #17143.

PiperOrigin-RevId: 500980364
Change-Id: Ie03d4bc8e167d8a27ed8b33cd90f2e3af2c472f6

# Conflicts:
#	WORKSPACE
#	maven_install.json
cushon added a commit to cushon/bazel that referenced this pull request Sep 9, 2023
Instead of checking in a precompiled jar, following the example of
bazelbuild#17112
cushon added a commit to cushon/bazel that referenced this pull request Sep 11, 2023
Instead of checking in a precompiled jar, following the example of
bazelbuild#17112
copybara-service bot pushed a commit that referenced this pull request Sep 13, 2023
Instead of checking in a precompiled jar, following the example of #17112

Closes #19472.

PiperOrigin-RevId: 565016180
Change-Id: Ie7f3e0d2c999e5bb97b278156c586f52bc951bab
copybara-service bot pushed a commit that referenced this pull request Sep 13, 2023
Instead of checking in a precompiled jar, following the example of
#17112

Partial commit for third_party/*, see #19472.

Signed-off-by: Pavan Singh <[email protected]>
kon72 pushed a commit to kon72/rules_jvm_external that referenced this pull request Mar 23, 2024
This change is required to support Bazel's offline bootstrap build.
More context in bazelbuild/bazel#17112

Instead of checking in jar files in Bazel's source tree, Bazel wants to use rules_jvm_external
to fetch jars dependencies. However, to support Bazel's bootstrap build,
we need to patch rules_jvm_external for vendoring the @maven repository.

- Generate a BUILD.vendor file to be used in the vendored `@maven` repository.
  Added a jvm_import and a filegroup rule for each downloaded jar artifact.
  The filegroup rule is required by the bootstrap Java toolchain used in Bazel's
  bootstrap build. The bootstrap Java toolchain cannot depend on a jvm_import target.
  Because the jvm_import rule depends on a java_binary tool "AddJarManifestEntry",
  which requires a Java toolchain. Depending on the jar via a filegroup rule helps
  avoid this cyclic dependency.
- Added a filegroup rule to collect all sources needed for vendoring `@maven`,
  including BUILD.vendor, WORKSPACE and jar files.
- Fix `testonly` attribute handling in Bzlmod.
- Set `fetch_sources` to false by default in Bzlmod.
- Fix `excluded_artifacts` in Bzlmod.

Signed-off-by: kon72 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review PR is awaiting review from an assigned reviewer team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants