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

Include wrapper args. in stdout family heuristics to restore classifying clang --driver-mode=cl as Msvc { clang_cl: true } #1378

Merged

Conversation

ErichDonGubler
Copy link
Contributor

@ErichDonGubler ErichDonGubler commented Jan 31, 2025

I'm not sure which version exactly broke this, but between 1.0.89 and latest releases, this case had broken for the primary tool family heuristic. This forces Firefox/mozilla-central to work around breakage in a cc upgrade a la D236305. We introduced it in #455, so we'd like to keep it working!

@ErichDonGubler ErichDonGubler force-pushed the restore-clang-cl-detection branch from 9eefc45 to 78469d1 Compare January 31, 2025 04:03
…ase_compiler`

Do this by plumbing through `args` associated with the compiler wrapper,
if any, instead of handling it in calling code.
@ErichDonGubler ErichDonGubler force-pushed the restore-clang-cl-detection branch from 78469d1 to e50b416 Compare January 31, 2025 04:06
@ErichDonGubler ErichDonGubler force-pushed the restore-clang-cl-detection branch from e50b416 to c5c1a91 Compare January 31, 2025 04:08
@madsmtm madsmtm mentioned this pull request Jan 31, 2025
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.

Not too familiar with our compiler detection, but fine with it if @NobodyXu is.

I'm sorry that it broke, if you'd really like it to not break in the future, I'd suggest you add a test ;)

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.

Thank you!

I have some feedbacks for the code itself, I think putting args in caching is the right approach

CHANGELOG.md Outdated Show resolved Hide resolved
src/tool.rs Outdated Show resolved Hide resolved
src/tool.rs Outdated Show resolved Hide resolved
@ErichDonGubler ErichDonGubler force-pushed the restore-clang-cl-detection branch 2 times, most recently from ffe0e41 to 17c805a Compare January 31, 2025 17:26
@ErichDonGubler
Copy link
Contributor Author

Not too familiar with our compiler detection, but fine with it if @NobodyXu is.

I'm sorry that it broke, if you'd really like it to not break in the future, I'd suggest you add a test ;)

❤️ I think this is a pitch-perfect response. I'm not familiar with how cc does testing, so I scoped my efforts towards just fixing things, but I definitely am interested in avoiding future breakage too, so I'll roll up my sleeves and see if I can write a meaningful test.

@ErichDonGubler
Copy link
Contributor Author

I'm actually not sure how to test this without having a fully functional clang --driver-mode=cl in CI, since the thing being fixed relies on evaluating stdout from the provided compiler. 🤔

src/tool.rs Outdated Show resolved Hide resolved
src/tool.rs Outdated Show resolved Hide resolved
src/tool.rs Outdated Show resolved Hide resolved
@NobodyXu
Copy link
Collaborator

I'm actually not sure how to test this without having a fully functional clang --driver-mode=cl in CI

Maybe you can try adding a new shim here?

pub fn clang() -> Test {

We currently has a gcc-shim binary in cc-rs https://github.com/rust-lang/cc-rs/blob/main/src/bin/gcc-shim.rs

Maybe we could have another clang-shim that does the testing?

This can be particularly significant for compilers that can dynamically
change what options they accept based on arguments, like `clang
--driver-mode=cl`.
@ErichDonGubler ErichDonGubler force-pushed the restore-clang-cl-detection branch from 17c805a to 5d29081 Compare January 31, 2025 18:19
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, LGTM!

If you are still working on the test, you can open a separate PR for it.

@ErichDonGubler
Copy link
Contributor Author

Thanks, LGTM!

If you are still working on the test, you can open a separate PR for it.

Yes, that would be good! I'm doing a bit more refactoring to accommodate a new shim in Test than I think is appropriate for this fix, but I have written a test locally that fails before and succeeds after this PR. So, I think I'm on the right track for a good follow-up PR. Thanks for the coaching!

One question: When this lands, is there a rough timeline for a release to come out?

ErichDonGubler added a commit to erichdongubler-mozilla/gecko-dev that referenced this pull request Jan 31, 2025
… r=#gfx-reviewers

This is no longer needed with an update to a `cc` consuming
<rust-lang/cc-rs#1378>. 🎉
@madsmtm
Copy link
Collaborator

madsmtm commented Jan 31, 2025

Re release, see #1377. If not in that, then next week.

@NobodyXu NobodyXu merged commit 3a4a86d into rust-lang:main Jan 31, 2025
52 checks passed
@ErichDonGubler ErichDonGubler deleted the restore-clang-cl-detection branch January 31, 2025 19:45
ErichDonGubler added a commit to erichdongubler-mozilla/gecko-dev that referenced this pull request Jan 31, 2025
… r=#gfx-reviewers

This is no longer needed with an update to a `cc` consuming
<rust-lang/cc-rs#1378>. 🎉
ErichDonGubler added a commit to erichdongubler-mozilla/gecko-dev that referenced this pull request Feb 4, 2025
… r=#gfx-reviewers

This is no longer needed with an update to a `cc` consuming
<rust-lang/cc-rs#1378>. 🎉
ErichDonGubler added a commit to erichdongubler-mozilla/gecko-dev that referenced this pull request Feb 4, 2025
… r=#gfx-reviewers

This is no longer needed with an update to a `cc` consuming
<rust-lang/cc-rs#1378>. 🎉

Differential Revision: https://phabricator.services.mozilla.com/D236650
ErichDonGubler added a commit to erichdongubler-mozilla/gecko-dev that referenced this pull request Feb 4, 2025
…etection of `clang --driver-mode=cl` r=#gfx-reviewers

With the current version of `cc`, we depend on behavior where, if `CC`
is set to something like `clang --driver-mode=cl`, we expect to be able
to use arguments on the command line a la MSVC's `cl.exe`. We were
actually the original contributors of a heuristic to detect this in the
`cc` crate, and it's served us well.

In `cc` upstream since 1.0.89, a new heuristic for detecting compiler
families in `cc::Tool` was introduced which does not have the desired
behavior, and misclassifies the above case as being `clang`-like, rather
than `cl`-like. The heuristic we originally submitted upstream is now
in a fallback path which does not get used for our case. This causes
`cc`'s default flags and APIs like `cc::Tool::is_like_msvc` to be
incorrect. `swgl`, in particular, breaks because of this, since it's
opinionated on the arguments it wants to provide to compilers.

Work around the above regression by detecting checking `Tool`s' base
command and "wrapper arguments" to see if we have a wrapper argument
matching `--driver-mode=cl`. If so, provide `cl`-like arguments in
`swgl`, rather than `clang`-like arguments.

This behavior has been fixed upstream; see
<rust-lang/cc-rs#1378>. Once released, we can
consume it and revert this patch.

Differential Revision: https://phabricator.services.mozilla.com/D236305
ErichDonGubler added a commit to erichdongubler-mozilla/gecko-dev that referenced this pull request Feb 4, 2025
… r=#gfx-reviewers

This is no longer needed with an update to a `cc` consuming
<rust-lang/cc-rs#1378>. 🎉

Differential Revision: https://phabricator.services.mozilla.com/D236650
ErichDonGubler added a commit to erichdongubler-mozilla/gecko-dev that referenced this pull request Feb 4, 2025
… r=#gfx-reviewers

This is no longer needed with an update to a `cc` consuming
<rust-lang/cc-rs#1378>. 🎉

Differential Revision: https://phabricator.services.mozilla.com/D236650
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Feb 4, 2025
…etection of `clang --driver-mode=cl` r=gfx-reviewers,nical

With the current version of `cc`, we depend on behavior where, if `CC`
is set to something like `clang --driver-mode=cl`, we expect to be able
to use arguments on the command line a la MSVC's `cl.exe`. We were
actually the original contributors of a heuristic to detect this in the
`cc` crate, and it's served us well.

In `cc` upstream since 1.0.89, a new heuristic for detecting compiler
families in `cc::Tool` was introduced which does not have the desired
behavior, and misclassifies the above case as being `clang`-like, rather
than `cl`-like. The heuristic we originally submitted upstream is now
in a fallback path which does not get used for our case. This causes
`cc`'s default flags and APIs like `cc::Tool::is_like_msvc` to be
incorrect. `swgl`, in particular, breaks because of this, since it's
opinionated on the arguments it wants to provide to compilers.

Work around the above regression by detecting checking `Tool`s' base
command and "wrapper arguments" to see if we have a wrapper argument
matching `--driver-mode=cl`. If so, provide `cl`-like arguments in
`swgl`, rather than `clang`-like arguments.

This behavior has been fixed upstream; see
<rust-lang/cc-rs#1378>. Once released, we can
consume it and revert this patch.

Differential Revision: https://phabricator.services.mozilla.com/D236305
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Feb 4, 2025
…etection of `clang --driver-mode=cl` r=gfx-reviewers,nical

With the current version of `cc`, we depend on behavior where, if `CC`
is set to something like `clang --driver-mode=cl`, we expect to be able
to use arguments on the command line a la MSVC's `cl.exe`. We were
actually the original contributors of a heuristic to detect this in the
`cc` crate, and it's served us well.

In `cc` upstream since 1.0.89, a new heuristic for detecting compiler
families in `cc::Tool` was introduced which does not have the desired
behavior, and misclassifies the above case as being `clang`-like, rather
than `cl`-like. The heuristic we originally submitted upstream is now
in a fallback path which does not get used for our case. This causes
`cc`'s default flags and APIs like `cc::Tool::is_like_msvc` to be
incorrect. `swgl`, in particular, breaks because of this, since it's
opinionated on the arguments it wants to provide to compilers.

Work around the above regression by detecting checking `Tool`s' base
command and "wrapper arguments" to see if we have a wrapper argument
matching `--driver-mode=cl`. If so, provide `cl`-like arguments in
`swgl`, rather than `clang`-like arguments.

This behavior has been fixed upstream; see
<rust-lang/cc-rs#1378>. Once released, we can
consume it and revert this patch.

Differential Revision: https://phabricator.services.mozilla.com/D236305
ErichDonGubler added a commit to erichdongubler-mozilla/gecko-dev that referenced this pull request Feb 4, 2025
… r=#gfx-reviewers

This is no longer needed with an update to a `cc` consuming
<rust-lang/cc-rs#1378>. 🎉

Differential Revision: https://phabricator.services.mozilla.com/D236650
ErichDonGubler added a commit to erichdongubler-mozilla/gecko-dev that referenced this pull request Feb 4, 2025
… r=#gfx-reviewers

This is no longer needed with an update to a `cc` consuming
<rust-lang/cc-rs#1378>. 🎉

Differential Revision: https://phabricator.services.mozilla.com/D236650
i3roly pushed a commit to i3roly/firefox-dynasty that referenced this pull request Feb 5, 2025
…etection of `clang --driver-mode=cl` r=gfx-reviewers,nical

With the current version of `cc`, we depend on behavior where, if `CC`
is set to something like `clang --driver-mode=cl`, we expect to be able
to use arguments on the command line a la MSVC's `cl.exe`. We were
actually the original contributors of a heuristic to detect this in the
`cc` crate, and it's served us well.

In `cc` upstream since 1.0.89, a new heuristic for detecting compiler
families in `cc::Tool` was introduced which does not have the desired
behavior, and misclassifies the above case as being `clang`-like, rather
than `cl`-like. The heuristic we originally submitted upstream is now
in a fallback path which does not get used for our case. This causes
`cc`'s default flags and APIs like `cc::Tool::is_like_msvc` to be
incorrect. `swgl`, in particular, breaks because of this, since it's
opinionated on the arguments it wants to provide to compilers.

Work around the above regression by detecting checking `Tool`s' base
command and "wrapper arguments" to see if we have a wrapper argument
matching `--driver-mode=cl`. If so, provide `cl`-like arguments in
`swgl`, rather than `clang`-like arguments.

This behavior has been fixed upstream; see
<rust-lang/cc-rs#1378>. Once released, we can
consume it and revert this patch.

Differential Revision: https://phabricator.services.mozilla.com/D236305
i3roly pushed a commit to i3roly/firefox-dynasty that referenced this pull request Feb 5, 2025
…etection of `clang --driver-mode=cl` r=gfx-reviewers,nical

With the current version of `cc`, we depend on behavior where, if `CC`
is set to something like `clang --driver-mode=cl`, we expect to be able
to use arguments on the command line a la MSVC's `cl.exe`. We were
actually the original contributors of a heuristic to detect this in the
`cc` crate, and it's served us well.

In `cc` upstream since 1.0.89, a new heuristic for detecting compiler
families in `cc::Tool` was introduced which does not have the desired
behavior, and misclassifies the above case as being `clang`-like, rather
than `cl`-like. The heuristic we originally submitted upstream is now
in a fallback path which does not get used for our case. This causes
`cc`'s default flags and APIs like `cc::Tool::is_like_msvc` to be
incorrect. `swgl`, in particular, breaks because of this, since it's
opinionated on the arguments it wants to provide to compilers.

Work around the above regression by detecting checking `Tool`s' base
command and "wrapper arguments" to see if we have a wrapper argument
matching `--driver-mode=cl`. If so, provide `cl`-like arguments in
`swgl`, rather than `clang`-like arguments.

This behavior has been fixed upstream; see
<rust-lang/cc-rs#1378>. Once released, we can
consume it and revert this patch.

Differential Revision: https://phabricator.services.mozilla.com/D236305
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Feb 5, 2025
… r=gfx-reviewers,lsalzman

This is no longer needed with an update to a `cc` consuming
<rust-lang/cc-rs#1378>. 🎉

Differential Revision: https://phabricator.services.mozilla.com/D236650
ErichDonGubler added a commit to erichdongubler-mozilla/gecko-dev that referenced this pull request Feb 5, 2025
… r=#gfx-reviewers

This is no longer needed with an update to a `cc` consuming
<rust-lang/cc-rs#1378>. 🎉

Differential Revision: https://phabricator.services.mozilla.com/D236650
ErichDonGubler added a commit to erichdongubler-mozilla/gecko-dev that referenced this pull request Feb 7, 2025
… r=#gfx-reviewers

This is no longer needed with an update to a `cc` consuming
<rust-lang/cc-rs#1378>. 🎉

Differential Revision: https://phabricator.services.mozilla.com/D236650
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.

3 participants