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

feat: cross-compile to windows msvc #390

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

f0rmiga
Copy link
Member

@f0rmiga f0rmiga commented Sep 17, 2024

So, I had this code on my computer for a long time. I found it and wanted to share it with the community. It's not ready for a thorough review, but I wanted to spark a discussion about whether such a thing is desirable.

My motivation is simple: I don't want to have a Windows machine, much less one for development, but I want to distribute my software to run on Windows machines.

To accomplish this, I untangled some code around cross-compilation, which should also pave the way to cross-compile targeting macOS.

If we don't make any assumptions about whether we are cross-compiling, we can have a single pipeline for the targets. E.g. exec Linux or macOS targeting Linux should have no difference in which tools are used to compile and link.
Notice that my code only uses the lld already in the downloaded toolchain.

One way to obtain the Windows sysroot is by using https://github.com/Jake-Shadle/xwin. At this point, I didn't give the search paths much thought and instead hard-coded the directories I had on my sysroot.

A very important piece of this puzzle is adding the windows_cc_toolchain_config.bzl file with a few fixes you can see here and here. What I had to change makes me believe that nobody has ever tried to set a Windows sysroot using msvc under Bazel. There's no way the original windows_cc_toolchain_config.bzl could have worked with a sysroot. It's also possible that I am missing something...

I hope to get some feedback, and I'm happy to answer any questions you may have.

Some features of this file doesn't seem to have ever been used under
Windows. E.g. the --sysroot flag when compiling with msvc doesn't exist.
Also, it was not supported for the user to provide a sysroot anyways.
This allows for picking clang-cl instead of clang.
This should be temporary while I don't combine the wrapper for all
platforms.
It's been a few years that lld is not experimental anymore.
The advantage of always using lld is that we don't need to make
assumptions about cross-compiling.
The library is not called stdc++, the same way libc++ is not called c++.
Because we now renamed "stdc++" to "libstdc++", we don't need to
hardcode the stdlib name inside the conditional blocks.
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.

1 participant