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

Allow rustc_compile_action to threat all dependencies as direct depenencies #970

Merged
merged 12 commits into from
Oct 14, 2021

Conversation

scentini
Copy link
Collaborator

@scentini scentini commented Oct 13, 2021

A code generator may not know which dependencies are direct and which transitive. When the new force_only_direct_deps parameter is set to True, the commandline will contain --extern=crate_name=... for all the transtive dependencies too.

@scentini scentini requested a review from hlopko October 13, 2021 12:41
@google-cla google-cla bot added the cla: yes label Oct 13, 2021
Copy link
Member

@hlopko hlopko left a comment

Choose a reason for hiding this comment

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

Looking good, only minor things, thank you!

@@ -453,6 +454,8 @@ def construct_arguments(
build_env_files (list): Files containing rustc environment variables, for instance from `cargo_build_script` actions.
build_flags_files (list): The output files of a `cargo_build_script` actions containing rustc build flags
emit (list): Values for the --emit flag to rustc.
force_only_direct_deps (bool, optional): Whether to pass the transitive rlibs with --external
Copy link
Member

Choose a reason for hiding this comment

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

Did you mean --extern (both here and in the PR description)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks! Done.

@@ -433,7 +433,8 @@ def construct_arguments(
out_dir,
build_env_files,
build_flags_files,
emit = ["dep-info", "link"]):
emit = ["dep-info", "link"],
force_only_direct_deps = False):
Copy link
Member

Choose a reason for hiding this comment

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

Wdyt about force_all_deps_direct?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

map_each = _crate_to_link_flag,
)
else:
# nb. Crates are linked via --extern regardless of their crate_type
Copy link
Member

Choose a reason for hiding this comment

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

while at it, would you mind changing the comment to say "Direct crates are linked via --extern...)? At its current form it's a bit misleading considering the previous block.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.


Returns:
list: Link flags for the current crate info
list: Link flags for the given crate_info
Copy link
Member

Choose a reason for hiding this comment

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

Nit: do you want to mention AliasableDepInfo in the return documentation too? Or just say "for the given provider".

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

rust/private/rustc.bzl Show resolved Hide resolved
DepInfo = _DepInfo
DepVariantInfo = _DepVariantInfo

rust_common = struct(
Copy link
Member

Choose a reason for hiding this comment

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

This is not really necessary for this PR, is it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@@ -0,0 +1,92 @@
"""A custom rule that threats all its dependencies as direct dependencies."""

load(
Copy link
Member

Choose a reason for hiding this comment

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

Feel free to add # buildifier: disable=bzl-visibility above the problematic load to silence the buildifier.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

action = tut.actions[1]
argv = action.argv
assert_action_mnemonic(env, action, "Rustc")
assert_argv_contains_prefix(
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Add assertion checking that there is no -Ldependency flag emitted.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We actually need the -Ldependency when resolving imports.

@hlopko hlopko merged commit 6bf03f2 into bazelbuild:main Oct 14, 2021
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

2 participants