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

Use features instead of build.rs to select llvm_x_or_greater #9

Merged
merged 1 commit into from Dec 18, 2020

Conversation

TheZoq2
Copy link
Contributor

@TheZoq2 TheZoq2 commented Dec 18, 2020

I had a problem with rust-analyzer thinking the debugloc fields were not present in most strutcs even though I'm building with llvm-11. Seing that those fields depend on CFG flags set in build.rs made mes suspect that this was the cause.

To fix it, I added some extra feature flags to Cargo.toml which do the same thing. It's a bit ugly, but the inheritance of features at least makes the amount of needed features linear in the amount of llvm versions supported.

Sidenote: after making this change, I found a r-a issue claiming to fix this kind of problem, but it seems like it's not fully fixed rust-lang/rust-analyzer#4296. Especially as if I removed the debugloc-fields, it would tell me that the field is needed. We may want to report this to them

Copy link
Owner

@cdisselkoen cdisselkoen left a comment

Choose a reason for hiding this comment

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

This looks great! Just a few small nits noted in my review. I hope it will be clear to crate users that they need not (and should not) manually activate these new features - but I think that will probably be clear enough, especially if we add a comment in Cargo.toml to that effect?

build.rs Outdated
@@ -12,30 +12,9 @@ fn main() {
if cfg!(feature = "llvm-11") {
versions.push(11);
}
let selected_version = match versions.len() {
match versions.len() {
0 => panic!("llvm-ir: Please select an LLVM version using a Cargo feature."),
1 => versions[0],
Copy link
Owner

Choose a reason for hiding this comment

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

tiny note, but since the let selected_version = was removed, we can also make this line be 1 => (), or similar.

Cargo.toml Outdated
llvm-11 = ["llvm-sys-110", "llvm-11-or-lower", "llvm-11-or-greater"]

# For convenience we set a number of configuration options to avoid
# checking complex combinations of features all the time.
Copy link
Owner

Choose a reason for hiding this comment

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

Can we also add a comment here to the effect of "These features are not meant to be manually enabled; use the features above instead"?

Copy link
Owner

Choose a reason for hiding this comment

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

Also, referring to "configuration options" might be confusing now since they're no longer cargo:rustc-cfg. Maybe "For convenience, these automatically-enabled features allow us to avoid checking complex combinations of features all the time"?

Cargo.toml Outdated

# For convenience we set a number of configuration options to avoid
# checking complex combinations of features all the time.
llvm-8-or-greater = [] # At least version 9
Copy link
Owner

Choose a reason for hiding this comment

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

I'm confused by the comment "At least version 9". I'm fine with removing this comment (also on the next line)?

Cargo.toml Outdated
llvm-9 = ["llvm-sys-90"]
llvm-10 = ["llvm-sys-100"]
llvm-11 = ["llvm-sys-110"]
llvm-8 = ["llvm-sys-80", "llvm-8-or-lower"]
Copy link
Owner

Choose a reason for hiding this comment

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

For symmetry we can have this also depend on llvm-8-or-greater

@TheZoq2
Copy link
Contributor Author

TheZoq2 commented Dec 18, 2020

Thanks for the quick reply! I pushed an update with the comments fixed

@cdisselkoen
Copy link
Owner

Awesome! Will merge this, thanks!

@cdisselkoen cdisselkoen merged commit fd90527 into cdisselkoen:master Dec 18, 2020
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.

None yet

2 participants