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

Fix compiler family detection issue with clang-cl on macOS #1328

Merged
merged 4 commits into from
Jan 8, 2025

Conversation

NobodyXu
Copy link
Collaborator

Fixed #1327

@NobodyXu NobodyXu requested a review from madsmtm December 22, 2024 13:57
@NobodyXu
Copy link
Collaborator Author

I can't know for sure if the compiler is clang-cl, so can't apply the workaround reliably.

Alternatively, we could combine cfg(macos) with accept cl flags check.

if both are true then it's likely clang-cl on macOS, which needs workaroud.

@NobodyXu NobodyXu requested a review from thomcc December 23, 2024 00:13
@madsmtm madsmtm added the bug label Jan 1, 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.

It is not clear to me why we even support clang-cl on macOS and Linux? cl.exe is not something you'd run on those platforms, so why would you ever run clang-cl? (Not a blocker for fixing this, just something I'd like to understand ;) )

cfg(macos)

That's a bad idea IMO, since this problem is also present on Linux and Windows hosts, just less prominently since their root paths usually start with a lowercase letter (on Linux), or prefixed with the drive letter (on Windows), but that's not a requirement!

Actually, the -- separator seems to be supported by normal Clang too, so why don't we just do this workaround everywhere?

This would also avoid issues if the user did e.g. .file("-l").

@NobodyXu
Copy link
Collaborator Author

NobodyXu commented Jan 2, 2025

It is not clear to me why we even support clang-cl on macOS and Linux? cl.exe is not something you'd run on those platforms, so why would you ever run clang-cl?

Based on the original issue, I believe they are using cargo-xwin to cross compile to msvc windows from a unix environment.

Actually, the -- separator seems to be supported by normal Clang too, so why don't we just do this workaround everywhere?

Does gcc and other compiler support it?

If they mostly do, we can add -- to compiler detection.

This would also avoid issues if the user did e.g. .file("-l").

Good idea

@madsmtm
Copy link
Collaborator

madsmtm commented Jan 2, 2025

Does gcc and other compiler support it?

$ touch foo.c
$ clang -c -- foo.c
$ gcc -c -- foo.c
gcc: error: unrecognized command-line option '--'

Doesn't seem like it?

NobodyXu and others added 2 commits January 7, 2025 00:50
to disambiguous path from arguments.

Signed-off-by: Jiahao XU <[email protected]>
Signed-off-by: Jiahao XU <[email protected]>
Signed-off-by: Jiahao XU <[email protected]>
@NobodyXu NobodyXu requested a review from madsmtm January 6, 2025 14:20
src/tool.rs Show resolved Hide resolved
"Expects macro `__clang__`, `__GNUC__` or `__EMSCRIPTEN__`, `__VXWORKS__` or accepts cl style flag `-?`, but found none",
))
}
if stdout.contains("-Wslash-u-filename") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This... Seems brittle :/.

Not that I have a better solution (yet).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't like it either, but I really can't think of an alternative solution that is better

Copy link
Collaborator

@madsmtm madsmtm Jan 7, 2025

Choose a reason for hiding this comment

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

What does CMake do? (if we're already following in their footsteps)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure , I didn't check about cmake.

I did remember the -? solution is copied from it, so perhaps it uses that as a hint?

src/tool.rs Show resolved Hide resolved
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.

I don't feel I know enough to really gauge whether this is the right approach or not, so I'll leave that up to you.

I don't think GitHub allows me to make a neutral review after having requested changes, so just so that won't block you, I've approved it.

@NobodyXu
Copy link
Collaborator Author

NobodyXu commented Jan 8, 2025

Thanks, let me merge it and try shipping it, if it doesn't work we have to revert and find another solution

@NobodyXu NobodyXu merged commit b886474 into main Jan 8, 2025
104 checks passed
@NobodyXu NobodyXu deleted the NobodyXu-patch-1 branch January 8, 2025 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compiler family detection issue with clang-cl on macOS
2 participants