-
-
Notifications
You must be signed in to change notification settings - Fork 106
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
cc-rs
link issue on windows msvc targets when using Clang with GNU cmdline syntax
#395
Comments
cdylib
broken on Clang + Windowscdylib
broken on Clang + Windows (with workarounds)
It appears you are using a rather old release of corrosion (v3.2). Did you test if this issue still exists on master?
I'd like to have a better understanding of what exactly goes wrong. Your setup seems to be the following from what I gathered:
If my understanding of your setup is correct, I'd ask you to:
|
Thanks for the swift reply.
I apologize for not mentioning I had tried this locally. Here's a commit and CI run
Unfortunately no dice: commit and CI run. (Note: ignore spurious
Yes, for this test branch this is the case; of course in the main branch, the vast majority of the project code is C/C++. Slightly beyond the scope of this issue, but although lld-link is indeed faster, it appears there may be some other issues that prevent it from being the default rust-lang/rust#71520 |
I'm guessing that this may actually be the issue. I haven't verified this yet, but from a quick look it seems the For MSVC there are actually three kinds of toolchains, but
|
It really doesn't seem like it? I pushed a run with it added back, and on lld, which completes our "Punnett square" in which all four combinations fail:
I also locally verified that once my patch is applied, both MT and MD CRTs work. I opted for MD, since I am already bundling the MSVCRT dll for my C++ core, and it shaves off some filesize. In IDA, I can verify that indeed it is defaulting to a dynamic CRT: The difference is also immediately noticeable: the .dll filesize grows 300KB. |
I think you misunderstood me. I'm saying this is an upstream issue of the I tested this fix with your rust crate by:
Edit: Sorry it seems like I may have been a bit to quick with this reply and messed up which terminal window had the CC variable set. Currently investigating. |
cdylib
broken on Clang + Windows (with workarounds)cc-rs
link issuen on windows msvc targets when using Clang with GNU cmdline syntax
cc-rs
link issuen on windows msvc targets when using Clang with GNU cmdline syntaxcc-rs
link issue on windows msvc targets when using Clang with GNU cmdline syntax
I compiled your crate with I stripped everything before the first library on the linker line to reduce the noise.
In comparison with
Unfortunately, I haven't been able to find yet where Complete logs: Edit: Apparently, |
Thank you for taking such a thorough look at the issue. Until it is fixed upstream, is there a particular workaround you'd endorse? I'd love to have my project on Corrosion's main branch, instead of my fork with an ugly workaround in the interim. Cheers |
I would have preferred to have the issue fixed upstream, but I currently don't have the time or knowledge about msvc to continue investigating. About possible solutions in the meantime: The user can set the environment variable Would this be sufficient for you? I am a bit hesitant of adding more flags, when it may not be necessary. |
@riidefi Did you have a chance to view the cc-rs PR above? I got the feedback that building C++ with clang for MSVC is not really possible, since clang with the GNU syntax has no way of accepting the /MD or /MT flags that |
Hi! I think that makes a lot of sense and should work perfectly well? The one thing I'd note is that there are some slight differences between clang-cl and clang that might catch someone off guard? See the motivating example here rust-lang/cc-rs#856 (Of course, minimal in comparison to that between clang and MSVC cl) |
In particular, the way Corrosion passes the CMake
CC_
/CXX_
to rust here causes issues when the rust linker attempts to link the binary with the MSVC linker. This affectslibcurl_sys
and many other-sys
crates that use the C compiler Corrosion specifies.The only change here is switching the target to
cdylib
(which forces a complete, not partial, link):A run with this issue can be seen here from this commit.
There are a few workarounds I've found:
clang-cl
(not viable)libcurl_sys
(not viable)CC
to overrideCC_
(hacky)CC_
altogether (hacky, but works and seen here and fixes the build on CI seen above with this CI commit and CI run)I believe the least annoying solution would be a flag to disable setting the
CC_
rustflag altogether, and let rust use the system compiler directly. Alternatively, it seems if we want to passCC
, we may also need to pass the linker, though that appears less feasible.Cheers
The text was updated successfully, but these errors were encountered: