Skip to content

Conversation

GregBowyer
Copy link

@GregBowyer GregBowyer commented Aug 19, 2022

Hi, this will be a little insane and a little strange, but I would
like to get a read on the following as I refine it towards a potential
addition to these rules.

The following code allows for cross compiling windows (with MSVC ABI
rather than GNU, and I hope to adapt it to cope with clang on windows
too.

If this is something wanted I can polish these rules further rather than
fork and adapt.

This is very much an initial read, so there are some hacks, a hard-coded
path I could use help with and probably constructions that I am sure we
want to change.

As an example of this running (the binary is bytewise equivalent to the windows produced version) is as follows.

https://youtu.be/v54e1pSMUbw

@siddharthab
Copy link
Contributor

Thanks! We would definitely welcome any Windows support in here, if we can introduce it while keeping things relatively clean. I can give you write permissions if you want. Unfortunately, I don't pay attention to this project anymore, so won't directly review your code.

msvc_lib_path = tools_path_prefix + "llvm-lib"

cxx_builtin_include_directories = [
"/home/greg/.cache/bazel/_bazel_greg/ea13bb2946567f0877199a8bd9383c6f/" + toolchain_path_prefix + "include/c++/v1",
Copy link
Author

Choose a reason for hiding this comment

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

This hack is obviously wrong, it used the hermetic toolchain as downloaded, but I need to figure out how to educate bazel via skylark about how to point to the downloads without a massive hack.

sysroot_path + "/crt/lib/x86_64",
sysroot_path + "/sdk/lib/um/x86_64",
sysroot_path + "/sdk/lib/ucrt/x86_64",
# TODO: How to get this in a sysroot
Copy link
Author

Choose a reason for hiding this comment

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

What I mean by this TODO is that this comes from the clang bundle, but only from the windows clang bundle.

This is a bit weird as the linux clang bundle contains everything else, but omits this file, its easy to script this part in the preparation of a windows sysroot (or maybe we ask LLVM upstream to include it as part of the linux tarball).


host_tool_features = struct(
SUPPORTS_ARG_FILE = "supports_arg_file",
)

toolchain_tools = [
"clang-cpp",
"clang-cl",
Copy link
Author

Choose a reason for hiding this comment

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

These are present in the linux (maybe OSX?) bundles, but I can naturally look to make them optional / stub files.

@@ -19,7 +19,8 @@
import sys


_known_distros = ["freebsd", "suse", "ubuntu", "arch", "manjaro", "debian", "fedora", "centos", "amzn", "raspbian", "pop"]
_known_distros = ["freebsd", "suse", "ubuntu", "arch", "manjaro", "debian",
"fedora", "centos", "amzn", "raspbian", "pop", "nixos"]
Copy link
Author

Choose a reason for hiding this comment

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

Minor: This is unrelated to windows toolchains, my personal Linux is NixOS, but I am pretending it is equivalent to Ubuntu.

Will remove for a real release

@@ -122,6 +122,9 @@ def _linux(llvm_version, distname, version, arch):
elif distname == "raspbian":
arch = "armv7a"
os_name = "linux-gnueabihf"
elif distname == "nixos":
Copy link
Author

Choose a reason for hiding this comment

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

Minor: This is unrelated to windows toolchains, my personal Linux is NixOS, but I am pretending it is equivalent to Ubuntu.

Will remove for a real release

@GregBowyer
Copy link
Author

Thanks! We would definitely welcome any Windows support in here, if we can introduce it while keeping things relatively clean. I can give you write permissions if you want. Unfortunately, I don't pay attention to this project anymore, so won't directly review your code.

Might be good, I will wait for others to chime in on thoughts of how to do these things.

Hi, this is going to be a little insane and a little strange but I would
like to get a read on the following as I refine it towards a potential
addition to these rules.

The following code allows for cross compiling windows (with MSVC ABI
rather than GNU, and I hope to adapt it to cope with clang on windows
too.

If this is something wanted I can polish these rules further rather than
fork and adapt.

This is very much an initial read, so there are some hacks, a hardcoded
path I could use help with and probably constructions that I am sure we
want to change.
@GregBowyer GregBowyer force-pushed the windows-cross-compile branch from 0d43fdc to cb1d170 Compare October 11, 2022 21:50
@siddharthab
Copy link
Contributor

@GregBowyer, are you still interested in pursuing this?

@siddharthab siddharthab marked this pull request as draft March 11, 2024 03:27
@siddharthab
Copy link
Contributor

Closing now because of inactivity. We can reopen if needed.

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.

2 participants