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

Handle external packages using CARGO_MANIFEST_DIR #464

Merged

Conversation

sitaktif
Copy link
Contributor

No description provided.

@google-cla
Copy link

google-cla bot commented Oct 23, 2020

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added the cla: no label Oct 23, 2020
@google-cla google-cla bot added cla: yes and removed cla: no labels Oct 23, 2020
Copy link
Collaborator

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

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

LGTM!

Looks like CI is failing because the root WORKSPACE doesn't have a definition for the hello_cargo_manifest_dir repository :)

@sitaktif
Copy link
Contributor Author

Fixed!

WORKSPACE Outdated
@@ -79,3 +79,9 @@ docs_deps()
load("@docs//:docs_transitive_deps.bzl", docs_transitive_deps = "transitive_deps")

docs_transitive_deps(is_top_level = True)

# For the hello_uses_cargo_manifest_dir example.
local_repository(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does this need to be a repository? And if it needs to be a repository, could it not be put into example_deps similar to how rules_proto was added to docs/docs_transitive_deps.bzl?
https://github.com/bazelbuild/rules_rust/blob/master/docs/docs_transitive_deps.bzl#L20-L31

Copy link
Contributor Author

@sitaktif sitaktif Oct 23, 2020

Choose a reason for hiding this comment

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

Great questions!

It needs to be a repository because that's specifically the case we are testing: something that depends on an external target that uses the CARGO_MANIFEST_DIR environment variable. If the target is not external (ie. not in a separate repo) it won't reproduce the issue that this commit is fixing.

I can definitely put the deps in a separate bzl and will do so. Unfortunately I won't be able to reuse that .bzl file in examples/WORKSPACE because the path attribute has to be different, but it will still be a nice improvement to avoid polluting the root WORKSPACE 👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

You could use a bool (is_top_level) similar to the snippet I sent you to toggle between the paths. Would that not be sufficient?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're totally right, I should have read your comment more carefully. Amended as suggested!

@sitaktif sitaktif force-pushed the external-cargo-manifest-dir branch 3 times, most recently from 222b9e3 to d740455 Compare October 24, 2020 12:33

# Needed by the hello_uses_cargo_manifest_dir example.
if is_top_level:
maybe(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be

        maybe(
            native.local_repository,
            name = "hello_cargo_manifest_dir",
            path = "hello_cargo_manifest_dir",
        )

(Sorry if this is obvious, just trying to help 😅)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"just one small change, surely I can't mess that one up". Anyway, thanks for the help :-)

Unrelated, but I noticed that if you build from the examples/ dir (which creates all the examples/bazel-* directories, building from the root directory sometimes fails because of infinite recursion, as if the .bazelignore was ignored. I couldn't find how to fix the issue (the issue wasn't introduced in this commit though).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah... that's what happens when you have nested workspaces that depend on the root workspace like this. local_repository should ignore bazel output paths (or accept a pattern to ignore certain directories).

Hopefully Bazel's proposal for external dependencies resolves this. For now, you'll just have to make sure you bazel clean in ./examples. Or at least that's what I do... 😅

@sitaktif
Copy link
Contributor Author

Ok I think we're good now :-)

@illicitonion illicitonion merged commit 224fe6a into bazelbuild:master Oct 26, 2020
@UebelAndre
Copy link
Collaborator

@sitaktif I know this is a bit late but I was wondering if you'd be willing to merge

examples
├── hello_cargo_manifest_dir
└── hello_uses_cargo_manifest_dir

to something like:

examples
└── manifest_dir
    ├── external_repo
    └── usage

Just as a way to bundle the two examples 😅

(obviously not major, just a drive-by thought)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants