carbon-lang icon indicating copy to clipboard operation
carbon-lang copied to clipboard

Adding Windows support for building Carbon with Bazel.

Open EthanG78 opened this issue 3 years ago • 2 comments
trafficstars

This PR fixes issue #298. I am attempting to build Carbon using Bazel on Windows, without the need to go through WSL. This is still a work in progress, below is a list of issues I have discovered and my fixes for them.

  • Windows does not support Homebrew; however, I was able to properly install all of the required packages through Chocolatey. This was my first time using the Chocolatey package manager, yet it was fairly easy to use. I believe there are other options as well for Windows.
  • As is mentioned in issue #298, your Windows installation must be running in Developer Mode. This will allow unprivileged users to create symlinks during the build process.
  • As it currently stands in trunk, clang_configuration.bzl will fail when attempting to run the method _compute_clang_cpp_include_search_paths on Windows. I have discovered that this is because Clang++.exe fails to execute if you provide it with an input file that does not exist. Thus, I have the build script generate an empty temp file in the Bazel repo for Clang to use when running the above method.
  • A cc toolchain specifically for Windows was created in clang_toolchain.BUILD. I simply mimicked what was done for other platforms, I apologize if this is incorrect since I am fairly new to Bazel.

As I understand it, the next step is to configure clang_cc_toolchain_config.bzl to support the new Windows toolchain. I intend to continue working on this, however as I stated I am quite new so help is seriously appreciated!

EthanG78 avatar Jul 26 '22 23:07 EthanG78

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

google-cla[bot] avatar Jul 26 '22 23:07 google-cla[bot]

Update: The chocolatey installation of LLVM and Clang was giving me a lot of PATH issues where Bazel just wouldn't be able to find standard header files. Therefore I have switched to using MYSYS2 to install MinGW and Clang. You can follow the process here to get started with that. Simply add the MinGW bin to your path and Bazel should have no problem finding everything it needs.

Currently bazel test // ... :all fails when trying to build llvm: image

EthanG78 avatar Jul 29 '22 18:07 EthanG78

after everything is reviewed and it works. can anyone please post the steps to do it, or a script file?

Eshanatnight avatar Aug 07 '22 12:08 Eshanatnight

after everything is reviewed and it works. can anyone please post the steps to do it, or a script file?

Yes absolutely. My work recently has ramped up, which explains the lack of commits, however I do intend on getting this working. Once it is working, I will write up documentation outlining all of the steps required. Ideally these steps will eventually be included in the contribution tools document.

EthanG78 avatar Aug 09 '22 00:08 EthanG78

@EthanG78 Would it help if I dive in and do the edits I'm suggesting? While I can't do them from the GitHub UI, I believe I could from the CLI just to get this in (and let you focus on incremental progress when you have time).

jonmeow avatar Aug 09 '22 16:08 jonmeow

Hello, sorry if this is a stupid question, but now if i clones carbon

choco install bazelisk

And ran the commands that are there in the readme. It should interpret the code right?

I already have clang from Mingw

Eshanatnight avatar Aug 25 '22 20:08 Eshanatnight

Apologies if this is a stupid question, I have basically always used Visual Studio and CMake to do the whole compile, and build my code.

I created an environment that to test out carbon on windows, cloned the repo, used chocolatey to get bazelisk, and used msys2 to get Mingw. And it almost built, the current error is

Header <netinet/in.h> is not found.

And to my understanding there is no port of that as it is a UNIX interface. So, does that mean that carbon won't build natively on windows? Or is this an issue i am facing because i did not do something properly, in setting up the environment.

Sorry again for any inconvenience, I am a newbie when it comes to all of this, specially bazel, and i wanted to try out carbon for myself.

Eshanatnight avatar Aug 26 '22 16:08 Eshanatnight

@Eshanatnight This is a PR implementing functionality. Please use GitHub Discussions if you want help with Windows builds; they still aren't something we support. I'm going to refrain from responding here because I want to discourage off-topic discussion on PRs.

jonmeow avatar Aug 26 '22 17:08 jonmeow

I apologise for the problem caused.

Eshanatnight avatar Aug 26 '22 18:08 Eshanatnight