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

tool: Expose family() in favour of incomplete is_like_xxx() wrappers #1358

Closed
wants to merge 1 commit into from

Conversation

MarijnS95
Copy link
Contributor

@MarijnS95 MarijnS95 commented Jan 10, 2025

Instead of adding a new is_like_xxx() function every time new information is needed, or new enumeration variants would be added, provide the (now non_exhaustive) enum directly to callers to match what they're interested in.

Also removes is_like_clang_cl() again from #1357 since that did not yet make it into a release, and would only cause unnecessary duplication in our API patterns.

Copy link
Collaborator

@NobodyXu NobodyXu left a comment

Choose a reason for hiding this comment

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

Thanks!

Have a few suggestions, and I will cut release tomorrow as it's too late for me.

src/tool.rs Outdated Show resolved Hide resolved
src/tool.rs Outdated Show resolved Hide resolved
src/tool.rs Show resolved Hide resolved
src/tool.rs Outdated
/// Whether the tool is GNU Compiler Collection-like.
#[deprecated = "Consider matching against the ToolFamily returned by family() instead"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure if we should deprecate this now cc @madsmtm what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wasn't sure either, might be a bit harsh but otherwise we could forget about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At the same time matching against self.family() for single variants is a bit ugly as you've seen.

@MarijnS95
Copy link
Contributor Author

Have a few suggestions, and I will cut release tomorrow as it's too late for me.

If we incorporate this PR, shall I just go ahead and remove is_like_clang_cl() again since it's only extra duplication?

@NobodyXu
Copy link
Collaborator

If we incorporate this PR, shall I just go ahead and remove is_like_clang_cl() again since it's only extra duplication?

Yes i think so

@MarijnS95 MarijnS95 requested a review from NobodyXu January 10, 2025 15:07
@briansmith
Copy link

I suggest we hold off on doing this until the situation gets out of hand. Deprecating the current methods will cause a lot of unneeded churn, especially for projects that don't want to increase their minimum cc-rs version.

Instead of adding a new `is_like_xxx()` function every time new
information is needed, or new enumeration variants would be added,
provide the (now `non_exhaustive`) `enum` directly to callers to match
what they're interested in.

Also removes `is_like_clang_cl()` again from rust-lang#1357 since that did not
yet make it into a release, and would only cause unnecessary duplication
in our API patterns.
@MarijnS95 MarijnS95 changed the title tool: Expose family() and deprecate is_like_xxx() wrappers tool: Expose family() in favour of incomplete is_like_xxx() wrappers Jan 10, 2025
@MarijnS95
Copy link
Contributor Author

@briansmith yeah makes sense, 1.x.x is likely to stay around for a long time. I've removed it so that this PR is ready for the proposed merge and release whenever @NobodyXu is available again (and I'm likely asleep).

@briansmith
Copy link

I wonder if it is a good idea to expose family() publicly like this at all, though? I would expect to have more thorough tests for it, first, if so.

@NobodyXu
Copy link
Collaborator

I wonder if it is a good idea to expose family() publicly like this at all, though?

Regarding API I think it's ok.

But since it's new API, cc @madsmtm can you take a look at this please?

I would expect to have more thorough tests for it, first, if so.

I remember we do have some tests for compiler family detection

Copy link
Collaborator

@madsmtm madsmtm left a comment

Choose a reason for hiding this comment

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

Hmm, I don't particularly like exposing ToolFamily, for several reasons:

  • I'm not certain that Msvc { clang_cl } is the right nesting, it could also be e.g. Clang { cl }.
  • I'm unsure if these three families are really the right separation, e.g. we might want ToolFamily::VxWorks or ToolFamily::Emscripten one day, but if we expose ToolFamily we're forced to put those under ToolFamily::Gnu { vxworks } or ToolFamily::Clang { emscripten }.
    Basically, I'm trying to say that even with #[non_exhaustive] on the enum, it'd still be a semantic breaking change to add a new variant.
  • Methods allows us to do the lookup more lazily. E.g. right now we don't use the zig_cc variable internally, so we might actually want to call is_zig_cc lazily instead when the user asks, but that would be harder if we exposed family.

@NobodyXu
Copy link
Collaborator

That's indeed true, we might want to reorder ToolFamily later...So perhaps we should close this PR for now and instead has more is_xxx functions?

@madsmtm
Copy link
Collaborator

madsmtm commented Jan 11, 2025

So perhaps we should close this PR for now and instead has more is_xxx functions?

I'd prefer that, yes.

@NobodyXu
Copy link
Collaborator

Sorry @MarijnS95, thank you for your work but we are still too worried about the potential API breakage/subpar API, we will close this PR for now and I will cut a new release.

@NobodyXu NobodyXu closed this Jan 11, 2025
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.

4 participants