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: struct holding cargo cfgs settings #18885

Merged
merged 3 commits into from
Jan 9, 2025

Conversation

qjerome
Copy link
Contributor

@qjerome qjerome commented Jan 8, 2025

Change to rust-analyzer.cargo.cfgs Setting

This PR replaces the current structure (a HashMap) for the rust-analyzer.cargo.cfgs setting with a Vec<String>. The use of a vector seems more appropriate for the following reasons:

  • Repeated same cfg keys can be used (currently impossible due to the use of a HashMap).
  • In the end, the original HashMap is turned into a vector of (key, value) tuples, so it seems there is no benefit to using a HashMap to hold these settings.

A beneficial side effect of this change is that rust-analyzer can have partial support for multi-target analysis through this setting (see the following configuration example).

New Format Example

{
  "rust-analyzer.cargo.cfgs": [
    "debug_assertion",
    "miri",
    "target_arch=x86_64",
    "target_arch=aarch64",
  ]
}

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 8, 2025
(key, val)
})
// we filter out anything with a None key
.filter(|(key, _)| key.is_some())
Copy link
Member

Choose a reason for hiding this comment

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

You can avoid the unwrap and do this in one step using filter_map.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

},
cargo_cfgs: Vec<String> = {
vec!["debug_assertion".into(), "miri".into()]
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}
},

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@lnicola
Copy link
Member

lnicola commented Jan 8, 2025

cargo test should fix the CI issue.

@Veykril
Copy link
Member

Veykril commented Jan 9, 2025

A beneficial side effect of this change is that rust-analyzer can have partial support for multi-target analysis through this setting (see the following configuration example).

No it still doesn't. What you are using it for merely enables CFGs that are assumed by the ecosystem to be disjoint. It may improve your specific situation here but it doesn't change the fact that r-a cannot handle multiple targets in a crate at once.

Either way thanks for the PR! You are correct that this being a map is incorrect given key-value cfgs can have overlapping keys.

@Veykril Veykril added this pull request to the merge queue Jan 9, 2025
@qjerome
Copy link
Contributor Author

qjerome commented Jan 9, 2025

No it still doesn't. What you are using it for merely enables CFGs that are assumed by the ecosystem to be disjoint. It may improve your specific situation here but it doesn't change the fact that r-a cannot handle multiple targets in a crate at once.

Yep, I fully agree with this statement. Yet I believe it provides a working alternative to opening several IDE with different r-a settings which becomes heavier when the number of targets increases. I actually hope it is gonna help others having the same issues as I have (being lazy enough to open several IDE instances to develop each of the targets).

Thank you @lnicola for the review and @Veykril for the merging

Merged via the queue into rust-lang:master with commit 5c106b4 Jan 9, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants