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

Workspace support #276

Merged
merged 17 commits into from
Nov 21, 2020
Merged

Workspace support #276

merged 17 commits into from
Nov 21, 2020

Conversation

UebelAndre
Copy link
Collaborator

@UebelAndre UebelAndre commented Nov 1, 2020

The following pull requests are included in this change set and should be closed first:

This pull requests adds support for cargo workspaces and closes #262

Notable Changes:

  1. There is now a new setting workspace_member_dir which is used to determine the location where a package's dependencies will get aliased. Previously, a BUILD file would be rendered into workspace_path which would contain aliases for direct dependencies. Because we now account for there being multiple packages (ie, in a workspace) a directory matching the name specified by workspace_member_dir will be created in each package directory (where a Cargo.toml file lives) containing a BUILD file with the aliases. This is intended to make it easier for users to specify the dependencies they care about as well as maintain the previous behavior (workspace_member_dir should simply match the package name specified by workspace_path to result in no change for existing projects).
  2. Binary dependencies are treated as workspace members. This is done by downloading the binary dependency's source into the mock workspace when raze is gathering metadata and modifying the workspace root's Cargo.toml to include a workspace definition that includes the binary dependency. This allows raze to share a single lockfile for all dependencies and ensure all dependencies use compatible versions with each other. (this actually solves a bug I noticed when generating wasm-bindgen-cli for rules_rust. This dependency will update if the file is regenerated and cause a build error). Cargo-raze will now output a Cargo.raze.lock file when binary dependencies are specified. This file is authoritative over subsequent raze runs.
  3. Add support for defining Raze Settings via [workspace.metadata.raze]. This will take precedence over package definitions ([package.metadata.raze]) if it's defined. This should provide a consistent central location for settings even in projects that only provide a single root package.

Sorry about the large PR. I did a pass to split out what I could into other pull requests but I found it difficult to do so.

@UebelAndre
Copy link
Collaborator Author

@acmcarther sorry about the large PR. Looking forward to your feedback. I'm really hoping you like some of the changes here 😄

This was referenced Nov 1, 2020
dfreese pushed a commit that referenced this pull request Nov 2, 2020
This is work pulled out of #276

Changes:
* renamed settings::testing to settings::tests to be consistent with other modules
* Ran cargo fmt
@UebelAndre
Copy link
Collaborator Author

@wchargin do you have any suggestion on how [package.metadata.raze] would work in the context of a workspace? I'm getting warnings output in #277

@UebelAndre
Copy link
Collaborator Author

@wchargin do you have any suggestion on how [package.metadata.raze] would work in the context of a workspace? I'm getting warnings output in #277

Ah, found https://doc.rust-lang.org/cargo/reference/workspaces.html#the-workspacemetadata-table

Sorry to bother 😅

Copy link
Member

@acmcarther acmcarther left a comment

Choose a reason for hiding this comment

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

I got tired half way through the review (on me, not you, didn't get enough sleep last night), so I'm only half way done. I'll need to continue from about half way through impl/src/metadata.rs on my next review.

Looks good so far. Thank you for your continued work here and throughout the repo!

impl/Cargo.toml Show resolved Hide resolved
impl/src/context.rs Show resolved Hide resolved
impl/src/bin/cargo-raze.rs Outdated Show resolved Hide resolved
impl/src/bin/cargo-raze.rs Outdated Show resolved Hide resolved
impl/src/bin/cargo-raze.rs Outdated Show resolved Hide resolved
impl/src/metadata.rs Outdated Show resolved Hide resolved
impl/src/metadata.rs Outdated Show resolved Hide resolved
impl/src/metadata.rs Show resolved Hide resolved
impl/src/metadata.rs Show resolved Hide resolved
impl/src/metadata.rs Outdated Show resolved Hide resolved
@UebelAndre
Copy link
Collaborator Author

@acmcarther Hey, I've addressed some stuff here and had questions on a few things but is otherwise ready for another pass 😀

Copy link
Member

@acmcarther acmcarther 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 going to take a very long time to review.

impl/src/bin/cargo-raze.rs Outdated Show resolved Hide resolved
impl/src/metadata.rs Outdated Show resolved Hide resolved
impl/src/testing.rs Outdated Show resolved Hide resolved
impl/src/testing.rs Outdated Show resolved Hide resolved
impl/src/settings.rs Outdated Show resolved Hide resolved
impl/src/rendering/bazel.rs Outdated Show resolved Hide resolved
impl/src/rendering/bazel.rs Outdated Show resolved Hide resolved
impl/src/planning/subplanners.rs Outdated Show resolved Hide resolved
impl/src/metadata.rs Outdated Show resolved Hide resolved
impl/src/bin/cargo-raze.rs Outdated Show resolved Hide resolved
@UebelAndre
Copy link
Collaborator Author

This is going to take a very long time to review.

Why is that? Is there something I can do to help with that?

@UebelAndre
Copy link
Collaborator Author

#276 (comment)
@acmcarther what are you referring to here?

@UebelAndre
Copy link
Collaborator Author

This is going to take a very long time to review.

Why is that? Is there something I can do to help with that?

Oh, is it just that you're busy @acmcarther ? Totally understandable if so.

Also, this PR is ready for another review

impl/src/metadata.rs Outdated Show resolved Hide resolved
@UebelAndre
Copy link
Collaborator Author

@acmcarther Don't know why comments are being hidden (maybe the rebasing?) but I think I've gone over everything now.

impl/src/metadata.rs Outdated Show resolved Hide resolved
impl/src/testing.rs Show resolved Hide resolved
impl/src/testing.rs Outdated Show resolved Hide resolved
impl/src/rendering/bazel.rs Outdated Show resolved Hide resolved
Copy link
Member

@acmcarther acmcarther left a comment

Choose a reason for hiding this comment

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

functions are too long man

too long

@UebelAndre
Copy link
Collaborator Author

#276 (comment)
Ah! I see, I thought you were saying I had duplicate code within the same function.

@acmcarther
Copy link
Member

Humble request to stop rebasing the commits unless you have a good reason. It's wrecking the review history.

I try to click https://github.com/google/cargo-raze/pull/276/files/558e3cb7b2259a369880d26642269f376801b73c#diff-c8fe41d4c65c6cc6fc8160d444cb04842ac218c135768f6e4309b18ec27ee784 because you asked me to provide an example, and the link is broken

@UebelAndre
Copy link
Collaborator Author

@acmcarther Updated. Back to you 🙏

@UebelAndre
Copy link
Collaborator Author

I have the sneaking suspicion that this is going to to be a breaking change, but the test suite isn't good enough to catch it, and I'm no longer familiar enough with the code to identify it in review.

Oh well I guess. I think this is the last pass of comments.

This may be a "breaking" change for more obscure projects. Notable the generation of the aliases is controlled by the workspace_member_dir setting and is always relative to the location of Cargo.toml files. That said though, I think with that setting, users should be able to get new generations with these changes to match previous outputs.

@UebelAndre
Copy link
Collaborator Author

Fixed a typo which should fix CI.

@UebelAndre
Copy link
Collaborator Author

#277 is also green with no changes other than a rebase

@UebelAndre
Copy link
Collaborator Author

@acmcarther Hey, are you around to take another quick look? 😅

@UebelAndre
Copy link
Collaborator Author

@acmcarther Removed the whitespace. Ready for another pass 🙏

@acmcarther
Copy link
Member

Will wait for green from CI

@UebelAndre
Copy link
Collaborator Author

@acmcarther Just finished 😄

@acmcarther acmcarther merged commit fe8bca0 into google:master Nov 21, 2020
@UebelAndre
Copy link
Collaborator Author

@acmcarther thank you so much for all your support!!! 🙏

@UebelAndre UebelAndre deleted the workspace-support branch November 21, 2020 01:36
@dae
Copy link
Contributor

dae commented Nov 24, 2020

@UebelAndre would it make sense for workspace_member_dir to default to "." for compatibility? After updating I found I was getting cargo/cargo/BUILD.bazel instead of cargo/BUILD.bazel, and had to dig around to find out how to change it.

@UebelAndre
Copy link
Collaborator Author

UebelAndre commented Nov 24, 2020

@dae I can do that but I originally worried about setting it to "." because I was afraid of overriding valuable build files. Do you feel "." covers the common case?

Also, what do you think of the name workspace_member_dir? It's really just the Bazel package aliases should be rendered into. Is there a better name for it?

@dae
Copy link
Contributor

dae commented Nov 24, 2020

Would build_file_output_dir work, or does it have other uses I have missed?

@UebelAndre
Copy link
Collaborator Author

@dae Also, is your project public? I'd love to know more about how raze is used. From what I've gathered, there's two kinds of usage:

  1. Cargo projects that are being ported to bazel.
  2. Bazel projects that want to introduce dependencies on crates.io crates.

I've been focusing on the first case for some time which is partly why workspace_member_dir ended up in the state that it is. I'd love to get to a point where either users don't have to define bogus Cargo.toml files to use this tool. Then for the second point, I'd want to update rules_rust to be able to act as the authority and interract with crate registries from within Bazel entirely. No Cargo.toml files required. Users should be able to author their targets to define all the dependencies they require and the rules should efficiently handle the rest. I think there's a very real path forward to that goal with this tool and maybe some updates to rules_gazelle.

Anywho, I'd love to see your project structure and to know which camp you fall into (camp 1 or camp 2) to give me better context for future changes.

@UebelAndre
Copy link
Collaborator Author

Would build_file_output_dir work, or does it have other uses I have missed?

I feel like that's similar to workspace_member_dir in that it doesn't quite communicate the intent. I was thinking something like package_aliases_dir. Your thoughts there?

@dae
Copy link
Contributor

dae commented Nov 24, 2020

aliases_build_file_dir? top_build_file_dir?

I run an open source project that was recently converted to Bazel, though it does not currently use workspaces: https://github.com/ankitects/anki

@dae
Copy link
Contributor

dae commented Nov 24, 2020

(the point being that when the BUILD file moved, I was hunting for something related to the build file that controlled where it was placed)

@UebelAndre
Copy link
Collaborator Author

(the point being that when the BUILD file moved, I was hunting for something related to the build file that controlled where it was placed)

Would I be correct in saying your primary frustration was in the lack of documentation? This I can understand and I'm going to be writing documentation ASAP if that's the case or not. I've created #306 to start addressing this feedback. We should continue the conversation there.

Also, thanks for showing me your project! 🙏

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.

Feature Request: Support Cargo Workspaces
4 participants