-
-
Notifications
You must be signed in to change notification settings - Fork 218
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
f0rmiga
wants to merge
15
commits into
bazel-contrib:master
Choose a base branch
from
f0rmiga:cross-compile-windows
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
@fmeum, any thoughts? |
I generally like this a lot and can review when you think it's ready. We should strive to make the change in a way that somewhat obviously doesn't change command lines for non-Windows target platforms. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 originalwindows_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.