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

rustc_compile_action now requires an explicit attr param #886

Merged
merged 4 commits into from
Aug 12, 2021

Conversation

UebelAndre
Copy link
Collaborator

@UebelAndre UebelAndre commented Aug 11, 2021

In addition to some slight cleanup of using keyword arguments in more places, rustc_compile_action, an internal function, now requires that attributes be passed explicitly and no longer uses ctx.attr.

@google-cla google-cla bot added the cla: yes label Aug 11, 2021
rust/private/clippy.bzl Show resolved Hide resolved
rust/private/rustc.bzl Outdated Show resolved Hide resolved
@UebelAndre UebelAndre changed the title Slight cleanup of rustc.bzl rustc_compile_action now requires explicit attr parameter Aug 12, 2021
@UebelAndre UebelAndre changed the title rustc_compile_action now requires explicit attr parameter rustc_compile_action now requires an explicit attr parameter Aug 12, 2021
@UebelAndre UebelAndre changed the title rustc_compile_action now requires an explicit attr parameter rustc_compile_action now requires an explicit attr param Aug 12, 2021
@UebelAndre UebelAndre requested a review from hlopko August 12, 2021 14:23
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.

Only nits/ramblings :) Thank you for doing this!

@@ -92,7 +92,7 @@ def _build_script_impl(ctx):
# Pull in env vars which may be required for the cc_toolchain to work (e.g. on OSX, the SDK version).
# We hope that the linker env is sufficient for the whole cc_toolchain.
cc_toolchain, feature_configuration = find_cc_toolchain(ctx)
_, _, linker_env = get_linker_and_args(ctx, cc_toolchain, feature_configuration, None)
_, _, linker_env = get_linker_and_args(ctx, ctx.attr, cc_toolchain, feature_configuration, None)
Copy link
Member

Choose a reason for hiding this comment

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

Oh thanks for this cleanup. I didn't want to force you to do it in this PR, but thank you! :) I'd recommend going a bit further and only pass attributes that are really needed. Here get_linker_and_args actually only needs deps, so I'd pass those instead of the full ctx.attr.

No need to do it in this PR, but I'd also try (as much as reasonable) to not pass ctx around unnecessarily. Here get_linker_and_args only uses it for getting ctx.fragments.cpp.linkopts, so I'd probably pass linkopts. In some situations it may be more reasonable to pass the cpp fragment.

@@ -220,6 +220,7 @@ def _rust_proto_compile(protos, descriptor_sets, imports, crate_name, ctx, is_gr

return rustc_compile_action(
ctx = ctx,
attr = ctx.attr,
Copy link
Member

Choose a reason for hiding this comment

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

Yeah changing this to only needed attributes is a huge change, and I agree that it should be done in a separate PR, not in this one. 👍

@@ -204,7 +206,7 @@ def get_linker_and_args(ctx, cc_toolchain, feature_configuration, rpaths):

# Add linkopt's from dependencies. This includes linkopts from transitive
# dependencies since they get merged up.
for dep in ctx.attr.deps:
for dep in getattr(attr, "deps", []):
Copy link
Member

Choose a reason for hiding this comment

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

And by making deps separate function parameter we can make it mandatory, and we can skip gettattr.

out_binary = getattr(ctx.attr, "out_binary")
# TODO: Remove after some resolution to
# https://github.com/bazelbuild/rules_rust/issues/771
out_binary = getattr(attr, "out_binary", False)
Copy link
Member

Choose a reason for hiding this comment

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

Nice!


return providers

def _is_dylib(dep):
return not bool(dep.static_library or dep.pic_static_library)

def establish_cc_info(ctx, crate_info, toolchain, cc_toolchain, feature_configuration):
def establish_cc_info(ctx, attr, crate_info, toolchain, cc_toolchain, feature_configuration):
Copy link
Member

Choose a reason for hiding this comment

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

Again, this can be a separate PR, but here I'd pass ctx.actions separately, as well as deps, as well as deps, label, and out_binary

@UebelAndre
Copy link
Collaborator Author

I've opened #889 to track the additional comments here. Seems like there's a decent amount of things that could be updated so to make sure that gets done and things are as consistent as possible going forward, we should discuss what we want the code to look like 😄

@UebelAndre UebelAndre merged commit 0346cc4 into bazelbuild:main Aug 12, 2021
@UebelAndre UebelAndre deleted the rustc branch August 14, 2021 22:29
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