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

Add support for Bzlmod #141

Merged
merged 13 commits into from
May 5, 2023
Merged

Add support for Bzlmod #141

merged 13 commits into from
May 5, 2023

Conversation

fmeum
Copy link
Contributor

@fmeum fmeum commented Nov 16, 2022

Input .bzl files are turned into runfiles of a custom Stardoc binary, which allows reusing the Java runfiles library to load the files while taking repository mappings into account.

@fmeum
Copy link
Contributor Author

fmeum commented Nov 18, 2022

@comius Should be ready for review, the failing test seems to require updating the stardoc parts in Bazel first.

@comius comius requested review from comius and removed request for tetromino and brandjon December 9, 2022 10:19
@comius comius self-assigned this Dec 9, 2022
@fmeum
Copy link
Contributor Author

fmeum commented Dec 12, 2022

@comius I pushed a new commit to fix the buildifier warnings.

@fmeum
Copy link
Contributor Author

fmeum commented Jan 5, 2023

@comius Friendly ping. Tests are expected to fail until we carry out bazelbuild/bazel#16775 (comment).

@aaronmondal
Copy link

Friendly ping. This is a blocker for downstream projects to fully migrate away from WORKSPACEs.

@tetromino
Copy link
Collaborator

@fmeum - am I correct in understanding that this PR requires using a Stardoc jar built after merging bazelbuild/bazel#16775 or similar? And without changing the doc extractor, we cannot get support for bzlmod?

@fmeum
Copy link
Contributor Author

fmeum commented Feb 13, 2023

@tetromino That's right. I outlined a process that I think should keep CI green at any time at bazelbuild/bazel#16775 (comment), but it's quite possible I missed something or there is a simpler way.

Copy link
Contributor

@comius comius left a comment

Choose a reason for hiding this comment

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

LGTM in general. I'll now import both changes at the same time and run tests internally and post if there is any additional feedback.

files = [ctx.file.input],
transitive_files = depset(transitive = [
dep[StarlarkLibraryInfo].transitive_srcs
for dep in ctx.attr.deps
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the implementation of bzl_library, it seems it is already returning transitive files within its runfiles. It would be nicer if you could just drop this additional rule and target and add input,deps directly stardoc_runfiles target. Is there anything preventing that?

Copy link
Contributor Author

@fmeum fmeum Mar 8, 2023

Choose a reason for hiding this comment

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

Thanks for the suggestion, that is indeed much nicer. Removed the rule.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also removed the target, please take a look as I may have missed an edge case in the data = [input] + deps logic.

@fmeum fmeum force-pushed the support-bzlmod branch 3 times, most recently from 901ed85 to 7689bf2 Compare March 8, 2023 14:11
@fmeum
Copy link
Contributor Author

fmeum commented Mar 8, 2023

I pushed a TMP commit that should make the pipeline green again, please ignore it during import.

copybara-service bot pushed a commit to bazelbuild/bazel that referenced this pull request Apr 20, 2023
Before Stardoc implementation was tested using stardoc.bzl from Stardoc repository. This makes it hard to change the implementation and bzl file at the same time.

The change is preparation to import #16775 and bazelbuild/stardoc#141. Without it we'd need to do a half-release of Stardoc PR to make Bazel's CI pass.

There's still a dependency on Stardoc repo/module from Bazel, which is used to generate the docs.

PiperOrigin-RevId: 525736214
Change-Id: I291838a9dd9bbb9482a47011e6e36fc6dd67eff1
Copy link
Contributor

@comius comius left a comment

Choose a reason for hiding this comment

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

Can you rebase and rebuild jars?

I'd rather merge this in from git side and then do a stardoc release.

stardoc/stardoc.bzl Show resolved Hide resolved
WORKSPACE Outdated Show resolved Hide resolved
stardoc/private/BUILD.bazel Outdated Show resolved Hide resolved
stardoc/stardoc.bzl Show resolved Hide resolved
stardoc/BUILD Outdated Show resolved Hide resolved
Input .bzl files are turned into runfiles of a custom Stardoc binary,
which allows reusing the Java runfiles library to load the files while
taking repository mappings into account.
@fmeum
Copy link
Contributor Author

fmeum commented Apr 27, 2023

I copied over the entire list of Maven deps from Bazel. It is long, but my attempts at doing this piece by piece resulted in a seemingly never-ending game of whack-a-mole.

@fmeum
Copy link
Contributor Author

fmeum commented Apr 27, 2023

The buildifier failure is due to bazelbuild/buildtools#1098, which is unrelated (except that I caused it, sorry :-))

@fmeum fmeum requested a review from comius April 27, 2023 14:48
@comius
Copy link
Contributor

comius commented Apr 28, 2023

@comius Updating Bazel turns out to be rather painful as it now uses rules_jvm_external. I was thinking whether we could switch to using Bzlmod exclusively for Stardoc development. What do you think?

I don't mind using bzlmod by default, but I'm not sure it helps. You'll need bazel, which is not on BCR. Adding it seems the easiest (cc @meteorcloudy @Wyverald ), but not sure if there are any objections to that.

Depending on Bazel via bzlmod via repo rules probably has the same problem.

Is it possible to depend on slightly older commit or disable some transitive tests to just get skydoc?

@fmeum
Copy link
Contributor Author

fmeum commented Apr 28, 2023

We could get it via a git_override, but would need to remove that line for BCR releases as non-root modules can't have overrides.

The commit with the changes for Stardoc landed after the switch to rules_jvm_external, so I don't see a way to depend on an older commit. I could manually prune the list based on query information, but starting from scratch led me to add quite a few deps that I wasn't expecting to be needed. @meteorcloudy Do you have an overview of what should be required here?

Copy link
Contributor

@comius comius left a comment

Choose a reason for hiding this comment

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

Is an empty .bazelversion needed?

stardoc/private/BUILD Outdated Show resolved Hide resolved
stardoc/BUILD Show resolved Hide resolved
Copy link
Contributor Author

@fmeum fmeum left a comment

Choose a reason for hiding this comment

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

Removed the .bazelversion file and trimmed down the list of dependencies manually.

stardoc/BUILD Show resolved Hide resolved
stardoc/stardoc.bzl Show resolved Hide resolved
stardoc/stardoc.bzl Show resolved Hide resolved
@fmeum fmeum requested a review from comius April 28, 2023 11:37
@comius
Copy link
Contributor

comius commented Apr 28, 2023

@tetromino this is now ready for review and/or merge

@Wyverald
Copy link
Member

Adding it seems the easiest (cc @meteorcloudy @Wyverald )

Adding Bazel to BCR is a bit weird since Bazel is not exactly a library people should depend on. (Granted, it's hella weird that Stardoc depends on Bazel, but that ship sailed before I even knew what Bazel was.)

I think we should probably just do the git_override plus patch thing. And hope @tetromino's rewrite ships soon (lol).

@meteorcloudy
Copy link
Member

Yeah, the prod version of Stardoc doesn't depend on Bazel, so even if we want to check in Stardoc in BCR, we don't need Bazel there. git_override with some patch should be enough.

Copy link
Collaborator

@tetromino tetromino left a comment

Choose a reason for hiding this comment

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

Thank you for this work. It's a hack which raises several questions, but every time upon careful reading of the code, one comes to the conclusion that this really is the least bad solution available at the moment :)

I regenerated the bundled jars on an internal machine - I hope you do not mind.

@tetromino tetromino merged commit ffcb4fb into bazelbuild:master May 5, 2023
@fmeum fmeum deleted the support-bzlmod branch May 5, 2023 08:59
@fmeum
Copy link
Contributor Author

fmeum commented May 5, 2023

@tetromino I found a small issue. I will fix it and submit a PR with a proper BCR test and publishing setup.

tetromino added a commit to tetromino/stardoc that referenced this pull request May 18, 2023
We need to ignore the _stardoc java_binary outputs introduced by bazelbuild#141.
tetromino added a commit that referenced this pull request May 19, 2023
In preparation for switching to starlark_doc_extract, we need to fix Stardoc tests to use .bzl files that can really be loaded by Bazel. This means:
* getting rid of misuses of aspect api
* getting rid of old Android and Java symbols
* getting rid of generated_bzl_test entirely, since Bazel cannot load dynamically generated .bzl modules.

Also fix update-stardoc-tests.sh script - we need to ignore the _stardoc java_binary outputs introduced by #141.
fweikert pushed a commit to fweikert/bazel that referenced this pull request May 25, 2023
Before Stardoc implementation was tested using stardoc.bzl from Stardoc repository. This makes it hard to change the implementation and bzl file at the same time.

The change is preparation to import bazelbuild#16775 and bazelbuild/stardoc#141. Without it we'd need to do a half-release of Stardoc PR to make Bazel's CI pass.

There's still a dependency on Stardoc repo/module from Bazel, which is used to generate the docs.

PiperOrigin-RevId: 525736214
Change-Id: I291838a9dd9bbb9482a47011e6e36fc6dd67eff1
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.

6 participants