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

Refactor rustc_compile_action to construct CrateInfo internally #2188

Merged
merged 9 commits into from
Oct 17, 2023

Conversation

daivinhtran
Copy link
Contributor

@daivinhtran daivinhtran commented Oct 9, 2023

In #2161, I anticipated to make create_crate_info_dict reusable across all rules and aspects.

The logic to construct crate_info is significantly different among the rules and aspects. As I tried to to expand the arguments to make create_crate_info_dict universally reusable, the arguments grow which make it not worth anymore. This PR changes the refactoring approach.

Before (result from #2161)

def _rust_library_common()
    return rustc_compile_action(
        # the callback allows us to slowly refactor one rule or aspect at a time.
        create_crate_info_callback = create_crate_info_dict,
    )

def rustc_compile_action(create_crate_info_callback)
  if create_crate_info_callback:
    crate_info_dict = create_crate_info_callback()

After (result from this PR)

def _rust_library_common()
    # create crate_info_dict
    return rustc_compile_action(
        crate_info_dict = crate_info_dict,
    )

def rustc_compile_action(crate_info_dict)
  # crate_info_dict always exists

Instead of creating crate_info_dict at the beginning of rustc_compile_action, this PR lifted the creation logic to the rules and aspects completely so that they can add any custom logic without caring about the rustc_compile_action's implementation.

@daivinhtran daivinhtran force-pushed the refactor-rustc_compile_action branch 4 times, most recently from 186c9c2 to 5fad717 Compare October 9, 2023 20:39
@daivinhtran daivinhtran changed the title Move output_hash creation upstream Refactor rustc_compile_action to construct CrateInfo internally Oct 9, 2023
@@ -849,68 +849,3 @@ def _symlink_for_non_generated_source(ctx, src_file, package_root):
return src_symlink
else:
return src_file

def create_crate_info_dict(ctx, toolchain, crate_type):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The logic of this function differs significantly across the rules and aspects so it's not sharable anymore.

@daivinhtran daivinhtran marked this pull request as ready for review October 9, 2023 21:34
Copy link
Collaborator

@scentini scentini left a comment

Choose a reason for hiding this comment

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

Thanks!

@scentini scentini merged commit 3a78d01 into bazelbuild:main Oct 17, 2023
3 checks passed
scentini pushed a commit that referenced this pull request Oct 18, 2023
#2188's follow-up PR to remove unused `_rustc_env_attr` field in
`CrateInfo` provider. We can rely on `skip_expanding_rustc_env` to
determine whether `rustc_env` is already expanded or not.
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.

2 participants